[PATCH 3/9] qemu: command: Move disk index validation closer to usage

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

 



The disk index validation is used only in very specific cases and does
not need to be performed otherwise. Move it out of the global check into
the usage place.
---
 src/qemu/qemu_command.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a77a0a1fa..e663bc357 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1468,15 +1468,8 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 static int
 qemuBuildDriveStrValidate(virDomainDiskDefPtr disk,
                           virQEMUCapsPtr qemuCaps,
-                          const char *bus,
-                          int idx)
+                          const char *bus)
 {
-    if (idx < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unsupported disk type '%s'"), disk->dst);
-        return -1;
-    }
-
     switch (disk->bus) {
     case VIR_DOMAIN_DISK_BUS_SCSI:
         if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
@@ -1638,10 +1631,9 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
     const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
     const char *trans =
         virDomainDiskGeometryTransTypeToString(disk->geometry.trans);
-    int idx = virDiskNameToIndex(disk->dst);
     bool emitDeviceSyntax = qemuDiskBusNeedsDeviceArg(disk->bus);

-    if (qemuBuildDriveStrValidate(disk, qemuCaps, bus, idx) < 0)
+    if (qemuBuildDriveStrValidate(disk, qemuCaps, bus) < 0)
         goto error;

     if (qemuBuildDriveSourceStr(disk, cfg, &opt, qemuCaps) < 0)
@@ -1671,6 +1663,13 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
         virBufferAsprintf(&opt, ",id=%s", drivealias);
         VIR_FREE(drivealias);
     } else {
+        int idx = virDiskNameToIndex(disk->dst);
+
+        if (idx < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("unsupported disk type '%s'"), disk->dst);
+            goto error;
+        }
         virBufferAsprintf(&opt, ",index=%d", idx);
     }
     if (bootable &&
-- 
2.14.3

--
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]
  Powered by Linux