]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodeDeviceParseMdevctlJSON: Accept empty string
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Aug 2023 08:08:07 +0000 (10:08 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Aug 2023 11:45:55 +0000 (13:45 +0200)
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>
src/node_device/node_device_driver.c

index 2ef9197adca22568a6de1ed385bfb7f2dff06321..593bc64e25612ecedae24d6d0d0a311d0ebd82d1 100644 (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)) {