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