mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
virtio-devices: vhost-user: Enable correct queue indexes
Rather than relying on the amount of queues to enable or disable the queue that have been activated, we rely on the actual queue indexes provided through the tuple including the queue index, the Queue and the EventFd. By storing the list of indexes, we simplify the code and also make it more accurate in case some queues aren't activated. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
3f62a172b2
commit
613c60fc6f
@ -342,11 +342,7 @@ impl VirtioDevice for Blk {
|
||||
}
|
||||
|
||||
if let Some(vu) = &self.vu_common.vu {
|
||||
if let Err(e) = vu
|
||||
.lock()
|
||||
.unwrap()
|
||||
.reset_vhost_user(self.common.queue_sizes.len())
|
||||
{
|
||||
if let Err(e) = vu.lock().unwrap().reset_vhost_user() {
|
||||
error!("Failed to reset vhost-user daemon: {:?}", e);
|
||||
return None;
|
||||
}
|
||||
|
@ -582,11 +582,7 @@ impl VirtioDevice for Fs {
|
||||
}
|
||||
|
||||
if let Some(vu) = &self.vu_common.vu {
|
||||
if let Err(e) = vu
|
||||
.lock()
|
||||
.unwrap()
|
||||
.reset_vhost_user(self.common.queue_sizes.len())
|
||||
{
|
||||
if let Err(e) = vu.lock().unwrap().reset_vhost_user() {
|
||||
error!("Failed to reset vhost-user daemon: {:?}", e);
|
||||
return None;
|
||||
}
|
||||
|
@ -401,12 +401,9 @@ impl VhostUserCommon {
|
||||
|
||||
pub fn pause(&mut self) -> std::result::Result<(), MigratableError> {
|
||||
if let Some(vu) = &self.vu {
|
||||
vu.lock()
|
||||
.unwrap()
|
||||
.pause_vhost_user(self.vu_num_queues)
|
||||
.map_err(|e| {
|
||||
MigratableError::Pause(anyhow!("Error pausing vhost-user-blk backend: {:?}", e))
|
||||
})
|
||||
vu.lock().unwrap().pause_vhost_user().map_err(|e| {
|
||||
MigratableError::Pause(anyhow!("Error pausing vhost-user-blk backend: {:?}", e))
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -414,15 +411,9 @@ impl VhostUserCommon {
|
||||
|
||||
pub fn resume(&mut self) -> std::result::Result<(), MigratableError> {
|
||||
if let Some(vu) = &self.vu {
|
||||
vu.lock()
|
||||
.unwrap()
|
||||
.resume_vhost_user(self.vu_num_queues)
|
||||
.map_err(|e| {
|
||||
MigratableError::Resume(anyhow!(
|
||||
"Error resuming vhost-user-blk backend: {:?}",
|
||||
e
|
||||
))
|
||||
})
|
||||
vu.lock().unwrap().resume_vhost_user().map_err(|e| {
|
||||
MigratableError::Resume(anyhow!("Error resuming vhost-user-blk backend: {:?}", e))
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -369,11 +369,7 @@ impl VirtioDevice for Net {
|
||||
}
|
||||
|
||||
if let Some(vu) = &self.vu_common.vu {
|
||||
if let Err(e) = vu
|
||||
.lock()
|
||||
.unwrap()
|
||||
.reset_vhost_user(self.common.queue_sizes.len())
|
||||
{
|
||||
if let Err(e) = vu.lock().unwrap().reset_vhost_user() {
|
||||
error!("Failed to reset vhost-user daemon: {:?}", e);
|
||||
return None;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ pub struct VhostUserHandle {
|
||||
shm_log: Option<Arc<MmapRegion>>,
|
||||
acked_features: u64,
|
||||
vrings_info: Option<Vec<VringInfo>>,
|
||||
queue_indexes: Vec<usize>,
|
||||
}
|
||||
|
||||
impl VhostUserHandle {
|
||||
@ -198,8 +199,6 @@ impl VhostUserHandle {
|
||||
.map_err(Error::VhostUserSetInflight)?;
|
||||
}
|
||||
|
||||
let num_queues = queues.len() as usize;
|
||||
|
||||
let mut vrings_info = Vec::new();
|
||||
for (queue_index, queue, queue_evt) in queues.iter() {
|
||||
let actual_size: usize = queue.state.size.try_into().unwrap();
|
||||
@ -262,9 +261,11 @@ impl VhostUserHandle {
|
||||
self.vu
|
||||
.set_vring_kick(*queue_index, queue_evt)
|
||||
.map_err(Error::VhostUserSetVringKick)?;
|
||||
|
||||
self.queue_indexes.push(*queue_index);
|
||||
}
|
||||
|
||||
self.enable_vhost_user_vrings(num_queues, true)?;
|
||||
self.enable_vhost_user_vrings(self.queue_indexes.clone(), true)?;
|
||||
|
||||
if let Some(slave_req_handler) = slave_req_handler {
|
||||
self.vu
|
||||
@ -278,8 +279,8 @@ impl VhostUserHandle {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn enable_vhost_user_vrings(&mut self, num_queues: usize, enable: bool) -> Result<()> {
|
||||
for queue_index in 0..num_queues {
|
||||
fn enable_vhost_user_vrings(&mut self, queue_indexes: Vec<usize>, enable: bool) -> Result<()> {
|
||||
for queue_index in queue_indexes {
|
||||
self.vu
|
||||
.set_vring_enable(queue_index, enable)
|
||||
.map_err(Error::VhostUserSetVringEnable)?;
|
||||
@ -288,8 +289,14 @@ impl VhostUserHandle {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reset_vhost_user(&mut self, num_queues: usize) -> Result<()> {
|
||||
self.enable_vhost_user_vrings(num_queues, false)
|
||||
pub fn reset_vhost_user(&mut self) -> Result<()> {
|
||||
for queue_index in self.queue_indexes.drain(..) {
|
||||
self.vu
|
||||
.set_vring_enable(queue_index, false)
|
||||
.map_err(Error::VhostUserSetVringEnable)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_protocol_features_vhost_user(
|
||||
@ -367,6 +374,7 @@ impl VhostUserHandle {
|
||||
shm_log: None,
|
||||
acked_features: 0,
|
||||
vrings_info: None,
|
||||
queue_indexes: Vec::new(),
|
||||
})
|
||||
} else {
|
||||
let now = Instant::now();
|
||||
@ -382,6 +390,7 @@ impl VhostUserHandle {
|
||||
shm_log: None,
|
||||
acked_features: 0,
|
||||
vrings_info: None,
|
||||
queue_indexes: Vec::new(),
|
||||
})
|
||||
}
|
||||
Err(e) => e,
|
||||
@ -405,17 +414,17 @@ impl VhostUserHandle {
|
||||
&mut self.vu
|
||||
}
|
||||
|
||||
pub fn pause_vhost_user(&mut self, num_queues: usize) -> Result<()> {
|
||||
pub fn pause_vhost_user(&mut self) -> Result<()> {
|
||||
if self.ready {
|
||||
self.enable_vhost_user_vrings(num_queues, false)?;
|
||||
self.enable_vhost_user_vrings(self.queue_indexes.clone(), false)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resume_vhost_user(&mut self, num_queues: usize) -> Result<()> {
|
||||
pub fn resume_vhost_user(&mut self) -> Result<()> {
|
||||
if self.ready {
|
||||
self.enable_vhost_user_vrings(num_queues, true)?;
|
||||
self.enable_vhost_user_vrings(self.queue_indexes.clone(), true)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user