Target uniqueness check was duplicated in all of the three workers
called from it. Extract it to the parent.
---
src/qemu/qemu_hotplug.c | 35 +++++++++--------------------------
1 file changed, 9 insertions(+), 26 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index fa83c6e..2e5cf64 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -315,7 +315,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
virDomainObjPtr vm,
virDomainDiskDefPtr disk)
{
- size_t i;
int ret = -1;
const char* type = virDomainDiskBusTypeToString(disk->bus);
qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -338,14 +337,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
goto cleanup;
}
- for (i = 0; i < vm->def->ndisks; i++) {
- if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("target %s already exists"), disk->dst);
- goto cleanup;
- }
- }
-
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
goto cleanup;
@@ -577,14 +568,6 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
int ret = -1;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- for (i = 0; i < vm->def->ndisks; i++) {
- if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("target %s already exists"), disk->dst);
- goto cleanup;
- }
- }
-
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
goto cleanup;
@@ -688,21 +671,12 @@ qemuDomainAttachUSBMassStorageDevice(virConnectPtr conn,
virDomainDiskDefPtr disk)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- size_t i;
int ret = -1;
char *drivestr = NULL;
char *devstr = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
const char *src = virDomainDiskGetSource(disk);
- for (i = 0; i < vm->def->ndisks; i++) {
- if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("target %s already exists"), disk->dst);
- goto cleanup;
- }
- }
-
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
goto cleanup;
@@ -770,6 +744,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
+ size_t i;
virDomainDiskDefPtr disk = dev->data.disk;
virDomainDiskDefPtr orig_disk = NULL;
int ret = -1;
@@ -818,6 +793,14 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
case VIR_DOMAIN_DISK_DEVICE_DISK:
case VIR_DOMAIN_DISK_DEVICE_LUN:
+ for (i = 0; i < vm->def->ndisks; i++) {
+ if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ _("target %s already exists"), disk->dst);
+ goto cleanup;
+ }
+ }
+
switch ((virDomainDiskBus) disk->bus) {
case VIR_DOMAIN_DISK_BUS_USB:
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
--
2.6.2