Skip to content

Commit 93db3c9

Browse files
committed
tetra: Use new pin.WalkDir in debug progs
Using new pin.WalkDir interface to get all the tetragon programs from bpffs directory. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent ef53ab5 commit 93db3c9

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

cmd/tetra/debug/progs.go

+8-24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12+
"io/fs"
1213
"log"
1314
"os"
1415
"path"
@@ -24,6 +25,7 @@ import (
2425
"github.com/cilium/ebpf"
2526
"github.com/cilium/ebpf/btf"
2627
"github.com/cilium/ebpf/link"
28+
"github.com/cilium/ebpf/pin"
2729
"github.com/spf13/cobra"
2830
"golang.org/x/sys/unix"
2931
"golang.org/x/term"
@@ -403,26 +405,20 @@ func getTetragonProgs(base string) ([]*prog, error) {
403405
var progs []*prog
404406

405407
// Walk bpffs/tetragon and look for programs
406-
err := filepath.Walk(base,
407-
func(path string, finfo os.FileInfo, err error) error {
408+
err := pin.WalkDir(base,
409+
func(path string, finfo fs.DirEntry, obj pin.Pinner, err error) error {
408410
if err != nil {
409411
return err
410412
}
411413
if finfo.IsDir() {
412414
return nil
413415
}
414-
if strings.HasSuffix(path, "/link") || strings.HasSuffix(path, "/link_override") {
415-
return nil // skip BPF links, they make the syscall fail since cilium/ebpf@78074c59
416-
}
417-
p, err := ebpf.LoadPinnedProgram(path, nil)
418-
if err != nil {
419-
return err
420-
}
421-
defer p.Close()
422416

423-
if !isProg(p.FD()) {
417+
p, ok := obj.(*ebpf.Program)
418+
if !ok {
424419
return nil
425420
}
421+
defer p.Close()
426422

427423
info, err := p.Info()
428424
if err != nil {
@@ -440,7 +436,7 @@ func getTetragonProgs(base string) ([]*prog, error) {
440436
progs = append(progs, &prog{
441437
id: uint32(id),
442438
name: getName(p, info),
443-
pin: path,
439+
pin: filepath.Join(base, path),
444440
cnt: runCnt,
445441
time: runTime,
446442
alive: true,
@@ -450,18 +446,6 @@ func getTetragonProgs(base string) ([]*prog, error) {
450446
return progs, err
451447
}
452448

453-
func isProg(fd int) bool {
454-
return isBPFObject("prog", fd)
455-
}
456-
457-
func isBPFObject(object string, fd int) bool {
458-
readlink, err := os.Readlink(fmt.Sprintf("/proc/self/fd/%d", fd))
459-
if err != nil {
460-
return false
461-
}
462-
return readlink == fmt.Sprintf("anon_inode:bpf-%s", object)
463-
}
464-
465449
func getName(p *ebpf.Program, info *ebpf.ProgramInfo) string {
466450
handle, err := p.Handle()
467451
if err != nil {

0 commit comments

Comments
 (0)