mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 12:34:31 +00:00
vhost-net: set backend to null when activate fn quit
Set the backend with null fd can reset the vq in vhost, which can allow the activate fn to run again. BUG=None TEST=launch Crosvm guest with vhost-net. It works fine with iperf test. TEST=cargo test -p devices Change-Id: Ida952409147fd6fbd1d8f69b3a88a7ef03051d65 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009523 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
282115bcdb
commit
bc499ec278
2 changed files with 13 additions and 6 deletions
|
@ -201,12 +201,19 @@ where
|
|||
let activate_vqs = |handle: &U| -> Result<()> {
|
||||
for idx in 0..NUM_QUEUES {
|
||||
handle
|
||||
.set_backend(idx, &tap)
|
||||
.set_backend(idx, Some(&tap))
|
||||
.map_err(Error::VhostNetSetBackend)?;
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
let cleanup_vqs = |handle: &U| -> Result<()> {
|
||||
for idx in 0..NUM_QUEUES {
|
||||
handle
|
||||
.set_backend(idx, None)
|
||||
.map_err(Error::VhostNetSetBackend)?;
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
let cleanup_vqs = |_handle: &U| -> Result<()> { Ok(()) };
|
||||
let result = worker.run(
|
||||
queue_evts,
|
||||
QUEUE_SIZES,
|
||||
|
|
|
@ -38,7 +38,7 @@ pub trait NetT<T: TapT>: Vhost + AsRawFd + Send + Sized {
|
|||
/// # Arguments
|
||||
/// * `queue_index` - Index of the queue to modify.
|
||||
/// * `fd` - Tap interface that will be used as the backend.
|
||||
fn set_backend(&self, queue_index: usize, fd: &T) -> Result<()>;
|
||||
fn set_backend(&self, queue_index: usize, fd: Option<&T>) -> Result<()>;
|
||||
}
|
||||
|
||||
impl<T> NetT<T> for Net<T>
|
||||
|
@ -62,10 +62,10 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
fn set_backend(&self, queue_index: usize, fd: &T) -> Result<()> {
|
||||
fn set_backend(&self, queue_index: usize, fd: Option<&T>) -> Result<()> {
|
||||
let vring_file = virtio_sys::vhost_vring_file {
|
||||
index: queue_index as u32,
|
||||
fd: fd.as_raw_fd(),
|
||||
fd: fd.map_or(-1, |fd| fd.as_raw_fd()),
|
||||
};
|
||||
|
||||
// This ioctl is called on a valid vhost_net fd and has its
|
||||
|
@ -127,7 +127,7 @@ pub mod fakes {
|
|||
})
|
||||
}
|
||||
|
||||
fn set_backend(&self, _queue_index: usize, _fd: &T) -> Result<()> {
|
||||
fn set_backend(&self, _queue_index: usize, _fd: Option<&T>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue