From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575504; cv=none; d=zohomail.com; s=zohoarc; b=VftT9g4dgLi8Mm6vwqBGz9N4L4m7k3OfToiOsohYJ3ERawTJnwUtNE3A0i56jVw5PyyChCR/BdMVQF4KYM+yIx+uwDJE/D5O7Wr1TPEWGuLa4YsbgnMq3FolVThIgF5j+l0wxVY5veIcxlzU3+Ovquc86GqHJ0VrmqpjKInbCTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575504; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I6AJ00v4xe7pZ7U+2EMaRrVrDuOSISx2swUnx8KFa20=; b=Fa8LzE0acJY/uYJ3ehxbMD0wYrQLkD5H8c6AEQN0Hcw+5RYb5CqRwU7ntWS5srxXI39+NZeEN+1TnpHabwwHxANO6iTynvI+P0dLdYJi/xEJeRzETmx+PxtsCnQzKRiiKxxdWtfp0waxOX+3LwlcQDc6muJh4fatHZ3HR/4pVvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644575504682399.3072267106071; Fri, 11 Feb 2022 02:31:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-357-ITuul1-NOpK_MWJpERZlRA-1; Fri, 11 Feb 2022 05:31:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4109B8B4534; Fri, 11 Feb 2022 10:30: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 113DC78DE0; Fri, 11 Feb 2022 10:30:53 +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 A7BA21809CB9; Fri, 11 Feb 2022 10:30:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUnxF031696 for ; Fri, 11 Feb 2022 05:30:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 499D97BB4A; Fri, 11 Feb 2022 10:30:49 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FA477D3D2; Fri, 11 Feb 2022 10:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575504; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=I6AJ00v4xe7pZ7U+2EMaRrVrDuOSISx2swUnx8KFa20=; b=DT/pL3+DOUTxkuuWss83Xwmue3mA8Uap+hEGszWvcmrKB6esCZQSFHwgStDgQyn+mAjGwX 0QFzN1WGJXNvxWoRKnKTGj6t833K9v9e2gCBVOazj9BMeCOAVwDud1LAvqZP+aEA9Gucyr NANU7eFb46ZHxv+kaJ9HGPg9HSc1NZw= X-MC-Unique: ITuul1-NOpK_MWJpERZlRA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 01/10] vz: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:37 +0100 Message-Id: <20220211103046.34651-2-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575521197100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/vz/vz_driver.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index be3e5e4b49..86bc53d631 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -169,11 +169,12 @@ vzGetDriverConnection(void) "%s", _("vz state driver is not active")); return NULL; } - virMutexLock(&vz_driver_lock); - if (!vz_driver) - vz_driver =3D vzDriverObjNew(); - virObjectRef(vz_driver); - virMutexUnlock(&vz_driver_lock); + + VIR_WITH_MUTEX_LOCK_GUARD(&vz_driver_lock) { + if (!vz_driver) + vz_driver =3D vzDriverObjNew(); + virObjectRef(vz_driver); + } =20 return vz_driver; } @@ -181,13 +182,13 @@ vzGetDriverConnection(void) void vzDestroyDriverConnection(void) { - struct _vzDriver *driver; - struct _vzConn *privconn_list; + struct _vzDriver *driver =3D NULL; + struct _vzConn *privconn_list =3D NULL; =20 - virMutexLock(&vz_driver_lock); - driver =3D g_steal_pointer(&vz_driver); - privconn_list =3D g_steal_pointer(&vz_conn_list); - virMutexUnlock(&vz_driver_lock); + VIR_WITH_MUTEX_LOCK_GUARD(&vz_driver_lock) { + driver =3D g_steal_pointer(&vz_driver); + privconn_list =3D g_steal_pointer(&vz_conn_list); + } =20 while (privconn_list) { struct _vzConn *privconn =3D privconn_list; @@ -382,10 +383,10 @@ vzConnectOpen(virConnectPtr conn, if (!(privconn->closeCallback =3D virNewConnectCloseCallbackData())) goto error; =20 - virMutexLock(&vz_driver_lock); - privconn->next =3D vz_conn_list; - vz_conn_list =3D privconn; - virMutexUnlock(&vz_driver_lock); + VIR_WITH_MUTEX_LOCK_GUARD(&vz_driver_lock) { + privconn->next =3D vz_conn_list; + vz_conn_list =3D privconn; + } =20 return VIR_DRV_OPEN_SUCCESS; =20 @@ -407,16 +408,15 @@ vzConnectClose(virConnectPtr conn) if (!privconn) return 0; =20 - virMutexLock(&vz_driver_lock); - for (curr =3D vz_conn_list; curr; prev =3D &curr->next, curr =3D curr-= >next) { - if (curr =3D=3D privconn) { - *prev =3D curr->next; - break; + VIR_WITH_MUTEX_LOCK_GUARD(&vz_driver_lock) { + for (curr =3D vz_conn_list; curr; prev =3D &curr->next, curr =3D c= urr->next) { + if (curr =3D=3D privconn) { + *prev =3D curr->next; + break; + } } } =20 - virMutexUnlock(&vz_driver_lock); - virObjectUnref(privconn->closeCallback); virObjectUnref(privconn->driver); VIR_FREE(privconn); --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575542; cv=none; d=zohomail.com; s=zohoarc; b=iGX+sB+ZDBMoK1tyxnqsh4zL3zi8Cg3RewBsXWeH5huLDw7wGXKuwu4vhes2BtEBxmHUo4Oio/eA3Fe7DIRmcYtsQrIrqJdfM9QBSnN6QMaG6pj+GyO8TF8VHgCqYahHWEvOzQDtzEidJXGley/6ZgHHWa1pwRnyW+qFxmDaISQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575542; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sJqsW4W12mPIDLkuKVZchfmrYDWtWxAJB2wnJt1LUYQ=; b=GPZw0IZnVJ+mbKhwIn2uKiWySyBQ1kTWvLSy26SxM97d4yMvpQHTitjJq8P/tnfSkiKCcb45cyQWRMRLwtTNeIrQrShAIaIVAY2/P9IlzD9qrL6PlSvh5lJ3ksxc5XWxTHWU0SSRx1F2lB5LRQurhKGciVyM0/PVGtMyDk/iMbs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644575542635941.5099755544494; Fri, 11 Feb 2022 02:32:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-203-tB4S9NHINNOwQo_rbOXkBQ-1; Fri, 11 Feb 2022 05:32:18 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 309DE10A2652; Fri, 11 Feb 2022 10:31:01 +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 0E0077C0DB; Fri, 11 Feb 2022 10:31:01 +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 D201D1809CBF; Fri, 11 Feb 2022 10:31:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUoFB031706 for ; Fri, 11 Feb 2022 05:30:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F7A77C0E8; Fri, 11 Feb 2022 10:30:50 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB11B7C0DC; Fri, 11 Feb 2022 10:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sJqsW4W12mPIDLkuKVZchfmrYDWtWxAJB2wnJt1LUYQ=; b=KXJkpBaO6KihQmZhPnn+j/E7sLMlOQnzTKi3kvX390JelS4O/FPWFAXc8tpMdd/2hrJ/xR B2P1Y+hEzNOyiW5XfDBTt5tzgeIjHifcHUSBtvxa4sQWrKSMwocYQ3RnC8too1/SLl780n GWTuGF1BjEqOV/54ZubwXphQHJL6J84= X-MC-Unique: tB4S9NHINNOwQo_rbOXkBQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 02/10] vmware: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:38 +0100 Message-Id: <20220211103046.34651-3-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575544751100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/vmware/vmware_driver.c | 100 ++++++++++++------------------------- 1 file changed, 31 insertions(+), 69 deletions(-) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 998ecdb546..da66f98db0 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -47,19 +47,6 @@ static const char * const vmrun_candidates[] =3D { #endif /* __APPLE__ */ }; =20 -static void -vmwareDriverLock(struct vmware_driver *driver) -{ - virMutexLock(&driver->lock); -} - -static void -vmwareDriverUnlock(struct vmware_driver *driver) -{ - virMutexUnlock(&driver->lock); -} - - static virDomainObj * vmwareDomObjFromDomainLocked(struct vmware_driver *driver, const unsigned char *uuid) @@ -83,12 +70,9 @@ static virDomainObj * vmwareDomObjFromDomain(struct vmware_driver *driver, const unsigned char *uuid) { - virDomainObj *vm; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 - vmwareDriverLock(driver); - vm =3D vmwareDomObjFromDomainLocked(driver, uuid); - vmwareDriverUnlock(driver); - return vm; + return vmwareDomObjFromDomainLocked(driver, uuid); } =20 =20 @@ -274,10 +258,9 @@ static int vmwareConnectGetVersion(virConnectPtr conn, unsigned long *version) { struct vmware_driver *driver =3D conn->privateData; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 - vmwareDriverLock(driver); *version =3D driver->version; - vmwareDriverUnlock(driver); return 0; } =20 @@ -395,6 +378,7 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int fla vmwareDomainPtr pDomain =3D NULL; virVMXContext ctx; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL); =20 @@ -406,7 +390,6 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int fla ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; =20 - vmwareDriverLock(driver); if ((vmdef =3D virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) =3D=3D NULL) goto cleanup; @@ -451,7 +434,6 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int fla VIR_FREE(vmxPath); if (vm) virObjectUnlock(vm); - vmwareDriverUnlock(driver); return dom; } =20 @@ -468,11 +450,10 @@ vmwareDomainShutdownFlags(virDomainPtr dom, struct vmware_driver *driver =3D dom->conn->privateData; virDomainObj *vm; int ret =3D -1; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 virCheckFlags(0, -1); =20 - vmwareDriverLock(driver); - if (!(vm =3D vmwareDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; =20 @@ -494,7 +475,6 @@ vmwareDomainShutdownFlags(virDomainPtr dom, ret =3D 0; cleanup: virDomainObjEndAPI(&vm); - vmwareDriverUnlock(driver); return ret; } =20 @@ -646,6 +626,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *x= ml, vmwareDomainPtr pDomain =3D NULL; virVMXContext ctx; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 virCheckFlags(VIR_DOMAIN_START_VALIDATE, NULL); =20 @@ -657,8 +638,6 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *x= ml, ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; =20 - vmwareDriverLock(driver); - if ((vmdef =3D virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) =3D=3D NULL) goto cleanup; @@ -704,7 +683,6 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *x= ml, VIR_FREE(vmx); VIR_FREE(vmxPath); virDomainObjEndAPI(&vm); - vmwareDriverUnlock(driver); return dom; } =20 @@ -715,10 +693,10 @@ vmwareDomainCreateWithFlags(virDomainPtr dom, struct vmware_driver *driver =3D dom->conn->privateData; virDomainObj *vm; int ret =3D -1; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 virCheckFlags(0, -1); =20 - vmwareDriverLock(driver); if (!(vm =3D vmwareDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; =20 @@ -735,7 +713,6 @@ vmwareDomainCreateWithFlags(virDomainPtr dom, =20 cleanup: virDomainObjEndAPI(&vm); - vmwareDriverUnlock(driver); return ret; } =20 @@ -752,10 +729,10 @@ vmwareDomainUndefineFlags(virDomainPtr dom, struct vmware_driver *driver =3D dom->conn->privateData; virDomainObj *vm; int ret =3D -1; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 virCheckFlags(0, -1); =20 - vmwareDriverLock(driver); if (!(vm =3D vmwareDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; =20 @@ -777,7 +754,6 @@ vmwareDomainUndefineFlags(virDomainPtr dom, =20 cleanup: virDomainObjEndAPI(&vm); - vmwareDriverUnlock(driver); return ret; } =20 @@ -791,12 +767,12 @@ static virDomainPtr vmwareDomainLookupByID(virConnectPtr conn, int id) { struct vmware_driver *driver =3D conn->privateData; - virDomainObj *vm; + virDomainObj *vm =3D NULL; virDomainPtr dom =3D NULL; =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByID(driver->domains, id); - vmwareDriverUnlock(driver); + VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { + vm =3D virDomainObjListFindByID(driver->domains, id); + } =20 if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, @@ -848,12 +824,12 @@ static virDomainPtr vmwareDomainLookupByName(virConnectPtr conn, const char *name) { struct vmware_driver *driver =3D conn->privateData; - virDomainObj *vm; + virDomainObj *vm =3D NULL; virDomainPtr dom =3D NULL; =20 - vmwareDriverLock(driver); - vm =3D virDomainObjListFindByName(driver->domains, name); - vmwareDriverUnlock(driver); + VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { + vm =3D virDomainObjListFindByName(driver->domains, name); + } =20 if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, @@ -972,28 +948,20 @@ static int vmwareConnectNumOfDefinedDomains(virConnectPtr conn) { struct vmware_driver *driver =3D conn->privateData; - int n; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 - vmwareDriverLock(driver); vmwareDomainObjListUpdateAll(driver->domains, driver); - n =3D virDomainObjListNumOfDomains(driver->domains, false, NULL, NULL); - vmwareDriverUnlock(driver); - - return n; + return virDomainObjListNumOfDomains(driver->domains, false, NULL, NULL= ); } =20 static int vmwareConnectNumOfDomains(virConnectPtr conn) { struct vmware_driver *driver =3D conn->privateData; - int n; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 - vmwareDriverLock(driver); vmwareDomainObjListUpdateAll(driver->domains, driver); - n =3D virDomainObjListNumOfDomains(driver->domains, true, NULL, NULL); - vmwareDriverUnlock(driver); - - return n; + return virDomainObjListNumOfDomains(driver->domains, true, NULL, NULL); } =20 =20 @@ -1001,14 +969,10 @@ static int vmwareConnectListDomains(virConnectPtr conn, int *ids, int nids) { struct vmware_driver *driver =3D conn->privateData; - int n; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 - vmwareDriverLock(driver); vmwareDomainObjListUpdateAll(driver->domains, driver); - n =3D virDomainObjListGetActiveIDs(driver->domains, ids, nids, NULL, N= ULL); - vmwareDriverUnlock(driver); - - return n; + return virDomainObjListGetActiveIDs(driver->domains, ids, nids, NULL, = NULL); } =20 static int @@ -1016,14 +980,11 @@ vmwareConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames) { struct vmware_driver *driver =3D conn->privateData; - int n; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); =20 - vmwareDriverLock(driver); vmwareDomainObjListUpdateAll(driver->domains, driver); - n =3D virDomainObjListGetInactiveNames(driver->domains, names, nnames, - NULL, NULL); - vmwareDriverUnlock(driver); - return n; + return virDomainObjListGetInactiveNames(driver->domains, names, nnames, + NULL, NULL); } =20 static int @@ -1093,11 +1054,12 @@ vmwareConnectListAllDomains(virConnectPtr conn, =20 virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1); =20 - vmwareDriverLock(driver); - vmwareDomainObjListUpdateAll(driver->domains, driver); - ret =3D virDomainObjListExport(driver->domains, conn, domains, - NULL, flags); - vmwareDriverUnlock(driver); + VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { + vmwareDomainObjListUpdateAll(driver->domains, driver); + ret =3D virDomainObjListExport(driver->domains, conn, domains, + NULL, flags); + } + return ret; } =20 --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575539; cv=none; d=zohomail.com; s=zohoarc; b=IQlz68jobkOr/XfwKuvAhQuAc8aPCdSvrnGX4HTpu7Ubo8O0L1ofd19vHH8SnnRuDyUaCW9e43XPte5LTC2EFjlcHwUVJvhmq5yBhfbsd6qwRfEFbo+wOVObzbriQbywAZGmSngPHJLzPHWVnnFYJfIeclyXbL+3lVFphZzO3hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575539; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Asp6kNCoxIfQlmGLK5P2I9yJGCpGArw9g5G03FXvXg4=; b=D99YRsPM0F0vuGh7ggsR84hvsOpixw49FUJcYTJ4WaQbUpEBCLqpV8YxXbwOQzetVcLpJgmSwYY4k81sfrdHnWiLGXNVkmcxbcSjdIf+oGhj5KiZmWm+ChZ9O96COolxegvalii3ubYvklL0J0HubS1ffiqlXR6dPo2Ua5/pchM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 164457553978538.13987766744253; Fri, 11 Feb 2022 02:32:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-185-wehZ_LzONw6fXMqUVPe-dw-1; Fri, 11 Feb 2022 05:32:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C80A28ED51; Fri, 11 Feb 2022 10:31:00 +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 812F06C1A6; Fri, 11 Feb 2022 10:31:00 +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 4C0194BB7C; Fri, 11 Feb 2022 10:31:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUpoA031719 for ; Fri, 11 Feb 2022 05:30:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDB957C0DA; Fri, 11 Feb 2022 10:30:51 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5A1E7BB4A; Fri, 11 Feb 2022 10:30:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575538; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Asp6kNCoxIfQlmGLK5P2I9yJGCpGArw9g5G03FXvXg4=; b=W/6xXeO/mZ7tLExvJPiqbjl40Arg78DYUb6YmXDq4GGEW46kRinDKxupp6sYglyIjKyTDs RT0DWKPJvJ3QvYugZkrfiBTxFsfxwaB0Twq2c9PDnSUd9kbEcuL+aSQsa8bXLxw6+Owmu2 /+HbzJxjVcAMA2Pc3y2qpAmXjtdUVIo= X-MC-Unique: wehZ_LzONw6fXMqUVPe-dw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 03/10] secret: Factor out mutex Date: Fri, 11 Feb 2022 11:30:39 +0100 Message-Id: <20220211103046.34651-4-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575540339100001 Content-Type: text/plain; charset="utf-8" If the mutex is part of the `driver` object, it cannot guard that object's creation and destruction perfectly. Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/secret/secret_driver.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 0220f394ef..d0e819809b 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -52,9 +52,10 @@ enum { SECRET_MAX_XML_FILE =3D 10*1024*1024 }; =20 /* Internal driver state */ =20 +static virMutex mutex =3D VIR_MUTEX_INITIALIZER; + typedef struct _virSecretDriverState virSecretDriverState; struct _virSecretDriverState { - virMutex lock; bool privileged; /* readonly */ char *embeddedRoot; /* readonly */ int embeddedRefs; @@ -74,14 +75,14 @@ static virSecretDriverState *driver; static void secretDriverLock(void) { - virMutexLock(&driver->lock); + virMutexLock(&mutex); } =20 =20 static void secretDriverUnlock(void) { - virMutexUnlock(&driver->lock); + virMutexUnlock(&mutex); } =20 =20 @@ -463,7 +464,6 @@ secretStateCleanup(void) =20 VIR_FREE(driver->stateDir); secretDriverUnlock(); - virMutexDestroy(&driver->lock); VIR_FREE(driver); =20 return 0; @@ -479,10 +479,6 @@ secretStateInitialize(bool privileged, driver =3D g_new0(virSecretDriverState, 1); =20 driver->lockFD =3D -1; - if (virMutexInit(&driver->lock) < 0) { - VIR_FREE(driver); - return VIR_DRV_STATE_INIT_ERROR; - } secretDriverLock(); =20 driver->secretEventState =3D virObjectEventStateNew(); --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575542; cv=none; d=zohomail.com; s=zohoarc; b=Epc55fqiP9bF05ccr2GJCXIEDi97rWI6lQz1J6Xie+TftkuvSWcX1pm/ZuDCiEseiPgHOQMdbIqtKnEnE/trJmb28jU8DS9cQc+7kRG8WOA9LwCZdbukMPFkHHrABISU04V4p/MloMqIRpWlWgK8RXCRUGC2TBqTMPiVrybAEZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575542; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vWy4lCBgjkOOWZxbCvcpFngLgKKoEKIjgETfylbDAWU=; b=Yi9BdXFhbhjyuApk+C8xEn2XNCkCDI1zpW2E9yL/b+s80fljoVHn5czBaYoxbKRYzD065+9UQzYeoeacj0f3KlCMCxj+1UGCm1s/2rP2XbK4DfiXzaA3DQS4y2GiwDup+XkNKIv+XJk/kQzTnEkGjxhMHVRRtbP62U/SMf8Ksn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644575542802413.2223839368388; Fri, 11 Feb 2022 02:32:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-540-P_EgDZOSM7CFpob0hdvlfQ-1; Fri, 11 Feb 2022 05:32:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 861A01B2C9BC; Fri, 11 Feb 2022 10:31:04 +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 E64066D03B; Fri, 11 Feb 2022 10:31:03 +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 775611809CBA; Fri, 11 Feb 2022 10:31:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUrIl031727 for ; Fri, 11 Feb 2022 05:30:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 056037C0DC; Fri, 11 Feb 2022 10:30:53 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2437A7C0D0; Fri, 11 Feb 2022 10:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575541; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vWy4lCBgjkOOWZxbCvcpFngLgKKoEKIjgETfylbDAWU=; b=c+pDswOdyLKM+pDRizwgDZSsZ1QLgBUzjF484RoQ32n5oiF6C6ewMxhm0hvb9pCH4Xg6RS QKmF65ibhe9tY64yOxikKUELP45c+U0xQEdoLagtHTpVJJgNcvb+E/Nz3pou+JhosBqo7s dQtKQ6qqDZleqZdGnR3bouWaECGQfwI= X-MC-Unique: P_EgDZOSM7CFpob0hdvlfQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 04/10] secret: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:40 +0100 Message-Id: <20220211103046.34651-5-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575545024100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/secret/secret_driver.c | 54 +++++++++++++++----------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index d0e819809b..09782b38d3 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -72,20 +72,6 @@ struct _virSecretDriverState { =20 static virSecretDriverState *driver; =20 -static void -secretDriverLock(void) -{ - virMutexLock(&mutex); -} - - -static void -secretDriverUnlock(void) -{ - virMutexUnlock(&mutex); -} - - static virSecretObj * secretObjFromSecret(virSecretPtr secret) { @@ -447,13 +433,11 @@ secretUndefine(virSecretPtr secret) =20 =20 static int -secretStateCleanup(void) +secretStateCleanupLocked(void) { if (!driver) return -1; =20 - secretDriverLock(); - virObjectUnref(driver->secrets); VIR_FREE(driver->configDir); =20 @@ -463,12 +447,19 @@ secretStateCleanup(void) virPidFileRelease(driver->stateDir, "driver", driver->lockFD); =20 VIR_FREE(driver->stateDir); - secretDriverUnlock(); VIR_FREE(driver); =20 return 0; } =20 +static int +secretStateCleanup(void) +{ + VIR_LOCK_GUARD lock =3D virLockGuardLock(&mutex); + + return secretStateCleanupLocked(); +} + =20 static int secretStateInitialize(bool privileged, @@ -476,11 +467,11 @@ secretStateInitialize(bool privileged, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&mutex); + driver =3D g_new0(virSecretDriverState, 1); =20 driver->lockFD =3D -1; - secretDriverLock(); - driver->secretEventState =3D virObjectEventStateNew(); driver->privileged =3D privileged; =20 @@ -524,12 +515,10 @@ secretStateInitialize(bool privileged, if (virSecretLoadAllConfigs(driver->secrets, driver->configDir) < 0) goto error; =20 - secretDriverUnlock(); return VIR_DRV_STATE_INIT_COMPLETE; =20 error: - secretDriverUnlock(); - secretStateCleanup(); + secretStateCleanupLocked(); return VIR_DRV_STATE_INIT_ERROR; } =20 @@ -537,14 +526,13 @@ secretStateInitialize(bool privileged, static int secretStateReload(void) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&mutex); + if (!driver) return -1; =20 - secretDriverLock(); - ignore_value(virSecretLoadAllConfigs(driver->secrets, driver->configDi= r)); =20 - secretDriverUnlock(); return 0; } =20 @@ -592,11 +580,11 @@ secretConnectOpen(virConnectPtr conn, return VIR_DRV_OPEN_ERROR; =20 if (driver->embeddedRoot) { - secretDriverLock(); - if (driver->embeddedRefs =3D=3D 0) - virSetConnectSecret(conn); - driver->embeddedRefs++; - secretDriverUnlock(); + VIR_WITH_MUTEX_LOCK_GUARD(&mutex) { + if (driver->embeddedRefs =3D=3D 0) + virSetConnectSecret(conn); + driver->embeddedRefs++; + } } =20 return VIR_DRV_OPEN_SUCCESS; @@ -604,12 +592,12 @@ secretConnectOpen(virConnectPtr conn, =20 static int secretConnectClose(virConnectPtr conn G_GNUC_UNUSED) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&mutex); + if (driver->embeddedRoot) { - secretDriverLock(); driver->embeddedRefs--; if (driver->embeddedRefs =3D=3D 0) virSetConnectSecret(NULL); - secretDriverUnlock(); } return 0; } --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575562; cv=none; d=zohomail.com; s=zohoarc; b=Bce+RZ6f/8fP/YtkhyORRyOkkXMd6vFtNda92t3dWItSMivOi2ZEVXcHqVjzen/MHDvcz1WqztSOR+BGi5Gs+Mq073fZtCWOiTbfauItdiB9QVQS0EtKShRcr/oeUnbj0XZMCMDnov0CCLFw7BbIJh1Ii+e66CZVwWCGrZoBydo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575562; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4AjVgzm7/OPi0VaWj9DwI1sC+87pgkDaWq6iCM7LPFE=; b=PkkGwLFb0T/FIM4a6kHgqqqFgxLv2DkywYz7j+CWJVd532JCw3wmesWT202MJowhqvf56KKsps32ndDq7Wc8gDAtHI8wZ8PdzE/3bpHnN0Ib7g8eOC1G47c9ojfUZE/KAfzBaemC6Kywxu3I6d+5hNJakr6oU4njMMhCOu95UQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644575562507912.5225240952713; Fri, 11 Feb 2022 02:32:42 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-VzzZ1_IVPkGY-y9ElOZy4A-1; Fri, 11 Feb 2022 05:32:38 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 881BE10B3E90; Fri, 11 Feb 2022 10:31:07 +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 044887DE42; Fri, 11 Feb 2022 10:31:06 +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 5C25C180BADA; Fri, 11 Feb 2022 10:31:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUskb031736 for ; Fri, 11 Feb 2022 05:30:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D4D47C0F8; Fri, 11 Feb 2022 10:30:54 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 509CC7DE2F; Fri, 11 Feb 2022 10:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575561; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4AjVgzm7/OPi0VaWj9DwI1sC+87pgkDaWq6iCM7LPFE=; b=MFXzTh3CnZnRL3lOjcZ0UoIaMnEtWwZxB57+Gjq5xdUpn2EAOwsIx+WcrjRGGsGJnfWIpz Z/5CH5DPhGuB3Ux4iMxbwaK3aOjQuO9qqsjjocIQXyJndnjUYVZcYMzjum8mJIMbBEI4x+ HJhr7hu7GEZHUCo+z/PMDCv0QjmNT1M= X-MC-Unique: VzzZ1_IVPkGY-y9ElOZy4A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 05/10] virlockspace: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:41 +0100 Message-Id: <20220211103046.34651-6-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575563753100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/util/virlockspace.c | 106 +++++++++++++--------------------------- 1 file changed, 33 insertions(+), 73 deletions(-) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index a7f1c2324f..79925053bf 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -414,12 +414,11 @@ virJSONValue *virLockSpacePreExecRestart(virLockSpace= *lockspace) g_autoptr(virJSONValue) resources =3D virJSONValueNewArray(); g_autofree virHashKeyValuePair *pairs =3D NULL; virHashKeyValuePair *tmp; - - virMutexLock(&lockspace->lock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&lockspace->lock); =20 if (lockspace->dir && virJSONValueObjectAppendString(object, "directory", lockspace->dir= ) < 0) - goto error; + return NULL; =20 =20 tmp =3D pairs =3D virHashGetItems(lockspace->resources, NULL, false); @@ -434,41 +433,36 @@ virJSONValue *virLockSpacePreExecRestart(virLockSpace= *lockspace) virJSONValueObjectAppendNumberInt(child, "fd", res->fd) < 0 || virJSONValueObjectAppendBoolean(child, "lockHeld", res->lockHe= ld) < 0 || virJSONValueObjectAppendNumberUint(child, "flags", res->flags)= < 0) - goto error; + return NULL; =20 if (virSetInherit(res->fd, true) < 0) { virReportSystemError(errno, "%s", _("Cannot disable close-on-exec flag")); - goto error; + return NULL; } =20 for (i =3D 0; i < res->nOwners; i++) { g_autoptr(virJSONValue) owner =3D virJSONValueNewNumberUlong(r= es->owners[i]); if (!owner) - goto error; + return NULL; =20 if (virJSONValueArrayAppend(owners, &owner) < 0) - goto error; + return NULL; } =20 if (virJSONValueObjectAppend(child, "owners", &owners) < 0) - goto error; + return NULL; =20 if (virJSONValueArrayAppend(resources, &child) < 0) - goto error; + return NULL; =20 tmp++; } =20 if (virJSONValueObjectAppend(object, "resources", &resources) < 0) - goto error; + return NULL; =20 - virMutexUnlock(&lockspace->lock); return g_steal_pointer(&object); - - error: - virMutexUnlock(&lockspace->lock); - return NULL; } =20 =20 @@ -493,67 +487,55 @@ const char *virLockSpaceGetDirectory(virLockSpace *lo= ckspace) int virLockSpaceCreateResource(virLockSpace *lockspace, const char *resname) { - int ret =3D -1; g_autofree char *respath =3D NULL; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&lockspace->lock); =20 VIR_DEBUG("lockspace=3D%p resname=3D%s", lockspace, resname); =20 - virMutexLock(&lockspace->lock); - if (virHashLookup(lockspace->resources, resname) !=3D NULL) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), resname); - goto cleanup; + return -1; } =20 if (!(respath =3D virLockSpaceGetResourcePath(lockspace, resname))) - goto cleanup; + return -1; =20 if (virFileTouch(respath, 0600) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - virMutexUnlock(&lockspace->lock); - return ret; + return 0; } =20 =20 int virLockSpaceDeleteResource(virLockSpace *lockspace, const char *resname) { - int ret =3D -1; g_autofree char *respath =3D NULL; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&lockspace->lock); =20 VIR_DEBUG("lockspace=3D%p resname=3D%s", lockspace, resname); =20 - virMutexLock(&lockspace->lock); - if (virHashLookup(lockspace->resources, resname) !=3D NULL) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), resname); - goto cleanup; + return -1; } =20 if (!(respath =3D virLockSpaceGetResourcePath(lockspace, resname))) - goto cleanup; + return -1; =20 if (unlink(respath) < 0 && errno !=3D ENOENT) { virReportSystemError(errno, _("Unable to delete lockspace resource %s"), respath); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virMutexUnlock(&lockspace->lock); - return ret; + return 0; } =20 =20 @@ -562,8 +544,8 @@ int virLockSpaceAcquireResource(virLockSpace *lockspace, pid_t owner, unsigned int flags) { - int ret =3D -1; virLockSpaceResource *res; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&lockspace->lock); =20 VIR_DEBUG("lockspace=3D%p resname=3D%s flags=3D0x%x owner=3D%lld", lockspace, resname, flags, (unsigned long long)owner); @@ -571,8 +553,6 @@ int virLockSpaceAcquireResource(virLockSpace *lockspace, virCheckFlags(VIR_LOCK_SPACE_ACQUIRE_SHARED | VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE, -1); =20 - virMutexLock(&lockspace->lock); - if ((res =3D virHashLookup(lockspace->resources, resname))) { if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) && (flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) { @@ -580,28 +560,23 @@ int virLockSpaceAcquireResource(virLockSpace *lockspa= ce, VIR_EXPAND_N(res->owners, res->nOwners, 1); res->owners[res->nOwners-1] =3D owner; =20 - goto done; + return 0; } virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), resname); - goto cleanup; + return -1; } =20 if (!(res =3D virLockSpaceResourceNew(lockspace, resname, flags, owner= ))) - goto cleanup; + return -1; =20 if (virHashAddEntry(lockspace->resources, resname, res) < 0) { virLockSpaceResourceFree(res); - goto cleanup; + return -1; } =20 - done: - ret =3D 0; - - cleanup: - virMutexUnlock(&lockspace->lock); - return ret; + return 0; } =20 =20 @@ -609,20 +584,18 @@ int virLockSpaceReleaseResource(virLockSpace *lockspa= ce, const char *resname, pid_t owner) { - int ret =3D -1; virLockSpaceResource *res; size_t i; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&lockspace->lock); =20 VIR_DEBUG("lockspace=3D%p resname=3D%s owner=3D%lld", lockspace, resname, (unsigned long long)owner); =20 - virMutexLock(&lockspace->lock); - if (!(res =3D virHashLookup(lockspace->resources, resname))) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is not locked"), resname); - goto cleanup; + return -1; } =20 for (i =3D 0; i < res->nOwners; i++) { @@ -634,20 +607,16 @@ int virLockSpaceReleaseResource(virLockSpace *lockspa= ce, virReportError(VIR_ERR_INTERNAL_ERROR, _("owner %lld does not hold the resource lock"), (unsigned long long)owner); - goto cleanup; + return -1; } =20 VIR_DELETE_ELEMENT(res->owners, i, res->nOwners); =20 if ((res->nOwners =3D=3D 0) && virHashRemoveEntry(lockspace->resources, resname) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virMutexUnlock(&lockspace->lock); - return ret; + return 0; } =20 =20 @@ -693,26 +662,17 @@ virLockSpaceRemoveResourcesForOwner(const void *paylo= ad, int virLockSpaceReleaseResourcesForOwner(virLockSpace *lockspace, pid_t owner) { - int ret =3D 0; struct virLockSpaceRemoveData data =3D { owner, 0 }; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&lockspace->lock); =20 VIR_DEBUG("lockspace=3D%p owner=3D%lld", lockspace, (unsigned long lon= g)owner); =20 - virMutexLock(&lockspace->lock); - if (virHashRemoveSet(lockspace->resources, virLockSpaceRemoveResourcesForOwner, &data) < 0) - goto error; + return -1; =20 - ret =3D data.count; - - virMutexUnlock(&lockspace->lock); - return ret; - - error: - virMutexUnlock(&lockspace->lock); - return -1; + return data.count; } --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575552; cv=none; d=zohomail.com; s=zohoarc; b=nehEZK/q3y2i+LQc7zxOp+fCSWyfF/Qf67gn0lqgMR6J/ka5ZwftTcNaArFpwIxGR331mWX037pxVYUSegQSEOytImIgByKvWi85WtdcdzGOQAYcPsxm0imiwJfNOvqURN8l6uIAhuUGOk7V5BP6RZaYRrOiAjlKXYUOtpt4eJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575552; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/Ehpt4AXKIrf8rjSOnb5OR9kmmMOCl1JZaPJWEGr08Y=; b=LIy+4/4B9QTCUICn2zphZXb/n6YJ829iiR/4U8PbiVY/OpdC1rhzKmX++blsuCV9HWMslMBwXIaQcPNRtiAbAVg+IK7JwdZ6UlzFjawnyCpluP19tNy8ik6w7LUhzDS5CB2ZEAPGWeGDaeoO5OVFBpuTEndUJDe01WnSEOQhn3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644575552124202.55340049474762; Fri, 11 Feb 2022 02:32:32 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-9O74w8WqPGKR0Ai_pu6MFA-1; Fri, 11 Feb 2022 05:32:27 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B0FF8C4FA4; Fri, 11 Feb 2022 10:31:12 +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 0AE367C0D1; Fri, 11 Feb 2022 10:31:12 +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 C67124BB7C; Fri, 11 Feb 2022 10:31:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUtnC031747 for ; Fri, 11 Feb 2022 05:30:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4E5117D3CE; Fri, 11 Feb 2022 10:30:55 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 898D07C0D0; Fri, 11 Feb 2022 10:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575551; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/Ehpt4AXKIrf8rjSOnb5OR9kmmMOCl1JZaPJWEGr08Y=; b=SX6oEw92YRXvtVfr70yRuNegN4dwwi/PU9rYLHP/+MVNVaV0+OTqGo0TM3nqzwDAm7bLmn cEJRWyQFZAjVSEikWiAG0DqMEC2sBz0xDB7stixc9Ajd+9lOVwENgmTIbNsZrs9hfaPkLm FZKT30f9KggamtAM/RTw+dMpgk139gU= X-MC-Unique: 9O74w8WqPGKR0Ai_pu6MFA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 06/10] virtpm: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:42 +0100 Message-Id: <20220211103046.34651-7-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575554256100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/util/virtpm.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/util/virtpm.c b/src/util/virtpm.c index c02b42f948..ca7506d82e 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -137,18 +137,12 @@ static int virTPMEmulatorInit(bool quiet); static char * virTPMBinaryGetPath(virTPMBinary binary) { - char *s =3D NULL; - - virMutexLock(&swtpm_tools_lock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&swtpm_tools_lock); =20 if (virTPMEmulatorInit(false) < 0) - goto cleanup; - - s =3D g_strdup(swtpmBinaries[binary].path); + return NULL; =20 - cleanup: - virMutexUnlock(&swtpm_tools_lock); - return s; + return g_strdup(swtpmBinaries[binary].path); } =20 char * @@ -171,20 +165,14 @@ virTPMGetSwtpmIoctl(void) =20 bool virTPMHasSwtpm(void) { - bool ret =3D false; - - virMutexLock(&swtpm_tools_lock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&swtpm_tools_lock); =20 if (virTPMEmulatorInit(true) < 0) - goto cleanup; + return false; =20 - ret =3D swtpmBinaries[VIR_TPM_BINARY_SWTPM].path !=3D NULL && + return swtpmBinaries[VIR_TPM_BINARY_SWTPM].path !=3D NULL && swtpmBinaries[VIR_TPM_BINARY_SWTPM_SETUP].path !=3D NULL && swtpmBinaries[VIR_TPM_BINARY_SWTPM_IOCTL].path !=3D NULL; - - cleanup: - virMutexUnlock(&swtpm_tools_lock); - return ret; } =20 /* virTPMExecGetCaps @@ -341,12 +329,10 @@ static bool virTPMBinaryGetCaps(virTPMBinary binary, unsigned int cap) { - bool ret =3D false; - - virMutexLock(&swtpm_tools_lock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&swtpm_tools_lock); =20 if (virTPMEmulatorInit(false) < 0) - goto cleanup; + return false; =20 if (!swtpmBinaries[binary].caps && swtpmBinaries[binary].capsParse) { @@ -355,12 +341,11 @@ virTPMBinaryGetCaps(virTPMBinary binary, swtpmBinaries[binary].path, swtpmBinaries[binary].parm); } - if (swtpmBinaries[binary].caps) - ret =3D virBitmapIsBitSet(swtpmBinaries[binary].caps, cap); =20 - cleanup: - virMutexUnlock(&swtpm_tools_lock); - return ret; + if (!swtpmBinaries[binary].caps) + return false; + + return virBitmapIsBitSet(swtpmBinaries[binary].caps, cap); } =20 bool --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575677; cv=none; d=zohomail.com; s=zohoarc; b=Y1Sr69BSxTUYDyYZ/tBj42FQAFWMTFDeK2SL+iVF/YifNwS4rH1qkEF5guYTyj3Wt6yPGa7mQUsBVlcWwFKjMC0iuJp3IWA//kuEjsoJzHcaJcyuQVjDfqO0gHngcETenm5G5SxyxTB2TP3+gw09jxFi2Ie2AXJc2unAivb8RZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575677; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EQL+pmBtXaLzVsYqhQz9Scsnyc1MsJdC4s/0FGvm2bE=; b=loO4NdTKgBtJW47d04klPcdIvAxhzp4IJ2772HeYbStP56oKqQmFCaRALQb88MMlVFMZvQqzamjEFkdQgvftglrCk36PofhzIaCW6fktpwrUbymqpIf8FpR+kV1VI6XenJPg2ti9YM+/8hc6K3lO7+VLIizjyA/NPMpnGGi3K14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644575677461665.7558803434079; Fri, 11 Feb 2022 02:34:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-y3TUUykXO7-UfXYceizX2w-1; Fri, 11 Feb 2022 05:34:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D94418460F3; Fri, 11 Feb 2022 10:32:22 +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 B8595E728; Fri, 11 Feb 2022 10:32:21 +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 720331806D2B; Fri, 11 Feb 2022 10:32:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUuik031753 for ; Fri, 11 Feb 2022 05:30:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 75E937C0E7; Fri, 11 Feb 2022 10:30:56 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id A14017C0D1; Fri, 11 Feb 2022 10:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575676; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EQL+pmBtXaLzVsYqhQz9Scsnyc1MsJdC4s/0FGvm2bE=; b=JRGq454H+6dkwvS4+HZFiMBzCOnZwABDTzcSaNS3XaQcKbiix2VJK4EML1QXUxZFglEsra 8nukLgr7g1POg8EG/0bYQ1AEIsu8AOqMYVml0Pm/R4o5f+tgidOWj9kH33qhri8PyFC6R1 XDlfY01cjFIwpbAZIfVDt3V4n/nYwms= X-MC-Unique: y3TUUykXO7-UfXYceizX2w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 07/10] vbox: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:43 +0100 Message-Id: <20220211103046.34651-8-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575678093100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/vbox/vbox_common.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 40180b0dfd..36db6e06be 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -224,7 +224,7 @@ vboxSdkUninitialize(void) static struct _vboxDriver * vboxGetDriverConnection(void) { - virMutexLock(&vbox_driver_lock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&vbox_driver_lock); =20 if (vbox_driver) { virObjectRef(vbox_driver); @@ -234,9 +234,6 @@ vboxGetDriverConnection(void) if (!vbox_driver) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to create vbox driver object.")); - - virMutexUnlock(&vbox_driver_lock); - return NULL; } } @@ -248,26 +245,20 @@ vboxGetDriverConnection(void) virObjectUnref(vbox_driver); if (vboxDriverDisposed) vbox_driver =3D NULL; - - virMutexUnlock(&vbox_driver_lock); - return NULL; } =20 vbox_driver->connectionCount++; - - virMutexUnlock(&vbox_driver_lock); - return vbox_driver; } =20 static void vboxDestroyDriverConnection(void) { - virMutexLock(&vbox_driver_lock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&vbox_driver_lock); =20 if (!vbox_driver) - goto cleanup; + return; =20 vbox_driver->connectionCount--; =20 @@ -277,9 +268,6 @@ vboxDestroyDriverConnection(void) virObjectUnref(vbox_driver); if (vboxDriverDisposed) vbox_driver =3D NULL; - - cleanup: - virMutexUnlock(&vbox_driver_lock); } =20 static int openSessionForMachine(struct _vboxDriver *data, const unsigned = char *dom_uuid, --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575684; cv=none; d=zohomail.com; s=zohoarc; b=e4gpxXs+wEtz+gRa2lMn/BL1PiI2htZIM2HmANFbOaMgc8/Geh4mqEqtq1jrm5u9I2JhnRIO6LtSRBUP8W26nF/o6m39Tq+C3mUH8UsWEC70Xe2nQyFLTVgo9/Fnslpc/wzIESevPyUzzi8h9Lg92YNyHYrwe1Bh2pO/jmowNUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575684; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oiFHczw7irrxVHttysl1iQh/kZ8TyUFkhjgJXpU6CZU=; b=eyUUU7EGhOpkInLc5pAwEZ/pPMn+eaCOtwovLPUL82itBCuSKPeWnuhylOZY4CCbwHp4GAOuvVLSsvYXTT18T4ny5kiWcFLCAZSv9u0/3bh6XitY6GHgUE4ptmLJhzGEEGKokvPre2VlZM59XkHwHVdM+XXi9MSugm2XMCoO3Mg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644575684515701.4976713853737; Fri, 11 Feb 2022 02:34:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-388-AlI9kR08No2TaeMndiu_bw-1; Fri, 11 Feb 2022 05:34:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2CAB710A3597; Fri, 11 Feb 2022 10:32:26 +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 0DD7C6C1B8; Fri, 11 Feb 2022 10:32:26 +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 CF0C61806D2C; Fri, 11 Feb 2022 10:32:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUv4V031770 for ; Fri, 11 Feb 2022 05:30:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 983597C0E9; Fri, 11 Feb 2022 10:30:57 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC0D17C0D8; Fri, 11 Feb 2022 10:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575683; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oiFHczw7irrxVHttysl1iQh/kZ8TyUFkhjgJXpU6CZU=; b=MTu415Cv+lfeE1GUjdAnmkTI0UTNM8hmKLTqIxZfbZhYOcqtugZRbsFtUd7eBjOwF70N0L gUSWi9Bbjj/kUNYL8TV3Hc0MaN5Y1r7VR1WO7766c7qjkjFYfHPwdGO6CWXywgqd3XO2EH DW99bf8k756ZktgZheALy5FVloXVNxk= X-MC-Unique: AlI9kR08No2TaeMndiu_bw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 08/10] tools: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:44 +0100 Message-Id: <20220211103046.34651-9-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575686711100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/util/virfirewall.c | 13 ++++--------- tools/virsh.c | 12 ++++++------ tools/virt-admin.c | 12 ++++++------ tools/vsh.c | 8 ++++---- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index 70092f2ef6..31a8352d4e 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -613,9 +613,7 @@ int virFirewallApply(virFirewall *firewall) { size_t i, j; - int ret =3D -1; - - virMutexLock(&ruleLock); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&ruleLock); =20 if (!firewall || firewall->err) { int err =3D EINVAL; @@ -624,7 +622,7 @@ virFirewallApply(virFirewall *firewall) err =3D firewall->err; =20 virReportSystemError(err, "%s", _("Unable to create rule")); - goto cleanup; + return -1; } =20 VIR_DEBUG("Applying groups for %p", firewall); @@ -657,13 +655,10 @@ virFirewallApply(virFirewall *firewall) =20 virErrorRestore(&saved_error); VIR_DEBUG("Done rolling back groups for %p", firewall); - goto cleanup; + return -1; } } VIR_DEBUG("Done applying groups for %p", firewall); =20 - ret =3D 0; - cleanup: - virMutexUnlock(&ruleLock); - return ret; + return 0; } diff --git a/tools/virsh.c b/tools/virsh.c index 1c75a66fcb..64e0700fcd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -412,13 +412,13 @@ virshDeinit(vshControl *ctl) virResetLastError(); =20 if (ctl->eventLoopStarted) { - int timer; + int timer =3D -1; =20 - virMutexLock(&ctl->lock); - ctl->quit =3D true; - /* HACK: Add a dummy timeout to break event loop */ - timer =3D virEventAddTimeout(0, virshDeinitTimer, NULL, NULL); - virMutexUnlock(&ctl->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) { + ctl->quit =3D true; + /* HACK: Add a dummy timeout to break event loop */ + timer =3D virEventAddTimeout(0, virshDeinitTimer, NULL, NULL); + } =20 virThreadJoin(&ctl->eventLoop); =20 diff --git a/tools/virt-admin.c b/tools/virt-admin.c index c0818e850a..e010763e21 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1189,13 +1189,13 @@ vshAdmDeinit(vshControl *ctl) virResetLastError(); =20 if (ctl->eventLoopStarted) { - int timer; + int timer =3D -1; =20 - virMutexLock(&ctl->lock); - ctl->quit =3D true; - /* HACK: Add a dummy timeout to break event loop */ - timer =3D virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL); - virMutexUnlock(&ctl->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) { + ctl->quit =3D true; + /* HACK: Add a dummy timeout to break event loop */ + timer =3D virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL); + } =20 virThreadJoin(&ctl->eventLoop); =20 diff --git a/tools/vsh.c b/tools/vsh.c index 5056d7e19d..4ec5e54b5d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2018,10 +2018,10 @@ vshEventLoop(void *opaque) vshControl *ctl =3D opaque; =20 while (1) { - bool quit; - virMutexLock(&ctl->lock); - quit =3D ctl->quit; - virMutexUnlock(&ctl->lock); + bool quit =3D false; + VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) { + quit =3D ctl->quit; + } =20 if (quit) break; --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575580; cv=none; d=zohomail.com; s=zohoarc; b=OXZgdd4Ms3zZuDt+LU0s46SUUwV9kv/Hj9Jcm7EG4mdsrzlBpqmmfxPE0IWd6TKpZCD/qiCqM+ul7aLt6ucCBChfGYpNCpXFn2fudCBmgKClk2jDTh6ZWLCEzODNwRyqmcUgu4HkWQYMUxyvM687vGLQGUw+6Ie5EI4P6ubWMRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575580; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FciPPUgZoX04r+UKTM82Y3tqJQffG7M/ZA1XvuAQeew=; b=j6vBH/AHuYls9q/PdmkJqcncVThnGq0aSBWt+2c/hGDs7GrMcchHMhif5Hx3Skcm4u/kD+elRfNQfT8ENeO76n/HuPMSR5Tt//sActg1aeJHCNtJmsczKj/8eHHaTk/lDS7CH3OuLJlKznO3HEWjEAAux4b3ML7yR/GSSlqsI+0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644575580173351.49110213619736; Fri, 11 Feb 2022 02:33:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-178-OJV4mXi0O4aqJ0bVx10_YA-1; Fri, 11 Feb 2022 05:32:55 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F166294B203; Fri, 11 Feb 2022 10:31: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 B79EA7C141; Fri, 11 Feb 2022 10:31: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 74AD11806D1C; Fri, 11 Feb 2022 10:31:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUws1031777 for ; Fri, 11 Feb 2022 05:30:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id A65E17C0D6; Fri, 11 Feb 2022 10:30:58 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA0017BB4A; Fri, 11 Feb 2022 10:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575579; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FciPPUgZoX04r+UKTM82Y3tqJQffG7M/ZA1XvuAQeew=; b=PA2MyvKn/XUiN2GRBjISd1J4jvf6o8cbDv0BVSk9xA9gBrievTKrqsX/FIYk6AaPwg6ESl trmlT/XB6dFa6QsYP1Y4rnrkRCVd5QmhH/mW1dgO+yf3yeyrFsgtvyy94Y7rDJc6oBObFy /cuOgCO2mWukr/bPXcMiiSynTC9BNvU= X-MC-Unique: OJV4mXi0O4aqJ0bVx10_YA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 09/10] qemusecuritymock: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:45 +0100 Message-Id: <20220211103046.34651-10-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575581921100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- tests/qemusecuritymock.c | 88 +++++++++++++--------------------------- 1 file changed, 29 insertions(+), 59 deletions(-) diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 778b0561ac..03c818d8a3 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -137,27 +137,21 @@ virFileGetXAttrQuiet(const char *path, const char *name, char **value) { - int ret =3D -1; - g_autofree char *key =3D NULL; + g_autofree char *key =3D get_key(path, name); char *val; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 - key =3D get_key(path, name); - - virMutexLock(&m); init_syms(); init_hash(); =20 if (!(val =3D virHashLookup(xattr_paths, key))) { errno =3D ENODATA; - goto cleanup; + return -1; } =20 *value =3D g_strdup(val); =20 - ret =3D 0; - cleanup: - virMutexUnlock(&m); - return ret; + return 0; } =20 =20 @@ -193,25 +187,18 @@ int virFileSetXAttr(const char *path, const char *name, const char *value) { - int ret =3D -1; - g_autofree char *key =3D NULL; - g_autofree char *val =3D NULL; - - key =3D get_key(path, name); - val =3D g_strdup(value); + g_autofree char *key =3D get_key(path, name); + g_autofree char *val =3D g_strdup(value); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 - virMutexLock(&m); init_syms(); init_hash(); =20 if (virHashUpdateEntry(xattr_paths, key, val) < 0) - goto cleanup; + return -1; val =3D NULL; =20 - ret =3D 0; - cleanup: - virMutexUnlock(&m); - return ret; + return 0; } =20 =20 @@ -219,18 +206,15 @@ int virFileRemoveXAttr(const char *path, const char *name) { int ret =3D -1; - g_autofree char *key =3D NULL; - - key =3D get_key(path, name); + g_autofree char *key =3D get_key(path, name); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 - virMutexLock(&m); init_syms(); init_hash(); =20 if ((ret =3D virHashRemoveEntry(xattr_paths, key)) < 0) errno =3D ENODATA; =20 - virMutexUnlock(&m); return ret; } =20 @@ -270,8 +254,8 @@ mock_chown(const char *path, uid_t uid, gid_t gid) { - uint32_t *val =3D NULL; - int ret =3D -1; + g_autofree uint32_t *val =3D NULL; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 if (gid >> 16 || uid >> 16) { fprintf(stderr, "Attempt to set too high UID or GID: %llu %llu", @@ -283,18 +267,13 @@ mock_chown(const char *path, =20 *val =3D (gid << 16) + uid; =20 - virMutexLock(&m); init_hash(); =20 if (virHashUpdateEntry(chown_paths, path, val) < 0) - goto cleanup; - val =3D NULL; + return -1; =20 - ret =3D 0; - cleanup: - virMutexUnlock(&m); - VIR_FREE(val); - return ret; + val =3D NULL; + return 0; } =20 =20 @@ -460,13 +439,12 @@ printXATTR(void *payload, */ int checkPaths(GHashTable *paths) { - int ret =3D -1; checkOwnerData data =3D { .paths =3D paths, .chown_fail =3D false, .se= linux_fail =3D false }; bool xattr_fail =3D false; GHashTableIter htitr; void *key; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 - virMutexLock(&m); init_hash(); =20 g_hash_table_iter_init(&htitr, paths); @@ -474,38 +452,35 @@ int checkPaths(GHashTable *paths) while (g_hash_table_iter_next(&htitr, &key, NULL)) { if (!virHashLookup(chown_paths, key)) { fprintf(stderr, "Unexpected path restored: %s\n", (const char = *) key); - goto cleanup; + return -1; } } =20 if (virHashForEach(selinux_paths, checkSELinux, &data) < 0) - goto cleanup; + return -1; =20 if (virHashForEach(chown_paths, checkOwner, &data) < 0) - goto cleanup; + return -1; =20 if (virHashForEach(xattr_paths, printXATTR, &xattr_fail) < 0) - goto cleanup; + return -1; =20 if (data.chown_fail || data.selinux_fail || xattr_fail) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virMutexUnlock(&m); - return ret; + return 0; } =20 =20 void freePaths(void) { - virMutexLock(&m); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); + init_hash(); =20 g_clear_pointer(&selinux_paths, g_hash_table_unref); g_clear_pointer(&chown_paths, g_hash_table_unref); g_clear_pointer(&xattr_paths, g_hash_table_unref); - virMutexUnlock(&m); } =20 =20 @@ -578,19 +553,15 @@ mock_setfilecon_raw(const char *path, const char *context) { g_autofree char *val =3D g_strdup(context); - int ret =3D -1; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 - virMutexLock(&m); init_hash(); =20 if (virHashUpdateEntry(selinux_paths, path, val) < 0) - goto cleanup; + return -1; val =3D NULL; =20 - ret =3D 0; - cleanup: - virMutexUnlock(&m); - return ret; + return 0; } =20 =20 @@ -599,8 +570,8 @@ mock_getfilecon_raw(const char *path, char **context) { const char *val; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&m); =20 - virMutexLock(&m); init_hash(); =20 val =3D virHashLookup(selinux_paths, path); @@ -608,7 +579,6 @@ mock_getfilecon_raw(const char *path, val =3D DEFAULT_SELINUX_LABEL; =20 *context =3D g_strdup(val); - virMutexUnlock(&m); return 0; } =20 --=20 2.31.1 From nobody Tue May 14 01:29:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644575573; cv=none; d=zohomail.com; s=zohoarc; b=J72ZmSKf8OyzzwQINwv6lSL592Zw5PCqTLGBMlJIz3fhBgikNLW12V0Z80wjhIPpmMC41WCyyK447IVOd0XlHn6lldYu4RXF5dhTSz5BgCaQ+uv9UCdkUduWJKIYRQMSjq2PvYPo0hbgTxGh1FmnQTUrak4m07uyX4FW1OUjzn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644575573; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=60ycLFSfR9aOaEBqo2VaPLOHZSPbhe0BZkXHVs8zvHE=; b=J7ukQu8M+F2QR6PFtmVpIQz1Q2mYWwgeW37AqNftVokdfD6xmFlwO7YDkRm2CS9m09nOZYWnPAWfCTqq3OfEeu96xrJegiJ+BIm2xPTM3X9LBgodfraU2H454p3BEWWur/bK1Dh2wYi2qOo94xl3GgRv5icpHGB+CFuWYUoAmZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644575573527225.63282050514385; Fri, 11 Feb 2022 02:32:53 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-346-WWIDxSitOv6ymk635_KPhg-1; Fri, 11 Feb 2022 05:32:47 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48ED2931EF0; Fri, 11 Feb 2022 10:31:18 +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 1E9A45452F; Fri, 11 Feb 2022 10:31:18 +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 D74D11806D2B; Fri, 11 Feb 2022 10:31:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BAUx22031797 for ; Fri, 11 Feb 2022 05:30:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id E70BA7C0D6; Fri, 11 Feb 2022 10:30:59 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08A707C0FA; Fri, 11 Feb 2022 10:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644575572; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=60ycLFSfR9aOaEBqo2VaPLOHZSPbhe0BZkXHVs8zvHE=; b=J3j8w0IC2D7Awg3ONXy4nyX+au4g1WGScZoI/CS0vPwUwLCK2jEmBBMfX42tFzKiiVzbn6 B8rrDau4vmHxnzc8l9NecCSk4Okpnr73cp4cOqTMAR/Wtnw0DuGzyEOXTdbTpLeazcTpe9 QeaAN9QivE5qOSoRWDhNzEAq6Hj1X+8= X-MC-Unique: WWIDxSitOv6ymk635_KPhg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 10/10] qemumonitortestutils: Use automatic mutex management Date: Fri, 11 Feb 2022 11:30:46 +0100 Message-Id: <20220211103046.34651-11-twiederh@redhat.com> In-Reply-To: <20220211103046.34651-1-twiederh@redhat.com> References: <20220211103046.34651-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644575574938100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- tests/qemumonitortestutils.c | 65 ++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index ce8e6e1645..86300da68a 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -253,12 +253,11 @@ qemuMonitorTestIO(virNetSocket *sock, { qemuMonitorTest *test =3D opaque; bool err =3D false; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&test->lock); =20 - virMutexLock(&test->lock); - if (test->quit) { - virMutexUnlock(&test->lock); + if (test->quit) return; - } + if (events & VIR_EVENT_HANDLE_WRITABLE) { ssize_t ret; if ((ret =3D virNetSocketWrite(sock, @@ -336,7 +335,6 @@ qemuMonitorTestIO(virNetSocket *sock, =20 virNetSocketUpdateIOCallback(sock, events); } - virMutexUnlock(&test->lock); } =20 =20 @@ -345,24 +343,22 @@ qemuMonitorTestWorker(void *opaque) { qemuMonitorTest *test =3D opaque; =20 - virMutexLock(&test->lock); - - while (!test->quit) { - virMutexUnlock(&test->lock); + while (true) { + VIR_WITH_MUTEX_LOCK_GUARD(&test->lock) { + if (test->quit) { + test->running =3D false; + return; + } + } =20 if (virEventRunDefaultImpl() < 0) { - virMutexLock(&test->lock); - test->quit =3D true; - break; + VIR_WITH_MUTEX_LOCK_GUARD(&test->lock) { + test->quit =3D true; + test->running =3D false; + return; + } } - - virMutexLock(&test->lock); } - - test->running =3D false; - - virMutexUnlock(&test->lock); - return; } =20 =20 @@ -383,13 +379,13 @@ qemuMonitorTestFree(qemuMonitorTest *test) if (!test) return; =20 - virMutexLock(&test->lock); - if (test->running) { - test->quit =3D true; - /* HACK: Add a dummy timeout to break event loop */ - timer =3D virEventAddTimeout(0, qemuMonitorTestFreeTimer, NULL, NU= LL); + VIR_WITH_MUTEX_LOCK_GUARD(&test->lock) { + if (test->running) { + test->quit =3D true; + /* HACK: Add a dummy timeout to break event loop */ + timer =3D virEventAddTimeout(0, qemuMonitorTestFreeTimer, NULL= , NULL); + } } - virMutexUnlock(&test->lock); =20 if (test->client) { virNetSocketRemoveIOCallback(test->client); @@ -463,9 +459,9 @@ qemuMonitorTestAddHandler(qemuMonitorTest *test, item->freecb =3D freecb; item->opaque =3D opaque; =20 - virMutexLock(&test->lock); - VIR_APPEND_ELEMENT(test->items, test->nitems, item); - virMutexUnlock(&test->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&test->lock) { + VIR_APPEND_ELEMENT(test->items, test->nitems, item); + } =20 return 0; } @@ -1072,16 +1068,11 @@ qemuMonitorCommonTestInit(qemuMonitorTest *test) NULL) < 0) return -1; =20 - virMutexLock(&test->lock); - if (virThreadCreate(&test->thread, - true, - qemuMonitorTestWorker, - test) < 0) { - virMutexUnlock(&test->lock); - return -1; + VIR_WITH_MUTEX_LOCK_GUARD(&test->lock) { + if (virThreadCreate(&test->thread, true, qemuMonitorTestWorker, te= st) < 0) + return -1; + test->started =3D test->running =3D true; } - test->started =3D test->running =3D true; - virMutexUnlock(&test->lock); =20 return 0; } --=20 2.31.1