runtime-rs: Add hotunplug_device dispatcher for device type routing

Introduce hotunplug_device() as the device-type dispatcher that routes
hot removal requests to the appropriate QMP method. Currently supports
Block and BlockModern device types, which are forwarded to
Qmp::hotunplug_block_device(). All other device types return an
explicit "unsupported" error.

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-06-13 22:39:25 +08:00
parent 281b6aa61a
commit d4212bcb74
2 changed files with 43 additions and 1 deletions

View File

@@ -931,6 +931,49 @@ impl QemuInner {
))
}
#[allow(dead_code)]
async fn hotunplug_device(&mut self, device: &DeviceType) -> Result<()> {
let qmp = match self.qmp {
Some(ref mut qmp) => qmp,
None => return Err(anyhow!("QMP not initialized")),
};
match device {
DeviceType::Block(ref block_device) => {
let block_driver = &self.config.blockdev_info.block_device_driver;
qmp.hotunplug_block_device(block_driver, block_device.config.index)
.context("hotunplug block device")?;
}
DeviceType::BlockModern(ref block_device) => {
let (index, driver) = {
let cfg = &block_device.lock().await.config;
(
cfg.index,
self.config.blockdev_info.block_device_driver.clone(),
)
};
qmp.hotunplug_block_device(&driver, index)
.context("hotunplug block device")?;
}
DeviceType::Network(_)
| DeviceType::Vfio(_)
| DeviceType::VfioModern(_)
| DeviceType::VhostUserBlk(_)
| DeviceType::VhostUserNetwork(_)
| DeviceType::ShareFs(_)
| DeviceType::HybridVsock(_)
| DeviceType::Vsock(_)
| DeviceType::Protection(_)
| DeviceType::PortDevice(_) => {
return Err(anyhow!(
"hotunplug for {} is currently unsupported",
device
));
}
}
Ok(())
}
async fn hotplug_device(&mut self, device: DeviceType) -> Result<DeviceType> {
let qmp = match self.qmp {
Some(ref mut qmp) => qmp,

View File

@@ -1036,7 +1036,6 @@ impl Qmp {
}
/// Hotunplug block device.
#[allow(dead_code)]
pub fn hotunplug_block_device(
&mut self,
block_driver: &str,