MCPcopy
hub / github.com/cilium/ebpf / handleMapCreateError

Function handleMapCreateError

map.go:665–734  ·  view source on GitHub ↗
(attr sys.MapCreateAttr, spec *MapSpec, err error)

Source from the content-addressed store, hash-verified

663}
664
665func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) error {
666 if platform.IsWindows {
667 if errors.Is(err, unix.EINVAL) && attr.MapFlags != 0 {
668 return fmt.Errorf("map create: flags: %w", internal.ErrNotSupportedOnOS)
669 }
670
671 return err
672 }
673
674 if errors.Is(err, sys.ErrTokenCapabilities) {
675 return fmt.Errorf("map create: %w", err)
676 }
677
678 if errors.Is(err, unix.EPERM) {
679 return fmt.Errorf("map create: %w (MEMLOCK may be too low, consider rlimit.RemoveMemlock)", err)
680 }
681
682 if errors.Is(err, unix.EINVAL) {
683 if spec.MaxEntries == 0 && !spec.Type.mustHaveZeroMaxEntries() {
684 return fmt.Errorf("map create: %w (MaxEntries may be incorrectly set to zero)", err)
685 }
686 if spec.Type == UnspecifiedMap {
687 return fmt.Errorf("map create: cannot use type %s", UnspecifiedMap)
688 }
689 if spec.Flags&sys.BPF_F_NO_PREALLOC != 0 && !spec.Type.mustHaveNoPrealloc() {
690 return fmt.Errorf("map create: %w (BPF_F_NO_PREALLOC flag may be incompatible with map type %s)", err, spec.Type)
691 }
692 if spec.Flags&sys.BPF_F_NO_PREALLOC == 0 && spec.Type.mustHaveNoPrealloc() {
693 return fmt.Errorf("map create: %w (BPF_F_NO_PREALLOC flag may need to be set for map type %s)", err, spec.Type)
694 }
695 }
696
697 if spec.Type.canStoreMap() {
698 if haveFeatErr := haveNestedMaps(); haveFeatErr != nil {
699 return fmt.Errorf("map create: %w", haveFeatErr)
700 }
701 }
702
703 if spec.readOnly() || spec.writeOnly() {
704 if haveFeatErr := haveMapMutabilityModifiers(); haveFeatErr != nil {
705 return fmt.Errorf("map create: %w", haveFeatErr)
706 }
707 }
708 if spec.Flags&sys.BPF_F_MMAPABLE > 0 {
709 if haveFeatErr := haveMmapableMaps(); haveFeatErr != nil {
710 return fmt.Errorf("map create: %w", haveFeatErr)
711 }
712 }
713 if spec.Flags&sys.BPF_F_INNER_MAP > 0 {
714 if haveFeatErr := haveInnerMaps(); haveFeatErr != nil {
715 return fmt.Errorf("map create: %w", haveFeatErr)
716 }
717 }
718 if spec.Flags&sys.BPF_F_NO_PREALLOC > 0 {
719 if haveFeatErr := haveNoPreallocMaps(); haveFeatErr != nil {
720 return fmt.Errorf("map create: %w", haveFeatErr)
721 }
722 }

Callers 1

createMapMethod · 0.85

Calls 7

IsPowFunction · 0.92
mustHaveNoPreallocMethod · 0.80
canStoreMapMethod · 0.80
readOnlyMethod · 0.80
writeOnlyMethod · 0.80
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…