diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 165 |
1 files changed, 15 insertions, 150 deletions
diff --git a/src/main.rs b/src/main.rs index 78dfbf2..1d18c3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,16 +4,10 @@ //! Runs a virtual machine under KVM -pub mod argument; -pub mod linux; pub mod panic_hook; -#[cfg(feature = "plugin")] -pub mod plugin; -use std::collections::BTreeMap; use std::fmt; use std::fs::{File, OpenOptions}; -use std::net; use std::num::ParseIntError; use std::os::unix::io::{FromRawFd, RawFd}; use std::path::{Path, PathBuf}; @@ -21,6 +15,10 @@ use std::string::String; use std::thread::sleep; use std::time::Duration; +use crosvm::{ + argument::{self, print_help, set_arguments, Argument}, + linux, BindMount, Config, DiskOption, Executable, GidMap, TouchDeviceOption, +}; use devices::{SerialParameters, SerialType}; use msg_socket::{MsgReceiver, MsgSender, MsgSocket}; use qcow::QcowFile; @@ -33,55 +31,6 @@ use vm_control::{ VmControlRequestSocket, VmRequest, VmResponse, USB_CONTROL_MAX_PORTS, }; -use crate::argument::{print_help, set_arguments, Argument}; - -static SECCOMP_POLICY_DIR: &'static str = "/usr/share/policy/crosvm"; - -struct DiskOption { - path: PathBuf, - read_only: bool, -} - -#[allow(dead_code)] -struct BindMount { - src: PathBuf, - dst: PathBuf, - writable: bool, -} - -#[allow(dead_code)] -struct GidMap { - inner: libc::gid_t, - outer: libc::gid_t, - count: u32, -} - -const DEFAULT_TOUCH_DEVICE_WIDTH: u32 = 800; -const DEFAULT_TOUCH_DEVICE_HEIGHT: u32 = 1280; - -struct TouchDeviceOption { - path: PathBuf, - width: u32, - height: u32, -} - -impl TouchDeviceOption { - fn new(path: PathBuf) -> TouchDeviceOption { - TouchDeviceOption { - path, - width: DEFAULT_TOUCH_DEVICE_WIDTH, - height: DEFAULT_TOUCH_DEVICE_HEIGHT, - } - } -} - -#[derive(Debug)] -pub enum Executable { - Bios(PathBuf), - Kernel(PathBuf), - Plugin(PathBuf), -} - fn executable_is_plugin(executable: &Option<Executable>) -> bool { match executable { Some(Executable::Plugin(_)) => true, @@ -89,92 +38,6 @@ fn executable_is_plugin(executable: &Option<Executable>) -> bool { } } -pub struct Config { - vcpu_count: Option<u32>, - vcpu_affinity: Vec<usize>, - memory: Option<usize>, - executable_path: Option<Executable>, - android_fstab: Option<PathBuf>, - initrd_path: Option<PathBuf>, - params: Vec<String>, - socket_path: Option<PathBuf>, - plugin_root: Option<PathBuf>, - plugin_mounts: Vec<BindMount>, - plugin_gid_maps: Vec<GidMap>, - disks: Vec<DiskOption>, - pmem_devices: Vec<DiskOption>, - host_ip: Option<net::Ipv4Addr>, - netmask: Option<net::Ipv4Addr>, - mac_address: Option<net_util::MacAddress>, - vhost_net: bool, - tap_fd: Vec<RawFd>, - cid: Option<u64>, - wayland_socket_path: Option<PathBuf>, - wayland_dmabuf: bool, - shared_dirs: Vec<(PathBuf, String)>, - sandbox: bool, - seccomp_policy_dir: PathBuf, - seccomp_log_failures: bool, - gpu: bool, - software_tpm: bool, - cras_audio: bool, - cras_capture: bool, - null_audio: bool, - serial_parameters: BTreeMap<u8, SerialParameters>, - syslog_tag: Option<String>, - virtio_single_touch: Option<TouchDeviceOption>, - virtio_trackpad: Option<TouchDeviceOption>, - virtio_mouse: Option<PathBuf>, - virtio_keyboard: Option<PathBuf>, - virtio_input_evdevs: Vec<PathBuf>, - split_irqchip: bool, -} - -impl Default for Config { - fn default() -> Config { - Config { - vcpu_count: None, - vcpu_affinity: Vec::new(), - memory: None, - executable_path: None, - android_fstab: None, - initrd_path: None, - params: Vec::new(), - socket_path: None, - plugin_root: None, - plugin_mounts: Vec::new(), - plugin_gid_maps: Vec::new(), - disks: Vec::new(), - pmem_devices: Vec::new(), - host_ip: None, - netmask: None, - mac_address: None, - vhost_net: false, - tap_fd: Vec::new(), - cid: None, - gpu: false, - software_tpm: false, - wayland_socket_path: None, - wayland_dmabuf: false, - shared_dirs: Vec::new(), - sandbox: !cfg!(feature = "default-no-sandbox"), - seccomp_policy_dir: PathBuf::from(SECCOMP_POLICY_DIR), - seccomp_log_failures: false, - cras_audio: false, - cras_capture: false, - null_audio: false, - serial_parameters: BTreeMap::new(), - syslog_tag: None, - virtio_single_touch: None, - virtio_trackpad: None, - virtio_mouse: None, - virtio_keyboard: None, - virtio_input_evdevs: Vec::new(), - split_irqchip: false, - } - } -} - // Wait for all children to exit. Return true if they have all exited, false // otherwise. fn wait_all_children() -> bool { @@ -939,16 +802,18 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> { match match_res { #[cfg(feature = "plugin")] - Ok(()) if executable_is_plugin(&cfg.executable_path) => match plugin::run_config(cfg) { - Ok(_) => { - info!("crosvm and plugin have exited normally"); - Ok(()) - } - Err(e) => { - error!("{}", e); - Err(()) + Ok(()) if executable_is_plugin(&cfg.executable_path) => { + match crosvm::plugin::run_config(cfg) { + Ok(_) => { + info!("crosvm and plugin have exited normally"); + Ok(()) + } + Err(e) => { + error!("{}", e); + Err(()) + } } - }, + } Ok(()) => match linux::run_config(cfg) { Ok(_) => { info!("crosvm has exited normally"); |