Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/devices/src/virtio/vhost_user_backend/mod.rs
5394 views
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
mod connection;
7
#[cfg(feature = "gpu")]
8
pub mod gpu;
9
mod handler;
10
#[cfg(feature = "net")]
11
mod net;
12
pub mod params;
13
#[cfg(feature = "audio")]
14
pub mod snd;
15
16
pub use block::run_block_device;
17
pub use block::Options as BlockOptions;
18
pub use connection::sys::VhostUserListener;
19
pub use connection::sys::VhostUserStream;
20
pub use connection::VhostUserConnectionTrait;
21
use cros_async::Executor;
22
#[cfg(feature = "gpu")]
23
pub use gpu::run_gpu_device;
24
#[cfg(feature = "gpu")]
25
pub use gpu::Options as GpuOptions;
26
pub use handler::VhostUserDevice;
27
#[cfg(feature = "net")]
28
pub use net::run_net_device;
29
#[cfg(feature = "net")]
30
pub use net::NetBackend;
31
#[cfg(feature = "net")]
32
pub use net::Options as NetOptions;
33
#[cfg(feature = "audio")]
34
pub use snd::run_snd_device;
35
#[cfg(feature = "audio")]
36
pub use snd::Options as SndOptions;
37
38
pub use crate::virtio::vhost_user_backend::connection::BackendConnection;
39
40
cfg_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]].
69
pub 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
}
75
76