From 1ba8156cc9070eed2b5cea4ea7e519442f14e8d2 Mon Sep 17 00:00:00 2001 From: Luyao Huang Date: Tue, 10 Feb 2015 17:35:56 +0800 Subject: [PATCH] virsh: fix IP address in domdisplay for listen type='network' https://bugzilla.redhat.com/show_bug.cgi?id=1191016 virsh's domdisplay command looks in /domain/devices/graphics/@listen of the domain's XML for the listen address, however for listen type='network' (added in libvirt 0.9.4), the element doesn't have a listen attribute, but has a subelement, *still* with no address (this is the inactive XML): However, at domain start time the subelement gets its address attribute filled in once libvirt figures out the IP address associated with the named network (this is the status XML): So in these cases, we need to look at /domain/devices/graphics/listen/@address instead. Even though another patch is being pushed that will backfill listen/@address into @listen, this patch is still useful, as it fixes domdisplay for cases of a new virsh (with this patch) connecting to a libvirtd that is newer than 0.9.4 but doesn't have the followup patch. Signed-off-by: Luyao Huang Signed-off-by: Laine Stump --- tools/virsh-domain.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 358d61c6d4..20bafbeb81 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1,7 +1,7 @@ /* * virsh-domain.c: Commands to manage domain * - * Copyright (C) 2005, 2007-2014 Red Hat, Inc. + * Copyright (C) 2005, 2007-2015 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -10024,7 +10024,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) int tmp; int flags = 0; bool params = false; - const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/@%s)"; + const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/%s)"; virSocketAddr addr; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -10054,7 +10054,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) continue; /* Create our XPATH lookup for the current display's port */ - if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0) + if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@port") < 0) goto cleanup; /* Attempt to get the port number for the current graphics scheme */ @@ -10068,7 +10068,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) /* Create our XPATH lookup for TLS Port (automatically skipped * for unsupported schemes */ - if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "tlsPort") < 0) + if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@tlsPort") < 0) goto cleanup; /* Attempt to get the TLS port number */ @@ -10081,7 +10081,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) continue; /* Create our XPATH lookup for the current display's address */ - if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen") < 0) + if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@listen") < 0) goto cleanup; /* Attempt to get the listening addr if set for the current @@ -10089,13 +10089,29 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) listen_addr = virXPathString(xpath, ctxt); VIR_FREE(xpath); + if (!listen_addr) { + /* The subelement address - - + * *should* have been automatically backfilled into its + * parent (which we just tried to + * retrieve into listen_addr above) but in some cases it + * isn't, so we also do an explicit check for the + * subelement (which, by the way, doesn't exist on libvirt + * < 0.9.4, so we really do need to check both places) + */ + if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@address") < 0) + goto cleanup; + + listen_addr = virXPathString(xpath, ctxt); + VIR_FREE(xpath); + } + /* We can query this info for all the graphics types since we'll * get nothing for the unsupported ones (just rdp for now). * Also the parameter '--include-password' was already taken * care of when getting the XML */ /* Create our XPATH lookup for the password */ - if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "passwd") < 0) + if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@passwd") < 0) goto cleanup; /* Attempt to get the password */