From nobody Wed May 15 03:45:24 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 1705684605305942.82561523752; Fri, 19 Jan 2024 09:16:45 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 295F0183D; Fri, 19 Jan 2024 12:16:44 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1B0311870; Fri, 19 Jan 2024 12:14:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2604B1889; Fri, 19 Jan 2024 12:14:37 -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 3D4F3183D for ; Fri, 19 Jan 2024 12:14:36 -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 40JGb7YE028743 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vquke21ft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:59 +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 40JGbGt9030599 for ; Fri, 19 Jan 2024 16:38:58 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 3vquke21f8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JEB6e0005788; Fri, 19 Jan 2024 16:38:58 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm6bm2g0k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcrYN25887442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:55 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B15EA2004B; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8993D2004F; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 01/11] virmdev: prepare type and attributes for dual state Date: Fri, 19 Jan 2024 17:38:43 +0100 Message-ID: <20240119163853.10191-2-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: fr7sM9tWcGQlG2wfvBErGkkq5qQK2fvN X-Proofpoint-ORIG-GUID: hiVu4lZeGaTpKjMWxL8jb9BjaXUVOjfO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxlogscore=998 spamscore=0 bulkscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: 7VESC5CLJWNWHVOJBEPF6WXZYOUWUUN2 X-Message-ID-Hash: 7VESC5CLJWNWHVOJBEPF6WXZYOUWUUN2 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: 1705684605823100001 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 4826be6f42..4e1bde503f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -590,15 +590,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); } @@ -2202,7 +2202,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; } @@ -2221,7 +2221,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; @@ -2596,11 +2596,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 Wed May 15 03:45:24 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 1705684009062461.97675166024055; Fri, 19 Jan 2024 09:06:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0A3F71BBE; Fri, 19 Jan 2024 12:06: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 8400C1CAD; Fri, 19 Jan 2024 12:01:28 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 527011AF3; Fri, 19 Jan 2024 12:01:16 -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 506881AE8 for ; Fri, 19 Jan 2024 11:57:49 -0500 (EST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40JG1gYU002026 for ; Fri, 19 Jan 2024 16:38:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqtxj2qfv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:57 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40JGI7pQ025855 for ; Fri, 19 Jan 2024 16:38:57 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 3vqtxj2qfj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:57 +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 40JDt9Rp000490; Fri, 19 Jan 2024 16:38:56 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vm4utasjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:56 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcs3N44827296 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:54 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E00A720040; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B8D3420043; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 02/11] node_device: refactor mdev attributes handling Date: Fri, 19 Jan 2024 17:38:44 +0100 Message-ID: <20240119163853.10191-3-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: diB8mwlUP-l9XAgfWlQ-iorxDivjne6t X-Proofpoint-ORIG-GUID: m3dcJ-3BUxDW-RfienlwXq4P3W_XB65z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 clxscore=1011 mlxscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: YSEY4KUQJDIBIMQ37UTFOP4RN4DXP7IH X-Message-ID-Hash: YSEY4KUQJDIBIMQ37UTFOP4RN4DXP7IH 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: 1705684009496100001 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 | 108 ++++++++++++++++----------- 2 files changed, 83 insertions(+), 52 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4e1bde503f..68924b3027 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -585,11 +585,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", @@ -597,11 +608,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 @@ -2188,7 +2195,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(); @@ -2202,7 +2209,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; } @@ -2253,7 +2260,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..0c8612eb71 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, + const 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 +nodeDeviceParseMdevctlAttribs(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 (nodeDeviceParseMdevctlAttribs(&mdev->dev_config, + virJSONValueObjectGet(props, "attrs"= )) < 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); @@ -1760,7 +1782,9 @@ nodeDeviceUpdateMediatedDevices(void) } =20 =20 -/* returns true if any attributes were copied, else returns false */ +/* Transfer mediated device attributes to the new definition. Any change in + * the attributes is elminated but causes the return value to be true. + * Returns true if any attribute is copied, else returns false */ static bool virMediatedDeviceAttrsCopy(virMediatedDeviceConfig *dst_config, virMediatedDeviceConfig *src_config) --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 03:45:24 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 1705683724409109.87298310926678; Fri, 19 Jan 2024 09:02:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 31F351B5F; Fri, 19 Jan 2024 12:02:03 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2D6761C24; Fri, 19 Jan 2024 11:57:56 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BAC941A74; Fri, 19 Jan 2024 11:57: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 7552B1C1F for ; Fri, 19 Jan 2024 11:55:30 -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 40JGFdgu002626 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqv8dry1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:59 +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 40JGHA3H008785 for ; Fri, 19 Jan 2024 16:38:58 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 3vqv8dry0g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JDsLvT011009; Fri, 19 Jan 2024 16:38:57 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm5802ssb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:57 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcsxP39912176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:54 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 139A220043; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA2A02004D; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Greylist: delayed 990 seconds by postgrey-1.37 at lists.libvirt.org; Fri, 19 Jan 2024 11:55:30 EST From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 03/11] node_device: remove unnecessary checks in virNodeDeviceDefFormat Date: Fri, 19 Jan 2024 17:38:45 +0100 Message-ID: <20240119163853.10191-4-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OaMywO9BMmhjmsEBZ_wULpfSfvvAVEu8 X-Proofpoint-ORIG-GUID: EV5FYPyEQcjOL_8rMt23W4f9NFb15zj- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 phishscore=0 clxscore=1015 mlxlogscore=766 adultscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: 3HPYUWA6J73P6AK7HVUZD2EQW2KLWM4M X-Message-ID-Hash: 3HPYUWA6J73P6AK7HVUZD2EQW2KLWM4M 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: 1705683726146100001 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 68924b3027..9a0fc68e67 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -669,16 +669,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 Wed May 15 03:45:24 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 1705683570444469.76103443386296; Fri, 19 Jan 2024 08:59:30 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 354F11B5D; Fri, 19 Jan 2024 11:59:29 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 874E81A01; Fri, 19 Jan 2024 11:55:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id E114F1A44; Fri, 19 Jan 2024 11:54:55 -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 507801A41 for ; Fri, 19 Jan 2024 11:54:54 -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 40JGb6Se028554 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vquke21fg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:58 +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 40JGbLGb031325 for ; Fri, 19 Jan 2024 16:38:58 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 3vquke21f0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JDtmo7011294; Fri, 19 Jan 2024 16:38:57 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm5802ssd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:57 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcstC39912178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:54 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D12120040; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1BD8B2004E; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 04/11] nodedev: add an active config to mdev Date: Fri, 19 Jan 2024 17:38:46 +0100 Message-ID: <20240119163853.10191-5-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: l2EHv9dAWKG1l69a5MuVVBLOzF93xAcX X-Proofpoint-ORIG-GUID: AWEjWI2JAfTbAj2uDp2PKCPu9pFYjoTR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: Q2QYDOFE5R2Y73Z7B3AZ5JJ7UASTPRPS X-Message-ID-Hash: Q2QYDOFE5R2Y73Z7B3AZ5JJ7UASTPRPS 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: 1705683571440100001 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..d18246e2f6 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 +/** + * virNodeDeviceGetXMLDescFlags: + * + * Flags used to provide the state of the returned node device configurati= on. + * + * Since: 10.1.0 + */ +typedef enum { + VIR_NODE_DEVICE_GET_XML_DESC_INACTIVE =3D 1 << 0, /* dump i= nactive device configuration (Since: 10.1.0) */ +} virNodeDeviceGetXMLDescFlags; + 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 9a0fc68e67..40e15ef4da 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -599,16 +599,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 @@ -659,25 +665,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_GET_XML_DESC_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); @@ -738,7 +747,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); @@ -2226,7 +2235,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; @@ -2258,7 +2267,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; } @@ -2601,11 +2610,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..9cc5c6466b 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 virNodeDeviceGetXMLDescFlags * * 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 0c8612eb71..d67c95d68d 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_GET_XML_DESC_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_GET_XML_DESC_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_GET_XML_DESC_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_config= : 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.type= ) < 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 @@ nodeDeviceParseMdevctlAttribs(virMediatedDeviceConfi= g *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 (nodeDeviceParseMdevctlAttribs(&mdev->dev_config, + if (nodeDeviceParseMdevctlAttribs(mdev_config, virJSONValueObjectGet(props, "attrs"= )) < 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 @@ -1831,16 +1848,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)) { @@ -1849,7 +1874,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..01863233bc 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_GET_XML_DESC_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..852d9ed6e7 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_GET_XML_DESC_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..be7a5b4df9 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_GET_XML_DESC_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_GET_XML_DESC_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_GET_XML_DESC_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 Wed May 15 03:45:24 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 1705684221860524.2886699911987; Fri, 19 Jan 2024 09:10:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A9E5F1B96; Fri, 19 Jan 2024 12:10:20 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 884EB1D29; Fri, 19 Jan 2024 12:05:45 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C18F11CC9; Fri, 19 Jan 2024 12:05: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 3725D1A49 for ; Fri, 19 Jan 2024 12:03:45 -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 40JGFfbb002770 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqv8dry10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:58 +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 40JGFpW3003905 for ; Fri, 19 Jan 2024 16:38:58 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 3vqv8dry0f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JE5B8p000561; Fri, 19 Jan 2024 16:38:57 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vm4utasjm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:57 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcspt44630384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:54 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72E982004D; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5465120043; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 05/11] tools: add option inactive to nodedev-dumpxml Date: Fri, 19 Jan 2024 17:38:47 +0100 Message-ID: <20240119163853.10191-6-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: N2mQKRvKvJ0ayPSAGfLoYaBo5XQP8n1d X-Proofpoint-ORIG-GUID: xWR4ck808foWflaJ1vQVFflVQSJ5J039 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 phishscore=0 clxscore=1015 mlxlogscore=747 adultscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: ZOT4RNCJBRD7N72LG664EEYTPFMB3FGA X-Message-ID-Hash: ZOT4RNCJBRD7N72LG664EEYTPFMB3FGA 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: 1705684222421100001 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 | 15 ++++++++++++++- 2 files changed, 19 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..54e192d619 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,15 @@ 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_GET_XML_DESC_INACTIVE; + if (!virNodeDeviceIsPersistent(device)) { + vshError(ctl, _("Node device '%1$s' is not persistent"), devic= e_value); + return false; + } + } + + 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 Wed May 15 03:45:24 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 1705684135828289.83634499902166; Fri, 19 Jan 2024 09:08:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AEFAD1BC6; Fri, 19 Jan 2024 12:08: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 597C61BA2; Fri, 19 Jan 2024 12:01:38 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 07B041B9E; Fri, 19 Jan 2024 12:01:17 -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 BBDD21C35 for ; Fri, 19 Jan 2024 11:58:32 -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 40JG8418013889 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqvav8tc3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:58 +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 40JG86Jr014253 for ; Fri, 19 Jan 2024 16:38:58 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 3vqvav8tbn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JDvapG000551; Fri, 19 Jan 2024 16:38:57 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vm4utasjn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:57 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcs4044630386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:54 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9784220040; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7A84F2004E; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 06/11] nodedev: add persisted and transient filter on list Date: Fri, 19 Jan 2024 17:38:48 +0100 Message-ID: <20240119163853.10191-7-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JrM-KNb57qtVpMEEkPLbU6blS0Jy777K X-Proofpoint-ORIG-GUID: wcl3JBpm_HPI8qodswMIGN4SIkwMDe3K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 mlxlogscore=737 priorityscore=1501 mlxscore=0 adultscore=0 suspectscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: J3XQ3STLVO64QWDTZ4DPB5NMQEML5ATI X-Message-ID-Hash: J3XQ3STLVO64QWDTZ4DPB5NMQEML5ATI 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: 1705684136067100001 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 d18246e2f6..dff394ec86 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_PERSISTED =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..3ee1fbc665 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_PERSIST \ + VIR_CONNECT_LIST_NODE_DEVICES_PERSISTED | \ + 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_PERSIST =20 int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHost *scsi_host); diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index cfef30d47e..0b9ca8c864 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_PERSIST)) { + if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_PERSISTED) && + 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 Wed May 15 03:45:24 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 1705684316363284.5125628210312; Fri, 19 Jan 2024 09:11:56 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3BCEC1D6A; Fri, 19 Jan 2024 12:11:55 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 96CF11CC4; Fri, 19 Jan 2024 12:08:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 58C711A54; Fri, 19 Jan 2024 12:08: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 0C7911A86 for ; Fri, 19 Jan 2024 12:07:56 -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 40JFE5PZ008338 for ; Fri, 19 Jan 2024 16:39:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqtg3v1da-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:39:00 +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 40JG0ZuV023095 for ; Fri, 19 Jan 2024 16:39:00 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 3vqtg3v1cn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:39:00 +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 40JDqMlq011131; Fri, 19 Jan 2024 16:38:59 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm5802ssh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcsXO20906632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:54 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BCC3C2004D; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9FAB220043; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 07/11] tools: add switches persisted and transient to nodedev-list Date: Fri, 19 Jan 2024 17:38:49 +0100 Message-ID: <20240119163853.10191-8-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KjUgGMLJTKYbItuBdqFaWWa82FPhuBAc X-Proofpoint-GUID: 5eQ0nrCGQ84VChII3NIraqYgbVsttX5y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 mlxlogscore=977 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: HXS5UFM7LUEECBDQZPDMFVEOEFNNCA6W X-Message-ID-Hash: HXS5UFM7LUEECBDQZPDMFVEOEFNNCA6W 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: 1705684316650100001 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..4bcfbc230b 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= ted | --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. +*--persisted* is used to list only persisted devices, and *--transient* is +used to list only transient devices. Not providing *--persisted* or +*--transient* will list all devices unless filtered otherwise. *--transien= t* +is mutually exclusive with *--persisted* 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 54e192d619..4acb955efe 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 "persisted", + .type =3D VSH_OT_BOOL, + .help =3D N_("list persisted 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 persisted =3D vshCommandOptBool(cmd, "persisted"); + 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 && (persisted || inactive)) { + vshError(ctl, "%s", _("Option --transient is incompatible with --p= ersisted and --inactive")); + return false; + } + + if (tree && (cap_str || inactive || persisted || transient)) { + vshError(ctl, "%s", _("Option --tree is incompatible with --cap, -= -inactive, --persisted 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 (persisted) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_PERSISTED; + 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 Wed May 15 03:45:24 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 1705683056300633.7021677347196; Fri, 19 Jan 2024 08:50:56 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 337C31ADB; Fri, 19 Jan 2024 11:50:55 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1C86E1A44; Fri, 19 Jan 2024 11:49:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id CC8181A43; Fri, 19 Jan 2024 11:49:44 -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 1A6711A40 for ; Fri, 19 Jan 2024 11:49:44 -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 40JFHnBO015504 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vquke21fp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:59 +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 40JGbJ2N031019 for ; Fri, 19 Jan 2024 16:38:58 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 3vquke21f7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JDw87X005842; Fri, 19 Jan 2024 16:38:58 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm6bm2g0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGcsjj26149488 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:55 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E0C2A20043; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3D2D20040; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Greylist: delayed 646 seconds by postgrey-1.37 at lists.libvirt.org; Fri, 19 Jan 2024 11:49:44 EST From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 08/11] virsh: doc fix on nodedev-list Date: Fri, 19 Jan 2024 17:38:50 +0100 Message-ID: <20240119163853.10191-9-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ALwau8VkzRUZgDvlcfMZK0QGnIaN0g1F X-Proofpoint-ORIG-GUID: dKh2-zu7Q3BNAag3zSve2LUtzrLWktPS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxlogscore=960 spamscore=0 bulkscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: TOUPFS7Z6UQ4YKAEGY44FJ25JUZVOJMM X-Message-ID-Hash: TOUPFS7Z6UQ4YKAEGY44FJ25JUZVOJMM 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: 1705683057773100001 Commit 26136e3 allowed to use option all with option tree but did not updat= e 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 4bcfbc230b..3315395c54 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5476,7 +5476,7 @@ used to list only transient devices. Not providing *-= -persisted* or *--transient* will list all devices unless filtered otherwise. *--transien= t* is mutually exclusive with *--persisted* 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 Wed May 15 03:45:24 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 170568598850130.919480560077886; Fri, 19 Jan 2024 09:39:48 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 43C191BAF; Fri, 19 Jan 2024 12:39:47 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2B53119BA; Fri, 19 Jan 2024 12:37:13 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 706A919B2; Fri, 19 Jan 2024 12:37: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 6020019AD for ; Fri, 19 Jan 2024 12:37:07 -0500 (EST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40JG1ftl001902 for ; Fri, 19 Jan 2024 16:38:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqtxj2qgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:59 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40JGbMI4020246 for ; Fri, 19 Jan 2024 16:38:58 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 3vqtxj2qg2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +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 40JECsYc000381; Fri, 19 Jan 2024 16:38:58 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vm4utasjp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:57 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGctvN45089166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:55 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B79C20040; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E8AF92004E; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 09/11] api: add virNodeDeviceUpdate() Date: Fri, 19 Jan 2024 17:38:51 +0100 Message-ID: <20240119163853.10191-10-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: tEDTAbfp3_KOQBaBEu-QwzrVEc9X9P1f X-Proofpoint-ORIG-GUID: kNBUwsFwX-CwGrcf_ms2w9NqyM3p6t54 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 mlxlogscore=853 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: RQAIREIZEQDNNTVC2YXOSNFO64Z7TNFB X-Message-ID-Hash: RQAIREIZEQDNNTVC2YXOSNFO64Z7TNFB 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: 1705685990436100001 This public API is implemented for almost all other objects that have a concept of persistent definition and activatability. Node devices (mdevs) that can be defined and inactive, it will be useful to be able to update defined and active node devices as well. Signed-off-by: Boris Fiuczynski --- include/libvirt/libvirt-nodedev.h | 18 +++++++++++++ src/access/viraccessperm.c | 1 + src/access/viraccessperm.h | 6 +++++ src/conf/virnodedeviceobj.c | 42 +++++++++++++++++++++++++++++ src/conf/virnodedeviceobj.h | 3 +++ src/driver-nodedev.h | 6 +++++ src/libvirt-nodedev.c | 45 +++++++++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libvirt_public.syms | 5 ++++ src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 17 +++++++++++- src/remote_protocol-structs | 6 +++++ 12 files changed, 150 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index dff394ec86..c1d3769eaf 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -188,6 +188,24 @@ int virNodeDeviceIsPersistent(virNodeDevicePtr dev); =20 int virNodeDeviceIsActive(virNodeDevicePtr dev); =20 +/** + * virNodeDeviceUpdateXMLFlags: + * + * Flags to control options for virNodeDeviceUpdateXML() + * + * Since: 10.1.0 + */ +typedef enum { + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CURRENT =3D 0, /* affect live i= f node device is active, + config if it's = not active (Since: 10.1.0) */ + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE =3D 1 << 0, /* affect live s= tate of node device only (Since: 10.1.0) */ + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG =3D 1 << 1, /* affect persis= tent config only (Since: 10.1.0) */ +} virNodeDeviceUpdateXMLFlags; + +int virNodeDeviceUpdateXML(virNodeDevicePtr dev, + const char *xmlDesc, + unsigned int flags); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index d4a0c98b9b..702bee761d 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -71,6 +71,7 @@ VIR_ENUM_IMPL(virAccessPermNodeDevice, "getattr", "read", "write", "start", "stop", "detach", "delete", + "save", ); =20 VIR_ENUM_IMPL(virAccessPermNWFilter, diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index 2f04459ed9..6cc2140c67 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -507,6 +507,12 @@ typedef enum { */ VIR_ACCESS_PERM_NODE_DEVICE_DELETE, =20 + /** + * @desc: Save node device + * @message: Saving node device driver requires authorization + */ + VIR_ACCESS_PERM_NODE_DEVICE_SAVE, + VIR_ACCESS_PERM_NODE_DEVICE_LAST } virAccessPermNodeDevice; =20 diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 0b9ca8c864..f185f79322 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -1137,3 +1137,45 @@ virNodeDeviceObjListFind(virNodeDeviceObjList *devs, virNodeDeviceObjListFindHelper, &data); } + + +/** + * virNodeDeviceObjUpdateModificationImpact: + * @obj: Pointer to node device object + * @flags: flags to update the modification impact on + * + * Resolves virNodeDeviceObjUpdateModificationImpact flags in @flags so th= at + * they correctly apply to the actual state of @obj. @flags may be modified + * after call to this function. + * + * Returns 0 on success if @flags point to a valid combination for @obj or= -1 + * on error. + */ +int +virNodeDeviceObjUpdateModificationImpact(virNodeDeviceObj *obj, + unsigned int *flags) +{ + bool isActive =3D virNodeDeviceObjIsActive(obj); + + if ((*flags & (VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE | VIR_NODE_DEVIC= E_UPDATE_XML_AFFECT_CONFIG)) =3D=3D + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CURRENT) { + if (isActive) + *flags |=3D VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE; + else + *flags |=3D VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG; + } + + if (!isActive && (*flags & VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("mdev is not active")); + return -1; + } + + if (!virNodeDeviceObjIsPersistent(obj) && (*flags & VIR_NODE_DEVICE_UP= DATE_XML_AFFECT_CONFIG)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("transient mdevs do not have any persistent confi= g")); + return -1; + } + + return 0; +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index ba2e424998..43889b8dc8 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -159,3 +159,6 @@ virNodeDeviceObj * virNodeDeviceObjListFind(virNodeDeviceObjList *devs, virNodeDeviceObjListPredicate callback, void *opaque); + +int virNodeDeviceObjUpdateModificationImpact(virNodeDeviceObj *obj, + unsigned int *flags); diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index 167a8166dd..1c6a731f4e 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -101,6 +101,11 @@ typedef int typedef int (*virDrvNodeDeviceIsActive)(virNodeDevicePtr dev); =20 +typedef int +(*virDrvNodeDeviceUpdateXML)(virNodeDevicePtr dev, + const char *xmlDesc, + unsigned int flags); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -146,4 +151,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceGetAutostart nodeDeviceGetAutostart; virDrvNodeDeviceIsPersistent nodeDeviceIsPersistent; virDrvNodeDeviceIsActive nodeDeviceIsActive; + virDrvNodeDeviceUpdateXML nodeDeviceUpdateXML; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 9cc5c6466b..e1f0c8af41 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -1174,3 +1174,48 @@ int virNodeDeviceIsActive(virNodeDevicePtr dev) virDispatchError(dev->conn); return -1; } + + +/** + * virNodeDeviceUpdateXML: + * @dev: pointer to the node device object + * @xmlDesc: string containing an XML description of the device to be defi= ned + * @flags: bitwise OR of virNodeDeviceUpdateXMLFlags + * + * Update the definition of an existing node device, either its live + * running configuration, its persistent configuration, or both. + * + * Returns 0 in case of success, -1 in case of error + * + * Since: 10.1.0 + */ +int +virNodeDeviceUpdateXML(virNodeDevicePtr dev, + const char *xmlDesc, + unsigned int flags) +{ + VIR_DEBUG("nodeDevice=3D%p, xmlDesc=3D%s, flags=3D0x%x", + dev, NULLSTR(xmlDesc), flags); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + + virCheckReadOnlyGoto(dev->conn->flags, error); + virCheckNonNullArgGoto(xmlDesc, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceUpdateXML) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceUpdateXML(de= v, xmlDesc, flags); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fc26109029..eb52610c2d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1373,6 +1373,7 @@ virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; virNodeDeviceObjSetAutostart; virNodeDeviceObjSetPersistent; +virNodeDeviceObjUpdateModificationImpact; =20 =20 # conf/virnwfilterbindingdef.h diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index bd1e916d2a..8b53eeb2ee 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -938,4 +938,9 @@ LIBVIRT_9.7.0 { virNetworkSetMetadata; } LIBVIRT_9.0.0; =20 +LIBVIRT_10.1.0 { + global: + virNodeDeviceUpdateXML; +} LIBVIRT_9.7.0; + # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 392377deae..9639ea01b3 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7983,6 +7983,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceSetAutostart =3D remoteNodeDeviceSetAutostart, /* 7.8.0 */ .nodeDeviceIsPersistent =3D remoteNodeDeviceIsPersistent, /* 7.8.0 */ .nodeDeviceIsActive =3D remoteNodeDeviceIsActive, /* 7.8.0 */ + .nodeDeviceUpdateXML =3D remoteNodeDeviceUpdateXML, /* 10.1.0 */ }; =20 static virNWFilterDriver nwfilter_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index e295b0acc3..e95f672daf 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2237,6 +2237,12 @@ struct remote_node_device_is_active_ret { int active; }; =20 +struct remote_node_device_update_xml_args { + remote_nonnull_string name; + remote_nonnull_string xml_desc; + unsigned int flags; +}; + =20 /* * Events Register/Deregister: @@ -7021,5 +7027,14 @@ enum remote_procedure { * @generate: both * @acl: none */ - REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446 + REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446, + + /** + * @generate: both + * @priority: high + * @acl: node_device:write + * @acl: node_device:save:!VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG|VI= R_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE + * @acl: node_device:save:VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG + */ + REMOTE_PROC_NODE_DEVICE_UPDATE_XML =3D 447 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 924ca41825..9a1b881caf 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1673,6 +1673,11 @@ struct remote_node_device_is_active_args { struct remote_node_device_is_active_ret { int active; }; +struct remote_node_device_update_xml_args { + remote_nonnull_string name; + remote_nonnull_string xml_desc; + u_int flags; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3743,4 +3748,5 @@ enum remote_procedure { REMOTE_PROC_NETWORK_SET_METADATA =3D 444, REMOTE_PROC_NETWORK_GET_METADATA =3D 445, REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446, + REMOTE_PROC_NODE_DEVICE_UPDATE_XML =3D 447, }; --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 03:45:24 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 1705683878936508.36009077005815; Fri, 19 Jan 2024 09:04:38 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C37541C2B; Fri, 19 Jan 2024 12:04:37 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1803F1C2D; Fri, 19 Jan 2024 11:58:28 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5D58E1B1A; Fri, 19 Jan 2024 11:58:17 -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 B4E3B1A73 for ; Fri, 19 Jan 2024 11:55:51 -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 40JGVxr2022905 for ; Fri, 19 Jan 2024 16:39:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqvav8tcw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:39:00 +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 40JG83EC013785 for ; Fri, 19 Jan 2024 16:38:59 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 3vqvav8tcb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:59 +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 40JEJSvb005800; Fri, 19 Jan 2024 16:38:58 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vm6bm2g0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGctOp45089168 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:55 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B93D2004B; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2438120043; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 10/11] nodedev: Implement virNodeDeviceUpdateXML Date: Fri, 19 Jan 2024 17:38:52 +0100 Message-ID: <20240119163853.10191-11-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qRIk4gKtkvao-C756eBy_ubf7Z2Wv3JD X-Proofpoint-ORIG-GUID: rL0k0Z4VJ7EHN7HVi1vKPcKkfMQsU9X0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 mlxlogscore=919 priorityscore=1501 mlxscore=0 adultscore=0 suspectscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: 6ZYVMEETRLL3SMNNJOV4VRHKP7CCPZ4J X-Message-ID-Hash: 6ZYVMEETRLL3SMNNJOV4VRHKP7CCPZ4J 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: 1705683881156100001 Implement the API functions in the node device driver by using mdevctl modify with the options defined and live. Increase the minimum mdevctl version to 1.3.0 in spec file to ensure support exists in mdevctl. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma =3D 185 # For managing persistent mediated devices -Requires: mdevctl +Requires: mdevctl >=3D 1.3.0 # for modprobe of pci devices Requires: module-init-tools =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index d67c95d68d..dd57e9ca5b 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,61 @@ 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; +} + + +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 (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) @@ -2108,3 +2166,122 @@ nodeDeviceIsActive(virNodeDevice *device) virNodeDeviceObjEndAPI(&obj); return ret; } + + +static int +nodeDeviceDefCompareMdevs(virNodeDeviceDef *def_cur, + virNodeDeviceDef *def_upd, + bool live) +{ + virNodeDevCapsDef *caps =3D NULL; + virNodeDevCapMdev *cap_mdev_cur =3D NULL; + virNodeDevCapMdev *cap_mdev_upd =3D NULL; + + for (caps =3D def_cur->caps; caps !=3D NULL; caps =3D caps->next) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + cap_mdev_cur =3D &caps->data.mdev; + } + } + if (!cap_mdev_cur) + return -1; + + for (caps =3D def_upd->caps; caps !=3D NULL; caps =3D caps->next) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + cap_mdev_upd =3D &caps->data.mdev; + } + } + if (!cap_mdev_upd) + return -1; + + if (STRNEQ_NULLABLE(cap_mdev_cur->uuid, cap_mdev_upd->uuid)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("uuid mismatch (mdev:'%1$s' update:'%2$s')"), + cap_mdev_cur->uuid, + cap_mdev_upd->uuid); + return -1; + } + // for a live update the types of the active configs must match! + if (live && + STRNEQ_NULLABLE(cap_mdev_cur->active_config.type, cap_mdev_upd->ac= tive_config.type)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("type mismatch (mdev:'%1$s' update:'%2$s')"), + cap_mdev_cur->active_config.type, + cap_mdev_upd->active_config.type); + return -1; + } + if (STRNEQ_NULLABLE(cap_mdev_cur->parent_addr, cap_mdev_upd->parent_ad= dr)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("parent address mismatch (mdev:'%1$s' update:'%2$= s')"), + cap_mdev_cur->parent_addr, + cap_mdev_upd->parent_addr); + return -1; + } + + return 0; +} + + +int +nodeDeviceUpdateXML(virNodeDevice *device, + const char *xmlDesc, + unsigned int flags) +{ + int ret =3D -1; + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def_cur; + g_autoptr(virNodeDeviceDef) def_upd =3D NULL; + const char *virt_type =3D NULL; + bool updated =3D false; + + virCheckFlags(VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LIVE | + VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CONFIG, -1); + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def_cur =3D virNodeDeviceObjGetDef(obj); + + virt_type =3D virConnectGetType(device->conn); + + if (virNodeDeviceUpdateXMLEnsureACL(device->conn, def_cur, flags) < 0) + goto cleanup; + + if (!(def_upd =3D virNodeDeviceDefParse(xmlDesc, NULL, EXISTING_DEVICE= , virt_type, + &driver->parserCallbacks, NULL, = true))) + goto cleanup; + + if (nodeDeviceHasCapability(def_cur, VIR_NODE_DEV_CAP_MDEV) && + nodeDeviceHasCapability(def_upd, 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_cur and def_upd for compatibleness e.g. parent, typ= e and uuid + if (nodeDeviceDefCompareMdevs(def_cur, def_upd, + (flags & VIR_NODE_DEVICE_UPDATE_XML_= AFFECT_LIVE)) < 0) + goto cleanup; + + // Update now + VIR_DEBUG("Update node device '%s' with mdevctl", def_cur->name); + if (virMdevctlModify(def_upd, + (flags & VIR_NODE_DEVICE_UPDATE_XML_AFFECT_CO= NFIG), + (flags & VIR_NODE_DEVICE_UPDATE_XML_AFFECT_LI= VE)) < 0) { + goto cleanup; + }; + // Detect updates and also trigger events + updated =3D true; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + 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..5751625eda 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 +nodeDeviceUpdateXML(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..4cd9d285fa 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 */ + .nodeDeviceUpdateXML =3D nodeDeviceUpdateXML, /* 10.1.0 */ }; =20 =20 diff --git a/tests/nodedevmdevctldata/mdevctl-modify.argv b/tests/nodedevmd= evctldata/mdevctl-modify.argv new file mode 100644 index 0000000000..6acb9ca0bf --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-modify.argv @@ -0,0 +1,19 @@ +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 \ +--defined \ +--live diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 852d9ed6e7..37978c9a5c 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -63,6 +63,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 +174,64 @@ 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; + 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; + /* just concatenate both calls into the same output file */ + g_autofree char *cmdlinefile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-modify.argv", + abs_srcdir); + g_autofree char *mdevxml =3D + g_strdup_printf("%s/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c= _c60cc60cc60c.xml", + 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, NULL, NULL); + + if (!(definedcmd =3D nodeDeviceGetMdevctlModifyCommand(def, true, fals= e, &errmsg))) + goto cleanup; + + if (virCommandRun(definedcmd, 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, 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; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + return ret; +} + static int testMdevctlListDefined(const void *data G_GNUC_UNUSED) { @@ -457,6 +516,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 +547,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 Wed May 15 03:45:24 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 1705685132068328.60112016156165; Fri, 19 Jan 2024 09:25:32 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C802D1AEA; Fri, 19 Jan 2024 12:25: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 A67FD1A4A; Fri, 19 Jan 2024 12:23:59 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4BB47197F; Fri, 19 Jan 2024 12:23:57 -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 7A635198C for ; Fri, 19 Jan 2024 12:23:56 -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 40JGFfAg002774 for ; Fri, 19 Jan 2024 16:39:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vqv8dry1n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 16:38:59 +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 40JGIHUl012089 for ; Fri, 19 Jan 2024 16:38:59 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 3vqv8dry17-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:59 +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 40JECsYe000381; Fri, 19 Jan 2024 16:38:58 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vm4utasjq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 16:38:58 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40JGctOl45089170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Jan 2024 16:38:55 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6FC3420040; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 52C872004D; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.171.151.33]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 19 Jan 2024 16:38:55 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 11/11] virsh: add nodedev-update Date: Fri, 19 Jan 2024 17:38:53 +0100 Message-ID: <20240119163853.10191-12-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163853.10191-1-fiuczy@linux.ibm.com> References: <20240119163853.10191-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: bwxSTf3LnISNyOkr9wwW0snmkOE8hIjQ X-Proofpoint-ORIG-GUID: z4EeQ-AmUYnLgC4Ogr-T-oSFx3c_78Oa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_10,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 phishscore=0 clxscore=1015 mlxlogscore=604 adultscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190095 Message-ID-Hash: 3YNVOOMIMS7GEERDG6DXGKTC4BBPMLYW X-Message-ID-Hash: 3YNVOOMIMS7GEERDG6DXGKTC4BBPMLYW 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: 1705685132864100001 Add ability to update node devices. Signed-off-by: Boris Fiuczynski --- docs/manpages/virsh.rst | 19 ++++++++ tools/virsh-nodedev.c | 98 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 3315395c54..ec3ad686cb 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 4acb955efe..279e45c2a0 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1304,6 +1304,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) //TODO +{ + 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_XML_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_NETWORK_UPDATE_AFFECT_CONFIG; + if (live) + flags |=3D VIR_NETWORK_UPDATE_AFFECT_LIVE; + + if (virNodeDeviceUpdateXML(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", @@ -1388,5 +1480,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