[libvirt] [PATCH] domain_conf: vnc: preserve autoport value if no port was specified

The issue is that if this graphics definition is provided: <graphics type='vnc' port='0'/> it's parsed as: <graphics type='vnc' autoport='no'> <listen type='address'/> </graphics> but if the resulting XML is parsed again the output is: <graphics type='vnc' port='-1' autoport='yes'> <listen type='address'/> </graphics> and this should not happen. The XML have to always remain the same after it was already parsed by libvirt. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1383039 Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 2 ++ .../generic-graphics-vnc-autoport-no.xml | 30 ++++++++++++++++++++++ tests/genericxml2xmltest.c | 1 + 3 files changed, 33 insertions(+) create mode 100644 tests/genericxml2xmlindata/generic-graphics-vnc-autoport-no.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 26bb0fdd0a..ffd020f641 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11716,6 +11716,8 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) def->data.vnc.port = 0; def->data.vnc.autoport = true; + } else { + def->data.vnc.autoport = false; } } diff --git a/tests/genericxml2xmlindata/generic-graphics-vnc-autoport-no.xml b/tests/genericxml2xmlindata/generic-graphics-vnc-autoport-no.xml new file mode 100644 index 0000000000..748e7f489d --- /dev/null +++ b/tests/genericxml2xmlindata/generic-graphics-vnc-autoport-no.xml @@ -0,0 +1,30 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</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> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <graphics type='vnc' autoport='no'> + <listen type='address'/> + </graphics> + <video> + <model type='cirrus' vram='16384' heads='1' primary='yes'/> + </video> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 2ea2396480..488190270f 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -91,6 +91,7 @@ mymain(void) DO_TEST_DIFFERENT("graphics-vnc-socket-attr-listen-socket"); DO_TEST_FULL("graphics-vnc-socket-attr-listen-socket-mismatch", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + DO_TEST("graphics-vnc-autoport-no"); DO_TEST_FULL("name-slash-fail", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); -- 2.11.0

On 01/25/2017 12:26 PM, Pavel Hrdina wrote:
The issue is that if this graphics definition is provided:
<graphics type='vnc' port='0'/>
it's parsed as:
<graphics type='vnc' autoport='no'> <listen type='address'/> </graphics>
but if the resulting XML is parsed again the output is:
<graphics type='vnc' port='-1' autoport='yes'> <listen type='address'/> </graphics>
and this should not happen. The XML have to always remain the same after it was already parsed by libvirt.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1383039
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 2 ++ .../generic-graphics-vnc-autoport-no.xml | 30 ++++++++++++++++++++++ tests/genericxml2xmltest.c | 1 + 3 files changed, 33 insertions(+) create mode 100644 tests/genericxml2xmlindata/generic-graphics-vnc-autoport-no.xml
I know this is a VNC bug, but RDP has similar code which would seemingly have the same issue. The SPICE code is a bit different (I assume it doesn't have the legacy compat issue). It doesn't set autoport when "port" is not supplied. ACK for this change, though. John

On Thu, Jan 26, 2017 at 04:30:31PM -0500, John Ferlan wrote:
On 01/25/2017 12:26 PM, Pavel Hrdina wrote:
The issue is that if this graphics definition is provided:
<graphics type='vnc' port='0'/>
it's parsed as:
<graphics type='vnc' autoport='no'> <listen type='address'/> </graphics>
but if the resulting XML is parsed again the output is:
<graphics type='vnc' port='-1' autoport='yes'> <listen type='address'/> </graphics>
and this should not happen. The XML have to always remain the same after it was already parsed by libvirt.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1383039
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 2 ++ .../generic-graphics-vnc-autoport-no.xml | 30 ++++++++++++++++++++++ tests/genericxml2xmltest.c | 1 + 3 files changed, 33 insertions(+) create mode 100644 tests/genericxml2xmlindata/generic-graphics-vnc-autoport-no.xml
I know this is a VNC bug, but RDP has similar code which would seemingly have the same issue.
I've also checked the RDP code and tested it and it seemed that it didn't have the same issue even though the code is the same. However I've tested it again and it does have the same issue, I'll send a patch for that as well.
The SPICE code is a bit different (I assume it doesn't have the legacy compat issue). It doesn't set autoport when "port" is not supplied.
ACK for this change, though.
Thanks, I'll push it shortly. Pavel
participants (2)
-
John Ferlan
-
Pavel Hrdina