[libvirt] [PATCH v7 05/11] util: storage: Add JSON backing volume parse for VxHS

John Ferlan jferlan at redhat.com
Fri Sep 1 17:09:49 UTC 2017


From: Ashish Mittal <Ashish.Mittal at veritas.com>

Add the backing parse and a test case to verify parsing of VxHS
backing storage.

Signed-off-by: Ashish Mittal <Ashish.Mittal at veritas.com>
Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/util/virstoragefile.c | 37 +++++++++++++++++++++++++++++++++++++
 tests/virstoragetest.c    | 11 +++++++++++
 2 files changed, 48 insertions(+)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index e0ec717..f3fe529 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3212,6 +3212,40 @@ virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src,
     return virStorageSourceParseBackingJSONInternal(src, json);
 }
 
+
+static int
+virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src,
+                                     virJSONValuePtr json,
+                                     int opaque ATTRIBUTE_UNUSED)
+{
+    const char *vdisk_id = virJSONValueObjectGetString(json, "vdisk-id");
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
+
+    if (!vdisk_id || !server) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing 'vdisk-id' or 'server' attribute in "
+                         "JSON backing definition for VxHS volume"));
+        return -1;
+    }
+
+    src->type = VIR_STORAGE_TYPE_NETWORK;
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_VXHS;
+
+    if (VIR_STRDUP(src->path, vdisk_id) < 0)
+        return -1;
+
+    if (VIR_ALLOC_N(src->hosts, 1) < 0)
+        return -1;
+    src->nhosts = 1;
+
+    if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts,
+                                                          server) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 struct virStorageSourceJSONDriverParser {
     const char *drvname;
     int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
@@ -3234,6 +3268,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
     {"ssh", virStorageSourceParseBackingJSONSSH, 0},
     {"rbd", virStorageSourceParseBackingJSONRBD, 0},
     {"raw", virStorageSourceParseBackingJSONRaw, 0},
+    {"vxhs", virStorageSourceParseBackingJSONVxHS, 0},
 };
 
 
@@ -3995,6 +4030,8 @@ virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
             return 0;
 
         case VIR_STORAGE_NET_PROTOCOL_VXHS:
+            return 9999;
+
         case VIR_STORAGE_NET_PROTOCOL_LAST:
         case VIR_STORAGE_NET_PROTOCOL_NONE:
             return 0;
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 60e3164..ffebd4d 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1592,6 +1592,17 @@ mymain(void)
                        "<source protocol='sheepdog' name='Alice'>\n"
                        "  <host name='10.10.10.10' port='7000'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"vxhs\","
+                                       "\"vdisk-id\":\"c6718f6b-0401-441d-a8c3-1f0064d75ee0\","
+                                       "\"server\": { \"type\":\"tcp\","
+                                                      "\"host\":\"example.com\","
+                                                      "\"port\":\"9999\""
+                                                   "}"
+                                      "}"
+                            "}",
+                       "<source protocol='vxhs' name='c6718f6b-0401-441d-a8c3-1f0064d75ee0'>\n"
+                       "  <host name='example.com' port='9999'/>\n"
+                       "</source>\n");
 #endif /* WITH_YAJL */
 
  cleanup:
-- 
2.9.5




More information about the libvir-list mailing list