From dab1cab4a7e398dfa38e83328b22c0dd5ae1cd0d Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 23 Apr 2021 10:55:05 +0100 Subject: [PATCH] virtio-devices: Simplify device state to support Versionize In order to support using Versionize for state structures it is necessary to use simpler, primitive, data types in the state definitions used for snapshot restore. Signed-off-by: Rob Bradford --- virtio-devices/src/block.rs | 6 +++--- virtio-devices/src/console.rs | 6 +++--- virtio-devices/src/iommu.rs | 32 ++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index 6dbc86271..2f825aba5 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -365,7 +365,7 @@ pub struct Block { #[derive(Serialize, Deserialize)] pub struct BlockState { - pub disk_path: PathBuf, + pub disk_path: String, pub disk_nsectors: u64, pub avail_features: u64, pub acked_features: u64, @@ -447,7 +447,7 @@ impl Block { fn state(&self) -> BlockState { BlockState { - disk_path: self.disk_path.clone(), + disk_path: self.disk_path.to_str().unwrap().to_owned(), disk_nsectors: self.disk_nsectors, avail_features: self.common.avail_features, acked_features: self.common.acked_features, @@ -456,7 +456,7 @@ impl Block { } fn set_state(&mut self, state: &BlockState) { - self.disk_path = state.disk_path.clone(); + self.disk_path = state.disk_path.clone().into(); self.disk_nsectors = state.disk_nsectors; self.common.avail_features = state.avail_features; self.common.acked_features = state.acked_features; diff --git a/virtio-devices/src/console.rs b/virtio-devices/src/console.rs index 3c7b0a7f5..79fe90670 100644 --- a/virtio-devices/src/console.rs +++ b/virtio-devices/src/console.rs @@ -282,7 +282,7 @@ pub struct ConsoleState { avail_features: u64, acked_features: u64, config: VirtioConsoleConfig, - in_buffer: VecDeque, + in_buffer: Vec, } impl Console { @@ -337,7 +337,7 @@ impl Console { avail_features: self.common.avail_features, acked_features: self.common.acked_features, config: *(self.config.lock().unwrap()), - in_buffer: self.input.in_buffer.lock().unwrap().clone(), + in_buffer: self.input.in_buffer.lock().unwrap().clone().into(), } } @@ -345,7 +345,7 @@ impl Console { self.common.avail_features = state.avail_features; self.common.acked_features = state.acked_features; *(self.config.lock().unwrap()) = state.config; - *(self.input.in_buffer.lock().unwrap()) = state.in_buffer.clone(); + *(self.input.in_buffer.lock().unwrap()) = state.in_buffer.clone().into(); } } diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index 687a9dfea..5afc30b8f 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -744,8 +744,8 @@ pub struct Iommu { struct IommuState { avail_features: u64, acked_features: u64, - endpoints: BTreeMap, - mappings: BTreeMap>, + endpoints: Vec<(u32, u32)>, + mappings: Vec<(u32, Vec<(u64, Mapping)>)>, } impl Iommu { @@ -787,16 +787,36 @@ impl Iommu { IommuState { avail_features: self.common.avail_features, acked_features: self.common.acked_features, - endpoints: self.mapping.endpoints.read().unwrap().clone(), - mappings: self.mapping.mappings.read().unwrap().clone(), + endpoints: self + .mapping + .endpoints + .read() + .unwrap() + .clone() + .into_iter() + .collect(), + mappings: self + .mapping + .mappings + .read() + .unwrap() + .clone() + .into_iter() + .map(|(k, v)| (k, v.into_iter().collect())) + .collect(), } } fn set_state(&mut self, state: &IommuState) { self.common.avail_features = state.avail_features; self.common.acked_features = state.acked_features; - *(self.mapping.endpoints.write().unwrap()) = state.endpoints.clone(); - *(self.mapping.mappings.write().unwrap()) = state.mappings.clone(); + *(self.mapping.endpoints.write().unwrap()) = state.endpoints.clone().into_iter().collect(); + *(self.mapping.mappings.write().unwrap()) = state + .mappings + .clone() + .into_iter() + .map(|(k, v)| (k, v.into_iter().collect())) + .collect(); } // This function lets the caller specify a list of devices attached to the