nodedev: fix internal error when no defined mdevs exist

Commit e9b534905f introduced an error when parsing an empty list
returned from mdevctl.

This occurs e.g. if nodedev-undefine is used to undefine the last
defined mdev which causes the following error messages

 libvirtd[33143]: internal error: Unexpected format for mdevctl response
 libvirtd[33143]: internal error: failed to query mdevs from mdevctl:
 libvirtd[33143]: mdevctl failed to updated mediated devices

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Shalini Chellathurai Saroja <shalini@linux.ibm.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Boris Fiuczynski 2021-07-21 13:30:00 +02:00 committed by Jonathon Jongsma
parent 299174c532
commit 19b088cfb9
4 changed files with 8 additions and 0 deletions

View File

@ -1139,6 +1139,12 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring,
goto error;
}
if (virJSONValueArraySize(json_devicelist) == 0) {
VIR_DEBUG("mdevctl has no defined mediated devices");
*devs = NULL;
return 0;
}
/* mdevctl list --dumpjson produces an output that is an array that
* contains only a single object which contains a property for each parent
* device */

View File

@ -0,0 +1 @@
[]

View File

@ -360,6 +360,7 @@ mymain(void)
DO_TEST_LIST_DEFINED();
DO_TEST_PARSE_JSON("mdevctl-list-empty");
DO_TEST_PARSE_JSON("mdevctl-list-multiple");
DO_TEST_DEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");