Blame SOURCES/libvirt-util-storagefile-Split-out-parsing-of-NBD-string-into-a-separate-func.patch

9119d9
From fc63fe21003f5c63a9ea9cd227ab8ee491784330 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <fc63fe21003f5c63a9ea9cd227ab8ee491784330@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Fri, 21 Nov 2014 15:04:09 +0100
9119d9
Subject: [PATCH] util: storagefile: Split out parsing of NBD string into a
9119d9
 separate func
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1164528
9119d9
9119d9
Split out the code so that the function looks homogenous after adding
9119d9
more protocol specific parsers.
9119d9
9119d9
(cherry picked from commit b327df87befd2870e5e9dc5a35dd1210ee8f3291)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/util/virstoragefile.c | 151 ++++++++++++++++++++++++++++------------------
9119d9
 1 file changed, 91 insertions(+), 60 deletions(-)
9119d9
9119d9
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
9119d9
index ecf329b..94fb3cd 100644
9119d9
--- a/src/util/virstoragefile.c
9119d9
+++ b/src/util/virstoragefile.c
9119d9
@@ -2333,77 +2333,109 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
9119d9
 
9119d9
 
9119d9
 static int
9119d9
+virStorageSourceParseNBDColonString(const char *nbdstr,
9119d9
+                                    virStorageSourcePtr src)
9119d9
+{
9119d9
+    char **backing = NULL;
9119d9
+    int ret = -1;
9119d9
+
9119d9
+    if (!(backing = virStringSplit(nbdstr, ":", 0)))
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    /* we know that backing[0] now equals to "nbd" */
9119d9
+
9119d9
+    if (VIR_ALLOC_N(src->hosts, 1) < 0)
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    src->nhosts = 1;
9119d9
+    src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
9119d9
+
9119d9
+    /* format: [] denotes optional sections, uppercase are variable strings
9119d9
+     * nbd:unix:/PATH/TO/SOCKET[:exportname=EXPORTNAME]
9119d9
+     * nbd:HOSTNAME:PORT[:exportname=EXPORTNAME]
9119d9
+     */
9119d9
+    if (!backing[1]) {
9119d9
+        virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
+                       _("missing remote information in '%s' for protocol nbd"),
9119d9
+                       nbdstr);
9119d9
+        goto cleanup;
9119d9
+    } else if (STREQ(backing[1], "unix")) {
9119d9
+        if (!backing[2]) {
9119d9
+            virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
+                           _("missing unix socket path in nbd backing string %s"),
9119d9
+                           nbdstr);
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+
9119d9
+        if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0)
9119d9
+            goto cleanup;
9119d9
+
9119d9
+   } else {
9119d9
+        if (!backing[1]) {
9119d9
+            virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
+                           _("missing host name in nbd string '%s'"),
9119d9
+                           nbdstr);
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+
9119d9
+        if (VIR_STRDUP(src->hosts->name, backing[1]) < 0)
9119d9
+            goto cleanup;
9119d9
+
9119d9
+        if (!backing[2]) {
9119d9
+            virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
+                           _("missing port in nbd string '%s'"),
9119d9
+                           nbdstr);
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+
9119d9
+        if (VIR_STRDUP(src->hosts->port, backing[2]) < 0)
9119d9
+            goto cleanup;
9119d9
+    }
9119d9
+
9119d9
+    if (backing[3] && STRPREFIX(backing[3], "exportname=")) {
9119d9
+        if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0)
9119d9
+            goto cleanup;
9119d9
+    }
9119d9
+
9119d9
+    ret = 0;
9119d9
+
9119d9
+ cleanup:
9119d9
+    virStringFreeList(backing);
9119d9
+
9119d9
+    return ret;
9119d9
+}
9119d9
+
9119d9
+
9119d9
+static int
9119d9
 virStorageSourceParseBackingColon(virStorageSourcePtr src,
9119d9
                                   const char *path)
9119d9
 {
9119d9
-    char **backing = NULL;
9119d9
+    char *protocol = NULL;
9119d9
+    const char *p;
9119d9
     int ret = -1;
9119d9
 
9119d9
-    if (!(backing = virStringSplit(path, ":", 0)))
9119d9
+    if (!(p = strchr(path, ':'))) {
9119d9
+        virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
+                       _("invalid backing protocol string '%s'"),
9119d9
+                       path);
9119d9
         goto cleanup;
9119d9
+    }
9119d9
 
9119d9
-    if (!backing[0] ||
9119d9
-        (src->protocol = virStorageNetProtocolTypeFromString(backing[0])) < 0) {
9119d9
+    if (VIR_STRNDUP(protocol, path, p - path) < 0)
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) < 0) {
9119d9
         virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
                        _("invalid backing protocol '%s'"),
9119d9
-                       NULLSTR(backing[0]));
9119d9
+                       protocol);
9119d9
         goto cleanup;
9119d9
     }
9119d9
 
9119d9
     switch ((virStorageNetProtocol) src->protocol) {
9119d9
     case VIR_STORAGE_NET_PROTOCOL_NBD:
9119d9
-        if (VIR_ALLOC_N(src->hosts, 1) < 0)
9119d9
+        if (virStorageSourceParseNBDColonString(path, src) < 0)
9119d9
             goto cleanup;
9119d9
-        src->nhosts = 1;
9119d9
-        src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
9119d9
-
9119d9
-        /* format: [] denotes optional sections, uppercase are variable strings
9119d9
-         * nbd:unix:/PATH/TO/SOCKET[:exportname=EXPORTNAME]
9119d9
-         * nbd:HOSTNAME:PORT[:exportname=EXPORTNAME]
9119d9
-         */
9119d9
-        if (!backing[1]) {
9119d9
-            virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
-                           _("missing remote information in '%s' for protocol nbd"),
9119d9
-                           path);
9119d9
-            goto cleanup;
9119d9
-        } else if (STREQ(backing[1], "unix")) {
9119d9
-            if (!backing[2]) {
9119d9
-                virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
-                               _("missing unix socket path in nbd backing string %s"),
9119d9
-                               path);
9119d9
-                goto cleanup;
9119d9
-            }
9119d9
-
9119d9
-            if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0)
9119d9
-                goto cleanup;
9119d9
-
9119d9
-       } else {
9119d9
-            if (!backing[1]) {
9119d9
-                virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
-                               _("missing host name in nbd string '%s'"),
9119d9
-                               path);
9119d9
-                goto cleanup;
9119d9
-            }
9119d9
-
9119d9
-            if (VIR_STRDUP(src->hosts->name, backing[1]) < 0)
9119d9
-                goto cleanup;
9119d9
-
9119d9
-            if (!backing[2]) {
9119d9
-                virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
-                               _("missing port in nbd string '%s'"),
9119d9
-                               path);
9119d9
-                goto cleanup;
9119d9
-            }
9119d9
-
9119d9
-            if (VIR_STRDUP(src->hosts->port, backing[2]) < 0)
9119d9
-                goto cleanup;
9119d9
-        }
9119d9
-
9119d9
-        if (backing[3] && STRPREFIX(backing[3], "exportname=")) {
9119d9
-            if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0)
9119d9
-                goto cleanup;
9119d9
-        }
9119d9
-     break;
9119d9
+        break;
9119d9
 
9119d9
     case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
9119d9
     case VIR_STORAGE_NET_PROTOCOL_RBD:
9119d9
@@ -2411,7 +2443,7 @@ virStorageSourceParseBackingColon(virStorageSourcePtr src,
9119d9
     case VIR_STORAGE_NET_PROTOCOL_NONE:
9119d9
         virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
                        _("backing store parser is not implemented for protocol %s"),
9119d9
-                       backing[0]);
9119d9
+                       protocol);
9119d9
         goto cleanup;
9119d9
 
9119d9
     case VIR_STORAGE_NET_PROTOCOL_HTTP:
9119d9
@@ -2423,16 +2455,15 @@ virStorageSourceParseBackingColon(virStorageSourcePtr src,
9119d9
     case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
9119d9
         virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
                        _("malformed backing store path for protocol %s"),
9119d9
-                       backing[0]);
9119d9
+                       protocol);
9119d9
         goto cleanup;
9119d9
     }
9119d9
 
9119d9
     ret = 0;
9119d9
 
9119d9
  cleanup:
9119d9
-    virStringFreeList(backing);
9119d9
+    VIR_FREE(protocol);
9119d9
     return ret;
9119d9
-
9119d9
 }
9119d9
 
9119d9
 
9119d9
-- 
9119d9
2.1.3
9119d9