Skip to content

Commit

Permalink
tetragon: Fix map PinPath setup in case the map is shared
Browse files Browse the repository at this point in the history
In case the map is shared we bailed out before we properly setup
map's PinPath, which is needed later on in loader code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri authored and jrfastab committed Sep 20, 2024
1 parent 3cefc44 commit 609584e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func (s *Sensor) setMapPinPath(m *program.Map) {
func (s *Sensor) loadMaps(bpfDir string) error {
l := logger.GetLogger()
for _, m := range s.Maps {
// Even if the map already exists we need to setup proper PinPath
// so the loader can have access to the map location.
s.setMapPinPath(m)

if m.PinState.IsLoaded() {
l.WithFields(logrus.Fields{
"sensor": s.Name,
Expand All @@ -245,9 +249,6 @@ func (s *Sensor) loadMaps(bpfDir string) error {
continue
}

s.setMapPinPath(m)
pinPath := filepath.Join(bpfDir, m.PinPath)

spec, err := ebpf.LoadCollectionSpec(m.Prog.Name)
if err != nil {
return fmt.Errorf("failed to open collection '%s': %w", m.Prog.Name, err)
Expand All @@ -267,6 +268,8 @@ func (s *Sensor) loadMaps(bpfDir string) error {
}
}

pinPath := filepath.Join(bpfDir, m.PinPath)

if err := m.LoadOrCreatePinnedMap(pinPath, mapSpec); err != nil {
return fmt.Errorf("failed to load map '%s' for sensor '%s': %w", m.Name, s.Name, err)
}
Expand Down

0 comments on commit 609584e

Please sign in to comment.