From c31e7470056ddf126583806f926992801e719040 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sat, 27 Jun 2020 16:27:36 +0000 Subject: [PATCH] vmm: interrupt: generify impl InterruptManager for MsiInterruptManager The logic can be shared among hypervisor implementations. The 'static bound is used such that we don't need to deal with extra lifetime parameter everywhere. It should be okay because we know the entry type E doesn't contain any reference. Signed-off-by: Wei Liu --- vmm/src/interrupt.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index a6d09cbe9..960b79c7a 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -103,24 +103,24 @@ impl InterruptRoute { } } -struct RoutingEntry { +pub struct RoutingEntry { route: E, masked: bool, } type KvmRoutingEntry = RoutingEntry; -struct MsiInterruptGroup { +pub struct MsiInterruptGroup { vm_fd: Arc, gsi_msi_routes: Arc>>>, irq_routes: HashMap, } -trait MsiInterruptGroupOps { +pub trait MsiInterruptGroupOps { fn set_gsi_routes(&self) -> Result<()>; } -trait RoutingEntryExt { +pub trait RoutingEntryExt { fn make_entry(gsi: u32, config: &InterruptSourceConfig) -> Result>; } @@ -387,7 +387,12 @@ impl InterruptManager for LegacyUserspaceInterruptManager { } } -impl InterruptManager for KvmMsiInterruptManager { +impl InterruptManager for MsiInterruptManager +where + E: Send + Sync + 'static, + RoutingEntry: RoutingEntryExt, + MsiInterruptGroup: MsiInterruptGroupOps, +{ type GroupConfig = MsiIrqGroupConfig; fn create_group( @@ -401,7 +406,7 @@ impl InterruptManager for KvmMsiInterruptManager { irq_routes.insert(i, InterruptRoute::new(&mut allocator)?); } - Ok(Arc::new(Box::new(KvmMsiInterruptGroup::new( + Ok(Arc::new(Box::new(MsiInterruptGroup::new( self.vm_fd.clone(), self.gsi_msi_routes.clone(), irq_routes,