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

Update loading bpf programs with reuse map options #309

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 24 additions & 10 deletions kf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,15 +1108,7 @@ func (b *BPF) RemoveMapFiles(ifaceName string) error {
return fmt.Errorf("BPF program %s prog type %s ifacename %s map %s:failed to pin the map err - %#v",
b.Program.Name, b.Program.ProgType, ifaceName, mapFilename, err)
}
if strings.Contains(mapFilename, "..") {
return fmt.Errorf("BPF program %s prog type %s ifacename %s map %s:contains relative path",
b.Program.Name, b.Program.ProgType, ifaceName, mapFilename)
}
if err := os.RemoveAll(mapFilename); os.IsNotExist(err) {
log.Info().Msgf("RemoveMapFiles: BPF program %s map file removed successfully - %s err - %#v", b.Program.Name, mapFilename, err)
}
}

return nil
}

Expand Down Expand Up @@ -1189,9 +1181,31 @@ func (b *BPF) LoadBPFProgram(ifaceName string) error {
return fmt.Errorf("%s: remove rlimit lock failed", b.Program.Name)
}

prg, err := ebpf.LoadCollection(ObjectFile)
objSpec, err := ebpf.LoadCollectionSpec(ObjectFile)
if err != nil {
return fmt.Errorf("%s: loading collection spec failed - %#v", ObjectFile, err)
}

if err := b.CreateMapPinDirectory(ifaceName); err != nil {
return err
}

var mapPinPath string
if b.Program.ProgType == models.TCType {
mapPinPath = filepath.Join(b.hostConfig.BpfMapDefaultPath, models.TCMapPinPath, ifaceName)
} else {
mapPinPath = filepath.Join(b.hostConfig.BpfMapDefaultPath, ifaceName)
}
collOptions := ebpf.CollectionOptions{
Maps: ebpf.MapOptions{
PinPath: mapPinPath,
},
}

// Load the BPF program with the updated map options
prg, err := ebpf.NewCollectionWithOptions(objSpec, collOptions)
if err != nil {
return fmt.Errorf("%s: loading of bpf program failed - %#v", ObjectFile, err)
return fmt.Errorf("%s: loading of bpf program failed - %#v", b.Program.Name, err)
}

// Persist program handle
Expand Down