mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm, virtio-devices: Restore vhost-user devices in a dedicated way
We cannot let vhost-user devices connect to the backend when the Block, Fs or Net object is being created during a restore/migration. The reason is we can't have two VMs (source and destination) connected to the same backend at the same time. That's why we must delay the connection with the vhost-user backend until the restoration is performed. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -44,6 +44,8 @@ pub struct State {
|
||||
pub avail_features: u64,
|
||||
pub acked_features: u64,
|
||||
pub config: VirtioNetConfig,
|
||||
pub acked_protocol_features: u64,
|
||||
pub vu_num_queues: usize,
|
||||
}
|
||||
|
||||
impl VersionMapped for State {}
|
||||
@@ -127,9 +129,38 @@ impl Net {
|
||||
vu_cfg: VhostUserConfig,
|
||||
server: bool,
|
||||
seccomp_action: SeccompAction,
|
||||
restoring: bool,
|
||||
) -> Result<Net> {
|
||||
let mut num_queues = vu_cfg.num_queues;
|
||||
|
||||
if restoring {
|
||||
// We need 'queue_sizes' to report a number of queues that will be
|
||||
// enough to handle all the potential queues. Including the control
|
||||
// queue (with +1) will guarantee that. VirtioPciDevice::new() will
|
||||
// create the actual queues based on this information.
|
||||
return Ok(Net {
|
||||
id,
|
||||
common: VirtioCommon {
|
||||
device_type: VirtioDeviceType::Net as u32,
|
||||
queue_sizes: vec![vu_cfg.queue_size; num_queues + 1],
|
||||
paused_sync: Some(Arc::new(Barrier::new(2))),
|
||||
min_queues: DEFAULT_QUEUE_NUMBER as u16,
|
||||
..Default::default()
|
||||
},
|
||||
vu: None,
|
||||
config: VirtioNetConfig::default(),
|
||||
guest_memory: None,
|
||||
acked_protocol_features: 0,
|
||||
socket_path: vu_cfg.socket,
|
||||
server,
|
||||
ctrl_queue_epoll_thread: None,
|
||||
epoll_thread: None,
|
||||
seccomp_action,
|
||||
vu_num_queues: num_queues,
|
||||
migration_started: false,
|
||||
});
|
||||
}
|
||||
|
||||
// Filling device and vring features VMM supports.
|
||||
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
||||
| 1 << VIRTIO_NET_F_GUEST_CSUM
|
||||
@@ -218,6 +249,8 @@ impl Net {
|
||||
avail_features: self.common.avail_features,
|
||||
acked_features: self.common.acked_features,
|
||||
config: self.config,
|
||||
acked_protocol_features: self.acked_protocol_features,
|
||||
vu_num_queues: self.vu_num_queues,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,6 +258,31 @@ impl Net {
|
||||
self.common.avail_features = state.avail_features;
|
||||
self.common.acked_features = state.acked_features;
|
||||
self.config = state.config;
|
||||
self.acked_protocol_features = state.acked_protocol_features;
|
||||
self.vu_num_queues = state.vu_num_queues;
|
||||
|
||||
let mut vu = match VhostUserHandle::connect_vhost_user(
|
||||
self.server,
|
||||
&self.socket_path,
|
||||
self.vu_num_queues as u64,
|
||||
false,
|
||||
) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
error!("Failed connecting vhost-user backend: {:?}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = vu.set_protocol_features_vhost_user(
|
||||
self.common.acked_features,
|
||||
self.acked_protocol_features,
|
||||
) {
|
||||
error!("Failed setting up vhost-user backend: {:?}", e);
|
||||
return;
|
||||
}
|
||||
|
||||
self.vu = Some(Arc::new(Mutex::new(vu)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user