vmm: virtio-devices: Restore every VirtioDevice upon creation

Following the new design proposal to improve the restore codepath when
migrating a VM, all virtio devices are supplied with an optional state
they can use to restore from. The restore() implementation every device
was providing has been removed in order to prevent from going through
the restoration twice.

Here is the list of devices now following the new restore design:

- Block (virtio-block)
- Net (virtio-net)
- Rng (virtio-rng)
- Fs (vhost-user-fs)
- Blk (vhost-user-block)
- Net (vhost-user-net)
- Pmem (virtio-pmem)
- Vsock (virtio-vsock)
- Mem (virtio-mem)
- Balloon (virtio-balloon)
- Watchdog (virtio-watchdog)
- Vdpa (vDPA)
- Console (virtio-console)
- Iommu (virtio-iommu)

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-10-18 17:14:43 +02:00
parent 157db33d65
commit 1f0e5eb66a
26 changed files with 716 additions and 699 deletions

View File

@@ -337,6 +337,7 @@ where
{
/// Create a new virtio-vsock device with the given VM CID and vsock
/// backend.
#[allow(clippy::too_many_arguments)]
pub fn new(
id: String,
cid: u64,
@@ -345,17 +346,25 @@ where
iommu: bool,
seccomp_action: SeccompAction,
exit_evt: EventFd,
state: Option<VsockState>,
) -> io::Result<Vsock<B>> {
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_F_IN_ORDER;
let (avail_features, acked_features) = if let Some(state) = state {
info!("Restoring virtio-vsock {}", id);
(state.avail_features, state.acked_features)
} else {
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1 | 1u64 << VIRTIO_F_IN_ORDER;
if iommu {
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
}
if iommu {
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
}
(avail_features, 0)
};
Ok(Vsock {
common: VirtioCommon {
device_type: VirtioDeviceType::Vsock as u32,
avail_features,
acked_features,
paused_sync: Some(Arc::new(Barrier::new(2))),
queue_sizes: QUEUE_SIZES.to_vec(),
min_queues: NUM_QUEUES as u16,
@@ -376,11 +385,6 @@ where
acked_features: self.common.acked_features,
}
}
fn set_state(&mut self, state: &VsockState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
}
}
impl<B> Drop for Vsock<B>
@@ -515,11 +519,6 @@ where
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.id, &self.state())
}
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
self.set_state(&snapshot.to_versioned_state(&self.id)?);
Ok(())
}
}
impl<B> Transportable for Vsock<B> where B: VsockBackend + Sync + 'static {}
impl<B> Migratable for Vsock<B> where B: VsockBackend + Sync + 'static {}

View File

@@ -276,6 +276,7 @@ mod tests {
false,
seccompiler::SeccompAction::Trap,
EventFd::new(EFD_NONBLOCK).unwrap(),
None,
)
.unwrap(),
}