From nobody Sat Apr 27 17:25:59 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.zoho.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 1493736975970829.5120160937832; Tue, 2 May 2017 07:56:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BE57311690; Tue, 2 May 2017 14:56:12 +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 9877A71D4A; Tue, 2 May 2017 14:56: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 715FB18523C2; Tue, 2 May 2017 14:56:07 +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 v42Eu5sG001899 for ; Tue, 2 May 2017 10:56:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id D316478C27; Tue, 2 May 2017 14:56:05 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7954678C1E for ; Tue, 2 May 2017 14:56:01 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 96737100E8D; Tue, 2 May 2017 16:56:00 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5BE57311690 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5BE57311690 From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 2 May 2017 16:55:59 +0200 Message-Id: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] client: Report proper close reason 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 02 May 2017 14:56:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When we get a POLLHUP or VIR_EVENT_HANDLE_HANGUP event for a client, we still want to read from the socket to process any accumulated data. But doing so inevitably results in an error and a call to virNetClientMarkClose before we get to processing the hangup event (and another call to virNetClientMarkClose). However the close reason passed to the second virNetClientMarkClose call is ignored because another one was already set. We need to pass the correct close reason when marking the socket to be closed for the first time. https://bugzilla.redhat.com/show_bug.cgi?id=3D1373859 Signed-off-by: Jiri Denemark --- src/rpc/virnetclient.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index c95974794..837a8a707 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1595,6 +1595,7 @@ static int virNetClientIOEventLoop(virNetClientPtr cl= ient, { struct pollfd fds[2]; bool error =3D false; + int closeReason; int ret; =20 fds[0].fd =3D virNetSocketGetFD(client->sock); @@ -1703,9 +1704,14 @@ static int virNetClientIOEventLoop(virNetClientPtr c= lient, } } =20 + if (fds[0].revents & POLLHUP) + closeReason =3D VIR_CONNECT_CLOSE_REASON_EOF; + else + closeReason =3D VIR_CONNECT_CLOSE_REASON_ERROR; + if (fds[0].revents & POLLOUT) { if (virNetClientIOHandleOutput(client) < 0) { - virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERR= OR); + virNetClientMarkClose(client, closeReason); error =3D true; /* Fall through to process any pending data. */ } @@ -1713,7 +1719,7 @@ static int virNetClientIOEventLoop(virNetClientPtr cl= ient, =20 if (fds[0].revents & POLLIN) { if (virNetClientIOHandleInput(client) < 0) { - virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERR= OR); + virNetClientMarkClose(client, closeReason); error =3D true; /* Fall through to process any pending data. */ } @@ -1746,13 +1752,13 @@ static int virNetClientIOEventLoop(virNetClientPtr = client, if (fds[0].revents & POLLHUP) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("received hangup event on socket")); - virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_EOF); + virNetClientMarkClose(client, closeReason); goto error; } if (fds[0].revents & POLLERR) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("received error event on socket")); - virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR); + virNetClientMarkClose(client, closeReason); goto error; } } @@ -1968,6 +1974,7 @@ void virNetClientIncomingEvent(virNetSocketPtr sock, void *opaque) { virNetClientPtr client =3D opaque; + int closeReason; =20 virObjectLock(client); =20 @@ -1981,23 +1988,25 @@ void virNetClientIncomingEvent(virNetSocketPtr sock, =20 VIR_DEBUG("Event fired %p %d", sock, events); =20 + if (events & VIR_EVENT_HANDLE_HANGUP) + closeReason =3D VIR_CONNECT_CLOSE_REASON_EOF; + else + closeReason =3D VIR_CONNECT_CLOSE_REASON_ERROR; + if (events & VIR_EVENT_HANDLE_WRITABLE) { if (virNetClientIOHandleOutput(client) < 0) - virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR); + virNetClientMarkClose(client, closeReason); } =20 if (events & VIR_EVENT_HANDLE_READABLE) { if (virNetClientIOHandleInput(client) < 0) - virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR); + virNetClientMarkClose(client, closeReason); } =20 if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR)) { VIR_DEBUG("VIR_EVENT_HANDLE_HANGUP or " "VIR_EVENT_HANDLE_ERROR encountered"); - virNetClientMarkClose(client, - (events & VIR_EVENT_HANDLE_HANGUP) ? - VIR_CONNECT_CLOSE_REASON_EOF : - VIR_CONNECT_CLOSE_REASON_ERROR); + virNetClientMarkClose(client, closeReason); goto done; } =20 --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list