Blame SOURCES/libvirt-qemu-command-Refactor-code-extracted-to-qemuBuildDriveSourceStr.patch

6ae9ed
From 6dda778b55b7508e626635fa67d8f727167a8bed Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <6dda778b55b7508e626635fa67d8f727167a8bed@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Tue, 2 Aug 2016 13:42:00 +0200
6ae9ed
Subject: [PATCH] qemu: command: Refactor code extracted to
6ae9ed
 qemuBuildDriveSourceStr
6ae9ed
6ae9ed
Avoid a large block by tweaking the condition skipping empty drives and
6ae9ed
split up the switch containing two branches having different purpose.
6ae9ed
6ae9ed
(cherry picked from commit 1575f3e8d32b6049ec399cfb54ab36f4d0a0cb00)
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host]
6ae9ed
---
6ae9ed
 src/qemu/qemu_command.c | 119 +++++++++++++++++++++++-------------------------
6ae9ed
 1 file changed, 57 insertions(+), 62 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
6ae9ed
index bb40832..a3e838c 100644
6ae9ed
--- a/src/qemu/qemu_command.c
6ae9ed
+++ b/src/qemu/qemu_command.c
6ae9ed
@@ -1107,70 +1107,65 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
6ae9ed
     if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
-    if (source &&
6ae9ed
-        !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
6ae9ed
-           disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
6ae9ed
-          disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
6ae9ed
-
6ae9ed
-        virBufferAddLit(buf, "file=");
6ae9ed
-
6ae9ed
-        switch (actualType) {
6ae9ed
-        case VIR_STORAGE_TYPE_DIR:
6ae9ed
-            /* QEMU only supports magic FAT format for now */
6ae9ed
-            if (disk->src->format > 0 &&
6ae9ed
-                disk->src->format != VIR_STORAGE_FILE_FAT) {
6ae9ed
-                virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
-                               _("unsupported disk driver type for '%s'"),
6ae9ed
-                               virStorageFileFormatTypeToString(disk->src->format));
6ae9ed
-                goto cleanup;
6ae9ed
-            }
6ae9ed
-
6ae9ed
-            if (!disk->src->readonly) {
6ae9ed
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
6ae9ed
-                               _("cannot create virtual FAT disks in read-write mode"));
6ae9ed
-                goto cleanup;
6ae9ed
-            }
6ae9ed
-
6ae9ed
-            virBufferAddLit(buf, "fat:");
6ae9ed
-
6ae9ed
-            if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
6ae9ed
-                virBufferAddLit(buf, "floppy:");
6ae9ed
-
6ae9ed
-            break;
6ae9ed
-
6ae9ed
-        case VIR_STORAGE_TYPE_BLOCK:
6ae9ed
-            if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
6ae9ed
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
-                               disk->src->type == VIR_STORAGE_TYPE_VOLUME ?
6ae9ed
-                               _("tray status 'open' is invalid for block type volume") :
6ae9ed
-                               _("tray status 'open' is invalid for block type disk"));
6ae9ed
-                goto cleanup;
6ae9ed
-            }
6ae9ed
-
6ae9ed
-            break;
6ae9ed
-
6ae9ed
-        default:
6ae9ed
-            break;
6ae9ed
-        }
6ae9ed
-
6ae9ed
-        virQEMUBuildBufferEscapeComma(buf, source);
6ae9ed
-        virBufferAddLit(buf, ",");
6ae9ed
-
6ae9ed
-        if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
6ae9ed
-            virBufferAsprintf(buf, "password-secret=%s,",
6ae9ed
-                              secinfo->s.aes.alias);
6ae9ed
-        }
6ae9ed
-
6ae9ed
-        if (encinfo)
6ae9ed
-            virQEMUBuildLuksOpts(buf, &disk->src->encryption->encinfo,
6ae9ed
-                                 encinfo->s.aes.alias);
6ae9ed
-
6ae9ed
-        if (disk->src->format > 0 &&
6ae9ed
-            disk->src->type != VIR_STORAGE_TYPE_DIR)
6ae9ed
-            virBufferAsprintf(buf, "format=%s,",
6ae9ed
-                              virStorageFileFormatTypeToString(disk->src->format));
6ae9ed
+    /* nothing to format if the drive is empty */
6ae9ed
+    if (!source ||
6ae9ed
+        ((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
6ae9ed
+          disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
6ae9ed
+         disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
6ae9ed
+        ret = 0;
6ae9ed
+        goto cleanup;
6ae9ed
     }
6ae9ed
 
6ae9ed
+    if (actualType == VIR_STORAGE_TYPE_BLOCK &&
6ae9ed
+        disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
6ae9ed
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
+                       disk->src->type == VIR_STORAGE_TYPE_VOLUME ?
6ae9ed
+                       _("tray status 'open' is invalid for block type volume") :
6ae9ed
+                       _("tray status 'open' is invalid for block type disk"));
6ae9ed
+        goto cleanup;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    virBufferAddLit(buf, "file=");
6ae9ed
+
6ae9ed
+    /* for now the DIR based storage is handled by the magic FAT format */
6ae9ed
+    if (actualType == VIR_STORAGE_TYPE_DIR) {
6ae9ed
+        if (disk->src->format > 0 &&
6ae9ed
+            disk->src->format != VIR_STORAGE_FILE_FAT) {
6ae9ed
+            virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
+                           _("unsupported disk driver type for '%s'"),
6ae9ed
+                           virStorageFileFormatTypeToString(disk->src->format));
6ae9ed
+            goto cleanup;
6ae9ed
+        }
6ae9ed
+
6ae9ed
+        if (!disk->src->readonly) {
6ae9ed
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
6ae9ed
+                           _("cannot create virtual FAT disks in read-write mode"));
6ae9ed
+            goto cleanup;
6ae9ed
+        }
6ae9ed
+
6ae9ed
+        virBufferAddLit(buf, "fat:");
6ae9ed
+
6ae9ed
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
6ae9ed
+            virBufferAddLit(buf, "floppy:");
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    virQEMUBuildBufferEscapeComma(buf, source);
6ae9ed
+    virBufferAddLit(buf, ",");
6ae9ed
+
6ae9ed
+    if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
6ae9ed
+        virBufferAsprintf(buf, "password-secret=%s,",
6ae9ed
+                          secinfo->s.aes.alias);
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (encinfo)
6ae9ed
+        virQEMUBuildLuksOpts(buf, &disk->src->encryption->encinfo,
6ae9ed
+                             encinfo->s.aes.alias);
6ae9ed
+
6ae9ed
+    if (disk->src->format > 0 &&
6ae9ed
+        disk->src->type != VIR_STORAGE_TYPE_DIR)
6ae9ed
+        virBufferAsprintf(buf, "format=%s,",
6ae9ed
+                          virStorageFileFormatTypeToString(disk->src->format));
6ae9ed
+
6ae9ed
     ret = 0;
6ae9ed
 
6ae9ed
  cleanup:
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed