diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 1ef80b06ca..db3d171c3c 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1441,9 +1441,9 @@ are "nbd", "rbd", "sheepdog" or "gluster". If the protocol attribute is "rbd", "sheepdog" or "gluster", an additional attribute name is mandatory to specify which - volume/image will be used. When the disk type is - "network", the source may have zero or - more host sub-elements used to specify the hosts + volume/image will be used; for "nbd" it is optional. When the disk + type is "network", the source may have zero + or more host sub-elements used to specify the hosts to connect. Since 0.0.3; type='dir' since 0.7.5; type='network' since 0.8.7
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9e2d6a9bf6..0d2083ffc7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2378,6 +2378,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) { virDomainDiskHostDefPtr h = NULL; char *host, *port; + char *src; if (VIR_ALLOC(h) < 0) goto no_memory; @@ -2395,11 +2396,24 @@ qemuParseNBDString(virDomainDiskDefPtr disk) if (!h->name) goto no_memory; + src = strchr(port, ':'); + if (src) + *src++ = '\0'; + h->port = strdup(port); if (!h->port) goto no_memory; + if (src && STRPREFIX(src, "exportname=")) { + src = strdup(strchr(src, '=') + 1); + if (!src) + goto no_memory; + } else { + src = NULL; + } + VIR_FREE(disk->src); + disk->src = src; disk->nhosts = 1; disk->hosts = h; return 0; @@ -2503,6 +2517,9 @@ qemuBuildNBDString(virDomainDiskDefPtr disk, virBufferPtr opt) break; } + if (disk->src) + virBufferEscape(opt, ',', ",", ":exportname=%s", disk->src); + return 0; } diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index f7d6019b04..24f8129c12 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -185,6 +185,7 @@ mymain(void) DO_TEST("disk-drive-cache-directsync"); DO_TEST("disk-drive-cache-unsafe"); DO_TEST("disk-drive-network-nbd"); + DO_TEST("disk-drive-network-nbd-export"); DO_TEST("disk-drive-network-gluster"); DO_TEST("disk-drive-network-rbd"); DO_TEST("disk-drive-network-rbd-ipv6"); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.args new file mode 100644 index 0000000000..bc9d93dc53 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ +pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi -boot c -usb -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0 \ +-drive file=nbd:example.org:6000:exportname=bar,if=virtio,format=raw \ +-net none -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.xml new file mode 100644 index 0000000000..f2b5ca46fd --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.xml @@ -0,0 +1,33 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c77b73f66f..52ecb9240e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -493,6 +493,8 @@ mymain(void) QEMU_CAPS_DRIVE_CACHE_UNSAFE, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-nbd", QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); + DO_TEST("disk-drive-network-nbd-export", + QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-gluster", QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-rbd", diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 8c4487039b..e699fd1731 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -170,6 +170,7 @@ mymain(void) DO_TEST("disk-drive-cache-v1-wb"); DO_TEST("disk-drive-cache-v1-none"); DO_TEST("disk-drive-network-nbd"); + DO_TEST("disk-drive-network-nbd-export"); DO_TEST("disk-scsi-device"); DO_TEST("disk-scsi-vscsi"); DO_TEST("disk-scsi-virtio-scsi");