From 521cf5d6d3faad12671ba0f7eb5d6ed85fc20693 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 17 Dec 2019 16:14:52 -0800 Subject: [PATCH] qcow_utils: remove unused convert functions The convert_to_qcow2 and convert_to_raw functions are no longer used now that concierge's export operation exports the unmodified disk image in a tarball instead of converting it to qcow2. Remove the unused functions to clean up unreachable code. BUG=None TEST=cargo build -p qcow_utils TEST=emerge-nami crosvm vm_host_tools Change-Id: I525a9123481bd8cb6ebf022a289ecdf6e7ceaff2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1972476 Commit-Queue: Daniel Verkamp Tested-by: kokoro Reviewed-by: Dylan Reid --- qcow_utils/src/qcow_utils.h | 8 ----- qcow_utils/src/qcow_utils.rs | 57 ++---------------------------------- 2 files changed, 2 insertions(+), 63 deletions(-) diff --git a/qcow_utils/src/qcow_utils.h b/qcow_utils/src/qcow_utils.h index 90aa23baf0..79326a3841 100644 --- a/qcow_utils/src/qcow_utils.h +++ b/qcow_utils/src/qcow_utils.h @@ -17,14 +17,6 @@ int create_qcow_with_size(const char *path, uint64_t virtual_size); // the disk image is currently smaller than the requested size. int expand_disk_image(const char *path, uint64_t virtual_size); -// Copy the source disk image from `src_fd` into `dst_fd` as a qcow2 image file. -// Returns 0 on success or a negated errno value on failure. -int convert_to_qcow2(int src_fd, int dst_fd); - -// Copy the source disk image from `src_fd` into `dst_fd` as a raw image file. -// Returns 0 on success or a negated errno value on failure. -int convert_to_raw(int src_fd, int dst_fd); - #ifdef __cplusplus }; #endif diff --git a/qcow_utils/src/qcow_utils.rs b/qcow_utils/src/qcow_utils.rs index 6f11c663c0..0d77816231 100644 --- a/qcow_utils/src/qcow_utils.rs +++ b/qcow_utils/src/qcow_utils.rs @@ -4,14 +4,11 @@ // Exported interface to basic qcow functionality to be used from C. -use libc::{EBADFD, EINVAL, EIO, ENOSYS}; +use libc::{EINVAL, EIO, ENOSYS}; use std::ffi::CStr; -use std::fs::{File, OpenOptions}; +use std::fs::OpenOptions; use std::io::{Seek, SeekFrom}; -use std::mem::forget; use std::os::raw::{c_char, c_int}; -use std::os::unix::io::FromRawFd; -use std::panic::catch_unwind; use disk::ImageType; use qcow::QcowFile; @@ -106,53 +103,3 @@ pub unsafe extern "C" fn expand_disk_image(path: *const c_char, virtual_size: u6 Err(_) => -ENOSYS, } } - -#[no_mangle] -pub unsafe extern "C" fn convert_to_qcow2(src_fd: c_int, dst_fd: c_int) -> c_int { - // The caller is responsible for passing valid file descriptors. - // The caller retains ownership of the file descriptors. - let src_file = File::from_raw_fd(src_fd); - let src_file_owned = src_file.try_clone(); - forget(src_file); - - let dst_file = File::from_raw_fd(dst_fd); - let dst_file_owned = dst_file.try_clone(); - forget(dst_file); - - match (src_file_owned, dst_file_owned) { - (Ok(src_file), Ok(dst_file)) => { - catch_unwind( - || match disk::convert(src_file, dst_file, ImageType::Qcow2) { - Ok(_) => 0, - Err(_) => -EIO, - }, - ) - .unwrap_or(-EIO) - } - _ => -EBADFD, - } -} - -#[no_mangle] -pub unsafe extern "C" fn convert_to_raw(src_fd: c_int, dst_fd: c_int) -> c_int { - // The caller is responsible for passing valid file descriptors. - // The caller retains ownership of the file descriptors. - let src_file = File::from_raw_fd(src_fd); - let src_file_owned = src_file.try_clone(); - forget(src_file); - - let dst_file = File::from_raw_fd(dst_fd); - let dst_file_owned = dst_file.try_clone(); - forget(dst_file); - - match (src_file_owned, dst_file_owned) { - (Ok(src_file), Ok(dst_file)) => { - catch_unwind(|| match disk::convert(src_file, dst_file, ImageType::Raw) { - Ok(_) => 0, - Err(_) => -EIO, - }) - .unwrap_or(-EIO) - } - _ => -EBADFD, - } -}