vmm: disk resize infrastructure

Add basic infrastructure so resize events are
propagated to the underlying disk implementation.

On-behalf-of: SAP thomas.prescher@sap.com
Signed-off-by: Thomas Prescher <thomas.prescher@cyberus-technology.de>
This commit is contained in:
Thomas Prescher
2025-11-11 09:40:16 +01:00
committed by Rob Bradford
parent 8e52bf251b
commit 37d71fa038
7 changed files with 94 additions and 1 deletions

View File

@@ -315,6 +315,8 @@ pub trait RequestHandler {
fn vm_resize_zone(&mut self, id: String, desired_ram: u64) -> Result<(), VmError>;
fn vm_resize_disk(&mut self, id: String, desired_size: u64) -> Result<(), VmError>;
fn vm_add_device(&mut self, device_cfg: DeviceConfig) -> Result<Option<Vec<u8>>, VmError>;
fn vm_add_user_device(

View File

@@ -670,6 +670,10 @@ pub enum DeviceManagerError {
/// Error adding fw_cfg to bus.
#[error("Error adding fw_cfg to bus")]
ErrorAddingFwCfgToBus(#[source] vm_device::BusError),
/// Disk resizing failed.
#[error("Disk resize error")]
DiskResize(#[source] virtio_devices::block::Error),
}
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
@@ -4901,6 +4905,18 @@ impl DeviceManager {
0
}
pub fn resize_disk(&mut self, device_id: &str, new_size: u64) -> DeviceManagerResult<()> {
for dev in &self.block_devices {
let mut disk = dev.lock().unwrap();
if disk.id() == device_id {
return disk
.resize(new_size)
.map_err(DeviceManagerError::DiskResize);
}
}
Err(DeviceManagerError::UnknownDeviceId(device_id.to_string()))
}
pub fn device_tree(&self) -> Arc<Mutex<DeviceTree>> {
self.device_tree.clone()
}

View File

@@ -1962,6 +1962,16 @@ impl RequestHandler for Vmm {
}
}
fn vm_resize_disk(&mut self, id: String, desired_size: u64) -> result::Result<(), VmError> {
self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;
if let Some(ref mut vm) = self.vm {
return vm.resize_disk(&id, desired_size);
}
Err(VmError::ResizeDisk)
}
fn vm_resize_zone(&mut self, id: String, desired_ram: u64) -> result::Result<(), VmError> {
self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;

View File

@@ -246,6 +246,9 @@ pub enum Error {
#[error("Failed resizing a memory zone")]
ResizeZone,
#[error("Failed resizing a disk image")]
ResizeDisk,
#[error("Cannot activate virtio devices")]
ActivateVirtioDevices(#[source] DeviceManagerError),
@@ -1706,6 +1709,16 @@ impl Vm {
Ok(())
}
pub fn resize_disk(&mut self, id: &str, desired_size: u64) -> Result<()> {
self.device_manager
.lock()
.unwrap()
.resize_disk(id, desired_size)
.map_err(Error::DeviceManager)?;
Ok(())
}
pub fn resize_zone(&mut self, id: &str, desired_memory: u64) -> Result<()> {
let memory_config = &mut self.config.lock().unwrap().memory;