-
Notifications
You must be signed in to change notification settings - Fork 286
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
Load static maps #387
Load static maps #387
Conversation
✅ Deploy Preview for aya-rs-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
ccbd873
to
84bae01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for working on it 😊 See comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! A couple of comments to address...
aya/src/maps/mod.rs
Outdated
} | ||
|
||
/// Loads a map from a rawfd. | ||
/// We assume that the map is not pinned in this case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should elaborate on the use case a little here to avoid confusion.
/// Loads a map from a [`RawFd`].
///
/// If loading from a BPF Filesystem (bpffs) you should use [`Map::from_pinned`].
/// This API is intended for cases where you have received a valid BPF FD from some other means.
/// For example, you received an FD over Unix Domain Socket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
6149de3
to
44a6f88
Compare
I think I got to everything here, thanks @dave-tucker @alessandrod! |
Add `from_pinned` to allow loading BPF maps from pinned points in the bpffs and `from_fd` to allow loading BPF maps from RawFds aquired via some other means eg a unix socket. These functions return an aya::Map which has not been used previously but will be the future abstraction once all bpf maps are represented as an enum. Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
44a6f88
to
8a9cbf1
Compare
Oops rebased! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of nits then it's ready to go!
CString::new(path.as_ref().to_string_lossy().into_owned()).map_err(|e| { | ||
MapError::PinError { | ||
name: None, | ||
error: PinError::InvalidPinPath { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this should be PinError::InvalidPath
})?; | ||
|
||
Ok(Map { | ||
obj: obj::parse_map_info(info, crate::PinningType::ByName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add use statements for both parse_map_info and PinningType don't use paths
})?; | ||
|
||
Ok(Map { | ||
obj: obj::parse_map_info(info, crate::PinningType::None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add use statement for parse_map_info
|
||
self.fd = Some(fd); | ||
|
||
Ok(fd) | ||
} | ||
|
||
/// Loads a map from a pinned path in bpffs. | ||
pub fn from_pinned<P: AsRef<Path>>(path: P) -> Result<Map, MapError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from_pinned but in another PR we're adding from_path. We should agree on one.
Merging as-is. I'll fixup the final review nits and open a PR to rename all the pinning apis to use |
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
fixes #385
This PR adds the new
aya::maps::{from_pinned, from_fd}
APIs. Which will allow users to load in and interact with BPF maps from either a raw file descriptor or map pin point.The user can get a concrete aya map type to interact with like so
I tested this locally with a pinned map, but was unsure exactly how to add unit tests....and would appreciate any feedback on that :)