From nobody Sun Feb 8 06:05:28 2026 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 1528216999375872.8022324425962; Tue, 5 Jun 2018 09:43:19 -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 6D2023002317; Tue, 5 Jun 2018 16:43:17 +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 2BC358B331; Tue, 5 Jun 2018 16:43:17 +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 B19DF4CA80; Tue, 5 Jun 2018 16:43:16 +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 w55GgWLQ017764 for ; Tue, 5 Jun 2018 12:42:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A637100295D; Tue, 5 Jun 2018 16:42:32 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 333CF10F1C1D; Tue, 5 Jun 2018 16:42:31 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 5 Jun 2018 17:42:25 +0100 Message-Id: <20180605164225.7351-3-berrange@redhat.com> In-Reply-To: <20180605164225.7351-1-berrange@redhat.com> References: <20180605164225.7351-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 v2 2/2] nwfilter: directly use poll to wait for packets instead of pcap_next 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.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.43]); Tue, 05 Jun 2018 16:43:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 When a QEMU VM shuts down its TAP device gets deleted while nwfilter IP address learning thread is still capturing packets. It is seen that with TPACKET_V3 support in libcap, the pcap_next() call will not always exit its poll() when the NIC is removed. This prevents the learning thread from exiting which blocks the rest of libvirtd waiting on mutex acquisition. By switching to do poll() in libvirt code, we can ensure that we always exit the poll() at a time that is right for libvirt. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/nwfilter/nwfilter_learnipaddr.c | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 085af7892e..52adc37389 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -31,6 +31,7 @@ =20 #include #include +#include =20 #include #include @@ -414,6 +415,7 @@ learnIPAddressThread(void *arg) bool showError =3D true; enum howDetect howDetected =3D 0; virNWFilterTechDriverPtr techdriver =3D req->techdriver; + struct pollfd fds[1]; =20 if (virNWFilterLockIface(req->ifname) < 0) goto err_no_lock; @@ -435,6 +437,9 @@ learnIPAddressThread(void *arg) goto done; } =20 + fds[0].fd =3D pcap_fileno(handle); + fds[0].events =3D POLLIN | POLLERR; + virMacAddrFormat(&req->macaddr, macaddr); =20 if (req->howDetect =3D=3D DETECT_DHCP) { @@ -480,17 +485,45 @@ learnIPAddressThread(void *arg) pcap_freecode(&fp); =20 while (req->status =3D=3D 0 && vmaddr =3D=3D 0) { + int n =3D poll(fds, ARRAY_CARDINALITY(fds), PKT_TIMEOUT_MS); + + if (n < 0) { + if (errno =3D=3D EAGAIN || errno =3D=3D EINTR) + continue; + + req->status =3D errno; + showError =3D true; + break; + } + + if (n =3D=3D 0) { + if (threadsTerminate || req->terminate) { + VIR_DEBUG("Terminate request seen, cancelling pcap"); + req->status =3D ECANCELED; + showError =3D false; + break; + } + continue; + } + + if (fds[0].revents & (POLLHUP | POLLERR)) { + VIR_DEBUG("Error from FD probably dev deleted"); + req->status =3D ENODEV; + showError =3D false; + break; + } + packet =3D pcap_next(handle, &header); =20 if (!packet) { - + /* Already handled with poll, but lets be sure */ if (threadsTerminate || req->terminate) { req->status =3D ECANCELED; showError =3D false; break; } =20 - /* check whether VM's dev is still there */ + /* Again, already handled above, but lets be sure */ if (virNetDevValidateConfig(req->ifname, NULL, req->ifindex) <= =3D 0) { virResetLastError(); req->status =3D ENODEV; --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list