mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: raw_sync: Use query_device_size() for size queries
Use query_device_size() instead of seek(End(0)) and metadata().len() to correctly handle block device and regular file handles. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
f14e2d2b40
commit
290f57a6e3
@@ -4,7 +4,6 @@
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::fs::File;
|
||||
use std::io::{Seek, SeekFrom};
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
|
||||
use libc::{FALLOC_FL_KEEP_SIZE, FALLOC_FL_PUNCH_HOLE, FALLOC_FL_ZERO_RANGE};
|
||||
@@ -14,7 +13,7 @@ use vmm_sys_util::eventfd::EventFd;
|
||||
use crate::async_io::{
|
||||
AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult,
|
||||
};
|
||||
use crate::{DiskTopology, SECTOR_SIZE, probe_sparse_support};
|
||||
use crate::{DiskTopology, SECTOR_SIZE, probe_sparse_support, query_device_size};
|
||||
|
||||
pub struct RawFileDiskSync {
|
||||
file: File,
|
||||
@@ -28,16 +27,15 @@ impl RawFileDiskSync {
|
||||
|
||||
impl DiskFile for RawFileDiskSync {
|
||||
fn logical_size(&mut self) -> DiskFileResult<u64> {
|
||||
self.file
|
||||
.seek(SeekFrom::End(0))
|
||||
.map_err(DiskFileError::Size)
|
||||
Ok(query_device_size(&self.file)
|
||||
.map_err(DiskFileError::Size)?
|
||||
.0)
|
||||
}
|
||||
|
||||
fn physical_size(&mut self) -> DiskFileResult<u64> {
|
||||
self.file
|
||||
.metadata()
|
||||
.map(|m| m.len())
|
||||
.map_err(DiskFileError::Size)
|
||||
Ok(query_device_size(&self.file)
|
||||
.map_err(DiskFileError::Size)?
|
||||
.1)
|
||||
}
|
||||
|
||||
fn new_async_io(&self, _ring_depth: u32) -> DiskFileResult<Box<dyn AsyncIo>> {
|
||||
|
||||
Reference in New Issue
Block a user