summary refs log tree commit diff
diff options
context:
space:
mode:
authorChuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>2019-11-19 09:49:45 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-19 09:24:40 +0000
commit92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab (patch)
treefbde4e6388aa3084c6d4f15eb58723d3c934c92d
parent5de0604f2922681f1414bc05f8cfe9b30387e59e (diff)
downloadcrosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.tar
crosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.tar.gz
crosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.tar.bz2
crosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.tar.lz
crosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.tar.xz
crosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.tar.zst
crosvm-92ee1489ce4fb011f8a55fa7d2e8e3cb4ff75dab.zip
vhost: add cleanup_vqs to do some cleanup stuff
Activate_vqs is used to do the queue preparation before really
running. The virtio-vhost device might need to do some cleanup
to allow a second round activate in the future. How to do the
cleanup is depending on how the vhost virtio devices.

Just add an interface called cleanup_vqs to allow the vhost virtio
devices to do their own cleanup stuff.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I2472e79a8b63c9336f886cde55ffef6a78008ad8
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954172
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
-rw-r--r--devices/src/virtio/vhost/net.rs10
-rw-r--r--devices/src/virtio/vhost/vsock.rs10
-rw-r--r--devices/src/virtio/vhost/worker.rs9
3 files changed, 22 insertions, 7 deletions
diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs
index 2082a0f..b48ccf0 100644
--- a/devices/src/virtio/vhost/net.rs
+++ b/devices/src/virtio/vhost/net.rs
@@ -206,8 +206,14 @@ where
                                     }
                                     Ok(())
                                 };
-                                let result =
-                                    worker.run(queue_evts, QUEUE_SIZES, kill_evt, activate_vqs);
+                                let cleanup_vqs = |_handle: &U| -> Result<()> { Ok(()) };
+                                let result = worker.run(
+                                    queue_evts,
+                                    QUEUE_SIZES,
+                                    kill_evt,
+                                    activate_vqs,
+                                    cleanup_vqs,
+                                );
                                 if let Err(e) = result {
                                     error!("net worker thread exited with error: {}", e);
                                 }
diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs
index 32f2c99..192e5ce 100644
--- a/devices/src/virtio/vhost/vsock.rs
+++ b/devices/src/virtio/vhost/vsock.rs
@@ -173,8 +173,14 @@ impl VirtioDevice for Vsock {
                                 handle.start().map_err(Error::VhostVsockStart)?;
                                 Ok(())
                             };
-                            let result =
-                                worker.run(queue_evts, QUEUE_SIZES, kill_evt, activate_vqs);
+                            let cleanup_vqs = |_handle: &VhostVsockHandle| -> Result<()> { Ok(()) };
+                            let result = worker.run(
+                                queue_evts,
+                                QUEUE_SIZES,
+                                kill_evt,
+                                activate_vqs,
+                                cleanup_vqs,
+                            );
                             if let Err(e) = result {
                                 error!("vsock worker thread exited with error: {:?}", e);
                             }
diff --git a/devices/src/virtio/vhost/worker.rs b/devices/src/virtio/vhost/worker.rs
index 21aabfd..17114a4 100644
--- a/devices/src/virtio/vhost/worker.rs
+++ b/devices/src/virtio/vhost/worker.rs
@@ -39,15 +39,17 @@ impl<T: Vhost> Worker<T> {
         }
     }
 
-    pub fn run<F>(
+    pub fn run<F1, F2>(
         &mut self,
         queue_evts: Vec<EventFd>,
         queue_sizes: &[u16],
         kill_evt: EventFd,
-        activate_vqs: F,
+        activate_vqs: F1,
+        cleanup_vqs: F2,
     ) -> Result<()>
     where
-        F: FnOnce(&T) -> Result<()>,
+        F1: FnOnce(&T) -> Result<()>,
+        F2: FnOnce(&T) -> Result<()>,
     {
         // Preliminary setup for vhost net.
         self.vhost_handle
@@ -135,6 +137,7 @@ impl<T: Vhost> Worker<T> {
                 }
             }
         }
+        cleanup_vqs(&self.vhost_handle)?;
         Ok(())
     }
 }