aya/maps: fix libbpf_pin_by_name

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>
reviewable/pr783/r11
astoycos 1 year ago
parent 66bd85a8de
commit 0bf97eba64

@ -492,8 +492,13 @@ impl<'a> BpfLoader<'a> {
let mut map = match obj.pinning() {
PinningType::None => MapData::create(obj, &name, btf_fd)?,
PinningType::ByName => {
let path = map_pin_path.as_ref().ok_or(BpfError::NoPinPath)?;
MapData::create_pinned(path, obj, &name, btf_fd)?
// pin maps in /sys/fs/bpf by default to align with libbpf
// behavior https://github.com/libbpf/libbpf/blob/v1.2.2/src/libbpf.c#L2161.
let path = map_pin_path
.as_deref()
.unwrap_or_else(|| Path::new("/sys/fs/bpf"));
MapData::create_pinned_by_name(path, obj, &name, btf_fd)?
}
};
map.finalize()?;
@ -951,10 +956,6 @@ pub enum BpfError {
error: io::Error,
},
/// Pinning requested but no path provided
#[error("pinning requested but no path provided")]
NoPinPath,
/// Unexpected pinning type
#[error("unexpected pinning type {name}")]
UnexpectedPinningType {

@ -461,7 +461,7 @@ impl MapData {
Ok(Self { obj, fd })
}
pub(crate) fn create_pinned<P: AsRef<Path>>(
pub(crate) fn create_pinned_by_name<P: AsRef<Path>>(
path: P,
obj: obj::Map,
name: &str,
@ -490,7 +490,6 @@ impl MapData {
}
Err(_) => {
let mut map = Self::create(obj, name, btf_fd)?;
let path = path.join(name);
map.pin(&path).map_err(|error| MapError::PinError {
name: Some(name.into()),
error,

Loading…
Cancel
Save