mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: raw_async_aio: 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
290f57a6e3
commit
1b92af5534
@@ -7,7 +7,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};
|
||||
@@ -18,7 +17,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 RawFileDiskAio {
|
||||
file: File,
|
||||
@@ -32,16 +31,15 @@ impl RawFileDiskAio {
|
||||
|
||||
impl DiskFile for RawFileDiskAio {
|
||||
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