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

aya: Implement dedicated map pinning #783

Merged
merged 3 commits into from
Oct 10, 2023
Merged

Conversation

astoycos
Copy link
Member

@astoycos astoycos commented Sep 8, 2023

Align with libbpf's LIBBPF_PIN_BY_NAME map flag behavior. More specifically if map_pin_path is not provided but a program has a map defined with the flag, pin it in /sys/fs/bpf otherwise pin it in the path provided by map_pin_path(P).

Additionally, allow users to manually manage map pinning much like we do already for Programs, see commit messages for more details.

TODO support the pinning api for PerfEventArray's and AsyncPerfEventArray's


This change is Reviewable

@netlify
Copy link

netlify bot commented Sep 8, 2023

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8203914
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/652586c00a7cd500081cbf7b
😎 Deploy Preview https://deploy-preview-783--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 mergify bot added aya This is about aya (userspace) test A PR that improves test cases or CI labels Sep 8, 2023
@astoycos astoycos force-pushed the map_pin2 branch 2 times, most recently from c58e3ec to d9cf8e1 Compare September 8, 2023 19:42
@mergify
Copy link

mergify bot commented Sep 8, 2023

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

@mergify mergify bot requested a review from alessandrod September 8, 2023 19:43
@mergify mergify bot added the api/needs-review Makes an API change that needs review label Sep 8, 2023
@astoycos astoycos force-pushed the map_pin2 branch 2 times, most recently from 4711618 to 1ae55ac Compare September 11, 2023 14:41
aya/src/bpf.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/rbpf.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/rbpf.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/rbpf.rs Show resolved Hide resolved
test/integration-test/src/tests/load.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
@mergify
Copy link

mergify bot commented Sep 11, 2023

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

@mergify mergify bot added the needs-rebase label Sep 11, 2023
Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Did you forget to push?

aya/src/util.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/rbpf.rs Outdated Show resolved Hide resolved
@astoycos
Copy link
Member Author

Pushed in a new commit @tamird so it's easier to check diff, I'll squash everything whenever you approve it

@astoycos
Copy link
Member Author

astoycos commented Sep 13, 2023

Sorry usually I respond to comments as I fix things and then resolve them / re-request review after I push the changes.

@astoycos
Copy link
Member Author

I'll bless the public API on squash 👍

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Sorry usually I respond to comments as I fix things and then resolve them / re-request review after I push the changes.

You can "start a review" instead of publishing the comments as you go. That would be friendlier to reviewers.

aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/pin.rs Outdated Show resolved Hide resolved
aya/src/util.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/load.rs Show resolved Hide resolved
test/integration-test/src/tests/rbpf.rs Outdated Show resolved Hide resolved
aya/src/util.rs Outdated Show resolved Hide resolved
Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Moving my review to Reviewable because GitHub reviews are so painful :(

Reviewed 13 of 19 files at r1, 7 of 7 files at r2, all commit messages.
Reviewable status: all files reviewed, 29 unresolved discussions (waiting on @alessandrod, @astoycos, and @dave-tucker)


aya/src/maps/mod.rs line 519 at r2 (raw file):

    pub fn create(
        obj: obj::Map,
        name: &str,

we should maybe take a String here so that the caller can control allocation.


aya/src/maps/mod.rs line 554 at r2 (raw file):

        path: P,
        obj: obj::Map,
        name: &str,

ditto


aya/src/maps/mod.rs line 654 at r2 (raw file):

        if paths.contains(&path.as_ref().to_path_buf()) {
            return Err(PinError::AlreadyPinned {
                name: name.to_string(),

nit: .clone() because the thing is already a String


aya/src/maps/mod.rs line 693 at r2 (raw file):

            let (paths, errors) = errors.into_iter().unzip();
            return Err(PinError::UnpinError {
                name: name.to_string(),

.clone

aya/src/maps/mod.rs Outdated Show resolved Hide resolved
@mergify
Copy link

mergify bot commented Sep 18, 2023

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

@mergify mergify bot added the needs-rebase label Sep 18, 2023
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
@astoycos
Copy link
Member Author

Waiting for #790 to merge then I'll build back on top of it

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 19 files at r5, 17 of 17 files at r6, all commit messages.
Dismissed @dave-tucker from 3 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @alessandrod, @astoycos, and @dave-tucker)


test/integration-test/src/tests/load.rs line 80 at r3 (raw file):

Previously, astoycos (Andrew Stoycos) wrote…

Join is a method on path but it turns it into an owned PathBuf https://doc.rust-lang.org/std/path/struct.Path.html#method.join

Then we get a bunch of "borrow of moved value" errors

using an &Path which is coerced into an &PathBuf on .join fixes this

Ah I missed the .join.


test/integration-test/src/tests/rbpf.rs line 64 at r6 (raw file):

            "map_2" => 1,
            "map_pin_by_name" => 2,
            _ => panic!("Unexpected map name: {}", name),

Nit: s/_/name/ to clarify that it's not discarded

@mergify
Copy link

mergify bot commented Sep 25, 2023

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

@mergify mergify bot added the needs-rebase label Sep 25, 2023
Copy link
Member Author

@astoycos astoycos left a comment

Choose a reason for hiding this comment

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

Reviewable status: 17 of 26 files reviewed, all discussions resolved (waiting on @alessandrod and @tamird)


test/integration-test/src/tests/rbpf.rs line 64 at r6 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

Nit: s/_/name/ to clarify that it's not discarded

Done

@mergify mergify bot removed the needs-rebase label Sep 25, 2023
@astoycos
Copy link
Member Author

@alessandrod Just need a final pass on the API from you please 👼

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 9 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @alessandrod)


test/integration-test/src/tests/rbpf.rs line 64 at r6 (raw file):

Previously, astoycos (Andrew Stoycos) wrote…

Done

Sorry I meant replace the underscore with "name"

Copy link
Member Author

@astoycos astoycos left a comment

Choose a reason for hiding this comment

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

Reviewable status: 23 of 26 files reviewed, all discussions resolved (waiting on @alessandrod and @tamird)


test/integration-test/src/tests/rbpf.rs line 64 at r6 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

Sorry I meant replace the underscore with "name"

My bad fixed!

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @alessandrod)

@astoycos astoycos requested review from alessandrod and removed request for alessandrod September 29, 2023 15:45
@astoycos
Copy link
Member Author

astoycos commented Oct 3, 2023

Poke @alessandrod For a quick look, TIA!

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.

Just a few nits!

aya/src/maps/mod.rs Outdated Show resolved Hide resolved
}

// Implements map pinning for different map implementations
// TODO add support for PerfEventArrays and AsyncPerfEventArrays
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this todo? What's missing to implement it?

Copy link
Member Author

@astoycos astoycos Oct 10, 2023

Choose a reason for hiding this comment

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

A PerfEventArray keeps an Arc<MapData> instead of just MapData so we would need to write an explicit pin method for it rather than express it with the macro.

I can do that here if you want, or in a follow up!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not a fan of follow ups, because some of them tend to never happen. That said if landing this as is unblocks you I'm happy to make an exception 😋

aya/src/maps/mod.rs Show resolved Hide resolved
aya/src/bpf.rs Outdated Show resolved Hide resolved
Aligns with libbpf for the special LIBBPF_PIN_BY_NAME
map flag. Specifically if the flag is provided without a pin path
default to "/sys/fs/bpf".

Signed-off-by: astoycos <astoycos@redhat.com>
aya/src/maps/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 10 of 10 files at r10, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @astoycos)

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Dismissed @alessandrod from 3 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @astoycos)


aya/src/maps/mod.rs line 358 at r10 (raw file):

            {
                    /// Pins the map to a BPF filesystem.

here too

- Adds new `maps_mut()` API to the BpfManager to allow us to iterate though
and pin all of maps at the same time.

- Adds new pin(Path)/unpin(Path) api to Maps so they
can be generically pinned AFTER load.

- Adds macro for pinning explicit map types in aya.
Convert all explicit map types "inner" field to be
pub crate in order to facilitate this.

Signed-off-by: astoycos <astoycos@redhat.com>
Add coverage to the new public api's for
map pinning (pin and unpin) which can be called
on the generic aya::Map type OR explit map types.

Additionally add coverage for the new libbpf
LIBBPF_PIN_BY_NAME behavior.

Signed-off-by: astoycos <astoycos@redhat.com>
@astoycos
Copy link
Member Author

Dismissed @alessandrod from 3 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @astoycos)

aya/src/maps/mod.rs line 358 at r10 (raw file):

            {
                    /// Pins the map to a BPF filesystem.

here too

Done!

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 21 of 21 files at r12, all commit messages.
Dismissed @alessandrod from a discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @astoycos)

@astoycos astoycos merged commit ef27bce into aya-rs:main Oct 10, 2023
21 checks passed
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.

None yet

4 participants