[libvirt] [PATCH 0/2] util: storage: Fixes for the JSON pseudo protocol parser

Gluster protocol type was not set properly and the RBD protocol was missing. Peter Krempa (2): util: storage: Properly set protocol type when parsing gluster json string util: storage: Add json pseudo protocol support for legacy RBD strings src/util/virstoragefile.c | 26 ++++++++++++++++++++++++++ tests/virstoragetest.c | 10 ++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) -- 2.9.2

Commit 2ed772cd forgot to set proper protocol. This was also present in the test data. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1372251 --- src/util/virstoragefile.c | 3 +++ tests/virstoragetest.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index feeb061..02cae66 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2786,6 +2786,9 @@ virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src, return -1; } + src->type = VIR_STORAGE_TYPE_NETWORK; + src->protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; + if (VIR_STRDUP(src->volume, volume) < 0 || virAsprintf(&src->path, "/%s", path) < 0) return -1; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index f7f5030..fd79abb 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1412,7 +1412,7 @@ mymain(void) "]" "}" "}", - "<source protocol='none' name='testvol/img.qcow2'>\n" + "<source protocol='gluster' name='testvol/img.qcow2'>\n" " <host name='example.com' port='1234'/>\n" " <host transport='unix' socket='/path/socket'/>\n" " <host name='example.com'/>\n" @@ -1432,7 +1432,7 @@ mymain(void) "}" "]" "}", - "<source protocol='none' name='testvol/img.qcow2'>\n" + "<source protocol='gluster' name='testvol/img.qcow2'>\n" " <host name='example.com' port='1234'/>\n" " <host transport='unix' socket='/path/socket'/>\n" " <host name='example.com'/>\n" -- 2.9.2

RBD in qemu still uses only the legacy 'filename' syntax. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1371758 --- src/util/virstoragefile.c | 23 +++++++++++++++++++++++ tests/virstoragetest.c | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 02cae66..41827f0 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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}, }; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index fd79abb..f766df1 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -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 */ -- 2.9.2

On Mon, Sep 05, 2016 at 18:42:45 +0200, Peter Krempa wrote:
Gluster protocol type was not set properly and the RBD protocol was missing.
Peter Krempa (2): util: storage: Properly set protocol type when parsing gluster json string util: storage: Add json pseudo protocol support for legacy RBD strings
src/util/virstoragefile.c | 26 ++++++++++++++++++++++++++ tests/virstoragetest.c | 10 ++++++++--
ACK both Jirka
participants (2)
-
Jiri Denemark
-
Peter Krempa