From 61994cdb144065661dbf703d7201fa1d12a89843 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 2 Aug 2021 11:50:55 +0200 Subject: [PATCH] virtio-devices: vhost_user: Store ability to migrate Adding a simple field `migration_support` to VhostUserHandle in order to store the information about the device supporting migration or not. The value of this flag depends on the feature set negotiated with the backend. It's considered as supporting migration if VHOST_F_LOG_ALL is present in the virtio features and if VHOST_USER_PROTOCOL_F_LOG_SHMFD is present in the vhost-user protocol features. Signed-off-by: Sebastien Boeuf --- Cargo.lock | 1 + virtio-devices/Cargo.toml | 2 +- virtio-devices/src/vhost_user/vu_common_ctrl.rs | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ca1ad0f64..5bd4781ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1127,6 +1127,7 @@ source = "git+https://github.com/rust-vmm/vhost?branch=master#37a6a8e46444e9e4b5 dependencies = [ "bitflags", "libc", + "vm-memory", "vmm-sys-util", ] diff --git a/virtio-devices/Cargo.toml b/virtio-devices/Cargo.toml index 4885a52a1..3f8f40429 100644 --- a/virtio-devices/Cargo.toml +++ b/virtio-devices/Cargo.toml @@ -29,7 +29,7 @@ serde_derive = ">=1.0.27" serde_json = ">=1.0.9" versionize = "0.1.6" versionize_derive = "0.1.4" -vhost = { git = "https://github.com/rust-vmm/vhost", branch = "master", package = "vhost", features = ["vhost-user-master", "vhost-user-slave"] } +vhost = { git = "https://github.com/rust-vmm/vhost", branch = "master", package = "vhost", features = ["vhost-user-master", "vhost-user-slave", "vhost-kern"] } virtio-bindings = { version = "0.1", features = ["virtio-v5_0_0"]} vm-allocator = { path = "../vm-allocator" } vm-device = { path = "../vm-device" } diff --git a/virtio-devices/src/vhost_user/vu_common_ctrl.rs b/virtio-devices/src/vhost_user/vu_common_ctrl.rs index a8317d137..de838617b 100644 --- a/virtio-devices/src/vhost_user/vu_common_ctrl.rs +++ b/virtio-devices/src/vhost_user/vu_common_ctrl.rs @@ -32,6 +32,7 @@ pub struct VhostUserConfig { pub struct VhostUserHandle { vu: Master, ready: bool, + supports_migration: bool, } impl VhostUserHandle { @@ -120,6 +121,8 @@ impl VhostUserHandle { self.vu.set_hdr_flags(VhostUserHeaderFlag::NEED_REPLY); } + self.update_supports_migration(acked_features, acked_protocol_features.bits()); + Ok((acked_features, acked_protocol_features.bits())) } @@ -284,6 +287,8 @@ impl VhostUserHandle { } } + self.update_supports_migration(acked_features, acked_protocol_features); + self.setup_vhost_user( mem, queues, @@ -314,6 +319,7 @@ impl VhostUserHandle { Ok(VhostUserHandle { vu: Master::from_stream(stream, num_queues), ready: false, + supports_migration: false, }) } else { let now = Instant::now(); @@ -325,6 +331,7 @@ impl VhostUserHandle { return Ok(VhostUserHandle { vu: m, ready: false, + supports_migration: false, }) } Err(e) => e, @@ -363,4 +370,12 @@ impl VhostUserHandle { Ok(()) } + + fn update_supports_migration(&mut self, acked_features: u64, acked_protocol_features: u64) { + if (acked_features & u64::from(vhost::vhost_kern::vhost_binding::VHOST_F_LOG_ALL) != 0) + && (acked_protocol_features & VhostUserProtocolFeatures::LOG_SHMFD.bits() != 0) + { + self.supports_migration = true; + } + } }