On Mon, Aug 17, 2009 at 03:10:14PM +0100, Mark McLoughlin wrote:
The current code makes a poor effort at updating the device arrays
after
hot-unplug. Fix that and combine the two code paths into one.
* src/qemu_driver.c: fix list updating in qemudDomainDetachNetDevice(),
qemudDomainDetachPciDiskDevice() and qemudDomainDetachHostPciDevice()
---
src/qemu_driver.c | 54 ++++++++++++++++++++++++----------------------------
1 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index d9502bb..6476644 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -5704,18 +5704,17 @@ try_command:
goto cleanup;
}
- if (vm->def->ndisks > 1) {
- vm->def->disks[i] = vm->def->disks[--vm->def->ndisks];
- if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks) < 0) {
- virReportOOMError(conn);
- goto cleanup;
- }
- qsort(vm->def->disks, vm->def->ndisks,
sizeof(*vm->def->disks),
- virDomainDiskQSort);
- } else {
- VIR_FREE(vm->def->disks[0]);
- vm->def->ndisks = 0;
+ if (i != --vm->def->ndisks)
+ memmove(&vm->def->disks[i],
+ &vm->def->disks[i+1],
+ sizeof(*vm->def->disks) * (vm->def->ndisks-i));
+ if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks) < 0) {
+ virReportOOMError(conn);
+ goto cleanup;
}
+ qsort(vm->def->disks, vm->def->ndisks, sizeof(*vm->def->disks),
+ virDomainDiskQSort);
+
ret = 0;
cleanup:
@@ -5803,16 +5802,15 @@ qemudDomainDetachNetDevice(virConnectPtr conn,
DEBUG("%s: host_net_remove reply: %s", vm->def->name, reply);
- if (vm->def->nnets > 1) {
- vm->def->nets[i] = vm->def->nets[--vm->def->nnets];
- if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets) < 0) {
- virReportOOMError(conn);
- goto cleanup;
- }
- } else {
- VIR_FREE(vm->def->nets[0]);
- vm->def->nnets = 0;
+ if (i != --vm->def->nnets)
+ memmove(&vm->def->nets[i],
+ &vm->def->nets[i+1],
+ sizeof(*vm->def->nets) * (vm->def->nnets-i));
+ if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets) < 0) {
+ virReportOOMError(conn);
+ goto cleanup;
}
+
ret = 0;
cleanup:
@@ -5908,15 +5906,13 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
pciFreeDevice(conn, pci);
}
- if (vm->def->nhostdevs > 1) {
- vm->def->hostdevs[i] =
vm->def->hostdevs[--vm->def->nhostdevs];
- if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs) < 0) {
- virReportOOMError(conn);
- ret = -1;
- }
- } else {
- VIR_FREE(vm->def->hostdevs[0]);
- vm->def->nhostdevs = 0;
+ if (i != --vm->def->nhostdevs)
+ memmove(&vm->def->hostdevs[i],
+ &vm->def->hostdevs[i+1],
+ sizeof(*vm->def->hostdevs) * (vm->def->nhostdevs-i));
+ if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs) < 0) {
+ virReportOOMError(conn);
+ ret = -1;
}
return ret;
ACK, I've actually got much the same patch pending in my queue too.
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|