Skip to content

Better error for BPF_MAP_TYPE_LRU_HASH creation fail due to bpf_spin_lock field #1804

Open
@incfly

Description

@incfly

When a map value contains a bpf_spin_lock field, the map could not be declared as BPF_MAP_TYPE_LRU_HASH.

struct value {
  struct bpf_spin_lock semaphore;
  // other fields
}

This is a eBPF its own requirement. But currently I see the error message is a generic map create: operation not supported. I see we have similar effort before on refining error message, #1072

And in map.go map loader would try to provide more information

func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) error {
	if errors.Is(err, unix.EPERM) {
		return fmt.Errorf("map create: %w (MEMLOCK may be too low, consider rlimit.RemoveMemlock)", err)
	}
	if errors.Is(err, unix.EINVAL) && spec.MaxEntries == 0 {
		return fmt.Errorf("map create: %w (MaxEntries may be incorrectly set to zero)", err)
	}
	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 {
		return fmt.Errorf("map create: %w (noPrealloc flag may be incompatible with map type %s)", err, spec.Type)
	}

It would be great to indicate this type of error as well.

Version: 0.17.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions