block: qcow_sync: impl Resizable for QcowDiskSync

Add ErrorOp::Resize variant and implement the Resizable trait.
Resize is rejected when a backing file is present.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-12 21:20:08 +01:00
committed by Rob Bradford
parent 554562fef2
commit f35bec19e8
2 changed files with 21 additions and 0 deletions

View File

@@ -68,6 +68,8 @@ pub enum ErrorOp {
DetectImageType,
/// Duplicating a backing-file descriptor.
DupBackingFd,
/// Resizing a disk image.
Resize,
}
impl Display for ErrorOp {
@@ -76,6 +78,7 @@ impl Display for ErrorOp {
Self::Open => write!(f, "open"),
Self::DetectImageType => write!(f, "detect_image_type"),
Self::DupBackingFd => write!(f, "dup_backing_fd"),
Self::Resize => write!(f, "resize"),
}
}
}

View File

@@ -308,6 +308,24 @@ impl disk_file::SparseCapable for QcowDiskSync {
}
}
impl disk_file::Resizable for QcowDiskSync {
fn resize(&mut self, size: u64) -> BlockResult<()> {
if self.backing_file.is_some() {
return Err(BlockError::new(
BlockErrorKind::UnsupportedFeature,
DiskFileError::ResizeError(io::Error::other(
"resize not supported with backing file",
)),
)
.with_op(ErrorOp::Resize));
}
self.metadata.resize(size).map_err(|e| {
BlockError::new(BlockErrorKind::Io, DiskFileError::ResizeError(e))
.with_op(ErrorOp::Resize)
})
}
}
pub struct QcowSync {
metadata: Arc<QcowMetadata>,
data_file: QcowRawFile,