virtio-devices: vhost_user: Fully implement Migratable trait

All vhost-user devices are now equipped to support migration.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2021-08-04 16:16:54 +02:00
committed by Bo Chen
parent b3f5630c27
commit 9d88e0b417
3 changed files with 161 additions and 8 deletions
+54 -3
View File
@@ -29,9 +29,10 @@ use virtio_bindings::bindings::virtio_blk::{
VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_SEG_MAX,
VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_WRITE_ZEROES,
};
use vm_memory::{ByteValued, GuestAddressSpace, GuestMemoryAtomic};
use vm_memory::{Address, ByteValued, GuestAddressSpace, GuestMemory, GuestMemoryAtomic};
use vm_migration::{
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable,
Transportable, VersionMapped,
};
use vmm_sys_util::eventfd::EventFd;
@@ -399,4 +400,54 @@ impl Snapshottable for Blk {
}
}
impl Transportable for Blk {}
impl Migratable for Blk {}
impl Migratable for Blk {
fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
if let Some(guest_memory) = &self.guest_memory {
let last_ram_addr = guest_memory.memory().last_addr().raw_value();
self.vu
.lock()
.unwrap()
.start_dirty_log(last_ram_addr)
.map_err(|e| {
MigratableError::MigrateStart(anyhow!(
"Error starting migration for vhost-user-blk backend: {:?}",
e
))
})
} else {
Err(MigratableError::MigrateStart(anyhow!(
"Missing guest memory"
)))
}
}
fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> {
self.vu.lock().unwrap().stop_dirty_log().map_err(|e| {
MigratableError::MigrateStop(anyhow!(
"Error stopping migration for vhost-user-blk backend: {:?}",
e
))
})
}
fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> {
if let Some(guest_memory) = &self.guest_memory {
let last_ram_addr = guest_memory.memory().last_addr().raw_value();
self.vu
.lock()
.unwrap()
.dirty_log(last_ram_addr)
.map_err(|e| {
MigratableError::MigrateDirtyRanges(anyhow!(
"Error retrieving dirty ranges from vhost-user-blk backend: {:?}",
e
))
})
} else {
Err(MigratableError::MigrateDirtyRanges(anyhow!(
"Missing guest memory"
)))
}
}
}