block: qcow: Implement live resize with L1 table growth

Add support for live resizing QCOW2 images. This enables growing
the virtual size of a QCOW2 disk while the VM is running.

Key features:
- Growing the image automatically expands the L1 table if needed
- Shrinking is not supported
- Resizing for images with backing files is not supported

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-02-06 21:13:52 +01:00
committed by Rob Bradford
parent caa362c31f
commit 629c117ff3
3 changed files with 168 additions and 1 deletions
+9 -1
View File
@@ -4,7 +4,7 @@
use std::collections::VecDeque;
use std::fs::File;
use std::io::{Seek, SeekFrom};
use std::io::{self, Seek, SeekFrom};
use std::os::fd::AsRawFd;
use std::sync::{Arc, Mutex};
@@ -68,6 +68,14 @@ impl DiskFile for QcowDiskSync {
Ok(Box::new(QcowSync::new(Arc::clone(&self.qcow_file))) as Box<dyn AsyncIo>)
}
fn resize(&mut self, size: u64) -> DiskFileResult<()> {
self.qcow_file
.lock()
.unwrap()
.resize(size)
.map_err(|e| DiskFileError::ResizeError(io::Error::other(e)))
}
fn fd(&mut self) -> BorrowedDiskFd<'_> {
BorrowedDiskFd::new(self.qcow_file.lock().unwrap().as_raw_fd())
}