Fix list updating after disk/network/hostdev hot-unplug

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()
This commit is contained in:
Mark McLoughlin 2009-08-17 15:05:22 +01:00
parent 331e1fcbee
commit 0b973381dc

View File

@ -5704,18 +5704,17 @@ try_command:
goto cleanup;
}
if (vm->def->ndisks > 1) {
vm->def->disks[i] = vm->def->disks[--vm->def->ndisks];
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);
} else {
VIR_FREE(vm->def->disks[0]);
vm->def->ndisks = 0;
}
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 (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;
}
} else {
VIR_FREE(vm->def->nets[0]);
vm->def->nnets = 0;
}
ret = 0;
cleanup:
@ -5908,16 +5906,14 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
pciFreeDevice(conn, pci);
}
if (vm->def->nhostdevs > 1) {
vm->def->hostdevs[i] = vm->def->hostdevs[--vm->def->nhostdevs];
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;
}
} else {
VIR_FREE(vm->def->hostdevs[0]);
vm->def->nhostdevs = 0;
}
return ret;
}