summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorDylan Reid <dgreid@chromium.org>2018-01-11 09:20:16 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-19 23:29:52 -0800
commit88624f890e7e2a09c122c89f397a4d796c7680fb (patch)
treee34d9467f5a290e4d3546ab62487ce3ad63fdeea /src/linux.rs
parent76968703ad9f5c4edb4c533026ee35b6bd54a3d2 (diff)
downloadcrosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.tar
crosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.tar.gz
crosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.tar.bz2
crosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.tar.lz
crosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.tar.xz
crosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.tar.zst
crosvm-88624f890e7e2a09c122c89f397a4d796c7680fb.zip
main: Allow qcow files to be used as disks
Using qcow to allow for growable disk. These will be used for user data.

Change-Id: Iefb54eb4255db2ea7693db0020c5f1429acd73fd
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/862629
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 4ac793f..6446972 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -22,11 +22,13 @@ use io_jail::{self, Minijail};
 use kernel_cmdline;
 use kernel_loader;
 use kvm::*;
+use qcow::{self, QcowFile};
 use sys_util::*;
 use sys_util;
 use vm_control::VmRequest;
 
 use Config;
+use DiskType;
 
 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
 use x86_64;
@@ -55,6 +57,7 @@ pub enum Error {
     NetDeviceNew(devices::virtio::NetError),
     NoVarEmpty,
     OpenKernel(PathBuf, io::Error),
+    QcowDeviceCreate(qcow::Error),
     RegisterBalloon(device_manager::Error),
     RegisterBlock(device_manager::Error),
     RegisterIrqfd(sys_util::Error),
@@ -112,6 +115,9 @@ impl fmt::Display for Error {
             &Error::OpenKernel(ref p, ref e) => {
                 write!(f, "failed to open kernel image {:?}: {}", p, e)
             }
+            &Error::QcowDeviceCreate(ref e) => {
+                write!(f, "failed to read qcow formatted file {:?}", e)
+            }
             &Error::RegisterBalloon(ref e) => {
                 write!(f, "error registering balloon device: {:?}", e)
             },
@@ -290,14 +296,23 @@ fn setup_mmio_bus(cfg: &Config,
     }
 
     for disk in &cfg.disks {
-        let disk_image = OpenOptions::new()
+        let mut raw_image = OpenOptions::new()
                             .read(true)
                             .write(disk.writable)
                             .open(&disk.path)
                             .map_err(|e| Error::Disk(e))?;
-
-        let block_box = Box::new(devices::virtio::Block::new(disk_image)
-                    .map_err(|e| Error::BlockDeviceNew(e))?);
+        let block_box: Box<devices::virtio::VirtioDevice> = match disk.disk_type {
+            DiskType::FlatFile => { // Access as a raw block device.
+                Box::new(devices::virtio::Block::new(raw_image)
+                    .map_err(|e| Error::BlockDeviceNew(e))?)
+            }
+            DiskType::Qcow => { // Valid qcow header present
+                let qcow_image = QcowFile::from(raw_image)
+                    .map_err(|e| Error::QcowDeviceCreate(e))?;
+                Box::new(devices::virtio::Block::new(qcow_image)
+                    .map_err(|e| Error::BlockDeviceNew(e))?)
+            }
+        };
         let jail = if cfg.multiprocess {
             let policy_path: PathBuf = cfg.seccomp_policy_dir.join("block_device.policy");
             Some(create_base_minijail(empty_root_path, &policy_path)?)