In near future we will want to not report error when connecting
fails. In order to achieve that we have to pass a boolean that
suppresses error messages.
Signed-off-by: Michal Privoznik
---
tools/virsh-domain.c | 2 +-
tools/virsh.c| 67
tools/virsh.h| 5 +++-
tools/virt-admin.c | 49 +-
tools/vsh.c | 2 +-
tools/vsh.h | 3 ++-
6 files changed, 76 insertions(+), 52 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 42d552637..cf612f73e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10931,7 +10931,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "desturi", ) < 0)
goto cleanup;
-dconn = virshConnect(ctl, desturi, false);
+dconn = virshConnect(ctl, desturi, false, false);
if (!dconn)
goto cleanup;
diff --git a/tools/virsh.c b/tools/virsh.c
index d0c135016..7d6dc2620 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -137,7 +137,7 @@ virshCatchDisconnect(virConnectPtr conn,
/* Main Function which should be used for connecting.
* This function properly handles keepalive settings. */
virConnectPtr
-virshConnect(vshControl *ctl, const char *uri, bool readonly)
+virshConnect(vshControl *ctl, const char *uri, bool readonly, bool silent)
{
virConnectPtr c = NULL;
int interval = 5; /* Default */
@@ -191,15 +191,19 @@ virshConnect(vshControl *ctl, const char *uri, bool
readonly)
if (interval > 0 &&
virConnectSetKeepAlive(c, interval, count) != 0) {
if (keepalive_forced) {
-vshError(ctl, "%s",
- _("Cannot setup keepalive on connection "
- "as requested, disconnecting"));
+if (!silent) {
+vshError(ctl, "%s",
+ _("Cannot setup keepalive on connection "
+ "as requested, disconnecting"));
+}
virConnectClose(c);
c = NULL;
goto cleanup;
}
-vshDebug(ctl, VSH_ERR_INFO, "%s",
- _("Failed to setup keepalive on connection\n"));
+if (!silent) {
+vshDebug(ctl, VSH_ERR_INFO, "%s",
+ _("Failed to setup keepalive on connection\n"));
+}
}
cleanup:
@@ -214,7 +218,11 @@ virshConnect(vshControl *ctl, const char *uri, bool
readonly)
*
*/
static int
-virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force)
+virshReconnect(vshControl *ctl,
+ const char *name,
+ bool readonly,
+ bool force,
+ bool silent)
{
bool connected = false;
virshControlPtr priv = ctl->privData;
@@ -232,20 +240,25 @@ virshReconnect(vshControl *ctl, const char *name, bool
readonly, bool force)
virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect);
ret = virConnectClose(priv->conn);
-if (ret < 0)
-vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
-else if (ret > 0)
-vshError(ctl, "%s", _("One or more references were leaked after "
- "disconnect from the hypervisor"));
+if (!silent) {
+if (ret < 0)
+vshError(ctl, "%s", _("Failed to disconnect from the
hypervisor"));
+else if (ret > 0)
+vshError(ctl, "%s", _("One or more references were leaked
after "
+ "disconnect from the hypervisor"));
+}
}
-priv->conn = virshConnect(ctl, name ? name : ctl->connname, readonly);
+priv->conn = virshConnect(ctl, name ? name : ctl->connname,
+ readonly, silent);
if (!priv->conn) {
-if (disconnected)
-vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
-else
-vshError(ctl, "%s", _("failed to connect to the hypervisor"));
+if (!silent) {
+if (disconnected)
+vshError(ctl, "%s", _("Failed to reconnect to the
hypervisor"));
+else
+vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
+}
return -1;
} else {
if (name) {
@@ -255,8 +268,9 @@ virshReconnect(vshControl *ctl, const char *name, bool
readonly, bool force)
}
if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconnect,
ctl, NULL) < 0)
-vshError(ctl, "%s", _("Unable to register disconnect callback"));
-if (connected && !force)
+if (!silent)
+vshError(ctl, "%s", _("Unable to register disconnect
callback"));
+if (connected && !force && !silent)
vshError(ctl, "%s",