[libvirt] [PATCH v2 8/8] util: storage: adapt to changes in JSON format for sheepdog

Peter Krempa posted 8 patches 7 years, 11 months ago
[libvirt] [PATCH v2 8/8] util: storage: adapt to changes in JSON format for sheepdog
Posted by Peter Krempa 7 years, 11 months ago
Since qemu 2.9 the options changed from a monolithic string into fine
grained options for the json pseudo-protocol object.
---

Notes:
    v2:
    - fixed server type to 'inet' in test
    - removed spurious 'transport' value in test

 src/util/virstoragefile.c | 28 ++++++++++++++++++++++++----
 tests/virstoragetest.c    | 11 +++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index b8a3de85c..3cbbb6c8f 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3061,6 +3061,8 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
                                          int opaque ATTRIBUTE_UNUSED)
 {
     const char *filename;
+    const char *vdi = virJSONValueObjectGetString(json, "vdi");
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");

     /* legacy URI based syntax passed via 'filename' option */
     if ((filename = virJSONValueObjectGetString(json, "filename"))) {
@@ -3069,13 +3071,31 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
                                                           VIR_STORAGE_NET_PROTOCOL_SHEEPDOG);

         /* libvirt doesn't implement a parser for the legacy non-URI syntax */
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing sheepdog URI in JSON backing volume definition"));
+        return -1;
     }

-    /* Sheepdog currently supports only URI and legacy syntax passed in as filename */
-    virReportError(VIR_ERR_INVALID_ARG, "%s",
-                   _("missing sheepdog URI in JSON backing volume definition"));
+    src->type = VIR_STORAGE_TYPE_NETWORK;
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG;

-    return -1;
+    if (!vdi) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing sheepdog vdi name"));
+        return -1;
+    }
+
+    if (VIR_STRDUP(src->path, vdi) < 0)
+        return -1;
+
+    if (VIR_ALLOC(src->hosts) < 0)
+        return -1;
+
+    src->nhosts = 1;
+
+    if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) < 0)
+        return -1;
+
+    return 0;
 }


diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 08f6c9003..6c1287380 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1562,6 +1562,17 @@ mymain(void)
                        "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
                        "  <host name='test.org' port='1234'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"sheepdog\","
+                                       "\"vdi\":\"test\","
+                                       "\"server\":{ \"type\":\"inet\","
+                                                    "\"host\":\"example.com\","
+                                                    "\"port\":\"321\""
+                                                  "}"
+                                      "}"
+                            "}",
+                       "<source protocol='sheepdog' name='test'>\n"
+                       "  <host name='example.com' port='321'/>\n"
+                       "</source>\n");

  cleanup:
     /* Final cleanup */
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 8/8] util: storage: adapt to changes in JSON format for sheepdog
Posted by Pavel Hrdina 7 years, 10 months ago
On Mon, Jun 19, 2017 at 03:58:35PM +0200, Peter Krempa wrote:
> Since qemu 2.9 the options changed from a monolithic string into fine
> grained options for the json pseudo-protocol object.
> ---
> 
> Notes:
>     v2:
>     - fixed server type to 'inet' in test
>     - removed spurious 'transport' value in test
> 
>  src/util/virstoragefile.c | 28 ++++++++++++++++++++++++----
>  tests/virstoragetest.c    | 11 +++++++++++
>  2 files changed, 35 insertions(+), 4 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 8/8] util: storage: adapt to changes in JSON format for sheepdog
Posted by Peter Krempa 7 years, 10 months ago
On Tue, Jun 20, 2017 at 09:08:34 +0200, Pavel Hrdina wrote:
> On Mon, Jun 19, 2017 at 03:58:35PM +0200, Peter Krempa wrote:
> > Since qemu 2.9 the options changed from a monolithic string into fine
> > grained options for the json pseudo-protocol object.
> > ---
> > 
> > Notes:
> >     v2:
> >     - fixed server type to 'inet' in test
> >     - removed spurious 'transport' value in test
> > 
> >  src/util/virstoragefile.c | 28 ++++++++++++++++++++++++----
> >  tests/virstoragetest.c    | 11 +++++++++++
> >  2 files changed, 35 insertions(+), 4 deletions(-)
> 
> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Thanks! I've pushed the series.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list