[libvirt] [PATCH 00/18] cleanup of graphics code

Pavel Hrdina (18): tests: remove unwanted VIR_FREE of spice and vnc default listen docs: rewrite graphics XML documentation domain_conf: introduce virDomainGraphicsListensParseXML domain_conf: cleanup virDomainGraphicsListensParseXML domain_conf: split graphics xml parser into multiple functions domain_conf: cleanup error paths for graphics parser domain_conf: introduce virDomainGraphicsListenAddAddress domain_conf: introduce virDomainGraphicsListenAddNetwork domain_conf: remove unused virDomainGraphicsListenSetType domain_conf: cleanup virDomainGraphicsGetListen use virDomainGraphicsGetListen instead of the other getters domain_conf: cleanup virDomainGraphicsListenDefParseXML domain_conf: remove unused virDomainGraphicsListenGet* domain_conf: call ...ListensParseXML only for appropriate graphics qemu_process: generate vnc unix socket in qemuProcessPrepareDomain qemu_process: move listen code out of qemuProcessSetupGraphics domain_conf: introduce virDomainGraphicsListenClear qemu_domain: remove all listens if vncAutoUnixSocket is enabled docs/formatdomain.html.in | 351 +++--- src/conf/domain_conf.c | 1163 ++++++++++---------- src/conf/domain_conf.h | 24 +- src/libvirt_private.syms | 10 +- src/libxl/libxl_conf.c | 15 +- src/qemu/qemu_command.c | 120 +- src/qemu/qemu_command.h | 3 +- src/qemu/qemu_domain.c | 10 + src/qemu/qemu_migration.c | 9 +- src/qemu/qemu_parse_command.c | 4 +- src/qemu/qemu_process.c | 69 +- src/vbox/vbox_common.c | 14 +- src/vmx/vmx.c | 9 +- src/vz/vz_sdk.c | 11 +- src/xenconfig/xen_common.c | 28 +- src/xenconfig/xen_sxpr.c | 20 +- src/xenconfig/xen_xl.c | 12 +- .../qemuxml2argv-graphics-spice-timeout.args | 2 +- ...-graphics-vnc-auto-unix-socket-with-listen.args | 22 + ...v-graphics-vnc-auto-unix-socket-with-listen.xml | 36 + ...qemuxml2argv-graphics-vnc-auto-unix-socket.args | 22 + .../qemuxml2argv-graphics-vnc-auto-unix-socket.xml | 34 + tests/qemuxml2argvtest.c | 8 +- 23 files changed, 1051 insertions(+), 945 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml -- 2.7.4

After the test and qemu_process refactor now we can benefit from default listen address for spice and vnc in tests. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args | 2 +- tests/qemuxml2argvtest.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args index 8a29a7e..0950c1b 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args @@ -29,7 +29,7 @@ media=cdrom,id=drive-ide0-1-0 \ -net tap,fd=3,vlan=0,name=hostnet0 \ -serial pty \ -device usb-tablet,id=input0 \ --spice port=5900 \ +-spice port=5900,addr=127.0.0.1 \ -vga std \ -device AC97,id=sound0,bus=pci.0,addr=0x3 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e9b8d64..f8d0f56 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -489,9 +489,6 @@ mymain(void) driver.privileged = true; - VIR_FREE(driver.config->spiceListen); - VIR_FREE(driver.config->vncListen); - VIR_FREE(driver.config->vncTLSx509certdir); if (VIR_STRDUP_QUIET(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0) return EXIT_FAILURE; -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:18PM +0200, Pavel Hrdina wrote:
After the test and qemu_process refactor now we can benefit from default listen address for spice and vnc in tests.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args | 2 +- tests/qemuxml2argvtest.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-)
ACK Jan

This cleanups the documentation, reformat some of the paragraphs to use <p> instead of </br> and rewrites the listen part to be more extendable. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- docs/formatdomain.html.in | 351 ++++++++++++++++++++++------------------------ 1 file changed, 169 insertions(+), 182 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 957b839..c43c737 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4933,108 +4933,113 @@ qemu-kvm -net nic,model=? /dev/null <dl> <dt><code>graphics</code></dt> - <dd>The <code>graphics</code> element has a mandatory <code>type</code> - attribute which takes the value "sdl", "vnc", "spice", "rdp" or - "desktop": + <dd> + <p> + The <code>graphics</code> element has a mandatory <code>type</code> + attribute which takes the value <code>sdl</code>, <code>vnc</code>, + <code>spice</code>, <code>rdp</code> or <code>desktop</code>: + </p> <dl> <dt><code>"sdl"</code></dt> <dd> - This displays a window on the host desktop, it can take 3 - optional arguments: a <code>display</code> attribute for - the display to use, an <code>xauth</code> attribute for - the authentication identifier, and an - optional <code>fullscreen</code> attribute accepting - values 'yes' or 'no'. + <p> + This displays a window on the host desktop, it can take 3 optional + arguments: a <code>display</code> attribute for the display to use, + an <code>xauth</code> attribute for the authentication identifier, + and an optional <code>fullscreen</code> attribute accepting values + <code>yes</code> or <code>no</code>. + </p> </dd> <dt><code>"vnc"</code></dt> <dd> - Starts a VNC server. The <code>port</code> attribute - specifies the TCP port number (with -1 as legacy syntax - indicating that it should be - auto-allocated). The <code>autoport</code> attribute is - the new preferred syntax for indicating autoallocation of - the TCP port to use. The <code>listen</code> attribute is - an IP address for the server to listen - on. The <code>passwd</code> attribute provides a VNC - password in clear text. The <code>keymap</code> attribute - specifies the keymap to use. It is possible to set a limit - on the validity of the password be giving an - timestamp <code>passwdValidTo='2010-04-09T15:51:00'</code> - assumed to be in UTC. The <code>connected</code> attribute - allows control of connected client during password changes. - VNC accepts <code>keep</code> value only. - <span class="since">since 0.9.3</span> - NB, this may not be supported by all hypervisors.<br/> - The optional <code>sharePolicy</code> attribute specifies vnc server - display sharing policy. "allow-exclusive" allows clients to ask - for exclusive access by dropping other connections. Connecting - multiple clients in parallel requires all clients asking for a - shared session (vncviewer: -Shared switch). This is the default - value. "force-shared" disables exclusive client access, every - connection has to specify -Shared switch for vncviewer. "ignore" - welcomes every connection unconditionally - <span class="since">since 1.0.6</span>. <br/> <br/> - Rather than using listen/port, QEMU supports a - <code>socket</code> attribute for listening on a unix - domain socket path.<span class="since">Since 0.8.8</span> - - For VNC WebSocket functionality, <code>websocket</code> - attribute may be used to specify port to listen on (with - -1 meaning auto-allocation and <code>autoport</code> - having no effect due to security reasons). - <span class="since">Since 1.0.6</span> + <p> + Starts a VNC server. The <code>port</code> attribute specifies + the TCP port number (with -1 as legacy syntax indicating that it + should be auto-allocated). The <code>autoport</code> attribute is + the new preferred syntax for indicating auto-allocation of the TCP + port to use. The <code>listen</code> attribute is an IP address + for the server to listen on. The <code>passwd</code> attribute + provides a VNC password in clear text. The <code>keymap</code> + attribute specifies the keymap to use. It is possible to set + a limit on the validity of the password by giving an timestamp + <code>passwdValidTo='2010-04-09T15:51:00'</code> assumed to be + in UTC. The <code>connected</code> attribute allows control of + connected client during password changes. VNC accepts + <code>keep</code> value only <span class="since">since 0.9.3</span>. + NB, this may not be supported by all hypervisors. + </p> + <p> + The optional <code>sharePolicy</code> attribute specifies vnc + server display sharing policy. <code>allow-exclusive</code> allows + clients to ask for exclusive access by dropping other connections. + Connecting multiple clients in parallel requires all clients asking + for a shared session (vncviewer: -Shared switch). This is + the default value. <code>force-shared</code> disables exclusive + client access, every connection has to specify -Shared switch for + vncviewer. <code>ignore</code> welcomes every connection + unconditionally <span class="since">since 1.0.6</span>. + </p> + <p> + Rather than using listen/port, QEMU supports a <code>socket</code> + attribute for listening on a unix domain socket path + <span class="since">Since 0.8.8</span>. + </p> + <p> + For VNC WebSocket functionality, <code>websocket</code> attribute + may be used to specify port to listen on (with -1 meaning + auto-allocation and <code>autoport</code> having no effect due to + security reasons) <span class="since">Since 1.0.6</span>. + </p> </dd> - <dt><code>"spice"</code></dt> + <dt><code>"spice"</code> <span class="since">Since 0.8.6</span></dt> <dd> <p> - Starts a SPICE server. The <code>port</code> attribute - specifies the TCP port number (with -1 as legacy syntax - indicating that it should be auto-allocated), - while <code>tlsPort</code> gives an alternative secure - port number. The <code>autoport</code> attribute is the - new preferred syntax for indicating autoallocation of - needed port numbers. The <code>listen</code> attribute is - an IP address for the server to listen - on. The <code>passwd</code> attribute provides a SPICE - password in clear text. The <code>keymap</code> - attribute specifies the keymap to use. It is possible to - set a limit on the validity of the password be giving an - timestamp <code>passwdValidTo='2010-04-09T15:51:00'</code> - assumed to be in UTC. The <code>connected</code> attribute - allows control of connected client during password changes. - SPICE accepts <code>keep</code> to keep client connected, - <code>disconnect</code> to disconnect client and - <code>fail</code> to fail changing password. + Starts a SPICE server. The <code>port</code> attribute specifies + the TCP port number (with -1 as legacy syntax indicating that it + should be auto-allocated), while <code>tlsPort</code> gives + an alternative secure port number. The <code>autoport</code> + attribute is the new preferred syntax for indicating + auto-allocation of needed port numbers. The <code>listen</code> + attribute is an IP address for the server to listen on. + The <code>passwd</code> attribute provides a SPICE password in + clear text. The <code>keymap</code> attribute specifies the keymap + to use. It is possible to set a limit on the validity of + the password by giving an timestamp + <code>passwdValidTo='2010-04-09T15:51:00'</code> assumed to be in + UTC. + </p> + <p> + The <code>connected</code> attribute allows control of connected + client during password changes. SPICE accepts <code>keep</code> to + keep client connected, <code>disconnect</code> to disconnect client + and <code>fail</code> to fail changing password . NB, this may not + be supported by all hypervisors. <span class="since">Since 0.9.3</span> - NB, this may not be supported by all hypervisors. - <span class="since">"spice" since 0.8.6</span>. + </p> + <p> The <code>defaultMode</code> attribute sets the default channel security policy, valid values are <code>secure</code>, - <code>insecure</code> and the default <code>any</code> - (which is secure if possible, but falls back to insecure - rather than erroring out if no secure path is - available). <span class="since">"defaultMode" since - 0.9.12</span>. + <code>insecure</code> and the default <code>any</code> (which is + secure if possible, but falls back to insecure rather than erroring + out if no secure path is available). + <span class="since">Since 0.9.12</span> </p> <p> - When SPICE has both a normal and TLS secured TCP port - configured, it can be desirable to restrict what - channels can be run on each port. This is achieved by - adding one or more <channel> elements inside the - main <graphics> element and setting the <code>mode</code> - attribute to either <code>secure</code> or <code>insecure</code>. - Setting the mode attribute overrides the default value as set - by the <code>defaultMode</code> attribute. (Note that specifying + When SPICE has both a normal and TLS secured TCP port configured, + it can be desirable to restrict what channels can be run on each + port. This is achieved by adding one or more <code><channel> + </code> elements inside the main <code><graphics></code> + element and setting the <code>mode</code> attribute to either + <code>secure</code> or <code>insecure</code>. Setting the mode + attribute overrides the default value as set by + the <code>defaultMode</code> attribute. (Note that specifying <code>any</code> as mode discards the entry as the channel would - inherit the default mode anyways) - Valid channel names - include <code>main</code>, <code>display</code>, - <code>inputs</code>, <code>cursor</code>, - <code>playback</code>, <code>record</code> + inherit the default mode anyways.) Valid channel names include + <code>main</code>, <code>display</code>, <code>inputs</code>, + <code>cursor</code>, <code>playback</code>, <code>record</code> (all <span class="since"> since 0.8.6</span>); - <code>smartcard</code> (<span class="since">since - 0.8.8</span>); and <code>usbredir</code> - (<span class="since">since 0.9.12</span>). + <code>smartcard</code> (<span class="since">since 0.8.8</span>); + and <code>usbredir</code> (<span class="since">since 0.9.12</span>). </p> <pre> <graphics type='spice' port='-1' tlsPort='-1' autoport='yes'> @@ -5048,131 +5053,113 @@ qemu-kvm -net nic,model=? /dev/null <gl enable='yes'/> </graphics></pre> <p> - Spice supports variable compression settings for audio, - images and streaming, <span class="since">since - 0.9.1</span>. These settings are accessible via - the <code>compression</code> attribute in all following - elements: <code>image</code> to set image compression - (accepts <code>auto_glz</code>, <code>auto_lz</code>, - <code>quic</code>, <code>glz</code>, <code>lz</code>, - <code>off</code>), <code>jpeg</code> for JPEG - compression for images over wan - (accepts <code>auto</code>, <code>never</code>, - <code>always</code>), <code>zlib</code> for configuring - wan image compression (accepts <code>auto</code>, - <code>never</code>, <code>always</code>) - and <code>playback</code> for enabling audio stream - compression (accepts <code>on</code> or <code>off</code>). + Spice supports variable compression settings for audio, images and + streaming. These settings are accessible via the <code>compression + </code> attribute in all following elements: <code>image</code> to + set image compression (accepts <code>auto_glz</code>, + <code>auto_lz</code>, <code>quic</code>, <code>glz</code>, + <code>lz</code>, <code>off</code>), <code>jpeg</code> for JPEG + compression for images over wan (accepts <code>auto</code>, + <code>never</code>, <code>always</code>), <code>zlib</code> for + configuring wan image compression (accepts <code>auto</code>, + <code>never</code>, <code>always</code>) and <code>playback</code> + for enabling audio stream compression (accepts <code>on</code> or + <code>off</code>). <span class="since">Since 0.9.1</span> </p> <p> - Streaming mode is set by the <code>streaming</code> - element, settings its <code>mode</code> attribute to one - of <code>filter</code>, <code>all</code> - or <code>off</code>, <span class="since">since 0.9.2</span>. + Streaming mode is set by the <code>streaming</code> element, + settings its <code>mode</code> attribute to one of + <code>filter</code>, <code>all</code> or <code>off</code>. + <span class="since">Since 0.9.2</span> </p> <p> - Copy & Paste functionality (via Spice agent) is set - by the <code>clipboard</code> element. It is enabled by - default, and can be disabled by setting - the <code>copypaste</code> property - to <code>no</code>, <span class="since">since - 0.9.3</span>. + Copy & Paste functionality (via Spice agent) is set by the + <code>clipboard</code> element. It is enabled by default, and can + be disabled by setting the <code>copypaste</code> property to + <code>no</code>. <span class="since">Since 0.9.3</span> </p> <p> - Mouse mode is set by the <code>mouse</code> element, - setting its <code>mode</code> attribute to one of - <code>server</code> or <code>client</code> , - <span class="since">since 0.9.11</span>. If no mode is - specified, the qemu default will be used (client mode). + Mouse mode is set by the <code>mouse</code> element, setting its + <code>mode</code> attribute to one of <code>server</code> or + <code>client</code>. If no mode is specified, the qemu default will + be used (client mode). <span class="since">Since 0.9.11</span> </p> <p> File transfer functionality (via Spice agent) is set using the - <code>filetransfer</code> element. - It is enabled by default, and can be disabled by setting the - <code>enable</code> property to <code>no</code> , - since <span class="since">since 1.2.2</span>. + <code>filetransfer</code> element. It is enabled by default, and + can be disabled by setting the <code>enable</code> property to + <code>no</code>. <span class="since">Since 1.2.2</span> </p> <p> - Spice may provide accelerated server-side rendering with - OpenGL. You can enable or disable OpenGL support explicitly with - the <code>gl</code> element, by setting the - <code>enable</code> property. (QEMU - only, <span class="since">since 1.3.2</span>). + Spice may provide accelerated server-side rendering with OpenGL. + You can enable or disable OpenGL support explicitly with + the <code>gl</code> element, by setting the <code>enable</code> + property. (QEMU only, <span class="since">since 1.3.2</span>). </p> </dd> <dt><code>"rdp"</code></dt> <dd> - Starts a RDP server. The <code>port</code> attribute - specifies the TCP port number (with -1 as legacy syntax - indicating that it should be - auto-allocated). The <code>autoport</code> attribute is - the new preferred syntax for indicating autoallocation of - the TCP port to use. The <code>replaceUser</code> - attribute is a boolean deciding whether multiple - simultaneous connections to the VM are permitted. - The <code>multiUser</code> attribute is a boolean deciding - whether the existing connection must be dropped and a new - connection must be established by the VRDP server, when a - new client connects in single connection mode. + <p> + Starts a RDP server. The <code>port</code> attribute specifies the + TCP port number (with -1 as legacy syntax indicating that it should + be auto-allocated). The <code>autoport</code> attribute is the new + preferred syntax for indicating auto-allocation of the TCP port to + use. The <code>replaceUser</code> attribute is a boolean deciding + whether multiple simultaneous connections to the VM are permitted. + The <code>multiUser</code> attribute is a boolean deciding whether + the existing connection must be dropped and a new connection must + be established by the VRDP server, when a new client connects in + single connection mode. + </p> </dd> <dt><code>"desktop"</code></dt> <dd> - This value is reserved for VirtualBox domains for the - moment. It displays a window on the host desktop, - similarly to "sdl", but using the VirtualBox viewer. Just - like "sdl", it accepts the optional - attributes <code>display</code> - and <code>fullscreen</code>. + <p> + This value is reserved for VirtualBox domains for the moment. It + displays a window on the host desktop, similarly to "sdl", but + using the VirtualBox viewer. Just like "sdl", it accepts + the optional attributes <code>display</code> and + <code>fullscreen</code>. + </p> </dd> </dl> </dd> </dl> <p> - Rather than putting the address information used to set up the - listening socket for graphics types <code>vnc</code> - and <code>spice</code> in - the <code><graphics></code> <code>listen</code> attribute, - a separate subelement of <code><graphics></code>, - called <code><listen></code> can be specified (see the - examples above)<span class="since">since - 0.9.4</span>. <code><listen></code> accepts the following - attributes: + Graphics device uses a <code><listen></code> to set up where + the device should listen for clients. It has a mandatory attribute + <code>type</code> which specifies the listen type. Only <code>vnc</code>, + <code>spice</code> and <code>rdp</code> supports <code><listen> + </code> element. <span class="since">Since 0.9.4</span>. + Available types are: </p> <dl> - <dt><code>type</code></dt> - <dd>Set to either <code>address</code> - or <code>network</code>. This tells whether this listen - element is specifying the address to be used directly, or by - naming a network (which will then be used to determine an - appropriate address for listening). - </dd> - </dl> - <dl> <dt><code>address</code></dt> - <dd>if <code>type='address'</code>, the <code>address</code> - attribute will contain either an IP address or hostname (which - will be resolved to an IP address via a DNS query) to listen - on. In the "live" XML of a running domain, this attribute will - be set to the IP address used for listening, even - if <code>type='network'</code>. + <dd> + <p> + Tells a graphics device to use an address specified in the + <code>address</code> attribute, which will contain either an IP address + or hostname (which will be resolved to an IP address via a DNS query) + to listen on. + </p> </dd> - </dl> - <dl> <dt><code>network</code></dt> - <dd>if <code>type='network'</code>, the <code>network</code> - attribute will contain the name of a network in libvirt's list - of configured networks. The named network configuration will - be examined to determine an appropriate listen address. For - example, if the network has an IPv4 address in its - configuration (e.g. if it has a forward type - of <code>route</code>, <code>nat</code>, or no forward type - (isolated)), the first IPv4 address listed in the network's - configuration will be used. If the network is describing a - host bridge, the first IPv4 address associated with that - bridge device will be used, and if the network is describing - one of the 'direct' (macvtap) modes, the first IPv4 address of - the first forward dev will be used. + <dd> + <p> + This is used to specify an existing network in the <code>network</code> + attribute from libvirt's list of configured networks. The named network + configuration will be examined to determine an appropriate listen + address and the address will be stored in live XML in <code>address + </code> attribute. For example, if the network has an IPv4 address in + its configuration (e.g. if it has a forward type of <code>route</code>, + <code>nat</code>, or no forward type (isolated)), the first IPv4 + address listed in the network's configuration will be used. + If the network is describing a host bridge, the first IPv4 address + associated with that bridge device will be used, and if the network is + describing one of the 'direct' (macvtap) modes, the first IPv4 address + of the first forward dev will be used. + </p> </dd> </dl> -- 2.7.4

On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
This cleanups the documentation, reformat some of the paragraphs to use <p> instead of </br> and rewrites the listen part to be more extendable.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- docs/formatdomain.html.in | 351 ++++++++++++++++++++++------------------------ 1 file changed, 169 insertions(+), 182 deletions(-)
I just compared the end results rather than try to review the actual patch since most of it is whitespace change. New <listen> content is sensible and formatting changes look fine, ACK - Cole

On Fri, Apr 08, 2016 at 11:21:17AM -0400, Cole Robinson wrote:
On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
This cleanups the documentation, reformat some of the paragraphs to use <p> instead of </br> and rewrites the listen part to be more extendable.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- docs/formatdomain.html.in | 351 ++++++++++++++++++++++------------------------ 1 file changed, 169 insertions(+), 182 deletions(-)
I just compared the end results rather than try to review the actual patch since most of it is whitespace change.
New <listen> content is sensible and formatting changes look fine, ACK
- Cole
Thanks, Pushed now

Move code, that parses graphics listens, to it's own function. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 79 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d4c78fd..a0ef3d9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10675,38 +10675,19 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, } -/* Parse the XML definition for a graphics device */ -static virDomainGraphicsDefPtr -virDomainGraphicsDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt, - unsigned int flags) +static int +virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, + xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned int flags) { - virDomainGraphicsDefPtr def; - char *type = NULL; int nListens; xmlNodePtr *listenNodes = NULL; char *listenAddr = NULL; xmlNodePtr save = ctxt->node; - - if (VIR_ALLOC(def) < 0) - return NULL; + int ret = -1; ctxt->node = node; - - type = virXMLPropString(node, "type"); - - if (!type) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing graphics device type")); - goto error; - } - - if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown graphics device type '%s'"), type); - goto error; - } - if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP || def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { @@ -10723,10 +10704,10 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, goto error; for (i = 0; i < nListens; i++) { - int ret = virDomainGraphicsListenDefParseXML(&def->listens[i], - listenNodes[i], - flags); - if (ret < 0) + int rv = virDomainGraphicsListenDefParseXML(&def->listens[i], + listenNodes[i], + flags); + if (rv < 0) goto error; def->nListens++; } @@ -10780,6 +10761,43 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, } } + ret = 0; + error: + VIR_FREE(listenNodes); + VIR_FREE(listenAddr); + ctxt->node = save; + return ret; +} + + +/* Parse the XML definition for a graphics device */ +static virDomainGraphicsDefPtr +virDomainGraphicsDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned int flags) +{ + virDomainGraphicsDefPtr def; + char *type = NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + type = virXMLPropString(node, "type"); + if (!type) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing graphics device type")); + goto error; + } + + if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown graphics device type '%s'"), type); + goto error; + } + + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { char *port = virXMLPropString(node, "port"); char *websocket = virXMLPropString(node, "websocket"); @@ -11230,10 +11248,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, cleanup: VIR_FREE(type); - VIR_FREE(listenNodes); - VIR_FREE(listenAddr); - ctxt->node = save; return def; error: -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:20PM +0200, Pavel Hrdina wrote:
Move code, that parses graphics listens, to it's own function.
s/it's/its/
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 79 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 32 deletions(-)
ACK Jan

Refactor the listen parser to use only one loop. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 117 +++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 67 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a0ef3d9..9d48d07 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10681,86 +10681,69 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - int nListens; xmlNodePtr *listenNodes = NULL; - char *listenAddr = NULL; xmlNodePtr save = ctxt->node; + virDomainGraphicsListenDefPtr address = NULL; + char *listenAddr = NULL; + int nListens; int ret = -1; ctxt->node = node; - if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || - def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP || - def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - /* parse the <listen> subelements for graphics types that support it */ - nListens = virXPathNodeSet("./listen", ctxt, &listenNodes); - if (nListens < 0) - goto error; + if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC && + def->type != VIR_DOMAIN_GRAPHICS_TYPE_RDP && + def->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { + ret = 0; + goto error; + } - if (nListens > 0) { - size_t i; + /* parse the <listen> subelements for graphics types that support it */ + nListens = virXPathNodeSet("./listen", ctxt, &listenNodes); + if (nListens < 0) + goto error; + + if (nListens > 0) { + size_t i; - if (VIR_ALLOC_N(def->listens, nListens) < 0) + if (VIR_ALLOC_N(def->listens, nListens) < 0) + goto error; + + for (i = 0; i < nListens; i++) { + if (virDomainGraphicsListenDefParseXML(&def->listens[i], + listenNodes[i], + flags) < 0) goto error; - for (i = 0; i < nListens; i++) { - int rv = virDomainGraphicsListenDefParseXML(&def->listens[i], - listenNodes[i], - flags); - if (rv < 0) - goto error; - def->nListens++; - } - VIR_FREE(listenNodes); - } - - /* listen attribute of <graphics> is also supported by these, - * but must match the 'address' attribute of the first listen - * that is type='address' (if present) */ - listenAddr = virXMLPropString(node, "listen"); - if (listenAddr && !listenAddr[0]) - VIR_FREE(listenAddr); - - if (listenAddr) { - if (def->nListens == 0) { - /* There were no <listen> elements, so we can just - * directly set listenAddr as listens[0]->address */ - if (virDomainGraphicsListenSetAddress(def, 0, listenAddr, - -1, true) < 0) - goto error; - } else { - /* There is at least 1 listen element, so we look for - * the first listen of type='address', and make sure - * its address matches the listen attribute from - * graphics. */ - bool matched = false; - const char *found = NULL; - size_t i; - - for (i = 0; i < nListens; i++) { - if (virDomainGraphicsListenGetType(def, i) - == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { - found = virDomainGraphicsListenGetAddress(def, i); - if (STREQ_NULLABLE(found, listenAddr)) - matched = true; - break; - } - } - if (found && !matched) { - virReportError(VIR_ERR_XML_ERROR, - _("graphics listen attribute %s must match address " - "attribute of first listen element (found %s)"), - listenAddr, found); - goto error; - } else if (!found) { - /* quietly ignore listen address if none of the listens - * are of type address */ - VIR_FREE(listenAddr); - } - } + if (!address && + def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) + address = &def->listens[i]; + + def->nListens++; } + VIR_FREE(listenNodes); } + /* listen attribute of <graphics> is also supported by these, + * but must match the 'address' attribute of the first listen + * that is type='address' (if present) */ + listenAddr = virXMLPropString(node, "listen"); + if (listenAddr && !listenAddr[0]) + VIR_FREE(listenAddr); + + if (STREQ_NULLABLE(address->address, listenAddr) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("graphics listen attribute %s must match address " + "attribute of first listen element (found %s)"), + listenAddr, address->address); + goto error; + } + + /* There were no <listen> elements, so we can just + * directly set listenAddr as listens[0]->address */ + if (listenAddr && def->nListens == 0 && + virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0) + goto error; + ret = 0; error: VIR_FREE(listenNodes); -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:21PM +0200, Pavel Hrdina wrote:
Refactor the listen parser to use only one loop.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 117 +++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 67 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a0ef3d9..9d48d07 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c
+ /* listen attribute of <graphics> is also supported by these, + * but must match the 'address' attribute of the first listen + * that is type='address' (if present) */ + listenAddr = virXMLPropString(node, "listen"); + if (listenAddr && !listenAddr[0]) + VIR_FREE(listenAddr); + + if (STREQ_NULLABLE(address->address, listenAddr) < 0) {
This is dead code, since it expands to strcmp(a,b) == 0. Drop the comparison against zero and use STRNEQ_NULLABLE instead. Also, the check should only be done if address is non-NULL, for XMLs with no <listen> elements. ACK with that fixed. Jan

Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 835 +++++++++++++++++++++++++++---------------------- 1 file changed, 453 insertions(+), 382 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d48d07..fd9316f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10753,480 +10753,551 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, } -/* Parse the XML definition for a graphics device */ -static virDomainGraphicsDefPtr -virDomainGraphicsDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt, - unsigned int flags) +static int +virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, + xmlNodePtr node, + unsigned int flags) { - virDomainGraphicsDefPtr def; - char *type = NULL; - - if (VIR_ALLOC(def) < 0) - return NULL; - - type = virXMLPropString(node, "type"); - if (!type) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing graphics device type")); - goto error; - } - - if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown graphics device type '%s'"), type); - goto error; - } - - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; - - if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - char *port = virXMLPropString(node, "port"); - char *websocket = virXMLPropString(node, "websocket"); - char *sharePolicy = virXMLPropString(node, "sharePolicy"); - char *autoport; + char *port = virXMLPropString(node, "port"); + char *websocket = virXMLPropString(node, "websocket"); + char *sharePolicy = virXMLPropString(node, "sharePolicy"); + char *autoport; + int ret = -1; - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vnc port %s"), port); - VIR_FREE(port); - goto error; - } + if (port) { + if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse vnc port %s"), port); VIR_FREE(port); - /* Legacy compat syntax, used -1 for auto-port */ - if (def->data.vnc.port == -1) { - if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) - def->data.vnc.port = 0; - def->data.vnc.autoport = true; - } - } else { - def->data.vnc.port = 0; + goto error; + } + VIR_FREE(port); + /* Legacy compat syntax, used -1 for auto-port */ + if (def->data.vnc.port == -1) { + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) + def->data.vnc.port = 0; def->data.vnc.autoport = true; } + } else { + def->data.vnc.port = 0; + def->data.vnc.autoport = true; + } - if ((autoport = virXMLPropString(node, "autoport")) != NULL) { - if (STREQ(autoport, "yes")) { - if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) - def->data.vnc.port = 0; - def->data.vnc.autoport = true; - } - VIR_FREE(autoport); + if ((autoport = virXMLPropString(node, "autoport")) != NULL) { + if (STREQ(autoport, "yes")) { + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) + def->data.vnc.port = 0; + def->data.vnc.autoport = true; } + VIR_FREE(autoport); + } - if (websocket) { - if (virStrToLong_i(websocket, - NULL, 10, - &def->data.vnc.websocket) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vnc WebSocket port %s"), websocket); - VIR_FREE(websocket); - goto error; - } + if (websocket) { + if (virStrToLong_i(websocket, + NULL, 10, + &def->data.vnc.websocket) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse vnc WebSocket port %s"), websocket); VIR_FREE(websocket); + goto error; } + VIR_FREE(websocket); + } - if (sharePolicy) { - int policy = - virDomainGraphicsVNCSharePolicyTypeFromString(sharePolicy); + if (sharePolicy) { + int policy = + virDomainGraphicsVNCSharePolicyTypeFromString(sharePolicy); - if (policy < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown vnc display sharing policy '%s'"), sharePolicy); - VIR_FREE(sharePolicy); - goto error; - } else { - def->data.vnc.sharePolicy = policy; - } + if (policy < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown vnc display sharing policy '%s'"), sharePolicy); VIR_FREE(sharePolicy); + goto error; + } else { + def->data.vnc.sharePolicy = policy; } + VIR_FREE(sharePolicy); + } - def->data.vnc.socket = virXMLPropString(node, "socket"); - def->data.vnc.keymap = virXMLPropString(node, "keymap"); + def->data.vnc.socket = virXMLPropString(node, "socket"); + def->data.vnc.keymap = virXMLPropString(node, "keymap"); - if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, - def->type) < 0) - goto error; - } else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { - char *fullscreen = virXMLPropString(node, "fullscreen"); + if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, + def->type) < 0) + goto error; - if (fullscreen != NULL) { - if (STREQ(fullscreen, "yes")) { - def->data.sdl.fullscreen = true; - } else if (STREQ(fullscreen, "no")) { - def->data.sdl.fullscreen = false; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown fullscreen value '%s'"), fullscreen); - VIR_FREE(fullscreen); - goto error; - } - VIR_FREE(fullscreen); - } else { + ret = 0; + error: + return ret; +} + + +static int +virDomainGraphicsDefParseXMLSdl(virDomainGraphicsDefPtr def, + xmlNodePtr node) +{ + char *fullscreen = virXMLPropString(node, "fullscreen"); + + if (fullscreen != NULL) { + if (STREQ(fullscreen, "yes")) { + def->data.sdl.fullscreen = true; + } else if (STREQ(fullscreen, "no")) { def->data.sdl.fullscreen = false; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown fullscreen value '%s'"), fullscreen); + VIR_FREE(fullscreen); + return -1; } - def->data.sdl.xauth = virXMLPropString(node, "xauth"); - def->data.sdl.display = virXMLPropString(node, "display"); - } else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) { - char *port = virXMLPropString(node, "port"); - char *autoport; - char *replaceUser; - char *multiUser; + VIR_FREE(fullscreen); + } else { + def->data.sdl.fullscreen = false; + } + def->data.sdl.xauth = virXMLPropString(node, "xauth"); + def->data.sdl.display = virXMLPropString(node, "display"); - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse rdp port %s"), port); - VIR_FREE(port); - goto error; - } - /* Legacy compat syntax, used -1 for auto-port */ - if (def->data.rdp.port == -1) - def->data.rdp.autoport = true; + return 0; +} + + +static int +virDomainGraphicsDefParseXMLRdp(virDomainGraphicsDefPtr def, + xmlNodePtr node, + unsigned int flags) +{ + char *port = virXMLPropString(node, "port"); + char *autoport; + char *replaceUser; + char *multiUser; + int ret = -1; + if (port) { + if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse rdp port %s"), port); VIR_FREE(port); - } else { - def->data.rdp.port = 0; - def->data.rdp.autoport = true; + goto error; } + /* Legacy compat syntax, used -1 for auto-port */ + if (def->data.rdp.port == -1) + def->data.rdp.autoport = true; - if ((autoport = virXMLPropString(node, "autoport")) != NULL) { - if (STREQ(autoport, "yes")) - def->data.rdp.autoport = true; + VIR_FREE(port); + } else { + def->data.rdp.port = 0; + def->data.rdp.autoport = true; + } - VIR_FREE(autoport); - } + if ((autoport = virXMLPropString(node, "autoport")) != NULL) { + if (STREQ(autoport, "yes")) + def->data.rdp.autoport = true; - if (def->data.rdp.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - def->data.rdp.port = 0; + VIR_FREE(autoport); + } - if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { - if (STREQ(replaceUser, "yes")) - def->data.rdp.replaceUser = true; - VIR_FREE(replaceUser); - } + if (def->data.rdp.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + def->data.rdp.port = 0; - if ((multiUser = virXMLPropString(node, "multiUser")) != NULL) { - if (STREQ(multiUser, "yes")) - def->data.rdp.multiUser = true; - VIR_FREE(multiUser); - } + if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { + if (STREQ(replaceUser, "yes")) + def->data.rdp.replaceUser = true; + VIR_FREE(replaceUser); + } - } else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) { - char *fullscreen = virXMLPropString(node, "fullscreen"); + if ((multiUser = virXMLPropString(node, "multiUser")) != NULL) { + if (STREQ(multiUser, "yes")) + def->data.rdp.multiUser = true; + VIR_FREE(multiUser); + } - if (fullscreen != NULL) { - if (STREQ(fullscreen, "yes")) { - def->data.desktop.fullscreen = true; - } else if (STREQ(fullscreen, "no")) { - def->data.desktop.fullscreen = false; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown fullscreen value '%s'"), fullscreen); - VIR_FREE(fullscreen); - goto error; - } - VIR_FREE(fullscreen); - } else { + ret = 0; + error: + return ret; +} + + +static int +virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, + xmlNodePtr node) +{ + char *fullscreen = virXMLPropString(node, "fullscreen"); + + if (fullscreen != NULL) { + if (STREQ(fullscreen, "yes")) { + def->data.desktop.fullscreen = true; + } else if (STREQ(fullscreen, "no")) { def->data.desktop.fullscreen = false; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown fullscreen value '%s'"), fullscreen); + VIR_FREE(fullscreen); + return -1; } + VIR_FREE(fullscreen); + } else { + def->data.desktop.fullscreen = false; + } - def->data.desktop.display = virXMLPropString(node, "display"); - } else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - xmlNodePtr cur; - char *port = virXMLPropString(node, "port"); - char *tlsPort; - char *autoport; - char *defaultMode; - int defaultModeVal; + def->data.desktop.display = virXMLPropString(node, "display"); + return 0; +} - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse spice port %s"), port); - VIR_FREE(port); - goto error; - } + +static int +virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, + xmlNodePtr node, + unsigned int flags) +{ + xmlNodePtr cur; + char *port = virXMLPropString(node, "port"); + char *tlsPort; + char *autoport; + char *defaultMode; + int defaultModeVal; + int ret = -1; + + if (port) { + if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse spice port %s"), port); VIR_FREE(port); - } else { - def->data.spice.port = 0; + goto error; } + VIR_FREE(port); + } else { + def->data.spice.port = 0; + } - tlsPort = virXMLPropString(node, "tlsPort"); - if (tlsPort) { - if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse spice tlsPort %s"), tlsPort); - VIR_FREE(tlsPort); - goto error; - } + tlsPort = virXMLPropString(node, "tlsPort"); + if (tlsPort) { + if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse spice tlsPort %s"), tlsPort); VIR_FREE(tlsPort); - } else { - def->data.spice.tlsPort = 0; + goto error; } + VIR_FREE(tlsPort); + } else { + def->data.spice.tlsPort = 0; + } - if ((autoport = virXMLPropString(node, "autoport")) != NULL) { - if (STREQ(autoport, "yes")) - def->data.spice.autoport = true; - VIR_FREE(autoport); - } + if ((autoport = virXMLPropString(node, "autoport")) != NULL) { + if (STREQ(autoport, "yes")) + def->data.spice.autoport = true; + VIR_FREE(autoport); + } - def->data.spice.defaultMode = VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY; + def->data.spice.defaultMode = VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY; - if ((defaultMode = virXMLPropString(node, "defaultMode")) != NULL) { - if ((defaultModeVal = virDomainGraphicsSpiceChannelModeTypeFromString(defaultMode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown default spice channel mode %s"), - defaultMode); - VIR_FREE(defaultMode); - goto error; - } - def->data.spice.defaultMode = defaultModeVal; + if ((defaultMode = virXMLPropString(node, "defaultMode")) != NULL) { + if ((defaultModeVal = virDomainGraphicsSpiceChannelModeTypeFromString(defaultMode)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown default spice channel mode %s"), + defaultMode); VIR_FREE(defaultMode); + goto error; } + def->data.spice.defaultMode = defaultModeVal; + VIR_FREE(defaultMode); + } - if (def->data.spice.port == -1 && def->data.spice.tlsPort == -1) { - /* Legacy compat syntax, used -1 for auto-port */ - def->data.spice.autoport = true; - } + if (def->data.spice.port == -1 && def->data.spice.tlsPort == -1) { + /* Legacy compat syntax, used -1 for auto-port */ + def->data.spice.autoport = true; + } - if (def->data.spice.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { - def->data.spice.port = 0; - def->data.spice.tlsPort = 0; - } + if (def->data.spice.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { + def->data.spice.port = 0; + def->data.spice.tlsPort = 0; + } - def->data.spice.keymap = virXMLPropString(node, "keymap"); + def->data.spice.keymap = virXMLPropString(node, "keymap"); - if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, - def->type) < 0) - goto error; + if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, + def->type) < 0) + goto error; - cur = node->children; - while (cur != NULL) { - if (cur->type == XML_ELEMENT_NODE) { - if (xmlStrEqual(cur->name, BAD_CAST "channel")) { - char *name, *mode; - int nameval, modeval; - name = virXMLPropString(cur, "name"); - mode = virXMLPropString(cur, "mode"); + cur = node->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE) { + if (xmlStrEqual(cur->name, BAD_CAST "channel")) { + char *name, *mode; + int nameval, modeval; + name = virXMLPropString(cur, "name"); + mode = virXMLPropString(cur, "mode"); - if (!name || !mode) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice channel missing name/mode")); - VIR_FREE(name); - VIR_FREE(mode); - goto error; - } + if (!name || !mode) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("spice channel missing name/mode")); + VIR_FREE(name); + VIR_FREE(mode); + goto error; + } - if ((nameval = virDomainGraphicsSpiceChannelNameTypeFromString(name)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel name %s"), - name); - VIR_FREE(name); - VIR_FREE(mode); - goto error; - } - if ((modeval = virDomainGraphicsSpiceChannelModeTypeFromString(mode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel mode %s"), - mode); - VIR_FREE(name); - VIR_FREE(mode); - goto error; - } + if ((nameval = virDomainGraphicsSpiceChannelNameTypeFromString(name)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice channel name %s"), + name); VIR_FREE(name); VIR_FREE(mode); + goto error; + } + if ((modeval = virDomainGraphicsSpiceChannelModeTypeFromString(mode)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice channel mode %s"), + mode); + VIR_FREE(name); + VIR_FREE(mode); + goto error; + } + VIR_FREE(name); + VIR_FREE(mode); - def->data.spice.channels[nameval] = modeval; - } else if (xmlStrEqual(cur->name, BAD_CAST "image")) { - char *compression = virXMLPropString(cur, "compression"); - int compressionVal; + def->data.spice.channels[nameval] = modeval; + } else if (xmlStrEqual(cur->name, BAD_CAST "image")) { + char *compression = virXMLPropString(cur, "compression"); + int compressionVal; - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice image missing compression")); - goto error; - } + if (!compression) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("spice image missing compression")); + goto error; + } - if ((compressionVal = - virDomainGraphicsSpiceImageCompressionTypeFromString(compression)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice image compression %s"), - compression); - VIR_FREE(compression); - goto error; - } + if ((compressionVal = + virDomainGraphicsSpiceImageCompressionTypeFromString(compression)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice image compression %s"), + compression); VIR_FREE(compression); + goto error; + } + VIR_FREE(compression); - def->data.spice.image = compressionVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "jpeg")) { - char *compression = virXMLPropString(cur, "compression"); - int compressionVal; + def->data.spice.image = compressionVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "jpeg")) { + char *compression = virXMLPropString(cur, "compression"); + int compressionVal; - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice jpeg missing compression")); - goto error; - } + if (!compression) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("spice jpeg missing compression")); + goto error; + } - if ((compressionVal = - virDomainGraphicsSpiceJpegCompressionTypeFromString(compression)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice jpeg compression %s"), - compression); - VIR_FREE(compression); - goto error; - } + if ((compressionVal = + virDomainGraphicsSpiceJpegCompressionTypeFromString(compression)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice jpeg compression %s"), + compression); VIR_FREE(compression); + goto error; + } + VIR_FREE(compression); - def->data.spice.jpeg = compressionVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "zlib")) { - char *compression = virXMLPropString(cur, "compression"); - int compressionVal; + def->data.spice.jpeg = compressionVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "zlib")) { + char *compression = virXMLPropString(cur, "compression"); + int compressionVal; - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice zlib missing compression")); - goto error; - } + if (!compression) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("spice zlib missing compression")); + goto error; + } - if ((compressionVal = - virDomainGraphicsSpiceZlibCompressionTypeFromString(compression)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice zlib compression %s"), - compression); - VIR_FREE(compression); - goto error; - } + if ((compressionVal = + virDomainGraphicsSpiceZlibCompressionTypeFromString(compression)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice zlib compression %s"), + compression); VIR_FREE(compression); + goto error; + } + VIR_FREE(compression); - def->data.spice.zlib = compressionVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "playback")) { - char *compression = virXMLPropString(cur, "compression"); - int compressionVal; - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice playback missing compression")); - goto error; - } + def->data.spice.zlib = compressionVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "playback")) { + char *compression = virXMLPropString(cur, "compression"); + int compressionVal; - if ((compressionVal = - virTristateSwitchTypeFromString(compression)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice playback compression")); - VIR_FREE(compression); - goto error; + if (!compression) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("spice playback missing compression")); + goto error; + } - } + if ((compressionVal = + virTristateSwitchTypeFromString(compression)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown spice playback compression")); VIR_FREE(compression); + goto error; - def->data.spice.playback = compressionVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "streaming")) { - char *mode = virXMLPropString(cur, "mode"); - int modeVal; + } + VIR_FREE(compression); - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice streaming missing mode")); - goto error; - } - if ((modeVal = - virDomainGraphicsSpiceStreamingModeTypeFromString(mode)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice streaming mode")); - VIR_FREE(mode); - goto error; + def->data.spice.playback = compressionVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "streaming")) { + char *mode = virXMLPropString(cur, "mode"); + int modeVal; - } + if (!mode) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("spice streaming missing mode")); + goto error; + } + if ((modeVal = + virDomainGraphicsSpiceStreamingModeTypeFromString(mode)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown spice streaming mode")); VIR_FREE(mode); + goto error; - def->data.spice.streaming = modeVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "clipboard")) { - char *copypaste = virXMLPropString(cur, "copypaste"); - int copypasteVal; + } + VIR_FREE(mode); - if (!copypaste) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice clipboard missing copypaste")); - goto error; - } + def->data.spice.streaming = modeVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "clipboard")) { + char *copypaste = virXMLPropString(cur, "copypaste"); + int copypasteVal; - if ((copypasteVal = - virTristateBoolTypeFromString(copypaste)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copypaste); - VIR_FREE(copypaste); - goto error; - } + if (!copypaste) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("spice clipboard missing copypaste")); + goto error; + } + + if ((copypasteVal = + virTristateBoolTypeFromString(copypaste)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown copypaste value '%s'"), copypaste); VIR_FREE(copypaste); + goto error; + } + VIR_FREE(copypaste); - def->data.spice.copypaste = copypasteVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "filetransfer")) { - char *enable = virXMLPropString(cur, "enable"); - int enableVal; + def->data.spice.copypaste = copypasteVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "filetransfer")) { + char *enable = virXMLPropString(cur, "enable"); + int enableVal; - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice filetransfer missing enable")); - goto error; - } + if (!enable) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("spice filetransfer missing enable")); + goto error; + } - if ((enableVal = - virTristateBoolTypeFromString(enable)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - VIR_FREE(enable); - goto error; - } + if ((enableVal = + virTristateBoolTypeFromString(enable)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown enable value '%s'"), enable); VIR_FREE(enable); + goto error; + } + VIR_FREE(enable); - def->data.spice.filetransfer = enableVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "gl")) { - char *enable = virXMLPropString(cur, "enable"); - int enableVal; + def->data.spice.filetransfer = enableVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "gl")) { + char *enable = virXMLPropString(cur, "enable"); + int enableVal; - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice gl element missing enable")); - goto error; - } + if (!enable) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("spice gl element missing enable")); + goto error; + } - if ((enableVal = - virTristateBoolTypeFromString(enable)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - VIR_FREE(enable); - goto error; - } + if ((enableVal = + virTristateBoolTypeFromString(enable)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown enable value '%s'"), enable); VIR_FREE(enable); + goto error; + } + VIR_FREE(enable); - def->data.spice.gl = enableVal; - } else if (xmlStrEqual(cur->name, BAD_CAST "mouse")) { - char *mode = virXMLPropString(cur, "mode"); - int modeVal; + def->data.spice.gl = enableVal; + } else if (xmlStrEqual(cur->name, BAD_CAST "mouse")) { + char *mode = virXMLPropString(cur, "mode"); + int modeVal; - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice mouse missing mode")); - goto error; - } + if (!mode) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("spice mouse missing mode")); + goto error; + } - if ((modeVal = virDomainGraphicsSpiceMouseModeTypeFromString(mode)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown mouse mode value '%s'"), - mode); - VIR_FREE(mode); - goto error; - } + if ((modeVal = virDomainGraphicsSpiceMouseModeTypeFromString(mode)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown mouse mode value '%s'"), + mode); VIR_FREE(mode); - - def->data.spice.mousemode = modeVal; + goto error; } + VIR_FREE(mode); + + def->data.spice.mousemode = modeVal; } - cur = cur->next; } + cur = cur->next; + } + + ret = 0; + error: + return ret; +} + + +/* Parse the XML definition for a graphics device */ +static virDomainGraphicsDefPtr +virDomainGraphicsDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned int flags) +{ + virDomainGraphicsDefPtr def; + char *type = NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + type = virXMLPropString(node, "type"); + if (!type) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing graphics device type")); + goto error; + } + + if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown graphics device type '%s'"), type); + goto error; + } + + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + + switch (def->type) { + case VIR_DOMAIN_GRAPHICS_TYPE_VNC: + if (virDomainGraphicsDefParseXMLVnc(def, node, flags) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SDL: + if (virDomainGraphicsDefParseXMLSdl(def, node) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_RDP: + if (virDomainGraphicsDefParseXMLRdp(def, node, flags) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + if (virDomainGraphicsDefParseXMLDesktop(def, node) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: + if (virDomainGraphicsDefParseXMLSpice(def, node, flags) < 0) + goto error; + break; } cleanup: -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:22PM +0200, Pavel Hrdina wrote:
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 835 +++++++++++++++++++++++++++---------------------- 1 file changed, 453 insertions(+), 382 deletions(-)
s/ParseXMLVnc/ParseXMLVNC/g s/ParseXMLSdl/ParseXMLSDL/g s/ParseXMLRdp/ParseXMLRDP/g would IMO look nicer.
+ + if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown graphics device type '%s'"), type); + goto error; + } + + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + + switch (def->type) {
You could also cast the type to the enum, to annoy anyone adding a new graphics type to add it to this switch too. ACK Jan
+ case VIR_DOMAIN_GRAPHICS_TYPE_VNC: + if (virDomainGraphicsDefParseXMLVnc(def, node, flags) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SDL: + if (virDomainGraphicsDefParseXMLSdl(def, node) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_RDP: + if (virDomainGraphicsDefParseXMLRdp(def, node, flags) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + if (virDomainGraphicsDefParseXMLDesktop(def, node) < 0) + goto error; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: + if (virDomainGraphicsDefParseXMLSpice(def, node, flags) < 0) + goto error; + break; }

Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 100 ++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fd9316f..42050b0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10761,17 +10761,15 @@ virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, char *port = virXMLPropString(node, "port"); char *websocket = virXMLPropString(node, "websocket"); char *sharePolicy = virXMLPropString(node, "sharePolicy"); - char *autoport; + char *autoport = virXMLPropString(node, "autoport"); int ret = -1; if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc port %s"), port); - VIR_FREE(port); goto error; } - VIR_FREE(port); /* Legacy compat syntax, used -1 for auto-port */ if (def->data.vnc.port == -1) { if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) @@ -10783,13 +10781,12 @@ virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, def->data.vnc.autoport = true; } - if ((autoport = virXMLPropString(node, "autoport")) != NULL) { + if (autoport) { if (STREQ(autoport, "yes")) { if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) def->data.vnc.port = 0; def->data.vnc.autoport = true; } - VIR_FREE(autoport); } if (websocket) { @@ -10798,10 +10795,8 @@ virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, &def->data.vnc.websocket) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc WebSocket port %s"), websocket); - VIR_FREE(websocket); goto error; } - VIR_FREE(websocket); } if (sharePolicy) { @@ -10810,13 +10805,12 @@ virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, if (policy < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown vnc display sharing policy '%s'"), sharePolicy); - VIR_FREE(sharePolicy); + _("unknown vnc display sharing policy '%s'"), + sharePolicy); goto error; } else { def->data.vnc.sharePolicy = policy; } - VIR_FREE(sharePolicy); } def->data.vnc.socket = virXMLPropString(node, "socket"); @@ -10828,6 +10822,10 @@ virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, ret = 0; error: + VIR_FREE(port); + VIR_FREE(autoport); + VIR_FREE(websocket); + VIR_FREE(sharePolicy); return ret; } @@ -10837,6 +10835,7 @@ virDomainGraphicsDefParseXMLSdl(virDomainGraphicsDefPtr def, xmlNodePtr node) { char *fullscreen = virXMLPropString(node, "fullscreen"); + int ret = -1; if (fullscreen != NULL) { if (STREQ(fullscreen, "yes")) { @@ -10846,17 +10845,19 @@ virDomainGraphicsDefParseXMLSdl(virDomainGraphicsDefPtr def, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); - VIR_FREE(fullscreen); - return -1; + goto error; } - VIR_FREE(fullscreen); } else { def->data.sdl.fullscreen = false; } + def->data.sdl.xauth = virXMLPropString(node, "xauth"); def->data.sdl.display = virXMLPropString(node, "display"); - return 0; + ret = 0; + error: + VIR_FREE(fullscreen); + return ret; } @@ -10866,52 +10867,44 @@ virDomainGraphicsDefParseXMLRdp(virDomainGraphicsDefPtr def, unsigned int flags) { char *port = virXMLPropString(node, "port"); - char *autoport; - char *replaceUser; - char *multiUser; + char *autoport = virXMLPropString(node, "autoport"); + char *replaceUser = virXMLPropString(node, "replaceUser"); + char *multiUser = virXMLPropString(node, "multiUser"); int ret = -1; if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse rdp port %s"), port); - VIR_FREE(port); goto error; } /* Legacy compat syntax, used -1 for auto-port */ if (def->data.rdp.port == -1) def->data.rdp.autoport = true; - VIR_FREE(port); } else { def->data.rdp.port = 0; def->data.rdp.autoport = true; } - if ((autoport = virXMLPropString(node, "autoport")) != NULL) { - if (STREQ(autoport, "yes")) - def->data.rdp.autoport = true; - - VIR_FREE(autoport); - } + if (autoport && STREQ(autoport, "yes")) + def->data.rdp.autoport = true; if (def->data.rdp.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) def->data.rdp.port = 0; - if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { - if (STREQ(replaceUser, "yes")) - def->data.rdp.replaceUser = true; - VIR_FREE(replaceUser); - } + if (replaceUser && STREQ(replaceUser, "yes")) + def->data.rdp.replaceUser = true; - if ((multiUser = virXMLPropString(node, "multiUser")) != NULL) { - if (STREQ(multiUser, "yes")) - def->data.rdp.multiUser = true; - VIR_FREE(multiUser); - } + if (multiUser && STREQ(multiUser, "yes")) + def->data.rdp.multiUser = true; ret = 0; error: + VIR_FREE(port); + VIR_FREE(autoport); + VIR_FREE(replaceUser); + VIR_FREE(multiUser); return ret; } @@ -10921,6 +10914,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, xmlNodePtr node) { char *fullscreen = virXMLPropString(node, "fullscreen"); + int ret = -1; if (fullscreen != NULL) { if (STREQ(fullscreen, "yes")) { @@ -10930,16 +10924,18 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); - VIR_FREE(fullscreen); - return -1; + goto error; } - VIR_FREE(fullscreen); } else { def->data.desktop.fullscreen = false; } def->data.desktop.display = virXMLPropString(node, "display"); - return 0; + + ret = 0; + error: + VIR_FREE(fullscreen); + return ret; } @@ -10950,9 +10946,9 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, { xmlNodePtr cur; char *port = virXMLPropString(node, "port"); - char *tlsPort; - char *autoport; - char *defaultMode; + char *tlsPort = virXMLPropString(node, "tlsPort"); + char *autoport = virXMLPropString(node, "autoport"); + char *defaultMode = virXMLPropString(node, "defaultMode"); int defaultModeVal; int ret = -1; @@ -10960,45 +10956,35 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse spice port %s"), port); - VIR_FREE(port); goto error; } - VIR_FREE(port); } else { def->data.spice.port = 0; } - tlsPort = virXMLPropString(node, "tlsPort"); if (tlsPort) { if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse spice tlsPort %s"), tlsPort); - VIR_FREE(tlsPort); goto error; } - VIR_FREE(tlsPort); } else { def->data.spice.tlsPort = 0; } - if ((autoport = virXMLPropString(node, "autoport")) != NULL) { - if (STREQ(autoport, "yes")) - def->data.spice.autoport = true; - VIR_FREE(autoport); - } + if (autoport && STREQ(autoport, "yes")) + def->data.spice.autoport = true; def->data.spice.defaultMode = VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY; - if ((defaultMode = virXMLPropString(node, "defaultMode")) != NULL) { + if (defaultMode) { if ((defaultModeVal = virDomainGraphicsSpiceChannelModeTypeFromString(defaultMode)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown default spice channel mode %s"), defaultMode); - VIR_FREE(defaultMode); goto error; } def->data.spice.defaultMode = defaultModeVal; - VIR_FREE(defaultMode); } if (def->data.spice.port == -1 && def->data.spice.tlsPort == -1) { @@ -11245,6 +11231,10 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, ret = 0; error: + VIR_FREE(port); + VIR_FREE(tlsPort); + VIR_FREE(autoport); + VIR_FREE(defaultMode); return ret; } -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:23PM +0200, Pavel Hrdina wrote:
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 100 ++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 55 deletions(-)
@@ -10846,17 +10845,19 @@ virDomainGraphicsDefParseXMLSdl(virDomainGraphicsDefPtr def, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); - VIR_FREE(fullscreen); - return -1; + goto error; } - VIR_FREE(fullscreen); } else { def->data.sdl.fullscreen = false; } + def->data.sdl.xauth = virXMLPropString(node, "xauth"); def->data.sdl.display = virXMLPropString(node, "display");
- return 0; + ret = 0; + error:
If you're adding a new label, 'cleanup' is better for paths shared by the success and the error paths.
+ VIR_FREE(fullscreen); + return ret; }
@@ -10866,52 +10867,44 @@ virDomainGraphicsDefParseXMLRdp(virDomainGraphicsDefPtr def, }
- if ((autoport = virXMLPropString(node, "autoport")) != NULL) { - if (STREQ(autoport, "yes")) - def->data.rdp.autoport = true; - - VIR_FREE(autoport); - } + if (autoport && STREQ(autoport, "yes")) + def->data.rdp.autoport = true;
Could be STREQ_NULLABLE.
if (def->data.rdp.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) def->data.rdp.port = 0;
- if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { - if (STREQ(replaceUser, "yes")) - def->data.rdp.replaceUser = true; - VIR_FREE(replaceUser); - } + if (replaceUser && STREQ(replaceUser, "yes")) + def->data.rdp.replaceUser = true;
- if ((multiUser = virXMLPropString(node, "multiUser")) != NULL) { - if (STREQ(multiUser, "yes")) - def->data.rdp.multiUser = true; - VIR_FREE(multiUser); - } + if (multiUser && STREQ(multiUser, "yes")) + def->data.rdp.multiUser = true;
ret = 0; error: + VIR_FREE(port); + VIR_FREE(autoport); + VIR_FREE(replaceUser); + VIR_FREE(multiUser); return ret; }
@@ -10930,16 +10924,18 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); - VIR_FREE(fullscreen); - return -1; + goto error; } - VIR_FREE(fullscreen); } else { def->data.desktop.fullscreen = false; }
def->data.desktop.display = virXMLPropString(node, "display"); - return 0; + + ret = 0; + error:
s/error/cleanup/
+ VIR_FREE(fullscreen); + return ret; }
ACK Jan

On Wed, Apr 06, 2016 at 05:57:02PM +0200, Ján Tomko wrote:
On Mon, Apr 04, 2016 at 03:20:23PM +0200, Pavel Hrdina wrote:
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 100 ++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 55 deletions(-)
Thanks, pushed all ACKed patches with proposed fixes. Pavel

This effectively removes virDomainGraphicsListenSetAddress which was used only to change the address of listen structure and possible change the listen type. The new function will auto-expand the listens array and add a new listen. The old function was used on pre-allocated array of listens and in most cases it only "add" a new listen. The two remaining uses can access the listen structure directly. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 34 +++++++++++++++------------------- src/conf/domain_conf.h | 6 +++--- src/libvirt_private.syms | 2 +- src/qemu/qemu_command.c | 6 ++---- src/qemu/qemu_parse_command.c | 4 +++- src/qemu/qemu_process.c | 15 +++++++-------- src/vbox/vbox_common.c | 3 +-- src/vmx/vmx.c | 2 +- src/xenconfig/xen_common.c | 12 +++++------- src/xenconfig/xen_sxpr.c | 4 ++-- src/xenconfig/xen_xl.c | 4 +--- 11 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 42050b0..c79a432 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10741,7 +10741,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, /* There were no <listen> elements, so we can just * directly set listenAddr as listens[0]->address */ if (listenAddr && def->nListens == 0 && - virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0) + virDomainGraphicsListenAddAddress(def, 0, listenAddr) < 0) goto error; ret = 0; @@ -23820,31 +23820,27 @@ virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) } -/* Make a copy of up to len characters of address, and store it in - * listens[i].address. If setType is true, set the listen's type - * to 'address', otherwise leave type alone. */ int -virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def, - size_t i, const char *address, - int len, bool setType) +virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, + int pos, + const char *address) { - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, true); + virDomainGraphicsListenDef listen; - if (!listenInfo) - return -1; + memset(&listen, 0, sizeof(listen)); - if (setType) - listenInfo->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; + listen.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; - if (!address) { - VIR_FREE(listenInfo->address); - return 0; - } + if (VIR_STRDUP(listen.address, address) < 0) + goto error; + + if (VIR_INSERT_ELEMENT_COPY(def->listens, pos, def->nListens, listen) < 0) + goto error; - if (VIR_STRNDUP(listenInfo->address, address, len) < 0) - return -1; return 0; + error: + VIR_FREE(listen.address); + return -1; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fe9faeb..ed3d818 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2818,9 +2818,9 @@ int virDomainGraphicsListenSetType(virDomainGraphicsDefPtr def, size_t i, int va const char *virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) ATTRIBUTE_NONNULL(1); -int virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def, - size_t i, const char *address, - int len, bool setType) +int virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, + int pos, + const char *address) ATTRIBUTE_NONNULL(1); const char *virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def, size_t i) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 684f06c..cc1c969 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -300,10 +300,10 @@ virDomainGetFilesystemForTarget; virDomainGraphicsAuthConnectedTypeFromString; virDomainGraphicsAuthConnectedTypeToString; virDomainGraphicsDefFree; +virDomainGraphicsListenAddAddress; virDomainGraphicsListenGetAddress; virDomainGraphicsListenGetNetwork; virDomainGraphicsListenGetType; -virDomainGraphicsListenSetAddress; virDomainGraphicsListenSetNetwork; virDomainGraphicsListenSetType; virDomainGraphicsSpiceChannelModeTypeFromString; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2d0ca97..140bf98 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7274,8 +7274,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, listenAddr = netAddr; /* store the address we found in the <graphics> element so it * will show up in status. */ - if (virDomainGraphicsListenSetAddress(graphics, 0, - listenAddr, -1, false) < 0) + if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0) goto error; break; } @@ -7429,8 +7428,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, listenAddr = netAddr; /* store the address we found in the <graphics> element so it will * show up in status. */ - if (virDomainGraphicsListenSetAddress(graphics, 0, - listenAddr, -1, false) < 0) + if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0) goto error; break; } diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index 8b294a7..a556461 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -519,6 +519,7 @@ qemuParseCommandLineVnc(virDomainDefPtr def, char *opts; char *port; const char *sep = ":"; + char *listenAddr = NULL; if (val[0] == '[') sep = "]:"; tmp = strstr(val, sep); @@ -536,7 +537,8 @@ qemuParseCommandLineVnc(virDomainDefPtr def, } if (val[0] == '[') val++; - if (virDomainGraphicsListenSetAddress(vnc, 0, val, tmp-val, true) < 0) + if (VIR_STRNDUP(listenAddr, val, tmp-val) < 0 || + virDomainGraphicsListenAddAddress(vnc, 0, listenAddr) < 0) goto cleanup; if (*opts == ',') { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d9dca74..6a4fb8c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4286,15 +4286,14 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver, if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (graphics->nListens == 0) { - if (VIR_EXPAND_N(graphics->listens, graphics->nListens, 1) < 0) - goto cleanup; - graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; - if (VIR_STRDUP(graphics->listens[0].address, - graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? - cfg->vncListen : cfg->spiceListen) < 0) { - VIR_SHRINK_N(graphics->listens, graphics->nListens, 1); + const char *listenAddr + = graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? + cfg->vncListen : cfg->spiceListen; + + if (virDomainGraphicsListenAddAddress(graphics, 0, + listenAddr) < 0) goto cleanup; - } + graphics->listens[0].fromConfig = true; } else if (graphics->nListens > 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index c305eb5..ee3b9c5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3386,8 +3386,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) } if (STRNEQ_NULLABLE(netAddressUtf8, "") && - virDomainGraphicsListenSetAddress(graphics, 0, - netAddressUtf8, -1, true) < 0) + virDomainGraphicsListenAddAddress(graphics, 0, netAddressUtf8) < 0) goto cleanup; gVBoxAPI.UIVRDxServer.GetAllowMultiConnection(VRDxServer, &allowMultiConnection); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index f77a7a4..f6a4474 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1875,7 +1875,7 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) } if (listenAddr) { - if (virDomainGraphicsListenSetAddress(*def, 0, listenAddr, -1, true) < 0) + if (virDomainGraphicsListenAddAddress(*def, 0, listenAddr) < 0) goto failure; VIR_FREE(listenAddr); } diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 4dcd484..db1e236 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -595,12 +595,10 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) if (xenConfigCopyStringOpt(conf, "vnclisten", &listenAddr) < 0) goto cleanup; if (listenAddr && - virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, - -1, true) < 0) { - goto cleanup; - } - + virDomainGraphicsListenAddAddress(graphics, 0, listenAddr) < 0) + goto cleanup; VIR_FREE(listenAddr); + if (xenConfigCopyStringOpt(conf, "vncpasswd", &graphics->data.vnc.auth.passwd) < 0) goto cleanup; if (xenConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0) @@ -666,8 +664,8 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) if (STREQ(key + 10, "1")) graphics->data.vnc.autoport = true; } else if (STRPREFIX(key, "vnclisten=")) { - if (virDomainGraphicsListenSetAddress(graphics, 0, key+10, - -1, true) < 0) + if (virDomainGraphicsListenAddAddress(graphics, 0, + key+10) < 0) goto cleanup; } else if (STRPREFIX(key, "vncpasswd=")) { if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0) diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index fdfec2b..7d719b0 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -868,7 +868,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, graphics->data.vnc.port = port; if (listenAddr && - virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1, true) < 0) + virDomainGraphicsListenAddAddress(graphics, 0, listenAddr) < 0) goto error; if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0) @@ -987,7 +987,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, graphics->data.vnc.port = port; if (listenAddr && - virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1, true) < 0) + virDomainGraphicsListenAddAddress(graphics, 0, listenAddr) < 0) goto error; if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0) diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 98a7fa6..5478d9c 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -187,10 +187,8 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def) if (xenConfigCopyStringOpt(conf, "spicehost", &listenAddr) < 0) goto cleanup; if (listenAddr && - virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, - -1, true) < 0) { + virDomainGraphicsListenAddAddress(graphics, 0, listenAddr) < 0) goto cleanup; - } VIR_FREE(listenAddr); if (xenConfigGetULong(conf, "spicetls_port", &port, 0) < 0) -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:24PM +0200, Pavel Hrdina wrote:
This effectively removes virDomainGraphicsListenSetAddress which was used only to change the address of listen structure and possible change the listen type. The new function will auto-expand the listens array and add a new listen.
The old function was used on pre-allocated array of listens and in most cases it only "add" a new listen. The two remaining uses can access the listen structure directly.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 34 +++++++++++++++------------------- src/conf/domain_conf.h | 6 +++--- src/libvirt_private.syms | 2 +- src/qemu/qemu_command.c | 6 ++---- src/qemu/qemu_parse_command.c | 4 +++- src/qemu/qemu_process.c | 15 +++++++-------- src/vbox/vbox_common.c | 3 +-- src/vmx/vmx.c | 2 +- src/xenconfig/xen_common.c | 12 +++++------- src/xenconfig/xen_sxpr.c | 4 ++-- src/xenconfig/xen_xl.c | 4 +--- 11 files changed, 41 insertions(+), 51 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 42050b0..c79a432 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10741,7 +10741,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, /* There were no <listen> elements, so we can just * directly set listenAddr as listens[0]->address */ if (listenAddr && def->nListens == 0 && - virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0) + virDomainGraphicsListenAddAddress(def, 0, listenAddr) < 0) goto error;
ret = 0; @@ -23820,31 +23820,27 @@ virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) }
-/* Make a copy of up to len characters of address, and store it in - * listens[i].address. If setType is true, set the listen's type - * to 'address', otherwise leave type alone. */ int -virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def, - size_t i, const char *address, - int len, bool setType) +virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, + int pos,
I would go even further and delete the pos argument too. Every single caller uses 0 and only calls it when def->nListens == 0.
+ const char *address) { - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, true); + virDomainGraphicsListenDef listen;
- if (!listenInfo) - return -1; + memset(&listen, 0, sizeof(listen));
- if (setType) - listenInfo->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; + listen.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
- if (!address) { - VIR_FREE(listenInfo->address); - return 0; - } + if (VIR_STRDUP(listen.address, address) < 0) + goto error; + + if (VIR_INSERT_ELEMENT_COPY(def->listens, pos, def->nListens, listen) < 0)
This would become APPEND_ELEMENT_COPY. ACK Jan

The same as for virDomainGraphicsListenAddAddress from previous commit applies to this one too. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 30 +++++++++++++++--------------- src/conf/domain_conf.h | 5 +++-- src/libvirt_private.syms | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c79a432..a1a73ac 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23857,30 +23857,30 @@ virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def, size_t i) } -/* Make a copy of up to len characters of address, and store it in - * listens[i].network */ int -virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def, - size_t i, const char *network, int len) +virDomainGraphicsListenAddNetwork(virDomainGraphicsDefPtr def, + int pos, + const char *network) { - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, true); + virDomainGraphicsListenDef listen; - if (!listenInfo) - return -1; + memset(&listen, 0, sizeof(listen)); - listenInfo->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK; + listen.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK; - if (!network) { - VIR_FREE(listenInfo->network); - return 0; - } + if (VIR_STRDUP(listen.network, network) < 0) + goto error; + + if (VIR_INSERT_ELEMENT_COPY(def->listens, pos, def->nListens, listen) < 0) + goto error; - if (VIR_STRNDUP(listenInfo->network, network, len) < 0) - return -1; return 0; + error: + VIR_FREE(listen.network); + return -1; } + /** * virDomainNetFind: * @def: domain's def diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ed3d818..c1b26dd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2825,8 +2825,9 @@ int virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, const char *virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def, size_t i) ATTRIBUTE_NONNULL(1); -int virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def, - size_t i, const char *network, int len) +int virDomainGraphicsListenAddNetwork(virDomainGraphicsDefPtr def, + int pos, + const char *network) ATTRIBUTE_NONNULL(1); int virDomainNetGetActualType(virDomainNetDefPtr iface); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cc1c969..53eba5c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -301,10 +301,10 @@ virDomainGraphicsAuthConnectedTypeFromString; virDomainGraphicsAuthConnectedTypeToString; virDomainGraphicsDefFree; virDomainGraphicsListenAddAddress; +virDomainGraphicsListenAddNetwork; virDomainGraphicsListenGetAddress; virDomainGraphicsListenGetNetwork; virDomainGraphicsListenGetType; -virDomainGraphicsListenSetNetwork; virDomainGraphicsListenSetType; virDomainGraphicsSpiceChannelModeTypeFromString; virDomainGraphicsSpiceChannelModeTypeToString; -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:25PM +0200, Pavel Hrdina wrote:
The same as for virDomainGraphicsListenAddAddress from previous commit applies to this one too.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 30 +++++++++++++++--------------- src/conf/domain_conf.h | 5 +++-- src/libvirt_private.syms | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-)
Since listen type="network" is a libvirt feature, we will probably never need to convert it from a hypervisor config format. Libvirt's XML parser does not use it either. I think this helper can be dropped completely. Jan

Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 16 ---------------- src/conf/domain_conf.h | 2 -- src/libvirt_private.syms | 1 - 3 files changed, 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a1a73ac..abe5d5a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23789,22 +23789,6 @@ virDomainGraphicsListenGetType(virDomainGraphicsDefPtr def, size_t i) } -/* NB: This function assumes type has not previously been set. It - * *will not* free any existing address or network based on a change - * in value of type. */ -int -virDomainGraphicsListenSetType(virDomainGraphicsDefPtr def, size_t i, int val) -{ - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, true); - - if (!listenInfo) - return -1; - listenInfo->type = val; - return 0; -} - - const char * virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c1b26dd..96e2def 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2813,8 +2813,6 @@ int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match, int virDomainGraphicsListenGetType(virDomainGraphicsDefPtr def, size_t i) ATTRIBUTE_NONNULL(1); -int virDomainGraphicsListenSetType(virDomainGraphicsDefPtr def, size_t i, int val) - ATTRIBUTE_NONNULL(1); const char *virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) ATTRIBUTE_NONNULL(1); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 53eba5c..3c4abd7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -305,7 +305,6 @@ virDomainGraphicsListenAddNetwork; virDomainGraphicsListenGetAddress; virDomainGraphicsListenGetNetwork; virDomainGraphicsListenGetType; -virDomainGraphicsListenSetType; virDomainGraphicsSpiceChannelModeTypeFromString; virDomainGraphicsSpiceChannelModeTypeToString; virDomainGraphicsSpiceChannelNameTypeFromString; -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:26PM +0200, Pavel Hrdina wrote:
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 16 ---------------- src/conf/domain_conf.h | 2 -- src/libvirt_private.syms | 1 - 3 files changed, 19 deletions(-)
ACK Jan

Removes the check for graphics type, it's not a public API and developer know what he's doing and this check makes no sense. It also removes the ability to allocate a new array if there is none. This was used by the virDomainGraphicsListenAdd* functions and isn't used anymore. This is now a simple getter with simple check for listens array presence and whether the index in out of bounds. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 29 ++++++++--------------------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index abe5d5a..1f6e9f4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23741,26 +23741,13 @@ virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface) * type, or NULL if this is an unsuitable type, or the index is out of * bounds. If force0 is TRUE, i == 0, and there is no listen array, * allocate one with a single item. */ -static virDomainGraphicsListenDefPtr -virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i, bool force0) +virDomainGraphicsListenDefPtr +virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i) { - if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || - def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP || - def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - - if (!def->listens && (i == 0) && force0) { - if (VIR_ALLOC(def->listens) >= 0) - def->nListens = 1; - } - - if (!def->listens || (def->nListens <= i)) - return NULL; - - return &def->listens[i]; - } + if (!def->listens || (def->nListens <= i)) + return NULL; - /* it's a type that has no listens array */ - return NULL; + return &def->listens[i]; } @@ -23781,7 +23768,7 @@ int virDomainGraphicsListenGetType(virDomainGraphicsDefPtr def, size_t i) { virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, false); + = virDomainGraphicsGetListen(def, i); if (!listenInfo) return VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE; @@ -23793,7 +23780,7 @@ const char * virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) { virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, false); + = virDomainGraphicsGetListen(def, i); /* even a network can have a listen address */ if (!listenInfo || @@ -23832,7 +23819,7 @@ const char * virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def, size_t i) { virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i, false); + = virDomainGraphicsGetListen(def, i); if (!listenInfo || (listenInfo->type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 96e2def..672d8dc 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2811,6 +2811,8 @@ virDomainHostdevRemove(virDomainDefPtr def, size_t i); int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match, virDomainHostdevDefPtr *found); +virDomainGraphicsListenDefPtr +virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i); int virDomainGraphicsListenGetType(virDomainGraphicsDefPtr def, size_t i) ATTRIBUTE_NONNULL(1); const char *virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3c4abd7..b8a8ddc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -300,6 +300,7 @@ virDomainGetFilesystemForTarget; virDomainGraphicsAuthConnectedTypeFromString; virDomainGraphicsAuthConnectedTypeToString; virDomainGraphicsDefFree; +virDomainGraphicsGetListen; virDomainGraphicsListenAddAddress; virDomainGraphicsListenAddNetwork; virDomainGraphicsListenGetAddress; -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:27PM +0200, Pavel Hrdina wrote:
Removes the check for graphics type, it's not a public API and developer know what he's doing and this check makes no sense. It also removes the ability to allocate a new array if there is none. This was used by the virDomainGraphicsListenAdd* functions and isn't used anymore.
This is now a simple getter with simple check for listens array presence and whether the index in out of bounds.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 29 ++++++++--------------------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 11 insertions(+), 21 deletions(-)
ACK Jan

There is no point the use two different getters on the same listen structure few lines apart. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/libxl/libxl_conf.c | 15 +++---- src/qemu/qemu_command.c | 98 ++++++++++++++++++++++++---------------------- src/qemu/qemu_migration.c | 9 +++-- src/vbox/vbox_common.c | 11 +++--- src/vmx/vmx.c | 7 ++-- src/vz/vz_sdk.c | 11 +++--- src/xenconfig/xen_common.c | 16 ++++---- src/xenconfig/xen_sxpr.c | 16 ++++---- src/xenconfig/xen_xl.c | 8 ++-- 9 files changed, 99 insertions(+), 92 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 82ba417..e1cf914 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1494,7 +1494,7 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports, libxl_device_vfb *x_vfb) { unsigned short port; - const char *listenAddr; + virDomainGraphicsListenDefPtr listen = NULL; libxl_device_vfb_init(x_vfb); @@ -1521,11 +1521,11 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports, } x_vfb->vnc.display = l_vfb->data.vnc.port - LIBXL_VNC_PORT_MIN; - listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0); - if (listenAddr) { + if ((listen = virDomainGraphicsGetListen(l_vfb, 0)) && + listen->address) { /* libxl_device_vfb_init() does VIR_STRDUP("127.0.0.1") */ VIR_FREE(x_vfb->vnc.listen); - if (VIR_STRDUP(x_vfb->vnc.listen, listenAddr) < 0) + if (VIR_STRDUP(x_vfb->vnc.listen, listen->address) < 0) return -1; } if (VIR_STRDUP(x_vfb->vnc.passwd, l_vfb->data.vnc.auth.passwd) < 0) @@ -1609,7 +1609,7 @@ libxlMakeBuildInfoVfb(virPortAllocatorPtr graphicsports, for (i = 0; i < def->ngraphics; i++) { virDomainGraphicsDefPtr l_vfb = def->graphics[i]; unsigned short port; - const char *listenAddr; + virDomainGraphicsListenDefPtr listen = NULL; if (l_vfb->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) continue; @@ -1623,8 +1623,9 @@ libxlMakeBuildInfoVfb(virPortAllocatorPtr graphicsports, } b_info->u.hvm.spice.port = l_vfb->data.spice.port; - listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0); - if (VIR_STRDUP(b_info->u.hvm.spice.host, listenAddr) < 0) + if ((listen = virDomainGraphicsGetListen(l_vfb, 0)) && + listen->address && + VIR_STRDUP(b_info->u.hvm.spice.host, listen->address) < 0) return -1; if (VIR_STRDUP(b_info->u.hvm.keymap, l_vfb->data.spice.keymap) < 0) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 140bf98..9335f63 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7223,7 +7223,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, const char *domainLibDir) { virBuffer opt = VIR_BUFFER_INITIALIZER; - const char *listenNetwork; + virDomainGraphicsListenDefPtr listen = NULL; const char *listenAddr = NULL; char *netAddr = NULL; bool escapeAddr; @@ -7252,31 +7252,34 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, goto error; } - switch (virDomainGraphicsListenGetType(graphics, 0)) { - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: - listenAddr = virDomainGraphicsListenGetAddress(graphics, 0); - break; + if ((listen = virDomainGraphicsGetListen(graphics, 0))) { - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: - listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0); - if (!listenNetwork) + switch (listen->type) { + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: + listenAddr = listen->address; break; - ret = networkGetNetworkAddress(listenNetwork, &netAddr); - if (ret <= -2) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("network-based listen not possible, " - "network driver not present")); - goto error; - } - if (ret < 0) - goto error; - listenAddr = netAddr; - /* store the address we found in the <graphics> element so it - * will show up in status. */ - if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0) - goto error; - break; + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + if (!listen->network) + break; + + ret = networkGetNetworkAddress(listen->network, &netAddr); + if (ret <= -2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("network-based listen not possible, " + "network driver not present")); + goto error; + } + if (ret < 0) + goto error; + + listenAddr = netAddr; + /* store the address we found in the <graphics> element so it + * will show up in status. */ + if (VIR_STRDUP(listen->address, netAddr) < 0) + goto error; + break; + } } if (!listenAddr) @@ -7367,7 +7370,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, virDomainGraphicsDefPtr graphics) { virBuffer opt = VIR_BUFFER_INITIALIZER; - const char *listenNetwork; + virDomainGraphicsListenDefPtr listen = NULL; const char *listenAddr = NULL; char *netAddr = NULL; int ret; @@ -7406,31 +7409,34 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, } if (port > 0 || tlsPort > 0) { - switch (virDomainGraphicsListenGetType(graphics, 0)) { - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: - listenAddr = virDomainGraphicsListenGetAddress(graphics, 0); - break; + if ((listen = virDomainGraphicsGetListen(graphics, 0))) { - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: - listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0); - if (!listenNetwork) + switch (listen->type) { + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: + listenAddr = listen->address; break; - ret = networkGetNetworkAddress(listenNetwork, &netAddr); - if (ret <= -2) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("network-based listen not possible, " - "network driver not present")); - goto error; - } - if (ret < 0) - goto error; - listenAddr = netAddr; - /* store the address we found in the <graphics> element so it will - * show up in status. */ - if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0) - goto error; - break; + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + if (!listen->network) + break; + + ret = networkGetNetworkAddress(listen->network, &netAddr); + if (ret <= -2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("network-based listen not possible, " + "network driver not present")); + goto error; + } + if (ret < 0) + goto error; + + listenAddr = netAddr; + /* store the address we found in the <graphics> element so it will + * show up in status. */ + if (VIR_STRDUP(listen->address, listenAddr) < 0) + goto error; + break; + } } if (!listenAddr) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 8d2ca3b..d0055a2 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -314,6 +314,7 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, { qemuMigrationCookieGraphicsPtr mig = NULL; const char *listenAddr; + virDomainGraphicsListenDefPtr listen = virDomainGraphicsGetListen(def, 0); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); if (VIR_ALLOC(mig) < 0) @@ -322,8 +323,8 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, mig->type = def->type; if (mig->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { mig->port = def->data.vnc.port; - listenAddr = virDomainGraphicsListenGetAddress(def, 0); - if (!listenAddr) + + if (!listen || !(listenAddr = listen->address)) listenAddr = cfg->vncListen; #ifdef WITH_GNUTLS @@ -337,8 +338,8 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, mig->tlsPort = def->data.spice.tlsPort; else mig->tlsPort = -1; - listenAddr = virDomainGraphicsListenGetAddress(def, 0); - if (!listenAddr) + + if (!listen || !(listenAddr = listen->address)) listenAddr = cfg->spiceListen; #ifdef WITH_GNUTLS diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index ee3b9c5..9549cc7 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1578,6 +1578,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) char *guiDisplay = NULL; char *sdlDisplay = NULL; size_t i = 0; + virDomainGraphicsListenDefPtr listen; for (i = 0; i < def->ngraphics; i++) { IVRDxServer *VRDxServer = NULL; @@ -1588,9 +1589,6 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) vrdpPresent = 1; gVBoxAPI.UIMachine.GetVRDxServer(machine, &VRDxServer); if (VRDxServer) { - const char *listenAddr - = virDomainGraphicsListenGetAddress(def->graphics[i], 0); - gVBoxAPI.UIVRDxServer.SetEnabled(VRDxServer, PR_TRUE); VIR_DEBUG("VRDP Support turned ON."); @@ -1608,14 +1606,15 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) VIR_DEBUG("VRDP set to allow multiple connection"); } - if (listenAddr) { + if ((listen = virDomainGraphicsGetListen(def->graphics[i], 0)) && + listen->address) { PRUnichar *netAddressUtf16 = NULL; - VBOX_UTF8_TO_UTF16(listenAddr, &netAddressUtf16); + VBOX_UTF8_TO_UTF16(listen->address, &netAddressUtf16); gVBoxAPI.UIVRDxServer.SetNetAddress(data, VRDxServer, netAddressUtf16); VIR_DEBUG("VRDP listen address is set to: %s", - listenAddr); + listen->address); VBOX_UTF16_FREE(netAddressUtf16); } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index f6a4474..f5ad458 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -3403,7 +3403,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe int virVMXFormatVNC(virDomainGraphicsDefPtr def, virBufferPtr buffer) { - const char *listenAddr; + virDomainGraphicsListenDefPtr listen; if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); @@ -3425,9 +3425,10 @@ virVMXFormatVNC(virDomainGraphicsDefPtr def, virBufferPtr buffer) def->data.vnc.port); } - if ((listenAddr = virDomainGraphicsListenGetAddress(def, 0))) { + if ((listen = virDomainGraphicsGetListen(def, 0)) && + listen->address) { virBufferAsprintf(buffer, "RemoteDisplay.vnc.ip = \"%s\"\n", - listenAddr); + listen->address); } if (def->data.vnc.keymap != NULL) { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 8691887..41d9ff0 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -2238,7 +2238,7 @@ static int prlsdkCheckGraphicsUnsupportedParams(virDomainDefPtr def) } if (gr->nListens == 1 && - virDomainGraphicsListenGetType(gr, 0) != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { + gr->listens[0].type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("vz driver supports only address-based VNC listening")); return -1; @@ -2472,9 +2472,9 @@ static int prlsdkCheckFSUnsupportedParams(virDomainFSDefPtr fs) static int prlsdkApplyGraphicsParams(PRL_HANDLE sdkdom, virDomainDefPtr def) { virDomainGraphicsDefPtr gr; + virDomainGraphicsListenDefPtr listen; PRL_RESULT pret; int ret = -1; - const char *listenAddr = NULL; if (prlsdkCheckGraphicsUnsupportedParams(def)) return -1; @@ -2495,11 +2495,10 @@ static int prlsdkApplyGraphicsParams(PRL_HANDLE sdkdom, virDomainDefPtr def) prlsdkCheckRetGoto(pret, cleanup); } - if (gr->nListens == 1) { - listenAddr = virDomainGraphicsListenGetAddress(gr, 0); - if (!listenAddr) + if ((listen = virDomainGraphicsGetListen(gr, 0))) { + if (!listen->address) goto cleanup; - pret = PrlVmCfg_SetVNCHostName(sdkdom, listenAddr); + pret = PrlVmCfg_SetVNCHostName(sdkdom, listen->address); prlsdkCheckRetGoto(pret, cleanup); } diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index db1e236..e92d4e1 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -1628,7 +1628,7 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def) def->graphics[0]->data.sdl.xauth) < 0) return -1; } else { - const char *listenAddr; + virDomainGraphicsListenDefPtr listen; if (xenConfigSetInt(conf, "sdl", 0) < 0) return -1; @@ -1645,9 +1645,9 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def) def->graphics[0]->data.vnc.port - 5900) < 0) return -1; - listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0); - if (listenAddr && - xenConfigSetString(conf, "vnclisten", listenAddr) < 0) + if ((listen = virDomainGraphicsGetListen(def->graphics[0], 0)) && + listen->address && + xenConfigSetString(conf, "vnclisten", listen->address) < 0) return -1; if (def->graphics[0]->data.vnc.auth.passwd && @@ -1674,8 +1674,8 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def) virBufferAsprintf(&buf, ",xauthority=%s", def->graphics[0]->data.sdl.xauth); } else { - const char *listenAddr - = virDomainGraphicsListenGetAddress(def->graphics[0], 0); + virDomainGraphicsListenDefPtr listen + = virDomainGraphicsGetListen(def->graphics[0], 0); virBufferAddLit(&buf, "type=vnc"); virBufferAsprintf(&buf, ",vncunused=%d", @@ -1683,8 +1683,8 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def) if (!def->graphics[0]->data.vnc.autoport) virBufferAsprintf(&buf, ",vncdisplay=%d", def->graphics[0]->data.vnc.port - 5900); - if (listenAddr) - virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr); + if (listen && listen->address) + virBufferAsprintf(&buf, ",vnclisten=%s", listen->address); if (def->graphics[0]->data.vnc.auth.passwd) virBufferAsprintf(&buf, ",vncpasswd=%s", def->graphics[0]->data.vnc.auth.passwd); diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 7d719b0..cde462d 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -1523,7 +1523,7 @@ static int xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def, virBufferPtr buf) { - const char *listenAddr; + virDomainGraphicsListenDefPtr listen; if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_SDL && def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) { @@ -1551,9 +1551,9 @@ xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def, virBufferAsprintf(buf, "(vncdisplay %d)", def->data.vnc.port-5900); } - listenAddr = virDomainGraphicsListenGetAddress(def, 0); - if (listenAddr) - virBufferAsprintf(buf, "(vnclisten '%s')", listenAddr); + if ((listen = virDomainGraphicsGetListen(def, 0)) && + listen->address) + virBufferAsprintf(buf, "(vnclisten '%s')", listen->address); if (def->data.vnc.auth.passwd) virBufferAsprintf(buf, "(vncpasswd '%s')", def->data.vnc.auth.passwd); if (def->data.vnc.keymap) @@ -1579,7 +1579,7 @@ xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def, static int xenFormatSxprGraphicsOld(virDomainGraphicsDefPtr def, virBufferPtr buf) { - const char *listenAddr; + virDomainGraphicsListenDefPtr listen; if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_SDL && def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) { @@ -1604,9 +1604,9 @@ xenFormatSxprGraphicsOld(virDomainGraphicsDefPtr def, virBufferPtr buf) virBufferAsprintf(buf, "(vncdisplay %d)", def->data.vnc.port-5900); } - listenAddr = virDomainGraphicsListenGetAddress(def, 0); - if (listenAddr) - virBufferAsprintf(buf, "(vnclisten '%s')", listenAddr); + if ((listen = virDomainGraphicsGetListen(def, 0)) && + listen->address) + virBufferAsprintf(buf, "(vnclisten '%s')", listen->address); if (def->data.vnc.auth.passwd) virBufferAsprintf(buf, "(vncpasswd '%s')", def->data.vnc.auth.passwd); if (def->data.vnc.keymap) diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 5478d9c..2631ec6 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -837,7 +837,7 @@ xenFormatXLDomainDisks(virConfPtr conf, virDomainDefPtr def) static int xenFormatXLSpice(virConfPtr conf, virDomainDefPtr def) { - const char *listenAddr = NULL; + virDomainGraphicsListenDefPtr listen; virDomainGraphicsDefPtr graphics; if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { @@ -854,9 +854,9 @@ xenFormatXLSpice(virConfPtr conf, virDomainDefPtr def) if (xenConfigSetInt(conf, "spice", 1) < 0) return -1; - listenAddr = virDomainGraphicsListenGetAddress(graphics, 0); - if (listenAddr && - xenConfigSetString(conf, "spicehost", listenAddr) < 0) + if ((listen = virDomainGraphicsGetListen(graphics, 0)) && + listen->address && + xenConfigSetString(conf, "spicehost", listen->address) < 0) return -1; if (xenConfigSetInt(conf, "spiceport", -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:28PM +0200, Pavel Hrdina wrote:
There is no point the use two different getters on the same listen structure few lines apart.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/libxl/libxl_conf.c | 15 +++---- src/qemu/qemu_command.c | 98 ++++++++++++++++++++++++---------------------- src/qemu/qemu_migration.c | 9 +++-- src/vbox/vbox_common.c | 11 +++--- src/vmx/vmx.c | 7 ++-- src/vz/vz_sdk.c | 11 +++--- src/xenconfig/xen_common.c | 16 ++++---- src/xenconfig/xen_sxpr.c | 16 ++++---- src/xenconfig/xen_xl.c | 8 ++-- 9 files changed, 99 insertions(+), 92 deletions(-)
ACK Jan

Use VIR_APPEND_ELEMENT_COPY_INPLACE to add listen elements into listens array while parsing. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1f6e9f4..a5da4b3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10606,7 +10606,7 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, } static int -virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, +virDomainGraphicsListenDefParseXML(virDomainGraphicsDefPtr def, xmlNodePtr node, unsigned int flags) { @@ -10616,6 +10616,9 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, char *network = virXMLPropString(node, "network"); char *fromConfig = virXMLPropString(node, "fromConfig"); int tmp; + virDomainGraphicsListenDef listen; + + memset(&listen, 0, sizeof(listen)); if (!type) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -10623,7 +10626,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, goto error; } - if ((def->type = virDomainGraphicsListenTypeFromString(type)) < 0) { + if ((listen.type = virDomainGraphicsListenTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown graphics listen type '%s'"), type); goto error; @@ -10633,22 +10636,22 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, * type='network' and we're looking at live XML (i.e. *not* * inactive). It is otherwise ignored. */ if (address && address[0] && - (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || - (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && + (listen.type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || + (listen.type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)))) { - def->address = address; + listen.address = address; address = NULL; } if (network && network[0]) { - if (def->type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK) { + if (listen.type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK) { /* network='xxx' never makes sense with anything except * type='network' */ virReportError(VIR_ERR_XML_ERROR, "%s", _("network attribute not allowed when listen type is not network")); goto error; } - def->network = network; + listen.network = network; network = NULL; } @@ -10660,13 +10663,16 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, fromConfig); goto error; } - def->fromConfig = tmp != 0; + listen.fromConfig = tmp != 0; } + if (VIR_APPEND_ELEMENT_COPY_INPLACE(def->listens, def->nListens, listen) < 0) + goto error; + ret = 0; error: if (ret < 0) - virDomainGraphicsListenDefClear(def); + virDomainGraphicsListenDefClear(&listen); VIR_FREE(type); VIR_FREE(address); VIR_FREE(network); @@ -10709,7 +10715,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, goto error; for (i = 0; i < nListens; i++) { - if (virDomainGraphicsListenDefParseXML(&def->listens[i], + if (virDomainGraphicsListenDefParseXML(def, listenNodes[i], flags) < 0) goto error; @@ -10718,7 +10724,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) address = &def->listens[i]; - def->nListens++; } VIR_FREE(listenNodes); } -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:29PM +0200, Pavel Hrdina wrote:
Use VIR_APPEND_ELEMENT_COPY_INPLACE to add listen elements into listens array while parsing.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1f6e9f4..a5da4b3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10606,7 +10606,7 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, }
static int -virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, +virDomainGraphicsListenDefParseXML(virDomainGraphicsDefPtr def,
I prefer the original version where the function only touches the one single ListenDef it is parsing. Jan

Those are the last two places that uses the getter functions. Use a direct access instead and remove those getters. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 58 ++---------------------------------------------- src/conf/domain_conf.h | 8 ------- src/libvirt_private.syms | 3 --- 3 files changed, 2 insertions(+), 67 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a5da4b3..befbd4f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21347,7 +21347,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)) continue; - if ((listenAddr = virDomainGraphicsListenGetAddress(def, i))) + if ((listenAddr = def->listens[i].address)) break; } @@ -21460,8 +21460,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, } for (i = 0; i < def->nListens; i++) { - if (virDomainGraphicsListenGetType(def, i) - == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE) + if (def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE) continue; if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && def->listens[i].fromConfig) @@ -23756,46 +23755,6 @@ virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i) } -/* Access functions for the fields in a virDomainGraphicsDef's - * "listens" array. - * - * NB: For simple backward compatibility with existing code, any of - * the "Set" functions will auto-create listens[0] to store the new - * setting, when necessary. Auto-creation beyond the first item is not - * supported. - * - * Return values: All "Get" functions return the requested item, or - * 0/NULL. (in the case of returned const char *, the caller should - * make a copy if they want to keep it around). All "Set" functions - * return 0 on success, -1 on failure. */ - -int -virDomainGraphicsListenGetType(virDomainGraphicsDefPtr def, size_t i) -{ - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i); - - if (!listenInfo) - return VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE; - return listenInfo->type; -} - - -const char * -virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i) -{ - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i); - - /* even a network can have a listen address */ - if (!listenInfo || - !(listenInfo->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || - listenInfo->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) - return NULL; - return listenInfo->address; -} - - int virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, int pos, @@ -23820,19 +23779,6 @@ virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, } -const char * -virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def, size_t i) -{ - virDomainGraphicsListenDefPtr listenInfo - = virDomainGraphicsGetListen(def, i); - - if (!listenInfo || - (listenInfo->type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) - return NULL; - return listenInfo->network; -} - - int virDomainGraphicsListenAddNetwork(virDomainGraphicsDefPtr def, int pos, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 672d8dc..a96a130 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2813,18 +2813,10 @@ int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match, virDomainGraphicsListenDefPtr virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i); -int virDomainGraphicsListenGetType(virDomainGraphicsDefPtr def, size_t i) - ATTRIBUTE_NONNULL(1); -const char *virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, - size_t i) - ATTRIBUTE_NONNULL(1); int virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, int pos, const char *address) ATTRIBUTE_NONNULL(1); -const char *virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def, - size_t i) - ATTRIBUTE_NONNULL(1); int virDomainGraphicsListenAddNetwork(virDomainGraphicsDefPtr def, int pos, const char *network) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b8a8ddc..f864f78 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -303,9 +303,6 @@ virDomainGraphicsDefFree; virDomainGraphicsGetListen; virDomainGraphicsListenAddAddress; virDomainGraphicsListenAddNetwork; -virDomainGraphicsListenGetAddress; -virDomainGraphicsListenGetNetwork; -virDomainGraphicsListenGetType; virDomainGraphicsSpiceChannelModeTypeFromString; virDomainGraphicsSpiceChannelModeTypeToString; virDomainGraphicsSpiceChannelNameTypeFromString; -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:30PM +0200, Pavel Hrdina wrote:
Those are the last two places that uses the getter functions. Use a direct access instead and remove those getters.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 58 ++---------------------------------------------- src/conf/domain_conf.h | 8 ------- src/libvirt_private.syms | 3 --- 3 files changed, 2 insertions(+), 67 deletions(-)
ACK Jan

Instead of calling the virDomainGraphicsListensParseXML function for all graphics types and ignore the wrong ones move the call only to graphics types where we supports listen elements. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index befbd4f..dc3bc22 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10696,13 +10696,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, ctxt->node = node; - if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC && - def->type != VIR_DOMAIN_GRAPHICS_TYPE_RDP && - def->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - ret = 0; - goto error; - } - /* parse the <listen> subelements for graphics types that support it */ nListens = virXPathNodeSet("./listen", ctxt, &listenNodes); if (nListens < 0) @@ -10761,6 +10754,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, static int virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, xmlNodePtr node, + xmlXPathContextPtr ctxt, unsigned int flags) { char *port = virXMLPropString(node, "port"); @@ -10769,6 +10763,9 @@ virDomainGraphicsDefParseXMLVnc(virDomainGraphicsDefPtr def, char *autoport = virXMLPropString(node, "autoport"); int ret = -1; + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -10869,6 +10866,7 @@ virDomainGraphicsDefParseXMLSdl(virDomainGraphicsDefPtr def, static int virDomainGraphicsDefParseXMLRdp(virDomainGraphicsDefPtr def, xmlNodePtr node, + xmlXPathContextPtr ctxt, unsigned int flags) { char *port = virXMLPropString(node, "port"); @@ -10877,6 +10875,9 @@ virDomainGraphicsDefParseXMLRdp(virDomainGraphicsDefPtr def, char *multiUser = virXMLPropString(node, "multiUser"); int ret = -1; + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -10947,6 +10948,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, static int virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, xmlNodePtr node, + xmlXPathContextPtr ctxt, unsigned int flags) { xmlNodePtr cur; @@ -10957,6 +10959,9 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, int defaultModeVal; int ret = -1; + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -11269,12 +11274,9 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, goto error; } - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; - switch (def->type) { case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - if (virDomainGraphicsDefParseXMLVnc(def, node, flags) < 0) + if (virDomainGraphicsDefParseXMLVnc(def, node, ctxt, flags) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SDL: @@ -11282,7 +11284,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: - if (virDomainGraphicsDefParseXMLRdp(def, node, flags) < 0) + if (virDomainGraphicsDefParseXMLRdp(def, node, ctxt, flags) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: @@ -11290,7 +11292,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: - if (virDomainGraphicsDefParseXMLSpice(def, node, flags) < 0) + if (virDomainGraphicsDefParseXMLSpice(def, node, ctxt, flags) < 0) goto error; break; } -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:31PM +0200, Pavel Hrdina wrote:
Instead of calling the virDomainGraphicsListensParseXML function for all graphics types and ignore the wrong ones move the call only to graphics types where we supports listen elements.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
ACK Jan

On Fri, Apr 08, 2016 at 06:46:53PM +0200, Ján Tomko wrote:
On Mon, Apr 04, 2016 at 03:20:31PM +0200, Pavel Hrdina wrote:
Instead of calling the virDomainGraphicsListensParseXML function for all graphics types and ignore the wrong ones move the call only to graphics types where we supports listen elements.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
ACK
Jan
Thanks, pushed all patches except the 12/18. Pavel

Move generation of vnc unix socket to qemuProcessPrepareDomain which is the correct place to do those things. Now we can also test it. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/qemu/qemu_command.c | 20 ++++--------- src/qemu/qemu_command.h | 3 +- src/qemu/qemu_process.c | 20 +++++++++++-- ...qemuxml2argv-graphics-vnc-auto-unix-socket.args | 22 ++++++++++++++ .../qemuxml2argv-graphics-vnc-auto-unix-socket.xml | 34 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 4 +++ 6 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9335f63..67d3336 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7219,8 +7219,7 @@ static int qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, virCommandPtr cmd, virQEMUCapsPtr qemuCaps, - virDomainGraphicsDefPtr graphics, - const char *domainLibDir) + virDomainGraphicsDefPtr graphics) { virBuffer opt = VIR_BUFFER_INITIALIZER; virDomainGraphicsListenDefPtr listen = NULL; @@ -7235,14 +7234,8 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, goto error; } - if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) { - if (!graphics->data.vnc.socket && - virAsprintf(&graphics->data.vnc.socket, - "%s/vnc.sock", domainLibDir) == -1) - goto error; - + if (graphics->data.vnc.socket) { virBufferAsprintf(&opt, "unix:%s", graphics->data.vnc.socket); - } else { if (!graphics->data.vnc.autoport && (graphics->data.vnc.port < 5900 || @@ -7613,8 +7606,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, virCommandPtr cmd, virDomainDefPtr def, virQEMUCapsPtr qemuCaps, - virDomainGraphicsDefPtr graphics, - const char *domainLibDir) + virDomainGraphicsDefPtr graphics) { switch ((virDomainGraphicsType) graphics->type) { case VIR_DOMAIN_GRAPHICS_TYPE_SDL: @@ -7646,8 +7638,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, break; case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps, - graphics, domainLibDir); + return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps, graphics); case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: return qemuBuildGraphicsSPICECommandLine(cfg, cmd, qemuCaps, graphics); @@ -9199,7 +9190,6 @@ qemuBuildCommandLine(virConnectPtr conn, virBitmapPtr nodeset, size_t *nnicindexes, int **nicindexes, - const char *domainLibDir, const char *domainChannelTargetDir) { size_t i; @@ -9360,7 +9350,7 @@ qemuBuildCommandLine(virConnectPtr conn, for (i = 0; i < def->ngraphics; ++i) { if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps, - def->graphics[i], domainLibDir) < 0) + def->graphics[i]) < 0) goto error; } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 7c13d45..677fc05 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -74,10 +74,9 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn, virBitmapPtr nodeset, size_t *nnicindexes, int **nicindexes, - const char *domainLibDir, const char *domainChannelTargetDir) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11) - ATTRIBUTE_NONNULL(17) ATTRIBUTE_NONNULL(18); + ATTRIBUTE_NONNULL(17); /* Generate '-device' string for chardev device */ int diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6a4fb8c..cfd8a90 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4957,6 +4957,7 @@ qemuProcessPrepareDomain(virConnectPtr conn, size_t i; char *nodeset = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virCapsPtr caps; if (!(caps = virQEMUDriverGetCapabilities(driver, false))) @@ -4996,6 +4997,22 @@ qemuProcessPrepareDomain(virConnectPtr conn, if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0) goto cleanup; + /* Generate socket paths for graphics */ + for (i = 0; i < vm->def->ngraphics; i++) { + virDomainGraphicsDefPtr graphics = vm->def->graphics[i]; + + switch (graphics->type) { + case VIR_DOMAIN_GRAPHICS_TYPE_VNC: + if (cfg->vncAutoUnixSocket && !graphics->data.vnc.socket) { + if (virAsprintf(&graphics->data.vnc.socket, + "%s/vnc.sock", priv->libDir) < 0) + goto cleanup; + + continue; + } + } + } + /* "volume" type disk's source must be translated before * cgroup and security setting. */ @@ -5033,6 +5050,7 @@ qemuProcessPrepareDomain(virConnectPtr conn, cleanup: VIR_FREE(nodeset); virObjectUnref(caps); + virObjectUnref(cfg); return ret; } @@ -5230,7 +5248,6 @@ qemuProcessLaunch(virConnectPtr conn, qemuCheckFips(), priv->autoNodeset, &nnicindexes, &nicindexes, - priv->libDir, priv->channelTargetDir))) goto cleanup; @@ -5652,7 +5669,6 @@ qemuProcessCreatePretendCmd(virConnectPtr conn, priv->autoNodeset, NULL, NULL, - priv->libDir, priv->channelTargetDir); cleanup: diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args new file mode 100644 index 0000000..cfa63b1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args @@ -0,0 +1,22 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-vnc unix:/tmp/lib/domain--1-QEMUGuest1/vnc.sock \ +-vga cirrus diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml new file mode 100644 index 0000000..af961a5 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml @@ -0,0 +1,34 @@ +<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> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <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'/> + <video> + <model type='cirrus' vram='16384' heads='1'/> + </video> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index f8d0f56..7afe5c3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -903,6 +903,10 @@ mymain(void) VIR_FREE(driver.config->vncSASLdir); VIR_FREE(driver.config->vncTLSx509certdir); + driver.config->vncAutoUnixSocket = true; + DO_TEST("graphics-vnc-auto-unix-socket", QEMU_CAPS_VNC); + driver.config->vncAutoUnixSocket = false; + DO_TEST("graphics-sdl", QEMU_CAPS_SDL); DO_TEST("graphics-sdl-fullscreen", QEMU_CAPS_SDL); DO_TEST("nographics", NONE); -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:32PM +0200, Pavel Hrdina wrote:
Move generation of vnc unix socket to qemuProcessPrepareDomain which is the correct place to do those things. Now we can also test it.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/qemu/qemu_command.c | 20 ++++--------- src/qemu/qemu_command.h | 3 +- src/qemu/qemu_process.c | 20 +++++++++++-- ...qemuxml2argv-graphics-vnc-auto-unix-socket.args | 22 ++++++++++++++ .../qemuxml2argv-graphics-vnc-auto-unix-socket.xml | 34 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 4 +++ 6 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml
ACK Jan

On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
Move generation of vnc unix socket to qemuProcessPrepareDomain which is the correct place to do those things. Now we can also test it.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/qemu/qemu_command.c | 20 ++++--------- src/qemu/qemu_command.h | 3 +- src/qemu/qemu_process.c | 20 +++++++++++-- ...qemuxml2argv-graphics-vnc-auto-unix-socket.args | 22 ++++++++++++++ .../qemuxml2argv-graphics-vnc-auto-unix-socket.xml | 34 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 4 +++ 6 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9335f63..67d3336 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7219,8 +7219,7 @@ static int qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, virCommandPtr cmd, virQEMUCapsPtr qemuCaps, - virDomainGraphicsDefPtr graphics, - const char *domainLibDir) + virDomainGraphicsDefPtr graphics) { virBuffer opt = VIR_BUFFER_INITIALIZER; virDomainGraphicsListenDefPtr listen = NULL; @@ -7235,14 +7234,8 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, goto error; }
- if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) { - if (!graphics->data.vnc.socket && - virAsprintf(&graphics->data.vnc.socket, - "%s/vnc.sock", domainLibDir) == -1) - goto error; - + if (graphics->data.vnc.socket) { virBufferAsprintf(&opt, "unix:%s", graphics->data.vnc.socket); - } else { if (!graphics->data.vnc.autoport && (graphics->data.vnc.port < 5900 || @@ -7613,8 +7606,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, virCommandPtr cmd, virDomainDefPtr def, virQEMUCapsPtr qemuCaps, - virDomainGraphicsDefPtr graphics, - const char *domainLibDir) + virDomainGraphicsDefPtr graphics) { switch ((virDomainGraphicsType) graphics->type) { case VIR_DOMAIN_GRAPHICS_TYPE_SDL: @@ -7646,8 +7638,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, break;
case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps, - graphics, domainLibDir); + return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps, graphics);
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: return qemuBuildGraphicsSPICECommandLine(cfg, cmd, qemuCaps, graphics); @@ -9199,7 +9190,6 @@ qemuBuildCommandLine(virConnectPtr conn, virBitmapPtr nodeset, size_t *nnicindexes, int **nicindexes, - const char *domainLibDir, const char *domainChannelTargetDir) { size_t i; @@ -9360,7 +9350,7 @@ qemuBuildCommandLine(virConnectPtr conn,
for (i = 0; i < def->ngraphics; ++i) { if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps, - def->graphics[i], domainLibDir) < 0) + def->graphics[i]) < 0) goto error; }
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 7c13d45..677fc05 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -74,10 +74,9 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn, virBitmapPtr nodeset, size_t *nnicindexes, int **nicindexes, - const char *domainLibDir, const char *domainChannelTargetDir) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11) - ATTRIBUTE_NONNULL(17) ATTRIBUTE_NONNULL(18); + ATTRIBUTE_NONNULL(17);
/* Generate '-device' string for chardev device */ int diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6a4fb8c..cfd8a90 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4957,6 +4957,7 @@ qemuProcessPrepareDomain(virConnectPtr conn, size_t i; char *nodeset = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virCapsPtr caps;
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) @@ -4996,6 +4997,22 @@ qemuProcessPrepareDomain(virConnectPtr conn, if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0) goto cleanup;
+ /* Generate socket paths for graphics */ + for (i = 0; i < vm->def->ngraphics; i++) { + virDomainGraphicsDefPtr graphics = vm->def->graphics[i]; + + switch (graphics->type) { + case VIR_DOMAIN_GRAPHICS_TYPE_VNC: + if (cfg->vncAutoUnixSocket && !graphics->data.vnc.socket) { + if (virAsprintf(&graphics->data.vnc.socket, + "%s/vnc.sock", priv->libDir) < 0) + goto cleanup; + + continue; + } + } + }
A pre-existing bug, but we shouldn't be forcing usage of socket= here if the user already specified a listen address. So, check nListens == 0 first. But that's for a separate patch - Cole

Move adding the config listen type=address if there is none in qemuProcessPrepareDomain and move check for multiple listens to qemuProcessStartValidate. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/qemu/qemu_process.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index cfd8a90..8eb2b52 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4282,26 +4282,6 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver, if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics, true) < 0) goto cleanup; } - - if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || - graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - if (graphics->nListens == 0) { - const char *listenAddr - = graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? - cfg->vncListen : cfg->spiceListen; - - if (virDomainGraphicsListenAddAddress(graphics, 0, - listenAddr) < 0) - goto cleanup; - - graphics->listens[0].fromConfig = true; - } else if (graphics->nListens > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("QEMU does not support multiple listen " - "addresses for one graphics device.")); - goto cleanup; - } - } } ret = 0; @@ -4531,6 +4511,19 @@ qemuProcessStartValidate(virQEMUDriverPtr driver, } } + for (i = 0; i < vm->def->ngraphics; i++) { + virDomainGraphicsDefPtr graphics = vm->def->graphics[i]; + if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || + graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { + if (graphics->nListens > 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("QEMU does not support multiple listen " + "addresses for one graphics device.")); + return -1; + } + } + } + return 0; } @@ -5011,6 +5004,21 @@ qemuProcessPrepareDomain(virConnectPtr conn, continue; } } + + if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || + graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { + if (graphics->nListens == 0) { + const char *listenAddr + = graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? + cfg->vncListen : cfg->spiceListen; + + if (virDomainGraphicsListenAddAddress(graphics, 0, + listenAddr) < 0) + goto cleanup; + + graphics->listens[0].fromConfig = true; + } + } } /* "volume" type disk's source must be translated before -- 2.7.4

On Mon, Apr 04, 2016 at 03:20:33PM +0200, Pavel Hrdina wrote:
Move adding the config listen type=address if there is none in qemuProcessPrepareDomain and move check for multiple listens to qemuProcessStartValidate.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/qemu/qemu_process.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-)
Self-NACK for this patch, 17/18 and 18/18. I'll improve them in following patch series. Pavel

Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 16 ++++++++++++---- src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dc3bc22..801dcf8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1228,10 +1228,20 @@ virDomainGraphicsListenDefClear(virDomainGraphicsListenDefPtr def) } -void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) +void +virDomainGraphicsListenClear(virDomainGraphicsDefPtr def) { size_t i; + for (i = 0; i < def->nListens; i++) + virDomainGraphicsListenDefClear(&def->listens[i]); + VIR_FREE(def->listens); + def->nListens = 0; +} + + +void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) +{ if (!def) return; @@ -1263,9 +1273,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) break; } - for (i = 0; i < def->nListens; i++) - virDomainGraphicsListenDefClear(&def->listens[i]); - VIR_FREE(def->listens); + virDomainGraphicsListenClear(def); VIR_FREE(def); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a96a130..c5aa58d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2813,6 +2813,7 @@ int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match, virDomainGraphicsListenDefPtr virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i); +void virDomainGraphicsListenClear(virDomainGraphicsDefPtr def); int virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def, int pos, const char *address) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f864f78..85f1e0a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -303,6 +303,7 @@ virDomainGraphicsDefFree; virDomainGraphicsGetListen; virDomainGraphicsListenAddAddress; virDomainGraphicsListenAddNetwork; +virDomainGraphicsListenClear; virDomainGraphicsSpiceChannelModeTypeFromString; virDomainGraphicsSpiceChannelModeTypeToString; virDomainGraphicsSpiceChannelNameTypeFromString; -- 2.7.4

If in qemu.conf vncAutoUnixSocket is enabled remove all other listens parsed from XML config. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/qemu/qemu_domain.c | 10 ++++++ ...-graphics-vnc-auto-unix-socket-with-listen.args | 22 +++++++++++++ ...v-graphics-vnc-auto-unix-socket-with-listen.xml | 36 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 69 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.xml diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f38b0f3..65ab0f5 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1418,6 +1418,7 @@ qemuDomainDefPostParse(virDomainDefPtr def, virQEMUDriverPtr driver = opaque; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUCapsPtr qemuCaps = NULL; + size_t i; int ret = -1; if (def->os.bootloader || def->os.bootloaderArgs) { @@ -1446,6 +1447,15 @@ qemuDomainDefPostParse(virDomainDefPtr def, !(def->emulator = virDomainDefGetDefaultEmulator(def, caps))) return ret; + for (i = 0; i < def->ngraphics; i++) { + virDomainGraphicsDefPtr graphics = def->graphics[i]; + + if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { + if (cfg->vncAutoUnixSocket) + virDomainGraphicsListenClear(graphics); + } + } + if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) goto cleanup; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.args new file mode 100644 index 0000000..cfa63b1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.args @@ -0,0 +1,22 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-vnc unix:/tmp/lib/domain--1-QEMUGuest1/vnc.sock \ +-vga cirrus diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.xml new file mode 100644 index 0000000..af8442e --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.xml @@ -0,0 +1,36 @@ +<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> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <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'> + <listen type='address' address='127.0.0.1'/> + </graphics> + <video> + <model type='cirrus' vram='16384' heads='1'/> + </video> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 7afe5c3..475cb47 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -905,6 +905,7 @@ mymain(void) driver.config->vncAutoUnixSocket = true; DO_TEST("graphics-vnc-auto-unix-socket", QEMU_CAPS_VNC); + DO_TEST("graphics-vnc-auto-unix-socket-with-listen", QEMU_CAPS_VNC); driver.config->vncAutoUnixSocket = false; DO_TEST("graphics-sdl", QEMU_CAPS_SDL); -- 2.7.4

On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
If in qemu.conf vncAutoUnixSocket is enabled remove all other listens parsed from XML config.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Sorry I should have read further before commenting on patch #15 :) This isn't in line with how we handle qemu.conf vnc_listen, which is 'only use the qemu.conf setting if the user doesn't specify any explicit <listen> config' I think that's the more sensible behavior so I'd rather see the code fixed to abide that instead. So, the change I suggested in patch #15, but maybe it needs fixes elsewhere too - Cole

On Fri, Apr 08, 2016 at 01:40:21PM -0400, Cole Robinson wrote:
On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
If in qemu.conf vncAutoUnixSocket is enabled remove all other listens parsed from XML config.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Sorry I should have read further before commenting on patch #15 :)
This isn't in line with how we handle qemu.conf vnc_listen, which is 'only use the qemu.conf setting if the user doesn't specify any explicit <listen> config'
I think that's the more sensible behavior so I'd rather see the code fixed to abide that instead. So, the change I suggested in patch #15, but maybe it needs fixes elsewhere too
I dislike this behavior too, but I'm not sure whether we can change it or no since it was already released and someone can count on it and libvirt has a rule that we don't change anything. My intention in the following patches is to make the address/socket attribute of listen elements optional and if only <listen type='address'/> is present libvirt will use a config address and for <listen type='socket'/> libvirt will auto-generate the socket path. The qemu.conf will be used only to force all graphics to use only socket if that option is specified. Pavel
- Cole

On 04/09/2016 05:23 PM, Pavel Hrdina wrote:
On Fri, Apr 08, 2016 at 01:40:21PM -0400, Cole Robinson wrote:
On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
If in qemu.conf vncAutoUnixSocket is enabled remove all other listens parsed from XML config.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Sorry I should have read further before commenting on patch #15 :)
This isn't in line with how we handle qemu.conf vnc_listen, which is 'only use the qemu.conf setting if the user doesn't specify any explicit <listen> config'
I think that's the more sensible behavior so I'd rather see the code fixed to abide that instead. So, the change I suggested in patch #15, but maybe it needs fixes elsewhere too
I dislike this behavior too, but I'm not sure whether we can change it or no since it was already released and someone can count on it and libvirt has a rule that we don't change anything. My intention in the following patches is to make the address/socket attribute of listen elements optional and if only <listen type='address'/> is present libvirt will use a config address and for <listen type='socket'/> libvirt will auto-generate the socket path. The qemu.conf will be used only to force all graphics to use only socket if that option is specified.
I think this is a perfectly acceptable thing to change behavior for. I really doubt anyone is dependent on libvirt's behavior of throwing out other graphical config and forcing the socket bits, and this change would unify behavior with vnc_listen. Plus in my mind it's much more intuitive - Cole

On Sat, Apr 09, 2016 at 09:08:30PM -0400, Cole Robinson wrote:
On 04/09/2016 05:23 PM, Pavel Hrdina wrote:
On Fri, Apr 08, 2016 at 01:40:21PM -0400, Cole Robinson wrote:
On 04/04/2016 09:20 AM, Pavel Hrdina wrote:
If in qemu.conf vncAutoUnixSocket is enabled remove all other listens parsed from XML config.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Sorry I should have read further before commenting on patch #15 :)
This isn't in line with how we handle qemu.conf vnc_listen, which is 'only use the qemu.conf setting if the user doesn't specify any explicit <listen> config'
I think that's the more sensible behavior so I'd rather see the code fixed to abide that instead. So, the change I suggested in patch #15, but maybe it needs fixes elsewhere too
I dislike this behavior too, but I'm not sure whether we can change it or no since it was already released and someone can count on it and libvirt has a rule that we don't change anything. My intention in the following patches is to make the address/socket attribute of listen elements optional and if only <listen type='address'/> is present libvirt will use a config address and for <listen type='socket'/> libvirt will auto-generate the socket path. The qemu.conf will be used only to force all graphics to use only socket if that option is specified.
I think this is a perfectly acceptable thing to change behavior for. I really doubt anyone is dependent on libvirt's behavior of throwing out other graphical config and forcing the socket bits, and this change would unify behavior with vnc_listen. Plus in my mind it's much more intuitive
I've checked the qemu.conf again and even the comment for that option says this: "This will only be enabled for VNC configurations that do not have a hardcoded 'listen' or 'socket' value. This setting takes preference over vnc_listen." So yes, this is a bug and should be fixed. I'll include updated version of 15/18 patch in the next patch series. Pavel
participants (3)
-
Cole Robinson
-
Ján Tomko
-
Pavel Hrdina