• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
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 std::fmt::{self, Display};
8 
9 use base::{Error as SysError, TubeError};
10 use net_util::Error as TapError;
11 use remain::sorted;
12 use vhost::Error as VhostError;
13 
14 mod control_socket;
15 mod net;
16 pub mod user;
17 mod vsock;
18 mod worker;
19 
20 pub use self::control_socket::*;
21 pub use self::net::Net;
22 pub use self::vsock::Vsock;
23 
24 #[sorted]
25 #[derive(Debug)]
26 pub enum Error {
27     /// Cloning kill event failed.
28     CloneKillEvent(SysError),
29     /// Creating kill event failed.
30     CreateKillEvent(SysError),
31     /// Creating tube failed.
32     CreateTube(TubeError),
33     /// Creating wait context failed.
34     CreateWaitContext(SysError),
35     /// Enabling tap interface failed.
36     TapEnable(TapError),
37     /// Open tap device failed.
38     TapOpen(TapError),
39     /// Setting tap IP failed.
40     TapSetIp(TapError),
41     /// Setting tap mac address failed.
42     TapSetMacAddress(TapError),
43     /// Setting tap netmask failed.
44     TapSetNetmask(TapError),
45     /// Setting tap interface offload flags failed.
46     TapSetOffload(TapError),
47     /// Setting vnet header size failed.
48     TapSetVnetHdrSize(TapError),
49     /// Get features failed.
50     VhostGetFeatures(VhostError),
51     /// Failed to create vhost event.
52     VhostIrqCreate(SysError),
53     /// Failed to read vhost event.
54     VhostIrqRead(SysError),
55     /// Net set backend failed.
56     VhostNetSetBackend(VhostError),
57     /// Failed to open vhost device.
58     VhostOpen(VhostError),
59     /// Set features failed.
60     VhostSetFeatures(VhostError),
61     /// Set mem table failed.
62     VhostSetMemTable(VhostError),
63     /// Set owner failed.
64     VhostSetOwner(VhostError),
65     /// Set vring addr failed.
66     VhostSetVringAddr(VhostError),
67     /// Set vring base failed.
68     VhostSetVringBase(VhostError),
69     /// Set vring call failed.
70     VhostSetVringCall(VhostError),
71     /// Set vring kick failed.
72     VhostSetVringKick(VhostError),
73     /// Set vring num failed.
74     VhostSetVringNum(VhostError),
75     /// Failed to set CID for guest.
76     VhostVsockSetCid(VhostError),
77     /// Failed to start vhost-vsock driver.
78     VhostVsockStart(VhostError),
79     /// Error while waiting for events.
80     WaitError(SysError),
81 }
82 
83 pub type Result<T> = std::result::Result<T, Error>;
84 
85 impl Display for Error {
86     #[remain::check]
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result87     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
88         use self::Error::*;
89 
90         #[sorted]
91         match self {
92             CloneKillEvent(e) => write!(f, "failed to clone kill event: {}", e),
93             CreateKillEvent(e) => write!(f, "failed to create kill event: {}", e),
94             CreateTube(e) => write!(f, "failed to create tube: {}", e),
95             CreateWaitContext(e) => write!(f, "failed to create poll context: {}", e),
96             TapEnable(e) => write!(f, "failed to enable tap interface: {}", e),
97             TapOpen(e) => write!(f, "failed to open tap device: {}", e),
98             TapSetIp(e) => write!(f, "failed to set tap IP: {}", e),
99             TapSetMacAddress(e) => write!(f, "failed to set tap mac address: {}", e),
100             TapSetNetmask(e) => write!(f, "failed to set tap netmask: {}", e),
101             TapSetOffload(e) => write!(f, "failed to set tap interface offload flags: {}", e),
102             TapSetVnetHdrSize(e) => write!(f, "failed to set vnet header size: {}", e),
103             VhostGetFeatures(e) => write!(f, "failed to get features: {}", e),
104             VhostIrqCreate(e) => write!(f, "failed to create vhost event: {}", e),
105             VhostIrqRead(e) => write!(f, "failed to read vhost event: {}", e),
106             VhostNetSetBackend(e) => write!(f, "net set backend failed: {}", e),
107             VhostOpen(e) => write!(f, "failed to open vhost device: {}", e),
108             VhostSetFeatures(e) => write!(f, "failed to set features: {}", e),
109             VhostSetMemTable(e) => write!(f, "failed to set mem table: {}", e),
110             VhostSetOwner(e) => write!(f, "failed to set owner: {}", e),
111             VhostSetVringAddr(e) => write!(f, "failed to set vring addr: {}", e),
112             VhostSetVringBase(e) => write!(f, "failed to set vring base: {}", e),
113             VhostSetVringCall(e) => write!(f, "failed to set vring call: {}", e),
114             VhostSetVringKick(e) => write!(f, "failed to set vring kick: {}", e),
115             VhostSetVringNum(e) => write!(f, "failed to set vring num: {}", e),
116             VhostVsockSetCid(e) => write!(f, "failed to set CID for guest: {}", e),
117             VhostVsockStart(e) => write!(f, "failed to start vhost-vsock driver: {}", e),
118             WaitError(e) => write!(f, "failed waiting for events: {}", e),
119         }
120     }
121 }
122