From nobody Sat May 4 17:27:48 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 1519398346489515.6718641935214; Fri, 23 Feb 2018 07:05:46 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8916C03DFE3; Fri, 23 Feb 2018 15:05:44 +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 88D105D979; Fri, 23 Feb 2018 15:05:43 +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 C4A1E4A46C; Fri, 23 Feb 2018 15:05:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1NF5eHE008399 for ; Fri, 23 Feb 2018 10:05:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7C3BDAB599; Fri, 23 Feb 2018 15:05:40 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-125.phx2.redhat.com [10.3.117.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09A5CAB598 for ; Fri, 23 Feb 2018 15:05:37 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Fri, 23 Feb 2018 10:05:29 -0500 Message-Id: <20180223150529.19204-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] nwfilter: save error from DHCP snoop thread to report in main thread 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 23 Feb 2018 15:05:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A problem encountered due to a bug in libpcap was reported to the caller as: An error occurred, but the cause is unknown This was because the error had been logged in the DHCPSnoop thread. The worker thread handling the API call to start a domain spins up the DHCPSnoop thread which watches for dhcp packets with libpcap, then uses virCondSignal() to notify the worker thread (which has been waiting with virCondWait()). The worker thread knows that there was an error (because threadStatus !=3D THREAD_STATUS_OK), but the error info had been stored in thread-specific storage for the other thread, so the worker thread can only report that there was a failure, but it doesn't know why. The solution is to save the error that was logged (with virErrorPreserveLast() into the object the is used to share info between the threads, then we can set the error in the worker thread using virErrorRestore(). In the case of the error I was looking at, this changed the "unknown" message into: internal error: pcap_setfilter: can't remove kernel filter: Bad file descriptor Signed-off-by: Laine Stump --- src/nwfilter/nwfilter_dhcpsnoop.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 8e955150fa..6069e70460 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -147,6 +147,7 @@ struct _virNWFilterSnoopReq { virNWFilterSnoopIPLeasePtr start; virNWFilterSnoopIPLeasePtr end; char *threadkey; + virErrorPtr threadError; =20 virNWFilterSnoopThreadStatus threadStatus; virCond threadStatusCond; @@ -639,6 +640,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req) =20 virMutexDestroy(&req->lock); virCondDestroy(&req->threadStatusCond); + virFreeError(req->threadError); =20 VIR_FREE(req); } @@ -1404,10 +1406,12 @@ virNWFilterDHCPSnoopThread(void *req0) =20 /* let creator know how well we initialized */ if (error || !threadkey || tmp < 0 || !worker || - ifindex !=3D req->ifindex) + ifindex !=3D req->ifindex) { + virErrorPreserveLast(&req->threadError); req->threadStatus =3D THREAD_STATUS_FAIL; - else + } else { req->threadStatus =3D THREAD_STATUS_OK; + } =20 virCondSignal(&req->threadStatusCond); =20 @@ -1713,9 +1717,16 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tec= hdriver, } =20 /* sync with thread */ - if (virCondWait(&req->threadStatusCond, &req->lock) < 0 || - req->threadStatus !=3D THREAD_STATUS_OK) + if (virCondWait(&req->threadStatusCond, &req->lock) < 0) { + virReportSystemError(errno, "%s", + _("unable to wait on dhcp snoop thread")); goto exit_snoop_cancel; + } + + if (req->threadStatus !=3D THREAD_STATUS_OK) { + virErrorRestore(&req->threadError); + goto exit_snoop_cancel; + } =20 virNWFilterSnoopReqUnlock(req); =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list