[libvirt] [PATCH v2] qemu: set bind mode for chardev while parsing XML

Pavel Hrdina posted 1 patch 6 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/be6a415e5115047a10e64c6b7f7b3f7294ae5cc4.1504108366.git.phrdina@redhat.com
src/qemu/qemu_domain.c                             | 13 +++++++++---
...muxml2argv-chardev-reconnect-generated-path.xml | 23 ++++++++++++++++++++++
tests/qemuxml2argvtest.c                           |  3 +++
3 files changed, 36 insertions(+), 3 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-chardev-reconnect-generated-path.xml
[libvirt] [PATCH v2] qemu: set bind mode for chardev while parsing XML
Posted by Pavel Hrdina 6 years, 7 months ago
Currently while parsing domain XML we clear the UNIX path if it matches
one of the auto-generated paths by libvirt.  After that when the guest
is started new path is generated but the mode is also changed to "bind".

In the real-world use-case the mode should not change, it only happens
if a user provides a mode='connect' and path that matches one of the
auto-generated path or not provides a path at all.

Before *reconnect* feature was introduced there was no issue, but with
the new feature we need to make sure that it's used only with "connect"
mode, therefore we need to move the mode change into parsing in order
to have a proper error reported by validation code.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_domain.c                             | 13 +++++++++---
 ...muxml2argv-chardev-reconnect-generated-path.xml | 23 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  3 +++
 3 files changed, 36 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-chardev-reconnect-generated-path.xml

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index bf57f94a50..cbee151f5d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3766,8 +3766,17 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     /* clear auto generated unix socket path for inactive definitions */
     if ((parseFlags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
         dev->type == VIR_DOMAIN_DEVICE_CHR) {
-        if (qemuDomainChrDefDropDefaultPath(dev->data.chr, driver) < 0)
+        virDomainChrDefPtr chr = dev->data.chr;
+        if (qemuDomainChrDefDropDefaultPath(chr, driver) < 0)
             goto cleanup;
+
+        /* For UNIX chardev if no path is provided we generate one.
+         * This also implies that the mode is 'bind'. */
+        if (chr->source &&
+            chr->source->type == VIR_DOMAIN_CHR_TYPE_UNIX &&
+            !chr->source->data.nix.path) {
+            chr->source->data.nix.listen = true;
+        }
     }
 
     if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) {
@@ -7441,8 +7450,6 @@ qemuDomainPrepareChannel(virDomainChrDefPtr channel,
             return -1;
     }
 
-    channel->source->data.nix.listen = true;
-
     return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-chardev-reconnect-generated-path.xml b/tests/qemuxml2argvdata/qemuxml2argv-chardev-reconnect-generated-path.xml
new file mode 100644
index 0000000000..3cb67ecdcc
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-chardev-reconnect-generated-path.xml
@@ -0,0 +1,23 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-i686</emulator>
+    <controller type='virtio-serial' index='1'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
+    </controller>
+    <channel type='unix'>
+      <source mode='connect' path='/tmp/channel/domain-oldname/asdf'>
+        <reconnect enabled='yes' timeout='10'/>
+      </source>
+      <target type='virtio' name='asdf'/>
+    </channel>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 0c0bd16f94..18f06e5aa5 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1351,6 +1351,9 @@ mymain(void)
     DO_TEST_PARSE_ERROR("chardev-reconnect-invalid-timeout",
                         QEMU_CAPS_NODEFCONFIG,
                         QEMU_CAPS_CHARDEV_RECONNECT);
+    DO_TEST_PARSE_ERROR("chardev-reconnect-generated-path",
+                        QEMU_CAPS_NODEFCONFIG,
+                        QEMU_CAPS_CHARDEV_RECONNECT);
 
     DO_TEST("usb-controller",
             QEMU_CAPS_NODEFCONFIG);
-- 
2.13.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] qemu: set bind mode for chardev while parsing XML
Posted by Michal Privoznik 6 years, 7 months ago
On 08/30/2017 05:53 PM, Pavel Hrdina wrote:
> Currently while parsing domain XML we clear the UNIX path if it matches
> one of the auto-generated paths by libvirt.  After that when the guest
> is started new path is generated but the mode is also changed to "bind".
> 
> In the real-world use-case the mode should not change, it only happens
> if a user provides a mode='connect' and path that matches one of the
> auto-generated path or not provides a path at all.
> 
> Before *reconnect* feature was introduced there was no issue, but with
> the new feature we need to make sure that it's used only with "connect"
> mode, therefore we need to move the mode change into parsing in order
> to have a proper error reported by validation code.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/qemu/qemu_domain.c                             | 13 +++++++++---
>  ...muxml2argv-chardev-reconnect-generated-path.xml | 23 ++++++++++++++++++++++
>  tests/qemuxml2argvtest.c                           |  3 +++
>  3 files changed, 36 insertions(+), 3 deletions(-)
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-chardev-reconnect-generated-path.xml

Yup, definitely better.

ACK and safe for the freeze.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list