[libvirt] [PATCH 0/2] virsh: catch disconnections for non-default connections too

Right now virsh says 'Failed to reconnect to the hypervisor' even for the first connection to the default URI and it fails to catch disconnections for connections to the non-default URI. Ján Tomko (2): virsh: don't lie about reconnection in vshReconnect virsh: use vshReconnect for non-default connections too tools/virsh.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) -- 1.7.8.6

Since we (ab)use vshReconnect for the default URI connection, if it fails it might print 'Failed to reconnect to the hypervisor' even if we were never connected before. This changes it to only mention reconnection on the first try after getting disconnected. --- tools/virsh.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index b4829a3..9845b12 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -331,7 +331,10 @@ vshReconnect(vshControl *ctl) virConnectAuthPtrDefault, ctl->readonly ? VIR_CONNECT_RO : 0); if (!ctl->conn) { - vshError(ctl, "%s", _("Failed to reconnect to the hypervisor")); + if (disconnected) + vshError(ctl, "%s", _("Failed to reconnect to the hypervisor")); + else + vshError(ctl, "%s", _("failed to connect to the hypervisor")); } else { if (virConnectRegisterCloseCallback(ctl->conn, vshCatchDisconnect, NULL, NULL) < 0) -- 1.7.8.6

For non-default connections (specified by the environment variable or the command line option) we call virConnectOpenAuth without registering the vshCatchDisconnect callback. This calls vshReconnect instead which takes care of it. --- tools/virsh.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 9845b12..465cb44 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2189,10 +2189,7 @@ vshInit(vshControl *ctl) ctl->eventLoopStarted = true; if (ctl->name) { - ctl->conn = virConnectOpenAuth(ctl->name, - virConnectAuthPtrDefault, - ctl->readonly ? VIR_CONNECT_RO : 0); - + vshReconnect(ctl); /* Connecting to a named connection must succeed, but we delay * connecting to the default connection until we need it * (since the first command might be 'connect' which allows a @@ -2201,7 +2198,6 @@ vshInit(vshControl *ctl) */ if (!ctl->conn) { vshReportError(ctl); - vshError(ctl, "%s", _("failed to connect to the hypervisor")); return false; } } -- 1.7.8.6

On Thu, Dec 13, 2012 at 14:07:59 +0100, Ján Tomko wrote:
Right now virsh says 'Failed to reconnect to the hypervisor' even for the first connection to the default URI and it fails to catch disconnections for connections to the non-default URI.
Ján Tomko (2): virsh: don't lie about reconnection in vshReconnect virsh: use vshReconnect for non-default connections too
tools/virsh.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
ACK series Jirka

On Thu, Dec 13, 2012 at 14:24:03 +0100, Jiri Denemark wrote:
On Thu, Dec 13, 2012 at 14:07:59 +0100, Ján Tomko wrote:
Right now virsh says 'Failed to reconnect to the hypervisor' even for the first connection to the default URI and it fails to catch disconnections for connections to the non-default URI.
Ján Tomko (2): virsh: don't lie about reconnection in vshReconnect virsh: use vshReconnect for non-default connections too
tools/virsh.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
ACK series
And pushed. Jirka
participants (2)
-
Jiri Denemark
-
Ján Tomko