render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 61986f544f712b35a8fb6f31d4bd8e2822bfe5dc Mon Sep 17 00:00:00 2001
Message-Id: <61986f544f712b35a8fb6f31d4bd8e2822bfe5dc@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:54:58 +0100
Subject: [PATCH] qemu: Migrate sheepdog source generation into common function

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

(cherry picked from commit eaa1539b2f1c73e39b1d5fbe770a6c5f44f7fd11)

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

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f305a5a..f45b681 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3655,6 +3655,29 @@ qemuBuildNetworkDriveURI(int protocol,
             break;
 
         case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
+            if (!src) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("missing disk source for 'sheepdog' protocol"));
+                goto cleanup;
+            }
+
+            if (nhosts == 0) {
+                if (virAsprintf(&ret, "sheepdog:%s", src) < 0)
+                    goto cleanup;
+            } else if (nhosts == 1) {
+                if (virAsprintf(&ret, "sheepdog:%s:%s:%s",
+                                hosts->name,
+                                hosts->port ? hosts->port : "7000",
+                                src) < 0)
+                    goto cleanup;
+            } else {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("protocol 'sheepdog' accepts up to one host"));
+                goto cleanup;
+            }
+
+            break;
+
         case VIR_DOMAIN_DISK_PROTOCOL_RBD:
         case VIR_DOMAIN_DISK_PROTOCOL_LAST:
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3900,24 +3923,12 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
                 virBufferAddChar(&opt, ',');
                 break;
 
+            case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
             case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
             case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
                 if (qemuBuildDriveURIString(conn, disk, &opt) < 0)
                     goto error;
                 break;
-
-            case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
-                if (disk->nhosts == 0) {
-                    virBufferEscape(&opt, ',', ",", "file=sheepdog:%s,",
-                                    disk->src);
-                } else {
-                    /* only one host is supported now */
-                    virBufferAsprintf(&opt, "file=sheepdog:%s:%s:",
-                                      disk->hosts->name,
-                                      disk->hosts->port ? disk->hosts->port : "7000");
-                    virBufferEscape(&opt, ',', ",", "%s,", disk->src);
-                }
-                break;
             }
         } else {
             if ((actualType == VIR_DOMAIN_DISK_TYPE_BLOCK) &&
-- 
1.9.0