mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 12:34:31 +00:00
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>
This commit is contained in:
parent
ed6c972994
commit
1ba620d821
1 changed files with 4 additions and 8 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue