summary refs log tree commit diff
path: root/qcow_utils
diff options
context:
space:
mode:
authorCody Schuffelen <schuffelen@google.com>2019-07-02 16:54:05 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-28 23:52:36 +0000
commit7d533e5952b6bae600441e1183964d335a41d6fe (patch)
tree6f5fc375f4d7207fc02ee20c2c683f5c67d9beca /qcow_utils
parent971589f7ec1af2904cd5a5b828e9008df9c0bba1 (diff)
downloadcrosvm-7d533e5952b6bae600441e1183964d335a41d6fe.tar
crosvm-7d533e5952b6bae600441e1183964d335a41d6fe.tar.gz
crosvm-7d533e5952b6bae600441e1183964d335a41d6fe.tar.bz2
crosvm-7d533e5952b6bae600441e1183964d335a41d6fe.tar.lz
crosvm-7d533e5952b6bae600441e1183964d335a41d6fe.tar.xz
crosvm-7d533e5952b6bae600441e1183964d335a41d6fe.tar.zst
crosvm-7d533e5952b6bae600441e1183964d335a41d6fe.zip
Extract disk creation logic out of qcow and src.
Bug: b/133432409
Change-Id: Iba25d5f6bb5f60619bb2f5a3d72ddfd3a81650b4
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691460
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'qcow_utils')
-rw-r--r--qcow_utils/Cargo.toml1
-rw-r--r--qcow_utils/src/qcow_img.rs6
-rw-r--r--qcow_utils/src/qcow_utils.rs9
3 files changed, 9 insertions, 7 deletions
diff --git a/qcow_utils/Cargo.toml b/qcow_utils/Cargo.toml
index 67b9d28..88326db 100644
--- a/qcow_utils/Cargo.toml
+++ b/qcow_utils/Cargo.toml
@@ -15,5 +15,6 @@ path = "src/qcow_img.rs"
 [dependencies]
 getopts = "*"
 libc = "*"
+disk = { path = "../disk" }
 qcow = { path = "../qcow" }
 sys_util = { path = "../sys_util" }
diff --git a/qcow_utils/src/qcow_img.rs b/qcow_utils/src/qcow_img.rs
index 66230da..08040a1 100644
--- a/qcow_utils/src/qcow_img.rs
+++ b/qcow_utils/src/qcow_img.rs
@@ -304,12 +304,12 @@ fn convert(src_path: &str, dst_path: &str) -> std::result::Result<(), ()> {
     };
 
     let dst_type = if dst_path.ends_with("qcow2") {
-        qcow::ImageType::Qcow2
+        disk::ImageType::Qcow2
     } else {
-        qcow::ImageType::Raw
+        disk::ImageType::Raw
     };
 
-    match qcow::convert(src_file, dst_file, dst_type) {
+    match disk::convert(src_file, dst_file, dst_type) {
         Ok(_) => {
             println!("Converted {} to {}", src_path, dst_path);
             Ok(())
diff --git a/qcow_utils/src/qcow_utils.rs b/qcow_utils/src/qcow_utils.rs
index 6c8b86f..4c3ede7 100644
--- a/qcow_utils/src/qcow_utils.rs
+++ b/qcow_utils/src/qcow_utils.rs
@@ -13,7 +13,8 @@ use std::os::raw::{c_char, c_int};
 use std::os::unix::io::FromRawFd;
 use std::panic::catch_unwind;
 
-use qcow::{ImageType, QcowFile};
+use disk::ImageType;
+use qcow::QcowFile;
 use sys_util::{flock, FileSetLen, FlockOperation};
 
 trait DiskFile: FileSetLen + Seek {}
@@ -71,7 +72,7 @@ pub unsafe extern "C" fn expand_disk_image(path: *const c_char, virtual_size: u6
         return -EIO;
     }
 
-    let image_type = match qcow::detect_image_type(&raw_image) {
+    let image_type = match disk::detect_image_type(&raw_image) {
         Ok(t) => t,
         Err(_) => return -EINVAL,
     };
@@ -120,7 +121,7 @@ pub unsafe extern "C" fn convert_to_qcow2(src_fd: c_int, dst_fd: c_int) -> c_int
     match (src_file_owned, dst_file_owned) {
         (Ok(src_file), Ok(dst_file)) => {
             catch_unwind(
-                || match qcow::convert(src_file, dst_file, ImageType::Qcow2) {
+                || match disk::convert(src_file, dst_file, ImageType::Qcow2) {
                     Ok(_) => 0,
                     Err(_) => -EIO,
                 },
@@ -145,7 +146,7 @@ pub unsafe extern "C" fn convert_to_raw(src_fd: c_int, dst_fd: c_int) -> c_int {
 
     match (src_file_owned, dst_file_owned) {
         (Ok(src_file), Ok(dst_file)) => {
-            catch_unwind(|| match qcow::convert(src_file, dst_file, ImageType::Raw) {
+            catch_unwind(|| match disk::convert(src_file, dst_file, ImageType::Raw) {
                 Ok(_) => 0,
                 Err(_) => -EIO,
             })