mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: raw_file: Use query_device_size() for size queries
Use query_device_size() instead of 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
1b92af5534
commit
8b6eb83f2a
@@ -20,7 +20,7 @@ use vmm_sys_util::file_traits::FileSync;
|
|||||||
use vmm_sys_util::seek_hole::SeekHole;
|
use vmm_sys_util::seek_hole::SeekHole;
|
||||||
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};
|
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};
|
||||||
|
|
||||||
use crate::BlockBackend;
|
use crate::{BlockBackend, query_device_size};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RawFile {
|
pub struct RawFile {
|
||||||
@@ -374,11 +374,15 @@ impl SeekHole for RawFile {
|
|||||||
|
|
||||||
impl BlockBackend for RawFile {
|
impl BlockBackend for RawFile {
|
||||||
fn logical_size(&self) -> std::result::Result<u64, crate::Error> {
|
fn logical_size(&self) -> std::result::Result<u64, crate::Error> {
|
||||||
Ok(self.metadata().map_err(crate::Error::RawFileError)?.len())
|
Ok(query_device_size(&self.file)
|
||||||
|
.map_err(crate::Error::RawFileError)?
|
||||||
|
.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn physical_size(&self) -> std::result::Result<u64, crate::Error> {
|
fn physical_size(&self) -> std::result::Result<u64, crate::Error> {
|
||||||
Ok(self.metadata().map_err(crate::Error::RawFileError)?.len())
|
Ok(query_device_size(&self.file)
|
||||||
|
.map_err(crate::Error::RawFileError)?
|
||||||
|
.1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user