From nobody Wed Nov 27 18:36:53 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 1536668536330471.95588899742313; Tue, 11 Sep 2018 05:22:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACE26307CF27; Tue, 11 Sep 2018 12:22:14 +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 650706013D; Tue, 11 Sep 2018 12:22:14 +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 E4DE6181A12F; Tue, 11 Sep 2018 12:22:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8B5uBIv018502 for ; Tue, 11 Sep 2018 01:56:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 754E858B6; Tue, 11 Sep 2018 05:56:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DD2619498 for ; Tue, 11 Sep 2018 05:56:09 +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 8378F308A959 for ; Tue, 11 Sep 2018 05:56:06 +0000 (UTC) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 7C4197BB6C3D607C3ECE for ; Tue, 11 Sep 2018 13:56:04 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w8B5u01Z017168 for ; Tue, 11 Sep 2018 13:56:00 +0800 (GMT-8) (envelope-from wang.yechao255@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018091113560451-8334548 ; Tue, 11 Sep 2018 13:56:04 +0800 From: Wang Yechao To: libvir-list@redhat.com Date: Tue, 11 Sep 2018 13:56:21 +0800 Message-Id: <1536645381-30570-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-11 13:56:04, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-09-11 13:55:56, Serialize complete at 2018-09-11 13:55:56 X-MAIL: mse01.zte.com.cn w8B5u01Z017168 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 11 Sep 2018 05:56:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 11 Sep 2018 05:56:07 +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.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Tue, 11 Sep 2018 08:21:41 -0400 Cc: wang.yi59@zte.com.cn, wang.yechao255@zte.com.cn Subject: [libvirt] [PATCH] nwfilter:fix deadlock when nwfilter reload 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 11 Sep 2018 12:22:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" user run "firewalld-cmd --reload" nwfilterStateReload called in main thread step 1. virRWLockWrite(&updateLock) step 2. virNWFilterLoadAllConfigs step 3. virRWLockUnlock(&updateLock); lauch a vm: qemuDomainCreateXML runs in other thread step 1. virRWLockRead(&updateLock); step 2. qemuProcessStart step 3. qemuProcessWaitForMonitor step 4. ... step 5 virRWLockUnlock(&updateLock); if nwfilterStateReload called in the middle of step 1 and step 5 of qemuDomainCreateXML, it can't get the updateLock and then block the event_l= oop, so event_loop can't handle the qemu-monitor messages, cause deadlock move nwfilterStateReload into thread to fix this problem. Signed-off-by: Wang Yechao Reviewed-by: Yi Wang --- src/nwfilter/nwfilter_driver.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) mode change 100644 =3D> 100755 src/nwfilter/nwfilter_driver.c diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c old mode 100644 new mode 100755 index ac3a964..2c099e2 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -81,17 +81,28 @@ static void nwfilterDriverUnlock(void) =20 #if HAVE_FIREWALLD =20 +static void nwfilterThread(void *opaque ATTRIBUTE_UNUSED) +{ + nwfilterStateReload(); +} + static DBusHandlerResult nwfilterFirewalldDBusFilter(DBusConnection *connection ATTRIBUTE_UNUSED, DBusMessage *message, void *user_data ATTRIBUTE_UNUSED) { + virThread thread; + if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged") || dbus_message_is_signal(message, "org.fedoraproject.FirewallD1", "Reloaded")) { VIR_DEBUG("Reload in nwfilter_driver because of firewalld."); - nwfilterStateReload(); + + /* create thread handle the nwfilter reload, don't block the event= _loop.*/ + if (virThreadCreate(&thread, false, nwfilterThread, NULL) < 0) { + VIR_ERROR("create nwfilterThread failed."); + } } =20 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list