From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538250427311.9451388442643; Fri, 19 Apr 2024 07:50:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 262501E32; Fri, 19 Apr 2024 10:50:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D38C01D75; Fri, 19 Apr 2024 10:49:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F2FCA1D6A; Fri, 19 Apr 2024 10:49:51 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0CD8E1A22 for ; Fri, 19 Apr 2024 10:49:51 -0400 (EDT) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEWqcc008021 for ; Fri, 19 Apr 2024 14:49:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfc81d5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:50 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnndV003190 for ; Fri, 19 Apr 2024 14:49:49 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfc81d3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:49 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCRuV6020837; Fri, 19 Apr 2024 14:49:49 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6uc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnhNe43778334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:45 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9DC0F2004D; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F28620040; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 01/20] nodedev: fix mdev add udev event data handling Date: Fri, 19 Apr 2024 16:49:20 +0200 Message-ID: <20240419144939.107773-2-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4t_Oa5XRkddKn4L9_zwYDBukTAODtCWN X-Proofpoint-ORIG-GUID: snmod9WykS5MWzuVrckRBt0MMFrQLJ2n X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: R3R7MPMJWRSZVGRIGQTJMILKTMDZKB73 X-Message-ID-Hash: R3R7MPMJWRSZVGRIGQTJMILKTMDZKB73 X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538251744100001 From: Boris Fiuczynski Two situations will trigger an udev add event: 1) the mdev is created when started (transient) or 2) the mdev was defined and is started In case 1 there is no node object existing and no config data is copied. In case 2 copying the active config data of an existing node object will only copy invalid data. Instead copying the defined config data will store valid data into the newly added node object. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma Reviewed-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index f1e402f8f7f6..4730a5b986ca 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1572,7 +1572,7 @@ udevAddOneDevice(struct udev_device *device) objdef =3D virNodeDeviceObjGetDef(obj); =20 if (is_mdev) - nodeDeviceDefCopyFromMdevctl(def, objdef, false); + nodeDeviceDefCopyFromMdevctl(def, objdef, true); =20 persistent =3D virNodeDeviceObjIsPersistent(obj); autostart =3D virNodeDeviceObjIsAutostart(obj); --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538350194102.24315791237734; Fri, 19 Apr 2024 07:52:30 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 047091E4B; Fri, 19 Apr 2024 10:52:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 180141E11; Fri, 19 Apr 2024 10:50:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B74B11C69; Fri, 19 Apr 2024 10:49:52 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CE1DC1D63 for ; Fri, 19 Apr 2024 10:49:51 -0400 (EDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEnpoa020959 for ; Fri, 19 Apr 2024 14:49:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:51 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnoiC020953 for ; Fri, 19 Apr 2024 14:49:50 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:50 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCCaeI021044; Fri, 19 Apr 2024 14:49:49 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6uf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEni1T53412122 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:46 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F239F2004F; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B40CC20040; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 02/20] node_device_udev: Set @def to NULL Date: Fri, 19 Apr 2024 16:49:21 +0200 Message-ID: <20240419144939.107773-3-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: sneNjxKlRRw51n0gFjqWbFzL21rOiHmN X-Proofpoint-GUID: or-TOp5OaQDKLQzDfTh6AeRG_242YjIO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190110 Message-ID-Hash: LHHSGYDPRJL23ZRHMZ42WSP4WDOCUJWJ X-Message-ID-Hash: LHHSGYDPRJL23ZRHMZ42WSP4WDOCUJWJ X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538352088100001 @def is owned by @obj after adding it the node device object list. As soon = as the @obj lock has been released, another thread could free @obj and therefo= re @def. If now someone accesses @def this would lead to a heap-use-after-free= and therefore most likely to a segmentation fault, therefore set @def to NULL a= fter the ownership has moved. While at it, add comments to other code places why @def is set to NULL. Reviewed-by: Boris Fiuczynski Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 4 ++++ src/test/test_driver.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 4730a5b986ca..6613528d0e37 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1588,6 +1588,8 @@ udevAddOneDevice(struct udev_device *device) * and the current definition will take its place. */ if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; + /* @def is now owned by @obj */ + def =3D NULL; virNodeDeviceObjSetPersistent(obj, persistent); virNodeDeviceObjSetAutostart(obj, autostart); objdef =3D virNodeDeviceObjGetDef(obj); @@ -1983,6 +1985,8 @@ udevSetupSystemDev(void) if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; =20 + /* @def is now owned by @obj */ + def =3D NULL; virNodeDeviceObjSetActive(obj, true); virNodeDeviceObjSetAutostart(obj, true); virNodeDeviceObjSetPersistent(obj, true); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 41828f86b656..81b1ba4294bd 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7656,8 +7656,9 @@ testNodeDeviceMockCreateVport(testDriver *driver, =20 if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; - virNodeDeviceObjSetSkipUpdateCaps(obj, true); + /* @def is now owned by @obj */ def =3D NULL; + virNodeDeviceObjSetSkipUpdateCaps(obj, true); objdef =3D virNodeDeviceObjGetDef(obj); =20 event =3D virNodeDeviceEventLifecycleNew(objdef->name, --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538398273763.5690346226199; Fri, 19 Apr 2024 07:53:18 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 249A31B84; Fri, 19 Apr 2024 10:53:17 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 589C91D84; Fri, 19 Apr 2024 10:50:08 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1B7701D66; Fri, 19 Apr 2024 10:49:53 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 47ED71B84 for ; Fri, 19 Apr 2024 10:49:52 -0400 (EDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEU9qS022991 for ; Fri, 19 Apr 2024 14:49:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd681uh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:51 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEno7X021860 for ; Fri, 19 Apr 2024 14:49:51 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd681ue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:50 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCDwSa022064; Fri, 19 Apr 2024 14:49:50 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbk947c7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEniGe52691392 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:46 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 874B92004E; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 136A420040; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 03/20] nodedev: immediate update of active config on udev add Date: Fri, 19 Apr 2024 16:49:22 +0200 Message-ID: <20240419144939.107773-4-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: cDHu3DJH7cq4wZR68YUiua1bAq72O0LY X-Proofpoint-ORIG-GUID: 8lSCZLVpLhj-qL376dNVoygGQYVk8ewc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 bulkscore=0 impostorscore=0 mlxscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: VUNGVAOOVS7RVC2ANUPMAVIQUJSQWY2L X-Message-ID-Hash: VUNGVAOOVS7RVC2ANUPMAVIQUJSQWY2L X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538400216100001 From: Boris Fiuczynski When an udev add event occurs the mdev active config data requires an update via mdevctl as the udev does not contain all config data. This update needs to occur immediately and to be finished before the libvirt CREATE event is issued to keep the API usage reliable. After this change, scheduleMdevctlUpdate call is already called in `udevAddOneDevice` and can therefore be removed in `udevHandleOneDevice`. Reviewed-by: Jonathon Jongsma Signed-off-by: Boris Fiuczynski Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 6613528d0e37..44393c2718cb 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1535,6 +1535,7 @@ udevSetParent(struct udev_device *device, static int udevAddOneDevice(struct udev_device *device) { + g_autofree char *sysfs_path =3D NULL; virNodeDeviceDef *def =3D NULL; virNodeDeviceObj *obj =3D NULL; virNodeDeviceDef *objdef; @@ -1549,6 +1550,9 @@ udevAddOneDevice(struct udev_device *device) def =3D g_new0(virNodeDeviceDef, 1); =20 def->sysfs_path =3D g_strdup(udev_device_get_syspath(device)); + /* Create a copy of sysfs_path so it can be safely accessed, even with= out + * holding the @obj lock during the VIR_WARN(...) call at the end. */ + sysfs_path =3D g_strdup(def->sysfs_path); =20 udevGetStringProperty(device, "DRIVER", &def->driver); =20 @@ -1608,6 +1612,14 @@ udevAddOneDevice(struct udev_device *device) if (has_mdev_types) scheduleMdevctlUpdate(driver->privateData, false); =20 + /* The added mdev needs an immediate active config update before the e= vent + * is issued so that full device information is available at the time = that + * the 'created' event is emitted. */ + if (is_mdev && (nodeDeviceUpdateMediatedDevices() < 0)) { + VIR_WARN("Update of mediated device %s failed", + NULLSTR_EMPTY(sysfs_path)); + } + ret =3D 0; =20 cleanup: @@ -1758,19 +1770,12 @@ nodeStateCleanup(void) static int udevHandleOneDevice(struct udev_device *device) { - virNodeDevCapType dev_cap_type; const char *action =3D udev_device_get_action(device); =20 VIR_DEBUG("udev action: '%s': %s", action, udev_device_get_syspath(dev= ice)); =20 - if (STREQ(action, "add") || STREQ(action, "change")) { - int ret =3D udevAddOneDevice(device); - if (ret =3D=3D 0 && - udevGetDeviceType(device, &dev_cap_type) =3D=3D 0 && - dev_cap_type =3D=3D VIR_NODE_DEV_CAP_MDEV) - scheduleMdevctlUpdate(driver->privateData, false); - return ret; - } + if (STREQ(action, "add") || STREQ(action, "change")) + return udevAddOneDevice(device); =20 if (STREQ(action, "remove")) return udevRemoveOneDevice(device); --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538505802278.85150807062564; Fri, 19 Apr 2024 07:55:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AAE5E1892; Fri, 19 Apr 2024 10:55:04 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0F7B21DDD; Fri, 19 Apr 2024 10:50:17 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 40A0F1D67; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 719E81D62 for ; Fri, 19 Apr 2024 10:49:53 -0400 (EDT) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JElWUl023685 for ; Fri, 19 Apr 2024 14:49:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktp9g09u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:52 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JElU81023623 for ; Fri, 19 Apr 2024 14:49:51 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktp9g09s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:51 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JC6XAu010515; Fri, 19 Apr 2024 14:49:50 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbmm478d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEni2X51839368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:47 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DB09420063; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C08320040; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 04/20] nodedev: reset active config data on udev remove event Date: Fri, 19 Apr 2024 16:49:23 +0200 Message-ID: <20240419144939.107773-5-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pavn1yWi-AM53qq3ERK5_ZOdHWnRC2Iq X-Proofpoint-ORIG-GUID: u_zSB3tO8Z-TnTuO55YvGn2fuLbTl9E- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 mlxscore=0 suspectscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: TQKU2LWK6AI5OUGNZVGME5VHDLY3ZFSM X-Message-ID-Hash: TQKU2LWK6AI5OUGNZVGME5VHDLY3ZFSM X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538506704100001 From: Boris Fiuczynski When a mdev device is destroyed or stopped the udev remove event handling needs to reset the active config data of the node object representing a persisted mdev. Reviewed-by: Marc Hartmayer Reviewed-by: Jonathon Jongsma Signed-off-by: Boris Fiuczynski --- src/node_device/node_device_driver.h | 3 +++ src/util/virmdev.h | 4 ++++ src/conf/node_device_conf.c | 10 ++-------- src/node_device/node_device_driver.c | 13 +++++++++++++ src/node_device/node_device_udev.c | 1 + src/util/virmdev.c | 20 ++++++++++++++++++++ src/libvirt_private.syms | 2 ++ 7 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index b3bc4b2e96ed..f195cfef9d49 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -197,3 +197,6 @@ int nodeDeviceUpdate(virNodeDevice *dev, const char *xmlDesc, unsigned int flags); + +void +nodeDeviceDefResetMdevActiveConfig(virNodeDeviceDef *def); diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 853041ac0619..e8e69040e5d4 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -54,6 +54,10 @@ struct _virMediatedDeviceConfig { size_t nattributes; }; =20 +void virMediatedDeviceConfigClear(virMediatedDeviceConfig *config); +void virMediatedDeviceConfigFree(virMediatedDeviceConfig *config); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceConfig, virMediatedDeviceCo= nfigFree); + typedef struct _virMediatedDeviceType virMediatedDeviceType; struct _virMediatedDeviceType { char *id; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 5cfbd6a7eb72..897c67d6af91 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2592,15 +2592,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps) g_free(data->sg.path); break; case VIR_NODE_DEV_CAP_MDEV: - g_free(data->mdev.defined_config.type); - g_free(data->mdev.active_config.type); g_free(data->mdev.uuid); - for (i =3D 0; i < data->mdev.defined_config.nattributes; i++) - virMediatedDeviceAttrFree(data->mdev.defined_config.attributes= [i]); - g_free(data->mdev.defined_config.attributes); - for (i =3D 0; i < data->mdev.active_config.nattributes; i++) - virMediatedDeviceAttrFree(data->mdev.active_config.attributes[= i]); - g_free(data->mdev.active_config.attributes); + virMediatedDeviceConfigClear(&data->mdev.defined_config); + virMediatedDeviceConfigClear(&data->mdev.active_config); g_free(data->mdev.parent_addr); break; case VIR_NODE_DEV_CAP_CSS_DEV: diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index d99b48138ebf..f623339dc973 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -2018,6 +2018,19 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, } =20 =20 +/* A mediated device definition contains data from mdevctl about the active + * device. When the device is deactivated the active configuration data ne= eds + * to be removed. */ +void +nodeDeviceDefResetMdevActiveConfig(virNodeDeviceDef *def) +{ + if (def->caps->data.type !=3D VIR_NODE_DEV_CAP_MDEV) + return; + + virMediatedDeviceConfigClear(&def->caps->data.mdev.active_config); +} + + int nodeDeviceSetAutostart(virNodeDevice *device, int autostart) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 44393c2718cb..7eef802d5975 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1467,6 +1467,7 @@ udevRemoveOneDeviceSysPath(const char *path) if (virNodeDeviceObjIsPersistent(obj)) { VIR_FREE(def->sysfs_path); virNodeDeviceObjSetActive(obj, false); + nodeDeviceDefResetMdevActiveConfig(def); } else { VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, path); diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 992f3eb1b74c..6ecdbdf0ab77 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -516,6 +516,26 @@ void virMediatedDeviceAttrFree(virMediatedDeviceAttr *= attr) g_free(attr); } =20 +void virMediatedDeviceConfigFree(virMediatedDeviceConfig *config) +{ + if (!config) + return; + + virMediatedDeviceConfigClear(config); + g_free(config); +} + +void virMediatedDeviceConfigClear(virMediatedDeviceConfig *config) +{ + size_t i =3D 0; + + g_clear_pointer(&config->type, g_free); + for (i =3D 0; i < config->nattributes; i++) + virMediatedDeviceAttrFree(config->attributes[i]); + config->nattributes =3D 0; + g_clear_pointer(&config->attributes, g_free); +} + =20 #define MDEV_BUS_DIR "/sys/class/mdev_bus" =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 839fe4f545f1..b3c0c576aa60 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2780,6 +2780,8 @@ virMacMapWriteFile; # util/virmdev.h virMediatedDeviceAttrFree; virMediatedDeviceAttrNew; +virMediatedDeviceConfigClear; +virMediatedDeviceConfigFree; virMediatedDeviceFree; virMediatedDeviceGetIOMMUGroupDev; virMediatedDeviceGetIOMMUGroupNum; --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538543636944.3587638778442; Fri, 19 Apr 2024 07:55:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 868371DC5; Fri, 19 Apr 2024 10:55:42 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3E34A1DF3; Fri, 19 Apr 2024 10:50:21 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B6ED71D67; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EC98A1C69 for ; Fri, 19 Apr 2024 10:49:53 -0400 (EDT) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEn7tm005366 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpsr04q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:52 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnqJg006128 for ; Fri, 19 Apr 2024 14:49:52 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpsr04m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCGAtv010585; Fri, 19 Apr 2024 14:49:50 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbmm478e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnjH433424116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:47 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44E1F2004B; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFA9A20040; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:44 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 05/20] node_device_udev: Remove the timeout if the data is disposed Date: Fri, 19 Apr 2024 16:49:24 +0200 Message-ID: <20240419144939.107773-6-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: bR80QvI7CdQnzIPJXDhIiuGpWaW7DAsx X-Proofpoint-GUID: vZnumfUlfK78cHrFqmj0wg1OjTD2fRrw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: 2G65UZ5IIE74GIXBGQUG7XVC4HWX76KE X-Message-ID-Hash: 2G65UZ5IIE74GIXBGQUG7XVC4HWX76KE X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538544787100001 Remove the timeout when the udevEventData is disposed, analogous to priv->w= atch. Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 7eef802d5975..4ccef628d84c 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -88,6 +88,9 @@ udevEventDataDispose(void *obj) if (priv->watch !=3D -1) virEventRemoveHandle(priv->watch); =20 + if (priv->mdevctlTimeout > 0) + virEventRemoveTimeout(priv->mdevctlTimeout); + if (!priv->udev_monitor) return; =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538453278296.6528016479914; Fri, 19 Apr 2024 07:54:13 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3E7441DC6; Fri, 19 Apr 2024 10:54:12 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E498A1E30; Fri, 19 Apr 2024 10:50:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 717901B84; Fri, 19 Apr 2024 10:49:53 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id F302F1C69 for ; Fri, 19 Apr 2024 10:49:52 -0400 (EDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEnEwm020658 for ; Fri, 19 Apr 2024 14:49:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:52 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnpTk020970 for ; Fri, 19 Apr 2024 14:49:51 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:51 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JC8nhk007824; Fri, 19 Apr 2024 14:49:51 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmcv7c2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnjM630671420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:47 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98A9920049; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 59FE720040; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 06/20] node_device_udev: Test for mdevctlTimeout != -1 Date: Fri, 19 Apr 2024 16:49:25 +0200 Message-ID: <20240419144939.107773-7-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: JtpyNvRR5QS2vY-y-RwQUadqpfuVQGAt X-Proofpoint-GUID: EkEMeVRoGY5KB3xPLKjzTnljqFPPjLYX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190110 Message-ID-Hash: JJ6HOLBE6OWMCGW4S7ZM4SRY2SZXNRP3 X-Message-ID-Hash: JJ6HOLBE6OWMCGW4S7ZM4SRY2SZXNRP3 X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538454405100001 It is done a little differently everywhere in libvirt, but most common is to test for !=3D -1. Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 4ccef628d84c..049501c62870 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -88,7 +88,7 @@ udevEventDataDispose(void *obj) if (priv->watch !=3D -1) virEventRemoveHandle(priv->watch); =20 - if (priv->mdevctlTimeout > 0) + if (priv->mdevctlTimeout !=3D -1) virEventRemoveTimeout(priv->mdevctlTimeout); =20 if (!priv->udev_monitor) @@ -139,6 +139,7 @@ udevEventDataNew(void) return NULL; } =20 + ret->mdevctlTimeout =3D -1; ret->watch =3D -1; return ret; } @@ -2087,7 +2088,7 @@ launchMdevctlUpdateThread(int timer G_GNUC_UNUSED, vo= id *opaque) udevEventData *priv =3D opaque; virThread thread; =20 - if (priv->mdevctlTimeout > 0) { + if (priv->mdevctlTimeout !=3D -1) { virEventRemoveTimeout(priv->mdevctlTimeout); priv->mdevctlTimeout =3D -1; } @@ -2197,7 +2198,7 @@ scheduleMdevctlUpdate(udevEventData *data, bool force) { if (!force) { - if (data->mdevctlTimeout > 0) + if (data->mdevctlTimeout !=3D -1) virEventRemoveTimeout(data->mdevctlTimeout); data->mdevctlTimeout =3D virEventAddTimeout(100, launchMdevctlUpda= teThread, data, NULL); --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538719197868.235657140589; Fri, 19 Apr 2024 07:58:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 218F21E66; Fri, 19 Apr 2024 10:58:37 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6E9F11E33; Fri, 19 Apr 2024 10:50:37 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 43E841D7F; Fri, 19 Apr 2024 10:49:56 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C78131D63 for ; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JElc7q008379 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktp9r094-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:53 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEmP4h009579 for ; Fri, 19 Apr 2024 14:49:52 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktp9r08y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCCaeJ021044; Fri, 19 Apr 2024 14:49:51 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6un-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:51 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnkev36897274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EECFB2004D; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD80720040; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 07/20] node_device_udev: Don't take `mdevctlLock` for `mdevctl list` and add comments about locking Date: Fri, 19 Apr 2024 16:49:26 +0200 Message-ID: <20240419144939.107773-8-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4Hkx3xZ_hRYqWbqCVBJYE2Zlju1v-DIe X-Proofpoint-ORIG-GUID: noj-EwMvR_pfOHYY7ZOqzt43LfnK0yF3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=0 priorityscore=1501 phishscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: Q3V4TAXGYU26NVLY24FPXUCBVKJIZPXW X-Message-ID-Hash: Q3V4TAXGYU26NVLY24FPXUCBVKJIZPXW X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538719328100001 Commit a99d876a0f58 ("node_device: Use automatic mutex management") replace= d the locking mechanism and accidentally removed the comment with the reason why = the lock is taken. The reason was to "ensure only a single thread can query mde= vctl at a time", but this reason is no longer valid or maybe it never was. There= fore, let's remove this lock and add a comment to `mdevCtl` what it protects. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 049501c62870..757febffa2f8 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -72,8 +72,9 @@ struct _udevEventData { /* init thread */ virThread *initThread; =20 - GList *mdevctlMonitors; + /* Protects @mdevctlMonitors */ virMutex mdevctlLock; + GList *mdevctlMonitors; int mdevctlTimeout; }; =20 @@ -2074,9 +2075,6 @@ udevPCITranslateInit(bool privileged G_GNUC_UNUSED) static void mdevctlUpdateThreadFunc(void *opaque G_GNUC_UNUSED) { - udevEventData *priv =3D driver->privateData; - VIR_LOCK_GUARD lock =3D virLockGuardLock(&priv->mdevctlLock); - if (nodeDeviceUpdateMediatedDevices() < 0) VIR_WARN("mdevctl failed to update mediated devices"); } --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538621742859.3333647933813; Fri, 19 Apr 2024 07:57:01 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B309F1E5B; Fri, 19 Apr 2024 10:57:00 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3C68C1D65; Fri, 19 Apr 2024 10:50:30 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8FCC91D6D; Fri, 19 Apr 2024 10:49:55 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 5CDFC1D66 for ; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEmO4v020317 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpq805v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:53 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnqPb022153 for ; Fri, 19 Apr 2024 14:49:52 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpq805r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCGrc8027842; Fri, 19 Apr 2024 14:49:51 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmpc6px-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:51 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnkxf48496952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E28F2004F; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F83920040; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:45 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 08/20] node_device_udev: Take lock if `driver->privateData` is modified Date: Fri, 19 Apr 2024 16:49:27 +0200 Message-ID: <20240419144939.107773-9-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: c6H7-SpUngGIwvGKC6V4TvEfsH1DaAsV X-Proofpoint-GUID: KOtctTVOEq79DLi10ZwrH9eJkRXYezy4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: UXI3F4ZALZ7MIKZ5F5Q54RWU44YQU5FZ X-Message-ID-Hash: UXI3F4ZALZ7MIKZ5F5Q54RWU44YQU5FZ X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538623044100001 Since @driver->privateData is modified take the lock. Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 757febffa2f8..281e852c7ff1 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1481,7 +1481,9 @@ udevRemoveOneDeviceSysPath(const char *path) virNodeDeviceObjEndAPI(&obj); =20 /* cannot check for mdev_types since they have already been removed */ - scheduleMdevctlUpdate(driver->privateData, false); + VIR_WITH_OBJECT_LOCK_GUARD(driver->privateData) { + scheduleMdevctlUpdate(driver->privateData, false); + } =20 virObjectEventStateQueue(driver->nodeDeviceEventState, event); return 0; @@ -1615,8 +1617,11 @@ udevAddOneDevice(struct udev_device *device) has_mdev_types =3D virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_MDEV_T= YPES); virNodeDeviceObjEndAPI(&obj); =20 - if (has_mdev_types) - scheduleMdevctlUpdate(driver->privateData, false); + if (has_mdev_types) { + VIR_WITH_OBJECT_LOCK_GUARD(driver->privateData) { + scheduleMdevctlUpdate(driver->privateData, false); + } + } =20 /* The added mdev needs an immediate active config update before the e= vent * is issued so that full device information is available at the time = that @@ -2237,7 +2242,9 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_GN= UC_UNUSED, * configuration change, try to coalesce these changes by waiting for = the * CHANGES_DONE_HINT event. As a fallback, add a timeout to trigger t= he * signal if that event never comes */ - scheduleMdevctlUpdate(priv, (event_type =3D=3D G_FILE_MONITOR_EVENT_CH= ANGES_DONE_HINT)); + VIR_WITH_OBJECT_LOCK_GUARD(priv) { + scheduleMdevctlUpdate(priv, (event_type =3D=3D G_FILE_MONITOR_EVEN= T_CHANGES_DONE_HINT)); + } } =20 =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538803383514.3061998058198; Fri, 19 Apr 2024 08:00:03 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 371261BAA; Fri, 19 Apr 2024 11:00:02 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DA1761E03; Fri, 19 Apr 2024 10:50:46 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 06A191DC9; Fri, 19 Apr 2024 10:49:59 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4EAE81A22 for ; Fri, 19 Apr 2024 10:49:55 -0400 (EDT) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEmiLU004530 for ; Fri, 19 Apr 2024 14:49:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpsr04w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:54 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnqJi006128 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpsr04s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:53 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCEePZ021052; Fri, 19 Apr 2024 14:49:52 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnk8Z37880128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A4DA820067; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6309020040; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 09/20] node_device_udev: Add prefix `udev` for udev related data Date: Fri, 19 Apr 2024 16:49:28 +0200 Message-ID: <20240419144939.107773-10-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3Bovlv75jqFQMpu47CBspp3_gxjwjZMP X-Proofpoint-GUID: oUKDYu9qgMSV7euqxONxheYFvXoNUQwy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: CIQVIPJGXZP46TAXXJH3BCFYDFOYZCVC X-Message-ID-Hash: CIQVIPJGXZP46TAXXJH3BCFYDFOYZCVC X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538805128100001 The new names make it easier to understand the purpose of the data. Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 281e852c7ff1..616ceca0b5c0 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -63,11 +63,11 @@ struct _udevEventData { struct udev_monitor *udev_monitor; int watch; =20 - /* Thread data */ - virThread *th; - virCond threadCond; - bool threadQuit; - bool dataReady; + /* Udev thread data */ + virThread *udevThread; + virCond udevThreadCond; + bool udevThreadQuit; + bool udevDataReady; =20 /* init thread */ virThread *initThread; @@ -104,7 +104,7 @@ udevEventDataDispose(void *obj) } virMutexDestroy(&priv->mdevctlLock); =20 - virCondDestroy(&priv->threadCond); + virCondDestroy(&priv->udevThreadCond); } =20 =20 @@ -130,7 +130,7 @@ udevEventDataNew(void) if (!(ret =3D virObjectLockableNew(udevEventDataClass))) return NULL; =20 - if (virCondInit(&ret->threadCond) < 0) { + if (virCondInit(&ret->udevThreadCond) < 0) { virObjectUnref(ret); return NULL; } @@ -1747,16 +1747,16 @@ nodeStateCleanup(void) priv =3D driver->privateData; if (priv) { VIR_WITH_OBJECT_LOCK_GUARD(priv) { - priv->threadQuit =3D true; - virCondSignal(&priv->threadCond); + priv->udevThreadQuit =3D true; + virCondSignal(&priv->udevThreadCond); } if (priv->initThread) { virThreadJoin(priv->initThread); g_clear_pointer(&priv->initThread, g_free); } - if (priv->th) { - virThreadJoin(priv->th); - g_clear_pointer(&priv->th, g_free); + if (priv->udevThread) { + virThreadJoin(priv->udevThread); + g_clear_pointer(&priv->udevThread, g_free); } } =20 @@ -1865,15 +1865,15 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED) /* continue rather than break from the loop on non-fatal errors */ while (1) { VIR_WITH_OBJECT_LOCK_GUARD(priv) { - while (!priv->dataReady && !priv->threadQuit) { - if (virCondWait(&priv->threadCond, &priv->parent.lock)) { + while (!priv->udevDataReady && !priv->udevThreadQuit) { + if (virCondWait(&priv->udevThreadCond, &priv->parent.lock)= ) { virReportSystemError(errno, "%s", _("handler failed to wait on cond= ition")); return; } } =20 - if (priv->threadQuit) + if (priv->udevThreadQuit) return; =20 errno =3D 0; @@ -1904,7 +1904,7 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED) * after the udev_monitor_receive_device wouldn't help much * due to event mgmt and scheduler timing. */ VIR_WITH_OBJECT_LOCK_GUARD(priv) { - priv->dataReady =3D false; + priv->udevDataReady =3D false; } =20 continue; @@ -1931,11 +1931,11 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED, VIR_LOCK_GUARD lock =3D virObjectLockGuard(priv); =20 if (!udevEventMonitorSanityCheck(priv, fd)) - priv->threadQuit =3D true; + priv->udevThreadQuit =3D true; else - priv->dataReady =3D true; + priv->udevDataReady =3D true; =20 - virCondSignal(&priv->threadCond); + virCondSignal(&priv->udevThreadCond); } =20 =20 @@ -2045,8 +2045,8 @@ nodeStateInitializeEnumerate(void *opaque) VIR_WITH_OBJECT_LOCK_GUARD(priv) { ignore_value(virEventRemoveHandle(priv->watch)); priv->watch =3D -1; - priv->threadQuit =3D true; - virCondSignal(&priv->threadCond); + priv->udevThreadQuit =3D true; + virCondSignal(&priv->udevThreadCond); } =20 goto cleanup; @@ -2340,12 +2340,12 @@ nodeStateInitialize(bool privileged, udev_monitor_set_receive_buffer_size(priv->udev_monitor, 128 * 1024 * 1024); =20 - priv->th =3D g_new0(virThread, 1); - if (virThreadCreateFull(priv->th, true, udevEventHandleThread, + priv->udevThread =3D g_new0(virThread, 1); + if (virThreadCreateFull(priv->udevThread, true, udevEventHandleThread, "udev-event", false, NULL) < 0) { virReportSystemError(errno, "%s", _("failed to create udev handler thread")); - g_clear_pointer(&priv->th, g_free); + g_clear_pointer(&priv->udevThread, g_free); goto unlock; } =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538582221709.5119945949663; Fri, 19 Apr 2024 07:56:22 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 280761E3A; Fri, 19 Apr 2024 10:56:21 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CEBF91DE0; Fri, 19 Apr 2024 10:50:25 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D5C081A22; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2E7BF1A22 for ; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JES2lH019532 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd681uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:53 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnrM7021876 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd681uk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:53 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCNjNc030347; Fri, 19 Apr 2024 14:49:52 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmcm6ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnlGk47382986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0237020040; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B668A2004E; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:46 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 10/20] node_device_udev: Inline `udevRemoveOneDevice` Date: Fri, 19 Apr 2024 16:49:29 +0200 Message-ID: <20240419144939.107773-11-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: d_OXR_NoUQQwqNlKI6Aa4ii3dQ6fNBOC X-Proofpoint-ORIG-GUID: ytZ18q-y0NMFet7VsgDFE_AEp9SiOp97 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 bulkscore=0 impostorscore=0 mlxscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=972 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: 67RZQ5GQ3U7Z6Q3BABIXLQJG3NWK42L7 X-Message-ID-Hash: 67RZQ5GQ3U7Z6Q3BABIXLQJG3NWK42L7 X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538582894100001 Inline `udevRemoveOneDevice` as it's used only once. Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma Signed-off-by: Marc Hartmayer --- src/node_device/node_device_udev.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 616ceca0b5c0..1c8832ebd990 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1489,16 +1489,6 @@ udevRemoveOneDeviceSysPath(const char *path) return 0; } =20 - -static int -udevRemoveOneDevice(struct udev_device *device) -{ - const char *path =3D udev_device_get_syspath(device); - - return udevRemoveOneDeviceSysPath(path); -} - - static int udevSetParent(struct udev_device *device, virNodeDeviceDef *def) @@ -1788,8 +1778,11 @@ udevHandleOneDevice(struct udev_device *device) if (STREQ(action, "add") || STREQ(action, "change")) return udevAddOneDevice(device); =20 - if (STREQ(action, "remove")) - return udevRemoveOneDevice(device); + if (STREQ(action, "remove")) { + const char *path =3D udev_device_get_syspath(device); + + return udevRemoveOneDeviceSysPath(path); + } =20 if (STREQ(action, "move")) { const char *devpath_old =3D udevGetDeviceProperty(device, "DEVPATH= _OLD"); --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538678430203.19921122972914; Fri, 19 Apr 2024 07:57:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 61B221ED6; Fri, 19 Apr 2024 10:57:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 86AD91E53; Fri, 19 Apr 2024 10:50:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2DBB51D83; Fri, 19 Apr 2024 10:49:56 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CA93D1D6A for ; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEWSw8025930 for ; Fri, 19 Apr 2024 14:49:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfag1b7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:54 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnrZf021088 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfag1b4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:53 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCFUZr010526; Fri, 19 Apr 2024 14:49:53 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbmm478g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnlLG46399868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 55C0020063; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 16D4D2004E; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 11/20] node_device_udev: Move responsibility to release `(init|udev)Thread` to `udevEventDataDispose` Date: Fri, 19 Apr 2024 16:49:30 +0200 Message-ID: <20240419144939.107773-12-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: cOMRiQnrhu8LtYappAL-Caup98WbK8iI X-Proofpoint-GUID: 91r8i3tKDMJ9rjtpRTDvWBqm_WzlgfE9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 adultscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 mlxlogscore=999 impostorscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: UIJF336KDPLSUZQN75C5BDPZC552WYPF X-Message-ID-Hash: UIJF336KDPLSUZQN75C5BDPZC552WYPF X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538679248100001 Everything is released in `udevEventDataDispose` except for the threads, ch= ange this as this makes the code easier to read as it can be simplified a little. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 1c8832ebd990..7f233652b461 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -86,12 +86,16 @@ udevEventDataDispose(void *obj) struct udev *udev =3D NULL; udevEventData *priv =3D obj; =20 + g_clear_pointer(&priv->initThread, g_free); + if (priv->watch !=3D -1) virEventRemoveHandle(priv->watch); =20 if (priv->mdevctlTimeout !=3D -1) virEventRemoveTimeout(priv->mdevctlTimeout); =20 + g_clear_pointer(&priv->udevThread, g_free); + if (!priv->udev_monitor) return; =20 @@ -1740,14 +1744,10 @@ nodeStateCleanup(void) priv->udevThreadQuit =3D true; virCondSignal(&priv->udevThreadCond); } - if (priv->initThread) { + if (priv->initThread) virThreadJoin(priv->initThread); - g_clear_pointer(&priv->initThread, g_free); - } - if (priv->udevThread) { + if (priv->udevThread) virThreadJoin(priv->udevThread); - g_clear_pointer(&priv->udevThread, g_free); - } } =20 virObjectUnref(priv); @@ -2338,7 +2338,6 @@ nodeStateInitialize(bool privileged, "udev-event", false, NULL) < 0) { virReportSystemError(errno, "%s", _("failed to create udev handler thread")); - g_clear_pointer(&priv->udevThread, g_free); goto unlock; } =20 @@ -2370,7 +2369,6 @@ nodeStateInitialize(bool privileged, "nodedev-init", false, udev) < 0) { virReportSystemError(errno, "%s", _("failed to create udev enumerate thread")); - g_clear_pointer(&priv->initThread, g_free); goto cleanup; } =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538756329393.92522700087363; Fri, 19 Apr 2024 07:59:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4B5801F31; Fri, 19 Apr 2024 10:59:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 757EB1DE2; Fri, 19 Apr 2024 10:50:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BEEB01DA0; Fri, 19 Apr 2024 10:49:57 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id ECB911D67 for ; Fri, 19 Apr 2024 10:49:54 -0400 (EDT) Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEXMi2022976 for ; Fri, 19 Apr 2024 14:49:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfhg1cx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:54 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnrVJ016149 for ; Fri, 19 Apr 2024 14:49:53 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfhg1ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:53 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCLupS030356; Fri, 19 Apr 2024 14:49:53 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmcm6yc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnlL044892476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADE132004B; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A52B2004E; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 12/20] node_device_udev: Fix leak of mdevctlLock, udevThreadCond, and mdevCtlMonitors Date: Fri, 19 Apr 2024 16:49:31 +0200 Message-ID: <20240419144939.107773-13-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: CUgWvqnkZMtivFcEW8jT7jmlSdNStPNg X-Proofpoint-GUID: unWhsBatm2lxCI-DKRVu26mVZmmXPTDp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 bulkscore=0 mlxscore=0 suspectscore=0 adultscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: 424JDKGUCHQMWFP25SWC24BXUFDJQHJH X-Message-ID-Hash: 424JDKGUCHQMWFP25SWC24BXUFDJQHJH X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538758728100001 Even if `priv->udev_monitor` was never initialized, the mdevctlLock, udevTh= read were. Therefore let's match the order of releasing the resources the order = of allocating the resources in `nodeStateInitialize`. In addition, use `g_steal_pointer` in `g_list_free_full`. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 7f233652b461..1638a7196709 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -88,6 +88,10 @@ udevEventDataDispose(void *obj) =20 g_clear_pointer(&priv->initThread, g_free); =20 + VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) { + g_list_free_full(g_steal_pointer(&priv->mdevctlMonitors), g_object= _unref); + } + if (priv->watch !=3D -1) virEventRemoveHandle(priv->watch); =20 @@ -96,16 +100,12 @@ udevEventDataDispose(void *obj) =20 g_clear_pointer(&priv->udevThread, g_free); =20 - if (!priv->udev_monitor) - return; - - udev =3D udev_monitor_get_udev(priv->udev_monitor); - udev_monitor_unref(priv->udev_monitor); - udev_unref(udev); - - VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) { - g_list_free_full(priv->mdevctlMonitors, g_object_unref); + if (priv->udev_monitor) { + udev =3D udev_monitor_get_udev(priv->udev_monitor); + udev_monitor_unref(priv->udev_monitor); + udev_unref(udev); } + virMutexDestroy(&priv->mdevctlLock); =20 virCondDestroy(&priv->udevThreadCond); --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538850800364.6991790008574; Fri, 19 Apr 2024 08:00:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7BAF01E14; Fri, 19 Apr 2024 11:00:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9C8F31E6E; Fri, 19 Apr 2024 10:50:51 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1AD201D70; Fri, 19 Apr 2024 10:49:59 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A26E11D66 for ; Fri, 19 Apr 2024 10:49:55 -0400 (EDT) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEWbfu025982 for ; Fri, 19 Apr 2024 14:49:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfag1ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:54 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnsXf021098 for ; Fri, 19 Apr 2024 14:49:54 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktfag1b8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:54 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCGU7H021033; Fri, 19 Apr 2024 14:49:53 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6uv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:53 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnmC035717528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:50 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0D7A620049; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C37062004E; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:47 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 13/20] node_device_udev: Introduce and use `stateShutdownPrepare` and `stateShutdownWait` Date: Fri, 19 Apr 2024 16:49:32 +0200 Message-ID: <20240419144939.107773-14-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: fnHHtOrnL8HOMXik0UND8z-ZtZAtIRbL X-Proofpoint-GUID: tSOo4iPKVuH4TMqndcQY2GEYXMitPJF_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 adultscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 mlxlogscore=999 impostorscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: AR37I5MUMSYDAEUYTA4XGVVMNDF3YTRU X-Message-ID-Hash: AR37I5MUMSYDAEUYTA4XGVVMNDF3YTRU X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538851319100001 Introduce and use the driver functions for the node state shutdown preparat= ion and wait. As they're also called in the error/cleanup path of `nodeStateInitialize`, they must be written in a way, that they can safely = be executed even if not everything is initialized. In the next commit, these functions will be extended. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 84 ++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 21 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 1638a7196709..a3006433e842 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -92,12 +92,6 @@ udevEventDataDispose(void *obj) g_list_free_full(g_steal_pointer(&priv->mdevctlMonitors), g_object= _unref); } =20 - if (priv->watch !=3D -1) - virEventRemoveHandle(priv->watch); - - if (priv->mdevctlTimeout !=3D -1) - virEventRemoveTimeout(priv->mdevctlTimeout); - g_clear_pointer(&priv->udevThread, g_free); =20 if (priv->udev_monitor) { @@ -1733,24 +1727,10 @@ udevPCITranslateDeinit(void) static int nodeStateCleanup(void) { - udevEventData *priv =3D NULL; - if (!driver) return -1; =20 - priv =3D driver->privateData; - if (priv) { - VIR_WITH_OBJECT_LOCK_GUARD(priv) { - priv->udevThreadQuit =3D true; - virCondSignal(&priv->udevThreadCond); - } - if (priv->initThread) - virThreadJoin(priv->initThread); - if (priv->udevThread) - virThreadJoin(priv->udevThread); - } - - virObjectUnref(priv); + virObjectUnref(driver->privateData); virObjectUnref(driver->nodeDeviceEventState); =20 virNodeDeviceObjListFree(driver->devs); @@ -2241,6 +2221,64 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_G= NUC_UNUSED, } =20 =20 +/* Note: It must be safe to call this function even if the driver was not + * successfully initialized. This must be considered when changing t= his + * function. */ +static int +nodeStateShutdownPrepare(void) +{ + udevEventData *priv =3D NULL; + + if (!driver) + return 0; + + priv =3D driver->privateData; + if (!priv) + return 0; + + VIR_WITH_OBJECT_LOCK_GUARD(priv) { + if (priv->mdevctlTimeout !=3D -1) { + virEventRemoveTimeout(priv->mdevctlTimeout); + priv->mdevctlTimeout =3D -1; + } + + if (priv->watch) { + virEventRemoveHandle(priv->watch); + priv->watch =3D -1; + } + + priv->udevThreadQuit =3D true; + virCondSignal(&priv->udevThreadCond); + } + return 0; +} + + +/* Note: It must be safe to call this function even if the driver was not + * successfully initialized. This must be considered when changing t= his + * function. */ +static int +nodeStateShutdownWait(void) +{ + udevEventData *priv =3D NULL; + + if (!driver) + return 0; + + priv =3D driver->privateData; + if (!priv) + return 0; + + VIR_WITH_OBJECT_LOCK_GUARD(priv) { + if (priv->initThread) + virThreadJoin(priv->initThread); + if (priv->udevThread) + virThreadJoin(priv->udevThread); + } + return 0; +} + + static int nodeStateInitialize(bool privileged, const char *root, @@ -2375,6 +2413,8 @@ nodeStateInitialize(bool privileged, return VIR_DRV_STATE_INIT_COMPLETE; =20 cleanup: + nodeStateShutdownPrepare(); + nodeStateShutdownWait(); nodeStateCleanup(); return VIR_DRV_STATE_INIT_ERROR; =20 @@ -2440,6 +2480,8 @@ static virStateDriver udevStateDriver =3D { .stateInitialize =3D nodeStateInitialize, /* 0.7.3 */ .stateCleanup =3D nodeStateCleanup, /* 0.7.3 */ .stateReload =3D nodeStateReload, /* 0.7.3 */ + .stateShutdownPrepare =3D nodeStateShutdownPrepare, /* 10.3.0 */ + .stateShutdownWait =3D nodeStateShutdownWait, /* 10.3.0 */ }; =20 =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538914001755.8499461976742; Fri, 19 Apr 2024 08:01:54 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E46461E03; Fri, 19 Apr 2024 11:01:52 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id F28031E7B; Fri, 19 Apr 2024 10:50:53 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 44A6D1DF4; Fri, 19 Apr 2024 10:50:01 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E4BEE1D79 for ; Fri, 19 Apr 2024 10:49:55 -0400 (EDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEnEBH020661 for ; Fri, 19 Apr 2024 14:49:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:55 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnsWm020989 for ; Fri, 19 Apr 2024 14:49:54 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:54 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCJuYx022231; Fri, 19 Apr 2024 14:49:54 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbk947cf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:53 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnmSU30540066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:50 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 61B1A20065; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2347B2004E; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 14/20] node_device_udev: nodeStateShutdownPrepare: Disconnect the signals explicitly Date: Fri, 19 Apr 2024 16:49:33 +0200 Message-ID: <20240419144939.107773-15-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: qaxnaJzZjkAUiei20RywnNP5X2k149Uw X-Proofpoint-GUID: p1aHuqtkyAiMVCsEetVbYgPU6OrDomAl X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190110 Message-ID-Hash: HI6HBFVSPFZWZK2752D6V75SI2H6LMSZ X-Message-ID-Hash: HI6HBFVSPFZWZK2752D6V75SI2H6LMSZ X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538915849100001 The documentation of gobject signals reads: "If you are connecting handlers to signals and using a GObject instance as = your signal handler user data, you should remember to pair calls to g_signal_connect() with calls to g_signal_handler_disconnect() or g_signal_handlers_disconnect_by_func(). While signal handlers are automatic= ally disconnected when the object emitting the signal is finalised..." [1] This means that the signal handlers are automatically disconnected as soon = as the `priv->mdevCtlMonitors` are finalised/released by `udevEventDataDispose= `. But this also means that it's possible that new work is tried to be schedul= ed for the workerpool by the `mdevctlEventHandleCallback` (main thread context) even if the workerpool has already been stopped by `nodeStateShutdownWait`.= To fully understand this, it's important to know that the main loop of the main thread is still running for some time even after `nodeStateShutdownPrepare`= has been called. Let's avoid this situation by explicitly disconnect the signals during `nodeStateShutdownPrepare`, which is called in the main thread, so t= hat no new work is attempted to be scheduled for the worker pool. [1] https://docs.gtk.org/gobject/signals.html#memory-management-of-signal-h= andlers Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index a3006433e842..38740033a66e 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2236,6 +2236,12 @@ nodeStateShutdownPrepare(void) if (!priv) return 0; =20 + VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) { + GList *tmp; + for (tmp =3D priv->mdevctlMonitors; tmp; tmp =3D tmp->next) + g_signal_handlers_disconnect_by_data(tmp->data, priv); + } + VIR_WITH_OBJECT_LOCK_GUARD(priv) { if (priv->mdevctlTimeout !=3D -1) { virEventRemoveTimeout(priv->mdevctlTimeout); --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713539127580362.9778160188416; Fri, 19 Apr 2024 08:05:27 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6C133172C; Fri, 19 Apr 2024 11:05:26 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 794E51E5E; Fri, 19 Apr 2024 10:51:07 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 28EDA1D8E; Fri, 19 Apr 2024 10:50:17 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D9D811D8E for ; Fri, 19 Apr 2024 10:49:56 -0400 (EDT) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEmik7004526 for ; Fri, 19 Apr 2024 14:49:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpsr050-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:55 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEntVP006221 for ; Fri, 19 Apr 2024 14:49:55 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktpsr04x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:55 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCTjG8027875; Fri, 19 Apr 2024 14:49:54 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmpc6q5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnmAJ50463208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:50 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D17D62004F; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 773CB2004E; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 15/20] node_device_udev: Pass the driver state as parameter in preparation for the next commit Date: Fri, 19 Apr 2024 16:49:34 +0200 Message-ID: <20240419144939.107773-16-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: cZNeJ-rcmWC9JGT6TYtmDoydHXXtq7C- X-Proofpoint-GUID: BFR3WjiWBDu3-bBjCf-bIRMuK82CVOQp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: WN7SGZ4JKJ5EUSV3XILNNF4VCQZDRNV5 X-Message-ID-Hash: WN7SGZ4JKJ5EUSV3XILNNF4VCQZDRNV5 X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713539128942100001 It's better practice for all functions called by the threads to pass the dr= iver via parameter and not global variables. Easier to test and cleaner. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_driver.h | 2 +- src/node_device/node_device_driver.c | 6 +-- src/node_device/node_device_udev.c | 72 ++++++++++++++-------------- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index f195cfef9d49..2781ad136d68 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -147,7 +147,7 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, bool defined); =20 int -nodeDeviceUpdateMediatedDevices(void); +nodeDeviceUpdateMediatedDevices(virNodeDeviceDriverState *driver); =20 void nodeDeviceGenerateName(virNodeDeviceDef *def, diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index f623339dc973..59c5f9b417a4 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1887,7 +1887,7 @@ removeMissingPersistentMdev(virNodeDeviceObj *obj, =20 =20 int -nodeDeviceUpdateMediatedDevices(void) +nodeDeviceUpdateMediatedDevices(virNodeDeviceDriverState *node_driver) { g_autofree virNodeDeviceDef **defs =3D NULL; g_autofree virNodeDeviceDef **act_defs =3D NULL; @@ -1911,7 +1911,7 @@ nodeDeviceUpdateMediatedDevices(void) /* Any mdevs that were previously defined but were not returned in the * latest mdevctl query should be removed from the device list */ data.defs =3D defs; - virNodeDeviceObjListForEachRemove(driver->devs, + virNodeDeviceObjListForEachRemove(node_driver->devs, removeMissingPersistentMdev, &data); =20 for (i =3D 0; i < data.ndefs; i++) @@ -2374,7 +2374,7 @@ nodeDeviceUpdate(virNodeDevice *device, cleanup: virNodeDeviceObjEndAPI(&obj); if (updated) - nodeDeviceUpdateMediatedDevices(); + nodeDeviceUpdateMediatedDevices(driver); =20 return ret; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 38740033a66e..e4b1532dc385 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -361,7 +361,7 @@ udevTranslatePCIIds(unsigned int vendor, =20 =20 static int -udevProcessPCI(struct udev_device *device, +udevProcessPCI(virNodeDeviceDriverState *driver_state, struct udev_device = *device, virNodeDeviceDef *def) { virNodeDevCapPCIDev *pci_dev =3D &def->caps->data.pci_dev; @@ -372,8 +372,8 @@ udevProcessPCI(struct udev_device *device, char *p; bool privileged =3D false; =20 - VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { - privileged =3D driver->privileged; + VIR_WITH_MUTEX_LOCK_GUARD(&driver_state->lock) { + privileged =3D driver_state->privileged; } =20 pci_dev->klass =3D -1; @@ -1391,12 +1391,12 @@ udevGetDeviceType(struct udev_device *device, =20 =20 static int -udevGetDeviceDetails(struct udev_device *device, +udevGetDeviceDetails(virNodeDeviceDriverState *driver_state, struct udev_d= evice *device, virNodeDeviceDef *def) { switch (def->caps->data.type) { case VIR_NODE_DEV_CAP_PCI_DEV: - return udevProcessPCI(device, def); + return udevProcessPCI(driver_state, device, def); case VIR_NODE_DEV_CAP_USB_DEV: return udevProcessUSBDevice(device, def); case VIR_NODE_DEV_CAP_USB_INTERFACE: @@ -1447,13 +1447,13 @@ static void scheduleMdevctlUpdate(udevEventData *da= ta, bool force); =20 =20 static int -udevRemoveOneDeviceSysPath(const char *path) +udevRemoveOneDeviceSysPath(virNodeDeviceDriverState *driver_state, const c= har *path) { virNodeDeviceObj *obj =3D NULL; virNodeDeviceDef *def; virObjectEvent *event =3D NULL; =20 - if (!(obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, path))= ) { + if (!(obj =3D virNodeDeviceObjListFindBySysfsPath(driver_state->devs, = path))) { VIR_DEBUG("Failed to find device to remove that has udev path '%s'= ", path); return -1; @@ -1474,21 +1474,21 @@ udevRemoveOneDeviceSysPath(const char *path) } else { VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, path); - virNodeDeviceObjListRemove(driver->devs, obj); + virNodeDeviceObjListRemove(driver_state->devs, obj); } virNodeDeviceObjEndAPI(&obj); =20 /* cannot check for mdev_types since they have already been removed */ VIR_WITH_OBJECT_LOCK_GUARD(driver->privateData) { - scheduleMdevctlUpdate(driver->privateData, false); + scheduleMdevctlUpdate(driver_state->privateData, false); } =20 - virObjectEventStateQueue(driver->nodeDeviceEventState, event); + virObjectEventStateQueue(driver_state->nodeDeviceEventState, event); return 0; } =20 static int -udevSetParent(struct udev_device *device, +udevSetParent(virNodeDeviceDriverState *driver_state, struct udev_device *= device, virNodeDeviceDef *def) { struct udev_device *parent_device =3D NULL; @@ -1511,7 +1511,7 @@ udevSetParent(struct udev_device *device, return -1; } =20 - if ((obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, + if ((obj =3D virNodeDeviceObjListFindBySysfsPath(driver_state->dev= s, parent_sysfs_path))= ) { objdef =3D virNodeDeviceObjGetDef(obj); def->parent =3D g_strdup(objdef->name); @@ -1529,7 +1529,7 @@ udevSetParent(struct udev_device *device, } =20 static int -udevAddOneDevice(struct udev_device *device) +udevAddOneDevice(virNodeDeviceDriverState *driver_state, struct udev_devic= e *device) { g_autofree char *sysfs_path =3D NULL; virNodeDeviceDef *def =3D NULL; @@ -1560,15 +1560,15 @@ udevAddOneDevice(struct udev_device *device) if (udevGetDeviceNodes(device, def) !=3D 0) goto cleanup; =20 - if (udevGetDeviceDetails(device, def) !=3D 0) + if (udevGetDeviceDetails(driver_state, device, def) !=3D 0) goto cleanup; =20 - if (udevSetParent(device, def) !=3D 0) + if (udevSetParent(driver_state, device, def) !=3D 0) goto cleanup; =20 is_mdev =3D def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV; =20 - if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name)))= { + if ((obj =3D virNodeDeviceObjListFindByName(driver_state->devs, def->n= ame))) { objdef =3D virNodeDeviceObjGetDef(obj); =20 if (is_mdev) @@ -1586,7 +1586,7 @@ udevAddOneDevice(struct udev_device *device) =20 /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) + if (!(obj =3D virNodeDeviceObjListAssignDef(driver_state->devs, def))) goto cleanup; /* @def is now owned by @obj */ def =3D NULL; @@ -1606,15 +1606,15 @@ udevAddOneDevice(struct udev_device *device) virNodeDeviceObjEndAPI(&obj); =20 if (has_mdev_types) { - VIR_WITH_OBJECT_LOCK_GUARD(driver->privateData) { - scheduleMdevctlUpdate(driver->privateData, false); + VIR_WITH_OBJECT_LOCK_GUARD(driver_state->privateData) { + scheduleMdevctlUpdate(driver_state->privateData, false); } } =20 /* The added mdev needs an immediate active config update before the e= vent * is issued so that full device information is available at the time = that * the 'created' event is emitted. */ - if (is_mdev && (nodeDeviceUpdateMediatedDevices() < 0)) { + if (is_mdev && (nodeDeviceUpdateMediatedDevices(driver_state) < 0)) { VIR_WARN("Update of mediated device %s failed", NULLSTR_EMPTY(sysfs_path)); } @@ -1622,7 +1622,7 @@ udevAddOneDevice(struct udev_device *device) ret =3D 0; =20 cleanup: - virObjectEventStateQueue(driver->nodeDeviceEventState, event); + virObjectEventStateQueue(driver_state->nodeDeviceEventState, event); =20 if (ret !=3D 0) { VIR_DEBUG("Discarding device %d %p %s", ret, def, @@ -1635,7 +1635,7 @@ udevAddOneDevice(struct udev_device *device) =20 =20 static int -udevProcessDeviceListEntry(struct udev *udev, +udevProcessDeviceListEntry(virNodeDeviceDriverState *driver_state, struct = udev *udev, struct udev_list_entry *list_entry) { struct udev_device *device; @@ -1647,7 +1647,7 @@ udevProcessDeviceListEntry(struct udev *udev, device =3D udev_device_new_from_syspath(udev, name); =20 if (device !=3D NULL) { - if (udevAddOneDevice(device) !=3D 0) { + if (udevAddOneDevice(driver_state, device) !=3D 0) { VIR_DEBUG("Failed to create node device for udev device '%s'", name); } @@ -1685,7 +1685,7 @@ udevEnumerateAddMatches(struct udev_enumerate *udev_e= numerate) =20 =20 static int -udevEnumerateDevices(struct udev *udev) +udevEnumerateDevices(virNodeDeviceDriverState *driver_state, struct udev *= udev) { struct udev_enumerate *udev_enumerate =3D NULL; struct udev_list_entry *list_entry =3D NULL; @@ -1701,7 +1701,7 @@ udevEnumerateDevices(struct udev *udev) udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate))= { =20 - udevProcessDeviceListEntry(udev, list_entry); + udevProcessDeviceListEntry(driver_state, udev, list_entry); } =20 ret =3D 0; @@ -1756,12 +1756,12 @@ udevHandleOneDevice(struct udev_device *device) VIR_DEBUG("udev action: '%s': %s", action, udev_device_get_syspath(dev= ice)); =20 if (STREQ(action, "add") || STREQ(action, "change")) - return udevAddOneDevice(device); + return udevAddOneDevice(driver, device); =20 if (STREQ(action, "remove")) { const char *path =3D udev_device_get_syspath(device); =20 - return udevRemoveOneDeviceSysPath(path); + return udevRemoveOneDeviceSysPath(driver, path); } =20 if (STREQ(action, "move")) { @@ -1770,10 +1770,10 @@ udevHandleOneDevice(struct udev_device *device) if (devpath_old) { g_autofree char *devpath_old_fixed =3D g_strdup_printf("/sys%s= ", devpath_old); =20 - udevRemoveOneDeviceSysPath(devpath_old_fixed); + udevRemoveOneDeviceSysPath(driver, devpath_old_fixed); } =20 - return udevAddOneDevice(device); + return udevAddOneDevice(driver, device); } =20 return 0; @@ -1995,15 +1995,15 @@ udevSetupSystemDev(void) static void nodeStateInitializeEnumerate(void *opaque) { - struct udev *udev =3D opaque; udevEventData *priv =3D driver->privateData; + struct udev *udev =3D opaque; =20 /* Populate with known devices */ - if (udevEnumerateDevices(udev) !=3D 0) + if (udevEnumerateDevices(driver, udev) !=3D 0) goto error; /* Load persistent mdevs (which might not be activated yet) and additi= onal * information about active mediated devices from mdevctl */ - if (nodeDeviceUpdateMediatedDevices() !=3D 0) + if (nodeDeviceUpdateMediatedDevices(driver) !=3D 0) goto error; =20 cleanup: @@ -2051,9 +2051,11 @@ udevPCITranslateInit(bool privileged G_GNUC_UNUSED) =20 =20 static void -mdevctlUpdateThreadFunc(void *opaque G_GNUC_UNUSED) +mdevctlUpdateThreadFunc(void *opaque) { - if (nodeDeviceUpdateMediatedDevices() < 0) + virNodeDeviceDriverState *driver_state =3D opaque; + + if (nodeDeviceUpdateMediatedDevices(driver_state) < 0) VIR_WARN("mdevctl failed to update mediated devices"); } =20 @@ -2070,7 +2072,7 @@ launchMdevctlUpdateThread(int timer G_GNUC_UNUSED, vo= id *opaque) } =20 if (virThreadCreateFull(&thread, false, mdevctlUpdateThreadFunc, - "mdevctl-thread", false, NULL) < 0) { + "mdevctl-thread", false, driver) < 0) { virReportSystemError(errno, "%s", _("failed to create mdevctl thread")); } --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713538997771567.3840156606298; Fri, 19 Apr 2024 08:03:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 930A61F44; Fri, 19 Apr 2024 11:03:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 538D51E47; Fri, 19 Apr 2024 10:50:59 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E66B91D7F; Fri, 19 Apr 2024 10:50:15 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A77E51D7F for ; Fri, 19 Apr 2024 10:49:56 -0400 (EDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEnbZJ020853 for ; Fri, 19 Apr 2024 14:49:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:55 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnt7Q020998 for ; Fri, 19 Apr 2024 14:49:55 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:55 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCEhtl030331; Fri, 19 Apr 2024 14:49:54 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmcm6yn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnnaQ21365434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63A4A2005A; Fri, 19 Apr 2024 14:49:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E69482004E; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:48 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 16/20] node_device_udev: Use a worker pool for processing events and emitting nodedev event Date: Fri, 19 Apr 2024 16:49:35 +0200 Message-ID: <20240419144939.107773-17-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: K5HiYqTDFYu7ZQnz6oDS_lp2fpL-5_2a X-Proofpoint-GUID: 88Mv8YRLCnUHSBIcLBa1PBHT4qUuoD-g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190110 Message-ID-Hash: N5XBPFYQLEQBJ3RVK7GWCMT3T2VWRBKW X-Message-ID-Hash: N5XBPFYQLEQBJ3RVK7GWCMT3T2VWRBKW X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713538998325100001 Use a worker pool for processing the events (e.g. udev, mdevctl config chan= ges) and the initialization instead of a separate initThread and a mdevctl-threa= d. This has the large advantage that we can leverage the job API and now this thread pool is responsible to do all the "costly-work" and emitting the lib= virt nodedev events. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 244 +++++++++++++++++++++-------- 1 file changed, 179 insertions(+), 65 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e4b1532dc385..67a8b5cd7132 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -43,6 +43,7 @@ #include "virnetdev.h" #include "virmdev.h" #include "virutil.h" +#include "virthreadpool.h" =20 #include "configmake.h" =20 @@ -69,13 +70,13 @@ struct _udevEventData { bool udevThreadQuit; bool udevDataReady; =20 - /* init thread */ - virThread *initThread; - /* Protects @mdevctlMonitors */ virMutex mdevctlLock; GList *mdevctlMonitors; int mdevctlTimeout; + + /* Immutable pointer, self-locking APIs */ + virThreadPool *workerPool; }; =20 static virClass *udevEventDataClass; @@ -86,8 +87,6 @@ udevEventDataDispose(void *obj) struct udev *udev =3D NULL; udevEventData *priv =3D obj; =20 - g_clear_pointer(&priv->initThread, g_free); - VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) { g_list_free_full(g_steal_pointer(&priv->mdevctlMonitors), g_object= _unref); } @@ -100,6 +99,8 @@ udevEventDataDispose(void *obj) udev_unref(udev); } =20 + g_clear_pointer(&priv->workerPool, virThreadPoolFree); + virMutexDestroy(&priv->mdevctlLock); =20 virCondDestroy(&priv->udevThreadCond); @@ -143,6 +144,66 @@ udevEventDataNew(void) return ret; } =20 +typedef enum { + NODE_DEVICE_EVENT_INIT =3D 0, + NODE_DEVICE_EVENT_UDEV_ADD, + NODE_DEVICE_EVENT_UDEV_REMOVE, + NODE_DEVICE_EVENT_UDEV_CHANGE, + NODE_DEVICE_EVENT_UDEV_MOVE, + NODE_DEVICE_EVENT_MDEVCTL_CONFIG_CHANGED, + + NODE_DEVICE_EVENT_LAST +} nodeDeviceEventType; + +struct _nodeDeviceEvent { + nodeDeviceEventType eventType; + void *data; + virFreeCallback dataFreeFunc; +}; +typedef struct _nodeDeviceEvent nodeDeviceEvent; + +static void +nodeDeviceEventFree(nodeDeviceEvent *event) +{ + if (!event) + return; + + if (event->dataFreeFunc) + event->dataFreeFunc(event->data); + g_free(event); +} +G_DEFINE_AUTOPTR_CLEANUP_FUNC(nodeDeviceEvent, nodeDeviceEventFree); + + /** + * nodeDeviceEventSubmit: + * @eventType: the event to be processed + * @data: additional data for the event processor (the pointer is stolen = and it + * will be properly freed using @dataFreeFunc) + * @dataFreeFunc: callback to free @data + * + * Submits @eventType to be processed by the asynchronous event handling + * thread. + */ +static int nodeDeviceEventSubmit(nodeDeviceEventType eventType, void *data= , virFreeCallback dataFreeFunc) +{ + nodeDeviceEvent *event =3D g_new0(nodeDeviceEvent, 1); + udevEventData *priv =3D NULL; + + if (!driver) + return -1; + + priv =3D driver->privateData; + + event->eventType =3D eventType; + event->data =3D data; + event->dataFreeFunc =3D dataFreeFunc; + if (virThreadPoolSendJob(priv->workerPool, 0, event) < 0) { + nodeDeviceEventFree(event); + return -1; + } + return 0; +} + =20 static bool udevHasDeviceProperty(struct udev_device *dev, @@ -1447,7 +1508,7 @@ static void scheduleMdevctlUpdate(udevEventData *data= , bool force); =20 =20 static int -udevRemoveOneDeviceSysPath(virNodeDeviceDriverState *driver_state, const c= har *path) +processNodeDeviceRemoveEvent(virNodeDeviceDriverState *driver_state, const= char *path) { virNodeDeviceObj *obj =3D NULL; virNodeDeviceDef *def; @@ -1529,7 +1590,7 @@ udevSetParent(virNodeDeviceDriverState *driver_state,= struct udev_device *device } =20 static int -udevAddOneDevice(virNodeDeviceDriverState *driver_state, struct udev_devic= e *device) +processNodeDeviceAddAndChangeEvent(virNodeDeviceDriverState *driver_state,= struct udev_device *device) { g_autofree char *sysfs_path =3D NULL; virNodeDeviceDef *def =3D NULL; @@ -1647,7 +1708,7 @@ udevProcessDeviceListEntry(virNodeDeviceDriverState *= driver_state, struct udev * device =3D udev_device_new_from_syspath(udev, name); =20 if (device !=3D NULL) { - if (udevAddOneDevice(driver_state, device) !=3D 0) { + if (processNodeDeviceAddAndChangeEvent(driver_state, device) !=3D = 0) { VIR_DEBUG("Failed to create node device for udev device '%s'", name); } @@ -1755,26 +1816,23 @@ udevHandleOneDevice(struct udev_device *device) =20 VIR_DEBUG("udev action: '%s': %s", action, udev_device_get_syspath(dev= ice)); =20 - if (STREQ(action, "add") || STREQ(action, "change")) - return udevAddOneDevice(driver, device); - - if (STREQ(action, "remove")) { - const char *path =3D udev_device_get_syspath(device); - - return udevRemoveOneDeviceSysPath(driver, path); - } - - if (STREQ(action, "move")) { - const char *devpath_old =3D udevGetDeviceProperty(device, "DEVPATH= _OLD"); - - if (devpath_old) { - g_autofree char *devpath_old_fixed =3D g_strdup_printf("/sys%s= ", devpath_old); - - udevRemoveOneDeviceSysPath(driver, devpath_old_fixed); - } - - return udevAddOneDevice(driver, device); + /* Reference is either released via workerpool logic or at the end of = this + * function. */ + device =3D udev_device_ref(device); + if (STREQ(action, "add")) { + return nodeDeviceEventSubmit(NODE_DEVICE_EVENT_UDEV_ADD, device, + (virFreeCallback)udev_device_unref); + } else if (STREQ(action, "change")) { + return nodeDeviceEventSubmit(NODE_DEVICE_EVENT_UDEV_CHANGE, device, + (virFreeCallback)udev_device_unref); + } else if (STREQ(action, "remove")) { + return nodeDeviceEventSubmit(NODE_DEVICE_EVENT_UDEV_REMOVE, device, + (virFreeCallback)udev_device_unref); + } else if (STREQ(action, "move")) { + return nodeDeviceEventSubmit(NODE_DEVICE_EVENT_UDEV_MOVE, device, + (virFreeCallback)udev_device_unref); } + udev_device_unref(device); =20 return 0; } @@ -1993,23 +2051,23 @@ udevSetupSystemDev(void) =20 =20 static void -nodeStateInitializeEnumerate(void *opaque) +processNodeStateInitializeEnumerate(virNodeDeviceDriverState *driver_state= , void *opaque) { - udevEventData *priv =3D driver->privateData; + udevEventData *priv =3D driver_state->privateData; struct udev *udev =3D opaque; =20 /* Populate with known devices */ - if (udevEnumerateDevices(driver, udev) !=3D 0) + if (udevEnumerateDevices(driver_state, udev) !=3D 0) goto error; /* Load persistent mdevs (which might not be activated yet) and additi= onal * information about active mediated devices from mdevctl */ - if (nodeDeviceUpdateMediatedDevices(driver) !=3D 0) + if (nodeDeviceUpdateMediatedDevices(driver_state) !=3D 0) goto error; =20 cleanup: - VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { - driver->initialized =3D true; - virCondBroadcast(&driver->initCond); + VIR_WITH_MUTEX_LOCK_GUARD(&driver_state->lock) { + driver_state->initialized =3D true; + virCondBroadcast(&driver_state->initCond); } =20 return; @@ -2051,31 +2109,16 @@ udevPCITranslateInit(bool privileged G_GNUC_UNUSED) =20 =20 static void -mdevctlUpdateThreadFunc(void *opaque) -{ - virNodeDeviceDriverState *driver_state =3D opaque; - - if (nodeDeviceUpdateMediatedDevices(driver_state) < 0) - VIR_WARN("mdevctl failed to update mediated devices"); -} - - -static void -launchMdevctlUpdateThread(int timer G_GNUC_UNUSED, void *opaque) +submitMdevctlUpdate(int timer G_GNUC_UNUSED, void *opaque) { udevEventData *priv =3D opaque; - virThread thread; =20 if (priv->mdevctlTimeout !=3D -1) { virEventRemoveTimeout(priv->mdevctlTimeout); priv->mdevctlTimeout =3D -1; } =20 - if (virThreadCreateFull(&thread, false, mdevctlUpdateThreadFunc, - "mdevctl-thread", false, driver) < 0) { - virReportSystemError(errno, "%s", - _("failed to create mdevctl thread")); - } + nodeDeviceEventSubmit(NODE_DEVICE_EVENT_MDEVCTL_CONFIG_CHANGED, NULL,= NULL); } =20 =20 @@ -2170,7 +2213,7 @@ mdevctlEnableMonitor(udevEventData *priv) /* Schedules an mdevctl update for 100ms in the future, canceling any exis= ting * timeout that may have been set. In this way, multiple update requests in * quick succession can be collapsed into a single update. if @force is tr= ue, - * an update thread will be spawned immediately. */ + * the worker job is submitted immediately. */ static void scheduleMdevctlUpdate(udevEventData *data, bool force) @@ -2178,12 +2221,12 @@ scheduleMdevctlUpdate(udevEventData *data, if (!force) { if (data->mdevctlTimeout !=3D -1) virEventRemoveTimeout(data->mdevctlTimeout); - data->mdevctlTimeout =3D virEventAddTimeout(100, launchMdevctlUpda= teThread, + data->mdevctlTimeout =3D virEventAddTimeout(100, submitMdevctlUpda= te, data, NULL); return; } =20 - launchMdevctlUpdateThread(-1, data); + submitMdevctlUpdate(-1, data); } =20 =20 @@ -2223,6 +2266,62 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_G= NUC_UNUSED, } =20 =20 +static void nodeDeviceEventHandler(void *data, void *opaque) +{ + virNodeDeviceDriverState *driver_state =3D opaque; + g_autoptr(nodeDeviceEvent) processEvent =3D data; + + switch (processEvent->eventType) { + case NODE_DEVICE_EVENT_INIT: + { + struct udev *udev =3D processEvent->data; + + processNodeStateInitializeEnumerate(driver_state, udev); + } + break; + case NODE_DEVICE_EVENT_UDEV_ADD: + case NODE_DEVICE_EVENT_UDEV_CHANGE: + { + struct udev_device *device =3D processEvent->data; + + processNodeDeviceAddAndChangeEvent(driver_state, device); + } + break; + case NODE_DEVICE_EVENT_UDEV_REMOVE: + { + struct udev_device *device =3D processEvent->data; + const char *path =3D udev_device_get_syspath(device); + + processNodeDeviceRemoveEvent(driver_state, path); + } + break; + case NODE_DEVICE_EVENT_UDEV_MOVE: + { + struct udev_device *device =3D processEvent->data; + const char *devpath_old =3D udevGetDeviceProperty(device, "DEVPATH= _OLD"); + + if (devpath_old) { + g_autofree char *devpath_old_fixed =3D g_strdup_printf("/sys%s= ", devpath_old); + + processNodeDeviceRemoveEvent(driver_state, devpath_old_fixed); + } + + processNodeDeviceAddAndChangeEvent(driver_state, device); + } + break; + case NODE_DEVICE_EVENT_MDEVCTL_CONFIG_CHANGED: + { + if (nodeDeviceUpdateMediatedDevices(driver_state) < 0) + VIR_WARN("mdevctl failed to update mediated devices"); + } + break; + case NODE_DEVICE_EVENT_LAST: + g_assert_not_reached(); + break; + } +} + + /* Note: It must be safe to call this function even if the driver was not * successfully initialized. This must be considered when changing t= his * function. */ @@ -2258,6 +2357,9 @@ nodeStateShutdownPrepare(void) priv->udevThreadQuit =3D true; virCondSignal(&priv->udevThreadCond); } + + if (priv->workerPool) + virThreadPoolStop(priv->workerPool); return 0; } =20 @@ -2278,11 +2380,19 @@ nodeStateShutdownWait(void) return 0; =20 VIR_WITH_OBJECT_LOCK_GUARD(priv) { - if (priv->initThread) - virThreadJoin(priv->initThread); - if (priv->udevThread) - virThreadJoin(priv->udevThread); + if (priv->mdevctlTimeout !=3D -1) { + virEventRemoveTimeout(priv->mdevctlTimeout); + priv->mdevctlTimeout =3D -1; + } + + if (priv->watch) { + virEventRemoveHandle(priv->watch); + priv->watch =3D -1; + } } + + if (priv->workerPool) + virThreadPoolDrain(priv->workerPool); return 0; } =20 @@ -2353,6 +2463,16 @@ nodeStateInitialize(bool privileged, driver->parserCallbacks.postParse =3D nodeDeviceDefPostParse; driver->parserCallbacks.validate =3D nodeDeviceDefValidate; =20 + /* must be initialized before trying to reconnect to all the running m= devs + * since there might occur some mdevctl monitor events that will be + * dispatched to the worker pool */ + priv->workerPool =3D virThreadPoolNewFull(1, 1, 0, nodeDeviceEventHand= ler, + "nodev-device-event", + NULL, + driver); + if (!priv->workerPool) + goto unlock; + if (udevPCITranslateInit(privileged) < 0) goto unlock; =20 @@ -2410,13 +2530,7 @@ nodeStateInitialize(bool privileged, if (udevSetupSystemDev() !=3D 0) goto cleanup; =20 - priv->initThread =3D g_new0(virThread, 1); - if (virThreadCreateFull(priv->initThread, true, nodeStateInitializeEnu= merate, - "nodedev-init", false, udev) < 0) { - virReportSystemError(errno, "%s", - _("failed to create udev enumerate thread")); - goto cleanup; - } + nodeDeviceEventSubmit(NODE_DEVICE_EVENT_INIT, udev_ref(udev), (virFree= Callback)udev_unref); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713539217789533.6706564669988; Fri, 19 Apr 2024 08:06:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BC549AD5; Fri, 19 Apr 2024 11:06:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 739001EB1; Fri, 19 Apr 2024 10:51:17 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DDEA41DDF; Fri, 19 Apr 2024 10:50:19 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CA0401D6C for ; Fri, 19 Apr 2024 10:49:57 -0400 (EDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEnRLd020751 for ; Fri, 19 Apr 2024 14:49:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:56 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnur2021007 for ; Fri, 19 Apr 2024 14:49:56 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktq9r01u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:56 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCEePa021052; Fri, 19 Apr 2024 14:49:55 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6uy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:55 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnn1C16187864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B625E2004E; Fri, 19 Apr 2024 14:49:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7821220067; Fri, 19 Apr 2024 14:49:49 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:49 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 17/20] node_device_udev: Call `nodeDeviceUpdateMediatedDevices` directly Date: Fri, 19 Apr 2024 16:49:36 +0200 Message-ID: <20240419144939.107773-18-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Ahf_tbIt9_SW8q3AuKBaNyxg_XnWoF00 X-Proofpoint-GUID: jD2wLBOMG8JLe-4Fr4aR6YMaRv81vOEv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190110 Message-ID-Hash: JMWQ357S7VGOT7OXKOXLGMD343KHXKT4 X-Message-ID-Hash: JMWQ357S7VGOT7OXKOXLGMD343KHXKT4 X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713539219194100001 When an udev event occurs the mdev active config data requires an update via mdevctl as the udev does not contain all config data. This update needs to = occur immediate and to be finished before the libvirt nodedev event is issued to = keep the API usage reliable. The only case where a direct `nodeDeviceUpdateMediatedDevices` is not wishe= d is `mdevctlEventHandleCallback` - see commit 2c57b28191b9 ("nodedev: Refresh m= dev devices when changes are detected") for details, but for this case there ar= e no nodedev events created so the problem described above does not exist. `udevAddOneDevice` and `udevRemoveOneDeviceSysPath` are only called by the worker pool threads therefore it's possible to call the `nodeDeviceUpdateMediatedDevices` directly without blocking the udev thread. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 67a8b5cd7132..25571ebf708f 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1504,9 +1504,6 @@ udevGetDeviceDetails(virNodeDeviceDriverState *driver= _state, struct udev_device } =20 =20 -static void scheduleMdevctlUpdate(udevEventData *data, bool force); - - static int processNodeDeviceRemoveEvent(virNodeDeviceDriverState *driver_state, const= char *path) { @@ -1540,9 +1537,8 @@ processNodeDeviceRemoveEvent(virNodeDeviceDriverState= *driver_state, const char virNodeDeviceObjEndAPI(&obj); =20 /* cannot check for mdev_types since they have already been removed */ - VIR_WITH_OBJECT_LOCK_GUARD(driver->privateData) { - scheduleMdevctlUpdate(driver_state->privateData, false); - } + if (nodeDeviceUpdateMediatedDevices(driver_state) < 0) + VIR_WARN("mdevctl failed to update mediated devices"); =20 virObjectEventStateQueue(driver_state->nodeDeviceEventState, event); return 0; @@ -1666,16 +1662,10 @@ processNodeDeviceAddAndChangeEvent(virNodeDeviceDri= verState *driver_state, struc has_mdev_types =3D virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_MDEV_T= YPES); virNodeDeviceObjEndAPI(&obj); =20 - if (has_mdev_types) { - VIR_WITH_OBJECT_LOCK_GUARD(driver_state->privateData) { - scheduleMdevctlUpdate(driver_state->privateData, false); - } - } - /* The added mdev needs an immediate active config update before the e= vent * is issued so that full device information is available at the time = that * the 'created' event is emitted. */ - if (is_mdev && (nodeDeviceUpdateMediatedDevices(driver_state) < 0)) { + if ((has_mdev_types || is_mdev) && (nodeDeviceUpdateMediatedDevices(dr= iver_state) < 0)) { VIR_WARN("Update of mediated device %s failed", NULLSTR_EMPTY(sysfs_path)); } --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713539056819876.584750251094; Fri, 19 Apr 2024 08:04:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B49CB1F30; Fri, 19 Apr 2024 11:04:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9706C1EA3; Fri, 19 Apr 2024 10:51:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ADEE31DCC; Fri, 19 Apr 2024 10:50:16 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3D93D1D94 for ; Fri, 19 Apr 2024 10:49:57 -0400 (EDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JEhfPi011433 for ; Fri, 19 Apr 2024 14:49:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd681uw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:56 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnujH021898 for ; Fri, 19 Apr 2024 14:49:56 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd681ut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:56 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCDki9027825; Fri, 19 Apr 2024 14:49:55 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmpc6q8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:55 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEno3w39387528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 16CDD2004B; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB7B520063; Fri, 19 Apr 2024 14:49:49 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:49 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 18/20] node_device_udev: Make the code easier to read Date: Fri, 19 Apr 2024 16:49:37 +0200 Message-ID: <20240419144939.107773-19-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 551Ugigq_idVU2rxkEW3QXQw80a3uAW_ X-Proofpoint-ORIG-GUID: eL0QGST1nCBqEem1nWHAjR91ftv0ELnv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 bulkscore=0 impostorscore=0 mlxscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=850 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: SJMYOJIA5VQVKKRMKQCRRQU2SKDXRJSD X-Message-ID-Hash: SJMYOJIA5VQVKKRMKQCRRQU2SKDXRJSD X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713539058565100001 There is only one case where force is true, therefore let's inline that cas= e. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 25571ebf708f..0b255952a9f9 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2202,21 +2202,14 @@ mdevctlEnableMonitor(udevEventData *priv) =20 /* Schedules an mdevctl update for 100ms in the future, canceling any exis= ting * timeout that may have been set. In this way, multiple update requests in - * quick succession can be collapsed into a single update. if @force is tr= ue, - * the worker job is submitted immediately. */ + * quick succession can be collapsed into a single update. */ static void -scheduleMdevctlUpdate(udevEventData *data, - bool force) +scheduleMdevctlUpdate(udevEventData *data) { - if (!force) { - if (data->mdevctlTimeout !=3D -1) - virEventRemoveTimeout(data->mdevctlTimeout); - data->mdevctlTimeout =3D virEventAddTimeout(100, submitMdevctlUpda= te, - data, NULL); - return; - } - - submitMdevctlUpdate(-1, data); + if (data->mdevctlTimeout !=3D -1) + virEventRemoveTimeout(data->mdevctlTimeout); + data->mdevctlTimeout =3D virEventAddTimeout(100, submitMdevctlUpdate, + data, NULL); } =20 =20 @@ -2251,7 +2244,11 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_G= NUC_UNUSED, * CHANGES_DONE_HINT event. As a fallback, add a timeout to trigger t= he * signal if that event never comes */ VIR_WITH_OBJECT_LOCK_GUARD(priv) { - scheduleMdevctlUpdate(priv, (event_type =3D=3D G_FILE_MONITOR_EVEN= T_CHANGES_DONE_HINT)); + if (event_type =3D=3D G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { + submitMdevctlUpdate(-1, priv); + } else { + scheduleMdevctlUpdate(priv); + } } } =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713539165173209.64610558516256; Fri, 19 Apr 2024 08:06:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 196A01DDD; Fri, 19 Apr 2024 11:06:04 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BC1BB1D8D; Fri, 19 Apr 2024 10:51:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6BB241DD3; Fri, 19 Apr 2024 10:50:18 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 896001DA1 for ; Fri, 19 Apr 2024 10:49:57 -0400 (EDT) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JES0ii010381 for ; Fri, 19 Apr 2024 14:49:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd4r1tv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:56 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnu7P012607 for ; Fri, 19 Apr 2024 14:49:56 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktd4r1ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:56 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCFYwt007855; Fri, 19 Apr 2024 14:49:55 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xkbmcv7cg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:55 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEno6T50331910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A80F20049; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B93C20063; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 19/20] node_device_udev: Add support for `g_autoptr` to `udevEventData` Date: Fri, 19 Apr 2024 16:49:38 +0200 Message-ID: <20240419144939.107773-20-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: g2hHaC0q8vq51I3Zcj0Z4U3ormoqB7yW X-Proofpoint-GUID: ryj6_8mq32Lo99jDDb7YCW0D1RJz58Jx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_09,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 mlxlogscore=963 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 impostorscore=0 clxscore=1015 mlxscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190109 Message-ID-Hash: RDT2BI2BMZH2HD5XBTTBCKARQGIP5AHB X-Message-ID-Hash: RDT2BI2BMZH2HD5XBTTBCKARQGIP5AHB X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713539166999100001 Use this feature in `udevEventDataNew`. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 0b255952a9f9..cc8700fc4117 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -78,6 +78,7 @@ struct _udevEventData { /* Immutable pointer, self-locking APIs */ virThreadPool *workerPool; }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(udevEventData, virObjectUnref); =20 static virClass *udevEventDataClass; =20 @@ -121,7 +122,7 @@ VIR_ONCE_GLOBAL_INIT(udevEventData); static udevEventData * udevEventDataNew(void) { - udevEventData *ret =3D NULL; + g_autoptr(udevEventData) ret =3D NULL; =20 if (udevEventDataInitialize() < 0) return NULL; @@ -129,19 +130,15 @@ udevEventDataNew(void) if (!(ret =3D virObjectLockableNew(udevEventDataClass))) return NULL; =20 - if (virCondInit(&ret->udevThreadCond) < 0) { - virObjectUnref(ret); + if (virCondInit(&ret->udevThreadCond) < 0) return NULL; - } =20 - if (virMutexInit(&ret->mdevctlLock) < 0) { - virObjectUnref(ret); + if (virMutexInit(&ret->mdevctlLock) < 0) return NULL; - } =20 ret->mdevctlTimeout =3D -1; ret->watch =3D -1; - return ret; + return g_steal_pointer(&ret); } =20 typedef enum { --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:29:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713539255224638.6408425491421; Fri, 19 Apr 2024 08:07:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2F4331B98; Fri, 19 Apr 2024 11:07:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 821281C69; Fri, 19 Apr 2024 10:51:20 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9955E1DEF; Fri, 19 Apr 2024 10:50:20 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9424A1D6A for ; Fri, 19 Apr 2024 10:49:59 -0400 (EDT) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JERc6c027347 for ; Fri, 19 Apr 2024 14:49:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktcxg21g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Apr 2024 14:49:58 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43JEnvnC030563 for ; Fri, 19 Apr 2024 14:49:57 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xktcxg21d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:57 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43JCRuV7020837; Fri, 19 Apr 2024 14:49:56 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xkbm9m6v2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Apr 2024 14:49:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43JEnoTi50004342 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 14:49:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF71320067; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F5BD20063; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.fritz.box (unknown [9.171.43.6]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Apr 2024 14:49:50 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: Marc Hartmayer To: Subject: [PATCH v1 20/20] node_device_udev: Pass the `udevEventData` via parameter and use refcounting Date: Fri, 19 Apr 2024 16:49:39 +0200 Message-ID: <20240419144939.107773-21-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419144939.107773-1-mhartmay@linux.ibm.com> References: <20240419144939.107773-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: N4BBxK9PDiCp01V5uKdJD7GSX29FJN9r X-Proofpoint-ORIG-GUID: DPDUdEEJoUrDU4PS4F6AT3xRCL9yMfbE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190111 Message-ID-Hash: SDXDQUBEAXGKIDQXTYT72G6S472AML5M X-Message-ID-Hash: SDXDQUBEAXGKIDQXTYT72G6S472AML5M X-MailFrom: mhartmay@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Boris Fiuczynski , Jonathon Jongsma X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713539257403100001 Instead of accessing the global `driver` object pass the `udevEventData` as parameter to the thread handler and watch callback. This has the advantage = that: 1. proper refcounting 2. easier to read and test Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index cc8700fc4117..07cbdfa3bdeb 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1856,7 +1856,7 @@ udevEventMonitorSanityCheck(udevEventData *priv, =20 /** * udevEventHandleThread - * @opaque: unused + * @opaque: udevEventData * * Thread to handle the udevEventHandleCallback processing when udev * tells us there's a device change for us (add, modify, delete, etc). @@ -1875,9 +1875,9 @@ udevEventMonitorSanityCheck(udevEventData *priv, * would still come into play. */ static void -udevEventHandleThread(void *opaque G_GNUC_UNUSED) +udevEventHandleThread(void *opaque) { - udevEventData *priv =3D driver->privateData; + g_autoptr(udevEventData) priv =3D opaque; struct udev_device *device =3D NULL; =20 /* continue rather than break from the loop on non-fatal errors */ @@ -1943,9 +1943,9 @@ static void udevEventHandleCallback(int watch G_GNUC_UNUSED, int fd, int events G_GNUC_UNUSED, - void *data G_GNUC_UNUSED) + void *data) { - udevEventData *priv =3D driver->privateData; + udevEventData *priv =3D data; VIR_LOCK_GUARD lock =3D virObjectLockGuard(priv); =20 if (!udevEventMonitorSanityCheck(priv, fd)) @@ -2485,7 +2485,7 @@ nodeStateInitialize(bool privileged, =20 priv->udevThread =3D g_new0(virThread, 1); if (virThreadCreateFull(priv->udevThread, true, udevEventHandleThread, - "udev-event", false, NULL) < 0) { + "udev-event", false, virObjectRef(priv)) < 0) { virReportSystemError(errno, "%s", _("failed to create udev handler thread")); goto unlock; @@ -2501,7 +2501,7 @@ nodeStateInitialize(bool privileged, * that appear while the enumeration is taking place. */ priv->watch =3D virEventAddHandle(udev_monitor_get_fd(priv->udev_monit= or), VIR_EVENT_HANDLE_READABLE, - udevEventHandleCallback, NULL, NULL); + udevEventHandleCallback, virObjectRef(= priv), virObjectUnref); if (priv->watch =3D=3D -1) goto unlock; =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org