From nobody Mon Feb 9 06:34:30 2026 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 171389643437414.32085560636574; Tue, 23 Apr 2024 11:20:34 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 43F7F170C; Tue, 23 Apr 2024 14:20:33 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3CB171E03; Tue, 23 Apr 2024 14:10:19 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E5A771F1D; Tue, 23 Apr 2024 14:09:24 -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 41D221E3B for ; Tue, 23 Apr 2024 14:09:22 -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 43NHI0Ew016355 for ; Tue, 23 Apr 2024 18:09:21 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xph8pg3am-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 23 Apr 2024 18:09:21 +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 43NI9Ll6027010 for ; Tue, 23 Apr 2024 18:09:21 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 3xph8pg3ag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Apr 2024 18:09:20 +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 43NF5x0L015299; Tue, 23 Apr 2024 18:09:20 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xmshm6x7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Apr 2024 18:09:20 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43NI9E0v38928734 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Apr 2024 18:09:16 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6C712005A; Tue, 23 Apr 2024 18:09:14 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B4A920040; Tue, 23 Apr 2024 18:09:14 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.ibm.com.com (unknown [9.171.91.126]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 23 Apr 2024 18:09:14 +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 v2 13/20] node_device_udev: Introduce and use `stateShutdownPrepare` and `stateShutdownWait` Date: Tue, 23 Apr 2024 20:08:59 +0200 Message-ID: <20240423180906.16164-14-mhartmay@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423180906.16164-1-mhartmay@linux.ibm.com> References: <20240423180906.16164-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Nf614adYZOLpHG-O4dqXXnLq94CPfLpW X-Proofpoint-ORIG-GUID: cbi8WHIcbj4Ft2aaTXjIa858P3y11yIR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-23_15,2024-04-23_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 spamscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404230041 Message-ID-Hash: JIAA2IZ5FGNAB4JFBLCVI4OL2NKFF6II X-Message-ID-Hash: JIAA2IZ5FGNAB4JFBLCVI4OL2NKFF6II 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: 1713896436107100001 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. Reviewed-by: Jonathon Jongsma Reviewed-by: Boris Fiuczynski Signed-off-by: Marc Hartmayer --- 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 906b16778eef..b2c5d11acbdf 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) { @@ -1723,24 +1717,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); @@ -2231,6 +2211,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, @@ -2365,6 +2403,8 @@ nodeStateInitialize(bool privileged, return VIR_DRV_STATE_INIT_COMPLETE; =20 cleanup: + nodeStateShutdownPrepare(); + nodeStateShutdownWait(); nodeStateCleanup(); return VIR_DRV_STATE_INIT_ERROR; =20 @@ -2430,6 +2470,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