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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2021-08-02 11:50:55 +02:00
committed by Bo Chen
parent c1b962048c
commit 61994cdb14
3 changed files with 17 additions and 1 deletions

View File

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