]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: fix internal error when no defined mdevs exist
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Wed, 21 Jul 2021 11:30:00 +0000 (13:30 +0200)
committerJonathon Jongsma <jjongsma@redhat.com>
Thu, 22 Jul 2021 15:53:44 +0000 (10:53 -0500)
Commit e9b534905f4 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>
src/node_device/node_device_driver.c
tests/nodedevmdevctldata/mdevctl-list-empty.json [new file with mode: 0644]
tests/nodedevmdevctldata/mdevctl-list-empty.out.xml [new file with mode: 0644]
tests/nodedevmdevctltest.c

index 17a7aea2bb0fe72943c40caae51a4b4b91fe60b9..6f8968f1f09427479530d85c63e381a03eaf6e1a 100644 (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 */
diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.json b/tests/nodedevmdevctldata/mdevctl-list-empty.json
new file mode 100644 (file)
index 0000000..fe51488
--- /dev/null
@@ -0,0 +1 @@
+[]
diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.out.xml b/tests/nodedevmdevctldata/mdevctl-list-empty.out.xml
new file mode 100644 (file)
index 0000000..e69de29
index 8ba1d2da702e22dfc0e02cef8232f06be366dd8e..e246de4d87447371eaf1953b7f26774974480f81 100644 (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");