nodedev: Add parser validation for node devices

At the moment, this is only for mediated devices. When a new mediated
device is created or defined, the xml is expected specify the nodedev
name of an existing device as its parent. We were not previously
validating this and were simply accepting any string here.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jonathon Jongsma
2021-07-16 13:46:52 -05:00
parent e44408dd9c
commit d5ae634ba2
10 changed files with 129 additions and 18 deletions

View File

@@ -12,6 +12,10 @@
#define VIRT_TYPE "QEMU"
static virNodeDeviceDefParserCallbacks parser_callbacks = {
.validate = nodeDeviceDefValidate
};
struct TestInfo {
const char *filename;
virMdevctlCommand command;
@@ -66,7 +70,8 @@ testMdevctlCmd(virMdevctlCommand cmd_type,
return -1;
}
if (!(def = virNodeDeviceDefParseFile(mdevxml, create, VIRT_TYPE)))
if (!(def = virNodeDeviceDefParseFile(mdevxml, create, VIRT_TYPE,
&parser_callbacks, NULL)))
return -1;
/* this function will set a stdin buffer containing the json configuration

View File

@@ -25,7 +25,8 @@ testCompareXMLToXMLFiles(const char *xml, const char *outfile)
if (virTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE, NULL)))
if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE, NULL,
NULL, NULL)))
goto fail;
/* Calculate some things that are not read in */