]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONCheckError: Allow suppressing of error reporting
authorPeter Krempa <pkrempa@redhat.com>
Wed, 18 Mar 2020 10:08:58 +0000 (11:08 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 19 Mar 2020 08:57:46 +0000 (09:57 +0100)
In some cases we'll need to check whether there was an error but avoid
reporting an actual libvirt error. Rename qemuMonitorJSONCheckError to
qemuMonitorJSONCheckErrorFull with a new flag to suppress the error
reporting and add a wrapper with the original name so that callers don't
need to be fixed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index 31eb01006c0339e0b14fbd8b223beb087507f425..c18cef5c1a8c7e6f1ffef91218a8c1e9a7cab866 100644 (file)
@@ -388,8 +388,9 @@ qemuMonitorJSONCommandName(virJSONValuePtr cmd)
 }
 
 static int
-qemuMonitorJSONCheckError(virJSONValuePtr cmd,
-                          virJSONValuePtr reply)
+qemuMonitorJSONCheckErrorFull(virJSONValuePtr cmd,
+                              virJSONValuePtr reply,
+                              bool report)
 {
     if (virJSONValueObjectHasKey(reply, "error")) {
         virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
@@ -400,6 +401,9 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
         VIR_DEBUG("unable to execute QEMU command %s: %s",
                   NULLSTR(cmdstr), NULLSTR(replystr));
 
+        if (!report)
+            return -1;
+
         /* Only send the user the command name + friendly error */
         if (!error)
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -418,6 +422,10 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
 
         VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
                   NULLSTR(cmdstr), NULLSTR(replystr));
+
+        if (!report)
+            return -1;
+
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to execute QEMU command '%s'"),
                        qemuMonitorJSONCommandName(cmd));
@@ -427,6 +435,14 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
 }
 
 
+static int
+qemuMonitorJSONCheckError(virJSONValuePtr cmd,
+                          virJSONValuePtr reply)
+{
+    return qemuMonitorJSONCheckErrorFull(cmd, reply, true);
+}
+
+
 static int
 qemuMonitorJSONCheckReply(virJSONValuePtr cmd,
                           virJSONValuePtr reply,