devices/virtio/vhost/
mod.rs

1// Copyright 2017 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//! Implements vhost-based virtio devices.
6
7use base::Error as SysError;
8use base::TubeError;
9use net_util::Error as TapError;
10use remain::sorted;
11use thiserror::Error;
12#[cfg(any(target_os = "android", target_os = "linux"))]
13use vhost::Error as VhostError;
14
15mod control_socket;
16
17pub use self::control_socket::*;
18
19cfg_if::cfg_if! {
20    if #[cfg(any(target_os = "android", target_os = "linux"))] {
21        #[cfg(target_arch = "aarch64")]
22        pub mod scmi;
23        pub mod worker;
24
25        #[cfg(target_arch = "aarch64")]
26        pub use self::scmi::Scmi;
27    } else if #[cfg(windows)] {}
28}
29
30#[sorted]
31#[derive(Error, Debug)]
32pub enum Error {
33    /// Cloning kill event failed.
34    #[error("failed to clone kill event: {0}")]
35    CloneKillEvent(SysError),
36    /// Creating kill event failed.
37    #[error("failed to create kill event: {0}")]
38    CreateKillEvent(SysError),
39    /// Creating tube failed.
40    #[error("failed to create tube: {0}")]
41    CreateTube(TubeError),
42    /// Creating wait context failed.
43    #[error("failed to create poll context: {0}")]
44    CreateWaitContext(SysError),
45    /// Enabling tap interface failed.
46    #[error("failed to enable tap interface: {0}")]
47    TapEnable(TapError),
48    /// Open tap device failed.
49    #[error("failed to open tap device: {0}")]
50    TapOpen(TapError),
51    /// Setting tap IP failed.
52    #[error("failed to set tap IP: {0}")]
53    TapSetIp(TapError),
54    /// Setting tap mac address failed.
55    #[error("failed to set tap mac address: {0}")]
56    TapSetMacAddress(TapError),
57    /// Setting tap netmask failed.
58    #[error("failed to set tap netmask: {0}")]
59    TapSetNetmask(TapError),
60    /// Setting tap interface offload flags failed.
61    #[error("failed to set tap interface offload flags: {0}")]
62    TapSetOffload(TapError),
63    /// Setting vnet header size failed.
64    #[error("failed to set vnet header size: {0}")]
65    TapSetVnetHdrSize(TapError),
66    /// Failed to read vhost error event.
67    #[error("failed to read vhost error event: {0}")]
68    VhostErrorRead(SysError),
69    /// Get features failed.
70    #[cfg(any(target_os = "android", target_os = "linux"))]
71    #[error("failed to get features: {0}")]
72    VhostGetFeatures(VhostError),
73    /// Vhost IOTLB required but not supported.
74    #[error("Vhost IOTLB required but not supported")]
75    VhostIotlbUnsupported,
76    /// Failed to create vhost event.
77    #[error("failed to create vhost event: {0}")]
78    VhostIrqCreate(SysError),
79    /// Failed to read vhost interrupt event.
80    #[error("failed to read vhost interrupt event: {0}")]
81    VhostIrqRead(SysError),
82    /// Net set backend failed.
83    #[cfg(any(target_os = "android", target_os = "linux"))]
84    #[error("net set backend failed: {0}")]
85    VhostNetSetBackend(VhostError),
86    /// Failed to open vhost device.
87    #[cfg(any(target_os = "android", target_os = "linux"))]
88    #[error("failed to open vhost device: {0}")]
89    VhostOpen(VhostError),
90    /// Set features failed.
91    #[cfg(any(target_os = "android", target_os = "linux"))]
92    #[error("failed to set features: {0}")]
93    VhostSetFeatures(VhostError),
94    /// Set mem table failed.
95    #[cfg(any(target_os = "android", target_os = "linux"))]
96    #[error("failed to set mem table: {0}")]
97    VhostSetMemTable(VhostError),
98    /// Set owner failed.
99    #[cfg(any(target_os = "android", target_os = "linux"))]
100    #[error("failed to set owner: {0}")]
101    VhostSetOwner(VhostError),
102    /// Set vring addr failed.
103    #[cfg(any(target_os = "android", target_os = "linux"))]
104    #[error("failed to set vring addr: {0}")]
105    VhostSetVringAddr(VhostError),
106    /// Set vring base failed.
107    #[cfg(any(target_os = "android", target_os = "linux"))]
108    #[error("failed to set vring base: {0}")]
109    VhostSetVringBase(VhostError),
110    /// Set vring call failed.
111    #[cfg(any(target_os = "android", target_os = "linux"))]
112    #[error("failed to set vring call: {0}")]
113    VhostSetVringCall(VhostError),
114    /// Set vring err failed.
115    #[cfg(any(target_os = "android", target_os = "linux"))]
116    #[error("failed to set vring err: {0}")]
117    VhostSetVringErr(VhostError),
118    /// Set vring kick failed.
119    #[cfg(any(target_os = "android", target_os = "linux"))]
120    #[error("failed to set vring kick: {0}")]
121    VhostSetVringKick(VhostError),
122    /// Set vring num failed.
123    #[cfg(any(target_os = "android", target_os = "linux"))]
124    #[error("failed to set vring num: {0}")]
125    VhostSetVringNum(VhostError),
126    /// Failed to set CID for guest.
127    #[cfg(any(target_os = "android", target_os = "linux"))]
128    #[error("failed to set CID for guest: {0}")]
129    VhostVsockSetCid(VhostError),
130    /// Failed to start vhost-vsock driver.
131    #[cfg(any(target_os = "android", target_os = "linux"))]
132    #[error("failed to start vhost-vsock driver: {0}")]
133    VhostVsockStart(VhostError),
134    #[error("queue missing vring base")]
135    VringBaseMissing,
136    /// Error while waiting for events.
137    #[error("failed waiting for events: {0}")]
138    WaitError(SysError),
139}
140
141pub type Result<T> = std::result::Result<T, Error>;