From nobody Wed Jan 15 12:01:07 2025 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 17086075201921000.5676824704832; Thu, 22 Feb 2024 05:12:00 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1342F1BC7; Thu, 22 Feb 2024 08:11:59 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 669061D95; Thu, 22 Feb 2024 08:03:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7C0D61A16; Thu, 22 Feb 2024 08:02:25 -0500 (EST) 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 5E67E1A1C for ; Thu, 22 Feb 2024 08:02:21 -0500 (EST) 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 41MCqpt5011130 for ; Thu, 22 Feb 2024 13:02:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3we6nggb0b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 22 Feb 2024 13:02:19 +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 41MCqqwe011173 for ; Thu, 22 Feb 2024 13:02:19 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 3we6nggayq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 13:02:19 +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 41MBAQAq003596; Thu, 22 Feb 2024 13:02:18 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wb74txhmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 13:02:17 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41MD2CE054591992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Feb 2024 13:02:14 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 32ED520040; Thu, 22 Feb 2024 13:02:12 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DE7D20071; Thu, 22 Feb 2024 13:02:12 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.135.123]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 22 Feb 2024 13:02:12 +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.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH v5 12/12] nodedev: allow modify on define of a persistent node device Date: Thu, 22 Feb 2024 14:02:09 +0100 Message-ID: <20240222130209.8316-13-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240222130209.8316-1-fiuczy@linux.ibm.com> References: <20240222130209.8316-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: IQ08bgaLJxIDovA42mXKacnIBVKR_ocX X-Proofpoint-GUID: YTEiYRKiAnjPehnRdVY8jz7XDy3yKeIX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_10,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=855 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402220104 Message-ID-Hash: TQS4X4PAMOT6RTV3N7RRUKZMAC7XKQAX X-Message-ID-Hash: TQS4X4PAMOT6RTV3N7RRUKZMAC7XKQAX X-MailFrom: fiuczy@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: jjongsma@redhat.com, mhartmay@linux.ibm.com 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: 1708607521664100001 Allow to modify a node device by using virNodeDeviceDefineXML() to align its behavior with other drivers define methods. Signed-off-by: Boris Fiuczynski --- NEWS.rst | 5 +++ src/libvirt-nodedev.c | 4 ++- src/node_device/node_device_driver.c | 47 ++++++++++++++++++++++++---- tools/virsh-nodedev.c | 8 ++--- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index bb264a4bcc..def5a5edd0 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -45,6 +45,11 @@ v10.1.0 (unreleased) =20 * **Improvements** =20 +* nodedev: Add ability to update persistent mediated devices by defining t= hem + + Existing persistent mediated devices can now also be updated by + ``virNodeDeviceDefineXML()`` as long as parent and UUID remain unchang= ed. + * **Bug fixes** =20 * qemu_process: Skip over non-virtio non-TAP NIC models when refreshing = rx-filter diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index b97c199a3a..f242c0a8f6 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -780,7 +780,9 @@ virNodeDeviceDestroy(virNodeDevicePtr dev) * @xmlDesc: string containing an XML description of the device to be defi= ned * @flags: bitwise-OR of supported virNodeDeviceDefineXMLFlags * - * Define a new device on the VM host machine, for example, a mediated dev= ice + * Define a new inactive persistent device or modify an existing persistent + * one from the XML description on the VM host machine, for example, a med= iated + * device. * * virNodeDeviceFree should be used to free the resources after the * node device object is no longer needed. diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 07a951533d..ac9fba4406 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1544,16 +1544,38 @@ nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *de= f, } =20 =20 +static virNodeDeviceObj* +findPersistentMdevNodeDevice(virNodeDeviceDef *def) +{ + virNodeDeviceObj *obj =3D NULL; + + if (!nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) + return NULL; + + if (def->caps->data.mdev.uuid && + def->caps->data.mdev.parent_addr && + (obj =3D virNodeDeviceObjListFindMediatedDeviceByUUID(driver->devs, + def->caps->dat= a.mdev.uuid, + def->caps->dat= a.mdev.parent_addr)) && + !virNodeDeviceObjIsPersistent(obj)) + virNodeDeviceObjEndAPI(&obj); + + return obj; +} + + virNodeDevice* nodeDeviceDefineXML(virConnect *conn, const char *xmlDesc, unsigned int flags) { g_autoptr(virNodeDeviceDef) def =3D NULL; + virNodeDeviceObj *persistent_obj =3D NULL; const char *virt_type =3D NULL; g_autofree char *uuid =3D NULL; g_autofree char *name =3D NULL; bool validate =3D flags & VIR_NODE_DEVICE_DEFINE_XML_VALIDATE; + bool modify_failed =3D false; =20 virCheckFlags(VIR_NODE_DEVICE_DEFINE_XML_VALIDATE, NULL); =20 @@ -1581,13 +1603,26 @@ nodeDeviceDefineXML(virConnect *conn, return NULL; } =20 - if (virMdevctlDefine(def, &uuid) < 0) { - return NULL; - } + if ((persistent_obj =3D findPersistentMdevNodeDevice(def))) { + // virNodeDeviceObjUpdateModificationImpact() is not required we w= ill + // modify the persistent config only. + // nodeDeviceDefValidateUpdate() is not required as uuid and paren= t are + // matching if def was found and changing the type in the persiste= nt + // config is allowed. + VIR_DEBUG("Update node device '%s' with mdevctl", def->name); + modify_failed =3D (virMdevctlModify(def, true, false) < 0); + virNodeDeviceObjEndAPI(&persistent_obj); + if (modify_failed) + return NULL; + } else { + VIR_DEBUG("Define node device '%s' with mdevctl", def->name); + if (virMdevctlDefine(def, &uuid) < 0) + return NULL; =20 - if (uuid && uuid[0]) { - g_free(def->caps->data.mdev.uuid); - def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); + if (uuid && uuid[0]) { + g_free(def->caps->data.mdev.uuid); + def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); + } } =20 mdevGenerateDeviceName(def); diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 7b80747819..912975dfed 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1083,12 +1083,12 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd= *cmd G_GNUC_UNUSED) */ static const vshCmdInfo info_node_device_define[] =3D { {.name =3D "help", - .data =3D N_("Define a device by an xml file on a node") + .data =3D N_("Define or modify a device by an xml file on a node") }, {.name =3D "desc", - .data =3D N_("Defines a persistent device on the node that can be " - "assigned to a domain. The device must be started before " - "it can be assigned to a domain.") + .data =3D N_("Defines or modifies a persistent device on the node tha= t " + "can be assigned to a domain. The device must be started " + "before it can be assigned to a domain.") }, {.name =3D NULL} }; --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org