From 98ee2fc5d1f1650aa8fafaf5448f48bf6bdcd48b Mon Sep 17 00:00:00 2001 Message-Id: <98ee2fc5d1f1650aa8fafaf5448f48bf6bdcd48b@dist-git> From: Peter Krempa Date: Tue, 2 Aug 2016 13:41:50 +0200 Subject: [PATCH] util: storage: Add support for URI based backing volumes in qemu's JSON pseudo-protocol 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. (cherry picked from commit ba05b5b7e78476497fb2222f449b8cad2738acb1) https://bugzilla.redhat.com/show_bug.cgi?id=1134878 [JSON backing] https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host] --- src/util/virstoragefile.c | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/virstoragetest.c | 15 +++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 45266c5..06f7f56 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2546,6 +2546,44 @@ virStorageSourceParseBackingJSONPath(virStorageSourcePtr src, } +static int +virStorageSourceParseBackingJSONUriStr(virStorageSourcePtr src, + const char *uri, + int protocol) +{ + 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; +} + + +static int +virStorageSourceParseBackingJSONUri(virStorageSourcePtr src, + virJSONValuePtr json, + int protocol) +{ + const char *uri; + + if (!(uri = virJSONValueObjectGetString(json, "uri"))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing URI in JSON backing volume definition")); + return -1; + } + + return virStorageSourceParseBackingJSONUriStr(src, uri, protocol); +} + + struct virStorageSourceJSONDriverParser { const char *drvname; int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque); @@ -2556,6 +2594,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 6873180..f8e6e9a 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1376,6 +1376,21 @@ mymain(void) TEST_BACKING_PARSE("json:{\"file.driver\":\"host_cdrom\", " "\"file.filename\":\"/path/to/cdrom\"}", "\n"); + TEST_BACKING_PARSE("json:{\"file.driver\":\"http\", " + "\"file.uri\":\"http://example.com/file\"}", + "\n" + " \n" + "\n"); + TEST_BACKING_PARSE("json:{\"file\":{ \"driver\":\"http\"," + "\"uri\":\"http://example.com/file\"" + "}" + "}", + "\n" + " \n" + "\n"); + TEST_BACKING_PARSE("json:{\"file.driver\":\"ftp\", " + "\"file.uri\":\"http://example.com/file\"}", + NULL); cleanup: /* Final cleanup */ -- 2.9.2