devices/virtio/vhost_user_backend/
mod.rs

1// Copyright 2021 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5mod block;
6mod connection;
7#[cfg(feature = "gpu")]
8pub mod gpu;
9mod handler;
10#[cfg(feature = "net")]
11mod net;
12pub mod params;
13#[cfg(feature = "audio")]
14pub mod snd;
15
16pub use block::run_block_device;
17pub use block::Options as BlockOptions;
18pub use connection::sys::VhostUserListener;
19pub use connection::sys::VhostUserStream;
20pub use connection::VhostUserConnectionTrait;
21use cros_async::Executor;
22#[cfg(feature = "gpu")]
23pub use gpu::run_gpu_device;
24#[cfg(feature = "gpu")]
25pub use gpu::Options as GpuOptions;
26pub use handler::VhostUserDevice;
27#[cfg(feature = "net")]
28pub use net::run_net_device;
29#[cfg(feature = "net")]
30pub use net::NetBackend;
31#[cfg(feature = "net")]
32pub use net::Options as NetOptions;
33#[cfg(feature = "audio")]
34pub use snd::run_snd_device;
35#[cfg(feature = "audio")]
36pub use snd::Options as SndOptions;
37
38pub use crate::virtio::vhost_user_backend::connection::BackendConnection;
39
40cfg_if::cfg_if! {
41    if #[cfg(any(target_os = "android", target_os = "linux"))] {
42        mod console;
43        mod fs;
44        mod vsock;
45        mod wl;
46
47        pub use vsock::{run_vsock_device, Options as VsockOptions, VhostUserVsockDevice};
48        pub use wl::{run_wl_device, parse_wayland_sock, Options as WlOptions};
49        pub use console::{create_vu_console_device, run_console_device, Options as ConsoleOptions};
50        pub use fs::{run_fs_device, Options as FsOptions};
51    } else if #[cfg(windows)] {
52        #[cfg(all(feature = "net", feature = "slirp"))]
53        pub use net::sys::windows::NetBackendConfig;
54    }
55}
56
57/// A trait for not-yet-built vhost-user devices.
58///
59/// Upon being given an [[Executor]], a builder can be converted into a [[vmm_vhost::Backend]],
60/// which can then process the requests from the front-end.
61///
62/// We don't build the device directly to ensure that the device only starts threads in the jailed
63/// process, not in the main process. [[VhostUserDeviceBuilder::build()]] is called only after
64/// jailing, which ensures that any operations by the device are done in the jailed process.
65///
66/// TODO: Ideally this would return a [[VhostUserDevice]] instead of [[vmm_vhost::Backend]]. Only
67/// the vhost-user vhost-vsock device uses the latter and it can probably be migrated to
68/// [[VhostUserDevice]].
69pub trait VhostUserDeviceBuilder {
70    /// Create the vhost-user device.
71    ///
72    /// `ex` is an executor the device can use to schedule its tasks.
73    fn build(self: Box<Self>, ex: &Executor) -> anyhow::Result<Box<dyn vmm_vhost::Backend>>;
74}