aya-obj: rename BtfMapDef to MapDef

This is in preparation of unifying map defs
pull/935/head
Alessandro Decina 7 months ago
parent ac58601fb9
commit e723c84f50

@ -65,7 +65,7 @@ impl TryFrom<u32> for crate::generated::bpf_map_type {
/// BTF definition of a map
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct BtfMapDef {
pub struct MapDef {
pub(crate) map_type: u32,
pub(crate) key_size: u32,
pub(crate) value_size: u32,
@ -73,9 +73,9 @@ pub struct BtfMapDef {
pub(crate) map_flags: u32,
pub(crate) pinning: PinningType,
/// BTF type id of the map key
pub btf_key_type_id: u32,
pub btf_key_type_id: Option<u32>,
/// BTF type id of the map value
pub btf_value_type_id: u32,
pub btf_value_type_id: Option<u32>,
}
/// The pinning type
@ -285,7 +285,7 @@ pub struct LegacyMap {
#[derive(Debug, Clone)]
pub struct BtfMap {
/// The definition of the map
pub def: BtfMapDef,
pub def: MapDef,
pub(crate) section_index: usize,
pub(crate) symbol_index: usize,
pub(crate) data: Vec<u8>,

@ -26,7 +26,7 @@ use crate::{
bpf_insn, bpf_map_info, bpf_map_type::BPF_MAP_TYPE_ARRAY, BPF_CALL, BPF_F_RDONLY_PROG,
BPF_JMP, BPF_K,
},
maps::{bpf_map_def, BtfMap, BtfMapDef, LegacyMap, Map, PinningType, MINIMUM_MAP_SIZE},
maps::{bpf_map_def, BtfMap, LegacyMap, Map, MapDef, PinningType, MINIMUM_MAP_SIZE},
programs::{
CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType, XdpAttachType,
},
@ -1217,7 +1217,7 @@ fn parse_map_def(name: &str, data: &[u8]) -> Result<bpf_map_def, ParseError> {
}
}
fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, BtfMapDef), BtfError> {
fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, MapDef), BtfError> {
let ty = match btf.type_by_id(info.btf_type)? {
BtfType::Var(var) => var,
other => {
@ -1227,7 +1227,7 @@ fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, BtfMapDe
}
};
let map_name = btf.string_at(ty.name_offset)?;
let mut map_def = BtfMapDef::default();
let mut map_def = MapDef::default();
// Safety: union
let root_type = btf.resolve_type(ty.btf_type)?;
@ -1250,7 +1250,7 @@ fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, BtfMapDe
// Safety: union
let t = pty.btf_type;
map_def.key_size = btf.type_size(t)? as u32;
map_def.btf_key_type_id = t;
map_def.btf_key_type_id = Some(t);
} else {
return Err(BtfError::UnexpectedBtfType {
type_id: m.btf_type,
@ -1264,7 +1264,7 @@ fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, BtfMapDe
if let BtfType::Ptr(pty) = btf.type_by_id(m.btf_type)? {
let t = pty.btf_type;
map_def.value_size = btf.type_size(t)? as u32;
map_def.btf_value_type_id = t;
map_def.btf_value_type_id = Some(t);
} else {
return Err(BtfError::UnexpectedBtfType {
type_id: m.btf_type,
@ -1300,15 +1300,15 @@ fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, BtfMapDe
pub fn parse_map_info(info: bpf_map_info, pinned: PinningType) -> Map {
if info.btf_key_type_id != 0 {
Map::Btf(BtfMap {
def: BtfMapDef {
def: MapDef {
map_type: info.type_,
key_size: info.key_size,
value_size: info.value_size,
max_entries: info.max_entries,
map_flags: info.map_flags,
pinning: pinned,
btf_key_type_id: info.btf_key_type_id,
btf_value_type_id: info.btf_value_type_id,
btf_key_type_id: Some(info.btf_key_type_id),
btf_value_type_id: Some(info.btf_value_type_id),
},
section_index: 0,
symbol_index: 0,

@ -75,8 +75,8 @@ pub(crate) fn bpf_create_map(
u.btf_fd = 0;
}
_ => {
u.btf_key_type_id = m.def.btf_key_type_id;
u.btf_value_type_id = m.def.btf_value_type_id;
u.btf_key_type_id = m.def.btf_key_type_id.unwrap_or_default();
u.btf_value_type_id = m.def.btf_value_type_id.unwrap_or_default();
u.btf_fd = btf_fd.map(|fd| fd.as_raw_fd()).unwrap_or_default() as u32;
}
}

Loading…
Cancel
Save