mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 19:35:21 +00:00
vmm: Factorize net creation
Since both Net and vhost_user::Net implement the Migratable trait, we can factorize the common part to simplify the code related to the net creation. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
425902b296
commit
058a61148c
@ -2211,7 +2211,7 @@ impl DeviceManager {
|
|||||||
};
|
};
|
||||||
info!("Creating virtio-net device: {:?}", net_cfg);
|
info!("Creating virtio-net device: {:?}", net_cfg);
|
||||||
|
|
||||||
if net_cfg.vhost_user {
|
let (virtio_device, migratable_device) = if net_cfg.vhost_user {
|
||||||
let socket = net_cfg.vhost_socket.as_ref().unwrap().clone();
|
let socket = net_cfg.vhost_socket.as_ref().unwrap().clone();
|
||||||
let vu_cfg = VhostUserConfig {
|
let vu_cfg = VhostUserConfig {
|
||||||
socket,
|
socket,
|
||||||
@ -2222,7 +2222,7 @@ impl DeviceManager {
|
|||||||
VhostMode::Client => false,
|
VhostMode::Client => false,
|
||||||
VhostMode::Server => true,
|
VhostMode::Server => true,
|
||||||
};
|
};
|
||||||
let vhost_user_net_device = Arc::new(Mutex::new(
|
let vhost_user_net = Arc::new(Mutex::new(
|
||||||
match virtio_devices::vhost_user::Net::new(
|
match virtio_devices::vhost_user::Net::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
net_cfg.mac,
|
net_cfg.mac,
|
||||||
@ -2242,24 +2242,12 @@ impl DeviceManager {
|
|||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
// Fill the device tree with a new node. In case of restore, we
|
(
|
||||||
// know there is nothing to do, so we can simply override the
|
Arc::clone(&vhost_user_net) as Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
|
||||||
// existing entry.
|
vhost_user_net as Arc<Mutex<dyn Migratable>>,
|
||||||
self.device_tree
|
)
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.insert(id.clone(), device_node!(id, vhost_user_net_device));
|
|
||||||
|
|
||||||
Ok(MetaVirtioDevice {
|
|
||||||
virtio_device: Arc::clone(&vhost_user_net_device)
|
|
||||||
as Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
|
|
||||||
iommu: net_cfg.iommu,
|
|
||||||
id,
|
|
||||||
pci_segment: net_cfg.pci_segment,
|
|
||||||
dma_handler: None,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
let virtio_net_device = if let Some(ref tap_if_name) = net_cfg.tap {
|
let virtio_net = if let Some(ref tap_if_name) = net_cfg.tap {
|
||||||
Arc::new(Mutex::new(
|
Arc::new(Mutex::new(
|
||||||
virtio_devices::Net::new(
|
virtio_devices::Net::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
@ -2317,23 +2305,27 @@ impl DeviceManager {
|
|||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fill the device tree with a new node. In case of restore, we
|
(
|
||||||
// know there is nothing to do, so we can simply override the
|
Arc::clone(&virtio_net) as Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
|
||||||
// existing entry.
|
virtio_net as Arc<Mutex<dyn Migratable>>,
|
||||||
self.device_tree
|
)
|
||||||
.lock()
|
};
|
||||||
.unwrap()
|
|
||||||
.insert(id.clone(), device_node!(id, virtio_net_device));
|
|
||||||
|
|
||||||
Ok(MetaVirtioDevice {
|
// Fill the device tree with a new node. In case of restore, we
|
||||||
virtio_device: Arc::clone(&virtio_net_device)
|
// know there is nothing to do, so we can simply override the
|
||||||
as Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
|
// existing entry.
|
||||||
iommu: net_cfg.iommu,
|
self.device_tree
|
||||||
id,
|
.lock()
|
||||||
pci_segment: net_cfg.pci_segment,
|
.unwrap()
|
||||||
dma_handler: None,
|
.insert(id.clone(), device_node!(id, migratable_device));
|
||||||
})
|
|
||||||
}
|
Ok(MetaVirtioDevice {
|
||||||
|
virtio_device,
|
||||||
|
iommu: net_cfg.iommu,
|
||||||
|
id,
|
||||||
|
pci_segment: net_cfg.pci_segment,
|
||||||
|
dma_handler: None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add virto-net and vhost-user-net devices
|
/// Add virto-net and vhost-user-net devices
|
||||||
|
Loading…
Reference in New Issue
Block a user