Add ProgramHandle for lifetime-independent program fd ownership #1391
Merged
Conversation
1e34825 to
2555822
Compare
…programs Mirrors MapHandle pattern — owns fd via OwnedFd, caches name/type/tag/id. Constructors: from_prog_id, from_pinned_path, TryFrom<&Program>. Implements AsFd, pin/unpin, TryFrom<&Self> for cloning. Closes libbpf#920
danielocfb
approved these changes
May 13, 2026
Collaborator
danielocfb
left a comment
There was a problem hiding this comment.
Seems fine to me, thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I needed a way to hold onto a program fd after the Object goes out of scope. MapHandle already solves this for maps — ProgramHandle does the same thing for programs.
The implementation queries bpf_prog_info via bpf_obj_get_info_by_fd and caches name, type, tag, and id. Constructors cover the three ways you'd typically get a program: by kernel id, from
a pinned bpffs path, or by converting from an existing Program reference. Pin/unpin and AsFd round it out.
Kept it scoped — no ProgramCore trait, no attach methods (those need the libbpf bpf_program pointer), no ProgramInfo renames. Those can come separately if wanted.
Closes #920