• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 console;
7 mod fs;
8 mod gpu;
9 mod handler;
10 mod mac80211_hwsim;
11 mod net;
12 mod snd;
13 mod video;
14 mod virtio_device;
15 mod vsock;
16 mod wl;
17 
18 use remain::sorted;
19 use thiserror::Error as ThisError;
20 use virtio_device::QueueSizes;
21 pub use virtio_device::VhostUserVirtioDevice;
22 use vm_memory::GuestMemoryError;
23 use vmm_vhost::message::VhostUserProtocolFeatures;
24 use vmm_vhost::Error as VhostError;
25 
26 pub use self::handler::VhostUserHandler;
27 
28 cfg_if::cfg_if! {
29     if #[cfg(unix)] {
30         pub type Connection = std::os::unix::net::UnixStream;
31     } else if #[cfg(windows)] {
32         pub type Connection = base::Tube;
33     }
34 }
35 
36 #[sorted]
37 #[derive(ThisError, Debug)]
38 pub enum Error {
39     /// Failed to copy config to a buffer.
40     #[error("failed to copy config to a buffer: {0}")]
41     CopyConfig(std::io::Error),
42     /// Failed to create backend request handler
43     #[error("could not create backend req handler: {0}")]
44     CreateBackendReqHandler(VhostError),
45     /// Failed to create `base::Event`.
46     #[error("failed to create Event: {0}")]
47     CreateEvent(base::Error),
48     /// Failed to get config.
49     #[error("failed to get config: {0}")]
50     GetConfig(VhostError),
51     /// Failed to get features.
52     #[error("failed to get features: {0}")]
53     GetFeatures(VhostError),
54     /// Failed to get host address.
55     #[error("failed to get host address: {0}")]
56     GetHostAddress(GuestMemoryError),
57     /// Failed to get protocol features.
58     #[error("failed to get protocol features: {0}")]
59     GetProtocolFeatures(VhostError),
60     /// Failed to get number of queues.
61     #[error("failed to get number of queues: {0}")]
62     GetQueueNum(VhostError),
63     /// Failed to get vring base offset.
64     #[error("failed to get vring base offset: {0}")]
65     GetVringBase(VhostError),
66     /// Invalid config length is given.
67     #[error("invalid config length is given: {0}")]
68     InvalidConfigLen(usize),
69     /// Invalid config offset is given.
70     #[error("invalid config offset is given: {0}")]
71     InvalidConfigOffset(u64),
72     /// MSI-X config is unavailable.
73     #[error("MSI-X config is unavailable")]
74     MsixConfigUnavailable,
75     /// MSI-X irqfd is unavailable.
76     #[error("MSI-X irqfd is unavailable")]
77     MsixIrqfdUnavailable,
78     #[error("protocol feature is not negotiated: {0:?}")]
79     ProtocolFeatureNotNegoiated(VhostUserProtocolFeatures),
80     /// Failed to reset owner.
81     #[error("failed to reset owner: {0}")]
82     ResetOwner(VhostError),
83     /// Failed to set config.
84     #[error("failed to set config: {0}")]
85     SetConfig(VhostError),
86     /// Failed to set device request channel.
87     #[error("failed to set device request channel: {0}")]
88     SetDeviceRequestChannel(VhostError),
89     /// Failed to set features.
90     #[error("failed to set features: {0}")]
91     SetFeatures(VhostError),
92     /// Failed to set memory map regions.
93     #[error("failed to set memory map regions: {0}")]
94     SetMemTable(VhostError),
95     /// Failed to set owner.
96     #[error("failed to set owner: {0}")]
97     SetOwner(VhostError),
98     /// Failed to set protocol features.
99     #[error("failed to set protocol features: {0}")]
100     SetProtocolFeatures(VhostError),
101     /// Failed to set vring address.
102     #[error("failed to set vring address: {0}")]
103     SetVringAddr(VhostError),
104     /// Failed to set vring base offset.
105     #[error("failed to set vring base offset: {0}")]
106     SetVringBase(VhostError),
107     /// Failed to set eventfd to signal used vring buffers.
108     #[error("failed to set eventfd to signal used vring buffers: {0}")]
109     SetVringCall(VhostError),
110     /// Failed to enable or disable vring.
111     #[error("failed to enable or disable vring: {0}")]
112     SetVringEnable(VhostError),
113     /// Failed to set eventfd for adding buffers to vring.
114     #[error("failed to set eventfd for adding buffers to vring: {0}")]
115     SetVringKick(VhostError),
116     /// Failed to set the size of the queue.
117     #[error("failed to set the size of the queue: {0}")]
118     SetVringNum(VhostError),
119     /// Error getting the shmem regions.
120     #[error("failed to enumerate shmem regions {0}")]
121     ShmemRegions(VhostError),
122     /// Failed to connect socket.
123     #[error("failed to connect socket: {0}")]
124     SocketConnect(std::io::Error),
125     /// Failed to create Master from a UDS path.
126     #[error("failed to connect to device socket while creating instance: {0}")]
127     SocketConnectOnMasterCreate(VhostError),
128     /// Failed to spawn worker thread.
129     #[error("failed to spawn worker: {0}")]
130     SpawnWorker(std::io::Error),
131     /// The tag for the Fs device was too long to fit in the config space.
132     #[error("tag is too long: {len} > {max}")]
133     TagTooLong { len: usize, max: usize },
134     /// Too many shmem regions.
135     #[error("too many shmem regions: {0} > 1")]
136     TooManyShmemRegions(usize),
137 }
138 
139 pub type Result<T> = std::result::Result<T, Error>;
140