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

Allow maps to be created from user-space #46

Open
dave-tucker opened this issue Aug 6, 2021 · 6 comments
Open

Allow maps to be created from user-space #46

dave-tucker opened this issue Aug 6, 2021 · 6 comments
Milestone

Comments

@dave-tucker
Copy link
Member

dave-tucker commented Aug 6, 2021

It would be nice if maps could be created from user-space before the program is loaded.
This gives more granular control over which maps should (or should not) be pinned than what is available in #45.

As for the API, it's going to be a fairly big change and requires a bit of upfront design.

Typed maps could be able to be instantiated directly, like in the bpf crate, but we'd make the syscalls immediately (or in the case of pinning and the map exists, the use that instead).

let mut my_map  = HashMap<MyPodKey, MyPodValue>::new(255, Some(Path::new("myapp/global")));

The only complication is that created maps need to be available to Bpf::load so we can perform relocations.
In which case we'd need to somehow register created maps with the Bpf struct and make ensure that all load functions have a reference to &self

@dave-tucker dave-tucker added this to the Aya 1.0 milestone Jan 31, 2022
@loheagn
Copy link

loheagn commented Nov 14, 2023

Hi, is this feature ready now? In my usecases, I want to create maps in userspace dynamically. There is a function bcc_create_map in bcc. I wonder how to do this in aya. :)

@astoycos
Copy link
Member

Hiya @loheagn This isn't implemented yet, but I might be able to pick it up here soon! Will post back here with updates.

@loheagn
Copy link

loheagn commented Nov 14, 2023

Hiya @loheagn This isn't implemented yet, but I might be able to pick it up here soon! Will post back here with updates.

@astoycos Thanks! I found the function aya::maps::MapData::create, can I use this function to create maps? Do you have any suggestions?

@astoycos
Copy link
Member

So aya::maps::MapData::create takes

        obj: obj::Map,
        name: &str,
        btf_fd: Option<BorrowedFd<'_>>,

as args meaning the map was defined in bytecode, and I don't think it was designed to be used directly (maybe this function shouldn't actually be public 🤔 ).

The API which @dave-tucker describes above allows direct instantiation of Maps with simple data such as K/V types+size along with pin path etc.

@loheagn
Copy link

loheagn commented Nov 14, 2023

So aya::maps::MapData::create takes

        obj: obj::Map,
        name: &str,
        btf_fd: Option<BorrowedFd<'_>>,

as args meaning the map was defined in bytecode, and I don't think it was designed to be used directly (maybe this function shouldn't actually be public 🤔 ).

The API which @dave-tucker describes above allows direct instantiation of Maps with simple data such as K/V types+size along with pin path etc.

@astoycos I see the differences. Then I may need some workaround. Thanks again!

@astoycos
Copy link
Member

@loheagn PTAL at #837 as it aligns with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants