]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Add json pseudo protocol support for legacy RBD strings
authorPeter Krempa <pkrempa@redhat.com>
Mon, 5 Sep 2016 13:15:22 +0000 (15:15 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 6 Sep 2016 12:01:41 +0000 (14:01 +0200)
RBD in qemu still uses only the legacy 'filename' syntax.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1371758

src/util/virstoragefile.c
tests/virstoragetest.c

index 02cae66830c10d36f204aa6473da43a9fe50629c..41827f0c9b6a9ee6139759fea2c4444f00ebae1d 100644 (file)
@@ -2940,6 +2940,28 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
 }
 
 
+static int
+virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
+                                    virJSONValuePtr json,
+                                    int opaque ATTRIBUTE_UNUSED)
+{
+    const char *filename;
+
+    src->type = VIR_STORAGE_TYPE_NETWORK;
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
+
+    /* legacy syntax passed via 'filename' option */
+    if ((filename = virJSONValueObjectGetString(json, "filename")))
+        return virStorageSourceParseRBDColonString(filename, src);
+
+    /* RBD currently supports only URI syntax passed in as filename */
+    virReportError(VIR_ERR_INVALID_ARG, "%s",
+                   _("missing RBD filename in JSON backing volume definition"));
+
+    return -1;
+}
+
+
 struct virStorageSourceJSONDriverParser {
     const char *drvname;
     int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
@@ -2960,6 +2982,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
     {"nbd", virStorageSourceParseBackingJSONNbd, 0},
     {"sheepdog", virStorageSourceParseBackingJSONSheepdog, 0},
     {"ssh", virStorageSourceParseBackingJSONSSH, 0},
+    {"rbd", virStorageSourceParseBackingJSONRBD, 0},
 };
 
 
index fd79abbaa5409f35405a98bd1269cafbbfbeb269..f766df11533b92828d6aacf0b8e92e876356d793 100644 (file)
@@ -1486,6 +1486,12 @@ mymain(void)
                        "<source protocol='ssh' name='blah'>\n"
                        "  <host name='example.org' port='6000'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file.driver\":\"rbd\","
+                             "\"file.filename\":\"rbd:testshare:id=asdf:mon_host=example.com\""
+                            "}",
+                       "<source protocol='rbd' name='testshare'>\n"
+                       "  <host name='example.com'/>\n"
+                       "</source>\n");
 
  cleanup:
     /* Final cleanup */