diff options
-rw-r--r-- | devices/src/virtio/vhost/net.rs | 11 | ||||
-rw-r--r-- | vhost/src/net.rs | 8 |
2 files changed, 13 insertions, 6 deletions
diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index ba24e3d..1107e9f 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -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, diff --git a/vhost/src/net.rs b/vhost/src/net.rs index 17ea91a..7d49f17 100644 --- a/vhost/src/net.rs +++ b/vhost/src/net.rs @@ -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(()) } } |