From fd45e945103cef5fce353fafd6969a61e0e04e73 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Wed, 8 Apr 2020 09:53:12 +0800 Subject: [PATCH] vm-virtio: Add the ability to serialize a Queue This commit relies on serde to serialize and deserialize the content of a Queue structure. This will be useful information to store when implementing snapshot/restore feature for virtio devices. Signed-off-by: Sebastien Boeuf Signed-off-by: Samuel Ortiz Signed-off-by: Yi Sun --- Cargo.lock | 4 ++++ vm-virtio/Cargo.toml | 4 ++++ vm-virtio/src/lib.rs | 4 ++++ vm-virtio/src/queue.rs | 12 ++++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b863a82db..eb4015501 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1454,6 +1454,7 @@ dependencies = [ name = "vm-virtio" version = "0.1.0" dependencies = [ + "anyhow", "arc-swap", "byteorder", "devices", @@ -1463,6 +1464,9 @@ dependencies = [ "net_gen", "net_util", "pci", + "serde", + "serde_derive", + "serde_json", "tempfile", "vhost", "virtio-bindings 0.1.0 (git+https://github.com/rust-vmm/virtio-bindings)", diff --git a/vm-virtio/Cargo.toml b/vm-virtio/Cargo.toml index 2f80f8c90..0fc18324b 100644 --- a/vm-virtio/Cargo.toml +++ b/vm-virtio/Cargo.toml @@ -10,6 +10,7 @@ pci_support = ["pci"] mmio_support = [] [dependencies] +anyhow = "1.0" arc-swap = ">=0.4.4" byteorder = "1.3.4" devices = { path = "../devices" } @@ -19,6 +20,9 @@ log = "0.4.8" net_gen = { path = "../net_gen" } net_util = { path = "../net_util" } pci = { path = "../pci", optional = true } +serde = ">=1.0.27" +serde_derive = ">=1.0.27" +serde_json = ">=1.0.9" tempfile = "3.1.0" virtio-bindings = { git = "https://github.com/rust-vmm/virtio-bindings", version = "0.1", features = ["virtio-v5_0_0"]} vm-allocator = { path = "../vm-allocator" } diff --git a/vm-virtio/src/lib.rs b/vm-virtio/src/lib.rs index 5c0c38010..ba32d708a 100755 --- a/vm-virtio/src/lib.rs +++ b/vm-virtio/src/lib.rs @@ -16,6 +16,10 @@ extern crate epoll; extern crate log; #[cfg(feature = "pci_support")] extern crate pci; +extern crate serde; +#[macro_use] +extern crate serde_derive; +extern crate serde_json; extern crate vhost_rs; extern crate virtio_bindings; extern crate vm_device; diff --git a/vm-virtio/src/queue.rs b/vm-virtio/src/queue.rs index 14a14a8d4..91f21ffba 100644 --- a/vm-virtio/src/queue.rs +++ b/vm-virtio/src/queue.rs @@ -383,11 +383,15 @@ impl<'a, 'b> Iterator for AvailIter<'a, 'b> { } } -#[derive(Clone)] +#[derive(Serialize, Deserialize)] +#[serde(remote = "GuestAddress")] +struct GuestAddressDef(pub u64); + +#[derive(Clone, Serialize, Deserialize)] /// A virtio queue's parameters. pub struct Queue { /// The maximal size in elements offered by the device - max_size: u16, + pub max_size: u16, /// The queue size in elements the driver selected pub size: u16, @@ -398,18 +402,22 @@ pub struct Queue { /// Interrupt vector index of the queue pub vector: u16, + #[serde(with = "GuestAddressDef")] /// Guest physical address of the descriptor table pub desc_table: GuestAddress, + #[serde(with = "GuestAddressDef")] /// Guest physical address of the available ring pub avail_ring: GuestAddress, + #[serde(with = "GuestAddressDef")] /// Guest physical address of the used ring pub used_ring: GuestAddress, pub next_avail: Wrapping, pub next_used: Wrapping, + #[serde(skip)] pub iommu_mapping_cb: Option>, }