Blame SOURCES/libvirt-qemu-Use-qemuBuildNetworkDriveURI-to-handle-http-ftp-and-friends.patch

c401cc
From 798cd86a4beff97eac491c4292e4a02b042a2a49 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <798cd86a4beff97eac491c4292e4a02b042a2a49@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:57 +0100
c401cc
Subject: [PATCH] qemu: Use qemuBuildNetworkDriveURI to handle http/ftp and
c401cc
 friends
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Prepare the function to integrate other protocols and start folding
c401cc
other network protocols into a common place.
c401cc
c401cc
Conflicts: Other protocols like TFTP, HTTP ... were not backported and
c401cc
thus were removed from this patch.
c401cc
c401cc
(cherry picked from commit 078a102537380162e7198b63530a6bfb36726cd6)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/qemu/qemu_command.c | 143 ++++++++++++++++++++++++++++++++----------------
c401cc
 1 file changed, 97 insertions(+), 46 deletions(-)
c401cc
c401cc
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c401cc
index b80ffe9..f305a5a 100644
c401cc
--- a/src/qemu/qemu_command.c
c401cc
+++ b/src/qemu/qemu_command.c
c401cc
@@ -3548,6 +3548,46 @@ error:
c401cc
 }
c401cc
 
c401cc
 
c401cc
+static int
c401cc
+qemuNetworkDriveGetPort(int protocol,
c401cc
+                        const char *port)
c401cc
+{
c401cc
+    int ret = 0;
c401cc
+
c401cc
+    if (port) {
c401cc
+        if (virStrToLong_i(port, NULL, 10, &ret) < 0) {
c401cc
+            virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                           _("failed to parse port number '%s'"),
c401cc
+                           port);
c401cc
+            return -1;
c401cc
+        }
c401cc
+
c401cc
+        return ret;
c401cc
+    }
c401cc
+
c401cc
+    switch ((enum virDomainDiskProtocol) protocol) {
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
c401cc
+            return 7000;
c401cc
+
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_NBD:
c401cc
+            return 10809;
c401cc
+
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
c401cc
+            /* no default port specified */
c401cc
+            return 0;
c401cc
+
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_RBD:
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_LAST:
c401cc
+            /* not aplicable */
c401cc
+            return -1;
c401cc
+    }
c401cc
+
c401cc
+    return -1;
c401cc
+}
c401cc
+
c401cc
+
c401cc
+
c401cc
 char *
c401cc
 qemuBuildNetworkDriveURI(int protocol,
c401cc
                          const char *src,
c401cc
@@ -3559,56 +3599,69 @@ qemuBuildNetworkDriveURI(int protocol,
c401cc
     char *ret = NULL;
c401cc
     virURIPtr uri = NULL;
c401cc
 
c401cc
-    if (nhosts != 1) {
c401cc
-        virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-                       _("protocol '%s' accepts only one host"),
c401cc
-                       virDomainDiskProtocolTypeToString(protocol));
c401cc
-        return NULL;
c401cc
-    }
c401cc
-
c401cc
-    if (VIR_ALLOC(uri) < 0)
c401cc
-        return NULL;
c401cc
+    switch ((enum virDomainDiskProtocol) protocol) {
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_ISCSI:
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_NBD:
c401cc
+            if (nhosts != 1) {
c401cc
+                virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                               _("protocol '%s' accepts only one host"),
c401cc
+                               virDomainDiskProtocolTypeToString(protocol));
c401cc
+                goto cleanup;
c401cc
+            }
c401cc
 
c401cc
-    if (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
c401cc
-        if (VIR_STRDUP(uri->scheme, virDomainDiskProtocolTypeToString(protocol)) < 0)
c401cc
-            goto cleanup;
c401cc
-    } else {
c401cc
-        if (virAsprintf(&uri->scheme, "%s+%s",
c401cc
-                        virDomainDiskProtocolTypeToString(protocol),
c401cc
-                        virDomainDiskProtocolTransportTypeToString(hosts->transport)) < 0)
c401cc
-            goto cleanup;
c401cc
-    }
c401cc
+            if (VIR_ALLOC(uri) < 0)
c401cc
+                goto cleanup;
c401cc
 
c401cc
-    if (src &&
c401cc
-        virAsprintf(&uri->path, "/%s", src) < 0)
c401cc
-        goto cleanup;
c401cc
+            if (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
c401cc
+                if (VIR_STRDUP(uri->scheme,
c401cc
+                               virDomainDiskProtocolTypeToString(protocol)) < 0)
c401cc
+                    goto cleanup;
c401cc
+            } else {
c401cc
+                if (virAsprintf(&uri->scheme, "%s+%s",
c401cc
+                                virDomainDiskProtocolTypeToString(protocol),
c401cc
+                                virDomainDiskProtocolTransportTypeToString(hosts->transport)) < 0)
c401cc
+                    goto cleanup;
c401cc
+            }
c401cc
 
c401cc
-    if (hosts->port &&
c401cc
-        virStrToLong_i(hosts->port, NULL, 10, &uri->port) < 0) {
c401cc
-        virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-                       _("failed to parse port number '%s'"),
c401cc
-                       hosts->port);
c401cc
-        goto cleanup;
c401cc
-    }
c401cc
+            if ((uri->port = qemuNetworkDriveGetPort(protocol, hosts->port)) < 0)
c401cc
+                goto cleanup;
c401cc
 
c401cc
-    if (hosts->socket &&
c401cc
-        virAsprintf(&uri->query, "socket=%s", hosts->socket) < 0)
c401cc
-        goto cleanup;
c401cc
+            if (src &&
c401cc
+                virAsprintf(&uri->path, "%s%s",
c401cc
+                            src[0] == '/' ? "" : "/",
c401cc
+                            src) < 0)
c401cc
+                goto cleanup;
c401cc
 
c401cc
-    if (username) {
c401cc
-        if (secret) {
c401cc
-            if (virAsprintf(&uri->user, "%s:%s", username, secret) < 0)
c401cc
+            if (hosts->socket &&
c401cc
+                virAsprintf(&uri->query, "socket=%s", hosts->socket) < 0)
c401cc
                 goto cleanup;
c401cc
-        } else {
c401cc
-            if (VIR_STRDUP(uri->user, username) < 0)
c401cc
+
c401cc
+            if (username) {
c401cc
+                if (secret) {
c401cc
+                    if (virAsprintf(&uri->user, "%s:%s", username, secret) < 0)
c401cc
+                        goto cleanup;
c401cc
+                } else {
c401cc
+                    if (VIR_STRDUP(uri->user, username) < 0)
c401cc
+                        goto cleanup;
c401cc
+                }
c401cc
+            }
c401cc
+
c401cc
+            if (VIR_STRDUP(uri->server, hosts->name) < 0)
c401cc
                 goto cleanup;
c401cc
-        }
c401cc
-    }
c401cc
 
c401cc
-    if (VIR_STRDUP(uri->server, hosts->name) < 0)
c401cc
-        goto cleanup;
c401cc
+            ret = virURIFormat(uri);
c401cc
+
c401cc
+            break;
c401cc
 
c401cc
-    ret = virURIFormat(uri);
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_RBD:
c401cc
+        case VIR_DOMAIN_DISK_PROTOCOL_LAST:
c401cc
+            virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                           _("network disk protocol '%s' not supported"),
c401cc
+                           virDomainDiskProtocolTypeToString(protocol));
c401cc
+            goto cleanup;
c401cc
+    }
c401cc
 
c401cc
 cleanup:
c401cc
     virURIFree(uri);
c401cc
@@ -3677,11 +3730,9 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
c401cc
         return -1;
c401cc
     }
c401cc
 
c401cc
-    if ((disk->hosts->name && strchr(disk->hosts->name, ':'))
c401cc
-        || (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP
c401cc
-            && !disk->hosts->name)
c401cc
-        || (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX
c401cc
-            && disk->hosts->socket && disk->hosts->socket[0] != '/'))
c401cc
+    if ((disk->hosts->name && strchr(disk->hosts->name, ':')) ||
c401cc
+        (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP && !disk->hosts->name) ||
c401cc
+        (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX && disk->hosts->socket && disk->hosts->socket[0] != '/'))
c401cc
         return qemuBuildDriveURIString(conn, disk, opt);
c401cc
 
c401cc
     virBufferAddLit(opt, "file=nbd:");
c401cc
-- 
c401cc
1.9.0
c401cc