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

feat: Add set for Array<T> #1005

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

fslongjin
Copy link
Contributor

@fslongjin fslongjin commented Jul 30, 2024

Add set() function for Array<T>


This change is Reviewable

Copy link

netlify bot commented Jul 30, 2024

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3decd82
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/67c616c5fdab580008681e4b
😎 Deploy Preview https://deploy-preview-1005--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 the aya-bpf This is about aya-bpf (kernel) label Jul 30, 2024
@fslongjin
Copy link
Contributor Author

ping

@tamird
Copy link
Member

tamird commented Aug 26, 2024

ping

Needs tests.

@vadorovsky
Copy link
Member

To be precise - a great place to add tests would be https://github.com/aya-rs/aya/blob/main/test/integration-ebpf/src/map_test.rs

A simple set call on any kind of map with some dummy values would be enough 🙂

@fslongjin
Copy link
Contributor Author

Ok, I'll add tests tomorrow

@fslongjin fslongjin force-pushed the patch-aya-ebpf-array-add-set-func branch from 4f0b904 to 5458de0 Compare November 28, 2024 12:07
@mergify mergify bot added the test A PR that improves test cases or CI label Nov 28, 2024
@fslongjin
Copy link
Contributor Author

To be precise - a great place to add tests would be https://github.com/aya-rs/aya/blob/main/test/integration-ebpf/src/map_test.rs

A simple set call on any kind of map with some dummy values would be enough 🙂

I've already added a test and rebased the branch to the latest version. Could you please review it? Thank you!

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 1 of 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 4 unresolved discussions (waiting on @fslongjin)


ebpf/aya-ebpf/src/maps/array.rs line 8 at r1 (raw file):

use crate::{
    bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_ARRAY},
    helpers::bpf_map_lookup_elem,

can you put bpf_map_update_elem here?


ebpf/aya-ebpf/src/maps/array.rs line 78 at r1 (raw file):

    /// Sets the value of the element at the given index.
    pub fn set(&self, index: u32, value: &T, flags: u64) -> Result<(), c_long> {
        insert(self.def.get(), &index, value, flags)

lookup above is unsafe, why is this one safe? why do we need the insert helper?


ebpf/aya-ebpf/src/maps/array.rs line 92 at r1 (raw file):

        )
    };
    (ret == 0).then_some(()).ok_or(ret)

why are we making an option only to turn it into a result?

    match unsafe {
        bpf_map_update_elem(
            def as *mut _,
            key as *const _ as *const _,
            value as *const _ as *const _,
            flags,
        )
    } {
        0 => Ok(())
        ret => Err(ret),
    }

Code quote:

    let ret = unsafe {
        bpf_map_update_elem(
            def as *mut _,
            key as *const _ as *const _,
            value as *const _ as *const _,
            flags,
        )
    };
    (ret == 0).then_some(()).ok_or(ret)

test/integration-test/src/tests/smoke.rs line 74 at r1 (raw file):

#[test]
fn map_set() {

i don't think this is an appropriate place for this test. this file is called "smoke" because it is testing only loading and attaching programs, and what you're doing here is different. please have a look at the other tests that do more sophisticated things.

@tamird
Copy link
Member

tamird commented Mar 3, 2025

@fslongjin are you planning to work on this?

Verified

This commit was signed with the committer’s verified signature.
tamird Tamir Duberstein
These functions (and more) are duplicated all over the place.
@tamird tamird force-pushed the patch-aya-ebpf-array-add-set-func branch 2 times, most recently from 573f590 to 488e5c5 Compare March 3, 2025 20:51
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.

Now that this is basically a 1-liner, I think we can forgo the tests.

Reviewable status: 0 of 12 files reviewed, all discussions resolved


ebpf/aya-ebpf/src/maps/array.rs line 8 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

can you put bpf_map_update_elem here?

Done.

Verified

This commit was signed with the committer’s verified signature.
tamird Tamir Duberstein
Signed-off-by: jinlong <[email protected]>
@tamird tamird force-pushed the patch-aya-ebpf-array-add-set-func branch from 488e5c5 to 3decd82 Compare March 3, 2025 20:53
@tamird tamird requested a review from vadorovsky March 3, 2025 20:54
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 12 files at r2, 2 of 3 files at r3, 2 of 2 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @vadorovsky)

@tamird tamird merged commit 2fb19f3 into aya-rs:main Mar 4, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya-bpf This is about aya-bpf (kernel) needs tests 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