Skip to content

Comments

improve error handling for einval with lpm trie.#1720

Closed
tommyp1ckles wants to merge 1 commit intocilium:mainfrom
tommyp1ckles:pr/tp/handle-trie-open-better
Closed

improve error handling for einval with lpm trie.#1720
tommyp1ckles wants to merge 1 commit intocilium:mainfrom
tommyp1ckles:pr/tp/handle-trie-open-better

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]>
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
Contributor

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.

@ti-mo
Copy link
Contributor

ti-mo commented May 6, 2025

Continuing this in #1776.

@ti-mo ti-mo closed this May 6, 2025
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