Skip to content

Commit

Permalink
map: add user-friendly message when ringbuffer size is incorrect
Browse files Browse the repository at this point in the history
Signed-off-by: hengyouhai <hengyouhai@tuhu.cn>
  • Loading branch information
hengyouhai authored and lmb committed Apr 10, 2024
1 parent 2e1ba13 commit d4bceb5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) erro
return fmt.Errorf("map create: %w", haveFeatErr)
}
}
// BPF_MAP_TYPE_RINGBUF's max_entries must be a power-of-2 multiple of kernel's page size.
if errors.Is(err, unix.EINVAL) &&
(attr.MapType == sys.BPF_MAP_TYPE_RINGBUF || attr.MapType == sys.BPF_MAP_TYPE_USER_RINGBUF) {
pageSize := uint32(os.Getpagesize())
maxEntries := attr.MaxEntries
if maxEntries%pageSize != 0 || !internal.IsPow(maxEntries) {
return fmt.Errorf("map create: %w (ring map size %d not a multiple of page size %d)", err, maxEntries, pageSize)
}
}
if attr.BtfFd == 0 {
return fmt.Errorf("map create: %w (without BTF k/v)", err)
}
Expand Down

0 comments on commit d4bceb5

Please sign in to comment.