[PATCH v2 3/9] qemu: Use qemuAssignDeviceDiskDriveAlias

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rather than open code build the drive alias command in multiple places,
use the helper to ensure consistency.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_command.c      | 12 ++++++++++--
 src/qemu/qemu_driver.c       |  3 +--
 src/qemu/qemu_hotplug.c      |  3 +--
 src/qemu/qemu_migration.c    |  9 +++------
 src/qemu/qemu_monitor_json.c |  2 +-
 src/qemu/qemu_monitor_text.c |  8 ++++++--
 6 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index affd0b0..482f993 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1245,7 +1245,11 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
     }
 
     if (emitDeviceSyntax) {
-        virBufferAsprintf(&opt, ",id=%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
+        char *drivealias = qemuAssignDeviceDiskDriveAlias(disk->info.alias);
+        if (!drivealias)
+            goto error;
+        virBufferAsprintf(&opt, ",id=%s", drivealias);
+        VIR_FREE(drivealias);
     } else {
         if (busid == -1 && unitid == -1) {
             if (idx != -1)
@@ -1607,6 +1611,7 @@ qemuBuildDriveDevStr(const virDomainDef *def,
     virBuffer opt = VIR_BUFFER_INITIALIZER;
     const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
     const char *contAlias;
+    char *drivealias;
     int controllerModel;
 
     if (qemuCheckDiskConfig(disk) < 0)
@@ -1832,7 +1837,10 @@ qemuBuildDriveDevStr(const virDomainDef *def,
         goto error;
     }
 
-    virBufferAsprintf(&opt, ",drive=%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
+    if (!(drivealias = qemuAssignDeviceDiskDriveAlias(disk->info.alias)))
+        goto error;
+    virBufferAsprintf(&opt, ",drive=%s", drivealias);
+    VIR_FREE(drivealias);
     virBufferAsprintf(&opt, ",id=%s", disk->info.alias);
     if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
         virBufferAsprintf(&opt, ",bootindex=%u", bootindex);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cda85f6..a152efc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10356,8 +10356,7 @@ qemuDomainBlockResize(virDomainPtr dom,
         disk->src->format == VIR_STORAGE_FILE_QED)
         size = VIR_ROUND_UP(size, 512);
 
-    if (virAsprintf(&device, "%s%s", QEMU_DRIVE_HOST_PREFIX,
-                    disk->info.alias) < 0)
+    if (!(device = qemuAssignDeviceDiskDriveAlias(disk->info.alias)))
         goto endjob;
 
     qemuDomainObjEnterMonitor(driver, vm);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 4f521a4..1b6e21e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2917,8 +2917,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
 
     /* build the actual drive id string as the disk->info.alias doesn't
      * contain the QEMU_DRIVE_HOST_PREFIX that is passed to qemu */
-    if (virAsprintf(&drivestr, "%s%s",
-                    QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0)
+    if (!(drivestr = qemuAssignDeviceDiskDriveAlias(disk->info.alias)))
         return -1;
 
     /* Let's look for some markers for a secret object and create an alias
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 04c847e..31d5e46 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1761,8 +1761,7 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
             continue;
 
         VIR_FREE(diskAlias);
-        if (virAsprintf(&diskAlias, "%s%s",
-                        QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0)
+        if (!(diskAlias = qemuAssignDeviceDiskDriveAlias(disk->info.alias)))
             goto cleanup;
 
         if (qemuDomainObjEnterMonitorAsync(driver, vm,
@@ -1978,8 +1977,7 @@ qemuMigrationCancelOneDriveMirror(virQEMUDriverPtr driver,
         return 1;
     }
 
-    if (virAsprintf(&diskAlias, "%s%s",
-                    QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0)
+    if (!(diskAlias = qemuAssignDeviceDiskDriveAlias(disk->info.alias)))
         return -1;
 
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
@@ -2154,8 +2152,7 @@ qemuMigrationDriveMirror(virQEMUDriverPtr driver,
         if (!qemuMigrateDisk(disk, nmigrate_disks, migrate_disks))
             continue;
 
-        if ((virAsprintf(&diskAlias, "%s%s",
-                         QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) ||
+        if (!(diskAlias = qemuAssignDeviceDiskDriveAlias(disk->info.alias)) ||
             (virAsprintf(&nbd_dest, "nbd:%s:%d:exportname=%s",
                          hoststr, port, diskAlias) < 0))
             goto cleanup;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index a54ff8d..633fb2a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3686,7 +3686,7 @@ int qemuMonitorJSONSetDrivePassphrase(qemuMonitorPtr mon,
     virJSONValuePtr reply = NULL;
     char *drive;
 
-    if (virAsprintf(&drive, "%s%s", QEMU_DRIVE_HOST_PREFIX, alias) < 0)
+    if (!(drive = qemuAssignDeviceDiskDriveAlias(alias)))
         return -1;
 
     cmd = qemuMonitorJSONMakeCommand("block_passwd",
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 6c458e2..ff92bb1 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -2001,6 +2001,7 @@ int qemuMonitorTextSetDrivePassphrase(qemuMonitorPtr mon,
 {
     char *cmd = NULL;
     char *reply = NULL;
+    char *drivealias = NULL;
     int ret = -1;
     char *safe_str;
 
@@ -2008,8 +2009,10 @@ int qemuMonitorTextSetDrivePassphrase(qemuMonitorPtr mon,
     if (!safe_str)
         return -1;
 
-    if (virAsprintf(&cmd, "block_passwd %s%s \"%s\"",
-                    QEMU_DRIVE_HOST_PREFIX, alias, safe_str) < 0)
+    if (!(drivealias = qemuAssignDeviceDiskDriveAlias(alias)))
+        goto cleanup;
+
+    if (virAsprintf(&cmd, "block_passwd %s \"%s\"", drivealias, safe_str) < 0)
         goto cleanup;
 
     if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0)
@@ -2030,6 +2033,7 @@ int qemuMonitorTextSetDrivePassphrase(qemuMonitorPtr mon,
  cleanup:
     VIR_FREE(cmd);
     VIR_FREE(reply);
+    VIR_FREE(drivealias);
     VIR_FREE(safe_str);
     return ret;
 }
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]