6d3351
From 5e1615fba181a37d805c17f517c0a925d171fff5 Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <5e1615fba181a37d805c17f517c0a925d171fff5@dist-git>
6d3351
From: Peter Krempa <pkrempa@redhat.com>
6d3351
Date: Tue, 20 Jun 2017 10:22:45 +0200
6d3351
Subject: [PATCH] util: storage: adapt to changes in JSON format for sheepdog
6d3351
6d3351
Since qemu 2.9 the options changed from a monolithic string into fine
6d3351
grained options for the json pseudo-protocol object.
6d3351
6d3351
(cherry picked from commit b16133b114fd0d787de1cda6bf2ff0110c523a32)
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1461638
6d3351
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6d3351
---
6d3351
 src/util/virstoragefile.c | 28 ++++++++++++++++++++++++----
6d3351
 tests/virstoragetest.c    | 11 +++++++++++
6d3351
 2 files changed, 35 insertions(+), 4 deletions(-)
6d3351
6d3351
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
6d3351
index 566c4c27c3..c2ba3fba9f 100644
6d3351
--- a/src/util/virstoragefile.c
6d3351
+++ b/src/util/virstoragefile.c
6d3351
@@ -3066,6 +3066,8 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
6d3351
                                          int opaque ATTRIBUTE_UNUSED)
6d3351
 {
6d3351
     const char *filename;
6d3351
+    const char *vdi = virJSONValueObjectGetString(json, "vdi");
6d3351
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
6d3351
 
6d3351
     /* legacy URI based syntax passed via 'filename' option */
6d3351
     if ((filename = virJSONValueObjectGetString(json, "filename"))) {
6d3351
@@ -3074,13 +3076,31 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
6d3351
                                                           VIR_STORAGE_NET_PROTOCOL_SHEEPDOG);
6d3351
 
6d3351
         /* libvirt doesn't implement a parser for the legacy non-URI syntax */
6d3351
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
6d3351
+                       _("missing sheepdog URI in JSON backing volume definition"));
6d3351
+        return -1;
6d3351
     }
6d3351
 
6d3351
-    /* Sheepdog currently supports only URI and legacy syntax passed in as filename */
6d3351
-    virReportError(VIR_ERR_INVALID_ARG, "%s",
6d3351
-                   _("missing sheepdog URI in JSON backing volume definition"));
6d3351
+    src->type = VIR_STORAGE_TYPE_NETWORK;
6d3351
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG;
6d3351
 
6d3351
-    return -1;
6d3351
+    if (!vdi) {
6d3351
+        virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing sheepdog vdi name"));
6d3351
+        return -1;
6d3351
+    }
6d3351
+
6d3351
+    if (VIR_STRDUP(src->path, vdi) < 0)
6d3351
+        return -1;
6d3351
+
6d3351
+    if (VIR_ALLOC(src->hosts) < 0)
6d3351
+        return -1;
6d3351
+
6d3351
+    src->nhosts = 1;
6d3351
+
6d3351
+    if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) < 0)
6d3351
+        return -1;
6d3351
+
6d3351
+    return 0;
6d3351
 }
6d3351
 
6d3351
 
6d3351
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
6d3351
index 9ca927b5e4..36b8265dff 100644
6d3351
--- a/tests/virstoragetest.c
6d3351
+++ b/tests/virstoragetest.c
6d3351
@@ -1562,6 +1562,17 @@ mymain(void)
6d3351
                        "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
6d3351
                        "  <host name='test.org' port='1234'/>\n"
6d3351
                        "</source>\n");
6d3351
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"sheepdog\","
6d3351
+                                       "\"vdi\":\"test\","
6d3351
+                                       "\"server\":{ \"type\":\"inet\","
6d3351
+                                                    "\"host\":\"example.com\","
6d3351
+                                                    "\"port\":\"321\""
6d3351
+                                                  "}"
6d3351
+                                      "}"
6d3351
+                            "}",
6d3351
+                       "<source protocol='sheepdog' name='test'>\n"
6d3351
+                       "  <host name='example.com' port='321'/>\n"
6d3351
+                       "</source>\n");
6d3351
 
6d3351
  cleanup:
6d3351
     /* Final cleanup */
6d3351
-- 
6d3351
2.13.1
6d3351