From nobody Wed May 14 01:27:44 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526564460297290.7780359173639; Thu, 17 May 2018 06:41:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B6C330D5AB1; Thu, 17 May 2018 13:40:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B9E56091E; Thu, 17 May 2018 13:40:58 +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 6A338180B5AA; Thu, 17 May 2018 13:40:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4HDesxT007154 for ; Thu, 17 May 2018 09:40:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7EF5310B2B4F; Thu, 17 May 2018 13:40:54 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDC5B10B2B4E; Thu, 17 May 2018 13:40:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 17 May 2018 14:40:45 +0100 Message-Id: <20180517134045.21610-5-berrange@redhat.com> In-Reply-To: <20180517134045.21610-1-berrange@redhat.com> References: <20180517134045.21610-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 4/4] qemu: remove pointless connect retry logic in agent 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: , Content-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 17 May 2018 13:40:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 When the agent code was first introduced back in commit c160ce3316852a797d7b06b4ee101233866e69a9 Author: Daniel P. Berrange Date: Wed Oct 5 18:31:54 2011 +0100 QEMU guest agent support there was code that would loop and retry the connection when opening the agent socket. At this time, the only thing done in between the opening of the monitor socket & opening of the agent socket was a call to set the monitor capabilities. This was a no-op on non-QMP versions, so in theory there could be a race which let us connect to the monitor while the agent socket was still not created by QEMU. In the modern world, however, we long ago mandated the use of QMP for managing QEMU, so we're guaranteed to have a set capabilities QMP call. Once we've seen a reply to this, we're guaranteed that QEMU has fully initialized all backends and is in its event loop. We can thus be sure the QEMU agent socket is present and don't need to retry connections to it, even without having the chardev FD passing feature. Reviewed-by: John Ferlan Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_agent.c | 84 ++++--------------------------------------- 1 file changed, 7 insertions(+), 77 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index b838f75207..e508abcc24 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -106,7 +106,6 @@ struct _qemuAgent { int fd; int watch; =20 - bool connectPending; bool running; =20 virDomainObjPtr vm; @@ -180,15 +179,12 @@ static void qemuAgentDispose(void *obj) } =20 static int -qemuAgentOpenUnix(const char *monitor, pid_t cpid, bool *inProgress) +qemuAgentOpenUnix(const char *monitor) { struct sockaddr_un addr; int monfd; - virTimeBackOffVar timeout; int ret =3D -1; =20 - *inProgress =3D false; - if ((monfd =3D socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { virReportSystemError(errno, "%s", _("failed to create socket")); @@ -217,39 +213,11 @@ qemuAgentOpenUnix(const char *monitor, pid_t cpid, bo= ol *inProgress) goto error; } =20 - if (virTimeBackOffStart(&timeout, 1, 3*1000 /* ms */) < 0) - goto error; - while (virTimeBackOffWait(&timeout)) { - ret =3D connect(monfd, (struct sockaddr *)&addr, sizeof(addr)); - - if (ret =3D=3D 0) - break; - - if ((errno =3D=3D ENOENT || errno =3D=3D ECONNREFUSED) && - virProcessKill(cpid, 0) =3D=3D 0) { - /* ENOENT : Socket may not have shown up yet - * ECONNREFUSED : Leftover socket hasn't been removed yet */ - continue; - } - - if ((errno =3D=3D EINPROGRESS) || - (errno =3D=3D EAGAIN)) { - VIR_DEBUG("Connection attempt continuing in background"); - *inProgress =3D true; - ret =3D 0; - break; - } - + ret =3D connect(monfd, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) { virReportSystemError(errno, "%s", _("failed to connect to monitor socket")); goto error; - - } - - if (ret !=3D 0) { - virReportSystemError(errno, "%s", - _("monitor socket did not show up")); - goto error; } =20 return monfd; @@ -470,35 +438,6 @@ qemuAgentIOProcess(qemuAgentPtr mon) } =20 =20 -static int -qemuAgentIOConnect(qemuAgentPtr mon) -{ - int optval; - socklen_t optlen; - - VIR_DEBUG("Checking on background connection status"); - - mon->connectPending =3D false; - - optlen =3D sizeof(optval); - - if (getsockopt(mon->fd, SOL_SOCKET, SO_ERROR, - &optval, &optlen) < 0) { - virReportSystemError(errno, "%s", - _("Cannot check socket connection status")); - return -1; - } - - if (optval !=3D 0) { - virReportSystemError(optval, "%s", - _("Cannot connect to agent socket")); - return -1; - } - - VIR_DEBUG("Agent is now connected"); - return 0; -} - /* * Called when the monitor is able to write data * Call this function while holding the monitor lock. @@ -630,13 +569,8 @@ qemuAgentIO(int watch, int fd, int events, void *opaqu= e) error =3D true; } else { if (events & VIR_EVENT_HANDLE_WRITABLE) { - if (mon->connectPending) { - if (qemuAgentIOConnect(mon) < 0) - error =3D true; - } else { - if (qemuAgentIOWrite(mon) < 0) - error =3D true; - } + if (qemuAgentIOWrite(mon) < 0) + error =3D true; events &=3D ~VIR_EVENT_HANDLE_WRITABLE; } =20 @@ -768,8 +702,7 @@ qemuAgentOpen(virDomainObjPtr vm, =20 switch (config->type) { case VIR_DOMAIN_CHR_TYPE_UNIX: - mon->fd =3D qemuAgentOpenUnix(config->data.nix.path, vm->pid, - &mon->connectPending); + mon->fd =3D qemuAgentOpenUnix(config->data.nix.path); break; =20 case VIR_DOMAIN_CHR_TYPE_PTY: @@ -790,10 +723,7 @@ qemuAgentOpen(virDomainObjPtr vm, if ((mon->watch =3D virEventAddHandle(mon->fd, VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR | - VIR_EVENT_HANDLE_READABLE | - (mon->connectPending ? - VIR_EVENT_HANDLE_WRITABLE : - 0), + VIR_EVENT_HANDLE_READABLE, qemuAgentIO, mon, virObjectFreeCallback)) < 0) { --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list