mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: device_manager: Refactor make_virtio_net_devices
Split it into a method that creates a single device which is called by the multiple device version so this can be used when dynamically adding a device. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
committed by
Sebastien Boeuf
parent
9df601a1df
commit
42a9896fe4
+21
-15
@@ -1209,12 +1209,10 @@ impl DeviceManager {
|
|||||||
Ok(sock)
|
Ok(sock)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add virto-net and vhost-user-net devices
|
fn make_virtio_net_device(
|
||||||
fn make_virtio_net_devices(&mut self) -> DeviceManagerResult<Vec<(VirtioDeviceArc, bool)>> {
|
&mut self,
|
||||||
let mut devices = Vec::new();
|
net_cfg: &NetConfig,
|
||||||
let net_devices = self.config.lock().unwrap().net.clone();
|
) -> DeviceManagerResult<(VirtioDeviceArc, bool)> {
|
||||||
if let Some(net_list_cfg) = &net_devices {
|
|
||||||
for net_cfg in net_list_cfg.iter() {
|
|
||||||
if net_cfg.vhost_user {
|
if net_cfg.vhost_user {
|
||||||
let sock = if let Some(sock) = net_cfg.vhost_socket.clone() {
|
let sock = if let Some(sock) = net_cfg.vhost_socket.clone() {
|
||||||
sock
|
sock
|
||||||
@@ -1230,13 +1228,12 @@ impl DeviceManager {
|
|||||||
vm_virtio::vhost_user::Net::new(net_cfg.mac, vu_cfg)
|
vm_virtio::vhost_user::Net::new(net_cfg.mac, vu_cfg)
|
||||||
.map_err(DeviceManagerError::CreateVhostUserNet)?,
|
.map_err(DeviceManagerError::CreateVhostUserNet)?,
|
||||||
));
|
));
|
||||||
devices.push((
|
|
||||||
Arc::clone(&vhost_user_net_device)
|
|
||||||
as Arc<Mutex<dyn vm_virtio::VirtioDevice>>,
|
|
||||||
net_cfg.iommu,
|
|
||||||
));
|
|
||||||
self.migratable_devices
|
self.migratable_devices
|
||||||
.push(Arc::clone(&vhost_user_net_device) as Arc<Mutex<dyn Migratable>>);
|
.push(Arc::clone(&vhost_user_net_device) as Arc<Mutex<dyn Migratable>>);
|
||||||
|
Ok((
|
||||||
|
Arc::clone(&vhost_user_net_device) as Arc<Mutex<dyn vm_virtio::VirtioDevice>>,
|
||||||
|
net_cfg.iommu,
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
let virtio_net_device = if let Some(ref tap_if_name) = net_cfg.tap {
|
let virtio_net_device = if let Some(ref tap_if_name) = net_cfg.tap {
|
||||||
Arc::new(Mutex::new(
|
Arc::new(Mutex::new(
|
||||||
@@ -1265,14 +1262,23 @@ impl DeviceManager {
|
|||||||
.map_err(DeviceManagerError::CreateVirtioNet)?,
|
.map_err(DeviceManagerError::CreateVirtioNet)?,
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
devices.push((
|
|
||||||
Arc::clone(&virtio_net_device) as Arc<Mutex<dyn vm_virtio::VirtioDevice>>,
|
|
||||||
net_cfg.iommu,
|
|
||||||
));
|
|
||||||
self.migratable_devices
|
self.migratable_devices
|
||||||
.push(Arc::clone(&virtio_net_device) as Arc<Mutex<dyn Migratable>>);
|
.push(Arc::clone(&virtio_net_device) as Arc<Mutex<dyn Migratable>>);
|
||||||
|
Ok((
|
||||||
|
Arc::clone(&virtio_net_device) as Arc<Mutex<dyn vm_virtio::VirtioDevice>>,
|
||||||
|
net_cfg.iommu,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add virto-net and vhost-user-net devices
|
||||||
|
fn make_virtio_net_devices(&mut self) -> DeviceManagerResult<Vec<(VirtioDeviceArc, bool)>> {
|
||||||
|
let mut devices = Vec::new();
|
||||||
|
let net_devices = self.config.lock().unwrap().net.clone();
|
||||||
|
if let Some(net_list_cfg) = &net_devices {
|
||||||
|
for net_cfg in net_list_cfg.iter() {
|
||||||
|
devices.push(self.make_virtio_net_device(net_cfg)?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(devices)
|
Ok(devices)
|
||||||
|
|||||||
Reference in New Issue
Block a user