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 use std::path::PathBuf;
6
7 use argh::FromArgValue;
8 use argh::FromArgs;
9 use cros_async::ExecutorKind;
10 use devices::virtio::block::DiskOption;
11 use devices::virtio::vhost::user::device;
12 use devices::virtio::vhost::user::VhostUserParams;
13 use devices::virtio::vsock::VsockConfig;
14 #[cfg(feature = "net")]
15 use devices::virtio::NetParameters;
16 use devices::SerialParameters;
17 use jail::JailConfig;
18
19 use crate::crosvm::config::validate_serial_parameters;
20
21 #[derive(FromArgs)]
22 #[argh(subcommand)]
23 /// Unix Devices
24 pub enum DeviceSubcommand {
25 Console(device::ConsoleOptions),
26 Fs(device::FsOptions),
27 Vsock(device::VsockOptions),
28 Wl(device::WlOptions),
29 }
30
parse_vu_serial_options(s: &str) -> Result<VhostUserParams<SerialParameters>, String>31 fn parse_vu_serial_options(s: &str) -> Result<VhostUserParams<SerialParameters>, String> {
32 let params = VhostUserParams::<SerialParameters>::from_arg_value(s)?;
33
34 validate_serial_parameters(¶ms.device)?;
35
36 Ok(params)
37 }
38
39 #[argh_helpers::pad_description_for_argh]
40 #[derive(FromArgs, Debug)]
41 #[argh(subcommand, name = "devices")]
42 /// Start one or several jailed device processes.
43 pub struct DevicesCommand {
44 /// configure async executor backend to "uring" or "epoll" (default).
45 #[argh(option, arg_name = "EXECUTOR")]
46 pub async_executor: Option<ExecutorKind>,
47
48 #[argh(switch)]
49 /// disable sandboxing. Will nullify the --jail option if it was present.
50 pub disable_sandbox: bool,
51
52 #[argh(
53 option,
54 arg_name = "jail configuration",
55 default = "Default::default()"
56 )]
57 /// set up the jail configuration.
58 /// Possible key values:
59 /// pivot-root=/path - Path to empty directory to use for
60 /// sandbox pivot root.
61 /// seccomp-policy-dir=/path - Path to seccomp .policy files
62 /// seccomp-log-failures=(true|false) - Log seccomp filter
63 /// failures instead of them being fatal.
64 pub jail: JailConfig,
65
66 #[argh(
67 option,
68 arg_name = "vhost=PATH,type=TYPE,[hardware=HW,num=NUM,path=PATH,input=PATH,console,earlycon,stdin,pci-address=ADDR]",
69 from_str_fn(parse_vu_serial_options)
70 )]
71 /// start a serial device.
72 /// Possible key values:
73 /// vhost=PATH - Path to a vhost-user socket to listen to.
74 /// This parameter must be given in first position.
75 /// type=(stdout,syslog,sink,file) - Where to route the
76 /// serial device
77 /// hardware=(serial,virtio-console) - Which type of serial
78 /// hardware to emulate. Defaults to 8250 UART (serial).
79 /// num=(1,2,3,4) - Serial Device Number. If not provided,
80 /// num will default to 1.
81 /// path=PATH - The path to the file to write to when
82 /// type=file
83 /// input=PATH - The path to the file to read from when not
84 /// stdin
85 /// console - Use this serial device as the guest console.
86 /// Can only be given once. Will default to first
87 /// serial port if not provided.
88 /// earlycon - Use this serial device as the early console.
89 /// Can only be given once.
90 /// stdin - Direct standard input to this serial device.
91 /// Can only be given once. Will default to first serial
92 /// port if not provided.
93 /// pci-address - Preferred PCI address, e.g. "00:01.0".
94 /// Only applies to virtio-console hardware type.
95 pub serial: Vec<VhostUserParams<SerialParameters>>,
96
97 #[argh(option, arg_name = "vhost=PATH[, block options]")]
98 /// start a block device.
99 /// Possible key values:
100 /// vhost=PATH - Path to a vhost-user socket to listen to.
101 /// This parameter must be given in first position.
102 /// block options:
103 /// See help from `crosvm run` command.
104 pub block: Vec<VhostUserParams<DiskOption>>,
105
106 #[argh(option, arg_name = "vhost=PATH,cid=CID[,device=VHOST_DEVICE]")]
107 /// start a vsock device.
108 /// Possible key values:
109 /// vhost=PATH - Path to a vhost-user socket to listen to.
110 /// This parameter must be given in first position.
111 /// cid=CID - CID to use for the device.
112 /// device=VHOST_DEVICE - path to the vhost-vsock device to
113 /// use (Linux only). Defaults to /dev/vhost-vsock.
114 pub vsock: Vec<VhostUserParams<VsockConfig>>,
115
116 #[cfg(feature = "net")]
117 #[argh(option, arg_name = "net options")]
118 /// start a network device.
119 /// Possible key values:
120 /// vhost=PATH - Path to a vhost-user socket to listen to.
121 /// This parameter must be given in first position.
122 /// network options:
123 /// See help from the `crosvm run` command.
124 pub net: Vec<VhostUserParams<NetParameters>>,
125
126 #[argh(option, short = 's', arg_name = "PATH")]
127 /// path to put the control socket.
128 pub control_socket: Option<PathBuf>,
129 }
130
131 #[derive(FromArgs)]
132 #[argh(subcommand)]
133 /// Unix Commands
134 pub enum Commands {
135 #[cfg(any(target_os = "android", target_os = "linux"))]
136 Devices(DevicesCommand),
137 }
138