nodeDeviceParseMdevctlJSON: Accept empty string

It is possible for 'mdevctl' to output nothing, an empty string
(e.g. when no mediated devices are defined on the host). What is
weird is that when passing '--defined' then 'mdevctl' outputs an
empty JSON array instead. Nevertheless, we should accept both and
treat them the same, i.e. as no mediated devices.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/523
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
This commit is contained in:
Michal Privoznik 2023-08-24 10:08:07 +02:00
parent 857efc74fe
commit 4e00d7fb04

View File

@ -43,6 +43,7 @@
#include "virutil.h"
#include "vircommand.h"
#include "virlog.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@ -1176,6 +1177,12 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring,
size_t j;
virJSONValue *obj;
if (virStringIsEmpty(jsonstring)) {
VIR_DEBUG("mdevctl has no defined mediated devices");
*devs = NULL;
return 0;
}
json_devicelist = virJSONValueFromString(jsonstring);
if (!json_devicelist || !virJSONValueIsArray(json_devicelist)) {