提交 a3a3de9b 编写于 作者: P Peter Krempa

storage: Fix formatting and parsing of qemu type 'UnixSocketAddress'

The documentation for the JSON/qapi type 'UnixSocketAddress' states that
the unix socket path field is named 'path'. Unfortunately qemu uses
'socket' in case of the gluster driver (despite documented otherwise).

Add logic which will format the correct fields while keeping support of
the old spelling.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1544325Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 bc84bb9f
...@@ -467,11 +467,14 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) ...@@ -467,11 +467,14 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
/** /**
* qemuBlockStorageSourceBuildJSONSocketAddress * qemuBlockStorageSourceBuildJSONSocketAddress
* @host: the virStorageNetHostDefPtr definition to build * @host: the virStorageNetHostDefPtr definition to build
* @legacy: use 'tcp' instead of 'inet' for compatibility reasons * @legacy: use old field names/values
* *
* Formats @hosts into a json object conforming to the 'SocketAddress' type * Formats @hosts into a json object conforming to the 'SocketAddress' type
* in qemu. * in qemu.
* *
* For compatibility with old approach used in the gluster driver of old qemus
* use the old spelling for TCP transport and, the path field of the unix socket.
*
* Returns a virJSONValuePtr for a single server. * Returns a virJSONValuePtr for a single server.
*/ */
static virJSONValuePtr static virJSONValuePtr
...@@ -481,6 +484,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host, ...@@ -481,6 +484,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host,
virJSONValuePtr server = NULL; virJSONValuePtr server = NULL;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
const char *transport; const char *transport;
const char *field;
char *port = NULL; char *port = NULL;
switch ((virStorageNetHostTransport) host->transport) { switch ((virStorageNetHostTransport) host->transport) {
...@@ -502,9 +506,14 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host, ...@@ -502,9 +506,14 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host,
break; break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX: case VIR_STORAGE_NET_HOST_TRANS_UNIX:
if (legacy)
field = "s:socket";
else
field = "s:path";
if (virJSONValueObjectCreate(&server, if (virJSONValueObjectCreate(&server,
"s:type", "unix", "s:type", "unix",
"s:socket", host->socket, field, host->socket,
NULL) < 0) NULL) < 0)
goto cleanup; goto cleanup;
break; break;
......
...@@ -2893,7 +2893,13 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host, ...@@ -2893,7 +2893,13 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
} else if (STREQ(type, "unix")) { } else if (STREQ(type, "unix")) {
host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX; host->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX;
if (!(socket = virJSONValueObjectGetString(json, "socket"))) { socket = virJSONValueObjectGetString(json, "path");
/* check for old spelling for gluster protocol */
if (!socket)
socket = virJSONValueObjectGetString(json, "socket");
if (!socket) {
virReportError(VIR_ERR_INVALID_ARG, "%s", virReportError(VIR_ERR_INVALID_ARG, "%s",
_("missing socket path for udp backing server in " _("missing socket path for udp backing server in "
"JSON backing volume definition")); "JSON backing volume definition"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册