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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-04-27 13:58:10 +02:00 committed by Rob Bradford
parent 46e0b3ff75
commit 354c2a4b3d
2 changed files with 9 additions and 3 deletions

View File

@ -37,6 +37,7 @@ struct SlaveReqHandler {}
impl VhostUserMasterReqHandler for SlaveReqHandler {} impl VhostUserMasterReqHandler for SlaveReqHandler {}
pub struct Net { pub struct Net {
id: String,
vhost_user_net: Master, vhost_user_net: Master,
kill_evt: Option<EventFd>, kill_evt: Option<EventFd>,
pause_evt: Option<EventFd>, pause_evt: Option<EventFd>,
@ -55,7 +56,7 @@ pub struct Net {
impl Net { impl Net {
/// Create a new vhost-user-net device /// Create a new vhost-user-net device
/// Create a new vhost-user-net device /// Create a new vhost-user-net device
pub fn new(mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result<Net> { pub fn new(id: String, mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result<Net> {
let mut vhost_user_net = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64) let mut vhost_user_net = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64)
.map_err(Error::VhostUserCreateMaster)?; .map_err(Error::VhostUserCreateMaster)?;
@ -141,6 +142,7 @@ impl Net {
} }
Ok(Net { Ok(Net {
id,
vhost_user_net, vhost_user_net,
kill_evt: None, kill_evt: None,
pause_evt: None, pause_evt: None,
@ -365,6 +367,10 @@ impl VirtioDevice for Net {
} }
virtio_ctrl_q_pausable!(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 Transportable for Net {}
impl Migratable for Net {} impl Migratable for Net {}

View File

@ -1360,7 +1360,7 @@ impl DeviceManager {
queue_size: net_cfg.queue_size, queue_size: net_cfg.queue_size,
}; };
let vhost_user_net_device = Arc::new(Mutex::new( 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)?, .map_err(DeviceManagerError::CreateVhostUserNet)?,
)); ));
self.add_migratable_device( self.add_migratable_device(