From nobody Thu May 15 06:23:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510057392143220.0609739724531; Tue, 7 Nov 2017 04:23:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89EBD883DC; Tue, 7 Nov 2017 12:23:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6500F5D6A9; Tue, 7 Nov 2017 12:23:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0A8FE4A469; Tue, 7 Nov 2017 12:23:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CN7tE031625 for ; Tue, 7 Nov 2017 07:23:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id D89435C545; Tue, 7 Nov 2017 12:23:07 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F90F5C8A1 for ; Tue, 7 Nov 2017 12:23:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89EBD883DC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 7 Nov 2017 13:22:51 +0100 Message-Id: <762ee1b32f7be5a3d44919e4b6aa41ad16e80471.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/11] vsh: Add @silent to vshConnectionHook X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 07 Nov 2017 12:23:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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", &desturi) < 0) goto cleanup; =20 - dconn =3D virshConnect(ctl, desturi, false); + dconn =3D virshConnect(ctl, desturi, false, false); if (!dconn) goto cleanup; =20 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 =3D NULL; int interval =3D 5; /* Default */ @@ -191,15 +191,19 @@ virshConnect(vshControl *ctl, const char *uri, bool r= eadonly) if (interval > 0 && virConnectSetKeepAlive(c, interval, count) !=3D 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 =3D 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")); + } } =20 cleanup: @@ -214,7 +218,11 @@ virshConnect(vshControl *ctl, const char *uri, bool re= adonly) * */ static int -virshReconnect(vshControl *ctl, const char *name, bool readonly, bool forc= e) +virshReconnect(vshControl *ctl, + const char *name, + bool readonly, + bool force, + bool silent) { bool connected =3D false; virshControlPtr priv =3D ctl->privData; @@ -232,20 +240,25 @@ virshReconnect(vshControl *ctl, const char *name, boo= l readonly, bool force) =20 virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect= ); ret =3D virConnectClose(priv->conn); - if (ret < 0) - vshError(ctl, "%s", _("Failed to disconnect from the hyperviso= r")); - else if (ret > 0) - vshError(ctl, "%s", _("One or more references were leaked afte= r " - "disconnect from the hypervisor")); + if (!silent) { + if (ret < 0) + vshError(ctl, "%s", _("Failed to disconnect from the hyper= visor")); + else if (ret > 0) + vshError(ctl, "%s", _("One or more references were leaked = after " + "disconnect from the hypervisor")); + } } =20 - priv->conn =3D virshConnect(ctl, name ? name : ctl->connname, readonly= ); + priv->conn =3D virshConnect(ctl, name ? name : ctl->connname, + readonly, silent); =20 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 hypervis= or")); + 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, virshCatchDisconne= ct, ctl, NULL) < 0) - vshError(ctl, "%s", _("Unable to register disconnect callback"= )); - if (connected && !force) + if (!silent) + vshError(ctl, "%s", _("Unable to register disconnect callb= ack")); + if (connected && !force && !silent) vshError(ctl, "%s", _("Reconnected to the hypervisor")); } disconnected =3D 0; @@ -304,7 +318,7 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) return false; =20 - if (virshReconnect(ctl, name, ro, true) < 0) + if (virshReconnect(ctl, name, ro, true, false) < 0) return false; =20 return true; @@ -316,11 +330,12 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) */ =20 static bool -virshConnectionUsability(vshControl *ctl, virConnectPtr conn) +virshConnectionUsability(vshControl *ctl, virConnectPtr conn, bool silent) { if (!conn || virConnectIsAlive(conn) =3D=3D 0) { - vshError(ctl, "%s", _("no valid connection")); + if (!silent) + vshError(ctl, "%s", _("no valid connection")); return false; } =20 @@ -333,15 +348,15 @@ virshConnectionUsability(vshControl *ctl, virConnectP= tr conn) } =20 static void * -virshConnectionHandler(vshControl *ctl) +virshConnectionHandler(vshControl *ctl, bool silent) { virshControlPtr priv =3D ctl->privData; =20 if ((!priv->conn || disconnected) && - virshReconnect(ctl, NULL, false, false) < 0) + virshReconnect(ctl, NULL, false, false, silent) < 0) return NULL; =20 - if (virshConnectionUsability(ctl, priv->conn)) + if (virshConnectionUsability(ctl, priv->conn, silent)) return priv->conn; =20 return NULL; @@ -391,7 +406,7 @@ virshInit(vshControl *ctl) * non-default connection, or might be 'help' which needs no * connection). */ - if (virshReconnect(ctl, NULL, false, false) < 0) { + if (virshReconnect(ctl, NULL, false, false, false) < 0) { vshReportError(ctl); return false; } diff --git a/tools/virsh.h b/tools/virsh.h index b353b645a..e03b597ef 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -144,6 +144,9 @@ typedef enum { VIRSH_BYMAC =3D (1 << 4), } virshLookupByFlags; =20 -virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly= ); +virConnectPtr virshConnect(vshControl *ctl, + const char *uri, + bool readonly, + bool silent); =20 #endif /* VIRSH_H */ diff --git a/tools/virt-admin.c b/tools/virt-admin.c index b8b33af19..5d7ef7988 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -154,24 +154,26 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn ATTRIBUTE= _UNUSED, } =20 static int -vshAdmConnect(vshControl *ctl, unsigned int flags) +vshAdmConnect(vshControl *ctl, unsigned int flags, bool silent) { vshAdmControlPtr priv =3D ctl->privData; =20 priv->conn =3D virAdmConnectOpen(ctl->connname, flags); =20 if (!priv->conn) { - if (priv->wantReconnect) - vshError(ctl, "%s", _("Failed to reconnect to the admin server= ")); - else - vshError(ctl, "%s", _("Failed to connect to the admin server")= ); + if (!silent) { + if (priv->wantReconnect) + vshError(ctl, "%s", _("Failed to reconnect to the admin se= rver")); + else + vshError(ctl, "%s", _("Failed to connect to the admin serv= er")); + } return -1; } else { if (virAdmConnectRegisterCloseCallback(priv->conn, vshAdmCatchDisc= onnect, - NULL, NULL) < 0) + NULL, NULL) < 0 && !silent) vshError(ctl, "%s", _("Unable to register disconnect callback"= )); =20 - if (priv->wantReconnect) + if (priv->wantReconnect && !silent) vshPrint(ctl, "%s\n", _("Reconnected to the admin server")); } =20 @@ -179,7 +181,7 @@ vshAdmConnect(vshControl *ctl, unsigned int flags) } =20 static int -vshAdmDisconnect(vshControl *ctl) +vshAdmDisconnect(vshControl *ctl, bool silent) { int ret =3D 0; vshAdmControlPtr priv =3D ctl->privData; @@ -189,11 +191,13 @@ vshAdmDisconnect(vshControl *ctl) =20 virAdmConnectUnregisterCloseCallback(priv->conn, vshAdmCatchDisconnect= ); ret =3D virAdmConnectClose(priv->conn); - if (ret < 0) - vshError(ctl, "%s", _("Failed to disconnect from the admin server"= )); - 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 admin ser= ver")); + else if (ret > 0) + vshError(ctl, "%s", _("One or more references were leaked afte= r " + "disconnect from the hypervisor")); + } priv->conn =3D NULL; return ret; } @@ -205,14 +209,14 @@ vshAdmDisconnect(vshControl *ctl) * */ static void -vshAdmReconnect(vshControl *ctl) +vshAdmReconnect(vshControl *ctl, bool silent) { vshAdmControlPtr priv =3D ctl->privData; if (priv->conn) priv->wantReconnect =3D true; =20 - vshAdmDisconnect(ctl); - vshAdmConnect(ctl, 0); + vshAdmDisconnect(ctl, silent); + vshAdmConnect(ctl, 0, silent); =20 priv->wantReconnect =3D false; } @@ -350,7 +354,7 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) ctl->connname =3D vshStrdup(ctl, name); } =20 - vshAdmReconnect(ctl); + vshAdmReconnect(ctl, false); if (!connected && priv->conn) vshPrint(ctl, "%s\n", _("Connected to the admin server")); =20 @@ -1080,15 +1084,16 @@ cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *= cmd) } =20 static void * -vshAdmConnectionHandler(vshControl *ctl) +vshAdmConnectionHandler(vshControl *ctl, bool silent) { vshAdmControlPtr priv =3D ctl->privData; =20 if (!virAdmConnectIsAlive(priv->conn)) - vshAdmReconnect(ctl); + vshAdmReconnect(ctl, silent); =20 if (!virAdmConnectIsAlive(priv->conn)) { - vshError(ctl, "%s", _("no valid connection")); + if (!silent) + vshError(ctl, "%s", _("no valid connection")); return NULL; } =20 @@ -1122,7 +1127,7 @@ vshAdmInit(vshControl *ctl) ctl->eventLoopStarted =3D true; =20 if (ctl->connname) { - vshAdmReconnect(ctl); + vshAdmReconnect(ctl, false); /* 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 @@ -1156,7 +1161,7 @@ vshAdmDeinit(vshControl *ctl) VIR_FREE(ctl->connname); =20 if (priv->conn) - vshAdmDisconnect(ctl); + vshAdmDisconnect(ctl, false); =20 virResetLastError(); =20 diff --git a/tools/vsh.c b/tools/vsh.c index 24ea45aa4..83c96e1a8 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1321,7 +1321,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) GETTIMEOFDAY(&before); =20 if ((cmd->def->flags & VSH_CMD_FLAG_NOCONNECT) || - (hooks && hooks->connHandler && hooks->connHandler(ctl))) { + (hooks && hooks->connHandler && hooks->connHandler(ctl, false)= )) { ret =3D cmd->def->handler(ctl, cmd); } else { /* connection is not usable, return error */ diff --git a/tools/vsh.h b/tools/vsh.h index 8f7df9ff8..c411c2ca4 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -232,7 +232,8 @@ struct _vshControl { }; =20 typedef void * -(*vshConnectionHook)(vshControl *ctl); +(*vshConnectionHook)(vshControl *ctl, + bool silent); =20 struct _vshClientHooks { vshConnectionHook connHandler; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list