Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error handling for einval with lpm trie. #1720

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tommyp1ckles
Copy link
Contributor

In case of invalid key (i.e. not following lpm rules) the default error message is quite misleading:

noPrealloc flag may be incompatible with map type

In fact, lpm-trie requires no prealloc to be enabled so this error is likely to waste a confused programmers time.

Instead, we validate key params and return a specific error.

In case of invalid key (i.e. not following lpm rules)
the default error message is quite misleading:

`noPrealloc flag may be incompatible with map type`

In fact, lpm-trie requires no prealloc to be enabled
so this error is likely to waste a confused programmers
time.

Instead, we validate key params and return a specific
error.

Signed-off-by: Tom Hadlaw <[email protected]>
@@ -556,7 +556,12 @@ func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) erro
if errors.Is(err, unix.EINVAL) && spec.Type == UnspecifiedMap {
return fmt.Errorf("map create: cannot use type %s", UnspecifiedMap)
}
if errors.Is(err, unix.EINVAL) && spec.Flags&sys.BPF_F_NO_PREALLOC > 0 {
// LPM trie key size must be a multiple of 8 and not exceed 2048.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect according to my experience and the doc https://docs.ebpf.io/linux/map-type/BPF_MAP_TYPE_LPM_TRIE/.

if errors.Is(err, unix.EINVAL) && spec.Flags&sys.BPF_F_NO_PREALLOC > 0 {
// LPM trie key size must be a multiple of 8 and not exceed 2048.
// Ref: https://docs.kernel.org/bpf/map_lpm_trie.html#bpf-map-type-lpm-trie
if errors.Is(err, unix.EINVAL) && spec.Type == LPMTrie && (spec.KeySize%8 != 0 || spec.KeySize > 2048) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is becoming a bit too specific for me. The goal is not to be exhaustive, and the wording here has always been soft on purpose. Could you drop this change?

The actual problem is a false-positive on the error message. I suggest adding the the following to types.go:

func (mt MapType) mustHaveNoPrealloc() bool { }

I'd check the kernel sources for all currently-known cases and make this function return true for LPM, cgroup storage and others that require NO_PREALLOC to be set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants