]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: Split out parsing of TCP network host from JSON pseudoprotocol
authorPeter Krempa <pkrempa@redhat.com>
Mon, 19 Jun 2017 12:42:18 +0000 (14:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 20 Jun 2017 06:40:18 +0000 (08:40 +0200)
Few backing protocols support only TCP. Split out the function which
will correspond to parsing qemu's InetSocketAddressBase.

src/util/virstoragefile.c

index 7f2a50fd16f77979b4836ebc5a683f37a4e85813..9af0cdbcd357393553aba95c3405a9ea50b6fdb8 100644 (file)
@@ -2794,13 +2794,35 @@ virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
 }
 
 
+static int
+virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host,
+                                                  virJSONValuePtr json)
+{
+    const char *hostname = virJSONValueObjectGetString(json, "host");
+    const char *port = virJSONValueObjectGetString(json, "port");
+
+    if (!hostname) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing hostname for tcp backing server in "
+                         "JSON backing volume definition"));
+        return -1;
+    }
+
+    host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+
+    if (VIR_STRDUP(host->name, hostname) < 0 ||
+        VIR_STRDUP(host->port, port) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
                                               virJSONValuePtr json)
 {
     const char *type = virJSONValueObjectGetString(json, "type");
-    const char *hostname = virJSONValueObjectGetString(json, "host");
-    const char *port = virJSONValueObjectGetString(json, "port");
     const char *socket = virJSONValueObjectGetString(json, "socket");
 
     if (!type) {
@@ -2811,18 +2833,8 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
     }
 
     if (STREQ(type, "tcp") || STREQ(type, "inet")) {
-        host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+        return virStorageSourceParseBackingJSONInetSocketAddress(host, json);
 
-        if (!hostname) {
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("missing hostname for tcp backing server in "
-                             "JSON backing volume definition"));
-            return -1;
-        }
-
-        if (VIR_STRDUP(host->name, hostname) < 0 ||
-            VIR_STRDUP(host->port, port) < 0)
-            return -1;
     } else if (STREQ(type, "unix")) {
         host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;