Original implementation used 'SocketAddress' equivalent from qemu for the disk server field, while qemu documentation specifies 'InetSocketAddress'. The backing store parser uses the correct parsing function but the formatter used the incorrect one (and also with the legacy mode enabled which was wrong). --- src/qemu/qemu_block.c | 36 +++++++++++++++++++++- ...muxml2argv-disk-drive-network-tlsx509-vxhs.args | 8 ++--- .../qemuxml2argv-disk-drive-network-vxhs.args | 4 +-- tests/virstoragetest.c | 3 +- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 0761f8991..96db19226 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -501,6 +501,40 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src, } +/** + * qemuBlockStorageSourceBuildJSONInetSocketAddress + * @host: the virStorageNetHostDefPtr definition to build + * + * Formats @hosts into a json object conforming to the 'InetSocketAddress' type + * in qemu. + * + * Returns a virJSONValuePtr for a single server. + */ +static virJSONValuePtr +qemuBlockStorageSourceBuildJSONInetSocketAddress(virStorageNetHostDefPtr host) +{ + virJSONValuePtr ret = NULL; + char *port = NULL; + + if (host->transport != VIR_STORAGE_NET_HOST_TRANS_TCP) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only TCP protocol can be converted to InetSocketAddress")); + return NULL; + } + + if (virAsprintf(&port, "%u", host->port) < 0) + return NULL; + + ignore_value(virJSONValueObjectCreate(&ret, + "s:host", host->name, + "s:port", port, + NULL)); + + VIR_FREE(port); + return ret; +} + + static virJSONValuePtr qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src) { @@ -540,7 +574,7 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src) return NULL; } - if (!(server = qemuBlockStorageSourceBuildJSONSocketAddress(src->hosts, true))) + if (!(server = qemuBlockStorageSourceBuildJSONInetSocketAddress(&src->hosts[0]))) return NULL; /* VxHS disk specification example: diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-tlsx509-vxhs.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-tlsx509-vxhs.args index a75272454..eaa8699a9 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-tlsx509-vxhs.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-tlsx509-vxhs.args @@ -23,7 +23,7 @@ server,nowait \ -object tls-creds-x509,id=objvirtio-disk0_tls0,dir=/etc/pki/libvirt-vxhs,\ endpoint=client,verify-peer=yes \ -drive file.driver=vxhs,file.tls-creds=objvirtio-disk0_tls0,\ -file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc251,file.server.type=tcp,\ +file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc251,\ file.server.host=192.168.0.1,file.server.port=9999,format=raw,if=none,\ id=drive-virtio-disk0,cache=none \ -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\ @@ -31,13 +31,13 @@ id=virtio-disk0 \ -object tls-creds-x509,id=objvirtio-disk1_tls0,dir=/etc/pki/libvirt-vxhs,\ endpoint=client,verify-peer=yes \ -drive file.driver=vxhs,file.tls-creds=objvirtio-disk1_tls0,\ -file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc252,file.server.type=tcp,\ +file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc252,\ file.server.host=192.168.0.2,file.server.port=9999,format=raw,if=none,\ id=drive-virtio-disk1,cache=none \ -device virtio-blk-pci,bus=pci.0,addr=0x5,drive=drive-virtio-disk1,\ id=virtio-disk1 \ -drive file.driver=vxhs,file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc253,\ -file.server.type=tcp,file.server.host=192.168.0.3,file.server.port=9999,\ -format=raw,if=none,id=drive-virtio-disk2,cache=none \ +file.server.host=192.168.0.3,file.server.port=9999,format=raw,if=none,\ +id=drive-virtio-disk2,cache=none \ -device virtio-blk-pci,bus=pci.0,addr=0x6,drive=drive-virtio-disk2,\ id=virtio-disk2 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-vxhs.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-vxhs.args index b62ace3de..1747dc80f 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-vxhs.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-vxhs.args @@ -21,7 +21,7 @@ server,nowait \ -boot c \ -usb \ -drive file.driver=vxhs,file.vdisk-id=eb90327c-8302-4725-9e1b-4e85ed4dc251,\ -file.server.type=tcp,file.server.host=192.168.0.1,file.server.port=9999,\ -format=raw,if=none,id=drive-virtio-disk0,cache=none \ +file.server.host=192.168.0.1,file.server.port=9999,format=raw,if=none,\ +id=drive-virtio-disk0,cache=none \ -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\ id=virtio-disk0 diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index e1d875172..78f24ad78 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1601,8 +1601,7 @@ mymain(void) "</source>\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"vxhs\"," "\"vdisk-id\":\"c6718f6b-0401-441d-a8c3-1f0064d75ee0\"," - "\"server\": { \"type\":\"tcp\"," - "\"host\":\"example.com\"," + "\"server\": { \"host\":\"example.com\"," "\"port\":\"9999\"" "}" "}" -- 2.14.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list