crosvm/crosvm/sys/linux/
cmdline.rs

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