From nobody Mon Sep 16 19:02:40 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 1707315040053478.0884060722303; Wed, 7 Feb 2024 06:10:40 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id B23831819; Wed, 7 Feb 2024 09:10:38 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 788891A76; Wed, 7 Feb 2024 08:42:04 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4F9421C3D; Wed, 7 Feb 2024 08:40:15 -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 6BF641BB3 for ; Wed, 7 Feb 2024 08:40:01 -0500 (EST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 417DOsds017065 for ; Wed, 7 Feb 2024 13:40:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w4935k9dj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 07 Feb 2024 13:40:00 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 417DB5fJ023927 for ; Wed, 7 Feb 2024 13:39:59 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w4935k9db-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Feb 2024 13:39:59 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 417COdhP008515; Wed, 7 Feb 2024 13:39:59 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w221k5m0v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Feb 2024 13:39:59 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 417DdutT27328964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Feb 2024 13:39:56 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15BDB20040; Wed, 7 Feb 2024 13:39:56 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D86C72004B; Wed, 7 Feb 2024 13:39:55 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.152.222.239]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 7 Feb 2024 13:39: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 v2 04/11] nodedev: add an active config to mdev Date: Wed, 7 Feb 2024 14:39:47 +0100 Message-ID: <20240207133954.86634-5-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207133954.86634-1-fiuczy@linux.ibm.com> References: <20240207133954.86634-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: FXuerTRSoXroEH71uCPcmrBRZkQIsXY6 X-Proofpoint-GUID: OguB4vA7D6R6gwgBiH7xOztoyR0Vj6Ja X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-07_04,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402070101 Message-ID-Hash: 3UBHNUULZKT2B6JRP4NN2BGGELCXGQKZ X-Message-ID-Hash: 3UBHNUULZKT2B6JRP4NN2BGGELCXGQKZ 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: 1707315041156100001 The configuration of a defined mdev can be modified after the mdev is started. The defined configuration and the active configuration can therefore run out of sync. Handle this by storing the modifiable data which is the mdev type and attributes in two separate active and defined configurations. mdevctl supports with callout scripts to do an attribute retrieval of started mdevs which is already implemented in libvirt. Signed-off-by: Boris Fiuczynski Reviewed-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 11 ++++ src/conf/node_device_conf.c | 53 ++++++++++------ src/conf/node_device_conf.h | 5 +- src/libvirt-nodedev.c | 2 +- src/node_device/node_device_driver.c | 61 +++++++++++++------ src/node_device/node_device_driver.h | 6 +- src/node_device/node_device_udev.c | 4 +- src/test/test_driver.c | 6 +- tests/nodedevmdevctltest.c | 4 +- ...v_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml | 14 +++++ ...d_b7f0_4fea_b468_f1da537d301b_inactive.xml | 1 + ...v_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml | 10 +++ ...c_c60c_c60c_c60c_c60cc60cc60c_inactive.xml | 9 +++ ...9_36ea_4111_8f0a_8c9a70e21366_inactive.xml | 1 + ...9_495e_4243_ad9f_beb3f14c23d9_inactive.xml | 1 + ...4_f554_4dc1_809d_b2a01e8e48ad_inactive.xml | 8 +++ ...6_1ca8_49ac_b176_871d16c13076_inactive.xml | 1 + tests/nodedevxml2xmltest.c | 59 +++++++++++++++--- 18 files changed, 197 insertions(+), 59 deletions(-) create mode 100644 tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c6= 0cc60cc60c.xml create mode 120000 tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1= da537d301b_inactive.xml create mode 100644 tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c6= 0cc60cc60c.xml create mode 100644 tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c6= 0cc60cc60c_inactive.xml create mode 120000 tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366_inactive.xml create mode 120000 tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9_inactive.xml create mode 100644 tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2= a01e8e48ad_inactive.xml create mode 120000 tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076_inactive.xml diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 428b0d722f..53ffce6c69 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -117,6 +117,17 @@ int virNodeDeviceListCaps (virN= odeDevicePtr dev, char **const names, int maxnames); =20 +/** + * virNodeDeviceXMLFlags: + * + * Flags used to provide the state of the returned node device configurati= on. + * + * Since: 10.1.0 + */ +typedef enum { + VIR_NODE_DEVICE_XML_INACTIVE =3D 1 << 0, /* dump inactive d= evice configuration (Since: 10.1.0) */ +} virNodeDeviceXMLFlags; + char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev, unsigned int flags); =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index febc58afd1..4de29ef01f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -602,16 +602,22 @@ virNodeDeviceCapMdevAttrFormat(virBuffer *buf, =20 static void virNodeDeviceCapMdevDefFormat(virBuffer *buf, - const virNodeDevCapData *data) + const virNodeDevCapData *data, + bool defined) { - virBufferEscapeString(buf, "\n", data->mdev.dev_confi= g.type); + if (defined) + virBufferEscapeString(buf, "\n", data->mdev.defin= ed_config.type); + else + virBufferEscapeString(buf, "\n", data->mdev.activ= e_config.type); virBufferEscapeString(buf, "%s\n", data->mdev.uuid); virBufferEscapeString(buf, "%s\n", data->mdev.parent_addr); virBufferAsprintf(buf, "\n", data->mdev.iommuGroupNumber); - - virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.dev_config); + if (defined) + virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.defined_config); + else + virNodeDeviceCapMdevAttrFormat(buf, &data->mdev.active_config); } =20 static void @@ -662,25 +668,28 @@ virNodeDeviceCapCSSDefFormat(virBuffer *buf, =20 =20 char * -virNodeDeviceDefFormat(const virNodeDeviceDef *def) +virNodeDeviceDefFormat(const virNodeDeviceDef *def, unsigned int flags) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; virNodeDevCapsDef *caps; size_t i =3D 0; + bool inactive_state =3D flags & VIR_NODE_DEVICE_XML_INACTIVE; =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); virBufferEscapeString(&buf, "%s\n", def->name); - virBufferEscapeString(&buf, "%s\n", def->sysfs_path); - virBufferEscapeString(&buf, "%s\n", - def->devnode); - if (def->devlinks) { - for (i =3D 0; def->devlinks[i]; i++) - virBufferEscapeString(&buf, "%s\n", - def->devlinks[i]); + if (!inactive_state) { + virBufferEscapeString(&buf, "%s\n", def->sysfs_path); + virBufferEscapeString(&buf, "%s\n", + def->devnode); + if (def->devlinks) { + for (i =3D 0; def->devlinks[i]; i++) + virBufferEscapeString(&buf, "%s\n", + def->devlinks[i]); + } } virBufferEscapeString(&buf, "%s\n", def->parent); - if (def->driver) { + if (def->driver && !inactive_state) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); virBufferEscapeString(&buf, "%s\n", def->driver); @@ -741,7 +750,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; case VIR_NODE_DEV_CAP_MDEV: - virNodeDeviceCapMdevDefFormat(&buf, data); + virNodeDeviceCapMdevDefFormat(&buf, data, inactive_state); break; case VIR_NODE_DEV_CAP_CCW_DEV: virNodeDeviceCapCCWDefFormat(&buf, data); @@ -2207,7 +2216,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, =20 ctxt->node =3D node; =20 - if (!(mdev->dev_config.type =3D virXPathString("string(./type[1]/@id)"= , ctxt))) { + if (!(mdev->defined_config.type =3D virXPathString("string(./type[1]/@= id)", ctxt))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("missing type id attribute for '%1$s'"), def->nam= e); return -1; @@ -2239,7 +2248,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, return -1; =20 for (i =3D 0; i < nattrs; i++) - virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], &mdev->dev_conf= ig); + virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], &mdev->defined_= config); =20 return 0; } @@ -2582,11 +2591,15 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps) g_free(data->sg.path); break; case VIR_NODE_DEV_CAP_MDEV: - g_free(data->mdev.dev_config.type); + g_free(data->mdev.defined_config.type); + g_free(data->mdev.active_config.type); g_free(data->mdev.uuid); - for (i =3D 0; i < data->mdev.dev_config.nattributes; i++) - virMediatedDeviceAttrFree(data->mdev.dev_config.attributes[i]); - g_free(data->mdev.dev_config.attributes); + for (i =3D 0; i < data->mdev.defined_config.nattributes; i++) + virMediatedDeviceAttrFree(data->mdev.defined_config.attributes= [i]); + g_free(data->mdev.defined_config.attributes); + for (i =3D 0; i < data->mdev.active_config.nattributes; i++) + virMediatedDeviceAttrFree(data->mdev.active_config.attributes[= i]); + g_free(data->mdev.active_config.attributes); g_free(data->mdev.parent_addr); break; case VIR_NODE_DEV_CAP_CSS_DEV: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index f100496272..f59440dbb9 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -153,7 +153,8 @@ typedef struct _virNodeDevCapMdev virNodeDevCapMdev; struct _virNodeDevCapMdev { unsigned int iommuGroupNumber; char *uuid; - virMediatedDeviceConfig dev_config; + virMediatedDeviceConfig defined_config; + virMediatedDeviceConfig active_config; char *parent_addr; bool autostart; }; @@ -360,7 +361,7 @@ struct _virNodeDeviceDef { }; =20 char * -virNodeDeviceDefFormat(const virNodeDeviceDef *def); +virNodeDeviceDefFormat(const virNodeDeviceDef *def, unsigned int flags); =20 =20 typedef int (*virNodeDeviceDefPostParseCallback)(virNodeDeviceDef *dev, diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index f0f99bc020..c683b2eef9 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -264,7 +264,7 @@ virNodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, /** * virNodeDeviceGetXMLDesc: * @dev: pointer to the node device - * @flags: extra flags; not used yet, so callers should always pass 0 + * @flags: bitwise-OR of virNodeDeviceXMLFlags * * Fetch an XML document describing all aspects of * the device. diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 7118f833f6..baff49a0ae 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -338,7 +338,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, virNodeDeviceDef *def; char *ret =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_XML_INACTIVE, NULL); =20 if (nodeDeviceInitWait() < 0) return NULL; @@ -356,7 +356,19 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, if (virNodeDeviceUpdateCaps(def) < 0) goto cleanup; =20 - ret =3D virNodeDeviceDefFormat(def); + if (flags & VIR_NODE_DEVICE_XML_INACTIVE) { + if (!virNodeDeviceObjIsPersistent(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("node device '%1$s' is not persistent"), + def->name); + goto cleanup; + } + } else { + if (!virNodeDeviceObjIsActive(obj)) + flags |=3D VIR_NODE_DEVICE_XML_INACTIVE; + } + + ret =3D virNodeDeviceDefFormat(def, flags); =20 cleanup: virNodeDeviceObjEndAPI(&obj); @@ -629,19 +641,20 @@ nodeDeviceAttributesToJSON(virJSONValue *json, /* format a json string that provides configuration information about this= mdev * to the mdevctl utility */ static int -nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf) +nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf, bool defin= ed) { virNodeDevCapMdev *mdev =3D &def->caps->data.mdev; + virMediatedDeviceConfig *mdev_config =3D defined ? &mdev->defined_conf= ig : &mdev->active_config; g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); const char *startval =3D mdev->autostart ? "auto" : "manual"; =20 - if (virJSONValueObjectAppendString(json, "mdev_type", mdev->dev_config= .type) < 0) + if (virJSONValueObjectAppendString(json, "mdev_type", mdev_config->typ= e) < 0) return -1; =20 if (virJSONValueObjectAppendString(json, "start", startval) < 0) return -1; =20 - if (nodeDeviceAttributesToJSON(json, &mdev->dev_config) < 0) + if (nodeDeviceAttributesToJSON(json, mdev_config) < 0) return -1; =20 *buf =3D virJSONValueToString(json, false); @@ -760,7 +773,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, return NULL; } =20 - if (nodeDeviceDefToMdevctlConfig(def, &inbuf) < 0) { + if (nodeDeviceDefToMdevctlConfig(def, &inbuf, true) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("couldn't convert node device def to mdevctl = JSON")); return NULL; @@ -1138,9 +1151,11 @@ nodeDeviceParseMdevctlAttributes(virMediatedDeviceCo= nfig *config, =20 static virNodeDeviceDef* nodeDeviceParseMdevctlChildDevice(const char *parent, - virJSONValue *json) + virJSONValue *json, + bool defined) { virNodeDevCapMdev *mdev; + virMediatedDeviceConfig *mdev_config; const char *uuid; virJSONValue *props; g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); @@ -1170,14 +1185,15 @@ nodeDeviceParseMdevctlChildDevice(const char *paren= t, child->caps->data.type =3D VIR_NODE_DEV_CAP_MDEV; =20 mdev =3D &child->caps->data.mdev; + mdev_config =3D defined ? &mdev->defined_config : &mdev->active_config; mdev->uuid =3D g_strdup(uuid); mdev->parent_addr =3D g_strdup(parent); - mdev->dev_config.type =3D + mdev_config->type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type")); start =3D virJSONValueObjectGetString(props, "start"); mdev->autostart =3D STREQ_NULLABLE(start, "auto"); =20 - if (nodeDeviceParseMdevctlAttributes(&mdev->dev_config, + if (nodeDeviceParseMdevctlAttributes(mdev_config, virJSONValueObjectGet(props, "att= rs")) < 0) return NULL; =20 @@ -1189,7 +1205,8 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, =20 int nodeDeviceParseMdevctlJSON(const char *jsonstring, - virNodeDeviceDef ***devs) + virNodeDeviceDef ***devs, + bool defined) { int n; g_autoptr(virJSONValue) json_devicelist =3D NULL; @@ -1259,7 +1276,7 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, g_autoptr(virNodeDeviceDef) child =3D NULL; virJSONValue *child_obj =3D virJSONValueArrayGet(child_array, = j); =20 - if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj))) { + if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj, defined))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to parse child device")); goto error; @@ -1402,7 +1419,7 @@ nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *def, /* Active devices contain some additional information (e.g. sysfs * path) that is not provided by mdevctl, so re-use the existing * definition and copy over new mdev data */ - changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned); + changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned, defined); =20 if (was_defined && !changed) { /* if this device was already defined and the definition @@ -1672,7 +1689,7 @@ virMdevctlList(bool defined, return -1; } =20 - return nodeDeviceParseMdevctlJSON(output, devs); + return nodeDeviceParseMdevctlJSON(output, devs, defined); } =20 =20 @@ -1829,16 +1846,24 @@ virMediatedDeviceAttrsCopy(virMediatedDeviceConfig = *dst_config, * Returns true if anything was copied, else returns false */ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, - virNodeDeviceDef *src) + virNodeDeviceDef *src, + bool defined) { bool ret =3D false; virNodeDevCapMdev *srcmdev =3D &src->caps->data.mdev; virNodeDevCapMdev *dstmdev =3D &dst->caps->data.mdev; + virMediatedDeviceConfig *srcmdevconfig =3D &src->caps->data.mdev.activ= e_config; + virMediatedDeviceConfig *dstmdevconfig =3D &dst->caps->data.mdev.activ= e_config; + + if (defined) { + srcmdevconfig =3D &src->caps->data.mdev.defined_config; + dstmdevconfig =3D &dst->caps->data.mdev.defined_config; + } =20 - if (STRNEQ_NULLABLE(dstmdev->dev_config.type, srcmdev->dev_config.type= )) { + if (STRNEQ_NULLABLE(dstmdevconfig->type, srcmdevconfig->type)) { ret =3D true; - g_free(dstmdev->dev_config.type); - dstmdev->dev_config.type =3D g_strdup(srcmdev->dev_config.type); + g_free(dstmdevconfig->type); + dstmdevconfig->type =3D g_strdup(srcmdevconfig->type); } =20 if (STRNEQ_NULLABLE(dstmdev->uuid, srcmdev->uuid)) { @@ -1847,7 +1872,7 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, dstmdev->uuid =3D g_strdup(srcmdev->uuid); } =20 - if (virMediatedDeviceAttrsCopy(&dstmdev->dev_config, &srcmdev->dev_con= fig)) + if (virMediatedDeviceAttrsCopy(dstmdevconfig, srcmdevconfig)) ret =3D true; =20 if (dstmdev->autostart !=3D srcmdev->autostart) { diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index c7d5e22daf..4dce7e6f17 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -142,7 +142,8 @@ nodeDeviceGetMdevctlListCommand(bool defined, =20 int nodeDeviceParseMdevctlJSON(const char *jsonstring, - virNodeDeviceDef ***devs); + virNodeDeviceDef ***devs, + bool defined); =20 int nodeDeviceUpdateMediatedDevices(void); @@ -154,7 +155,8 @@ nodeDeviceGenerateName(virNodeDeviceDef *def, const char *s); =20 bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, - virNodeDeviceDef *src); + virNodeDeviceDef *src, + bool defined); =20 int nodeDeviceCreate(virNodeDevice *dev, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 254e802c50..57368a96c3 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1069,7 +1069,7 @@ udevProcessMediatedDevice(struct udev_device *dev, return -1; } =20 - data->dev_config.type =3D g_path_get_basename(canonicalpath); + data->active_config.type =3D g_path_get_basename(canonicalpath); =20 data->uuid =3D g_strdup(udev_device_get_sysname(dev)); if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(data->uuid)) < 0) @@ -1572,7 +1572,7 @@ udevAddOneDevice(struct udev_device *device) objdef =3D virNodeDeviceObjGetDef(obj); =20 if (is_mdev) - nodeDeviceDefCopyFromMdevctl(def, objdef); + nodeDeviceDefCopyFromMdevctl(def, objdef, false); =20 persistent =3D virNodeDeviceObjIsPersistent(obj); autostart =3D virNodeDeviceObjIsAutostart(obj); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ed545848af..ed0cdc0dab 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7514,12 +7514,12 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virNodeDeviceObj *obj; char *ret =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_XML_INACTIVE, NULL); =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) return NULL; =20 - ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj)); + ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj), flags); =20 virNodeDeviceObjEndAPI(&obj); return ret; @@ -7619,7 +7619,7 @@ testNodeDeviceMockCreateVport(testDriver *driver, "scsi_host11"))) goto cleanup; =20 - xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy)); + xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy), 0); virNodeDeviceObjEndAPI(&objcopy); if (!xml) goto cleanup; diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index e403328e5a..f49d668461 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -229,13 +229,13 @@ testMdevctlParse(const void *data) return -1; } =20 - if ((nmdevs =3D nodeDeviceParseMdevctlJSON(buf, &mdevs)) < 0) { + if ((nmdevs =3D nodeDeviceParseMdevctlJSON(buf, &mdevs, true)) < 0) { VIR_TEST_DEBUG("Unable to parse json for %s", filename); return -1; } =20 for (i =3D 0; i < nmdevs; i++) { - g_autofree char *devxml =3D virNodeDeviceDefFormat(mdevs[i]); + g_autofree char *devxml =3D virNodeDeviceDefFormat(mdevs[i], VIR_N= ODE_DEVICE_XML_INACTIVE); if (!devxml) goto cleanup; virBufferAddStr(&xmloutbuf, devxml); diff --git a/tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc= 60c.xml b/tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c= .xml new file mode 100644 index 0000000000..6926559efa --- /dev/null +++ b/tests/nodedevschemadata/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml @@ -0,0 +1,14 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + /sys/devices/css0/0.0.0052/c60cc60c-c60c-c60c-c60c-c60cc60cc60c + css_0_0_0052 + + vfio_ccw_mdev + + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + 0.0.0052 + + + diff --git a/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d3= 01b_inactive.xml b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1d= a537d301b_inactive.xml new file mode 120000 index 0000000000..f8ec7d8a32 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b_ina= ctive.xml @@ -0,0 +1 @@ +mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc= 60c.xml b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c= .xml new file mode 100644 index 0000000000..82c60cc065 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c.xml @@ -0,0 +1,10 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + /sys/devices/css0/0.0.0052/c60cc60c-c60c-c60c-c60c-c60cc60cc60c + css_0_0_0052 + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + + + diff --git a/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc= 60c_inactive.xml b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60= cc60cc60c_inactive.xml new file mode 100644 index 0000000000..87c5ed1340 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_ina= ctive.xml @@ -0,0 +1,9 @@ + + mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c_0_0_0052 + css_0_0_0052 + + + c60cc60c-c60c-c60c-c60c-c60cc60cc60c + + + diff --git a/tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c9a70e21= 366_inactive.xml b/tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c9= a70e21366_inactive.xml new file mode 120000 index 0000000000..f6d5789399 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366_ina= ctive.xml @@ -0,0 +1 @@ +mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_beb3f14c2= 3d9_inactive.xml b/tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_beb= 3f14c23d9_inactive.xml new file mode 120000 index 0000000000..233a7506fb --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9_ina= ctive.xml @@ -0,0 +1 @@ +mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e4= 8ad_inactive.xml b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a= 01e8e48ad_inactive.xml new file mode 100644 index 0000000000..8c4983f43c --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad_ina= ctive.xml @@ -0,0 +1,8 @@ + + mdev_ee0b88c4-f554-4dc1-809d-b2a01e8e48ad + ap_matrix + + + + + diff --git a/tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_871d16c13= 076_inactive.xml b/tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_871= d16c13076_inactive.xml new file mode 120000 index 0000000000..e053844177 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_fedc4916_1ca8_49ac_b176_871d16c13076_ina= ctive.xml @@ -0,0 +1 @@ +mdev_fedc4916_1ca8_49ac_b176_871d16c13076.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index 068ec68769..10e88f7779 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -11,14 +11,20 @@ =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 +struct TestData { + const char *filename; + unsigned int flags; +}; + static int -testCompareXMLToXMLFiles(const char *xml, const char *outfile) +testCompareXMLToXMLFiles(const char *xml, const char *outfile, unsigned in= t flags) { g_autofree char *xmlData =3D NULL; g_autofree char *actual =3D NULL; int ret =3D -1; virNodeDeviceDef *dev =3D NULL; virNodeDevCapsDef *caps; + size_t i; =20 if (virTestLoadFile(xml, &xmlData) < 0) goto fail; @@ -46,9 +52,22 @@ testCompareXMLToXMLFiles(const char *xml, const char *ou= tfile) data->storage.logical_block_siz= e; } } + + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV && + !(flags & VIR_NODE_DEVICE_XML_INACTIVE)) { + data->mdev.active_config.type =3D g_strdup(data->mdev.defined_= config.type); + for (i =3D 0; i < data->mdev.defined_config.nattributes; i++) { + g_autoptr(virMediatedDeviceAttr) attr =3D g_new0(virMediat= edDeviceAttr, 1); + attr->name =3D g_strdup(data->mdev.defined_config.attribut= es[i]->name); + attr->value =3D g_strdup(data->mdev.defined_config.attribu= tes[i]->value); + VIR_APPEND_ELEMENT(data->mdev.active_config.attributes, + data->mdev.active_config.nattributes, + attr); + } + } } =20 - if (!(actual =3D virNodeDeviceDefFormat(dev))) + if (!(actual =3D virNodeDeviceDefFormat(dev, flags))) goto fail; =20 if (virTestCompareToFile(actual, outfile) < 0) @@ -65,16 +84,21 @@ static int testCompareXMLToXMLHelper(const void *data) { int result =3D -1; + const struct TestData *tdata =3D data; g_autofree char *xml =3D NULL; g_autofree char *outfile =3D NULL; =20 xml =3D g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, - (const char *)data); + tdata->filename); =20 - outfile =3D g_strdup_printf("%s/nodedevxml2xmlout/%s.xml", abs_srcdir, - (const char *)data); + if (tdata->flags & VIR_NODE_DEVICE_XML_INACTIVE) + outfile =3D g_strdup_printf("%s/nodedevxml2xmlout/%s_inactive.xml"= , abs_srcdir, + tdata->filename); + else + outfile =3D g_strdup_printf("%s/nodedevxml2xmlout/%s.xml", abs_src= dir, + tdata->filename); =20 - result =3D testCompareXMLToXMLFiles(xml, outfile); + result =3D testCompareXMLToXMLFiles(xml, outfile, tdata->flags); =20 return result; } @@ -85,10 +109,20 @@ mymain(void) { int ret =3D 0; =20 +#define DO_TEST_FLAGS(desc, filename, flags) \ + do { \ + struct TestData data =3D { filename, flags }; \ + if (virTestRun(desc, testCompareXMLToXMLHelper, &data) < 0) \ + ret =3D -1; \ + } \ + while (0) + #define DO_TEST(name) \ - if (virTestRun("Node device XML-2-XML " name, \ - testCompareXMLToXMLHelper, (name)) < 0) \ - ret =3D -1 + DO_TEST_FLAGS("Node device XML-2-XML " name, name, 0) + +#define DO_TEST_INACTIVE(name) \ + DO_TEST_FLAGS("Node device XML-2-XML INACTIVE " name, \ + name, VIR_NODE_DEVICE_XML_INACTIVE) =20 DO_TEST("computer"); DO_TEST("DVD_GCC_4247N"); @@ -121,6 +155,7 @@ mymain(void) DO_TEST("pci_0000_02_10_7_mdev_types"); DO_TEST("pci_0000_42_00_0_vpd"); DO_TEST("mdev_3627463d_b7f0_4fea_b468_f1da537d301b"); + DO_TEST_INACTIVE("mdev_3627463d_b7f0_4fea_b468_f1da537d301b"); DO_TEST("ccw_0_0_ffff"); DO_TEST("css_0_0_ffff"); DO_TEST("css_0_0_ffff_channel_dev_addr"); @@ -134,7 +169,13 @@ mymain(void) DO_TEST("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); DO_TEST("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); DO_TEST("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST_INACTIVE("mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad"); + DO_TEST_INACTIVE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_INACTIVE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); + DO_TEST_INACTIVE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST("hba_vport_ops"); + DO_TEST("mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c"); + DO_TEST_INACTIVE("mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.42.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org