From 92758a71d803e64ed565bd3f102c18d5b41a436c Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Wed, 10 Jul 2013 00:10:32 +0200 Subject: [PATCH] qemu: Separate controller removal into a standalone function --- src/qemu/qemu_hotplug.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f5accbdc30..d3aad2bea5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2267,6 +2267,28 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, } +static void +qemuDomainRemoveControllerDevice(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, + virDomainObjPtr vm, + virDomainControllerDefPtr controller) +{ + size_t i; + + VIR_DEBUG("Removing controller %s from domain %p %s", + controller->info.alias, vm, vm->def->name); + + for (i = 0; i < vm->def->ncontrollers; i++) { + if (vm->def->controllers[i] == controller) { + virDomainControllerRemove(vm->def, i); + break; + } + } + + qemuDomainReleaseDeviceAddress(vm, &controller->info, NULL); + virDomainControllerDefFree(controller); +} + + int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDiskDefPtr detach) @@ -2492,9 +2514,7 @@ int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver, } qemuDomainObjExitMonitor(driver, vm); - virDomainControllerRemove(vm->def, idx); - qemuDomainReleaseDeviceAddress(vm, &detach->info, NULL); - virDomainControllerDefFree(detach); + qemuDomainRemoveControllerDevice(driver, vm, detach); ret = 0;