From nobody Sun Apr 28 23:36:10 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 1537410237359854.6445810039636; Wed, 19 Sep 2018 19:23:57 -0700 (PDT) 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 C1CEC309174E; Thu, 20 Sep 2018 02:23:53 +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 B955285A26; Thu, 20 Sep 2018 02:23:51 +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 8F7FC181A12E; Thu, 20 Sep 2018 02:23:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K2Nk1D014541 for ; Wed, 19 Sep 2018 22:23:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 48FB3183C4; Thu, 20 Sep 2018 02:23:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E407183C3 for ; Thu, 20 Sep 2018 02:23:44 +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 4C36F2BEEE for ; Thu, 20 Sep 2018 02:23:42 +0000 (UTC) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id A476D2196261F034DFAA for ; Thu, 20 Sep 2018 10:23:40 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w8K2NV5x052140 for ; Thu, 20 Sep 2018 10:23:31 +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 2018092010234622-178722 ; Thu, 20 Sep 2018 10:23:46 +0800 From: Wang Yechao To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:27:57 +0800 Message-Id: <1537410477-2521-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-20 10:23:46, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-09-20 10:23:20, Serialize complete at 2018-09-20 10:23:20 X-MAIL: mse01.zte.com.cn w8K2NV5x052140 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.39]); Thu, 20 Sep 2018 02:23:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Sep 2018 02:23:43 +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.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Wang Yechao Subject: [libvirt] [PATCH v3] qemu: fix deadlock if create qemuProcessReconnect thread failed 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.41]); Thu, 20 Sep 2018 02:23:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qemuProcessReconnectHelper has hold lock on doms, if create qemuProcessReconnect thread failed, calls qemuDomainRemoveInactiveJob will lead to deadlock. Add a qemuDomainRemoveInactiveJobLocked, modify qemuProcessReconnectHelper to call it. Signed-off-by: Wang Yechao --- v2 patch: https://www.redhat.com/archives/libvir-list/2018-September/msg00635.html Changes in v3: - drop v2 patch, cause it is not good. - split qemuDomainRemoveInactive into qemuDomainRemoveInactiveCommon and virDomainObjListRemove. - create a qemuDomainRemoveInactiveLocked, consists of qemuDomainRemoveInactiveCommon and virDomainObjListRemoveLocked. - create a qemuDomainRemoveInactiveJobLocked, which copies qemuDomainRemoveInactiveJob except calling qemuDomainRemoveInactiveLocked - Modify qemuProcessReconnectHelper to call qemuDomainRemoveInactiveJobLoc= ked --- src/qemu/qemu_domain.c | 75 ++++++++++++++++++++++++++++++++++++++++-----= ---- src/qemu/qemu_domain.h | 9 ++++++ src/qemu/qemu_process.c | 2 +- 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2fd8a2a..ef0d91d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8343,24 +8343,13 @@ qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverP= tr driver, return rem.err; } =20 - -/** - * qemuDomainRemoveInactive: - * - * The caller must hold a lock to the vm. - */ void -qemuDomainRemoveInactive(virQEMUDriverPtr driver, - virDomainObjPtr vm) +qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driver, + virDomainObjPtr vm) { char *snapDir; virQEMUDriverConfigPtr cfg; =20 - if (vm->persistent) { - /* Short-circuit, we don't want to remove a persistent domain */ - return; - } - cfg =3D virQEMUDriverGetConfig(driver); =20 /* Remove any snapshot metadata prior to removing the domain */ @@ -8379,9 +8368,47 @@ qemuDomainRemoveInactive(virQEMUDriverPtr driver, } qemuExtDevicesCleanupHost(driver, vm->def); =20 + virObjectUnref(cfg); +} + +/** + * qemuDomainRemoveInactive: + * + * The caller must hold a lock to the vm. + */ +void +qemuDomainRemoveInactive(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + if (vm->persistent) { + /* Short-circuit, we don't want to remove a persistent domain */ + return; + } + + qemuDomainRemoveInactiveCommon(driver, vm); virDomainObjListRemove(driver->domains, vm); =20 - virObjectUnref(cfg); +} + +/** + * qemuDomainRemoveInactiveLocked: + * + * The caller must hold a lock to the vm , + * and hold a lock to the doms. + */ + +void +qemuDomainRemoveInactiveLocked(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + if (vm->persistent) { + /* Short-circuit, we don't want to remove a persistent domain */ + return; + } + + qemuDomainRemoveInactiveCommon(driver, vm); + virDomainObjListRemoveLocked(driver->domains, vm); + } =20 =20 @@ -8407,6 +8434,26 @@ qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver, qemuDomainObjEndJob(driver, vm); } =20 +/** + * qemuDomainRemoveInactiveJobLocked: + * + * Just like qemuDomainRemoveInactiveJob but it hold lock + * on 'doms'. + */ + +void +qemuDomainRemoveInactiveJobLocked(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + bool haveJob; + + haveJob =3D qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) >=3D 0; + + qemuDomainRemoveInactiveLocked(driver, vm); + + if (haveJob) + qemuDomainObjEndJob(driver, vm); +} =20 void qemuDomainSetFakeReboot(virQEMUDriverPtr driver, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 914c9a6..1d80621 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -698,12 +698,21 @@ int qemuDomainSnapshotDiscardAll(void *payload, int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver, virDomainObjPtr vm); =20 +void qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driver, + virDomainObjPtr vm); + void qemuDomainRemoveInactive(virQEMUDriverPtr driver, virDomainObjPtr vm); =20 +void qemuDomainRemoveInactiveLocked(virQEMUDriverPtr driver, + virDomainObjPtr vm); + void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver, virDomainObjPtr vm); =20 +void qemuDomainRemoveInactiveJobLocked(virQEMUDriverPtr driver, + virDomainObjPtr vm); + void qemuDomainSetFakeReboot(virQEMUDriverPtr driver, virDomainObjPtr vm, bool value); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 72a59de..ed24447 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8025,7 +8025,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj, */ qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, QEMU_ASYNC_JOB_NONE, 0); - qemuDomainRemoveInactiveJob(src->driver, obj); + qemuDomainRemoveInactiveJobLocked(src->driver, obj); =20 virDomainObjEndAPI(&obj); virNWFilterUnlockFilterUpdates(); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list