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

pin: new package for loading bpf pins and walking bpffs directories #1626

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Dec 12, 2024

See individual commits.

The API added in this PR:

type Pinner interface {
	Pin(string) error
}

// Load retrieves a pinned object from a bpf virtual filesystem. It returns one
// of [ebpf.Map], [ebpf.Program], or [link.Link].
//
// Trying to open anything other than a bpf object is an error.
func Load(path string, opts *ebpf.LoadPinOptions) (Pinner, error)

// WalkDirFunc is the type of the function called for each object visited by
// [WalkDir]. It's identical to [fs.WalkDirFunc], but with an extra [Pinner]
// argument. If the visited node is a directory, obj is nil.
//
// err contains any errors encountered during bpffs traversal or object loading.
type WalkDirFunc func(path string, d fs.DirEntry, obj Pinner, err error) error

// WalkDir walks the file tree rooted at path, calling bpffn for each node in
// the tree, including directories. Running WalkDir on a non-bpf filesystem is
// an error. Otherwise identical in behavior to [fs.WalkDir].
//
// See the [WalkDirFunc] for more information.
func WalkDir(root string, bpffn WalkDirFunc) error

Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this!

@ti-mo ti-mo marked this pull request as ready for review December 12, 2024 20:17
@ti-mo ti-mo requested a review from a team as a code owner December 12, 2024 20:17
Copy link
Contributor

@rgo3 rgo3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:very_nice:

internal/sys/fd.go Show resolved Hide resolved
Copy link
Member

@dylandreimerink dylandreimerink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me 🚀

This is useful API to call from other packages.

In a subsequent commit, it will be used for passing ownership of a sys.FD
from a sys.ObjGet caller to New*FromFD functions, which would otherwise
create multiple sys.FD wrapping the same underlying fd.

Signed-off-by: Timo Beckers <timo@isovalent.com>
…ven type

Signed-off-by: Timo Beckers <timo@isovalent.com>
This commit adds a new package pin with two main APIs: Load() and WalkDir().
It's split off from the root package since ebpf cannot import link.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo merged commit 0a77f25 into cilium:main Dec 16, 2024
17 checks passed
@ti-mo ti-mo deleted the tb/pin-load branch December 16, 2024 09:30
mtardy added a commit to cilium/tetragon that referenced this pull request Dec 20, 2024
PR cilium/ebpf#1626 added the new pin package that simplifies a lot how
one can parse a bpf fs. I just love it.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
@mtardy
Copy link
Member

mtardy commented Dec 20, 2024

This is so much better, look at the improvement cilium/tetragon@ef53ab5. It removed sketchy code. Thanks again!

mtardy added a commit to cilium/tetragon that referenced this pull request Dec 20, 2024
PR cilium/ebpf#1626 added the new pin package that simplifies a lot how
one can parse a bpf fs. I just love it.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
@ti-mo
Copy link
Collaborator Author

ti-mo commented Dec 22, 2024

This is so much better, look at the improvement cilium/tetragon@ef53ab5. It removed sketchy code. Thanks again!

Thanks for the feedback, enjoy!

mtardy added a commit to cilium/tetragon that referenced this pull request Jan 2, 2025
PR cilium/ebpf#1626 added the new pin package that simplifies a lot how
one can parse a bpf fs. I just love it.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants