From nobody Sat Feb 7 08:43:53 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 1708096154581458.3003880712341; Fri, 16 Feb 2024 07:09:14 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8786217A1; Fri, 16 Feb 2024 10:09:13 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9AF891DBD; Fri, 16 Feb 2024 09:58:43 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B72491CA8; Fri, 16 Feb 2024 09:58:16 -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 8DE061CB3 for ; Fri, 16 Feb 2024 09:56:15 -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 41GEu8U1026260 for ; Fri, 16 Feb 2024 14:56:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa9pt871a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:14 +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 41GEu90T026323 for ; Fri, 16 Feb 2024 14:56:13 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 3wa9pt86w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:13 +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 41GESRIW009728; Fri, 16 Feb 2024 14:52:27 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6p63bdm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:27 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqMZr16057080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:24 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7C142004B; Fri, 16 Feb 2024 14:52:22 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A1BBD20073; Fri, 16 Feb 2024 14:52:22 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.183.223]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 16 Feb 2024 14:52:22 +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 v3 12/12] nodedev: allow modify on define of a persistent node device Date: Fri, 16 Feb 2024 15:52:20 +0100 Message-ID: <20240216145220.5056-13-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216145220.5056-1-fiuczy@linux.ibm.com> References: <20240216145220.5056-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: I6hm01NroEKRKxsekVtzeftKOsahVxIK X-Proofpoint-ORIG-GUID: ujzdMvQTLJQRQPpj7d1njt1wkQIskA3H 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-16_13,2024-02-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 adultscore=0 suspectscore=0 bulkscore=0 clxscore=1015 spamscore=0 mlxlogscore=822 mlxscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: 32K44JWEHUMITSYLO7I6ZQ7MVUADOOVJ X-Message-ID-Hash: 32K44JWEHUMITSYLO7I6ZQ7MVUADOOVJ 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: 1708096155372100005 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 | 64 ++++++++++++++++++++++------ tools/virsh-nodedev.c | 8 ++-- 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index aa2fee3533..9b8b94dea4 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -32,6 +32,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 11bc9af92e..66de46513d 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1544,12 +1544,33 @@ nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *de= f, } =20 =20 +static virNodeDeviceObj* +findPersistentMdevNodeDevice(virNodeDeviceDef *def) +{ + virNodeDeviceObj *obj =3D NULL; + + if (!nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV) && !def->pare= nt) + return NULL; + + if (def->caps->data.mdev.uuid && def->caps->data.mdev.parent_addr) { + mdevGenerateDeviceName(def); + if ((obj =3D nodeDeviceObjFindByName(def->name)) && + virNodeDeviceObjIsPersistent(obj)) + return obj; + } + + return NULL; +} + + virNodeDevice* nodeDeviceDefineXML(virConnect *conn, const char *xmlDesc, unsigned int flags) { g_autoptr(virNodeDeviceDef) def =3D NULL; + virNodeDevicePtr new_nodedev =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; @@ -1566,28 +1587,43 @@ nodeDeviceDefineXML(virConnect *conn, &driver->parserCallbacks, NULL, vali= date))) return NULL; =20 + persistent_obj =3D findPersistentMdevNodeDevice(def); + if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0) - return NULL; + goto cleanup; =20 if (!nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Unsupported device type")); - return NULL; + goto cleanup; } =20 if (!def->parent) { virReportError(VIR_ERR_XML_ERROR, "%s", _("cannot define a mediated device without a parent= ")); - return NULL; + goto cleanup; } =20 - if (virMdevctlDefine(def, &uuid) < 0) { - return NULL; - } + if (persistent_obj) { + // virNodeDeviceObjUpdateModificationImpact() is not required we w= ill + // modify the persitent config only. + // nodeDeviceDefValidateUpdate() is not required as uuid and paren= t are + // machting 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); + if (virMdevctlModify(def, true, false) < 0) + goto cleanup; =20 - if (uuid && uuid[0]) { - g_free(def->caps->data.mdev.uuid); - def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); + virNodeDeviceObjEndAPI(&persistent_obj); + } else { + VIR_DEBUG("Define node device '%s' with mdevctl", def->name); + if (virMdevctlDefine(def, &uuid) < 0) + goto cleanup; + + if (uuid && uuid[0]) { + g_free(def->caps->data.mdev.uuid); + def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); + } } =20 mdevGenerateDeviceName(def); @@ -1601,9 +1637,13 @@ nodeDeviceDefineXML(virConnect *conn, * add the provisional device to the list and return it immediately and * avoid this long delay. */ if (nodeDeviceUpdateMediatedDevice(g_steal_pointer(&def), true) < 0) - return NULL; + goto cleanup; + + new_nodedev =3D virGetNodeDevice(conn, name); =20 - return virGetNodeDevice(conn, name); + cleanup: + virNodeDeviceObjEndAPI(&persistent_obj); + return new_nodedev; } =20 =20 @@ -2237,7 +2277,7 @@ nodeDeviceDefValidateUpdate(virNodeDeviceDef *def, cap_mdev->uuid); return -1; } - =20 + /* A live update cannot change the mdev type. Since the new config is * stored in defined_config, compare that to the mdev type of the curr= ent * live config to make sure they match */ 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