[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [libvirt RFC PATCH 04/10] util: storage: Add support for UR
From: |
Peter Krempa |
Subject: |
[Qemu-block] [libvirt RFC PATCH 04/10] util: storage: Add support for URI based backing volumes in qemu's JSON pseudo-protocol |
Date: |
Fri, 15 Jul 2016 15:46:37 +0200 |
http(s), ftp(s) and tftp use URIs for volume definitions in the JSON
pseudo protocol so it's pretty straightforward to add support for them.
---
src/util/virstoragefile.c | 34 ++++++++++++++++++++++++++++++++++
tests/virstoragetest.c | 8 ++++++++
2 files changed, 42 insertions(+)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2e47bdb..f8c5f64 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2537,6 +2537,35 @@ virStorageSourceParseBackingJSONPath(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;
+ }
+
+ if (virStorageSourceParseBackingURI(src, uri) < 0)
+ return -1;
+
+ if (src->protocol != protocol) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("expected protocol '%s' but got '%s' in URI JSON
volume "
+ "definition"),
+ virStorageNetProtocolTypeToString(protocol),
+ virStorageNetProtocolTypeToString(src->protocol));
+ return -1;
+ }
+
+ return 0;
+}
+
+
struct virStorageSourceJSONDriverParser {
const char *drvname;
int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
@@ -2547,6 +2576,11 @@ static const struct virStorageSourceJSONDriverParser
jsonParsers[] = {
{"file", virStorageSourceParseBackingJSONPath, VIR_STORAGE_TYPE_FILE},
{"host_device", virStorageSourceParseBackingJSONPath,
VIR_STORAGE_TYPE_BLOCK},
{"host_cdrom", virStorageSourceParseBackingJSONPath,
VIR_STORAGE_TYPE_BLOCK},
+ {"http", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_HTTP},
+ {"https", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_HTTPS},
+ {"ftp", virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PROTOCOL_FTP},
+ {"ftps", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_FTPS},
+ {"tftp", virStorageSourceParseBackingJSONUri,
VIR_STORAGE_NET_PROTOCOL_TFTP},
};
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 24bb419..955e4db 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1367,6 +1367,14 @@ mymain(void)
TEST_BACKING_PARSE(12, "json:{\"file.driver\":\"host_cdrom\", "
"\"file.filename\":\"/path/to/cdrom\"}",
"<source dev='/path/to/cdrom'/>\n");
+ TEST_BACKING_PARSE(13, "json:{\"file.driver\":\"http\", "
+ "\"file.uri\":\"http://example.com/file\"}",
+ "<source protocol='http' name='file'>\n"
+ " <host name='example.com'/>\n"
+ "</source>\n");
+ TEST_BACKING_PARSE(14, "json:{\"file.driver\":\"ftp\", "
+ "\"file.uri\":\"http://example.com/file\"}",
+ NULL);
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 <=
- [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, 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