Skip to content

Commit

Permalink
draft: current implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kwakubiney committed Jul 25, 2023
1 parent 211b0e6 commit cc575d2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion map.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,34 @@ func (spec *MapSpec) createMap(inner *sys.FD, opts MapOptions) (_ *Map, err erro
}

switch spec.Type {
case ArrayOfMaps, HashOfMaps:
case LRUHash:
if spec.Flags&unix.BPF_F_NO_PREALLOC > 0 {
return nil, errors.New("no prealloc flag cannot be set for lru hash")
}
case RingBuf:
if spec.Flags&unix.BPF_F_NO_PREALLOC > 0 {
return nil, errors.New("no prealloc flag cannot be set for ring buf")
}
case PerCPUArray:
if spec.Flags&unix.BPF_F_NO_PREALLOC > 0 {
return nil, errors.New("no prealloc flag cannot be set for per cpu array")
}
case ArrayOfMaps:
if spec.Flags&unix.BPF_F_NO_PREALLOC > 0 {
return nil, errors.New("no prealloc flag cannot be set for array of maps")
}
if err := haveNestedMaps(); err != nil {
return nil, err
}

if spec.ValueSize != 0 && spec.ValueSize != 4 {
return nil, errors.New("ValueSize must be zero or four for map of map")
}

spec = spec.Copy()
spec.ValueSize = 4

case HashOfMaps:
if err := haveNestedMaps(); err != nil {
return nil, err
}
Expand Down

0 comments on commit cc575d2

Please sign in to comment.