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 use remain::sorted; 6 use thiserror::Error as ThisError; 7 use vm_memory::GuestMemoryError; 8 use vmm_vhost::message::VhostUserProtocolFeatures; 9 use vmm_vhost::Error as VhostError; 10 11 #[sorted] 12 #[derive(ThisError, Debug)] 13 pub enum Error { 14 /// Failed to copy config to a buffer. 15 #[error("failed to copy config to a buffer: {0}")] 16 CopyConfig(std::io::Error), 17 /// Failed to create backend request handler 18 #[error("could not create backend req handler: {0}")] 19 CreateBackendReqHandler(VhostError), 20 /// Failed to create `base::Event`. 21 #[error("failed to create Event: {0}")] 22 CreateEvent(base::Error), 23 /// Failed to get config. 24 #[error("failed to get config: {0}")] 25 GetConfig(VhostError), 26 /// Failed to get features. 27 #[error("failed to get features: {0}")] 28 GetFeatures(VhostError), 29 /// Failed to get host address. 30 #[error("failed to get host address: {0}")] 31 GetHostAddress(GuestMemoryError), 32 /// Failed to get protocol features. 33 #[error("failed to get protocol features: {0}")] 34 GetProtocolFeatures(VhostError), 35 /// Failed to get number of queues. 36 #[error("failed to get number of queues: {0}")] 37 GetQueueNum(VhostError), 38 /// Failed to get vring base offset. 39 #[error("failed to get vring base offset: {0}")] 40 GetVringBase(VhostError), 41 /// MSI-X config is unavailable. 42 #[error("MSI-X config is unavailable")] 43 MsixConfigUnavailable, 44 /// MSI-X irqfd is unavailable. 45 #[error("MSI-X irqfd is unavailable")] 46 MsixIrqfdUnavailable, 47 #[error("protocol feature is not negotiated: {0:?}")] 48 ProtocolFeatureNotNegoiated(VhostUserProtocolFeatures), 49 /// Failed to reset owner. 50 #[error("failed to reset owner: {0}")] 51 ResetOwner(VhostError), 52 /// Failed to restore. 53 #[error("failed to restore: {0}")] 54 Restore(VhostError), 55 /// Failed to convert serde Value to a slice. 56 #[error("failed to convert a serde Value to slice {0}")] 57 SerdeValueToSlice(serde_json::Error), 58 /// Failed to set config. 59 #[error("failed to set config: {0}")] 60 SetConfig(VhostError), 61 /// Failed to set device request channel. 62 #[error("failed to set device request channel: {0}")] 63 SetDeviceRequestChannel(VhostError), 64 /// Failed to set features. 65 #[error("failed to set features: {0}")] 66 SetFeatures(VhostError), 67 /// Failed to set memory map regions. 68 #[error("failed to set memory map regions: {0}")] 69 SetMemTable(VhostError), 70 /// Failed to set owner. 71 #[error("failed to set owner: {0}")] 72 SetOwner(VhostError), 73 /// Failed to set protocol features. 74 #[error("failed to set protocol features: {0}")] 75 SetProtocolFeatures(VhostError), 76 /// Failed to set vring address. 77 #[error("failed to set vring address: {0}")] 78 SetVringAddr(VhostError), 79 /// Failed to set vring base offset. 80 #[error("failed to set vring base offset: {0}")] 81 SetVringBase(VhostError), 82 /// Failed to set eventfd to signal used vring buffers. 83 #[error("failed to set eventfd to signal used vring buffers: {0}")] 84 SetVringCall(VhostError), 85 /// Failed to enable or disable vring. 86 #[error("failed to enable or disable vring: {0}")] 87 SetVringEnable(VhostError), 88 /// Failed to set eventfd for adding buffers to vring. 89 #[error("failed to set eventfd for adding buffers to vring: {0}")] 90 SetVringKick(VhostError), 91 /// Failed to set the size of the queue. 92 #[error("failed to set the size of the queue: {0}")] 93 SetVringNum(VhostError), 94 /// Error getting the shmem regions. 95 #[error("failed to enumerate shmem regions {0}")] 96 ShmemRegions(VhostError), 97 /// Failed to sleep the device. 98 #[error("failed to sleep the device {0}")] 99 Sleep(VhostError), 100 /// Failed to convert a slice to a serde Value. 101 #[error("Failed to convert a slice to a serde Value: {0}")] 102 SliceToSerdeValue(serde_json::Error), 103 /// Failed to snapshot. 104 #[error("failed to snapshot: {0}")] 105 Snapshot(VhostError), 106 /// Failed to connect socket. 107 #[error("failed to connect socket: {0}")] 108 SocketConnect(std::io::Error), 109 /// Failed to spawn worker thread. 110 #[error("failed to spawn worker: {0}")] 111 SpawnWorker(std::io::Error), 112 /// The tag for the Fs device was too long to fit in the config space. 113 #[error("tag is too long: {len} > {max}")] 114 TagTooLong { len: usize, max: usize }, 115 /// Too many shmem regions. 116 #[error("too many shmem regions: {0} > 1")] 117 TooManyShmemRegions(usize), 118 /// vring base from vhost-user backend is too big. 119 #[error("vring base returned by vhost-user backend is too big: {0}")] 120 VringBaseTooBig(u32), 121 /// failed to wake the vhost user device. 122 #[error("failed to wake the vhost user device.")] 123 Wake(VhostError), 124 /// failed to wake the worker. 125 #[error("failed to wake the worker.")] 126 WakeWorker, 127 } 128 129 pub type Result<T> = std::result::Result<T, Error>; 130