From 354c2a4b3db069dd0f16138e11059c2912238398 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 27 Apr 2020 13:58:10 +0200 Subject: [PATCH] vm-virtio: vhost-user-net: Expect an identifier upon device creation This identifier is chosen from the DeviceManager so that it will manage all identifiers across the VM, which will ensure uniqueness. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/vhost_user/net.rs | 10 ++++++++-- vmm/src/device_manager.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vm-virtio/src/vhost_user/net.rs b/vm-virtio/src/vhost_user/net.rs index a7d37926c..e84d4664b 100644 --- a/vm-virtio/src/vhost_user/net.rs +++ b/vm-virtio/src/vhost_user/net.rs @@ -37,6 +37,7 @@ struct SlaveReqHandler {} impl VhostUserMasterReqHandler for SlaveReqHandler {} pub struct Net { + id: String, vhost_user_net: Master, kill_evt: Option, pause_evt: Option, @@ -55,7 +56,7 @@ pub struct Net { impl Net { /// Create a new vhost-user-net device /// Create a new vhost-user-net device - pub fn new(mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result { + pub fn new(id: String, mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result { let mut vhost_user_net = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64) .map_err(Error::VhostUserCreateMaster)?; @@ -141,6 +142,7 @@ impl Net { } Ok(Net { + id, vhost_user_net, kill_evt: None, pause_evt: None, @@ -365,6 +367,10 @@ impl VirtioDevice for Net { } virtio_ctrl_q_pausable!(Net); -impl Snapshottable for Net {} +impl Snapshottable for Net { + fn id(&self) -> String { + self.id.clone() + } +} impl Transportable for Net {} impl Migratable for Net {} diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 4ecaec32e..998e0dd19 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1360,7 +1360,7 @@ impl DeviceManager { queue_size: net_cfg.queue_size, }; let vhost_user_net_device = Arc::new(Mutex::new( - vm_virtio::vhost_user::Net::new(net_cfg.mac, vu_cfg) + vm_virtio::vhost_user::Net::new(id, net_cfg.mac, vu_cfg) .map_err(DeviceManagerError::CreateVhostUserNet)?, )); self.add_migratable_device(