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