devices: vhost: user: convert console and block to use run_device
Since these devices implement VhostUserDevice, we can use the listener's
run_device method instead of doing the conversion to a VhostUserBackend
ourselves.
BUG=b:217480043
TEST=console and block devices can be used as vhost-user devices.
Change-Id: I5404cffca17f0e8c10a910d7342b300c909489c3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4222837
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Ryuichiro Chiba <chibar@chromium.org>
diff --git a/devices/src/virtio/vhost/user/device/block/sys/unix.rs b/devices/src/virtio/vhost/user/device/block/sys/unix.rs
index 00bfbd3..a053650 100644
--- a/devices/src/virtio/vhost/user/device/block/sys/unix.rs
+++ b/devices/src/virtio/vhost/user/device/block/sys/unix.rs
@@ -65,8 +65,7 @@
None,
None,
None,
- )?)
- .into_backend(&ex)?;
+ )?);
let listener = VhostUserListener::new_from_socket_or_vfio(
&opts.socket,
@@ -75,6 +74,6 @@
None,
)?;
info!("vhost-user disk device ready, starting run loop...");
- // run_until() returns an Result<Result<..>> which the ? operator lets us flatten.
- ex.run_until(listener.run_backend(block, &ex))?
+
+ listener.run_device(ex, block)
}
diff --git a/devices/src/virtio/vhost/user/device/console.rs b/devices/src/virtio/vhost/user/device/console.rs
index 7fbb0e8..e6d7d52 100644
--- a/devices/src/virtio/vhost/user/device/console.rs
+++ b/devices/src/virtio/vhost/user/device/console.rs
@@ -255,15 +255,13 @@
// We won't jail the device and can simply ignore `keep_rds`.
let device = Box::new(create_vu_console_device(¶ms, &mut Vec::new())?);
let ex = Executor::new().context("Failed to create executor")?;
- let backend = device.into_backend(&ex)?;
let listener = VhostUserListener::new_from_socket_or_vfio(
&opts.socket,
&opts.vfio,
- backend.max_queue_num(),
+ device.max_queue_num(),
None,
)?;
- // run_until() returns an Result<Result<..>> which the ? operator lets us flatten.
- ex.run_until(listener.run_backend(backend, &ex))?
+ listener.run_device(ex, device)
}