From d4212bcb74886344ab16489e4fed4e2effd93ec4 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Sat, 13 Jun 2026 22:39:25 +0800 Subject: [PATCH] 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 --- .../crates/hypervisor/src/qemu/inner.rs | 43 +++++++++++++++++++ .../crates/hypervisor/src/qemu/qmp.rs | 1 - 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs index 655de37d69..6a16ab6faf 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs @@ -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 { let qmp = match self.qmp { Some(ref mut qmp) => qmp, diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs b/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs index 8595d630d6..eda604ac3b 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs @@ -1036,7 +1036,6 @@ impl Qmp { } /// Hotunplug block device. - #[allow(dead_code)] pub fn hotunplug_block_device( &mut self, block_driver: &str,