From 07666e292e731910208a86ee1cafab34af71e112 Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Fri, 29 Jan 2021 15:24:10 -0600 Subject: [PATCH] nodedev: add element to mdev caps It will be useful to be able to specify a particular UUID for a mediated device when defining the node device. To accomodate that, allow this to be specified in the xml schema. This patch also parses and formats that value to the xml, but does not yet use it. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- docs/schemas/nodedev.rng | 43 +++++++++++-------- src/conf/node_device_conf.c | 14 ++++++ .../mdevctl-list-multiple.out.xml | 4 ++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 5840dc9f0d..777227c38a 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -606,27 +606,34 @@ - - mdev - - - - + + + mdev - - - - - + + + - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index b1739ceb01..d167da6171 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -527,6 +527,7 @@ virNodeDeviceCapMdevDefFormat(virBufferPtr buf, size_t i; virBufferEscapeString(buf, "\n", data->mdev.type); + virBufferEscapeString(buf, "%s\n", data->mdev.uuid); virBufferAsprintf(buf, "\n", data->mdev.iommuGroupNumber); @@ -1948,6 +1949,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, int nattrs = 0; g_autofree xmlNodePtr *attrs = NULL; size_t i; + g_autofree char *uuidstr = NULL; ctxt->node = node; @@ -1957,6 +1959,18 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, return -1; } + if ((uuidstr = virXPathString("string(./uuid[1])", ctxt))) { + unsigned char uuidbuf[VIR_UUID_BUFLEN]; + /* make sure that the provided uuid is valid */ + if (virUUIDParse(uuidstr, uuidbuf) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid uuid '%s' for new mdev device"), uuidstr); + return -1; + } + mdev->uuid = g_new0(char, VIR_UUID_STRING_BUFLEN); + virUUIDFormat(uuidbuf, mdev->uuid); + } + /* 'iommuGroup' is optional, only report an error if the supplied value is * invalid (-2), not if it's missing (-1) */ if (virXPathUInt("number(./iommuGroup[1]/@number)", diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml index 543ad916b7..cf7e966256 100644 --- a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -3,6 +3,7 @@ 0000:00:02.0 + 200f228a-c80a-4d50-bfb7-f5a0e4e34045 @@ -11,6 +12,7 @@ 0000:00:02.0 + de807ffc-1923-4d5f-b6c9-b20ecebc6d4b @@ -19,6 +21,7 @@ 0000:00:02.0 + 435722ea-5f43-468a-874f-da34f1217f13 @@ -28,6 +31,7 @@ matrix + 783e6dbb-ea0e-411f-94e2-717eaad438bf