Skip to content

Commit 1fb9925

Browse files
bchaliosShadowCurse
authored andcommitted
kvm_irq_routing: add FamStruct wrapper
Create the KvmIrqRouting FamStruct wrapper for the kvm_irq_routing type. Also, define the serde implementation of these. Do it for all three supported architectures. Signed-off-by: Babis Chalios <bchalios@amazon.es>
1 parent 1d81ba8 commit 1fb9925

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

kvm-bindings/src/arm64/fam_wrappers.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,37 @@ impl PartialEq for kvm_reg_list {
2929
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
3030
pub type RegList = FamStructWrapper<kvm_reg_list>;
3131

32+
// Implement the FamStruct trait for kvm_irq_routing
33+
generate_fam_struct_impl!(
34+
kvm_irq_routing,
35+
kvm_irq_routing_entry,
36+
entries,
37+
u32,
38+
nr,
39+
1024
40+
);
41+
42+
// Implement the PartialEq trait for kvm_irq_routing.
43+
impl PartialEq for kvm_irq_routing {
44+
fn eq(&self, other: &kvm_irq_routing) -> bool {
45+
// No need to call entries's eq, FamStructWrapper's PartialEq will do it for you
46+
self.nr == other.nr && self.flags == other.flags
47+
}
48+
}
49+
50+
/// Wrapper over the `kvm_irq_routing` structure.
51+
///
52+
/// The `kvm_irq_routing` structure contains a flexible array member. For details check the [KVM
53+
/// API](https://docs.kernel.org/virt/kvm/api.html#kvm-set-gsi-routing) documentation on
54+
/// `kvm_irq_routing`. To provide safe access to the array elements, this type is implemented using
55+
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
56+
pub type KvmIrqRouting = FamStructWrapper<kvm_irq_routing>;
57+
3258
#[cfg(test)]
3359
mod tests {
60+
use super::KvmIrqRouting;
3461
use super::RegList;
62+
use vmm_sys_util::fam::FamStruct;
3563

3664
#[test]
3765
fn test_reg_list_eq() {
@@ -46,4 +74,11 @@ mod tests {
4674
wrapper2.as_mut_slice()[0] = 1;
4775
assert!(wrapper == wrapper2);
4876
}
77+
#[test]
78+
fn test_kvm_irq_routing() {
79+
let wrapper = KvmIrqRouting::new(1).unwrap();
80+
assert_eq!(wrapper.as_slice().len(), 1);
81+
assert_eq!(wrapper.as_fam_struct_ref().len(), 1);
82+
assert_eq!(wrapper.as_fam_struct_ref().nr, 1);
83+
}
4984
}

kvm-bindings/src/riscv64/fam_wrappers.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,37 @@ impl PartialEq for kvm_reg_list {
2929
/// implemented using [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
3030
pub type RegList = FamStructWrapper<kvm_reg_list>;
3131

32+
// Implement the FamStruct trait for kvm_irq_routing
33+
generate_fam_struct_impl!(
34+
kvm_irq_routing,
35+
kvm_irq_routing_entry,
36+
entries,
37+
u32,
38+
nr,
39+
1024
40+
);
41+
42+
// Implement the PartialEq trait for kvm_irq_routing.
43+
impl PartialEq for kvm_irq_routing {
44+
fn eq(&self, other: &kvm_irq_routing) -> bool {
45+
// No need to call entries's eq, FamStructWrapper's PartialEq will do it for you
46+
self.nr == other.nr && self.flags == other.flags
47+
}
48+
}
49+
50+
/// Wrapper over the `kvm_irq_routing` structure.
51+
///
52+
/// The `kvm_irq_routing` structure contains a flexible array member. For details check the [KVM
53+
/// API](https://docs.kernel.org/virt/kvm/api.html#kvm-set-gsi-routing) documentation on
54+
/// `kvm_irq_routing`. To provide safe access to the array elements, this type is implemented using
55+
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
56+
pub type KvmIrqRouting = FamStructWrapper<kvm_irq_routing>;
57+
3258
#[cfg(test)]
3359
mod tests {
60+
use super::KvmIrqRouting;
3461
use super::RegList;
62+
use vmm_sys_util::fam::FamStruct;
3563

3664
#[test]
3765
fn test_reg_list_eq() {
@@ -46,4 +74,11 @@ mod tests {
4674
wrapper2.as_mut_slice()[0] = 1;
4775
assert!(wrapper == wrapper2);
4876
}
77+
#[test]
78+
fn test_kvm_irq_routing() {
79+
let wrapper = KvmIrqRouting::new(1).unwrap();
80+
assert_eq!(wrapper.as_slice().len(), 1);
81+
assert_eq!(wrapper.as_fam_struct_ref().len(), 1);
82+
assert_eq!(wrapper.as_fam_struct_ref().nr, 1);
83+
}
4984
}

kvm-bindings/src/x86_64/fam_wrappers.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ impl PartialEq for kvm_msrs {
7474
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
7575
pub type Msrs = FamStructWrapper<kvm_msrs>;
7676

77+
// Implement the FamStruct trait for kvm_irq_routing
78+
generate_fam_struct_impl!(
79+
kvm_irq_routing,
80+
kvm_irq_routing_entry,
81+
entries,
82+
u32,
83+
nr,
84+
1024
85+
);
86+
87+
// Implement the PartialEq trait for kvm_irq_routing.
88+
impl PartialEq for kvm_irq_routing {
89+
fn eq(&self, other: &kvm_irq_routing) -> bool {
90+
// No need to call entries's eq, FamStructWrapper's PartialEq will do it for you
91+
self.nr == other.nr && self.flags == other.flags
92+
}
93+
}
94+
95+
/// Wrapper over the `kvm_irq_routing` structure.
96+
///
97+
/// The `kvm_irq_routing` structure contains a flexible array member. For details check the [KVM
98+
/// API](https://docs.kernel.org/virt/kvm/api.html#kvm-set-gsi-routing) documentation on
99+
/// `kvm_irq_routing`. To provide safe access to the array elements, this type is implemented using
100+
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
101+
pub type KvmIrqRouting = FamStructWrapper<kvm_irq_routing>;
102+
77103
// Implement the FamStruct trait for kvm_msr_list.
78104
generate_fam_struct_impl!(kvm_msr_list, u32, indices, u32, nmsrs, KVM_MAX_MSR_ENTRIES);
79105

@@ -173,6 +199,8 @@ pub type Xsave = FamStructWrapper<kvm_xsave2>;
173199

174200
#[cfg(test)]
175201
mod tests {
202+
use crate::KvmIrqRouting;
203+
176204
use super::{CpuId, MsrList, Msrs, Xsave};
177205
use x86_64::bindings::kvm_cpuid_entry2;
178206

@@ -237,4 +265,11 @@ mod tests {
237265
assert_eq!(wrapper.as_fam_struct_ref().len(), 1);
238266
assert_eq!(wrapper.as_fam_struct_ref().len, 1);
239267
}
268+
#[test]
269+
fn test_kvm_irq_routing() {
270+
let wrapper = KvmIrqRouting::new(1).unwrap();
271+
assert_eq!(wrapper.as_slice().len(), 1);
272+
assert_eq!(wrapper.as_fam_struct_ref().len(), 1);
273+
assert_eq!(wrapper.as_fam_struct_ref().nr, 1);
274+
}
240275
}

0 commit comments

Comments
 (0)