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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-04-23 10:55:05 +01:00
parent f643ba6111
commit dab1cab4a7
3 changed files with 32 additions and 12 deletions

View File

@ -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;

View File

@ -282,7 +282,7 @@ pub struct ConsoleState {
avail_features: u64,
acked_features: u64,
config: VirtioConsoleConfig,
in_buffer: VecDeque<u8>,
in_buffer: Vec<u8>,
}
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();
}
}

View File

@ -744,8 +744,8 @@ pub struct Iommu {
struct IommuState {
avail_features: u64,
acked_features: u64,
endpoints: BTreeMap<u32, u32>,
mappings: BTreeMap<u32, BTreeMap<u64, Mapping>>,
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