diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2020-01-03 13:38:03 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-19 00:46:39 +0000 |
commit | 1ba620d8219cbda05ca170ad8ffefa76d6bb72d4 (patch) | |
tree | 5c3ae33e0800dfd4327509531b4c9bededc549dc /qcow_utils | |
parent | ed6c972994418cae6e09ad95511fe378b6057f53 (diff) | |
download | crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.tar crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.tar.gz crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.tar.bz2 crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.tar.lz crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.tar.xz crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.tar.zst crosvm-1ba620d8219cbda05ca170ad8ffefa76d6bb72d4.zip |
qcow_utils: use DiskFile trait from disk crate
Drop the local DiskFile trait definition from qcow_utils and use the one defined by the disk crate, since qcow_utils already depends on disk. In order to make the switch, use the DiskGetLen::get_len function instead of seeking to the end of the file to get the current file size. BUG=None TEST=emerge-nami crosvm TEST=cargo build -p qcow_utils Change-Id: Ie4b3b8ee0fb11ef02fbc322c5b0f9e22b0345bb0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2056991 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'qcow_utils')
-rw-r--r-- | qcow_utils/src/qcow_utils.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/qcow_utils/src/qcow_utils.rs b/qcow_utils/src/qcow_utils.rs index 97d9a94..dc9adad 100644 --- a/qcow_utils/src/qcow_utils.rs +++ b/qcow_utils/src/qcow_utils.rs @@ -7,14 +7,10 @@ use libc::{EINVAL, EIO, ENOSYS}; use std::ffi::CStr; use std::fs::OpenOptions; -use std::io::{Seek, SeekFrom}; use std::os::raw::{c_char, c_int}; -use disk::{ImageType, QcowFile}; -use sys_util::{flock, FileSetLen, FlockOperation}; - -trait DiskFile: FileSetLen + Seek {} -impl<D: FileSetLen + Seek> DiskFile for D {} +use disk::{DiskFile, ImageType, QcowFile}; +use sys_util::{flock, FlockOperation}; #[no_mangle] pub unsafe extern "C" fn create_qcow_with_size(path: *const c_char, virtual_size: u64) -> c_int { @@ -73,7 +69,7 @@ pub unsafe extern "C" fn expand_disk_image(path: *const c_char, virtual_size: u6 Err(_) => return -EINVAL, }; - let mut disk_image: Box<dyn DiskFile> = match image_type { + let disk_image: Box<dyn DiskFile> = match image_type { ImageType::Raw => Box::new(raw_image), ImageType::Qcow2 => match QcowFile::from(raw_image) { Ok(f) => Box::new(f), @@ -89,7 +85,7 @@ pub unsafe extern "C" fn expand_disk_image(path: *const c_char, virtual_size: u6 // acquired by other instances of this function as well as crosvm // itself when running a VM, so this should be safe in all cases that // can access a disk image in normal operation. - let current_size = match disk_image.seek(SeekFrom::End(0)) { + let current_size = match disk_image.get_len() { Ok(len) => len, Err(_) => return -EIO, }; |