[libvirt] [PATCH] virsh: use the same connection URI for reconnect

Martin Kletzander mkletzan at redhat.com
Thu Apr 14 08:00:46 UTC 2016


On Thu, Apr 14, 2016 at 10:23:04AM +0300, Roman Bogorodskiy wrote:
>When for some reason virsh looses connection and then tries to
>reconnection, it uses the default URI instead of the one that was used
>for the previous connection it got disconnected from.
>
>In order to make it reconnect using the same URI, copy URI of the
>current (disconnected) connection to vshControl 'connname' attribute.
>---
> tools/virsh.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
>diff --git a/tools/virsh.c b/tools/virsh.c
>index 5a61189..07097aa 100644
>--- a/tools/virsh.c
>+++ b/tools/virsh.c
>@@ -359,6 +359,14 @@ virshConnectionHandler(vshControl *ctl)
> {
>     virshControlPtr priv = ctl->privData;
>
>+    if (disconnected && priv->conn) {
>+        if (!ctl->connname) {
>+            char *uri = virConnectGetURI(priv->conn);
>+            ctl->connname = vshStrdup(ctl, uri);

This would mean that next "connect" without parameters would connect to
the new uri.  Is that how you were trying that?  It's no how it should
behave IMHO.  I tried force-killing the daemon as well as letting the
client disconnect due to keepalive and in both cases virsh reconnected
to the last daemon it was connected to.  If you actually used 'connect'
after disconnection, you actually forced new connection to be made and
because no uri was supplied you got connected to the default uri.  With
your patch, I'm afraid the behaviour would change.  Also it would be
impossible to reconnect to the default uri unless you know it or printed
it out in the session.  Not that the last thing would be a great deal,
it's just a minor obstruction in usage I'd say.

>+            VIR_FREE(uri);
>+        }
>+    }
>+
>     if (!priv->conn || disconnected)
>         virshReconnect(ctl);
>
>--
>2.7.4
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160414/a42f27f4/attachment-0001.sig>


More information about the libvir-list mailing list