From nobody Thu May 9 14:07:19 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 1708095367979274.9467983472109; Fri, 16 Feb 2024 06:56:07 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D99C01D64; Fri, 16 Feb 2024 09:56:06 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 09D731883; Fri, 16 Feb 2024 09:53:22 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DAA7B1C76; Fri, 16 Feb 2024 09:53:08 -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 D3B751D12 for ; Fri, 16 Feb 2024 09:52:27 -0500 (EST) 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 41GDS9HJ009393 for ; Fri, 16 Feb 2024 14:52:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8m29rs7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:52:26 +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 41GDtgnP032295 for ; Fri, 16 Feb 2024 14:52:26 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 3wa8m29rry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:26 +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 41GEEmux009896; Fri, 16 Feb 2024 14:52:25 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6npmbguy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:25 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqK5b34603658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:22 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A31A720040; Fri, 16 Feb 2024 14:52:20 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7679C2004E; Fri, 16 Feb 2024 14:52:20 +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:20 +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 01/12] virmdev: prepare type and attributes for dual state Date: Fri, 16 Feb 2024 15:52:09 +0100 Message-ID: <20240216145220.5056-2-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-ORIG-GUID: 5KTaWCEpR0oRTawNlDea1n85KCzUJkHG X-Proofpoint-GUID: kI8PzNSTn3zTGNtsf8CzXbCU6rKO2D6- 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 impostorscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160119 Message-ID-Hash: MPBZZZREPRN3W6DLYXOUFNT7AC322K5G X-Message-ID-Hash: MPBZZZREPRN3W6DLYXOUFNT7AC322K5G 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: 1708095368906100001 Create a new structure holding type and attributes as these are modifable in a persisted mdev configuration and run out of sync with the active mdev configuration. Signed-off-by: Boris Fiuczynski --- src/conf/node_device_conf.c | 18 +++---- src/conf/node_device_conf.h | 4 +- src/node_device/node_device_driver.c | 70 ++++++++++++++-------------- src/node_device/node_device_udev.c | 2 +- src/util/virmdev.h | 6 +++ 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index b8c91d6ecd..59d69ff985 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -593,15 +593,15 @@ virNodeDeviceCapMdevDefFormat(virBuffer *buf, { size_t i; =20 - virBufferEscapeString(buf, "\n", data->mdev.type); + virBufferEscapeString(buf, "\n", data->mdev.dev_confi= g.type); virBufferEscapeString(buf, "%s\n", data->mdev.uuid); virBufferEscapeString(buf, "%s\n", data->mdev.parent_addr); virBufferAsprintf(buf, "\n", data->mdev.iommuGroupNumber); =20 - for (i =3D 0; i < data->mdev.nattributes; i++) { - virMediatedDeviceAttr *attr =3D data->mdev.attributes[i]; + for (i =3D 0; i < data->mdev.dev_config.nattributes; i++) { + virMediatedDeviceAttr *attr =3D data->mdev.dev_config.attributes[i= ]; virBufferAsprintf(buf, "\n", attr->name, attr->value); } @@ -2183,7 +2183,7 @@ virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr= ctxt, return -1; } =20 - VIR_APPEND_ELEMENT(mdev->attributes, mdev->nattributes, attr); + VIR_APPEND_ELEMENT(mdev->dev_config.attributes, mdev->dev_config.nattr= ibutes, attr); =20 return 0; } @@ -2202,7 +2202,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, =20 ctxt->node =3D node; =20 - if (!(mdev->type =3D virXPathString("string(./type[1]/@id)", ctxt))) { + if (!(mdev->dev_config.type =3D virXPathString("string(./type[1]/@id)"= , ctxt))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("missing type id attribute for '%1$s'"), def->nam= e); return -1; @@ -2577,11 +2577,11 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps) g_free(data->sg.path); break; case VIR_NODE_DEV_CAP_MDEV: - g_free(data->mdev.type); + g_free(data->mdev.dev_config.type); g_free(data->mdev.uuid); - for (i =3D 0; i < data->mdev.nattributes; i++) - virMediatedDeviceAttrFree(data->mdev.attributes[i]); - g_free(data->mdev.attributes); + for (i =3D 0; i < data->mdev.dev_config.nattributes; i++) + virMediatedDeviceAttrFree(data->mdev.dev_config.attributes[i]); + g_free(data->mdev.dev_config.attributes); g_free(data->mdev.parent_addr); break; case VIR_NODE_DEV_CAP_CSS_DEV: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 2b2c8f797e..f100496272 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -151,11 +151,9 @@ struct _virNodeDevCapSystem { =20 typedef struct _virNodeDevCapMdev virNodeDevCapMdev; struct _virNodeDevCapMdev { - char *type; unsigned int iommuGroupNumber; char *uuid; - virMediatedDeviceAttr **attributes; - size_t nattributes; + virMediatedDeviceConfig dev_config; char *parent_addr; bool autostart; }; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index a59cd0875d..1ee59d710b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -609,17 +609,17 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, c= har **buf) g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); const char *startval =3D mdev->autostart ? "auto" : "manual"; =20 - if (virJSONValueObjectAppendString(json, "mdev_type", mdev->type) < 0) + if (virJSONValueObjectAppendString(json, "mdev_type", mdev->dev_config= .type) < 0) return -1; =20 if (virJSONValueObjectAppendString(json, "start", startval) < 0) return -1; =20 - if (mdev->attributes) { + if (mdev->dev_config.attributes) { g_autoptr(virJSONValue) attributes =3D virJSONValueNewArray(); =20 - for (i =3D 0; i < mdev->nattributes; i++) { - virMediatedDeviceAttr *attr =3D mdev->attributes[i]; + for (i =3D 0; i < mdev->dev_config.nattributes; i++) { + virMediatedDeviceAttr *attr =3D mdev->dev_config.attributes[i]; g_autoptr(virJSONValue) jsonattr =3D virJSONValueNewObject(); =20 if (virJSONValueObjectAppendString(jsonattr, attr->name, attr-= >value) < 0) @@ -1129,7 +1129,7 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, mdev =3D &child->caps->data.mdev; mdev->uuid =3D g_strdup(uuid); mdev->parent_addr =3D g_strdup(parent); - mdev->type =3D + mdev->dev_config.type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type")); start =3D virJSONValueObjectGetString(props, "start"); mdev->autostart =3D STREQ_NULLABLE(start, "auto"); @@ -1140,8 +1140,8 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, size_t i; int nattrs =3D virJSONValueArraySize(attrs); =20 - mdev->attributes =3D g_new0(virMediatedDeviceAttr*, nattrs); - mdev->nattributes =3D nattrs; + mdev->dev_config.attributes =3D g_new0(virMediatedDeviceAttr*, nat= trs); + mdev->dev_config.nattributes =3D nattrs; =20 for (i =3D 0; i < nattrs; i++) { virJSONValue *attr =3D virJSONValueArrayGet(attrs, i); @@ -1156,7 +1156,7 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, attribute->name =3D g_strdup(virJSONValueObjectGetKey(attr, 0)= ); value =3D virJSONValueObjectGetValue(attr, 0); attribute->value =3D g_strdup(virJSONValueGetString(value)); - mdev->attributes[i] =3D attribute; + mdev->dev_config.attributes[i] =3D attribute; } } mdevGenerateDeviceName(child); @@ -1762,39 +1762,39 @@ nodeDeviceUpdateMediatedDevices(void) =20 /* returns true if any attributes were copied, else returns false */ static bool -virMediatedDeviceAttrsCopy(virNodeDevCapMdev *dst, - virNodeDevCapMdev *src) +virMediatedDeviceAttrsCopy(virMediatedDeviceConfig *dst_config, + virMediatedDeviceConfig *src_config) { bool ret =3D false; size_t i; =20 - if (src->nattributes !=3D dst->nattributes) { + if (src_config->nattributes !=3D dst_config->nattributes) { ret =3D true; - for (i =3D 0; i < dst->nattributes; i++) - virMediatedDeviceAttrFree(dst->attributes[i]); - g_free(dst->attributes); - - dst->nattributes =3D src->nattributes; - dst->attributes =3D g_new0(virMediatedDeviceAttr*, - src->nattributes); - for (i =3D 0; i < dst->nattributes; i++) - dst->attributes[i] =3D virMediatedDeviceAttrNew(); + for (i =3D 0; i < dst_config->nattributes; i++) + virMediatedDeviceAttrFree(dst_config->attributes[i]); + g_free(dst_config->attributes); + + dst_config->nattributes =3D src_config->nattributes; + dst_config->attributes =3D g_new0(virMediatedDeviceAttr*, + src_config->nattributes); + for (i =3D 0; i < dst_config->nattributes; i++) + dst_config->attributes[i] =3D virMediatedDeviceAttrNew(); } =20 - for (i =3D 0; i < src->nattributes; i++) { - if (STRNEQ_NULLABLE(src->attributes[i]->name, - dst->attributes[i]->name)) { + for (i =3D 0; i < src_config->nattributes; i++) { + if (STRNEQ_NULLABLE(src_config->attributes[i]->name, + dst_config->attributes[i]->name)) { ret =3D true; - g_free(dst->attributes[i]->name); - dst->attributes[i]->name =3D - g_strdup(src->attributes[i]->name); + g_free(dst_config->attributes[i]->name); + dst_config->attributes[i]->name =3D + g_strdup(src_config->attributes[i]->name); } - if (STRNEQ_NULLABLE(src->attributes[i]->value, - dst->attributes[i]->value)) { + if (STRNEQ_NULLABLE(src_config->attributes[i]->value, + dst_config->attributes[i]->value)) { ret =3D true; - g_free(dst->attributes[i]->value); - dst->attributes[i]->value =3D - g_strdup(src->attributes[i]->value); + g_free(dst_config->attributes[i]->value); + dst_config->attributes[i]->value =3D + g_strdup(src_config->attributes[i]->value); } } =20 @@ -1813,10 +1813,10 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, virNodeDevCapMdev *srcmdev =3D &src->caps->data.mdev; virNodeDevCapMdev *dstmdev =3D &dst->caps->data.mdev; =20 - if (STRNEQ_NULLABLE(dstmdev->type, srcmdev->type)) { + if (STRNEQ_NULLABLE(dstmdev->dev_config.type, srcmdev->dev_config.type= )) { ret =3D true; - g_free(dstmdev->type); - dstmdev->type =3D g_strdup(srcmdev->type); + g_free(dstmdev->dev_config.type); + dstmdev->dev_config.type =3D g_strdup(srcmdev->dev_config.type); } =20 if (STRNEQ_NULLABLE(dstmdev->uuid, srcmdev->uuid)) { @@ -1825,7 +1825,7 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, dstmdev->uuid =3D g_strdup(srcmdev->uuid); } =20 - if (virMediatedDeviceAttrsCopy(dstmdev, srcmdev)) + if (virMediatedDeviceAttrsCopy(&dstmdev->dev_config, &srcmdev->dev_con= fig)) ret =3D true; =20 if (dstmdev->autostart !=3D srcmdev->autostart) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index faddbef929..254e802c50 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1069,7 +1069,7 @@ udevProcessMediatedDevice(struct udev_device *dev, return -1; } =20 - data->type =3D g_path_get_basename(canonicalpath); + data->dev_config.type =3D g_path_get_basename(canonicalpath); =20 data->uuid =3D g_strdup(udev_device_get_sysname(dev)); if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(data->uuid)) < 0) diff --git a/src/util/virmdev.h b/src/util/virmdev.h index bc8306d0e1..853041ac06 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -47,6 +47,12 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceAttr, vir= MediatedDeviceAttrFree); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceList, virObjectUnref); =20 +typedef struct _virMediatedDeviceConfig virMediatedDeviceConfig; +struct _virMediatedDeviceConfig { + char *type; + virMediatedDeviceAttr **attributes; + size_t nattributes; +}; =20 typedef struct _virMediatedDeviceType virMediatedDeviceType; struct _virMediatedDeviceType { --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 170809650412248.62258385018265; Fri, 16 Feb 2024 07:15:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id CDD821E00; Fri, 16 Feb 2024 10:15:02 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E36321DF2; Fri, 16 Feb 2024 09:59:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B312A1827; Fri, 16 Feb 2024 09:58:33 -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 606701DA8 for ; Fri, 16 Feb 2024 09:56:19 -0500 (EST) 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 41GEtjif016437 for ; Fri, 16 Feb 2024 14:56:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa5ya4wff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:17 +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 41GEuFXI016910 for ; Fri, 16 Feb 2024 14:56:15 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 3wa5ya4wa9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:14 +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 41GEKYC2009712; Fri, 16 Feb 2024 14:52:25 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6p63bdm4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:25 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqKPO40370666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:23 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D43922004E; Fri, 16 Feb 2024 14:52:20 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ABBC72004F; Fri, 16 Feb 2024 14:52:20 +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:20 +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 02/12] node_device: refactor mdev attributes handling Date: Fri, 16 Feb 2024 15:52:10 +0100 Message-ID: <20240216145220.5056-3-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: dL0m5yKA1S16SGuAR1hGnCvH9iE9RLgO X-Proofpoint-ORIG-GUID: s22tpys9eB8sJ5ceU0NCQcdpM03hm5Up 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 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: F63GHSDRNMTDQCENBRXRUORX4GFPFEEM X-Message-ID-Hash: F63GHSDRNMTDQCENBRXRUORX4GFPFEEM 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: 1708096504910100001 Refactor attribute handling code into methods for easier reuse. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- src/conf/node_device_conf.c | 27 ++++--- src/node_device/node_device_driver.c | 104 ++++++++++++++++----------- 2 files changed, 80 insertions(+), 51 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 59d69ff985..a8554102fc 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -588,11 +588,22 @@ virNodeDeviceCapStorageDefFormat(virBuffer *buf, } =20 static void -virNodeDeviceCapMdevDefFormat(virBuffer *buf, - const virNodeDevCapData *data) +virNodeDeviceCapMdevAttrFormat(virBuffer *buf, + const virMediatedDeviceConfig *config) { size_t i; =20 + for (i =3D 0; i < config->nattributes; i++) { + virMediatedDeviceAttr *attr =3D config->attributes[i]; + virBufferAsprintf(buf, "\n", + attr->name, attr->value); + } +} + +static void +virNodeDeviceCapMdevDefFormat(virBuffer *buf, + const virNodeDevCapData *data) +{ virBufferEscapeString(buf, "\n", data->mdev.dev_confi= g.type); virBufferEscapeString(buf, "%s\n", data->mdev.uuid); virBufferEscapeString(buf, "%s\n", @@ -600,11 +611,7 @@ virNodeDeviceCapMdevDefFormat(virBuffer *buf, virBufferAsprintf(buf, "\n", data->mdev.iommuGroupNumber); =20 - for (i =3D 0; i < data->mdev.dev_config.nattributes; i++) { - virMediatedDeviceAttr *attr =3D data->mdev.dev_config.attributes[i= ]; - virBufferAsprintf(buf, "\n", - attr->name, attr->value); - } + virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.dev_config); } =20 static void @@ -2169,7 +2176,7 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, static int virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, - virNodeDevCapMdev *mdev) + virMediatedDeviceConfig *config) { VIR_XPATH_NODE_AUTORESTORE(ctxt) g_autoptr(virMediatedDeviceAttr) attr =3D virMediatedDeviceAttrNew(); @@ -2183,7 +2190,7 @@ virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr= ctxt, return -1; } =20 - VIR_APPEND_ELEMENT(mdev->dev_config.attributes, mdev->dev_config.nattr= ibutes, attr); + VIR_APPEND_ELEMENT(config->attributes, config->nattributes, attr); =20 return 0; } @@ -2234,7 +2241,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, return -1; =20 for (i =3D 0; i < nattrs; i++) - virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], mdev); + virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], &mdev->dev_conf= ig); =20 return 0; } diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 1ee59d710b..7118f833f6 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -599,27 +599,16 @@ nodeDeviceHasCapability(virNodeDeviceDef *def, virNod= eDevCapType type) } =20 =20 -/* format a json string that provides configuration information about this= mdev - * to the mdevctl utility */ static int -nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf) +nodeDeviceAttributesToJSON(virJSONValue *json, + virMediatedDeviceConfig *config) { size_t i; - virNodeDevCapMdev *mdev =3D &def->caps->data.mdev; - g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); - const char *startval =3D mdev->autostart ? "auto" : "manual"; - - if (virJSONValueObjectAppendString(json, "mdev_type", mdev->dev_config= .type) < 0) - return -1; - - if (virJSONValueObjectAppendString(json, "start", startval) < 0) - return -1; - - if (mdev->dev_config.attributes) { + if (config->attributes) { g_autoptr(virJSONValue) attributes =3D virJSONValueNewArray(); =20 - for (i =3D 0; i < mdev->dev_config.nattributes; i++) { - virMediatedDeviceAttr *attr =3D mdev->dev_config.attributes[i]; + for (i =3D 0; i < config->nattributes; i++) { + virMediatedDeviceAttr *attr =3D config->attributes[i]; g_autoptr(virJSONValue) jsonattr =3D virJSONValueNewObject(); =20 if (virJSONValueObjectAppendString(jsonattr, attr->name, attr-= >value) < 0) @@ -633,6 +622,28 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, ch= ar **buf) return -1; } =20 + return 0; +} + + +/* format a json string that provides configuration information about this= mdev + * to the mdevctl utility */ +static int +nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf) +{ + virNodeDevCapMdev *mdev =3D &def->caps->data.mdev; + g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); + const char *startval =3D mdev->autostart ? "auto" : "manual"; + + if (virJSONValueObjectAppendString(json, "mdev_type", mdev->dev_config= .type) < 0) + return -1; + + if (virJSONValueObjectAppendString(json, "start", startval) < 0) + return -1; + + if (nodeDeviceAttributesToJSON(json, &mdev->dev_config) < 0) + return -1; + *buf =3D virJSONValueToString(json, false); if (!*buf) return -1; @@ -1092,6 +1103,39 @@ matchDeviceAddress(virNodeDeviceObj *obj, } =20 =20 +static int +nodeDeviceParseMdevctlAttributes(virMediatedDeviceConfig *config, + virJSONValue *attrs) +{ + size_t i; + + if (attrs && virJSONValueIsArray(attrs)) { + int nattrs =3D virJSONValueArraySize(attrs); + + config->attributes =3D g_new0(virMediatedDeviceAttr*, nattrs); + config->nattributes =3D nattrs; + + for (i =3D 0; i < nattrs; i++) { + virJSONValue *attr =3D virJSONValueArrayGet(attrs, i); + virMediatedDeviceAttr *attribute; + virJSONValue *value; + + if (!virJSONValueIsObject(attr) || + virJSONValueObjectKeysNumber(attr) !=3D 1) + return -1; + + attribute =3D g_new0(virMediatedDeviceAttr, 1); + attribute->name =3D g_strdup(virJSONValueObjectGetKey(attr, 0)= ); + value =3D virJSONValueObjectGetValue(attr, 0); + attribute->value =3D g_strdup(virJSONValueGetString(value)); + config->attributes[i] =3D attribute; + } + } + + return 0; +} + + static virNodeDeviceDef* nodeDeviceParseMdevctlChildDevice(const char *parent, virJSONValue *json) @@ -1099,7 +1143,6 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, virNodeDevCapMdev *mdev; const char *uuid; virJSONValue *props; - virJSONValue *attrs; g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); virNodeDeviceObj *parent_obj; const char *start =3D NULL; @@ -1134,31 +1177,10 @@ nodeDeviceParseMdevctlChildDevice(const char *paren= t, start =3D virJSONValueObjectGetString(props, "start"); mdev->autostart =3D STREQ_NULLABLE(start, "auto"); =20 - attrs =3D virJSONValueObjectGet(props, "attrs"); - - if (attrs && virJSONValueIsArray(attrs)) { - size_t i; - int nattrs =3D virJSONValueArraySize(attrs); - - mdev->dev_config.attributes =3D g_new0(virMediatedDeviceAttr*, nat= trs); - mdev->dev_config.nattributes =3D nattrs; - - for (i =3D 0; i < nattrs; i++) { - virJSONValue *attr =3D virJSONValueArrayGet(attrs, i); - virMediatedDeviceAttr *attribute; - virJSONValue *value; - - if (!virJSONValueIsObject(attr) || - virJSONValueObjectKeysNumber(attr) !=3D 1) - return NULL; + if (nodeDeviceParseMdevctlAttributes(&mdev->dev_config, + virJSONValueObjectGet(props, "att= rs")) < 0) + return NULL; =20 - attribute =3D g_new0(virMediatedDeviceAttr, 1); - attribute->name =3D g_strdup(virJSONValueObjectGetKey(attr, 0)= ); - value =3D virJSONValueObjectGetValue(attr, 0); - attribute->value =3D g_strdup(virJSONValueGetString(value)); - mdev->dev_config.attributes[i] =3D attribute; - } - } mdevGenerateDeviceName(child); =20 return g_steal_pointer(&child); --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708096354820714.5394936688716; Fri, 16 Feb 2024 07:12:34 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C000C1D85; Fri, 16 Feb 2024 10:12:33 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CCF691DD5; Fri, 16 Feb 2024 09:59:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 981DA1D0D; Fri, 16 Feb 2024 09:58:26 -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 124891DA5 for ; Fri, 16 Feb 2024 09:56:18 -0500 (EST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41GEu8sf011926 for ; Fri, 16 Feb 2024 14:56:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8rfhnwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:17 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41GEuDxr012319 for ; Fri, 16 Feb 2024 14:56:13 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 3wa8rfhnmm-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 (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 41GCS3TQ004251; Fri, 16 Feb 2024 14:52:26 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6kv0v3q1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:26 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqLFk23331376 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:23 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 071402004F; Fri, 16 Feb 2024 14:52:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD0F22005A; Fri, 16 Feb 2024 14:52:20 +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:20 +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 03/12] node_device: remove unnecessary checks in virNodeDeviceDefFormat Date: Fri, 16 Feb 2024 15:52:11 +0100 Message-ID: <20240216145220.5056-4-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: ky5vrUqSOUW9_9U-Sf6dqmhDW_GeA85K X-Proofpoint-ORIG-GUID: JnPnDq_iaG9HMBJMsXzNQqFqGuOmPmGM 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 mlxscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=891 malwarescore=0 bulkscore=0 adultscore=0 clxscore=1015 spamscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: 2GD32CCHKYKPUCKZMQ7SRJNTKGNPMTO2 X-Message-ID-Hash: 2GD32CCHKYKPUCKZMQ7SRJNTKGNPMTO2 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: 1708096356383100001 virBufferEscapeString already contains the null check. Signed-off-by: Boris Fiuczynski --- src/conf/node_device_conf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index a8554102fc..febc58afd1 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -672,16 +672,14 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferAdjustIndent(&buf, 2); virBufferEscapeString(&buf, "%s\n", def->name); virBufferEscapeString(&buf, "%s\n", def->sysfs_path); - if (def->devnode) - virBufferEscapeString(&buf, "%s\n", - def->devnode); + virBufferEscapeString(&buf, "%s\n", + def->devnode); if (def->devlinks) { for (i =3D 0; def->devlinks[i]; i++) virBufferEscapeString(&buf, "%s\n", def->devlinks[i]); } - if (def->parent) - virBufferEscapeString(&buf, "%s\n", def->parent); + virBufferEscapeString(&buf, "%s\n", def->parent); if (def->driver) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708096860270232.9785587964817; Fri, 16 Feb 2024 07:21:00 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 10CF31E25; Fri, 16 Feb 2024 10:20:59 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9686E1C38; Fri, 16 Feb 2024 09:59:30 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DFF591D5F; Fri, 16 Feb 2024 09:58:45 -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 E16311D02 for ; Fri, 16 Feb 2024 09:56:19 -0500 (EST) 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 41GEuC8Q001191 for ; Fri, 16 Feb 2024 14:56:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa7vctm1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:18 +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 41GEuINs001719 for ; Fri, 16 Feb 2024 14:56:18 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 3wa7vctkwa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:17 +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 41GDa3LV016203; Fri, 16 Feb 2024 14:52:27 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6myn3sx7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:26 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqLhu18547316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:23 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4178C20065; Fri, 16 Feb 2024 14:52:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0FBFC20063; Fri, 16 Feb 2024 14:52:21 +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:21 +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 04/12] nodedev: add an active config to mdev Date: Fri, 16 Feb 2024 15:52:12 +0100 Message-ID: <20240216145220.5056-5-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-ORIG-GUID: hqmEPueh68rYsuHygLOhajMGeZLKNyl2 X-Proofpoint-GUID: Yaj9zUCogDM9mGv54_MotjnV8Pg6KO7X 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 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 adultscore=0 clxscore=1015 impostorscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: LPS3UMP7EVVH2L52YPHBUQN2TWPGM23A X-Message-ID-Hash: LPS3UMP7EVVH2L52YPHBUQN2TWPGM23A 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: 1708096862459100001 The configuration of a defined mdev can be modified after the mdev is started. The defined configuration and the active configuration can therefore run out of sync. Handle this by storing the modifiable data which is the mdev type and attributes in two separate active and defined configurations. mdevctl supports with callout scripts to do an attribute retrieval of started mdevs which is already implemented in libvirt. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 11 ++++ src/conf/node_device_conf.c | 53 ++++++++++------ src/conf/node_device_conf.h | 5 +- src/libvirt-nodedev.c | 2 +- src/node_device/node_device_driver.c | 61 +++++++++++++------ src/node_device/node_device_driver.h | 6 +- src/node_device/node_device_udev.c | 4 +- src/test/test_driver.c | 6 +- tests/nodedevmdevctltest.c | 4 +- ...v_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml | 14 +++++ ...d_b7f0_4fea_b468_f1da537d301b_inactive.xml | 1 + ...v_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml | 10 +++ ...c_c60c_c60c_c60c_c60cc60cc60c_inactive.xml | 9 +++ ...9_36ea_4111_8f0a_8c9a70e21366_inactive.xml | 1 + ...9_495e_4243_ad9f_beb3f14c23d9_inactive.xml | 1 + ...4_f554_4dc1_809d_b2a01e8e48ad_inactive.xml | 8 +++ ...6_1ca8_49ac_b176_871d16c13076_inactive.xml | 1 + tests/nodedevxml2xmltest.c | 59 +++++++++++++++--- 18 files changed, 197 insertions(+), 59 deletions(-) create mode 100644 tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c6= 0cc60cc60c.xml create mode 120000 tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1= da537d301b_inactive.xml create mode 100644 tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c6= 0cc60cc60c.xml create mode 100644 tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c6= 0cc60cc60c_inactive.xml create mode 120000 tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366_inactive.xml create mode 120000 tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9_inactive.xml create mode 100644 tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2= a01e8e48ad_inactive.xml create mode 120000 tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076_inactive.xml diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 428b0d722f..53ffce6c69 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -117,6 +117,17 @@ int virNodeDeviceListCaps (virN= odeDevicePtr dev, char **const names, int maxnames); =20 +/** + * virNodeDeviceXMLFlags: + * + * Flags used to provide the state of the returned node device configurati= on. + * + * Since: 10.1.0 + */ +typedef enum { + VIR_NODE_DEVICE_XML_INACTIVE =3D 1 << 0, /* dump inactive d= evice configuration (Since: 10.1.0) */ +} virNodeDeviceXMLFlags; + char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev, unsigned int flags); =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index febc58afd1..4de29ef01f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -602,16 +602,22 @@ virNodeDeviceCapMdevAttrFormat(virBuffer *buf, =20 static void virNodeDeviceCapMdevDefFormat(virBuffer *buf, - const virNodeDevCapData *data) + const virNodeDevCapData *data, + bool defined) { - virBufferEscapeString(buf, "\n", data->mdev.dev_confi= g.type); + if (defined) + virBufferEscapeString(buf, "\n", data->mdev.defin= ed_config.type); + else + virBufferEscapeString(buf, "\n", data->mdev.activ= e_config.type); virBufferEscapeString(buf, "%s\n", data->mdev.uuid); virBufferEscapeString(buf, "%s\n", data->mdev.parent_addr); virBufferAsprintf(buf, "\n", data->mdev.iommuGroupNumber); - - virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.dev_config); + if (defined) + virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.defined_config); + else + virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.active_config); } =20 static void @@ -662,25 +668,28 @@ virNodeDeviceCapCSSDefFormat(virBuffer *buf, =20 =20 char * -virNodeDeviceDefFormat(const virNodeDeviceDef *def) +virNodeDeviceDefFormat(const virNodeDeviceDef *def, unsigned int flags) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; virNodeDevCapsDef *caps; size_t i =3D 0; + bool inactive_state =3D flags & VIR_NODE_DEVICE_XML_INACTIVE; =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); virBufferEscapeString(&buf, "%s\n", def->name); - virBufferEscapeString(&buf, "%s\n", def->sysfs_path); - virBufferEscapeString(&buf, "%s\n", - def->devnode); - if (def->devlinks) { - for (i =3D 0; def->devlinks[i]; i++) - virBufferEscapeString(&buf, "%s\n", - def->devlinks[i]); + if (!inactive_state) { + virBufferEscapeString(&buf, "%s\n", def->sysfs_path); + virBufferEscapeString(&buf, "%s\n", + def->devnode); + if (def->devlinks) { + for (i =3D 0; def->devlinks[i]; i++) + virBufferEscapeString(&buf, "%s\n", + def->devlinks[i]); + } } virBufferEscapeString(&buf, "%s\n", def->parent); - if (def->driver) { + if (def->driver && !inactive_state) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); virBufferEscapeString(&buf, "%s\n", def->driver); @@ -741,7 +750,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; case VIR_NODE_DEV_CAP_MDEV: - virNodeDeviceCapMdevDefFormat(&buf, data); + virNodeDeviceCapMdevDefFormat(&buf, data, inactive_state); break; case VIR_NODE_DEV_CAP_CCW_DEV: virNodeDeviceCapCCWDefFormat(&buf, data); @@ -2207,7 +2216,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, =20 ctxt->node =3D node; =20 - if (!(mdev->dev_config.type =3D virXPathString("string(./type[1]/@id)"= , ctxt))) { + if (!(mdev->defined_config.type =3D virXPathString("string(./type[1]/@= id)", ctxt))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("missing type id attribute for '%1$s'"), def->nam= e); return -1; @@ -2239,7 +2248,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, return -1; =20 for (i =3D 0; i < nattrs; i++) - virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], &mdev->dev_conf= ig); + virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], &mdev->defined_= config); =20 return 0; } @@ -2582,11 +2591,15 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps) g_free(data->sg.path); break; case VIR_NODE_DEV_CAP_MDEV: - g_free(data->mdev.dev_config.type); + 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.dev_config.nattributes; i++) - virMediatedDeviceAttrFree(data->mdev.dev_config.attributes[i]); - g_free(data->mdev.dev_config.attributes); + 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); g_free(data->mdev.parent_addr); break; case VIR_NODE_DEV_CAP_CSS_DEV: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index f100496272..f59440dbb9 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -153,7 +153,8 @@ typedef struct _virNodeDevCapMdev virNodeDevCapMdev; struct _virNodeDevCapMdev { unsigned int iommuGroupNumber; char *uuid; - virMediatedDeviceConfig dev_config; + virMediatedDeviceConfig defined_config; + virMediatedDeviceConfig active_config; char *parent_addr; bool autostart; }; @@ -360,7 +361,7 @@ struct _virNodeDeviceDef { }; =20 char * -virNodeDeviceDefFormat(const virNodeDeviceDef *def); +virNodeDeviceDefFormat(const virNodeDeviceDef *def, unsigned int flags); =20 =20 typedef int (*virNodeDeviceDefPostParseCallback)(virNodeDeviceDef *dev, diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index f0f99bc020..c683b2eef9 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -264,7 +264,7 @@ virNodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, /** * virNodeDeviceGetXMLDesc: * @dev: pointer to the node device - * @flags: extra flags; not used yet, so callers should always pass 0 + * @flags: bitwise-OR of virNodeDeviceXMLFlags * * Fetch an XML document describing all aspects of * the device. diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 7118f833f6..baff49a0ae 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -338,7 +338,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, virNodeDeviceDef *def; char *ret =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_XML_INACTIVE, NULL); =20 if (nodeDeviceInitWait() < 0) return NULL; @@ -356,7 +356,19 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, if (virNodeDeviceUpdateCaps(def) < 0) goto cleanup; =20 - ret =3D virNodeDeviceDefFormat(def); + if (flags & VIR_NODE_DEVICE_XML_INACTIVE) { + if (!virNodeDeviceObjIsPersistent(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("node device '%1$s' is not persistent"), + def->name); + goto cleanup; + } + } else { + if (!virNodeDeviceObjIsActive(obj)) + flags |=3D VIR_NODE_DEVICE_XML_INACTIVE; + } + + ret =3D virNodeDeviceDefFormat(def, flags); =20 cleanup: virNodeDeviceObjEndAPI(&obj); @@ -629,19 +641,20 @@ nodeDeviceAttributesToJSON(virJSONValue *json, /* format a json string that provides configuration information about this= mdev * to the mdevctl utility */ static int -nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf) +nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf, bool defin= ed) { virNodeDevCapMdev *mdev =3D &def->caps->data.mdev; + virMediatedDeviceConfig *mdev_config =3D defined ? &mdev->defined_conf= ig : &mdev->active_config; g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); const char *startval =3D mdev->autostart ? "auto" : "manual"; =20 - if (virJSONValueObjectAppendString(json, "mdev_type", mdev->dev_config= .type) < 0) + if (virJSONValueObjectAppendString(json, "mdev_type", mdev_config->typ= e) < 0) return -1; =20 if (virJSONValueObjectAppendString(json, "start", startval) < 0) return -1; =20 - if (nodeDeviceAttributesToJSON(json, &mdev->dev_config) < 0) + if (nodeDeviceAttributesToJSON(json, mdev_config) < 0) return -1; =20 *buf =3D virJSONValueToString(json, false); @@ -760,7 +773,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, return NULL; } =20 - if (nodeDeviceDefToMdevctlConfig(def, &inbuf) < 0) { + if (nodeDeviceDefToMdevctlConfig(def, &inbuf, true) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("couldn't convert node device def to mdevctl = JSON")); return NULL; @@ -1138,9 +1151,11 @@ nodeDeviceParseMdevctlAttributes(virMediatedDeviceCo= nfig *config, =20 static virNodeDeviceDef* nodeDeviceParseMdevctlChildDevice(const char *parent, - virJSONValue *json) + virJSONValue *json, + bool defined) { virNodeDevCapMdev *mdev; + virMediatedDeviceConfig *mdev_config; const char *uuid; virJSONValue *props; g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); @@ -1170,14 +1185,15 @@ nodeDeviceParseMdevctlChildDevice(const char *paren= t, child->caps->data.type =3D VIR_NODE_DEV_CAP_MDEV; =20 mdev =3D &child->caps->data.mdev; + mdev_config =3D defined ? &mdev->defined_config : &mdev->active_config; mdev->uuid =3D g_strdup(uuid); mdev->parent_addr =3D g_strdup(parent); - mdev->dev_config.type =3D + mdev_config->type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type")); start =3D virJSONValueObjectGetString(props, "start"); mdev->autostart =3D STREQ_NULLABLE(start, "auto"); =20 - if (nodeDeviceParseMdevctlAttributes(&mdev->dev_config, + if (nodeDeviceParseMdevctlAttributes(mdev_config, virJSONValueObjectGet(props, "att= rs")) < 0) return NULL; =20 @@ -1189,7 +1205,8 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, =20 int nodeDeviceParseMdevctlJSON(const char *jsonstring, - virNodeDeviceDef ***devs) + virNodeDeviceDef ***devs, + bool defined) { int n; g_autoptr(virJSONValue) json_devicelist =3D NULL; @@ -1259,7 +1276,7 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, g_autoptr(virNodeDeviceDef) child =3D NULL; virJSONValue *child_obj =3D virJSONValueArrayGet(child_array, = j); =20 - if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj))) { + if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj, defined))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to parse child device")); goto error; @@ -1402,7 +1419,7 @@ nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *def, /* Active devices contain some additional information (e.g. sysfs * path) that is not provided by mdevctl, so re-use the existing * definition and copy over new mdev data */ - changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned); + changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned, defined); =20 if (was_defined && !changed) { /* if this device was already defined and the definition @@ -1672,7 +1689,7 @@ virMdevctlList(bool defined, return -1; } =20 - return nodeDeviceParseMdevctlJSON(output, devs); + return nodeDeviceParseMdevctlJSON(output, devs, defined); } =20 =20 @@ -1829,16 +1846,24 @@ virMediatedDeviceAttrsCopy(virMediatedDeviceConfig = *dst_config, * Returns true if anything was copied, else returns false */ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, - virNodeDeviceDef *src) + virNodeDeviceDef *src, + bool defined) { bool ret =3D false; virNodeDevCapMdev *srcmdev =3D &src->caps->data.mdev; virNodeDevCapMdev *dstmdev =3D &dst->caps->data.mdev; + virMediatedDeviceConfig *srcmdevconfig =3D &src->caps->data.mdev.activ= e_config; + virMediatedDeviceConfig *dstmdevconfig =3D &dst->caps->data.mdev.activ= e_config; + + if (defined) { + srcmdevconfig =3D &src->caps->data.mdev.defined_config; + dstmdevconfig =3D &dst->caps->data.mdev.defined_config; + } =20 - if (STRNEQ_NULLABLE(dstmdev->dev_config.type, srcmdev->dev_config.type= )) { + if (STRNEQ_NULLABLE(dstmdevconfig->type, srcmdevconfig->type)) { ret =3D true; - g_free(dstmdev->dev_config.type); - dstmdev->dev_config.type =3D g_strdup(srcmdev->dev_config.type); + g_free(dstmdevconfig->type); + dstmdevconfig->type =3D g_strdup(srcmdevconfig->type); } =20 if (STRNEQ_NULLABLE(dstmdev->uuid, srcmdev->uuid)) { @@ -1847,7 +1872,7 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, dstmdev->uuid =3D g_strdup(srcmdev->uuid); } =20 - if (virMediatedDeviceAttrsCopy(&dstmdev->dev_config, &srcmdev->dev_con= fig)) + if (virMediatedDeviceAttrsCopy(dstmdevconfig, srcmdevconfig)) ret =3D true; =20 if (dstmdev->autostart !=3D srcmdev->autostart) { diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index c7d5e22daf..4dce7e6f17 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -142,7 +142,8 @@ nodeDeviceGetMdevctlListCommand(bool defined, =20 int nodeDeviceParseMdevctlJSON(const char *jsonstring, - virNodeDeviceDef ***devs); + virNodeDeviceDef ***devs, + bool defined); =20 int nodeDeviceUpdateMediatedDevices(void); @@ -154,7 +155,8 @@ nodeDeviceGenerateName(virNodeDeviceDef *def, const char *s); =20 bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, - virNodeDeviceDef *src); + virNodeDeviceDef *src, + bool defined); =20 int nodeDeviceCreate(virNodeDevice *dev, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 254e802c50..57368a96c3 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1069,7 +1069,7 @@ udevProcessMediatedDevice(struct udev_device *dev, return -1; } =20 - data->dev_config.type =3D g_path_get_basename(canonicalpath); + data->active_config.type =3D g_path_get_basename(canonicalpath); =20 data->uuid =3D g_strdup(udev_device_get_sysname(dev)); if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(data->uuid)) < 0) @@ -1572,7 +1572,7 @@ udevAddOneDevice(struct udev_device *device) objdef =3D virNodeDeviceObjGetDef(obj); =20 if (is_mdev) - nodeDeviceDefCopyFromMdevctl(def, objdef); + nodeDeviceDefCopyFromMdevctl(def, objdef, false); =20 persistent =3D virNodeDeviceObjIsPersistent(obj); autostart =3D virNodeDeviceObjIsAutostart(obj); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ed545848af..ed0cdc0dab 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7514,12 +7514,12 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virNodeDeviceObj *obj; char *ret =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_XML_INACTIVE, NULL); =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) return NULL; =20 - ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj)); + ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj), flags); =20 virNodeDeviceObjEndAPI(&obj); return ret; @@ -7619,7 +7619,7 @@ testNodeDeviceMockCreateVport(testDriver *driver, "scsi_host11"))) goto cleanup; =20 - xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy)); + xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy), 0); virNodeDeviceObjEndAPI(&objcopy); if (!xml) goto cleanup; diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index e403328e5a..f49d668461 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -229,13 +229,13 @@ testMdevctlParse(const void *data) return -1; } =20 - if ((nmdevs =3D nodeDeviceParseMdevctlJSON(buf, &mdevs)) < 0) { + if ((nmdevs =3D nodeDeviceParseMdevctlJSON(buf, &mdevs, true)) < 0) { VIR_TEST_DEBUG("Unable to parse json for %s", filename); return -1; } =20 for (i =3D 0; i < nmdevs; i++) { - g_autofree char *devxml =3D virNodeDeviceDefFormat(mdevs[i]); + g_autofree char *devxml =3D virNodeDeviceDefFormat(mdevs[i], VIR_N= ODE_DEVICE_XML_INACTIVE); if (!devxml) goto cleanup; virBufferAddStr(&xmloutbuf, devxml); diff --git a/tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc= 60c.xml b/tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c= .xml new file mode 100644 index 0000000000..6926559efa --- /dev/null +++ b/tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml @@ -0,0 +1,14 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + /sys/devices/css0/0.0.0052/c60cc60c-c60c-c60c-c60c-c60cc60cc60c + css_0_0_0052 + + vfio_ccw_mdev + + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + 0.0.0052 + + + diff --git a/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d3= 01b_inactive.xml b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1d= a537d301b_inactive.xml new file mode 120000 index 0000000000..f8ec7d8a32 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b_ina= ctive.xml @@ -0,0 +1 @@ +mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc= 60c.xml b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c= .xml new file mode 100644 index 0000000000..82c60cc065 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml @@ -0,0 +1,10 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + /sys/devices/css0/0.0.0052/c60cc60c-c60c-c60c-c60c-c60cc60cc60c + css_0_0_0052 + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + + + diff --git a/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc= 60c_inactive.xml b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60= cc60cc60c_inactive.xml new file mode 100644 index 0000000000..87c5ed1340 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_ina= ctive.xml @@ -0,0 +1,9 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + css_0_0_0052 + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + + + diff --git a/tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c9a70e21= 366_inactive.xml b/tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c9= a70e21366_inactive.xml new file mode 120000 index 0000000000..f6d5789399 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366_ina= ctive.xml @@ -0,0 +1 @@ +mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_beb3f14c2= 3d9_inactive.xml b/tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_beb= 3f14c23d9_inactive.xml new file mode 120000 index 0000000000..233a7506fb --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9_ina= ctive.xml @@ -0,0 +1 @@ +mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e4= 8ad_inactive.xml b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a= 01e8e48ad_inactive.xml new file mode 100644 index 0000000000..8c4983f43c --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad_ina= ctive.xml @@ -0,0 +1,8 @@ + + mdev_ee0b88c4-f554-4dc1-809d-b2a01e8e48ad + ap_matrix + + + + + diff --git a/tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_871d16c13= 076_inactive.xml b/tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_871= d16c13076_inactive.xml new file mode 120000 index 0000000000..e053844177 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_871d16c13076_ina= ctive.xml @@ -0,0 +1 @@ +mdev_fedc4916_1ca8_49ac_b176_871d16c13076.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index 068ec68769..10e88f7779 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -11,14 +11,20 @@ =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 +struct TestData { + const char *filename; + unsigned int flags; +}; + static int -testCompareXMLToXMLFiles(const char *xml, const char *outfile) +testCompareXMLToXMLFiles(const char *xml, const char *outfile, unsigned in= t flags) { g_autofree char *xmlData =3D NULL; g_autofree char *actual =3D NULL; int ret =3D -1; virNodeDeviceDef *dev =3D NULL; virNodeDevCapsDef *caps; + size_t i; =20 if (virTestLoadFile(xml, &xmlData) < 0) goto fail; @@ -46,9 +52,22 @@ testCompareXMLToXMLFiles(const char *xml, const char *ou= tfile) data->storage.logical_block_siz= e; } } + + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV && + !(flags & VIR_NODE_DEVICE_XML_INACTIVE)) { + data->mdev.active_config.type =3D g_strdup(data->mdev.defined_= config.type); + for (i =3D 0; i < data->mdev.defined_config.nattributes; i++) { + g_autoptr(virMediatedDeviceAttr) attr =3D g_new0(virMediat= edDeviceAttr, 1); + attr->name =3D g_strdup(data->mdev.defined_config.attribut= es[i]->name); + attr->value =3D g_strdup(data->mdev.defined_config.attribu= tes[i]->value); + VIR_APPEND_ELEMENT(data->mdev.active_config.attributes, + data->mdev.active_config.nattributes, + attr); + } + } } =20 - if (!(actual =3D virNodeDeviceDefFormat(dev))) + if (!(actual =3D virNodeDeviceDefFormat(dev, flags))) goto fail; =20 if (virTestCompareToFile(actual, outfile) < 0) @@ -65,16 +84,21 @@ static int testCompareXMLToXMLHelper(const void *data) { int result =3D -1; + const struct TestData *tdata =3D data; g_autofree char *xml =3D NULL; g_autofree char *outfile =3D NULL; =20 xml =3D g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, - (const char *)data); + tdata->filename); =20 - outfile =3D g_strdup_printf("%s/nodedevxml2xmlout/%s.xml", abs_srcdir, - (const char *)data); + if (tdata->flags & VIR_NODE_DEVICE_XML_INACTIVE) + outfile =3D g_strdup_printf("%s/nodedevxml2xmlout/%s_inactive.xml"= , abs_srcdir, + tdata->filename); + else + outfile =3D g_strdup_printf("%s/nodedevxml2xmlout/%s.xml", abs_src= dir, + tdata->filename); =20 - result =3D testCompareXMLToXMLFiles(xml, outfile); + result =3D testCompareXMLToXMLFiles(xml, outfile, tdata->flags); =20 return result; } @@ -85,10 +109,20 @@ mymain(void) { int ret =3D 0; =20 +#define DO_TEST_FLAGS(desc, filename, flags) \ + do { \ + struct TestData data =3D { filename, flags }; \ + if (virTestRun(desc, testCompareXMLToXMLHelper, &data) < 0) \ + ret =3D -1; \ + } \ + while (0) + #define DO_TEST(name) \ - if (virTestRun("Node device XML-2-XML " name, \ - testCompareXMLToXMLHelper, (name)) < 0) \ - ret =3D -1 + DO_TEST_FLAGS("Node device XML-2-XML " name, name, 0) + +#define DO_TEST_INACTIVE(name) \ + DO_TEST_FLAGS("Node device XML-2-XML INACTIVE " name, \ + name, VIR_NODE_DEVICE_XML_INACTIVE) =20 DO_TEST("computer"); DO_TEST("DVD_GCC_4247N"); @@ -121,6 +155,7 @@ mymain(void) DO_TEST("pci_0000_02_10_7_mdev_types"); DO_TEST("pci_0000_42_00_0_vpd"); DO_TEST("mdev_3627463d_b7f0_4fea_b468_f1da537d301b"); + DO_TEST_INACTIVE("mdev_3627463d_b7f0_4fea_b468_f1da537d301b"); DO_TEST("ccw_0_0_ffff"); DO_TEST("css_0_0_ffff"); DO_TEST("css_0_0_ffff_channel_dev_addr"); @@ -134,7 +169,13 @@ mymain(void) DO_TEST("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); DO_TEST("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); DO_TEST("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST_INACTIVE("mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad"); + DO_TEST_INACTIVE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_INACTIVE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); + DO_TEST_INACTIVE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST("hba_vport_ops"); + DO_TEST("mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c"); + DO_TEST_INACTIVE("mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708095876635190.00519393946013; Fri, 16 Feb 2024 07:04:36 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8AE601CD0; Fri, 16 Feb 2024 10:04:35 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9CA2B1D12; Fri, 16 Feb 2024 09:58:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id CD3EF1CF8; Fri, 16 Feb 2024 09:58:00 -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 6B43C1D28 for ; Fri, 16 Feb 2024 09:55:36 -0500 (EST) 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 41GEtUeT024390 for ; Fri, 16 Feb 2024 14:55:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8ym1eap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:55:35 +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 41GEtZgk024587 for ; Fri, 16 Feb 2024 14:55:35 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 3wa8ym1dp4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:55:33 +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 41GDJ30X016184; Fri, 16 Feb 2024 14:52:26 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6myn3sx5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:26 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqL7g17892092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:23 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AFA220063; Fri, 16 Feb 2024 14:52:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A13720067; Fri, 16 Feb 2024 14:52:21 +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:21 +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 05/12] tools: add option inactive to nodedev-dumpxml Date: Fri, 16 Feb 2024 15:52:13 +0100 Message-ID: <20240216145220.5056-6-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: Y1K1vuvY3vVl_bYDl5np8y2u8WnN_Nd3 X-Proofpoint-ORIG-GUID: pP5cMdoDtJvj4hM1kBHemJbxSgCvOnZw 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 impostorscore=0 mlxscore=0 bulkscore=0 mlxlogscore=831 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160119 Message-ID-Hash: MY6B63JLVU66V6QRS36Q6LJKWJRS6VVL X-Message-ID-Hash: MY6B63JLVU66V6QRS36Q6LJKWJRS6VVL 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: 1708095877847100001 Allow to dump the XML of the persisted mdev when the mdev has been started instead of the current state only. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- docs/manpages/virsh.rst | 7 +++++-- tools/virsh-nodedev.c | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index ed1027e133..3a814dccd2 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5422,14 +5422,17 @@ nodedev-dumpxml =20 :: =20 - nodedev-dumpxml [--xpath EXPRESSION] [--wrap] device + nodedev-dumpxml [--inactive] [--xpath EXPRESSION] [--wrap] device =20 Dump a XML representation for the given node device, including such information as the device name, which bus owns the device, the vendor and product id, and any capabilities of the device usable by libvirt (such as whether device reset is supported). *device* can be either device name or wwn pair in "wwnn,wwpn" format (only works -for HBA). +for HBA). An additional option affecting the XML dump may be +used. *--inactive* tells virsh to dump the node device configuration +that will be used on next start of the node device as opposed to the +current node device configuration. =20 If the **--xpath** argument provides an XPath expression, it will be evaluated against the output XML and only those matching nodes will diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index fb38fd7fcc..aeb3685aca 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -575,6 +575,10 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = =3D { .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format"), .completer =3D virshNodeDeviceNameCompleter, }, + {.name =3D "inactive", + .type =3D VSH_OT_BOOL, + .help =3D N_("show inactive defined XML"), + }, {.name =3D "xpath", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_REQ_OPT, @@ -594,6 +598,7 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshNodeDevice) device =3D NULL; g_autofree char *xml =3D NULL; const char *device_value =3D NULL; + unsigned int flags =3D 0; bool wrap =3D vshCommandOptBool(cmd, "wrap"); const char *xpath =3D NULL; =20 @@ -608,7 +613,10 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cm= d) if (!device) return false; =20 - if (!(xml =3D virNodeDeviceGetXMLDesc(device, 0))) + if (vshCommandOptBool(cmd, "inactive")) + flags |=3D VIR_NODE_DEVICE_XML_INACTIVE; + + if (!(xml =3D virNodeDeviceGetXMLDesc(device, flags))) return false; =20 return virshDumpXML(ctl, xml, "node-device", xpath, wrap); --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708097011785905.9731726420417; Fri, 16 Feb 2024 07:23:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AA66B18DA; Fri, 16 Feb 2024 10:23:30 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8AFD21D11; Fri, 16 Feb 2024 09:59:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 460F31D5F; Fri, 16 Feb 2024 09:58:49 -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 84730540 for ; Fri, 16 Feb 2024 09:56:24 -0500 (EST) 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 41GEu9uC024454 for ; Fri, 16 Feb 2024 14:56:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8kn25m9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:22 +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 41GEuJaK025770 for ; Fri, 16 Feb 2024 14:56: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 3wa8kn251a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:17 +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 41GEnIvD032605; Fri, 16 Feb 2024 14:52:26 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6kfu43wp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:26 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqLZY38011182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:23 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95B8920067; Fri, 16 Feb 2024 14:52:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 729B22006A; Fri, 16 Feb 2024 14:52:21 +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:21 +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 06/12] nodedev: add persisted and transient filter on list Date: Fri, 16 Feb 2024 15:52:14 +0100 Message-ID: <20240216145220.5056-7-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-ORIG-GUID: DLyZUWK_Co9D0OQm86M-5XdaW7CtSmHp X-Proofpoint-GUID: 2bCrabK7cpLSvKIdUiYk4x27CMtzo3kf 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 mlxlogscore=818 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 phishscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: NYBGJKFSAV5GAJ4ONEJHBXYUJJB35PYE X-Message-ID-Hash: NYBGJKFSAV5GAJ4ONEJHBXYUJJB35PYE 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: 1708097013189100001 Allow to filter node devices based on their persisted or transient states. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 2 ++ src/conf/node_device_conf.h | 7 ++++++- src/conf/virnodedeviceobj.c | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 53ffce6c69..f7ddbfa4ad 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -91,6 +91,8 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX =3D 1 << 20, /* s390 A= P Matrix (Since: 7.0.0) */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPD =3D 1 << 21, /* Device= with VPD (Since: 7.9.0) */ =20 + VIR_CONNECT_LIST_NODE_DEVICES_PERSISTENT =3D 1 << 28, /* Persis= ted devices (Since: 10.1.0) */ + VIR_CONNECT_LIST_NODE_DEVICES_TRANSIENT =3D 1 << 29, /* Transi= ent devices (Since: 10.1.0) */ VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE =3D 1 << 30, /* Inacti= ve devices (Since: 7.3.0) */ VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE =3D 1U << 31, /* Activ= e devices (Since: 7.3.0) */ } virConnectListAllNodeDeviceFlags; diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index f59440dbb9..f0a5333881 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -432,9 +432,14 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevCapsDef, virNo= deDevCapsDefFree); VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE | \ VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE =20 +#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_PERSISTENT \ + VIR_CONNECT_LIST_NODE_DEVICES_PERSISTENT | \ + VIR_CONNECT_LIST_NODE_DEVICES_TRANSIENT + #define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL \ VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP | \ - VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE + VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE | \ + VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_PERSISTENT =20 int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHost *scsi_host); diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index cfef30d47e..31ec4249d8 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -911,6 +911,14 @@ virNodeDeviceObjMatch(virNodeDeviceObj *obj, return false; } =20 + if (flags & (VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_PERSISTENT)) { + if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_PERSISTENT) && + virNodeDeviceObjIsPersistent(obj)) || + (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_TRANSIENT) && + !virNodeDeviceObjIsPersistent(obj)))) + return false; + } + return true; } #undef MATCH --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708096610011730.7396263714298; Fri, 16 Feb 2024 07:16:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E6E4C18AD; Fri, 16 Feb 2024 10:16:48 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4D9D71D8D; Fri, 16 Feb 2024 09:59:21 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 217351D29; Fri, 16 Feb 2024 09:58:43 -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 020651BC5 for ; Fri, 16 Feb 2024 09:56:19 -0500 (EST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41GEuCqk012236 for ; Fri, 16 Feb 2024 14:56:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8rfhnxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:18 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41GEuEtV012414 for ; Fri, 16 Feb 2024 14:56:14 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 3wa8rfhnnb-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 (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 41GBq7Ha032600; Fri, 16 Feb 2024 14:52:28 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6kfu43wx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:28 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqNJC26804928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:25 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC89C2006E; Fri, 16 Feb 2024 14:52:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D9962006C; Fri, 16 Feb 2024 14:52:21 +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:21 +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 07/12] tools: add switches persisted and transient to nodedev-list Date: Fri, 16 Feb 2024 15:52:15 +0100 Message-ID: <20240216145220.5056-8-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: IJizQTAUnoGNEtupAj7xC3ZUqtQ-Zrvz X-Proofpoint-ORIG-GUID: ON_xuVcd6vIG-UuYg7MYb6aFdo2RC6Gt 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 mlxscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 adultscore=0 clxscore=1015 spamscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: 6GTYDYSDPGGYVSCI2NTTCBUTFUHZJZLH X-Message-ID-Hash: 6GTYDYSDPGGYVSCI2NTTCBUTFUHZJZLH 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: 1708096611396100001 Now that we can filter persisted and transient node devices in virConnectListAllNodeDevices(), add these switches also to the virsh nodedev-list command. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- docs/manpages/virsh.rst | 8 ++++++-- tools/virsh-nodedev.c | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 3a814dccd2..248807d0e9 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5461,7 +5461,7 @@ nodedev-list =20 :: =20 - nodedev-list [--cap capability] [--tree] [--inactive | --all] + nodedev-list [--cap capability] [--tree] [--inactive | --all] [--persis= tent | --transient] =20 List all of the devices available on the node that are known by libvirt. *cap* is used to filter the list by capability types, the types must be @@ -5470,7 +5470,11 @@ separated by comma, e.g. --cap pci,scsi. Valid capab= ility types include 'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm', 'mdev', 'mdev_types', 'ccw', 'css', 'ap_card', 'ap_queue', 'ap_matrix'. By default, only active devices are listed. *--inactive* is used to list only inactive -devices, and *-all* is used to list both active and inactive devices. +devices, and *--all* is used to list both active and inactive devices. +*--persistent* is used to list only persistent devices, and *--transient* = is +used to list only transient devices. Not providing *--persistent* or +*--transient* will list all devices unless filtered otherwise. *--transien= t* +is mutually exclusive with *--persistent* and *--inactive*. If *--tree* is used, the output is formatted in a tree representing parent= s of each node. *--tree* is mutually exclusive with all other options. =20 diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index aeb3685aca..5942c43689 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -390,6 +390,14 @@ static const vshCmdOptDef opts_node_list_devices[] =3D= { .type =3D VSH_OT_BOOL, .help =3D N_("list inactive & active devices") }, + {.name =3D "persistent", + .type =3D VSH_OT_BOOL, + .help =3D N_("list persistent devices") + }, + {.name =3D "transient", + .type =3D VSH_OT_BOOL, + .help =3D N_("list transient devices") + }, {.name =3D NULL} }; =20 @@ -407,6 +415,8 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G= _GNUC_UNUSED) int cap_type =3D -1; bool inactive =3D vshCommandOptBool(cmd, "inactive"); bool all =3D vshCommandOptBool(cmd, "all"); + bool persistent =3D vshCommandOptBool(cmd, "persistent"); + bool transient =3D vshCommandOptBool(cmd, "transient"); =20 ignore_value(vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str)); =20 @@ -420,8 +430,13 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd = G_GNUC_UNUSED) return false; } =20 - if (tree && (cap_str || inactive)) { - vshError(ctl, "%s", _("Option --tree is incompatible with --cap an= d --inactive")); + if (transient && (persistent || inactive)) { + vshError(ctl, "%s", _("Option --transient is incompatible with --p= ersistent and --inactive")); + return false; + } + + if (tree && (cap_str || inactive || persistent || transient)) { + vshError(ctl, "%s", _("Option --tree is incompatible with --cap, -= -inactive, --persistent and --transient")); return false; } =20 @@ -509,6 +524,11 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd = G_GNUC_UNUSED) if (!inactive) flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE; =20 + if (persistent) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_PERSISTENT; + if (transient) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_TRANSIENT; + if (!(list =3D virshNodeDeviceListCollect(ctl, caps, ncaps, flags))) { ret =3D false; goto cleanup; --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708096249367808.5442433064903; Fri, 16 Feb 2024 07:10:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4A2051CCE; Fri, 16 Feb 2024 10:10:48 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 940CB1DD2; Fri, 16 Feb 2024 09:58:52 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D35BD1CB3; Fri, 16 Feb 2024 09:58:19 -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 E0B661D91 for ; Fri, 16 Feb 2024 09:56:18 -0500 (EST) 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 41GEtk5e016458 for ; Fri, 16 Feb 2024 14:56:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa5ya4wfa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:17 +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 41GEuEqg016897 for ; Fri, 16 Feb 2024 14:56:15 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 3wa5ya4wba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:14 +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 41GD2l79016517; Fri, 16 Feb 2024 14:52:29 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6myn3sxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:28 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41GEqNY223331378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 14:52:25 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E355620043; Fri, 16 Feb 2024 14:52:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C549C20071; Fri, 16 Feb 2024 14:52:21 +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:21 +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 08/12] virsh: doc fix on nodedev-list Date: Fri, 16 Feb 2024 15:52:16 +0100 Message-ID: <20240216145220.5056-9-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: KqbhlH9bFvPNyrCUmEfSIUJo8MYvXNC7 X-Proofpoint-ORIG-GUID: sZdj5fo8aHsGOHAx1sFRkl6nVZQPo6yB 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 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: 3OV3JNLTRQUZSEIKOW3PM5O4RAXNMXTD X-Message-ID-Hash: 3OV3JNLTRQUZSEIKOW3PM5O4RAXNMXTD 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: 1708096249781100001 Commit 26136e3 allowed to use option all with option tree but did not update the manpage. Signed-off-by: Boris Fiuczynski --- docs/manpages/virsh.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 248807d0e9..bc0ad6542b 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5476,7 +5476,7 @@ used to list only transient devices. Not providing *-= -persistent* or *--transient* will list all devices unless filtered otherwise. *--transien= t* is mutually exclusive with *--persistent* and *--inactive*. If *--tree* is used, the output is formatted in a tree representing parent= s of -each node. *--tree* is mutually exclusive with all other options. +each node. *--tree* is mutually exclusive with all other options but *--al= l*. =20 =20 nodedev-reattach --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708095535416252.43987920367238; Fri, 16 Feb 2024 06:58:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6141D1CC4; Fri, 16 Feb 2024 09:58:54 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 71F4E17F9; Fri, 16 Feb 2024 09:53:33 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id E76BB1C2D; Fri, 16 Feb 2024 09:53:08 -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 27F4F1D26 for ; Fri, 16 Feb 2024 09:52:29 -0500 (EST) 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 41GDS8Lf009333 for ; Fri, 16 Feb 2024 14:52:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8m29rsq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:52:28 +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 41GElaZT004733 for ; Fri, 16 Feb 2024 14:52:27 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 3wa8m29rsc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:27 +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 41GC7WPh032572; Fri, 16 Feb 2024 14:52:27 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6kfu43wr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:26 +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 41GEqMGL590414 (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 223F62006C; 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 ECAC62005A; Fri, 16 Feb 2024 14:52:21 +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:21 +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 09/12] api: add virNodeDeviceUpdate() Date: Fri, 16 Feb 2024 15:52:17 +0100 Message-ID: <20240216145220.5056-10-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-ORIG-GUID: smo2LW7jvjsWoOJmC8bi_orBkTKgh5U1 X-Proofpoint-GUID: aLT7my0dfTXfX1LAihr20U07jyNylVb7 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 impostorscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160119 Message-ID-Hash: WP4C63FO5J5SIFJYORNCQU75742KVXT3 X-Message-ID-Hash: WP4C63FO5J5SIFJYORNCQU75742KVXT3 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: 1708095535736100001 A public API method which allows to update or modify objects is implemented for almost all other objects that have a concept of persistent definition and activatability. Currently node devices of type mdev can be persistent and active. This new method allows 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..ec26c7a5e1 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 +/** + * virNodeDeviceUpdateFlags: + * + * Flags to control options for virNodeDeviceUpdate() + * + * Since: 10.1.0 + */ +typedef enum { + VIR_NODE_DEVICE_UPDATE_AFFECT_CURRENT =3D 0, /* affect live if no= de device is active, + config if it's not = active (Since: 10.1.0) */ + VIR_NODE_DEVICE_UPDATE_AFFECT_LIVE =3D 1 << 0, /* affect live state= of node device only (Since: 10.1.0) */ + VIR_NODE_DEVICE_UPDATE_AFFECT_CONFIG =3D 1 << 1, /* affect persistent= config only (Since: 10.1.0) */ +} virNodeDeviceUpdateFlags; + +int virNodeDeviceUpdate(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..d0a6eab42b 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 virNodeDeviceUpdateFlags flags in @flags so that 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_AFFECT_LIVE | VIR_NODE_DEVICE_UP= DATE_AFFECT_CONFIG)) =3D=3D + VIR_NODE_DEVICE_UPDATE_AFFECT_CURRENT) { + if (isActive) + *flags |=3D VIR_NODE_DEVICE_UPDATE_AFFECT_LIVE; + else + *flags |=3D VIR_NODE_DEVICE_UPDATE_AFFECT_CONFIG; + } + + if (!isActive && (*flags & VIR_NODE_DEVICE_UPDATE_AFFECT_LIVE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("node device is not active")); + return -1; + } + + if (!virNodeDeviceObjIsPersistent(obj) && (*flags & VIR_NODE_DEVICE_UP= DATE_AFFECT_CONFIG)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("transient node devices do not have any persisten= t config")); + 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..eff989706b 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 +(*virDrvNodeDeviceUpdate)(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; + virDrvNodeDeviceUpdate nodeDeviceUpdate; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index c683b2eef9..b97c199a3a 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -1174,3 +1174,48 @@ int virNodeDeviceIsActive(virNodeDevicePtr dev) virDispatchError(dev->conn); return -1; } + + +/** + * virNodeDeviceUpdate: + * @dev: pointer to the node device object + * @xmlDesc: string containing an XML description of the device to be defi= ned + * @flags: bitwise OR of virNodeDeviceUpdateFlags + * + * Update the definition of an existing node device, either its live runni= ng + * configuration, its persistent configuration, or both. + * + * Returns 0 in case of success, -1 in case of error + * + * Since: 10.1.0 + */ +int +virNodeDeviceUpdate(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->nodeDeviceUpdate) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceUpdate(dev, = 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..0304b8f824 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: + virNodeDeviceUpdate; +} 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..f156475bd2 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 */ + .nodeDeviceUpdate =3D remoteNodeDeviceUpdate, /* 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..ffe865965d 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_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_AFFECT_CONFIG|VIR_NO= DE_DEVICE_UPDATE_AFFECT_LIVE + * @acl: node_device:save:VIR_NODE_DEVICE_UPDATE_AFFECT_CONFIG + */ + REMOTE_PROC_NODE_DEVICE_UPDATE =3D 447 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 924ca41825..ee2ec3e6fa 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_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 =3D 447, }; --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708097316201926.7738384256372; Fri, 16 Feb 2024 07:28:36 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1E4A51C4C; Fri, 16 Feb 2024 10:28:35 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5A2021E23; Fri, 16 Feb 2024 09:59:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 480751DF8; Fri, 16 Feb 2024 09:59:36 -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 4C6F01C15 for ; Fri, 16 Feb 2024 09:56:29 -0500 (EST) 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 41GEuEXV016820 for ; Fri, 16 Feb 2024 14:56:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa5ya4wjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:24 +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 41GEuLlN018108 for ; Fri, 16 Feb 2024 14:56: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 3wa5ya4wb4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:18 +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 41GD093G016479; Fri, 16 Feb 2024 14:52:28 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6myn3sxe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:52:28 +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 41GEqMEg27919020 (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 6C68C2005A; 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 2E80220073; 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 10/12] nodedev: Implement virNodeDeviceUpdate Date: Fri, 16 Feb 2024 15:52:18 +0100 Message-ID: <20240216145220.5056-11-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: bRlg7rm8X6SIGMAAhQaK9DuTrNFp4Nv0 X-Proofpoint-ORIG-GUID: w6jvNNHn79rPxgLVkkSBoUkBh9HnAKgF 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 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: AEYTXNSQHAFRSQFCXDDS44BXCCXVQUKI X-Message-ID-Hash: AEYTXNSQHAFRSQFCXDDS44BXCCXVQUKI 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: 1708097318461100001 Implement the API functions in the node device driver by using mdevctl modify with the options defined and live. Instead of increasing the minimum mdevctl version to 1.3.0 in spec file to ensure support exists in mdevctl the support is dynamically checked before using mdevctl. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- NEWS.rst | 7 + libvirt.spec.in | 1 + src/node_device/node_device_driver.c | 224 +++++++++++++++++- src/node_device/node_device_driver.h | 11 + src/node_device/node_device_udev.c | 1 + ...60c_c60c_c60c_c60c_c60cc60cc60c_update.xml | 16 ++ tests/nodedevmdevctldata/mdevctl-modify.argv | 25 ++ tests/nodedevmdevctldata/mdevctl-modify.json | 4 + tests/nodedevmdevctltest.c | 90 ++++++- 9 files changed, 376 insertions(+), 3 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdev_c60cc60c_c60c_c60c_c60c_c= 60cc60cc60c_update.xml create mode 100644 tests/nodedevmdevctldata/mdevctl-modify.argv create mode 100644 tests/nodedevmdevctldata/mdevctl-modify.json diff --git a/NEWS.rst b/NEWS.rst index e2796fd8b2..aa2fee3533 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -17,6 +17,13 @@ v10.1.0 (unreleased) =20 * **New features** =20 + * nodedev: Support updating mdevs + + The node device driver has been extended to allow updating mediated no= de + devices. Options are available to target the update against the persis= ted, + active or both configurations of an mediated device. + **Note:** The support is only available with at least mdevctl v1.3.0 i= nstalled. + * qemu: Support clusters in CPU topology =20 It is now possible to configure the guest CPU topology to use clusters. diff --git a/libvirt.spec.in b/libvirt.spec.in index 8413e3c19a..a8dff4a32e 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -613,6 +613,7 @@ Requires: libvirt-libs =3D %{version}-%{release} # needed for device enumeration Requires: systemd >=3D 185 # For managing persistent mediated devices +# Note: for nodedev-update support at least mdevctl v1.3.0 is required Requires: mdevctl # for modprobe of pci devices Requires: module-init-tools diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index baff49a0ae..11bc9af92e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -54,7 +54,7 @@ virNodeDeviceDriverState *driver; =20 VIR_ENUM_IMPL(virMdevctlCommand, MDEVCTL_CMD_LAST, - "start", "stop", "define", "undefine", "create" + "start", "stop", "define", "undefine", "create", "modify" ); =20 =20 @@ -754,6 +754,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, case MDEVCTL_CMD_START: case MDEVCTL_CMD_DEFINE: case MDEVCTL_CMD_UNDEFINE: + case MDEVCTL_CMD_MODIFY: cmd =3D virCommandNewArgList(MDEVCTL, subcommand, NULL); break; case MDEVCTL_CMD_LAST: @@ -767,6 +768,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, switch (cmd_type) { case MDEVCTL_CMD_CREATE: case MDEVCTL_CMD_DEFINE: + case MDEVCTL_CMD_MODIFY: if (!def->caps->data.mdev.parent_addr) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find parent device '%1$s'"), def->= parent); @@ -783,7 +785,8 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, virCommandAddArgPair(cmd, "--jsonfile", "/dev/stdin"); =20 virCommandSetInputBuffer(cmd, inbuf); - virCommandSetOutputBuffer(cmd, outbuf); + if (outbuf) + virCommandSetOutputBuffer(cmd, outbuf); break; =20 case MDEVCTL_CMD_UNDEFINE: @@ -868,6 +871,100 @@ virMdevctlDefine(virNodeDeviceDef *def, char **uuid) } =20 =20 +/* gets a virCommand object that executes a mdevctl command to modify a + * a device to an updated version + */ +virCommand* +nodeDeviceGetMdevctlModifyCommand(virNodeDeviceDef *def, + bool defined, + bool live, + char **errmsg) +{ + virCommand *cmd =3D nodeDeviceGetMdevctlCommand(def, + MDEVCTL_CMD_MODIFY, + NULL, errmsg); + + if (!cmd) + return NULL; + + if (defined) + virCommandAddArg(cmd, "--defined"); + + if (live) + virCommandAddArg(cmd, "--live"); + + return cmd; +} + + +/* checks if mdevctl supports on the command modify the options live, defi= ned + * and jsonfile + */ +static int +nodeDeviceGetMdevctlModifySupportCheck(void) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + const char *subcommand =3D virMdevctlCommandTypeToString(MDEVCTL_CMD_M= ODIFY); + + cmd =3D virCommandNewArgList(MDEVCTL, + subcommand, + "--defined", + "--live", + "--jsonfile", + "b", + "--help", + NULL); + + if (!cmd) + return -1; + + if (virCommandRun(cmd, &status) < 0) + return -1; + + if (status !=3D 0) // update is unsupported + return -1; + + return 0; +} + + +static int +virMdevctlModify(virNodeDeviceDef *def, + bool defined, + bool live) +{ + int status; + g_autofree char *errmsg =3D NULL; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlModifyCommand(def, + defined, + live, + &errmsg); + + if (!cmd) + return -1; + + if (nodeDeviceGetMdevctlModifySupportCheck() < 0) { + VIR_WARN("Installed mdevctl version does not support modify with o= ptions jsonfile, defined and live"); + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Unable to modify mediated device: modify unsuppo= rted")); + return -1; + } + + if (virCommandRun(cmd, &status) < 0) + return -1; + + if (status !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to modify mediated device: %1$s"), + MDEVCTL_ERROR(errmsg)); + return -1; + } + + return 0; +} + + static virNodeDevicePtr nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDef *def) @@ -2106,3 +2203,126 @@ nodeDeviceIsActive(virNodeDevice *device) virNodeDeviceObjEndAPI(&obj); return ret; } + + +static int +nodeDeviceDefValidateUpdate(virNodeDeviceDef *def, + virNodeDeviceDef *new_def, + bool live) +{ + virNodeDevCapsDef *caps =3D NULL; + virNodeDevCapMdev *cap_mdev =3D NULL; + virNodeDevCapMdev *cap_new_mdev =3D NULL; + + for (caps =3D def->caps; caps !=3D NULL; caps =3D caps->next) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + cap_mdev =3D &caps->data.mdev; + } + } + if (!cap_mdev) + return -1; + + for (caps =3D new_def->caps; caps !=3D NULL; caps =3D caps->next) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + cap_new_mdev =3D &caps->data.mdev; + } + } + if (!cap_new_mdev) + return -1; + + if (STRNEQ_NULLABLE(cap_mdev->uuid, cap_new_mdev->uuid)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Cannot update device '%1$s, uuid mismatch (curre= nt uuid '%2$s')"), + def->name, + 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 */ + if (live && + STRNEQ_NULLABLE(cap_mdev->active_config.type, cap_new_mdev->define= d_config.type)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Cannot update device '%1$s', type mismatch (curr= ent type '%2$s')"), + def->name, + cap_mdev->active_config.type); + return -1; + } + if (STRNEQ_NULLABLE(cap_mdev->parent_addr, cap_new_mdev->parent_addr))= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Cannot update device '%1$s', parent address mism= atch (current parent address '%2$s')"), + def->name, + cap_mdev->parent_addr); + return -1; + } + + return 0; +} + + +int +nodeDeviceUpdate(virNodeDevice *device, + const char *xmlDesc, + unsigned int flags) +{ + int ret =3D -1; + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def; + g_autoptr(virNodeDeviceDef) new_def =3D NULL; + const char *virt_type =3D NULL; + bool updated =3D false; + + virCheckFlags(VIR_NODE_DEVICE_UPDATE_AFFECT_LIVE | + VIR_NODE_DEVICE_UPDATE_AFFECT_CONFIG, -1); + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + virt_type =3D virConnectGetType(device->conn); + + if (virNodeDeviceUpdateEnsureACL(device->conn, def, flags) < 0) + goto cleanup; + + if (!(new_def =3D virNodeDeviceDefParse(xmlDesc, NULL, EXISTING_DEVICE= , virt_type, + &driver->parserCallbacks, NULL, = true))) + goto cleanup; + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV) && + nodeDeviceHasCapability(new_def, VIR_NODE_DEV_CAP_MDEV)) { + // Checks flags are valid for the state and sets flags for current= if flags not set + if (virNodeDeviceObjUpdateModificationImpact(obj, &flags) < 0) + goto cleanup; + + // Compare def and new_def for compatibility e.g. parent, type and= uuid + if (nodeDeviceDefValidateUpdate(def, new_def, + (flags & VIR_NODE_DEVICE_UPDATE_AF= FECT_LIVE)) < 0) + goto cleanup; + + // Update now + VIR_DEBUG("Update node device '%s' with mdevctl", def->name); + if (virMdevctlModify(new_def, + (flags & VIR_NODE_DEVICE_UPDATE_AFFECT_CONFIG= ), + (flags & VIR_NODE_DEVICE_UPDATE_AFFECT_LIVE))= < 0) { + goto cleanup; + }; + // Detect updates and also trigger events + updated =3D true; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + goto cleanup; + } + + ret =3D 0; + cleanup: + virNodeDeviceObjEndAPI(&obj); + if (updated) + nodeDeviceUpdateMediatedDevices(); + + return ret; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 4dce7e6f17..b3bc4b2e96 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -39,6 +39,7 @@ typedef enum { * separation makes our code more readable in terms of knowing when we= 're * starting a defined device and when we're creating a transient one */ MDEVCTL_CMD_CREATE, + MDEVCTL_CMD_MODIFY, =20 MDEVCTL_CMD_LAST, } virMdevctlCommand; @@ -186,3 +187,13 @@ virCommand* nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def, bool autostart, char **errmsg); + +virCommand* +nodeDeviceGetMdevctlModifyCommand(virNodeDeviceDef *def, + bool defined, + bool live, + char **errmsg); +int +nodeDeviceUpdate(virNodeDevice *dev, + const char *xmlDesc, + unsigned int flags); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 57368a96c3..f1e402f8f7 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2403,6 +2403,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceGetAutostart =3D nodeDeviceGetAutostart, /* 7.8.0 */ .nodeDeviceIsPersistent =3D nodeDeviceIsPersistent, /* 7.8.0 */ .nodeDeviceIsActive =3D nodeDeviceIsActive, /* 7.8.0 */ + .nodeDeviceUpdate =3D nodeDeviceUpdate, /* 10.1.0 */ }; =20 =20 diff --git a/tests/nodedevmdevctldata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60c= c60c_update.xml b/tests/nodedevmdevctldata/mdev_c60cc60c_c60c_c60c_c60c_c60= cc60cc60c_update.xml new file mode 100644 index 0000000000..17e3611bf4 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_up= date.xml @@ -0,0 +1,16 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + /sys/devices/css0/0.0.0052/c60cc60c-c60c-c60c-c60c-c60cc60cc60c + css_0_0_0052 + + vfio_ccw_mdev + + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + 0.0.0052 + + + + + diff --git a/tests/nodedevmdevctldata/mdevctl-modify.argv b/tests/nodedevmd= evctldata/mdevctl-modify.argv new file mode 100644 index 0000000000..341c5e7fd0 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-modify.argv @@ -0,0 +1,25 @@ +mdevctl \ +modify \ +--parent=3D0.0.0052 \ +--jsonfile=3D/dev/stdin \ +--uuid=3Dc60cc60c-c60c-c60c-c60c-c60cc60cc60c \ +--defined +mdevctl \ +modify \ +--parent=3D0.0.0052 \ +--jsonfile=3D/dev/stdin \ +--uuid=3Dc60cc60c-c60c-c60c-c60c-c60cc60cc60c \ +--live +mdevctl \ +modify \ +--parent=3D0.0.0052 \ +--jsonfile=3D/dev/stdin \ +--uuid=3Dc60cc60c-c60c-c60c-c60c-c60cc60cc60c \ +--live +mdevctl \ +modify \ +--parent=3D0.0.0052 \ +--jsonfile=3D/dev/stdin \ +--uuid=3Dc60cc60c-c60c-c60c-c60c-c60cc60cc60c \ +--defined \ +--live diff --git a/tests/nodedevmdevctldata/mdevctl-modify.json b/tests/nodedevmd= evctldata/mdevctl-modify.json new file mode 100644 index 0000000000..a778730fac --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-modify.json @@ -0,0 +1,4 @@ +{"mdev_type":"vfio_ccw-io","start":"manual"} +{"mdev_type":"vfio_ccw-io","start":"manual","attrs":[{"add_attr_1":"val1"}= ,{"add_attr_2":"val2"}]} +{"mdev_type":"vfio_ccw-io","start":"manual"} +{"mdev_type":"vfio_ccw-io","start":"manual","attrs":[{"add_attr_1":"val1"}= ,{"add_attr_2":"val2"}]} diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index f49d668461..de688c982e 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -33,7 +33,10 @@ testCommandDryRunCallback(const char *const*args G_GNUC_= UNUSED, { char **stdinbuf =3D opaque; =20 - *stdinbuf =3D g_strdup(input); + if (*stdinbuf) + *stdinbuf =3D g_strconcat(*stdinbuf, "\n", input, NULL); + else + *stdinbuf =3D g_strdup(input); } =20 typedef virCommand * (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char *= *); @@ -63,6 +66,7 @@ testMdevctlCmd(virMdevctlCommand cmd_type, case MDEVCTL_CMD_START: case MDEVCTL_CMD_STOP: case MDEVCTL_CMD_UNDEFINE: + case MDEVCTL_CMD_MODIFY: create =3D EXISTING_DEVICE; break; case MDEVCTL_CMD_LAST: @@ -173,6 +177,85 @@ testMdevctlAutostart(const void *data G_GNUC_UNUSED) return ret; } =20 + +static int +testMdevctlModify(const void *data G_GNUC_UNUSED) +{ + g_autoptr(virNodeDeviceDef) def =3D NULL; + g_autoptr(virNodeDeviceDef) def_update =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + const char *actualCmdline =3D NULL; + int ret =3D -1; + g_autoptr(virCommand) definedcmd =3D NULL; + g_autoptr(virCommand) livecmd =3D NULL; + g_autoptr(virCommand) bothcmd =3D NULL; + g_autofree char *errmsg =3D NULL; + g_autofree char *stdinbuf =3D NULL; + g_autofree char *mdevxml =3D + g_strdup_printf("%s/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c= _c60cc60cc60c.xml", + abs_srcdir); + g_autofree char *mdevxml_update =3D + g_strdup_printf("%s/nodedevmdevctldata/mdev_c60cc60c_c60c_c60c_c60= c_c60cc60cc60c_update.xml", + abs_srcdir); + /* just concatenate both calls into the same output files */ + g_autofree char *cmdlinefile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-modify.argv", + abs_srcdir); + g_autofree char *jsonfile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-modify.json", + abs_srcdir); + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + if (!(def =3D virNodeDeviceDefParse(NULL, mdevxml, CREATE_DEVICE, VIRT= _TYPE, + &parser_callbacks, NULL, false))) + return -1; + + virCommandSetDryRun(dryRunToken, &buf, true, true, testCommandDryRunCa= llback, &stdinbuf); + + if (!(definedcmd =3D nodeDeviceGetMdevctlModifyCommand(def, true, fals= e, &errmsg))) + goto cleanup; + + if (virCommandRun(definedcmd, NULL) < 0) + goto cleanup; + + if (!(def_update =3D virNodeDeviceDefParse(NULL, mdevxml_update, EXIST= ING_DEVICE, VIRT_TYPE, + &parser_callbacks, NULL, fals= e))) + goto cleanup; + + if (!(livecmd =3D nodeDeviceGetMdevctlModifyCommand(def_update, false,= true, &errmsg))) + goto cleanup; + + if (virCommandRun(livecmd, NULL) < 0) + goto cleanup; + + if (!(livecmd =3D nodeDeviceGetMdevctlModifyCommand(def, false, true, = &errmsg))) + goto cleanup; + + if (virCommandRun(livecmd, NULL) < 0) + goto cleanup; + + if (!(bothcmd =3D nodeDeviceGetMdevctlModifyCommand(def_update, true, = true, &errmsg))) + goto cleanup; + + if (virCommandRun(bothcmd, NULL) < 0) + goto cleanup; + + if (!(actualCmdline =3D virBufferCurrentContent(&buf))) + goto cleanup; + + if (virTestCompareToFileFull(actualCmdline, cmdlinefile, false) < 0) + goto cleanup; + + if (virTestCompareToFile(stdinbuf, jsonfile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + return ret; +} + static int testMdevctlListDefined(const void *data G_GNUC_UNUSED) { @@ -457,6 +540,9 @@ mymain(void) #define DO_TEST_AUTOSTART() \ DO_TEST_FULL("autostart mdevs", testMdevctlAutostart, NULL) =20 +#define DO_TEST_MODIFY() \ + DO_TEST_FULL("modify mdevs", testMdevctlModify, NULL) + #define DO_TEST_PARSE_JSON(filename) \ DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filenam= e) =20 @@ -485,6 +571,8 @@ mymain(void) =20 DO_TEST_AUTOSTART(); =20 + DO_TEST_MODIFY(); + done: nodedevTestDriverFree(driver); =20 --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 14:07:19 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 1708097127094198.98263497374808; Fri, 16 Feb 2024 07:25:27 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BBDA71CF8; Fri, 16 Feb 2024 10:25:25 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 992E11E13; Fri, 16 Feb 2024 09:59:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3FC861CF1; Fri, 16 Feb 2024 09:58:55 -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 1368C18FE for ; Fri, 16 Feb 2024 09:56:26 -0500 (EST) 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 41GEu9uE024454 for ; Fri, 16 Feb 2024 14:56:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wa8kn25mh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 16 Feb 2024 14:56:23 +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 41GEuJw1025809 for ; Fri, 16 Feb 2024 14:56:19 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 3wa8kn251s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 14:56:16 +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 41GEH5pY010083; Fri, 16 Feb 2024 14:52:27 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6npmbgv4-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 41GEqM4727656866 (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 9A90E20071; 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 7459620074; 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 11/12] virsh: add nodedev-update Date: Fri, 16 Feb 2024 15:52:19 +0100 Message-ID: <20240216145220.5056-12-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> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: EPPHHUHakGj63DWW7fqf3QS0LWtnURVG X-Proofpoint-GUID: P1e55I7ltrxXURmu8LsZ99UMTp1uUOdg X-Proofpoint-UnRewURL: 6 URL's were un-rewritten MIME-Version: 1.0 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 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 phishscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160120 Message-ID-Hash: AOIMMZ5UH4BDSRVULCYQEAGV5CFRJPPI X-Message-ID-Hash: AOIMMZ5UH4BDSRVULCYQEAGV5CFRJPPI 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: 1708097127742100001 Add ability to update node devices. Signed-off-by: Boris Fiuczynski --- docs/drvnodedev.rst | 4 +- docs/manpages/virsh.rst | 19 ++++++++ tools/virsh-nodedev.c | 98 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) diff --git a/docs/drvnodedev.rst b/docs/drvnodedev.rst index 115d52ca02..b455fa67a4 100644 --- a/docs/drvnodedev.rst +++ b/docs/drvnodedev.rst @@ -23,7 +23,8 @@ NPIV) `__). Persistent virtual devices are managed with ``virsh nodedev-define`` and ``virsh nodedev-undefine``. Persistent devices can be configured to start manually or automatically using ``virsh nodedev-autostart``. Inactive devi= ces -can be made active with ``virsh nodedev-start``. +can be made active with ``virsh nodedev-start``. ``virsh nodedev-update`` +allows to modify devices (:since:`Since 10.1.0`). =20 Transient virtual devices are started and stopped with the commands ``virsh nodedev-create`` and ``virsh nodedev-destroy``. @@ -278,6 +279,7 @@ covers the following features: - display device details ( :since:`Since 3.4.0` ) - create transient mediated devices ( :since:`Since 6.5.0` ) - define persistent mediated devices ( :since:`Since 7.3.0` ) +- update mediated devices ( :since:`Since 10.1.0` ) =20 Because mediated devices are instantiated from vendor specific templates, = simply called 'types', information describing these types is contained within the diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index bc0ad6542b..8224aec8c3 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5331,6 +5331,25 @@ If *--validate* is specified, validates the format o= f the XML document against an internal RNG schema. =20 =20 +nodedev-update +-------------- + +**Syntax:** + +:: + + nodedev-update device FILE [[--live] [--config] | [--current]] + +Update a device on the host. *device* can be either device name or wwn pair +in "wwnn,wwpn" format (only works for vHBA currently). *file* +contains xml for a top-level description of the node device. +*--current* can be either or both of *live* and *config*, depends on +the hypervisor's implementation. +Both *--live* and *--config* flags may be given, but *--current* is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. + + nodedev-destroy --------------- =20 diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5942c43689..7b80747819 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1299,6 +1299,98 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) } =20 =20 +/* + * "nodedev-update" command + */ +static const vshCmdInfo info_node_device_update[] =3D { + {.name =3D "help", + .data =3D N_("Update a active and/or inactive node device") + }, + {.name =3D "desc", + .data =3D N_("Updates the configuration of a node device") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_update[] =3D { + {.name =3D "device", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format"), + .completer =3D virshNodeDeviceNameCompleter, + }, + VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " + "of the device")), + VIRSH_COMMON_OPT_CONFIG(N_("affect next node device startup")), + VIRSH_COMMON_OPT_LIVE(N_("affect running node device")), + VIRSH_COMMON_OPT_CURRENT(N_("affect current state of node device")), + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceUpdate(vshControl *ctl, const vshCmd *cmd) +{ + bool ret =3D false; + g_autoptr(virshNodeDevice) device =3D NULL; + const char *device_value =3D NULL; + const char *from =3D NULL; + g_autofree char *xml =3D NULL; + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + unsigned int flags =3D VIR_NODE_DEVICE_UPDATE_AFFECT_CURRENT; + + VSH_EXCLUSIVE_OPTIONS("current", "live"); + VSH_EXCLUSIVE_OPTIONS("current", "config"); + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + device =3D vshFindNodeDevice(ctl, device_value); + + if (!device) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + goto cleanup; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &xml) < 0) + goto cleanup; + + if (config) + flags |=3D VIR_NODE_DEVICE_UPDATE_AFFECT_CONFIG; + if (live) + flags |=3D VIR_NODE_DEVICE_UPDATE_AFFECT_LIVE; + + if (virNodeDeviceUpdate(device, xml, flags) < 0) { + vshError(ctl, _("Failed to update node device %1$s from '%2$s'"), + virNodeDeviceGetName(device), from); + goto cleanup; + } + + if (config) { + if (live) + vshPrintExtra(ctl, _("Updated node device %1$s persistent conf= ig and live state"), + virNodeDeviceGetName(device)); + else + vshPrintExtra(ctl, _("Updated node device %1$s persistent conf= ig"), + virNodeDeviceGetName(device)); + } else if (live) { + vshPrintExtra(ctl, _("Updated node device %1$s live state"), + virNodeDeviceGetName(device)); + } else if (virNodeDeviceIsActive(device)) { + vshPrintExtra(ctl, _("Updated node device %1$s live state"), + virNodeDeviceGetName(device)); + } else { + vshPrintExtra(ctl, _("Updated node device %1$s persistent config"), + virNodeDeviceGetName(device)); + } + + ret =3D true; + cleanup: + vshReportError(ctl); + return ret; +} + =20 const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", @@ -1383,5 +1475,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_info, .flags =3D 0 }, + {.name =3D "nodedev-update", + .handler =3D cmdNodeDeviceUpdate, + .opts =3D opts_node_device_update, + .info =3D info_node_device_update, + .flags =3D 0 + }, {.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 From nobody Thu May 9 14:07:19 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 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