aya icon indicating copy to clipboard operation
aya copied to clipboard

Implement HashOfMaps and ArrayOfMaps

Open dave-tucker opened this issue 4 years ago • 17 comments

This PR adds user and kernel space implementations of HashOfMaps and ArrayOfMaps.


This change is Reviewable

dave-tucker avatar Oct 18 '21 14:10 dave-tucker

Thanks for taking this up!

I only skimmed through the changes. The user space side looks ok, the ebpf side I think should probably be a bit different. Right now maps of maps return an integer from get() (which is presumably a map id). I think they should return typed maps, eg:

#[map]
static mut OUTER: ArrayOfMaps<HashMap<X, Y>> = ...

fn some_probe(...) -> Result {
    let inner_map: HashMap<X, Y> = unsafe { OUTER.get(0).ok_or(())? };
    inner_map.insert(x_value, y_value);
    ...
}

This will also require adding some kind of from_id(u32) method to all maps, and we'll have to refactor maps to remove the assumption that we always have a bpf_map_def in self.def.

alessandrod avatar Oct 21 '21 20:10 alessandrod

This is of interest to us!

jeromegn avatar Jan 11 '22 12:01 jeromegn

@jeromegn awesome! i'll get back to this after #127... and probably after #151 since may as well handle internal changes to fetching internal maps/programs by id together...

@alessandrod I haven't looked into the kernel side yet, but are all maps in the array/hashmap constrained to being of the same type? if not, it won't be possible to return a strongly typed wrapper....

dave-tucker avatar Jan 11 '22 14:01 dave-tucker

@dave-tucker Any interest in continuing on this? We actually need it and are happy to contribute.

I haven't looked into the kernel side yet, but are all maps in the array/hashmap constrained to being of the same type? if not, it won't be possible to return a strongly typed wrapper....

If I'm not mistaken, all the values are the same for the map of maps. They're refs u32.

kakkoyun avatar Aug 10 '22 14:08 kakkoyun

I'd like to take a stab at getting this up to day/ finishing if need be! WDYT @dave-tucker?

astoycos avatar Dec 19 '22 19:12 astoycos

@dave-tucker, this pull request is now in conflict and requires a rebase.

mergify[bot] avatar Sep 14 '23 23:09 mergify[bot]

@dave-tucker, this pull request is now in conflict and requires a rebase.

mergify[bot] avatar Feb 06 '24 12:02 mergify[bot]

Our project could use this feature. Any updates? Glad to lend a hand in finishing this up if needed.

kckeiks avatar Feb 29 '24 19:02 kckeiks

Our project could use this feature. Any updates? Glad to lend a hand in finishing this up if needed.

I've needed this too recently so I'd like to get it landed. We've changed the implementation of maps so the code in this PR needs to be updated. Getting it to compile/work would be a good first step I guess?

alessandrod avatar Mar 02 '24 21:03 alessandrod