summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-10-15 14:58:48 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-10-31 21:59:16 -0700
commitaac28134d22a35fabca309f8149c56d60a856c02 (patch)
tree9deab1b9ad8fc4724e5e68df672e4f9a2aad9dd6 /src
parent402d53bba8f92794e322e1497115eb2d15b635df (diff)
downloadcrosvm-aac28134d22a35fabca309f8149c56d60a856c02.tar
crosvm-aac28134d22a35fabca309f8149c56d60a856c02.tar.gz
crosvm-aac28134d22a35fabca309f8149c56d60a856c02.tar.bz2
crosvm-aac28134d22a35fabca309f8149c56d60a856c02.tar.lz
crosvm-aac28134d22a35fabca309f8149c56d60a856c02.tar.xz
crosvm-aac28134d22a35fabca309f8149c56d60a856c02.tar.zst
crosvm-aac28134d22a35fabca309f8149c56d60a856c02.zip
main: merge VirtIoDeviceInfo back into Config
This was split to allow the virtio PCI transition. Now that everything
is moved over, we can put the virtio configuration back into Config.

BUG=None
TEST=Boot crosvm on kevin and verify virtio devices still work

Change-Id: I2411f5131729f84b6820aac67a92d07346f64021
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1281833
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/linux.rs18
-rw-r--r--src/main.rs128
-rw-r--r--src/plugin/mod.rs10
3 files changed, 67 insertions, 89 deletions
diff --git a/src/linux.rs b/src/linux.rs
index ae3130d..40f32a1 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -36,7 +36,6 @@ use vhost;
 use vm_control::VmRequest;
 
 use Config;
-use VirtIoDeviceInfo;
 
 use arch::{self, LinuxArch, RunnableLinuxVm, VirtioDeviceStub, VmComponents};
 
@@ -244,7 +243,7 @@ fn create_base_minijail(root: &Path, seccomp_policy: &Path) -> Result<Minijail>
 }
 
 fn create_virtio_devs(
-    cfg: VirtIoDeviceInfo,
+    cfg: Config,
     mem: &GuestMemory,
     _exit_evt: &EventFd,
     wayland_device_socket: UnixDatagram,
@@ -764,7 +763,7 @@ fn file_to_u64<P: AsRef<Path>>(path: P) -> io::Result<u64> {
 }
 
 pub fn run_config(cfg: Config) -> Result<()> {
-    if cfg.virtio_dev_info.multiprocess {
+    if cfg.multiprocess {
         // Printing something to the syslog before entering minijail so that libc's syslogger has a
         // chance to open files necessary for its operation, like `/etc/localtime`. After jailing,
         // access to those files will not be possible.
@@ -781,8 +780,8 @@ pub fn run_config(cfg: Config) -> Result<()> {
         vcpu_count: cfg.vcpu_count.unwrap_or(1),
         kernel_image: File::open(cfg.kernel_path.as_path())
             .map_err(|e| Error::OpenKernel(cfg.kernel_path.clone(), e))?,
-        extra_kernel_params: cfg.params,
-        wayland_dmabuf: cfg.virtio_dev_info.wayland_dmabuf,
+        extra_kernel_params: cfg.params.clone(),
+        wayland_dmabuf: cfg.wayland_dmabuf,
     };
 
     let mut control_sockets = Vec::new();
@@ -798,15 +797,8 @@ pub fn run_config(cfg: Config) -> Result<()> {
     let (balloon_host_socket, balloon_device_socket) =
         UnixDatagram::pair().map_err(Error::CreateSocket)?;
 
-    let virtio_dev_info = cfg.virtio_dev_info;
     let linux = Arch::build_vm(components, |m, e| {
-        create_virtio_devs(
-            virtio_dev_info,
-            m,
-            e,
-            wayland_device_socket,
-            balloon_device_socket,
-        )
+        create_virtio_devs(cfg, m, e, wayland_device_socket, balloon_device_socket)
     }).map_err(Error::BuildingVm)?;
     run_control(linux, control_sockets, balloon_host_socket, sigchld_fd)
 }
diff --git a/src/main.rs b/src/main.rs
index ea6964e..7158f67 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,9 +60,14 @@ struct DiskOption {
     read_only: bool,
 }
 
-/// Contains all the info needed to create the system's virtio devices.
-/// TODO(dgreid) - remove this once all devices are PCI based instead of MMIO.
-pub struct VirtIoDeviceInfo {
+pub struct Config {
+    vcpu_count: Option<u32>,
+    memory: Option<usize>,
+    kernel_path: PathBuf,
+    params: Vec<String>,
+    socket_path: Option<PathBuf>,
+    plugin: Option<PathBuf>,
+    plugin_root: Option<PathBuf>,
     disks: Vec<DiskOption>,
     host_ip: Option<net::Ipv4Addr>,
     netmask: Option<net::Ipv4Addr>,
@@ -78,17 +83,6 @@ pub struct VirtIoDeviceInfo {
     gpu: bool,
 }
 
-pub struct Config {
-    vcpu_count: Option<u32>,
-    memory: Option<usize>,
-    kernel_path: PathBuf,
-    params: Vec<String>,
-    socket_path: Option<PathBuf>,
-    plugin: Option<PathBuf>,
-    plugin_root: Option<PathBuf>,
-    virtio_dev_info: VirtIoDeviceInfo,
-}
-
 impl Default for Config {
     fn default() -> Config {
         Config {
@@ -99,21 +93,19 @@ impl Default for Config {
             socket_path: None,
             plugin: None,
             plugin_root: None,
-            virtio_dev_info: VirtIoDeviceInfo {
-                disks: Vec::new(),
-                host_ip: None,
-                netmask: None,
-                mac_address: None,
-                vhost_net: false,
-                tap_fd: None,
-                cid: None,
-                gpu: false,
-                wayland_socket_path: None,
-                wayland_dmabuf: false,
-                shared_dirs: Vec::new(),
-                multiprocess: !cfg!(feature = "default-no-sandbox"),
-                seccomp_policy_dir: PathBuf::from(SECCOMP_POLICY_DIR),
-            },
+            disks: Vec::new(),
+            host_ip: None,
+            netmask: None,
+            mac_address: None,
+            vhost_net: false,
+            tap_fd: None,
+            cid: None,
+            gpu: false,
+            wayland_socket_path: None,
+            wayland_dmabuf: false,
+            shared_dirs: Vec::new(),
+            multiprocess: !cfg!(feature = "default-no-sandbox"),
+            seccomp_policy_dir: PathBuf::from(SECCOMP_POLICY_DIR),
         }
     }
 }
@@ -214,28 +206,28 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 });
             }
             if name == "root" {
-                if cfg.virtio_dev_info.disks.len() >= 26 {
+                if cfg.disks.len() >= 26 {
                     return Err(argument::Error::TooManyArguments(
                         "ran out of letters for to assign to root disk".to_owned(),
                     ));
                 }
                 cfg.params.push(format!(
                     "root=/dev/vd{} ro",
-                    char::from('a' as u8 + cfg.virtio_dev_info.disks.len() as u8)
+                    char::from('a' as u8 + cfg.disks.len() as u8)
                 ));
             }
-            cfg.virtio_dev_info.disks.push(DiskOption {
+            cfg.disks.push(DiskOption {
                 path: disk_path,
                 read_only: !name.starts_with("rw"),
             });
         }
         "host_ip" => {
-            if cfg.virtio_dev_info.host_ip.is_some() {
+            if cfg.host_ip.is_some() {
                 return Err(argument::Error::TooManyArguments(
                     "`host_ip` already given".to_owned(),
                 ));
             }
-            cfg.virtio_dev_info.host_ip =
+            cfg.host_ip =
                 Some(
                     value
                         .unwrap()
@@ -247,12 +239,12 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 )
         }
         "netmask" => {
-            if cfg.virtio_dev_info.netmask.is_some() {
+            if cfg.netmask.is_some() {
                 return Err(argument::Error::TooManyArguments(
                     "`netmask` already given".to_owned(),
                 ));
             }
-            cfg.virtio_dev_info.netmask =
+            cfg.netmask =
                 Some(
                     value
                         .unwrap()
@@ -264,12 +256,12 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 )
         }
         "mac" => {
-            if cfg.virtio_dev_info.mac_address.is_some() {
+            if cfg.mac_address.is_some() {
                 return Err(argument::Error::TooManyArguments(
                     "`mac` already given".to_owned(),
                 ));
             }
-            cfg.virtio_dev_info.mac_address =
+            cfg.mac_address =
                 Some(
                     value
                         .unwrap()
@@ -281,7 +273,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 )
         }
         "wayland-sock" => {
-            if cfg.virtio_dev_info.wayland_socket_path.is_some() {
+            if cfg.wayland_socket_path.is_some() {
                 return Err(argument::Error::TooManyArguments(
                     "`wayland-sock` already given".to_owned(),
                 ));
@@ -293,10 +285,10 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                     expected: "Wayland socket does not exist",
                 });
             }
-            cfg.virtio_dev_info.wayland_socket_path = Some(wayland_socket_path);
+            cfg.wayland_socket_path = Some(wayland_socket_path);
         }
         #[cfg(feature = "wl-dmabuf")]
-        "wayland-dmabuf" => cfg.virtio_dev_info.wayland_dmabuf = true,
+        "wayland-dmabuf" => cfg.wayland_dmabuf = true,
         "socket" => {
             if cfg.socket_path.is_some() {
                 return Err(argument::Error::TooManyArguments(
@@ -316,27 +308,26 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
             cfg.socket_path = Some(socket_path);
         }
         "multiprocess" => {
-            cfg.virtio_dev_info.multiprocess = true;
+            cfg.multiprocess = true;
         }
         "disable-sandbox" => {
-            cfg.virtio_dev_info.multiprocess = false;
+            cfg.multiprocess = false;
         }
         "cid" => {
-            if cfg.virtio_dev_info.cid.is_some() {
+            if cfg.cid.is_some() {
                 return Err(argument::Error::TooManyArguments(
                     "`cid` alread given".to_owned(),
                 ));
             }
-            cfg.virtio_dev_info.cid =
-                Some(
-                    value
-                        .unwrap()
-                        .parse()
-                        .map_err(|_| argument::Error::InvalidValue {
-                            value: value.unwrap().to_owned(),
-                            expected: "this value for `cid` must be an unsigned integer",
-                        })?,
-                );
+            cfg.cid = Some(
+                value
+                    .unwrap()
+                    .parse()
+                    .map_err(|_| argument::Error::InvalidValue {
+                        value: value.unwrap().to_owned(),
+                        expected: "this value for `cid` must be an unsigned integer",
+                    })?,
+            );
         }
         "shared-dir" => {
             // Formatted as <src:tag>.
@@ -365,11 +356,11 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 });
             }
 
-            cfg.virtio_dev_info.shared_dirs.push((src, tag));
+            cfg.shared_dirs.push((src, tag));
         }
         "seccomp-policy-dir" => {
             // `value` is Some because we are in this match so it's safe to unwrap.
-            cfg.virtio_dev_info.seccomp_policy_dir = PathBuf::from(value.unwrap());
+            cfg.seccomp_policy_dir = PathBuf::from(value.unwrap());
         }
         "plugin" => {
             if !cfg.kernel_path.as_os_str().is_empty() {
@@ -393,14 +384,14 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
         "plugin-root" => {
             cfg.plugin_root = Some(PathBuf::from(value.unwrap().to_owned()));
         }
-        "vhost-net" => cfg.virtio_dev_info.vhost_net = true,
+        "vhost-net" => cfg.vhost_net = true,
         "tap-fd" => {
-            if cfg.virtio_dev_info.tap_fd.is_some() {
+            if cfg.tap_fd.is_some() {
                 return Err(argument::Error::TooManyArguments(
                     "`tap-fd` alread given".to_owned(),
                 ));
             }
-            cfg.virtio_dev_info.tap_fd =
+            cfg.tap_fd =
                 Some(
                     value
                         .unwrap()
@@ -412,7 +403,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 );
         }
         "gpu" => {
-            cfg.virtio_dev_info.gpu = true;
+            cfg.gpu = true;
         }
         "help" => return Err(argument::Error::PrintHelp),
         _ => unreachable!(),
@@ -476,21 +467,18 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
         if cfg.kernel_path.as_os_str().is_empty() && cfg.plugin.is_none() {
             return Err(argument::Error::ExpectedArgument("`KERNEL`".to_owned()));
         }
-        if cfg.virtio_dev_info.host_ip.is_some()
-            || cfg.virtio_dev_info.netmask.is_some()
-            || cfg.virtio_dev_info.mac_address.is_some()
-        {
-            if cfg.virtio_dev_info.host_ip.is_none() {
+        if cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some() {
+            if cfg.host_ip.is_none() {
                 return Err(argument::Error::ExpectedArgument(
                     "`host_ip` missing from network config".to_owned(),
                 ));
             }
-            if cfg.virtio_dev_info.netmask.is_none() {
+            if cfg.netmask.is_none() {
                 return Err(argument::Error::ExpectedArgument(
                     "`netmask` missing from network config".to_owned(),
                 ));
             }
-            if cfg.virtio_dev_info.mac_address.is_none() {
+            if cfg.mac_address.is_none() {
                 return Err(argument::Error::ExpectedArgument(
                     "`mac` missing from network config".to_owned(),
                 ));
@@ -501,10 +489,8 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
                 "`plugin-root` requires `plugin`".to_owned(),
             ));
         }
-        if cfg.virtio_dev_info.tap_fd.is_some()
-            && (cfg.virtio_dev_info.host_ip.is_some()
-                || cfg.virtio_dev_info.netmask.is_some()
-                || cfg.virtio_dev_info.mac_address.is_some())
+        if cfg.tap_fd.is_some()
+            && (cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some())
         {
             return Err(argument::Error::TooManyArguments(
                 "`tap_fd` and any of `host_ip`, `netmask`, or `mac` are mutually exclusive"
diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs
index 9f229ac..5dca8f7 100644
--- a/src/plugin/mod.rs
+++ b/src/plugin/mod.rs
@@ -464,7 +464,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
     // quickly.
     let sigchld_fd = SignalFd::new(SIGCHLD).map_err(Error::CreateSignalFd)?;
 
-    let jail = if cfg.virtio_dev_info.multiprocess {
+    let jail = if cfg.multiprocess {
         // An empty directory for jailed plugin pivot root.
         let root_path = match cfg.plugin_root {
             Some(ref dir) => Path::new(dir),
@@ -483,7 +483,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
             return Err(Error::RootNotDir);
         }
 
-        let policy_path = cfg.virtio_dev_info.seccomp_policy_dir.join("plugin.policy");
+        let policy_path = cfg.seccomp_policy_dir.join("plugin.policy");
         let jail = create_plugin_jail(root_path, &policy_path)?;
         Some(jail)
     } else {
@@ -491,9 +491,9 @@ pub fn run_config(cfg: Config) -> Result<()> {
     };
 
     let mut tap_opt: Option<Tap> = None;
-    if let Some(host_ip) = cfg.virtio_dev_info.host_ip {
-        if let Some(netmask) = cfg.virtio_dev_info.netmask {
-            if let Some(mac_address) = cfg.virtio_dev_info.mac_address {
+    if let Some(host_ip) = cfg.host_ip {
+        if let Some(netmask) = cfg.netmask {
+            if let Some(mac_address) = cfg.mac_address {
                 let tap = Tap::new(false).map_err(Error::TapOpen)?;
                 tap.set_ip_addr(host_ip).map_err(Error::TapSetIp)?;
                 tap.set_netmask(netmask).map_err(Error::TapSetNetmask)?;