[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [libvirt RFC PATCH 05/10] util: storage: Add json pseudo pr
From: |
Peter Krempa |
Subject: |
[Qemu-block] [libvirt RFC PATCH 05/10] util: storage: Add json pseudo protocol support for gluster volumes |
Date: |
Fri, 15 Jul 2016 15:46:38 +0200 |
Extract the common code of the URI parser and reuse it with gluster
volumes. The gluster code has a separate function as multi-host support
will add an alternative to the URI syntax.
---
src/util/virstoragefile.c | 52 +++++++++++++++++++++++++++++++++++++----------
tests/virstoragetest.c | 5 +++++
2 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index f8c5f64..6aaf3ff 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2538,18 +2538,10 @@
virStorageSourceParseBackingJSONPath(virStorageSourcePtr src,
static int
-virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
- virJSONValuePtr json,
- int protocol)
+virStorageSourceParseBackingJSONUriStr(virStorageSourcePtr src,
+ const char *uri,
+ int protocol)
{
- const char *uri;
-
- if (!(uri = virJSONValueObjectGetString(json, "file.uri"))) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("missing URI in JSON backing volume definition"));
- return -1;
- }
-
if (virStorageSourceParseBackingURI(src, uri) < 0)
return -1;
@@ -2566,6 +2558,43 @@ virStorageSourceParseBackingJSONUri(virStorageSourcePtr
src,
}
+static int
+virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
+ virJSONValuePtr json,
+ int protocol)
+{
+ const char *uri;
+
+ if (!(uri = virJSONValueObjectGetString(json, "file.uri"))) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("missing URI in JSON backing volume definition"));
+ return -1;
+ }
+
+ return virStorageSourceParseBackingJSONUriStr(src, uri, protocol);
+}
+
+
+static int
+virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src,
+ virJSONValuePtr json,
+ int opaque ATTRIBUTE_UNUSED)
+{
+ const char *uri;
+
+ /* legacy URI based syntax passed via 'filename' option */
+ if ((uri = virJSONValueObjectGetString(json, "file.filename")))
+ return virStorageSourceParseBackingJSONUriStr(src, uri,
+
VIR_STORAGE_NET_PROTOCOL_GLUSTER);
+
+ /* gluster currently supports only URI syntax passed in as filename */
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("missing gluster URI in JSON backing volume definition"));
+
+ return -1;
+}
+
+
struct virStorageSourceJSONDriverParser {
const char *drvname;
int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
@@ -2581,6 +2610,7 @@ static const struct virStorageSourceJSONDriverParser
jsonParsers[] = {
{"ftp", virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PROTOCOL_FTP},
{"ftps", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_FTPS},
{"tftp", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_TFTP},
+ {"gluster", virStorageSourceParseBackingJSONGluster, 0},
};
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 955e4db..4250a2f 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1375,6 +1375,11 @@ mymain(void)
TEST_BACKING_PARSE(14, "json:{\"file.driver\":\"ftp\", "
"\"file.uri\":\"http://example.com/file\"}",
NULL);
+ TEST_BACKING_PARSE(15, "json:{\"file.driver\":\"gluster\", "
+
"\"file.filename\":\"gluster://example.com/vol/file\"}",
+ "<source protocol='gluster' name='vol/file'>\n"
+ " <host name='example.com'/>\n"
+ "</source>\n");
cleanup:
/* Final cleanup */
--
2.8.2
- [Qemu-block] [libvirt RFC PATCH 00/10] Add support for qemu's JSON pseudo'protocol for backing store, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 03/10] util: storage: Add support for host device backing specified via JSON, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 01/10] tests: Add testing of backing store string parser, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 04/10] util: storage: Add support for URI based backing volumes in qemu's JSON pseudo-protocol, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 05/10] util: storage: Add json pseudo protocol support for gluster volumes,
Peter Krempa <=
- [Qemu-block] [libvirt RFC PATCH 02/10] util: storage: Add parser for qemu's "json" backing pseudo-protocol, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 06/10] util: storage: Add json pseudo protocol support for iSCSI volumes, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 07/10] Add JSON backing volume parser for 'nbd' protocol, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 09/10] util: storage: Add 'ssh' network storage protocol, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 08/10] util: storage: Add JSON backing store parser for 'sheepdog' protocol, Peter Krempa, 2016/07/15
- [Qemu-block] [libvirt RFC PATCH 10/10] util: storage: Add JSON backing volume parser for 'ssh' protocol, Peter Krempa, 2016/07/15
- Re: [Qemu-block] [libvirt] [libvirt RFC PATCH 00/10] Add support for qemu's JSON pseudo'protocol for backing store, Daniel P. Berrange, 2016/07/15