From 699299419b4d079a57fc7faa5e819403ba198381 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Tue, 10 Feb 2015 13:49:16 -0500 Subject: [PATCH] domain: backfill listen address to parent listen attribute Prior to 0.9.4, libvirt only supported a single listen, and it had to be an IP address: Starting with 0.9.4, a graphics element could have a subelement (actually the grammar supports multiples, but all of the drivers only support a single per ), and that listen element can be of type='address' or type='network'. For type='address', also has an attribute called 'address' which contains the IP address for listening: type can also be "network", and in that case listen will have a "network" attribute which will contain the name of a libvirt network: At domain start (or migrate) time, libvirt will attempt to find an IP address associated with that network (e.g. the IP address of the bridge device used by the network, or the physical device listed in ) and fill in that address in the status XML: In the case that a element has a subelement of type='address', that listen subelement's "address" attribute is backfilled into the parent graphics element's "listen" *attribute* for backward compatibility (so that a management application unaware of the separate element can still learn the listen address). This backfill should be done with the IP learned from type='network' as well, and that's what this patch does: This is a continuation of the fix for: https://bugzilla.redhat.com/show_bug.cgi?id=1191016 --- src/conf/domain_conf.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 365f14b732..1e43903914 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18915,17 +18915,23 @@ virDomainGraphicsDefFormat(virBufferPtr buf, return -1; } - /* find the first listen element of type='address' and duplicate - * its address attribute as the listen attribute of - * . This is done to improve backward compatibility. */ + /* find the first listen subelement with a valid address and + * duplicate its address attribute as the listen attribute of + * . This is done to improve backward compatibility. + */ for (i = 0; i < def->nListens; i++) { - if (virDomainGraphicsListenGetType(def, i) - == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { - if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && - def->listens[i].fromConfig) - continue; - listenAddr = virDomainGraphicsListenGetAddress(def, i); - break; + virDomainGraphicsListenType listenType; + + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && + def->listens[i].fromConfig) + continue; + listenType = virDomainGraphicsListenGetType(def, i); + + if (listenType == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || + (listenType == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) { + if ((listenAddr = virDomainGraphicsListenGetAddress(def, i))) + break; } }