From 3e536f91eb192ac0b457be43542fde5cf187a704 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sun, 5 Dec 2021 16:54:31 +0000 Subject: [PATCH] block_util: drop disk_size It is only used by qcow_sync code. Merge it to its caller. No functional change. Signed-off-by: Wei Liu --- block_util/src/lib.rs | 10 +--------- block_util/src/qcow_sync.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block_util/src/lib.rs b/block_util/src/lib.rs index 8cd7079e5..fc9eebfdf 100644 --- a/block_util/src/lib.rs +++ b/block_util/src/lib.rs @@ -20,7 +20,7 @@ pub mod raw_sync; pub mod vhd; pub mod vhdx_sync; -use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult, DiskFileError, DiskFileResult}; +use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult}; #[cfg(feature = "io_uring")] use io_uring::{opcode, IoUring, Probe}; use std::cmp; @@ -476,14 +476,6 @@ pub fn block_io_uring_is_supported() -> bool { false } -pub fn disk_size(file: &mut dyn Seek, semaphore: &mut Arc>) -> DiskFileResult { - // Take the semaphore to ensure other threads are not interacting with - // the underlying file. - let _lock = semaphore.lock().unwrap(); - - Ok(file.seek(SeekFrom::End(0)).map_err(DiskFileError::Size)? as u64) -} - pub trait ReadSeekFile: Read + Seek {} impl ReadSeekFile for F {} diff --git a/block_util/src/qcow_sync.rs b/block_util/src/qcow_sync.rs index 1c5229ed7..f3d749c32 100644 --- a/block_util/src/qcow_sync.rs +++ b/block_util/src/qcow_sync.rs @@ -2,10 +2,11 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause -use crate::async_io::{AsyncIo, AsyncIoResult, DiskFile, DiskFileResult}; -use crate::{disk_size, fsync_sync, read_vectored_sync, write_vectored_sync}; +use crate::async_io::{AsyncIo, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult}; +use crate::{fsync_sync, read_vectored_sync, write_vectored_sync}; use qcow::{QcowFile, RawFile, Result as QcowResult}; use std::fs::File; +use std::io::{Seek, SeekFrom}; use std::sync::{Arc, Mutex}; use vmm_sys_util::eventfd::EventFd; @@ -25,7 +26,14 @@ impl QcowDiskSync { impl DiskFile for QcowDiskSync { fn size(&mut self) -> DiskFileResult { - disk_size(&mut self.qcow_file, &mut self.semaphore) + // Take the semaphore to ensure other threads are not interacting with + // the underlying file. + let _lock = self.semaphore.lock().unwrap(); + + Ok(self + .qcow_file + .seek(SeekFrom::End(0)) + .map_err(DiskFileError::Size)? as u64) } fn new_async_io(&self, _ring_depth: u32) -> DiskFileResult> {