From nobody Tue May 7 20:33:25 2024 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 1538127071681385.0767811889999; Fri, 28 Sep 2018 02:31:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 688833DD47; Fri, 28 Sep 2018 09:31:09 +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 94EA5D723D; Fri, 28 Sep 2018 09:31:07 +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 11531181A12F; Fri, 28 Sep 2018 09:31:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8S9V4Sh010699 for ; Fri, 28 Sep 2018 05:31:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7F846253E; Fri, 28 Sep 2018 09:31:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCEED6253D for ; Fri, 28 Sep 2018 09:31:01 +0000 (UTC) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C8D44E902 for ; Fri, 28 Sep 2018 09:30:59 +0000 (UTC) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 7EF4CDE0B29472A9F2BF for ; Fri, 28 Sep 2018 17:30:57 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w8S9Up1w019958 for ; Fri, 28 Sep 2018 17:30:51 +0800 (GMT-8) (envelope-from wang.yechao255@zte.com.cn) Received: from kvm-146.zte.com.cn ([10.74.120.146]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018092817313049-1686149 ; Fri, 28 Sep 2018 17:31:30 +0800 From: Wang Yechao To: libvir-list@redhat.com Date: Fri, 28 Sep 2018 17:36:08 +0800 Message-Id: <1538127368-2305-1-git-send-email-wang.yechao255@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-09-28 17:31:30, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-09-28 17:30:36, Serialize complete at 2018-09-28 17:30:36 X-MAIL: mse01.zte.com.cn w8S9Up1w019958 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 214 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 28 Sep 2018 09:30:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 28 Sep 2018 09:30:59 +0000 (UTC) for IP:'63.217.80.70' DOMAIN:'mxhk.zte.com.cn' HELO:'mxhk.zte.com.cn' FROM:'wang.yechao255@zte.com.cn' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 63.217.80.70 mxhk.zte.com.cn 63.217.80.70 mxhk.zte.com.cn X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Wang Yechao Subject: [libvirt] [PATCH v2] qemu: agent: Avoid agentError when closing the QEMU 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: , 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 28 Sep 2018 09:31:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" After calling qemuAgentClose(), it is still possible for the QEMU Agent I/O event callback to get invoked. This will trigger an agent error because mon->fd has been set to -1 at this point. Then vm->privateData->agentError is always 'true' except that restart libvirtd or restart qemu-guest-agent process in guest. Silently ignore the case where mon->fd is -1, likewise for mon->watch being zero. Signed-off-by: Wang Yechao --- v1 patch: https://www.redhat.com/archives/libvir-list/2018-September/msg01382.html Changes in v2: - do not set agentError, let agent state as disconnected instead of error. --- src/qemu/qemu_agent.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 97ad0e7..d842b0e 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -530,6 +530,9 @@ static void qemuAgentUpdateWatch(qemuAgentPtr mon) VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR; =20 + if (!mon->watch) + return; + if (mon->lastError.code =3D=3D VIR_ERR_OK) { events |=3D VIR_EVENT_HANDLE_READABLE; =20 @@ -555,6 +558,12 @@ qemuAgentIO(int watch, int fd, int events, void *opaqu= e) VIR_DEBUG("Agent %p I/O on watch %d fd %d events %d", mon, watch, fd, = events); #endif =20 + if (mon->fd =3D=3D -1 || mon->watch =3D=3D 0) { + virObjectUnlock(mon); + virObjectUnref(mon); + return; + } + if (mon->fd !=3D fd || mon->watch !=3D watch) { if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR)) eof =3D true; @@ -788,8 +797,10 @@ void qemuAgentClose(qemuAgentPtr mon) virObjectLock(mon); =20 if (mon->fd >=3D 0) { - if (mon->watch) + if (mon->watch) { virEventRemoveHandle(mon->watch); + mon->watch =3D 0; + } VIR_FORCE_CLOSE(mon->fd); } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list