[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [libvirt RFC PATCH 07/10] Add JSON backing volume parser fo
From: |
Peter Krempa |
Subject: |
[Qemu-block] [libvirt RFC PATCH 07/10] Add JSON backing volume parser for 'nbd' protocol |
Date: |
Fri, 15 Jul 2016 15:46:40 +0200 |
---
src/util/virstoragefile.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
tests/virstoragetest.c | 14 ++++++++++++++
2 files changed, 59 insertions(+)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 0679824..06f9737 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2615,6 +2615,50 @@
virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
}
+static int
+virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
+ virJSONValuePtr json,
+ int opaque ATTRIBUTE_UNUSED)
+{
+ const char *path = virJSONValueObjectGetString(json, "file.path");
+ const char *host = virJSONValueObjectGetString(json, "file.host");
+ const char *port = virJSONValueObjectGetString(json, "file.port");
+ const char *export = virJSONValueObjectGetString(json, "file.export");
+
+ if (!path && !host) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("missing path or host of NBD server in JSON backing "
+ "volume definition"));
+ return -1;
+ }
+
+ src->type = VIR_STORAGE_TYPE_NETWORK;
+ src->protocol = VIR_STORAGE_NET_PROTOCOL_NBD;
+
+ if (VIR_STRDUP(src->path, export) < 0)
+ return -1;
+
+ if (VIR_ALLOC_N(src->hosts, 1) < 0)
+ return -1;
+ src->nhosts = 1;
+
+ if (path) {
+ src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
+ if (VIR_STRDUP(src->hosts[0].socket, path) < 0)
+ return -1;
+ } else {
+ src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+ if (VIR_STRDUP(src->hosts[0].name, host) < 0)
+ return -1;
+
+ if (VIR_STRDUP(src->hosts[0].port, port) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+
struct virStorageSourceJSONDriverParser {
const char *drvname;
int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
@@ -2632,6 +2676,7 @@ static const struct virStorageSourceJSONDriverParser
jsonParsers[] = {
{"tftp", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_TFTP},
{"gluster", virStorageSourceParseBackingJSONGluster, 0},
{"iscsi", virStorageSourceParseBackingJSONiSCSI, 0},
+ {"nbd", virStorageSourceParseBackingJSONNbd, 0},
};
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 4250a2f..fcb6750 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1380,6 +1380,20 @@ mymain(void)
"<source protocol='gluster' name='vol/file'>\n"
" <host name='example.com'/>\n"
"</source>\n");
+ TEST_BACKING_PARSE(16, "json:{\"file.driver\":\"nbd\","
+ "\"file.path\":\"/path/to/socket\""
+ "}",
+ "<source protocol='nbd'>\n"
+ " <host transport='unix' socket='/path/to/socket'/>\n"
+ "</source>\n");
+ TEST_BACKING_PARSE(17, "json:{\"file.driver\":\"nbd\","
+ "\"file.export\":\"blah\","
+ "\"file.host\":\"example.org\","
+ "\"file.port\":\"6000\""
+ "}",
+ "<source protocol='nbd' name='blah'>\n"
+ " <host name='example.org' port='6000'/>\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, 2016/07/15
- [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 <=
- [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