|
|
6ae9ed |
From 666a718d25a45051137ef6dfd353607492c58801 Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <666a718d25a45051137ef6dfd353607492c58801@dist-git>
|
|
|
6ae9ed |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
6ae9ed |
Date: Tue, 2 Aug 2016 13:37:38 +0200
|
|
|
6ae9ed |
Subject: [PATCH] virsh: Report error when explicit connection fails
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Commit 0c56d9431839 forgot to return false in the cmdConnect command
|
|
|
6ae9ed |
after the clean up made there.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Before (assuming you don't have uri alias for 'asdf'):
|
|
|
6ae9ed |
$ virsh connect asdf
|
|
|
6ae9ed |
error: failed to connect to the hypervisor
|
|
|
6ae9ed |
|
|
|
6ae9ed |
$ echo $?
|
|
|
6ae9ed |
0
|
|
|
6ae9ed |
|
|
|
6ae9ed |
After (with the same assumption):
|
|
|
6ae9ed |
$ virsh connect asdf
|
|
|
6ae9ed |
error: failed to connect to the hypervisor
|
|
|
6ae9ed |
error: no connection driver available for asdf
|
|
|
6ae9ed |
|
|
|
6ae9ed |
$ echo $?
|
|
|
6ae9ed |
1
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1356461
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
6ae9ed |
(cherry picked from commit ff498a9ac70a550bed08233a86e00a4faf12aecf)
|
|
|
6ae9ed |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
tools/virsh.c | 16 ++++++++++------
|
|
|
6ae9ed |
1 file changed, 10 insertions(+), 6 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/tools/virsh.c b/tools/virsh.c
|
|
|
6ae9ed |
index f74698f..d3fe06f 100644
|
|
|
6ae9ed |
--- a/tools/virsh.c
|
|
|
6ae9ed |
+++ b/tools/virsh.c
|
|
|
6ae9ed |
@@ -210,7 +210,7 @@ virshConnect(vshControl *ctl, const char *uri, bool readonly)
|
|
|
6ae9ed |
* Reconnect after a disconnect from libvirtd
|
|
|
6ae9ed |
*
|
|
|
6ae9ed |
*/
|
|
|
6ae9ed |
-static void
|
|
|
6ae9ed |
+static int
|
|
|
6ae9ed |
virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
bool connected = false;
|
|
|
6ae9ed |
@@ -237,6 +237,7 @@ virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force)
|
|
|
6ae9ed |
vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
|
|
|
6ae9ed |
else
|
|
|
6ae9ed |
vshError(ctl, "%s", _("failed to connect to the hypervisor"));
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
} else {
|
|
|
6ae9ed |
if (name) {
|
|
|
6ae9ed |
VIR_FREE(ctl->connname);
|
|
|
6ae9ed |
@@ -253,6 +254,7 @@ virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force)
|
|
|
6ae9ed |
priv->useGetInfo = false;
|
|
|
6ae9ed |
priv->useSnapshotOld = false;
|
|
|
6ae9ed |
priv->blockJobNoBytes = false;
|
|
|
6ae9ed |
+ return 0;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
int virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
|
|
|
6ae9ed |
@@ -301,7 +303,8 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
|
|
6ae9ed |
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
|
|
|
6ae9ed |
return false;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- virshReconnect(ctl, name, ro, true);
|
|
|
6ae9ed |
+ if (virshReconnect(ctl, name, ro, true) < 0)
|
|
|
6ae9ed |
+ return false;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
return true;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
@@ -333,11 +336,13 @@ virshConnectionHandler(vshControl *ctl)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
virshControlPtr priv = ctl->privData;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- if (!priv->conn || disconnected)
|
|
|
6ae9ed |
- virshReconnect(ctl, NULL, false, false);
|
|
|
6ae9ed |
+ if ((!priv->conn || disconnected) &&
|
|
|
6ae9ed |
+ virshReconnect(ctl, NULL, false, false) < 0)
|
|
|
6ae9ed |
+ return NULL;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (virshConnectionUsability(ctl, priv->conn))
|
|
|
6ae9ed |
return priv->conn;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
return NULL;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
@@ -444,14 +449,13 @@ virshInit(vshControl *ctl)
|
|
|
6ae9ed |
return false;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (ctl->connname) {
|
|
|
6ae9ed |
- virshReconnect(ctl, NULL, false, false);
|
|
|
6ae9ed |
/* Connecting to a named connection must succeed, but we delay
|
|
|
6ae9ed |
* connecting to the default connection until we need it
|
|
|
6ae9ed |
* (since the first command might be 'connect' which allows a
|
|
|
6ae9ed |
* non-default connection, or might be 'help' which needs no
|
|
|
6ae9ed |
* connection).
|
|
|
6ae9ed |
*/
|
|
|
6ae9ed |
- if (!priv->conn) {
|
|
|
6ae9ed |
+ if (virshReconnect(ctl, NULL, false, false) < 0) {
|
|
|
6ae9ed |
vshReportError(ctl);
|
|
|
6ae9ed |
return false;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|