[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 04/13] qemu: support named nbd exports



These are supported by nbd-server and by the NBD server that QEMU
embeds for live image access.

Signed-off-by: Paolo Bonzini <pbonzini redhat com>
---
 docs/formatdomain.html.in                          |  6 ++--
 src/qemu/qemu_command.c                            | 17 +++++++++++
 tests/qemuargv2xmltest.c                           |  1 +
 ...qemuxml2argv-disk-drive-network-nbd-export.args |  5 ++++
 .../qemuxml2argv-disk-drive-network-nbd-export.xml | 33 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  2 ++
 tests/qemuxml2xmltest.c                            |  1 +
 7 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a9003d7..90cfc03 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1441,9 +1441,9 @@
         are "nbd", "rbd", "sheepdog" or "gluster".  If the
         <code>protocol</code> attribute is "rbd", "sheepdog" or "gluster", an
         additional attribute <code>name</code> is mandatory to specify which
-        volume/image will be used.  When the disk <code>type</code> is
-        "network", the <code>source</code> may have zero or
-        more <code>host</code> sub-elements used to specify the hosts
+        volume/image will be used; for "nbd" it is optional.  When the disk
+        <code>type</code> is "network", the <code>source</code> may have zero
+        or more <code>host</code> sub-elements used to specify the hosts
         to connect.
         <span class="since">Since 0.0.3; <code>type='dir'</code> since
         0.7.5; <code>type='network'</code> since 0.8.7</span><br/>
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index beb7cfe..4762f0a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2132,6 +2132,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
 {
     virDomainDiskHostDefPtr h = NULL;
     char *host, *port;
+    char *src;
 
     if (VIR_ALLOC(h) < 0)
         goto no_memory;
@@ -2149,11 +2150,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;
@@ -2254,6 +2268,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 3c23010..1731022 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -182,6 +182,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 0000000..bf411ff
--- /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 0000000..f2b5ca4
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-nbd-export.xml
@@ -0,0 +1,33 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <disk type='network' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source protocol='nbd' name='bar'>
+        <host name='example.org' port='6000'/>
+      </source>
+      <target dev='vda' bus='virtio'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 4357068..7d44be2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -485,6 +485,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 2fa93a9..cdf6554 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -167,6 +167,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");
-- 
1.8.1.2



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]