From 2ac723228893e39c352d3700a7cd4854d74fc7b1 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 1 Jun 2021 09:54:48 +0000 Subject: [PATCH] virtio-devices: vsock: Implement versioning for state Signed-off-by: Rob Bradford --- virtio-devices/src/vsock/device.rs | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/virtio-devices/src/vsock/device.rs b/virtio-devices/src/vsock/device.rs index bf8b8eaa7..0ec57e287 100644 --- a/virtio-devices/src/vsock/device.rs +++ b/virtio-devices/src/vsock/device.rs @@ -8,15 +8,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the THIRD-PARTY file. -use super::{VsockBackend, VsockPacket}; -use crate::seccomp_filters::{get_seccomp_filter, Thread}; -use crate::Error as DeviceError; -use crate::VirtioInterrupt; -use crate::{ - ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, Queue, - VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, - VIRTIO_F_IN_ORDER, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, -}; /// This is the `VirtioDevice` implementation for our vsock device. It handles the virtio-level /// device logic: feature negotiation, device configuration, and device activation. /// The run-time device logic (i.e. event-driven data handling) is implemented by @@ -36,6 +27,15 @@ use crate::{ /// - an event queue FD; and /// - a backend FD. /// +use super::{VsockBackend, VsockPacket}; +use crate::seccomp_filters::{get_seccomp_filter, Thread}; +use crate::Error as DeviceError; +use crate::VirtioInterrupt; +use crate::{ + ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, Queue, + VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, + VIRTIO_F_IN_ORDER, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, +}; use byteorder::{ByteOrder, LittleEndian}; use seccomp::{SeccompAction, SeccompFilter}; use std::io; @@ -45,8 +45,12 @@ use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, RwLock}; use std::thread; +use versionize::{VersionMap, Versionize, VersionizeResult}; +use versionize_derive::Versionize; use vm_memory::{GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap}; -use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; +use vm_migration::{ + Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, +}; use vmm_sys_util::eventfd::EventFd; const QUEUE_SIZE: u16 = 256; @@ -301,12 +305,14 @@ pub struct Vsock { seccomp_action: SeccompAction, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] pub struct VsockState { pub avail_features: u64, pub acked_features: u64, } +impl VersionMapped for VsockState {} + impl Vsock where B: VsockBackend, @@ -504,11 +510,11 @@ where } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id, &self.state()) + Snapshot::new_from_versioned_state(&self.id, &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id)?); + self.set_state(&snapshot.to_versioned_state(&self.id)?); Ok(()) } }