From nobody Sat Feb 7 07:31:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592317696; cv=none; d=zohomail.com; s=zohoarc; b=OMxcfabWIhsGkPc7yIy6zsAPBGNa4fipWKxIGmiXtwyAqnyWv3Dl5ZBdKqTUFAPM8MwxNr3rBIgO4zIUO9VvUTNJEDk/PG6pnOptEnUtm21CTLIrVYmzrmZNHXtUORMmNrV3SWxqRd1yBliJAC9fkxLZaF+YTcvn2jMBP9njbp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317696; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HQoTl+MtAjR/0BC1GX6vKPRDvYNtU7vEKq65RioJVa0=; b=NBc1hv6jbS7BV9mBTIjjIueFAFIKN19LQNbjXDLsr/Fxe9WY4X6B12zSeDmjgd7wYnmN7xCw7jYPJpyuHpZ5Kra04/jracmFvpP3Tl1zYD7KIJ822yqvM6W2Z0UvfPKIVIWP7bOrKjlLswiWdJ0zbskRf26Rltew7TC15biJ8rM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1592317696481109.16991116913584; Tue, 16 Jun 2020 07:28:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-F6YJd1tyMJ69hybPGs6hxw-1; Tue, 16 Jun 2020 10:28:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE59118585C7; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ABD151002393; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7EF40833BD; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05GES4f5020332 for ; Tue, 16 Jun 2020 10:28:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ABA678F0F; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FECD7890A; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317695; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HQoTl+MtAjR/0BC1GX6vKPRDvYNtU7vEKq65RioJVa0=; b=DIDdqz3chsMCOMXaH06Zjo/spLLkjiX5ihynR6yQtsn79OYJj+vl5tLeUU+isSuinX7TCh FvspAWVEGYhy1j/BpZ6WBpmgGZhfsViuaqthDzTppFboveN8v8anwb+TBEzn3GDzs6HUaH EDdTer9S4pDet4OeLGFi6lel5DaxuCo= X-MC-Unique: F6YJd1tyMJ69hybPGs6hxw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 03/11] nodedev: add support for mdev attributes Date: Tue, 16 Jun 2020 09:27:51 -0500 Message-Id: <20200616142759.4625-4-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Mediated devices support arbitrary vendor-specific attributes that can be attached to a mediated device. These attributes are ordered, and are written to sysfs in order after a device is created. This patch adds support for these attributes to the mdev data types and XML schema. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- docs/formatnode.html.in | 7 +++++ docs/schemas/nodedev.rng | 6 +++++ src/conf/node_device_conf.c | 51 ++++++++++++++++++++++++++++++++++--- src/conf/node_device_conf.h | 2 ++ src/libvirt_private.syms | 2 ++ src/util/virmdev.c | 12 +++++++++ src/util/virmdev.h | 11 ++++++++ 7 files changed, 88 insertions(+), 3 deletions(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 4ed43ec0cb..0637d457ee 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -394,6 +394,13 @@ belongs. This is a read-only field that is reported by the device driver. +
attr
+
+ This optional element can occur multiple times. It represe= nts a + vendor-specific attribute that is used to configure this + mediated device. It has two required attributes: + name and value. +
ccw
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index ca3a79db87..4b2b350fd8 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -636,6 +636,12 @@ + + + + + + =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4b3b04b7b8..b1dfe81653 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -500,6 +500,21 @@ virNodeDeviceCapStorageDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); } =20 +static void +virNodeDeviceCapMdevDefFormat(virBufferPtr buf, + const virNodeDevCapData *data) +{ + size_t i; + + virBufferEscapeString(buf, "\n", data->mdev.type); + virBufferAsprintf(buf, "\n", + data->mdev.iommuGroupNumber); + for (i =3D 0; i < data->mdev.nattributes; i++) { + virMediatedDeviceAttrPtr attr =3D data->mdev.attributes[i]; + virBufferAsprintf(buf, "\n", + attr->name, attr->value); + } +} =20 char * virNodeDeviceDefFormat(const virNodeDeviceDef *def) @@ -583,9 +598,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; case VIR_NODE_DEV_CAP_MDEV: - virBufferEscapeString(&buf, "\n", data->mdev.= type); - virBufferAsprintf(&buf, "\n", - data->mdev.iommuGroupNumber); + virNodeDeviceCapMdevDefFormat(&buf, data); break; case VIR_NODE_DEV_CAP_CCW_DEV: virBufferAsprintf(&buf, "0x%x\n", @@ -1757,6 +1770,27 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; } =20 +static int +virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapMdevPtr mdev) +{ + VIR_XPATH_NODE_AUTORESTORE(ctxt); + g_autoptr(virMediatedDeviceAttr) attr =3D virMediatedDeviceAttrNew(); + + ctxt->node =3D node; + attr->name =3D virXPathString("string(./@name)", ctxt); + attr->value =3D virXPathString("string(./@value)", ctxt); + if (!attr->name || !attr->value) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("mdev attribute missing name or value")); + return -1; + } + + return VIR_APPEND_ELEMENT(mdev->attributes, + mdev->nattributes, + attr); +} =20 static int virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, @@ -1766,6 +1800,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, { VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; + int nattrs =3D 0; + g_autofree xmlNodePtr *attrs =3D NULL; + size_t i; =20 ctxt->node =3D node; =20 @@ -1783,6 +1820,11 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, goto out; } =20 + if ((nattrs =3D virXPathNodeSet("./attr", ctxt, &attrs)) < 0) + goto out; + for (i =3D 0; i < nattrs; i++) + virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], mdev); + ret =3D 0; out: return ret; @@ -2172,6 +2214,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) break; case VIR_NODE_DEV_CAP_MDEV: VIR_FREE(data->mdev.type); + for (i =3D 0; i < data->mdev.nattributes; i++) + virMediatedDeviceAttrFree(data->mdev.attributes[i]); + VIR_FREE(data->mdev.attributes); break; case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_DRM: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 9e4b0847fb..e3e1e788d4 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -141,6 +141,8 @@ typedef virNodeDevCapMdev *virNodeDevCapMdevPtr; struct _virNodeDevCapMdev { char *type; unsigned int iommuGroupNumber; + virMediatedDeviceAttrPtr *attributes; + size_t nattributes; }; =20 typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fc7406f2b7..97d790aced 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2487,6 +2487,8 @@ virMacMapRemove; virMacMapWriteFile; =20 # util/virmdev.h +virMediatedDeviceAttrFree; +virMediatedDeviceAttrNew; virMediatedDeviceFree; virMediatedDeviceGetIOMMUGroupDev; virMediatedDeviceGetIOMMUGroupNum; diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 51a88a91d7..b8023dd991 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -512,3 +512,15 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, =20 return 0; } + +virMediatedDeviceAttrPtr virMediatedDeviceAttrNew(void) +{ + return g_new0(virMediatedDeviceAttr, 1); +} + +void virMediatedDeviceAttrFree(virMediatedDeviceAttrPtr attr) +{ + g_free(attr->name); + g_free(attr->value); + g_free(attr); +} diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 51f7f608a2..eb167ccb48 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -37,6 +37,17 @@ typedef struct _virMediatedDevice virMediatedDevice; typedef virMediatedDevice *virMediatedDevicePtr; typedef struct _virMediatedDeviceList virMediatedDeviceList; typedef virMediatedDeviceList *virMediatedDeviceListPtr; +typedef struct _virMediatedDeviceAttr virMediatedDeviceAttr; +typedef virMediatedDeviceAttr *virMediatedDeviceAttrPtr; + +struct _virMediatedDeviceAttr { + char *name; + char *value; +}; + +virMediatedDeviceAttrPtr virMediatedDeviceAttrNew(void); +void virMediatedDeviceAttrFree(virMediatedDeviceAttrPtr attr); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceAttr, virMediatedDeviceAttr= Free); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceList, virObjectUnref); =20 --=20 2.21.3