mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Implement DiskSize trait for RawFileDisk
Add disk_file::DiskSize trait implementation for RawFileDisk using BlockError and BlockResult. Uses metadata().len() instead of seek(SeekFrom::End(0)), taking &self instead of &mut self. Add BlockError, BlockErrorKind, BlockResult, and disk_file imports needed by this and subsequent trait impls. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
@@ -14,8 +14,10 @@ use vmm_sys_util::eventfd::EventFd;
|
||||
use crate::async_io::{
|
||||
AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult,
|
||||
};
|
||||
use crate::error::{BlockError, BlockErrorKind, BlockResult};
|
||||
use crate::{
|
||||
BatchRequest, DiskTopology, RequestType, SECTOR_SIZE, probe_sparse_support, query_device_size,
|
||||
BatchRequest, DiskTopology, RequestType, SECTOR_SIZE, disk_file, probe_sparse_support,
|
||||
query_device_size,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -72,6 +74,14 @@ impl DiskFile for RawFileDisk {
|
||||
}
|
||||
}
|
||||
|
||||
impl disk_file::DiskSize for RawFileDisk {
|
||||
fn logical_size(&self) -> BlockResult<u64> {
|
||||
query_device_size(&self.file)
|
||||
.map(|(logical_size, _)| logical_size)
|
||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::Size(e)))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RawFileAsync {
|
||||
fd: RawFd,
|
||||
io_uring: IoUring,
|
||||
|
||||
Reference in New Issue
Block a user