diff --git a/Cargo.lock b/Cargo.lock index cada45fea..2a1e45712 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1398,6 +1398,7 @@ dependencies = [ "versionize", "versionize_derive", "vfio-ioctls", + "vfio_user", "vhdx", "virtio-devices", "vm-allocator", diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index c90856530..404f8ba19 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -11,7 +11,6 @@ use crate::{ use hypervisor::HypervisorVmError; use std::any::Any; use std::os::unix::prelude::AsRawFd; -use std::path::Path; use std::ptr::null_mut; use std::sync::{Arc, Barrier, Mutex}; use std::u32; @@ -61,12 +60,10 @@ impl PciSubclass for PciVfioUserSubclass { impl VfioUserPciDevice { pub fn new( vm: &Arc, - path: &Path, + client: Arc>, msi_interrupt_manager: &Arc>, legacy_interrupt_group: Option>, ) -> Result { - let mut client = Client::new(path).map_err(VfioUserPciDeviceError::Client)?; - // This is used for the BAR and capabilities only let configuration = PciConfiguration::new( 0, @@ -80,12 +77,15 @@ impl VfioUserPciDevice { 0, None, ); - if client.resettable() { - client.reset().map_err(VfioUserPciDeviceError::Client)?; + let resettable = client.lock().unwrap().resettable(); + if resettable { + client + .lock() + .unwrap() + .reset() + .map_err(VfioUserPciDeviceError::Client)?; } - let client = Arc::new(Mutex::new(client)); - let vfio_wrapper = VfioUserClientWrapper { client: client.clone(), }; diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index be13b1021..e3760478c 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -45,6 +45,7 @@ uuid = "0.8.2" versionize = "0.1.6" versionize_derive = "0.1.4" vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "main", default-features = false } +vfio_user = { path = "../vfio_user" } vhdx = { path = "../vhdx" } virtio-devices = { path = "../virtio-devices" } vm-allocator = { path = "../vm-allocator" } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 6ce5fb23c..22241445e 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -442,6 +442,9 @@ pub enum DeviceManagerError { /// Failed removing DMA mapping handler from virtio-mem device. RemoveDmaMappingHandlerVirtioMem(virtio_devices::mem::Error), + /// Failed to create vfio-user client + VfioUserCreateClient(vfio_user::Error), + /// Failed to create VFIO user device VfioUserCreate(VfioUserPciDeviceError), @@ -3105,9 +3108,14 @@ impl DeviceManager { None }; + let client = Arc::new(Mutex::new( + vfio_user::Client::new(&device_cfg.socket) + .map_err(DeviceManagerError::VfioUserCreateClient)?, + )); + let mut vfio_user_pci_device = VfioUserPciDevice::new( &self.address_manager.vm, - &device_cfg.socket, + client, &self.msi_interrupt_manager, legacy_interrupt_group, )