From 820140930a5ccbd59d9bfeb9e310d4ef5ae49141 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Mon, 16 Mar 2026 17:55:52 +0000 Subject: [PATCH] vmm: interrupt: Reduce visibility of internal types and methods Signed-off-by: Bo Chen --- vmm/src/interrupt.rs | 58 ++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index 0995d8356..80ddd46ae 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -17,7 +17,7 @@ use vm_device::interrupt::{ use vmm_sys_util::eventfd::EventFd; /// Reuse std::io::Result to simplify interoperability among crates. -pub type Result = std::io::Result; +type Result = std::io::Result; struct InterruptRoute { gsi: u32, @@ -26,11 +26,11 @@ struct InterruptRoute { } impl InterruptRoute { - pub fn new(allocator: &mut SystemAllocator) -> Result { + fn new(allocator: &mut SystemAllocator) -> Result { Self::new_with_fd(allocator, Some(EventFd::new(libc::EFD_NONBLOCK)?)) } - pub fn new_with_fd(allocator: &mut SystemAllocator, irq_fd: Option) -> Result { + fn new_with_fd(allocator: &mut SystemAllocator, irq_fd: Option) -> Result { let gsi = allocator .allocate_gsi() .ok_or_else(|| io::Error::other("Failed allocating new GSI"))?; @@ -42,7 +42,7 @@ impl InterruptRoute { }) } - pub fn enable(&mut self, vm: &dyn hypervisor::Vm) -> Result<()> { + fn enable(&mut self, vm: &dyn hypervisor::Vm) -> Result<()> { if !self.registered { if let Some(ref irq_fd) = self.irq_fd { vm.register_irqfd(irq_fd, self.gsi) @@ -56,7 +56,7 @@ impl InterruptRoute { Ok(()) } - pub fn disable(&mut self, vm: &dyn hypervisor::Vm) -> Result<()> { + fn disable(&mut self, vm: &dyn hypervisor::Vm) -> Result<()> { if self.registered { if let Some(ref irq_fd) = self.irq_fd { vm.unregister_irqfd(irq_fd, self.gsi) @@ -70,14 +70,14 @@ impl InterruptRoute { Ok(()) } - pub fn trigger(&mut self) -> Result<()> { + fn trigger(&mut self) -> Result<()> { match self.irq_fd { Some(ref fd) => fd.write(1), None => Ok(()), } } - pub fn notifier(&mut self) -> Option { + fn notifier(&mut self) -> Option { Some( self.irq_fd .as_ref()? @@ -90,11 +90,7 @@ impl InterruptRoute { // will use it. Use #[allow(dead_code)] to suppress a compiler // warning. #[allow(dead_code)] - pub fn set_notifier( - &mut self, - eventfd: Option, - vm: &dyn hypervisor::Vm, - ) -> Result<()> { + fn set_notifier(&mut self, eventfd: Option, vm: &dyn hypervisor::Vm) -> Result<()> { let old_irqfd = core::mem::replace(&mut self.irq_fd, eventfd); if self.registered { if let Some(ref irq_fd) = self.irq_fd { @@ -114,34 +110,17 @@ impl InterruptRoute { } } -pub struct RoutingEntry { +struct RoutingEntry { route: IrqRoutingEntry, masked: bool, } -pub struct MsiInterruptGroup { +struct MsiInterruptGroup { vm: Arc, gsi_msi_routes: Arc>>, irq_routes: HashMap>, } -impl MsiInterruptGroup { - fn set_gsi_routes(&self, routes: &HashMap) -> Result<()> { - let mut entry_vec: Vec = Vec::new(); - for (_, entry) in routes.iter() { - if entry.masked { - continue; - } - - entry_vec.push(entry.route); - } - - self.vm - .set_gsi_routing(&entry_vec) - .map_err(|e| io::Error::other(format!("Failed setting GSI routing: {e}"))) - } -} - impl MsiInterruptGroup { fn new( vm: Arc, @@ -154,6 +133,21 @@ impl MsiInterruptGroup { irq_routes, } } + + fn set_gsi_routes(&self, routes: &HashMap) -> Result<()> { + let mut entry_vec: Vec = Vec::new(); + for (_, entry) in routes.iter() { + if entry.masked { + continue; + } + + entry_vec.push(entry.route); + } + + self.vm + .set_gsi_routing(&entry_vec) + .map_err(|e| io::Error::other(format!("Failed setting GSI routing: {e}"))) + } } impl InterruptSourceGroup for MsiInterruptGroup { @@ -253,7 +247,7 @@ impl InterruptSourceGroup for MsiInterruptGroup { } } -pub struct LegacyUserspaceInterruptGroup { +struct LegacyUserspaceInterruptGroup { ioapic: Arc>, irq: u32, }