Blob Blame History Raw
From 122cab08174f4346cf101ad2e150d2ebf6507d9f Mon Sep 17 00:00:00 2001
Message-Id: <122cab08174f4346cf101ad2e150d2ebf6507d9f@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:54:56 +0100
Subject: [PATCH] qemu: Simplify call pattern of qemuBuildDriveURIString

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

Automatically assign secret type from the disk source definition and
pull in adding of the comma. Then update callers to keep generated
output the same.

(cherry picked from commit 927ddae1972ac36149a3a95d4feed6453089b743)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_command.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index da4d2f8..b80ffe9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3620,9 +3620,7 @@ cleanup:
 static int
 qemuBuildDriveURIString(virConnectPtr conn,
                         virDomainDiskDefPtr disk,
-                        virBufferPtr opt,
-                        int protocol,
-                        virSecretUsageType secretUsageType)
+                        virBufferPtr opt)
 {
     char *secret = NULL;
     char *builturi = NULL;
@@ -3630,20 +3628,22 @@ qemuBuildDriveURIString(virConnectPtr conn,
 
     virBufferAddLit(opt, "file=");
 
-    if (disk->auth.username && secretUsageType != VIR_SECRET_USAGE_TYPE_NONE) {
+    if (disk->protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI &&
+        disk->auth.username) {
         /* Get the secret string using the virDomainDiskDef */
         if (!(secret = qemuGetSecretString(conn,
-                                           virDomainDiskProtocolTypeToString(protocol),
+                                           virDomainDiskProtocolTypeToString(disk->protocol),
                                            false,
                                            disk->auth.secretType,
                                            disk->auth.username,
                                            disk->auth.secret.uuid,
                                            disk->auth.secret.usage,
-                                           secretUsageType)))
+                                           VIR_SECRET_USAGE_TYPE_ISCSI)))
             goto cleanup;
     }
 
-    if (!(builturi = qemuBuildNetworkDriveURI(protocol,
+
+    if (!(builturi = qemuBuildNetworkDriveURI(disk->protocol,
                                               disk->src,
                                               disk->nhosts,
                                               disk->hosts,
@@ -3652,6 +3652,7 @@ qemuBuildDriveURIString(virConnectPtr conn,
         goto cleanup;
 
     virBufferEscape(opt, ',', ",", "%s", builturi);
+    virBufferAddChar(opt, ',');
 
     ret = 0;
 
@@ -3681,9 +3682,7 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
             && !disk->hosts->name)
         || (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX
             && disk->hosts->socket && disk->hosts->socket[0] != '/'))
-        return qemuBuildDriveURIString(conn, disk, opt,
-                                       VIR_DOMAIN_DISK_PROTOCOL_NBD,
-                                       VIR_SECRET_USAGE_TYPE_NONE);
+        return qemuBuildDriveURIString(conn, disk, opt);
 
     virBufferAddLit(opt, "file=nbd:");
 
@@ -3713,6 +3712,8 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
     if (disk->src)
         virBufferEscape(opt, ',', ",", ":exportname=%s", disk->src);
 
+    virBufferAddChar(opt, ',');
+
     return 0;
 }
 
@@ -3840,7 +3841,6 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
             case VIR_DOMAIN_DISK_PROTOCOL_NBD:
                 if (qemuBuildNBDString(conn, disk, &opt) < 0)
                     goto error;
-                virBufferAddChar(&opt, ',');
                 break;
             case VIR_DOMAIN_DISK_PROTOCOL_RBD:
                 virBufferAddLit(&opt, "file=");
@@ -3848,19 +3848,11 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
                     goto error;
                 virBufferAddChar(&opt, ',');
                 break;
+
             case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
-                if (qemuBuildDriveURIString(conn, disk, &opt,
-                                            VIR_DOMAIN_DISK_PROTOCOL_GLUSTER,
-                                            VIR_SECRET_USAGE_TYPE_NONE) < 0)
-                    goto error;
-                virBufferAddChar(&opt, ',');
-                break;
             case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
-                if (qemuBuildDriveURIString(conn, disk, &opt,
-                                            VIR_DOMAIN_DISK_PROTOCOL_ISCSI,
-                                            VIR_SECRET_USAGE_TYPE_ISCSI) < 0)
+                if (qemuBuildDriveURIString(conn, disk, &opt) < 0)
                     goto error;
-                virBufferAddChar(&opt, ',');
                 break;
 
             case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
-- 
1.9.0