Re: [PATCH] virsh: fix show the wrong IP address for network type listen address graphic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/10/2015 04:35 AM, Luyao Huang wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1191016
>
> We try to get the IP address in /domain/devices/graphics/@listen, howerver
> for the network type listen address donnot have this parameter, it will
> show the address in the /domain/devices/graphics/listen/@address, running
> XML like this:
>
>  <graphics type='spice' port='5901' autoport='yes' keymap='en-us'>
>   <listen type='network' address='192.168.122.1' network='default'/>
>  </graphics>
>
> This patch will try to get the IP address in this path
> /domain/devices/graphics/listen/@address

That will work when the libvirtd being connected to is 0.9.4 or later,
but earlier versions of libvirt don't have the <listen> subelement;
instead they just have a 'listen' attribute directly inside <graphics>
that contains the address. All newer versions of libvirt are supposed to
populate that from <listen>[0] for backward compatibility.

The real bug here is that the listen attribute in <graphics> isn't being
filled in in the case of type='network' when the domain is active. On
the other hand, fixing the problem there would leave it unfixed for
cases where the client is a new libvirt but the server is running
libvirt between 0.9.4 and 1.2.12. So I think what is needed is for your
patch to check @listen, and if nothing is found there, *then* check
listen/@address. I attached a patch to this mail that I propose
squashing into your patch before pushing. Let me know if it behaves
properly and looks correct.

Beyond that, the server side should still be fixed. I just sent a patch
that does that:

https://www.redhat.com/archives/libvir-list/2015-February/msg00332.html

Between the two patches, we will have fixed the problem for all versions
of server, as long as the client is new enough.

>From 5f8800d93375ee67dd94bf50a87ed75f44ca2b19 Mon Sep 17 00:00:00 2001
From: Laine Stump <laine@xxxxxxxxx>
Date: Tue, 10 Feb 2015 13:32:33 -0500
Subject: [PATCH] virsh: check listen attribute *and* listen subelement in
 domdisplay

This should be squashed into Luyao Huang's patch fixing the output of
virsh domdisplay. Without it, virsh would fail when connecting to a
libvirtd older than 0.9.4.
---
 tools/virsh-domain.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 4a9b574..20bafbe 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
@@ -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/@address") < 0)
+        if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@listen") < 0)
             goto cleanup;
 
         /* Attempt to get the listening addr if set for the current
@@ -10089,6 +10089,22 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         listen_addr = virXPathString(xpath, ctxt);
         VIR_FREE(xpath);
 
+        if (!listen_addr) {
+            /* The subelement address - <listen address='xyz'/> -
+             * *should* have been automatically backfilled into its
+             * parent <graphics listen='xyz'> (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
-- 
2.1.0

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]