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 <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-06-13 23:01:53 +08:00
parent d4212bcb74
commit 0a63aebea9

View File

@@ -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,