Skip to content

Commit

Permalink
refactor(block): readding skip of vhost-user-block from snapshots
Browse files Browse the repository at this point in the history
Adding back the skip of vhost-user-block devices.

Signed-off-by: Egor Lazarchuk <[email protected]>
  • Loading branch information
ShadowCurse committed Nov 30, 2023
1 parent f5c99b3 commit fde8989
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
39 changes: 23 additions & 16 deletions src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex};

use event_manager::{MutEventSubscriber, SubscriberOps};
use kvm_ioctls::VmFd;
use log::error;
use log::{error, warn};
use snapshot::Persist;
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;
Expand Down Expand Up @@ -175,8 +175,8 @@ pub struct DeviceStates {
#[cfg(target_arch = "aarch64")]
// State of legacy devices in MMIO space.
pub legacy_devices: Vec<ConnectedLegacyState>,
/// Virtio block device states.
pub virtio_block_devices: Vec<ConnectedBlockState>,
/// Block device states.
pub block_devices: Vec<ConnectedBlockState>,
/// Net device states.
pub net_devices: Vec<ConnectedNetState>,
/// Vsock device state.
Expand Down Expand Up @@ -274,13 +274,20 @@ impl<'a> Persist<'a> for MMIODeviceManager {
// Both virtio-block and vhost-user-block share same device type.
TYPE_BLOCK => {
let block = locked_device.as_mut_any().downcast_mut::<Block>().unwrap();
block.prepare_save();
states.virtio_block_devices.push(ConnectedBlockState {
device_id: devid.clone(),
device_state: block.save(),
transport_state,
device_info: device_info.clone(),
})
if block.is_vhost_user() {
warn!(
"Skipping vhost-user-block device. VhostUserBlock does not support \
snapshotting yet"
);
} else {
block.prepare_save();
states.block_devices.push(ConnectedBlockState {
device_id: devid.clone(),
device_state: block.save(),
transport_state,
device_info: device_info.clone(),
})
}
}
TYPE_NET => {
let net = locked_device.as_any().downcast_ref::<Net>().unwrap();
Expand Down Expand Up @@ -470,10 +477,10 @@ impl<'a> Persist<'a> for MMIODeviceManager {
)?;
}

for virtio_block_state in &state.virtio_block_devices {
for block_state in &state.block_devices {
let device = Arc::new(Mutex::new(Block::restore(
BlockConstructorArgs { mem: mem.clone() },
&virtio_block_state.device_state,
&block_state.device_state,
)?));

(constructor_args.for_each_restored_device)(
Expand All @@ -485,9 +492,9 @@ impl<'a> Persist<'a> for MMIODeviceManager {
device.clone(),
false,
device,
&virtio_block_state.device_id,
&virtio_block_state.transport_state,
&virtio_block_state.device_info,
&block_state.device_id,
&block_state.transport_state,
&block_state.device_info,
constructor_args.event_manager,
)?;
}
Expand Down Expand Up @@ -640,7 +647,7 @@ mod tests {
impl PartialEq for DeviceStates {
fn eq(&self, other: &DeviceStates) -> bool {
self.balloon_device == other.balloon_device
&& self.virtio_block_devices == other.virtio_block_devices
&& self.block_devices == other.block_devices
&& self.net_devices == other.net_devices
&& self.vsock_device == other.vsock_device
}
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ mod tests {

// Only checking that all devices are saved, actual device state
// is tested by that device's tests.
assert_eq!(states.virtio_block_devices.len(), 1);
assert_eq!(states.block_devices.len(), 1);
assert_eq!(states.net_devices.len(), 1);
assert!(states.vsock_device.is_some());
assert!(states.balloon_device.is_some());
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn verify_create_snapshot(is_diff: bool) -> (TempFile, TempFile) {
assert_eq!(
restored_microvm_state
.device_states
.virtio_block_devices
.block_devices
.len(),
0
);
Expand Down

0 comments on commit fde8989

Please sign in to comment.