Skip to content

Commit

Permalink
tetra: Use new pin.WalkDir in debug progs
Browse files Browse the repository at this point in the history
Using new pin.WalkDir interface to get all the tetragon
programs from bpffs directory.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Dec 21, 2024
1 parent ef53ab5 commit e4b3734
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions cmd/tetra/debug/progs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"log"
"os"
"path"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/btf"
"github.com/cilium/ebpf/link"
"github.com/cilium/ebpf/pin"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
"golang.org/x/term"
Expand Down Expand Up @@ -403,50 +405,44 @@ func getTetragonProgs(base string) ([]*prog, error) {
var progs []*prog

// Walk bpffs/tetragon and look for programs
err := filepath.Walk(base,
func(path string, finfo os.FileInfo, err error) error {
if err != nil {
return err
}
if finfo.IsDir() {
return nil
}
if strings.HasSuffix(path, "/link") || strings.HasSuffix(path, "/link_override") {
return nil // skip BPF links, they make the syscall fail since cilium/ebpf@78074c59
}
p, err := ebpf.LoadPinnedProgram(path, nil)
if err != nil {
return err
}
defer p.Close()
err := pin.WalkDir(base, func(path string, d fs.DirEntry, obj pin.Pinner, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}

if !isProg(p.FD()) {
return nil
}
p, ok := obj.(*ebpf.Program)
if !ok {
return nil
}
defer p.Close()

info, err := p.Info()
if err != nil {
return err
}
info, err := p.Info()
if err != nil {
return err
}

id, ok := info.ID()
if !ok {
return err
}
id, ok := info.ID()
if !ok {
return err
}

runTime, _ := info.Runtime()
runCnt, _ := info.RunCount()

progs = append(progs, &prog{
id: uint32(id),
name: getName(p, info),
pin: path,
cnt: runCnt,
time: runTime,
alive: true,
})
return nil
runTime, _ := info.Runtime()
runCnt, _ := info.RunCount()

progs = append(progs, &prog{
id: uint32(id),
name: getName(p, info),
pin: filepath.Join(base, path),
cnt: runCnt,
time: runTime,
alive: true,
})
return nil
})

return progs, err
}

Expand Down

0 comments on commit e4b3734

Please sign in to comment.