From 2aabf58bf5f592cff7e1ce31d21d1b70ab493393 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 20 Jan 2020 11:37:05 +0100 Subject: [PATCH] vmm: Move irq_routes creation to specific MSI use case When KvmInterruptManager initializes a new InterruptSourceGroup, it's only for PCI_MSI_IRQ case that it needs to allocate the GSI and create a new InterruptRoute. That's why this commit moves the general code into the specific use case. Signed-off-by: Sebastien Boeuf --- vmm/src/interrupt.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index 1ee4de91d..9b1951eaf 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -268,20 +268,21 @@ impl InterruptManager for KvmInterruptManager { base: InterruptIndex, count: InterruptIndex, ) -> Result>> { - let mut allocator = self.allocator.lock().unwrap(); - - let mut irq_routes: HashMap = - HashMap::with_capacity(count as usize); - for i in base..base + count { - irq_routes.insert(i, InterruptRoute::new(&mut allocator)?); - } - let interrupt_source_group: Arc> = match interrupt_type { - PCI_MSI_IRQ => Arc::new(Box::new(MsiInterruptGroup::new( - self.vm_fd.clone(), - self.gsi_msi_routes.clone(), - irq_routes, - ))), + PCI_MSI_IRQ => { + let mut allocator = self.allocator.lock().unwrap(); + let mut irq_routes: HashMap = + HashMap::with_capacity(count as usize); + for i in base..base + count { + irq_routes.insert(i, InterruptRoute::new(&mut allocator)?); + } + + Arc::new(Box::new(MsiInterruptGroup::new( + self.vm_fd.clone(), + self.gsi_msi_routes.clone(), + irq_routes, + ))) + } _ => { return Err(io::Error::new( io::ErrorKind::Other,