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 pub mod user; 17 18 pub use self::control_socket::*; 19 20 cfg_if::cfg_if! { 21 if #[cfg(any(target_os = "android", target_os = "linux"))] { 22 #[cfg(feature = "net")] 23 mod net; 24 pub mod vsock; 25 #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] 26 pub mod scmi; 27 mod worker; 28 29 #[cfg(feature = "net")] 30 pub use self::net::Net; 31 pub use self::vsock::Vsock; 32 #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] 33 pub use self::scmi::Scmi; 34 } else if #[cfg(windows)] {} 35 } 36 37 #[sorted] 38 #[derive(Error, Debug)] 39 pub enum Error { 40 /// Cloning kill event failed. 41 #[error("failed to clone kill event: {0}")] 42 CloneKillEvent(SysError), 43 /// Creating kill event failed. 44 #[error("failed to create kill event: {0}")] 45 CreateKillEvent(SysError), 46 /// Creating tube failed. 47 #[error("failed to create tube: {0}")] 48 CreateTube(TubeError), 49 /// Creating wait context failed. 50 #[error("failed to create poll context: {0}")] 51 CreateWaitContext(SysError), 52 /// Enabling tap interface failed. 53 #[error("failed to enable tap interface: {0}")] 54 TapEnable(TapError), 55 /// Open tap device failed. 56 #[error("failed to open tap device: {0}")] 57 TapOpen(TapError), 58 /// Setting tap IP failed. 59 #[error("failed to set tap IP: {0}")] 60 TapSetIp(TapError), 61 /// Setting tap mac address failed. 62 #[error("failed to set tap mac address: {0}")] 63 TapSetMacAddress(TapError), 64 /// Setting tap netmask failed. 65 #[error("failed to set tap netmask: {0}")] 66 TapSetNetmask(TapError), 67 /// Setting tap interface offload flags failed. 68 #[error("failed to set tap interface offload flags: {0}")] 69 TapSetOffload(TapError), 70 /// Setting vnet header size failed. 71 #[error("failed to set vnet header size: {0}")] 72 TapSetVnetHdrSize(TapError), 73 /// Get features failed. 74 #[cfg(any(target_os = "android", target_os = "linux"))] 75 #[error("failed to get features: {0}")] 76 VhostGetFeatures(VhostError), 77 /// Vhost IOTLB required but not supported. 78 #[error("Vhost IOTLB required but not supported")] 79 VhostIotlbUnsupported, 80 /// Failed to create vhost event. 81 #[error("failed to create vhost event: {0}")] 82 VhostIrqCreate(SysError), 83 /// Failed to read vhost event. 84 #[error("failed to read vhost event: {0}")] 85 VhostIrqRead(SysError), 86 /// Net set backend failed. 87 #[cfg(any(target_os = "android", target_os = "linux"))] 88 #[error("net set backend failed: {0}")] 89 VhostNetSetBackend(VhostError), 90 /// Failed to open vhost device. 91 #[cfg(any(target_os = "android", target_os = "linux"))] 92 #[error("failed to open vhost device: {0}")] 93 VhostOpen(VhostError), 94 /// Set features failed. 95 #[cfg(any(target_os = "android", target_os = "linux"))] 96 #[error("failed to set features: {0}")] 97 VhostSetFeatures(VhostError), 98 /// Set mem table failed. 99 #[cfg(any(target_os = "android", target_os = "linux"))] 100 #[error("failed to set mem table: {0}")] 101 VhostSetMemTable(VhostError), 102 /// Set owner failed. 103 #[cfg(any(target_os = "android", target_os = "linux"))] 104 #[error("failed to set owner: {0}")] 105 VhostSetOwner(VhostError), 106 /// Set vring addr failed. 107 #[cfg(any(target_os = "android", target_os = "linux"))] 108 #[error("failed to set vring addr: {0}")] 109 VhostSetVringAddr(VhostError), 110 /// Set vring base failed. 111 #[cfg(any(target_os = "android", target_os = "linux"))] 112 #[error("failed to set vring base: {0}")] 113 VhostSetVringBase(VhostError), 114 /// Set vring call failed. 115 #[cfg(any(target_os = "android", target_os = "linux"))] 116 #[error("failed to set vring call: {0}")] 117 VhostSetVringCall(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 141 pub type Result<T> = std::result::Result<T, Error>; 142