From nobody Mon Sep 16 19:44:21 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