|
|
6ae9ed |
From e8733d3357443e9265d923ff0824ae13902a4f9a Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <e8733d3357443e9265d923ff0824ae13902a4f9a@dist-git>
|
|
|
6ae9ed |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
6ae9ed |
Date: Tue, 2 Aug 2016 13:41:51 +0200
|
|
|
6ae9ed |
Subject: [PATCH] util: storage: Add json pseudo protocol support for gluster
|
|
|
6ae9ed |
volumes
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Along with the legacy URI based syntax add support for the brand-new
|
|
|
6ae9ed |
fully object based syntax.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
(cherry picked from commit 2ed772cd635bfc0fa332c1122aea3f489b879b1a)
|
|
|
6ae9ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1134878 [JSON backing]
|
|
|
6ae9ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host]
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
src/util/virstoragefile.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
6ae9ed |
tests/virstoragetest.c | 46 ++++++++++++++++++++
|
|
|
6ae9ed |
2 files changed, 154 insertions(+)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
6ae9ed |
index 06f7f56..23cdf4b 100644
|
|
|
6ae9ed |
--- a/src/util/virstoragefile.c
|
|
|
6ae9ed |
+++ b/src/util/virstoragefile.c
|
|
|
6ae9ed |
@@ -2584,6 +2584,113 @@ virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+static int
|
|
|
6ae9ed |
+virStorageSourceParseBackingJSONGlusterHost(virStorageNetHostDefPtr host,
|
|
|
6ae9ed |
+ virJSONValuePtr json)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ const char *type = virJSONValueObjectGetString(json, "type");
|
|
|
6ae9ed |
+ const char *hostname = virJSONValueObjectGetString(json, "host");
|
|
|
6ae9ed |
+ const char *port = virJSONValueObjectGetString(json, "port");
|
|
|
6ae9ed |
+ const char *socket = virJSONValueObjectGetString(json, "socket");
|
|
|
6ae9ed |
+ int transport;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if ((transport = virStorageNetHostTransportTypeFromString(type)) < 0) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
6ae9ed |
+ _("unknown backing store transport protocol '%s'"), type);
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ host->transport = transport;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ switch ((virStorageNetHostTransport) transport) {
|
|
|
6ae9ed |
+ case VIR_STORAGE_NET_HOST_TRANS_TCP:
|
|
|
6ae9ed |
+ if (!hostname) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
6ae9ed |
+ _("missing hostname for tcp backing server in "
|
|
|
6ae9ed |
+ "JSON backing definition for gluster volume"));
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (VIR_STRDUP(host->name, hostname) < 0 ||
|
|
|
6ae9ed |
+ VIR_STRDUP(host->port, port) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ case VIR_STORAGE_NET_HOST_TRANS_UNIX:
|
|
|
6ae9ed |
+ if (!socket) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
6ae9ed |
+ _("missing socket path for udp backing server in "
|
|
|
6ae9ed |
+ "JSON backing definition for gluster volume"));
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (VIR_STRDUP(host->socket, socket) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ case VIR_STORAGE_NET_HOST_TRANS_RDMA:
|
|
|
6ae9ed |
+ case VIR_STORAGE_NET_HOST_TRANS_LAST:
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
6ae9ed |
+ _("backing store protocol '%s' is not yet supported"),
|
|
|
6ae9ed |
+ type);
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ return 0;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+static int
|
|
|
6ae9ed |
+virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src,
|
|
|
6ae9ed |
+ virJSONValuePtr json,
|
|
|
6ae9ed |
+ int opaque ATTRIBUTE_UNUSED)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ const char *uri = virJSONValueObjectGetString(json, "filename");
|
|
|
6ae9ed |
+ const char *volume = virJSONValueObjectGetString(json, "volume");
|
|
|
6ae9ed |
+ const char *path = virJSONValueObjectGetString(json, "path");
|
|
|
6ae9ed |
+ virJSONValuePtr server = virJSONValueObjectGetArray(json, "server");
|
|
|
6ae9ed |
+ size_t nservers;
|
|
|
6ae9ed |
+ size_t i;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ /* legacy URI based syntax passed via 'filename' option */
|
|
|
6ae9ed |
+ if (uri)
|
|
|
6ae9ed |
+ return virStorageSourceParseBackingJSONUriStr(src, uri,
|
|
|
6ae9ed |
+ VIR_STORAGE_NET_PROTOCOL_GLUSTER);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (!volume || !path || !server) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
6ae9ed |
+ _("missing 'volume', 'path' or 'server' attribute in "
|
|
|
6ae9ed |
+ "JSON backing definition for gluster volume"));
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (VIR_STRDUP(src->volume, volume) < 0 ||
|
|
|
6ae9ed |
+ virAsprintf(&src->path, "/%s", path) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ nservers = virJSONValueArraySize(server);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (nservers < 1) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
6ae9ed |
+ _("at least 1 server is necessary in "
|
|
|
6ae9ed |
+ "JSON backing definition for gluster volume"));
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (VIR_ALLOC_N(src->hosts, nservers) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ src->nhosts = nservers;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ for (i = 0; i < nservers; i++) {
|
|
|
6ae9ed |
+ if (virStorageSourceParseBackingJSONGlusterHost(src->hosts + i,
|
|
|
6ae9ed |
+ virJSONValueArrayGet(server, i)) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ return 0;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
struct virStorageSourceJSONDriverParser {
|
|
|
6ae9ed |
const char *drvname;
|
|
|
6ae9ed |
int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
|
|
|
6ae9ed |
@@ -2599,6 +2706,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
|
|
|
6ae9ed |
{"ftp", virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PROTOCOL_FTP},
|
|
|
6ae9ed |
{"ftps", virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PROTOCOL_FTPS},
|
|
|
6ae9ed |
{"tftp", virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PROTOCOL_TFTP},
|
|
|
6ae9ed |
+ {"gluster", virStorageSourceParseBackingJSONGluster, 0},
|
|
|
6ae9ed |
};
|
|
|
6ae9ed |
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
|
|
|
6ae9ed |
index f8e6e9a..22aae47 100644
|
|
|
6ae9ed |
--- a/tests/virstoragetest.c
|
|
|
6ae9ed |
+++ b/tests/virstoragetest.c
|
|
|
6ae9ed |
@@ -1391,6 +1391,52 @@ mymain(void)
|
|
|
6ae9ed |
TEST_BACKING_PARSE("json:{\"file.driver\":\"ftp\", "
|
|
|
6ae9ed |
"\"file.uri\":\"http://example.com/file\"}",
|
|
|
6ae9ed |
NULL);
|
|
|
6ae9ed |
+ TEST_BACKING_PARSE("json:{\"file.driver\":\"gluster\", "
|
|
|
6ae9ed |
+ "\"file.filename\":\"gluster://example.com/vol/file\"}",
|
|
|
6ae9ed |
+ "<source protocol='gluster' name='vol/file'>\n"
|
|
|
6ae9ed |
+ " <host name='example.com'/>\n"
|
|
|
6ae9ed |
+ "</source>\n");
|
|
|
6ae9ed |
+ TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"gluster\","
|
|
|
6ae9ed |
+ "\"volume\":\"testvol\","
|
|
|
6ae9ed |
+ "\"path\":\"img.qcow2\","
|
|
|
6ae9ed |
+ "\"server\":[ { \"type\":\"tcp\","
|
|
|
6ae9ed |
+ "\"host\":\"example.com\","
|
|
|
6ae9ed |
+ "\"port\":\"1234\""
|
|
|
6ae9ed |
+ "},"
|
|
|
6ae9ed |
+ "{ \"type\":\"unix\","
|
|
|
6ae9ed |
+ "\"socket\":\"/path/socket\""
|
|
|
6ae9ed |
+ "},"
|
|
|
6ae9ed |
+ "{ \"type\":\"tcp\","
|
|
|
6ae9ed |
+ "\"host\":\"example.com\""
|
|
|
6ae9ed |
+ "}"
|
|
|
6ae9ed |
+ "]"
|
|
|
6ae9ed |
+ "}"
|
|
|
6ae9ed |
+ "}",
|
|
|
6ae9ed |
+ "<source protocol='none' name='testvol/img.qcow2'>\n"
|
|
|
6ae9ed |
+ " <host name='example.com' port='1234'/>\n"
|
|
|
6ae9ed |
+ " <host transport='unix' socket='/path/socket'/>\n"
|
|
|
6ae9ed |
+ " <host name='example.com'/>\n"
|
|
|
6ae9ed |
+ "</source>\n");
|
|
|
6ae9ed |
+ TEST_BACKING_PARSE("json:{\"file.driver\":\"gluster\","
|
|
|
6ae9ed |
+ "\"file.volume\":\"testvol\","
|
|
|
6ae9ed |
+ "\"file.path\":\"img.qcow2\","
|
|
|
6ae9ed |
+ "\"file.server\":[ { \"type\":\"tcp\","
|
|
|
6ae9ed |
+ "\"host\":\"example.com\","
|
|
|
6ae9ed |
+ "\"port\":\"1234\""
|
|
|
6ae9ed |
+ "},"
|
|
|
6ae9ed |
+ "{ \"type\":\"unix\","
|
|
|
6ae9ed |
+ "\"socket\":\"/path/socket\""
|
|
|
6ae9ed |
+ "},"
|
|
|
6ae9ed |
+ "{ \"type\":\"tcp\","
|
|
|
6ae9ed |
+ "\"host\":\"example.com\""
|
|
|
6ae9ed |
+ "}"
|
|
|
6ae9ed |
+ "]"
|
|
|
6ae9ed |
+ "}",
|
|
|
6ae9ed |
+ "<source protocol='none' name='testvol/img.qcow2'>\n"
|
|
|
6ae9ed |
+ " <host name='example.com' port='1234'/>\n"
|
|
|
6ae9ed |
+ " <host transport='unix' socket='/path/socket'/>\n"
|
|
|
6ae9ed |
+ " <host name='example.com'/>\n"
|
|
|
6ae9ed |
+ "</source>\n");
|
|
|
6ae9ed |
|
|
|
6ae9ed |
cleanup:
|
|
|
6ae9ed |
/* Final cleanup */
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|