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

programs: ProgramFd is owned #744

Merged
merged 1 commit into from
Aug 14, 2023
Merged

programs: ProgramFd is owned #744

merged 1 commit into from
Aug 14, 2023

Conversation

tamird
Copy link
Member

@tamird tamird commented Aug 10, 2023

ProgramData::fd is now also owned. This means that ProgramData now
closes the file descriptor on drop. In the future we might consider
making ProgramFd hold a BorrowedFd but this requires API design work
due to overlapping borrows.

Since ProgramFd is no longer Copy, update methods to take it by
reference to allow callers to use it multiple times as they are
accustomed to doing.

This is an API breaking change.

Updates #612.

@mergify
Copy link

mergify bot commented Aug 10, 2023

Hey @alessandrod, this pull request changes the Aya Public API and requires your review.

@mergify mergify bot added api/needs-review Makes an API change that needs review aya This is about aya (userspace) test A PR that improves test cases or CI labels Aug 10, 2023
@netlify
Copy link

netlify bot commented Aug 10, 2023

Deploy Preview for aya-rs-docs ready!

Name Link
🔨 Latest commit 504fd1d
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/64da49f71e794a0008882499
😎 Deploy Preview https://deploy-preview-744--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mergify
Copy link

mergify bot commented Aug 10, 2023

@tamird, this pull request is now in conflict and requires a rebase.

@mergify
Copy link

mergify bot commented Aug 11, 2023

@tamird, this pull request is now in conflict and requires a rebase.

aya/src/programs/extension.rs Outdated Show resolved Hide resolved
@tamird tamird force-pushed the programfd-borrowed branch 2 times, most recently from 35d85e5 to db61441 Compare August 11, 2023 16:44
@tamird tamird changed the title programs: ProgramFd is borrowed from the program programs: ProgramFd is owned Aug 11, 2023
aya/src/programs/mod.rs Outdated Show resolved Hide resolved
@tamird tamird force-pushed the programfd-borrowed branch 2 times, most recently from 69d2afc to edd307c Compare August 13, 2023 14:37
@@ -174,7 +176,9 @@ impl Xdp {
///
/// Ownership of the link will transfer to this program.
pub fn attach_to_link(&mut self, link: XdpLink) -> Result<XdpLinkId, ProgramError> {
let prog_fd = self.data.fd_or_err()?;
let prog_fd = self.fd()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and everywhere else, why not do:

let prog_fd = self.fd()?.as_fd().as_raw_fd();

Copy link
Member Author

Choose a reason for hiding this comment

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

Just personal preference - I prefer to avoid ? in the middle of an expression. This will also make the diff cleaner when we get around to removing the need for as_raw_fd; it'll be a pure deletion.

@mergify
Copy link

mergify bot commented Aug 14, 2023

@tamird, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Aug 14, 2023
Copy link
Collaborator

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

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

See nit, otherwise looks good

@tamird
Copy link
Member Author

tamird commented Aug 14, 2023

Will merge after @dave-tucker has a chance to approve.

`ProgramData::fd` is now a `ProgramFd`. This means that `ProgramData`
now closes the file descriptor on drop. In the future we might consider
making `ProgramFd` hold a `BorrowedFd` but this requires API design work
due to overlapping borrows.

Since `ProgramFd` is no longer `Copy`, update methods to take it by
reference to allow callers to use it multiple times as they are
accustomed to doing.

`ProgramFd` is now returned by reference and implements `try_clone` to
allow callers to avoid file descriptor cloning when desired.

This is an API breaking change.

Updates #612.
@tamird tamird merged commit e813a05 into main Aug 14, 2023
21 checks passed
@tamird tamird deleted the programfd-borrowed branch August 14, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/needs-review Makes an API change that needs review aya This is about aya (userspace) test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants