From 0a63aebea93fb8317dca27cff37d013b56d41231 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Sat, 13 Jun 2026 23:01:53 +0800 Subject: [PATCH] runtime-rs: Implement remove_device for block device hot removal Replace the "Not yet implemented" stub in QemuInner::remove_device() with a working implementation that calls hotunplug_device() to perform the QMP-level device removal, then cleans up the internal devices list via retain() to remove stale coldplug entries. Signed-off-by: Alex Lyn --- src/runtime-rs/crates/hypervisor/src/qemu/inner.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs index 6a16ab6faf..2661cb0233 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs @@ -925,13 +925,17 @@ impl QemuInner { pub(crate) async fn remove_device(&mut self, device: DeviceType) -> Result<()> { info!(sl!(), "QemuInner::remove_device() {} ", device); - Err(anyhow!( - "QemuInner::remove_device({}): Not yet implemented", - device - )) + self.hotunplug_device(&device).await?; + + self.devices.retain(|d| match (d, &device) { + (DeviceType::Block(a), DeviceType::Block(b)) => a.config.index != b.config.index, + (DeviceType::BlockModern(a), DeviceType::BlockModern(b)) => !std::sync::Arc::ptr_eq(a, b), + _ => true, + }); + + Ok(()) } - #[allow(dead_code)] async fn hotunplug_device(&mut self, device: &DeviceType) -> Result<()> { let qmp = match self.qmp { Some(ref mut qmp) => qmp,