render / rpms / libvirt

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