render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c401cc
From 122cab08174f4346cf101ad2e150d2ebf6507d9f Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <122cab08174f4346cf101ad2e150d2ebf6507d9f@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:56 +0100
c401cc
Subject: [PATCH] qemu: Simplify call pattern of qemuBuildDriveURIString
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Automatically assign secret type from the disk source definition and
c401cc
pull in adding of the comma. Then update callers to keep generated
c401cc
output the same.
c401cc
c401cc
(cherry picked from commit 927ddae1972ac36149a3a95d4feed6453089b743)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/qemu/qemu_command.c | 34 +++++++++++++---------------------
c401cc
 1 file changed, 13 insertions(+), 21 deletions(-)
c401cc
c401cc
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c401cc
index da4d2f8..b80ffe9 100644
c401cc
--- a/src/qemu/qemu_command.c
c401cc
+++ b/src/qemu/qemu_command.c
c401cc
@@ -3620,9 +3620,7 @@ cleanup:
c401cc
 static int
c401cc
 qemuBuildDriveURIString(virConnectPtr conn,
c401cc
                         virDomainDiskDefPtr disk,
c401cc
-                        virBufferPtr opt,
c401cc
-                        int protocol,
c401cc
-                        virSecretUsageType secretUsageType)
c401cc
+                        virBufferPtr opt)
c401cc
 {
c401cc
     char *secret = NULL;
c401cc
     char *builturi = NULL;
c401cc
@@ -3630,20 +3628,22 @@ qemuBuildDriveURIString(virConnectPtr conn,
c401cc
 
c401cc
     virBufferAddLit(opt, "file=");
c401cc
 
c401cc
-    if (disk->auth.username && secretUsageType != VIR_SECRET_USAGE_TYPE_NONE) {
c401cc
+    if (disk->protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI &&
c401cc
+        disk->auth.username) {
c401cc
         /* Get the secret string using the virDomainDiskDef */
c401cc
         if (!(secret = qemuGetSecretString(conn,
c401cc
-                                           virDomainDiskProtocolTypeToString(protocol),
c401cc
+                                           virDomainDiskProtocolTypeToString(disk->protocol),
c401cc
                                            false,
c401cc
                                            disk->auth.secretType,
c401cc
                                            disk->auth.username,
c401cc
                                            disk->auth.secret.uuid,
c401cc
                                            disk->auth.secret.usage,
c401cc
-                                           secretUsageType)))
c401cc
+                                           VIR_SECRET_USAGE_TYPE_ISCSI)))
c401cc
             goto cleanup;
c401cc
     }
c401cc
 
c401cc
-    if (!(builturi = qemuBuildNetworkDriveURI(protocol,
c401cc
+
c401cc
+    if (!(builturi = qemuBuildNetworkDriveURI(disk->protocol,
c401cc
                                               disk->src,
c401cc
                                               disk->nhosts,
c401cc
                                               disk->hosts,
c401cc
@@ -3652,6 +3652,7 @@ qemuBuildDriveURIString(virConnectPtr conn,
c401cc
         goto cleanup;
c401cc
 
c401cc
     virBufferEscape(opt, ',', ",", "%s", builturi);
c401cc
+    virBufferAddChar(opt, ',');
c401cc
 
c401cc
     ret = 0;
c401cc
 
c401cc
@@ -3681,9 +3682,7 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
c401cc
             && !disk->hosts->name)
c401cc
         || (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX
c401cc
             && disk->hosts->socket && disk->hosts->socket[0] != '/'))
c401cc
-        return qemuBuildDriveURIString(conn, disk, opt,
c401cc
-                                       VIR_DOMAIN_DISK_PROTOCOL_NBD,
c401cc
-                                       VIR_SECRET_USAGE_TYPE_NONE);
c401cc
+        return qemuBuildDriveURIString(conn, disk, opt);
c401cc
 
c401cc
     virBufferAddLit(opt, "file=nbd:");
c401cc
 
c401cc
@@ -3713,6 +3712,8 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
c401cc
     if (disk->src)
c401cc
         virBufferEscape(opt, ',', ",", ":exportname=%s", disk->src);
c401cc
 
c401cc
+    virBufferAddChar(opt, ',');
c401cc
+
c401cc
     return 0;
c401cc
 }
c401cc
 
c401cc
@@ -3840,7 +3841,6 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
c401cc
             case VIR_DOMAIN_DISK_PROTOCOL_NBD:
c401cc
                 if (qemuBuildNBDString(conn, disk, &opt) < 0)
c401cc
                     goto error;
c401cc
-                virBufferAddChar(&opt, ',');
c401cc
                 break;
c401cc
             case VIR_DOMAIN_DISK_PROTOCOL_RBD:
c401cc
                 virBufferAddLit(&opt, "file=");
c401cc
@@ -3848,19 +3848,11 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
c401cc
                     goto error;
c401cc
                 virBufferAddChar(&opt, ',');
c401cc
                 break;
c401cc
+
c401cc
             case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
c401cc
-                if (qemuBuildDriveURIString(conn, disk, &opt,
c401cc
-                                            VIR_DOMAIN_DISK_PROTOCOL_GLUSTER,
c401cc
-                                            VIR_SECRET_USAGE_TYPE_NONE) < 0)
c401cc
-                    goto error;
c401cc
-                virBufferAddChar(&opt, ',');
c401cc
-                break;
c401cc
             case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
c401cc
-                if (qemuBuildDriveURIString(conn, disk, &opt,
c401cc
-                                            VIR_DOMAIN_DISK_PROTOCOL_ISCSI,
c401cc
-                                            VIR_SECRET_USAGE_TYPE_ISCSI) < 0)
c401cc
+                if (qemuBuildDriveURIString(conn, disk, &opt) < 0)
c401cc
                     goto error;
c401cc
-                virBufferAddChar(&opt, ',');
c401cc
                 break;
c401cc
 
c401cc
             case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
c401cc
-- 
c401cc
1.9.0
c401cc