On Tue, Jun 16, 2020 at 09:27:51AM -0500, Jonathon Jongsma wrote: > 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 <jjongsma@xxxxxxxxxx> > --- > 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. > </dd> > + <dt><code>attr</code></dt> > + <dd> > + This optional element can occur multiple times. It represents a > + vendor-specific attribute that is used to configure this > + mediated device. It has two required attributes: > + <code>name</code> and <code>value</code>. > + </dd> > </dl> > </dd> > <dt><code>ccw</code></dt> > 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 @@ > </attribute> > </element> > </optional> > + <zeroOrMore> > + <element name="attr"> > + <attribute name="name"/> > + <attribute name="value"/> > + </element> > + </zeroOrMore> > </define> > > <define name='capccwdev'> > 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, "<capability type='hotpluggable'/>\n"); > } > > +static void > +virNodeDeviceCapMdevDefFormat(virBufferPtr buf, > + const virNodeDevCapData *data) > +{ > + size_t i; > + > + virBufferEscapeString(buf, "<type id='%s'/>\n", data->mdev.type); > + virBufferAsprintf(buf, "<iommuGroup number='%u'/>\n", > + data->mdev.iommuGroupNumber); An empty line would be nice here. > + for (i = 0; i < data->mdev.nattributes; i++) { > + virMediatedDeviceAttrPtr attr = data->mdev.attributes[i]; > + virBufferAsprintf(buf, "<attr name='%s' value='%s'/>\n", > + attr->name, attr->value); > + } > +} > > char * > virNodeDeviceDefFormat(const virNodeDeviceDef *def) > @@ -583,9 +598,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) > virBufferEscapeString(&buf, "<type>%s</type>\n", virNodeDevDRMTypeToString(data->drm.type)); > break; > case VIR_NODE_DEV_CAP_MDEV: > - virBufferEscapeString(&buf, "<type id='%s'/>\n", data->mdev.type); > - virBufferAsprintf(&buf, "<iommuGroup number='%u'/>\n", > - data->mdev.iommuGroupNumber); > + virNodeDeviceCapMdevDefFormat(&buf, data); > break; > case VIR_NODE_DEV_CAP_CCW_DEV: > virBufferAsprintf(&buf, "<cssid>0x%x</cssid>\n", > @@ -1757,6 +1770,27 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, > return ret; > } > > +static int > +virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt, > + xmlNodePtr node, > + virNodeDevCapMdevPtr mdev) > +{ > + VIR_XPATH_NODE_AUTORESTORE(ctxt); > + g_autoptr(virMediatedDeviceAttr) attr = virMediatedDeviceAttrNew(); > + > + ctxt->node = node; > + attr->name = virXPathString("string(./@name)", ctxt); > + attr->value = 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); > +} > > static int > virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, > @@ -1766,6 +1800,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, > { > VIR_XPATH_NODE_AUTORESTORE(ctxt); > int ret = -1; > + int nattrs = 0; > + g_autofree xmlNodePtr *attrs = NULL; > + size_t i; > > ctxt->node = node; > > @@ -1783,6 +1820,11 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, > goto out; > } > > + if ((nattrs = virXPathNodeSet("./attr", ctxt, &attrs)) < 0) > + goto out; ...here too.. Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>