virtio-devices: vhost_user: Make vhost-user handle optional

This anticipates the need for creating a new Blk, Fs or Net object
without having performed the connection with the vhost-user backend yet.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-08-06 17:43:53 +02:00 committed by Bo Chen
parent 06729bb3ba
commit a738808604
3 changed files with 295 additions and 225 deletions

View File

@ -53,7 +53,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {}
pub struct Blk { pub struct Blk {
common: VirtioCommon, common: VirtioCommon,
id: String, id: String,
vu: Arc<Mutex<VhostUserHandle>>, vu: Option<Arc<Mutex<VhostUserHandle>>>,
config: VirtioBlockConfig, config: VirtioBlockConfig,
guest_memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>, guest_memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>,
acked_protocol_features: u64, acked_protocol_features: u64,
@ -140,7 +140,7 @@ impl Blk {
..Default::default() ..Default::default()
}, },
id, id,
vu: Arc::new(Mutex::new(vu)), vu: Some(Arc::new(Mutex::new(vu))),
config, config,
guest_memory: None, guest_memory: None,
acked_protocol_features, acked_protocol_features,
@ -211,15 +211,16 @@ impl VirtioDevice for Blk {
} }
self.config.writeback = data[0]; self.config.writeback = data[0];
if let Err(e) = self if let Some(vu) = &self.vu {
.vu if let Err(e) = vu
.lock() .lock()
.unwrap() .unwrap()
.socket_handle() .socket_handle()
.set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data) .set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data)
.map_err(Error::VhostUserSetConfig) .map_err(Error::VhostUserSetConfig)
{ {
error!("Failed setting vhost-user-blk configuration: {:?}", e); error!("Failed setting vhost-user-blk configuration: {:?}", e);
}
} }
} }
@ -249,8 +250,12 @@ impl VirtioDevice for Blk {
None None
}; };
self.vu if self.vu.is_none() {
.lock() error!("Missing vhost-user handle");
return Err(ActivateError::BadActivate);
}
let vu = self.vu.as_ref().unwrap();
vu.lock()
.unwrap() .unwrap()
.setup_vhost_user( .setup_vhost_user(
&mem.memory(), &mem.memory(),
@ -268,7 +273,7 @@ impl VirtioDevice for Blk {
let (kill_evt, pause_evt) = self.common.dup_eventfds(); let (kill_evt, pause_evt) = self.common.dup_eventfds();
let mut handler: VhostUserEpollHandler<SlaveReqHandler> = VhostUserEpollHandler { let mut handler: VhostUserEpollHandler<SlaveReqHandler> = VhostUserEpollHandler {
vu: self.vu.clone(), vu: vu.clone(),
mem, mem,
kill_evt, kill_evt,
pause_evt, pause_evt,
@ -308,14 +313,15 @@ impl VirtioDevice for Blk {
self.common.resume().ok()?; self.common.resume().ok()?;
} }
if let Err(e) = self if let Some(vu) = &self.vu {
.vu if let Err(e) = vu
.lock() .lock()
.unwrap() .unwrap()
.reset_vhost_user(self.common.queue_sizes.len()) .reset_vhost_user(self.common.queue_sizes.len())
{ {
error!("Failed to reset vhost-user daemon: {:?}", e); error!("Failed to reset vhost-user daemon: {:?}", e);
return None; return None;
}
} }
if let Some(kill_evt) = self.common.kill_evt.take() { if let Some(kill_evt) = self.common.kill_evt.take() {
@ -330,41 +336,46 @@ impl VirtioDevice for Blk {
} }
fn shutdown(&mut self) { fn shutdown(&mut self) {
let _ = unsafe { libc::close(self.vu.lock().unwrap().socket_handle().as_raw_fd()) }; if let Some(vu) = &self.vu {
let _ = unsafe { libc::close(vu.lock().unwrap().socket_handle().as_raw_fd()) };
}
} }
fn add_memory_region( fn add_memory_region(
&mut self, &mut self,
region: &Arc<GuestRegionMmap>, region: &Arc<GuestRegionMmap>,
) -> std::result::Result<(), crate::Error> { ) -> std::result::Result<(), crate::Error> {
if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() != 0 if let Some(vu) = &self.vu {
{ if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits()
self.vu != 0
.lock() {
.unwrap() return vu
.add_memory_region(region) .lock()
.map_err(crate::Error::VhostUserAddMemoryRegion) .unwrap()
} else if let Some(guest_memory) = &self.guest_memory { .add_memory_region(region)
self.vu .map_err(crate::Error::VhostUserAddMemoryRegion);
.lock() } else if let Some(guest_memory) = &self.guest_memory {
.unwrap() return vu
.update_mem_table(guest_memory.memory().deref()) .lock()
.map_err(crate::Error::VhostUserUpdateMemory) .unwrap()
} else { .update_mem_table(guest_memory.memory().deref())
Ok(()) .map_err(crate::Error::VhostUserUpdateMemory);
}
} }
Ok(())
} }
} }
impl Pausable for Blk { impl Pausable for Blk {
fn pause(&mut self) -> result::Result<(), MigratableError> { fn pause(&mut self) -> result::Result<(), MigratableError> {
self.vu if let Some(vu) = &self.vu {
.lock() vu.lock()
.unwrap() .unwrap()
.pause_vhost_user(self.vu_num_queues) .pause_vhost_user(self.vu_num_queues)
.map_err(|e| { .map_err(|e| {
MigratableError::Pause(anyhow!("Error pausing vhost-user-blk backend: {:?}", e)) MigratableError::Pause(anyhow!("Error pausing vhost-user-blk backend: {:?}", e))
})?; })?;
}
self.common.pause() self.common.pause()
} }
@ -376,13 +387,19 @@ impl Pausable for Blk {
epoll_thread.thread().unpark(); epoll_thread.thread().unpark();
} }
self.vu if let Some(vu) = &self.vu {
.lock() vu.lock()
.unwrap() .unwrap()
.resume_vhost_user(self.vu_num_queues) .resume_vhost_user(self.vu_num_queues)
.map_err(|e| { .map_err(|e| {
MigratableError::Resume(anyhow!("Error resuming vhost-user-blk backend: {:?}", e)) MigratableError::Resume(anyhow!(
}) "Error resuming vhost-user-blk backend: {:?}",
e
))
})
} else {
Ok(())
}
} }
} }
@ -404,49 +421,56 @@ impl Transportable for Blk {}
impl Migratable for Blk { impl Migratable for Blk {
fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
if let Some(guest_memory) = &self.guest_memory { if let Some(vu) = &self.vu {
let last_ram_addr = guest_memory.memory().last_addr().raw_value(); if let Some(guest_memory) = &self.guest_memory {
self.vu let last_ram_addr = guest_memory.memory().last_addr().raw_value();
.lock() vu.lock()
.unwrap() .unwrap()
.start_dirty_log(last_ram_addr) .start_dirty_log(last_ram_addr)
.map_err(|e| { .map_err(|e| {
MigratableError::StartDirtyLog(anyhow!( MigratableError::StartDirtyLog(anyhow!(
"Error starting migration for vhost-user-blk backend: {:?}", "Error starting migration for vhost-user-blk backend: {:?}",
e e
)) ))
}) })
} else {
Err(MigratableError::StartDirtyLog(anyhow!(
"Missing guest memory"
)))
}
} else { } else {
Err(MigratableError::StartDirtyLog(anyhow!( Ok(())
"Missing guest memory"
)))
} }
} }
fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
self.vu.lock().unwrap().stop_dirty_log().map_err(|e| { if let Some(vu) = &self.vu {
MigratableError::StopDirtyLog(anyhow!( vu.lock().unwrap().stop_dirty_log().map_err(|e| {
"Error stopping migration for vhost-user-blk backend: {:?}", MigratableError::StopDirtyLog(anyhow!(
e "Error stopping migration for vhost-user-blk backend: {:?}",
)) e
}) ))
})
} else {
Ok(())
}
} }
fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> { fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> {
if let Some(guest_memory) = &self.guest_memory { if let Some(vu) = &self.vu {
let last_ram_addr = guest_memory.memory().last_addr().raw_value(); if let Some(guest_memory) = &self.guest_memory {
self.vu let last_ram_addr = guest_memory.memory().last_addr().raw_value();
.lock() vu.lock().unwrap().dirty_log(last_ram_addr).map_err(|e| {
.unwrap()
.dirty_log(last_ram_addr)
.map_err(|e| {
MigratableError::DirtyLog(anyhow!( MigratableError::DirtyLog(anyhow!(
"Error retrieving dirty ranges from vhost-user-blk backend: {:?}", "Error retrieving dirty ranges from vhost-user-blk backend: {:?}",
e e
)) ))
}) })
} else {
Err(MigratableError::DirtyLog(anyhow!("Missing guest memory")))
}
} else { } else {
Err(MigratableError::DirtyLog(anyhow!("Missing guest memory"))) Ok(MemoryRangeTable::default())
} }
} }
} }

View File

@ -298,7 +298,7 @@ unsafe impl ByteValued for VirtioFsConfig {}
pub struct Fs { pub struct Fs {
common: VirtioCommon, common: VirtioCommon,
id: String, id: String,
vu: Arc<Mutex<VhostUserHandle>>, vu: Option<Arc<Mutex<VhostUserHandle>>>,
config: VirtioFsConfig, config: VirtioFsConfig,
// Hold ownership of the memory that is allocated for the device // Hold ownership of the memory that is allocated for the device
// which will be automatically dropped when the device is dropped // which will be automatically dropped when the device is dropped
@ -388,7 +388,7 @@ impl Fs {
..Default::default() ..Default::default()
}, },
id, id,
vu: Arc::new(Mutex::new(vu)), vu: Some(Arc::new(Mutex::new(vu))),
config, config,
cache, cache,
slave_req_support, slave_req_support,
@ -493,8 +493,12 @@ impl VirtioDevice for Fs {
None None
}; };
self.vu if self.vu.is_none() {
.lock() error!("Missing vhost-user handle");
return Err(ActivateError::BadActivate);
}
let vu = self.vu.as_ref().unwrap();
vu.lock()
.unwrap() .unwrap()
.setup_vhost_user( .setup_vhost_user(
&mem.memory(), &mem.memory(),
@ -511,7 +515,7 @@ impl VirtioDevice for Fs {
// the backend as well as requests initiated by the backend. // the backend as well as requests initiated by the backend.
let (kill_evt, pause_evt) = self.common.dup_eventfds(); let (kill_evt, pause_evt) = self.common.dup_eventfds();
let mut handler: VhostUserEpollHandler<SlaveReqHandler> = VhostUserEpollHandler { let mut handler: VhostUserEpollHandler<SlaveReqHandler> = VhostUserEpollHandler {
vu: self.vu.clone(), vu: vu.clone(),
mem, mem,
kill_evt, kill_evt,
pause_evt, pause_evt,
@ -558,14 +562,15 @@ impl VirtioDevice for Fs {
self.common.resume().ok()?; self.common.resume().ok()?;
} }
if let Err(e) = self if let Some(vu) = &self.vu {
.vu if let Err(e) = vu
.lock() .lock()
.unwrap() .unwrap()
.reset_vhost_user(self.common.queue_sizes.len()) .reset_vhost_user(self.common.queue_sizes.len())
{ {
error!("Failed to reset vhost-user daemon: {:?}", e); error!("Failed to reset vhost-user daemon: {:?}", e);
return None; return None;
}
} }
if let Some(kill_evt) = self.common.kill_evt.take() { if let Some(kill_evt) = self.common.kill_evt.take() {
@ -580,7 +585,9 @@ impl VirtioDevice for Fs {
} }
fn shutdown(&mut self) { fn shutdown(&mut self) {
let _ = unsafe { libc::close(self.vu.lock().unwrap().socket_handle().as_raw_fd()) }; if let Some(vu) = &self.vu {
let _ = unsafe { libc::close(vu.lock().unwrap().socket_handle().as_raw_fd()) };
}
} }
fn get_shm_regions(&self) -> Option<VirtioSharedMemoryList> { fn get_shm_regions(&self) -> Option<VirtioSharedMemoryList> {
@ -603,22 +610,24 @@ impl VirtioDevice for Fs {
&mut self, &mut self,
region: &Arc<GuestRegionMmap>, region: &Arc<GuestRegionMmap>,
) -> std::result::Result<(), crate::Error> { ) -> std::result::Result<(), crate::Error> {
if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() != 0 if let Some(vu) = &self.vu {
{ if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits()
self.vu != 0
.lock() {
.unwrap() return vu
.add_memory_region(region) .lock()
.map_err(crate::Error::VhostUserAddMemoryRegion) .unwrap()
} else if let Some(guest_memory) = &self.guest_memory { .add_memory_region(region)
self.vu .map_err(crate::Error::VhostUserAddMemoryRegion);
.lock() } else if let Some(guest_memory) = &self.guest_memory {
.unwrap() return vu
.update_mem_table(guest_memory.memory().deref()) .lock()
.map_err(crate::Error::VhostUserUpdateMemory) .unwrap()
} else { .update_mem_table(guest_memory.memory().deref())
Ok(()) .map_err(crate::Error::VhostUserUpdateMemory);
}
} }
Ok(())
} }
fn userspace_mappings(&self) -> Vec<UserspaceMapping> { fn userspace_mappings(&self) -> Vec<UserspaceMapping> {
@ -639,13 +648,14 @@ impl VirtioDevice for Fs {
impl Pausable for Fs { impl Pausable for Fs {
fn pause(&mut self) -> result::Result<(), MigratableError> { fn pause(&mut self) -> result::Result<(), MigratableError> {
self.vu if let Some(vu) = &self.vu {
.lock() vu.lock()
.unwrap() .unwrap()
.pause_vhost_user(self.vu_num_queues) .pause_vhost_user(self.vu_num_queues)
.map_err(|e| { .map_err(|e| {
MigratableError::Pause(anyhow!("Error pausing vhost-user-fs backend: {:?}", e)) MigratableError::Pause(anyhow!("Error pausing vhost-user-fs backend: {:?}", e))
})?; })?;
}
self.common.pause() self.common.pause()
} }
@ -657,13 +667,19 @@ impl Pausable for Fs {
epoll_thread.thread().unpark(); epoll_thread.thread().unpark();
} }
self.vu if let Some(vu) = &self.vu {
.lock() vu.lock()
.unwrap() .unwrap()
.resume_vhost_user(self.vu_num_queues) .resume_vhost_user(self.vu_num_queues)
.map_err(|e| { .map_err(|e| {
MigratableError::Resume(anyhow!("Error resuming vhost-user-fs backend: {:?}", e)) MigratableError::Resume(anyhow!(
}) "Error resuming vhost-user-fs backend: {:?}",
e
))
})
} else {
Ok(())
}
} }
} }
@ -685,49 +701,56 @@ impl Transportable for Fs {}
impl Migratable for Fs { impl Migratable for Fs {
fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
if let Some(guest_memory) = &self.guest_memory { if let Some(vu) = &self.vu {
let last_ram_addr = guest_memory.memory().last_addr().raw_value(); if let Some(guest_memory) = &self.guest_memory {
self.vu let last_ram_addr = guest_memory.memory().last_addr().raw_value();
.lock() vu.lock()
.unwrap() .unwrap()
.start_dirty_log(last_ram_addr) .start_dirty_log(last_ram_addr)
.map_err(|e| { .map_err(|e| {
MigratableError::StartDirtyLog(anyhow!( MigratableError::StartDirtyLog(anyhow!(
"Error starting migration for vhost-user-fs backend: {:?}", "Error starting migration for vhost-user-fs backend: {:?}",
e e
)) ))
}) })
} else {
Err(MigratableError::StartDirtyLog(anyhow!(
"Missing guest memory"
)))
}
} else { } else {
Err(MigratableError::StartDirtyLog(anyhow!( Ok(())
"Missing guest memory"
)))
} }
} }
fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
self.vu.lock().unwrap().stop_dirty_log().map_err(|e| { if let Some(vu) = &self.vu {
MigratableError::StopDirtyLog(anyhow!( vu.lock().unwrap().stop_dirty_log().map_err(|e| {
"Error stopping migration for vhost-user-fs backend: {:?}", MigratableError::StopDirtyLog(anyhow!(
e "Error stopping migration for vhost-user-fs backend: {:?}",
)) e
}) ))
})
} else {
Ok(())
}
} }
fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> { fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> {
if let Some(guest_memory) = &self.guest_memory { if let Some(vu) = &self.vu {
let last_ram_addr = guest_memory.memory().last_addr().raw_value(); if let Some(guest_memory) = &self.guest_memory {
self.vu let last_ram_addr = guest_memory.memory().last_addr().raw_value();
.lock() vu.lock().unwrap().dirty_log(last_ram_addr).map_err(|e| {
.unwrap()
.dirty_log(last_ram_addr)
.map_err(|e| {
MigratableError::DirtyLog(anyhow!( MigratableError::DirtyLog(anyhow!(
"Error retrieving dirty ranges from vhost-user-fs backend: {:?}", "Error retrieving dirty ranges from vhost-user-fs backend: {:?}",
e e
)) ))
}) })
} else {
Err(MigratableError::DirtyLog(anyhow!("Missing guest memory")))
}
} else { } else {
Err(MigratableError::DirtyLog(anyhow!("Missing guest memory"))) Ok(MemoryRangeTable::default())
} }
} }
} }

View File

@ -106,7 +106,7 @@ impl EpollHelperHandler for NetCtrlEpollHandler {
pub struct Net { pub struct Net {
common: VirtioCommon, common: VirtioCommon,
id: String, id: String,
vu: Arc<Mutex<VhostUserHandle>>, vu: Option<Arc<Mutex<VhostUserHandle>>>,
config: VirtioNetConfig, config: VirtioNetConfig,
guest_memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>, guest_memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>,
acked_protocol_features: u64, acked_protocol_features: u64,
@ -198,7 +198,7 @@ impl Net {
min_queues: DEFAULT_QUEUE_NUMBER as u16, min_queues: DEFAULT_QUEUE_NUMBER as u16,
..Default::default() ..Default::default()
}, },
vu: Arc::new(Mutex::new(vu)), vu: Some(Arc::new(Mutex::new(vu))),
config, config,
guest_memory: None, guest_memory: None,
acked_protocol_features, acked_protocol_features,
@ -327,8 +327,12 @@ impl VirtioDevice for Net {
None None
}; };
self.vu if self.vu.is_none() {
.lock() error!("Missing vhost-user handle");
return Err(ActivateError::BadActivate);
}
let vu = self.vu.as_ref().unwrap();
vu.lock()
.unwrap() .unwrap()
.setup_vhost_user( .setup_vhost_user(
&mem.memory(), &mem.memory(),
@ -346,7 +350,7 @@ impl VirtioDevice for Net {
let (kill_evt, pause_evt) = self.common.dup_eventfds(); let (kill_evt, pause_evt) = self.common.dup_eventfds();
let mut handler: VhostUserEpollHandler<SlaveReqHandler> = VhostUserEpollHandler { let mut handler: VhostUserEpollHandler<SlaveReqHandler> = VhostUserEpollHandler {
vu: self.vu.clone(), vu: vu.clone(),
mem, mem,
kill_evt, kill_evt,
pause_evt, pause_evt,
@ -386,14 +390,15 @@ impl VirtioDevice for Net {
self.common.resume().ok()?; self.common.resume().ok()?;
} }
if let Err(e) = self if let Some(vu) = &self.vu {
.vu if let Err(e) = vu
.lock() .lock()
.unwrap() .unwrap()
.reset_vhost_user(self.common.queue_sizes.len()) .reset_vhost_user(self.common.queue_sizes.len())
{ {
error!("Failed to reset vhost-user daemon: {:?}", e); error!("Failed to reset vhost-user daemon: {:?}", e);
return None; return None;
}
} }
if let Some(kill_evt) = self.common.kill_evt.take() { if let Some(kill_evt) = self.common.kill_evt.take() {
@ -408,7 +413,9 @@ impl VirtioDevice for Net {
} }
fn shutdown(&mut self) { fn shutdown(&mut self) {
let _ = unsafe { libc::close(self.vu.lock().unwrap().socket_handle().as_raw_fd()) }; if let Some(vu) = &self.vu {
let _ = unsafe { libc::close(vu.lock().unwrap().socket_handle().as_raw_fd()) };
}
// Remove socket path if needed // Remove socket path if needed
if self.server { if self.server {
@ -420,34 +427,37 @@ impl VirtioDevice for Net {
&mut self, &mut self,
region: &Arc<GuestRegionMmap>, region: &Arc<GuestRegionMmap>,
) -> std::result::Result<(), crate::Error> { ) -> std::result::Result<(), crate::Error> {
if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() != 0 if let Some(vu) = &self.vu {
{ if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits()
self.vu != 0
.lock() {
.unwrap() return vu
.add_memory_region(region) .lock()
.map_err(crate::Error::VhostUserAddMemoryRegion) .unwrap()
} else if let Some(guest_memory) = &self.guest_memory { .add_memory_region(region)
self.vu .map_err(crate::Error::VhostUserAddMemoryRegion);
.lock() } else if let Some(guest_memory) = &self.guest_memory {
.unwrap() return vu
.update_mem_table(guest_memory.memory().deref()) .lock()
.map_err(crate::Error::VhostUserUpdateMemory) .unwrap()
} else { .update_mem_table(guest_memory.memory().deref())
Ok(()) .map_err(crate::Error::VhostUserUpdateMemory);
}
} }
Ok(())
} }
} }
impl Pausable for Net { impl Pausable for Net {
fn pause(&mut self) -> result::Result<(), MigratableError> { fn pause(&mut self) -> result::Result<(), MigratableError> {
self.vu if let Some(vu) = &self.vu {
.lock() vu.lock()
.unwrap() .unwrap()
.pause_vhost_user(self.vu_num_queues) .pause_vhost_user(self.vu_num_queues)
.map_err(|e| { .map_err(|e| {
MigratableError::Pause(anyhow!("Error pausing vhost-user-net backend: {:?}", e)) MigratableError::Pause(anyhow!("Error pausing vhost-user-net backend: {:?}", e))
})?; })?;
}
self.common.pause() self.common.pause()
} }
@ -463,13 +473,19 @@ impl Pausable for Net {
ctrl_queue_epoll_thread.thread().unpark(); ctrl_queue_epoll_thread.thread().unpark();
} }
self.vu if let Some(vu) = &self.vu {
.lock() vu.lock()
.unwrap() .unwrap()
.resume_vhost_user(self.vu_num_queues) .resume_vhost_user(self.vu_num_queues)
.map_err(|e| { .map_err(|e| {
MigratableError::Resume(anyhow!("Error resuming vhost-user-net backend: {:?}", e)) MigratableError::Resume(anyhow!(
}) "Error resuming vhost-user-net backend: {:?}",
e
))
})
} else {
Ok(())
}
} }
} }
@ -491,49 +507,56 @@ impl Transportable for Net {}
impl Migratable for Net { impl Migratable for Net {
fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
if let Some(guest_memory) = &self.guest_memory { if let Some(vu) = &self.vu {
let last_ram_addr = guest_memory.memory().last_addr().raw_value(); if let Some(guest_memory) = &self.guest_memory {
self.vu let last_ram_addr = guest_memory.memory().last_addr().raw_value();
.lock() vu.lock()
.unwrap() .unwrap()
.start_dirty_log(last_ram_addr) .start_dirty_log(last_ram_addr)
.map_err(|e| { .map_err(|e| {
MigratableError::StartDirtyLog(anyhow!( MigratableError::StartDirtyLog(anyhow!(
"Error starting migration for vhost-user-net backend: {:?}", "Error starting migration for vhost-user-net backend: {:?}",
e e
)) ))
}) })
} else {
Err(MigratableError::StartDirtyLog(anyhow!(
"Missing guest memory"
)))
}
} else { } else {
Err(MigratableError::StartDirtyLog(anyhow!( Ok(())
"Missing guest memory"
)))
} }
} }
fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
self.vu.lock().unwrap().stop_dirty_log().map_err(|e| { if let Some(vu) = &self.vu {
MigratableError::StopDirtyLog(anyhow!( vu.lock().unwrap().stop_dirty_log().map_err(|e| {
"Error stopping migration for vhost-user-net backend: {:?}", MigratableError::StopDirtyLog(anyhow!(
e "Error stopping migration for vhost-user-net backend: {:?}",
)) e
}) ))
})
} else {
Ok(())
}
} }
fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> { fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> {
if let Some(guest_memory) = &self.guest_memory { if let Some(vu) = &self.vu {
let last_ram_addr = guest_memory.memory().last_addr().raw_value(); if let Some(guest_memory) = &self.guest_memory {
self.vu let last_ram_addr = guest_memory.memory().last_addr().raw_value();
.lock() vu.lock().unwrap().dirty_log(last_ram_addr).map_err(|e| {
.unwrap()
.dirty_log(last_ram_addr)
.map_err(|e| {
MigratableError::DirtyLog(anyhow!( MigratableError::DirtyLog(anyhow!(
"Error retrieving dirty ranges from vhost-user-net backend: {:?}", "Error retrieving dirty ranges from vhost-user-net backend: {:?}",
e e
)) ))
}) })
} else {
Err(MigratableError::DirtyLog(anyhow!("Missing guest memory")))
}
} else { } else {
Err(MigratableError::DirtyLog(anyhow!("Missing guest memory"))) Ok(MemoryRangeTable::default())
} }
} }
} }