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