[libvirt] [PATCH v2 0/2] Fix parsing and formatting of 'UnixSocketAddress' qapi type

v2: Don't 'fix' it for gluster disks which use old syntax not conforming to the schema in qemu. Peter Krempa (2): storage: Fix formatting and parsing of qemu type 'UnixSocketAddress' virstoragetest: Add test case for NBD over unix socket with new syntax src/qemu/qemu_block.c | 13 +++++++++++-- src/util/virstoragefile.c | 8 +++++++- tests/virstoragetest.c | 9 +++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) -- 2.15.0

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=1544325 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_block.c | 13 +++++++++++-- src/util/virstoragefile.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 8b71679118..6f81e9d96c 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -467,11 +467,14 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) /** * qemuBlockStorageSourceBuildJSONSocketAddress * @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 * 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. */ static virJSONValuePtr @@ -481,6 +484,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host, virJSONValuePtr server = NULL; virJSONValuePtr ret = NULL; const char *transport; + const char *field; char *port = NULL; switch ((virStorageNetHostTransport) host->transport) { @@ -502,9 +506,14 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host, break; case VIR_STORAGE_NET_HOST_TRANS_UNIX: + if (legacy) + field = "s:socket"; + else + field = "s:path"; + if (virJSONValueObjectCreate(&server, "s:type", "unix", - "s:socket", host->socket, + field, host->socket, NULL) < 0) goto cleanup; break; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 7f878039ba..ebfb0a860a 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2893,7 +2893,13 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host, } else if (STREQ(type, "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", _("missing socket path for udp backing server in " "JSON backing volume definition")); -- 2.15.0

Use the new syntax which uses the 'UnixSocket' type in qemu. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virstoragetest.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 6eed7134ed..16c271c781 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1494,6 +1494,15 @@ mymain(void) "<source protocol='nbd' name='blah'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"nbd\"," + "\"server\": { \"type\":\"unix\"," + "\"path\":\"/path/socket\"" + "}" + "}" + "}", + "<source protocol='nbd'>\n" + " <host transport='unix' socket='/path/socket'/>\n" + "</source>\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\"," "\"host\":\"example.org\"," "\"port\":\"6000\"," -- 2.15.0

On Wed, Feb 14, 2018 at 01:33:09PM +0100, Peter Krempa wrote:
v2: Don't 'fix' it for gluster disks which use old syntax not conforming to the schema in qemu.
Peter Krempa (2): storage: Fix formatting and parsing of qemu type 'UnixSocketAddress' virstoragetest: Add test case for NBD over unix socket with new syntax
src/qemu/qemu_block.c | 13 +++++++++++-- src/util/virstoragefile.c | 8 +++++++- tests/virstoragetest.c | 9 +++++++++ 3 files changed, 27 insertions(+), 3 deletions(-)
ACK series Jan
participants (2)
-
Ján Tomko
-
Peter Krempa