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

Refactor map API #397

Merged
merged 9 commits into from
Oct 20, 2022
Merged

Refactor map API #397

merged 9 commits into from
Oct 20, 2022

Conversation

astoycos
Copy link
Member

Fixes #386

@netlify
Copy link

netlify bot commented Sep 29, 2022

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 82edd68
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/63519bbb7ff1c60009fa17c1
😎 Deploy Preview https://deploy-preview-397--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 settings.

@astoycos
Copy link
Member Author

Still need to clean up commits and other stuff but the core bits are building and passing unit tests

aya/src/bpf.rs Outdated Show resolved Hide resolved
aya/src/bpf.rs Outdated Show resolved Hide resolved
@astoycos astoycos force-pushed the refactor-map-api2 branch 2 times, most recently from 8db7617 to 67bc3b9 Compare September 30, 2022 17:58
aya/src/bpf.rs Outdated Show resolved Hide resolved
aya/src/maps/array/array.rs Outdated Show resolved Hide resolved
aya/src/maps/array/array.rs Outdated Show resolved Hide resolved
aya/src/maps/bloom_filter.rs Outdated Show resolved Hide resolved
aya/src/maps/bloom_filter.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya-log/src/lib.rs Outdated Show resolved Hide resolved
aya/src/maps/bloom_filter.rs Outdated Show resolved Hide resolved
@astoycos
Copy link
Member Author

astoycos commented Oct 3, 2022

This PR is rebased against #398 to ensure CI goes green

Also there are still some tasks left on #386 to finish this up, Please let me know if there are any others i'm missing.

@astoycos astoycos marked this pull request as ready for review October 3, 2022 19:04
@astoycos
Copy link
Member Author

astoycos commented Oct 3, 2022

@alessandrod @dave-tucker I think this is ready for you to start reviewing....I'm happy to add more testing or anything else you would like to this PR or in follow up Issues, Thanks!

@astoycos
Copy link
Member Author

astoycos commented Oct 3, 2022

(also I can't assign you since I'm not a member of the org, any chance I could get added? )

@astoycos
Copy link
Member Author

astoycos commented Oct 3, 2022

Ah #398 Merged updating now :)

Remove MapError::UnexpectedMapType

Add Macro for converting from aya::Map to
u32 (map type) for use in
`MapError::InvalidMapType { map_type: x }`

Signed-off-by: Andrew Stoycos <[email protected]>
macro_rules! impl_try_from_map_generic_key_or_value {
($($typ:ty),+ $(,)?) => {
$(
impl From<$typ> for u32 {
Copy link
Collaborator

@alessandrod alessandrod Oct 19, 2022

Choose a reason for hiding this comment

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

Someone is getting excited with these macros! :P

I think this should be just an internal utility method and not a from impl (nor a macro). Right now you've made it (accidentally) a public API and I don't think we want to expose Map => u32 publicly

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol yeah I go over excited, I forgot this was as simple as adding a simple aya::Map Method, and I do like Macros :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

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.

Looking great now, see last thing about the from impl, then it's good to go

Remove From method and replace with internal
helper function.

Signed-off-by: Andrew Stoycos <[email protected]>
@astoycos
Copy link
Member Author

Should be all set! :)

@astoycos astoycos requested review from alessandrod and removed request for vadorovsky October 20, 2022 12:36
aya/src/bpf.rs Outdated Show resolved Hide resolved
aya/src/bpf.rs Outdated Show resolved Hide resolved
aya/src/bpf.rs Outdated Show resolved Hide resolved
switch map() and map_mut() from returning a
`Result` to an `Option` since it's just getting
a value from a Hashmap, and to stay in line with
the Programs API.

Remove `MapError::MapNotFound`

Signed-off-by: Andrew Stoycos <[email protected]>
aya/src/maps/sock/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Show resolved Hide resolved
aya/src/bpf.rs Outdated
///
/// # Errors
/// This API is intended for cases where the map must be moved into spawned
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use this when borrowing with [`map`] or [`map_mut`] is not possible (eg when using the map from an async task). The returned map will be closed on `Drop`, therefore the caller is responsible for managing its lifetime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Fix some broken rust doc links.

Make sure rustdoc build fail on warnings
so we catch these broken links in CI.

Signed-off-by: Andrew Stoycos <[email protected]>
@@ -90,7 +90,7 @@ impl BpfLogger {
logger: T,
) -> Result<BpfLogger, Error> {
let logger = Arc::new(logger);
let mut logs: AsyncPerfEventArray<_> = bpf.map_mut("AYA_LOGS")?.try_into()?;
let mut logs: AsyncPerfEventArray<_> = bpf.take_map("AYA_LOGS").unwrap().try_into()?;
Copy link
Member

Choose a reason for hiding this comment

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

this ? -> .unwrap() means that bpf programs that don't log will result in a panic on the userspace side.

Sent #476 to fix this.

alessandrod added a commit to alessandrod/aya that referenced this pull request Feb 7, 2023
@dave-tucker dave-tucker added feature A PR that implements a new feature or enhancement aya This is about aya (userspace) labels Feb 23, 2023
tamird added a commit to aya-rs/aya-template that referenced this pull request Jun 13, 2023
These were broken by #89 which pulled in
aya-rs/aya#397 and other changes which were not
reflected in the templates.
tamird added a commit to aya-rs/aya-template that referenced this pull request Jun 13, 2023
These were broken by #89 which pulled in
aya-rs/aya#397 and other changes which were not
reflected in the templates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya This is about aya (userspace) feature A PR that implements a new feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert BPF maps to using enums
5 participants