From nobody Mon Sep 16 18:49:05 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 1707313818590114.04390611565145; Wed, 7 Feb 2024 05:50:18 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 73EC61EAA; Wed, 7 Feb 2024 08:50:17 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BD4301E01; Wed, 7 Feb 2024 08:40:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id A2A2F1BC4; Wed, 7 Feb 2024 08:40:07 -0500 (EST) 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 CC7371BA6 for ; Wed, 7 Feb 2024 08:40:01 -0500 (EST) 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 417DHsuh023868 for ; Wed, 7 Feb 2024 13:40:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w4am7rvpk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 07 Feb 2024 13:40:01 +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 417DJ4Df026199 for ; Wed, 7 Feb 2024 13:40:00 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 3w4am7rvpf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Feb 2024 13:40:00 +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 417DaxRg014724; Wed, 7 Feb 2024 13:40:00 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w20tnwyf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Feb 2024 13:39:59 +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 417DdvDG21561966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Feb 2024 13:39:57 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E123D20040; Wed, 7 Feb 2024 13:39:56 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B92B62004D; Wed, 7 Feb 2024 13:39:56 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.152.222.239]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 7 Feb 2024 13:39:56 +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_H4,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 v2 09/11] api: add virNodeDeviceUpdate() Date: Wed, 7 Feb 2024 14:39:52 +0100 Message-ID: <20240207133954.86634-10-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207133954.86634-1-fiuczy@linux.ibm.com> References: <20240207133954.86634-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yEpTJOIVnWKQTQlh75rbE0VICrmbEDQx X-Proofpoint-ORIG-GUID: 89e8PTPgoVYUtPPzBY1yz_aR0cHSW2YE 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-07_04,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1015 mlxscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 spamscore=0 mlxlogscore=846 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402070101 Message-ID-Hash: MZLL6BNWRKZG6HKXX4EGC6XVFA2STSVL X-Message-ID-Hash: MZLL6BNWRKZG6HKXX4EGC6XVFA2STSVL 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: 1707313820452100001 This public API is implemented for almost all other objects that have a concept of persistent definition and activatability. Node devices (mdevs) that can be defined and inactive, it will be useful to be able to update defined and active node devices as well. Signed-off-by: Boris Fiuczynski --- include/libvirt/libvirt-nodedev.h | 18 +++++++++++++ src/access/viraccessperm.c | 1 + src/access/viraccessperm.h | 6 +++++ src/conf/virnodedeviceobj.c | 42 +++++++++++++++++++++++++++++ src/conf/virnodedeviceobj.h | 3 +++ src/driver-nodedev.h | 6 +++++ src/libvirt-nodedev.c | 45 +++++++++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libvirt_public.syms | 5 ++++ src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 17 +++++++++++- src/remote_protocol-structs | 6 +++++ 12 files changed, 150 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index f7ddbfa4ad..de1d5bcbc1 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -188,6 +188,24 @@ int virNodeDeviceIsPersistent(virNodeDevicePtr dev); =20 int virNodeDeviceIsActive(virNodeDevicePtr dev); =20 +/** + * virNodeDeviceUpdateXMLFlags: + * + * Flags to control options for virNodeDeviceUpdateXML() + * + * Since: 10.1.0 + */ +typedef enum { + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CURRENT =3D 0, /* affect live i= f node device is active, + config if it's = not active (Since: 10.1.0) */ + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE =3D 1 << 0, /* affect live s= tate of node device only (Since: 10.1.0) */ + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG =3D 1 << 1, /* affect persis= tent config only (Since: 10.1.0) */ +} virNodeDeviceUpdateXMLFlags; + +int virNodeDeviceUpdateXML(virNodeDevicePtr dev, + const char *xmlDesc, + unsigned int flags); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index d4a0c98b9b..702bee761d 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -71,6 +71,7 @@ VIR_ENUM_IMPL(virAccessPermNodeDevice, "getattr", "read", "write", "start", "stop", "detach", "delete", + "save", ); =20 VIR_ENUM_IMPL(virAccessPermNWFilter, diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index 2f04459ed9..6cc2140c67 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -507,6 +507,12 @@ typedef enum { */ VIR_ACCESS_PERM_NODE_DEVICE_DELETE, =20 + /** + * @desc: Save node device + * @message: Saving node device driver requires authorization + */ + VIR_ACCESS_PERM_NODE_DEVICE_SAVE, + VIR_ACCESS_PERM_NODE_DEVICE_LAST } virAccessPermNodeDevice; =20 diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 31ec4249d8..a8b1b625a7 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -1137,3 +1137,45 @@ virNodeDeviceObjListFind(virNodeDeviceObjList *devs, virNodeDeviceObjListFindHelper, &data); } + + +/** + * virNodeDeviceObjUpdateModificationImpact: + * @obj: Pointer to node device object + * @flags: flags to update the modification impact on + * + * Resolves virNodeDeviceObjUpdateModificationImpact flags in @flags so th= at + * they correctly apply to the actual state of @obj. @flags may be modified + * after call to this function. + * + * Returns 0 on success if @flags point to a valid combination for @obj or= -1 + * on error. + */ +int +virNodeDeviceObjUpdateModificationImpact(virNodeDeviceObj *obj, + unsigned int *flags) +{ + bool isActive =3D virNodeDeviceObjIsActive(obj); + + if ((*flags & (VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE | VIR_NODE_DEVIC= E_UPDATE_XML_AFFECT_CONFIG)) =3D=3D + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CURRENT) { + if (isActive) + *flags |=3D VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE; + else + *flags |=3D VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG; + } + + if (!isActive && (*flags & VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("mdev is not active")); + return -1; + } + + if (!virNodeDeviceObjIsPersistent(obj) && (*flags & VIR_NODE_DEVICE_UP= DATE_XML_AFFECT_CONFIG)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("transient mdevs do not have any persistent confi= g")); + return -1; + } + + return 0; +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index ba2e424998..43889b8dc8 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -159,3 +159,6 @@ virNodeDeviceObj * virNodeDeviceObjListFind(virNodeDeviceObjList *devs, virNodeDeviceObjListPredicate callback, void *opaque); + +int virNodeDeviceObjUpdateModificationImpact(virNodeDeviceObj *obj, + unsigned int *flags); diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index 167a8166dd..1c6a731f4e 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -101,6 +101,11 @@ typedef int typedef int (*virDrvNodeDeviceIsActive)(virNodeDevicePtr dev); =20 +typedef int +(*virDrvNodeDeviceUpdateXML)(virNodeDevicePtr dev, + const char *xmlDesc, + unsigned int flags); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -146,4 +151,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceGetAutostart nodeDeviceGetAutostart; virDrvNodeDeviceIsPersistent nodeDeviceIsPersistent; virDrvNodeDeviceIsActive nodeDeviceIsActive; + virDrvNodeDeviceUpdateXML nodeDeviceUpdateXML; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index c683b2eef9..064ee48650 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -1174,3 +1174,48 @@ int virNodeDeviceIsActive(virNodeDevicePtr dev) virDispatchError(dev->conn); return -1; } + + +/** + * virNodeDeviceUpdateXML: + * @dev: pointer to the node device object + * @xmlDesc: string containing an XML description of the device to be defi= ned + * @flags: bitwise OR of virNodeDeviceUpdateXMLFlags + * + * Update the definition of an existing node device, either its live + * running configuration, its persistent configuration, or both. + * + * Returns 0 in case of success, -1 in case of error + * + * Since: 10.1.0 + */ +int +virNodeDeviceUpdateXML(virNodeDevicePtr dev, + const char *xmlDesc, + unsigned int flags) +{ + VIR_DEBUG("nodeDevice=3D%p, xmlDesc=3D%s, flags=3D0x%x", + dev, NULLSTR(xmlDesc), flags); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + + virCheckReadOnlyGoto(dev->conn->flags, error); + virCheckNonNullArgGoto(xmlDesc, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceUpdateXML) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceUpdateXML(de= v, xmlDesc, flags); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c398371734..fae873aba0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1373,6 +1373,7 @@ virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; virNodeDeviceObjSetAutostart; virNodeDeviceObjSetPersistent; +virNodeDeviceObjUpdateModificationImpact; =20 =20 # conf/virnwfilterbindingdef.h diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index bd1e916d2a..8b53eeb2ee 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -938,4 +938,9 @@ LIBVIRT_9.7.0 { virNetworkSetMetadata; } LIBVIRT_9.0.0; =20 +LIBVIRT_10.1.0 { + global: + virNodeDeviceUpdateXML; +} LIBVIRT_9.7.0; + # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index bedf2cb833..ca7e125141 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7983,6 +7983,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceSetAutostart =3D remoteNodeDeviceSetAutostart, /* 7.8.0 */ .nodeDeviceIsPersistent =3D remoteNodeDeviceIsPersistent, /* 7.8.0 */ .nodeDeviceIsActive =3D remoteNodeDeviceIsActive, /* 7.8.0 */ + .nodeDeviceUpdateXML =3D remoteNodeDeviceUpdateXML, /* 10.1.0 */ }; =20 static virNWFilterDriver nwfilter_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index e295b0acc3..e95f672daf 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2237,6 +2237,12 @@ struct remote_node_device_is_active_ret { int active; }; =20 +struct remote_node_device_update_xml_args { + remote_nonnull_string name; + remote_nonnull_string xml_desc; + unsigned int flags; +}; + =20 /* * Events Register/Deregister: @@ -7021,5 +7027,14 @@ enum remote_procedure { * @generate: both * @acl: none */ - REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446 + REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446, + + /** + * @generate: both + * @priority: high + * @acl: node_device:write + * @acl: node_device:save:!VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG|VI= R_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE + * @acl: node_device:save:VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG + */ + REMOTE_PROC_NODE_DEVICE_UPDATE_XML =3D 447 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 924ca41825..9a1b881caf 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1673,6 +1673,11 @@ struct remote_node_device_is_active_args { struct remote_node_device_is_active_ret { int active; }; +struct remote_node_device_update_xml_args { + remote_nonnull_string name; + remote_nonnull_string xml_desc; + u_int flags; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3743,4 +3748,5 @@ enum remote_procedure { REMOTE_PROC_NETWORK_SET_METADATA =3D 444, REMOTE_PROC_NETWORK_GET_METADATA =3D 445, REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446, + REMOTE_PROC_NODE_DEVICE_UPDATE_XML =3D 447, }; --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org