On 6/9/20 11:43 PM, 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(a)redhat.com>
---
docs/formatnode.html.in | 7 +++++
docs/schemas/nodedev.rng | 6 ++++
src/conf/node_device_conf.c | 59 +++++++++++++++++++++++++++++++++++--
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, 96 insertions(+), 3 deletions(-)
+static int
+virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt,
+ xmlNodePtr node,
+ virNodeDevCapMdevPtr mdev)
+{
+ xmlNodePtr orig_node = node;
+ ctxt->node = node;
Alternatively, VIR_XPATH_NODE_AUTORESTORE() can be used.
+ int ret = -1;
+ g_autoptr(virMediatedDeviceAttr) attr = virMediatedDeviceAttrNew();
+
+ 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"));
+ goto cleanup;
+ }
+
+ if (VIR_APPEND_ELEMENT(mdev->attributes,
+ mdev->nattributes,
+ attr) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ ctxt->node = orig_node;
+ return ret;
+}
static int
virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
@@ -1766,6 +1808,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
{
VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1;
+ int nattrs = 0;
+ xmlNodePtr *attrs;
g_autofree becasue ..
+ size_t i;
ctxt->node = node;
@@ -1783,6 +1828,11 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
"'%s'")) < 0)
goto out;
+ if ((nattrs = virXPathNodeSet("./attr", ctxt, &attrs)) < 0)
+ goto out;
.. this allocates @attrs array.
+ for (i = 0; i < nattrs; i++)
+ virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], mdev);
+
ret = 0;
out:
return ret;
Just squash this in:
diff --git i/src/conf/node_device_conf.c w/src/conf/node_device_conf.c
index 045d146433..7b2a8c5545 100644
--- i/src/conf/node_device_conf.c
+++ w/src/conf/node_device_conf.c
@@ -1775,29 +1775,21 @@
virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node,
virNodeDevCapMdevPtr mdev)
{
- xmlNodePtr orig_node = node;
- ctxt->node = node;
- int ret = -1;
+ 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"));
- goto cleanup;
+ return -1;
}
- if (VIR_APPEND_ELEMENT(mdev->attributes,
- mdev->nattributes,
- attr) < 0)
- goto cleanup;
-
- ret = 0;
-
- cleanup:
- ctxt->node = orig_node;
- return ret;
+ return VIR_APPEND_ELEMENT(mdev->attributes,
+ mdev->nattributes,
+ attr);
}
static int
@@ -1809,7 +1801,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1;
int nattrs = 0;
- xmlNodePtr *attrs;
+ g_autofree xmlNodePtr *attrs = NULL;
size_t i;
ctxt->node = node;
Michal