]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentCommand: Wire up suppressing of error reporting for unsupported commands
authorPeter Krempa <pkrempa@redhat.com>
Fri, 13 Mar 2020 08:49:35 +0000 (09:49 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Mar 2020 11:02:20 +0000 (12:02 +0100)
In some cases we don't want to log errors if an agent command is
unsupported. Wire it up into qemuAgentCheckError via qemuAgentCommandFull
and provide a thin wrapper (qemuAgentCommand) to prevent having to fix
all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_agent.c

index 56181d5404ff2d3d2888a0fbbe99224d93135f74..8b6b774263162736ee442cf2303c8a8578cac1e4 100644 (file)
@@ -1051,7 +1051,8 @@ qemuAgentCommandName(virJSONValuePtr cmd)
 
 static int
 qemuAgentCheckError(virJSONValuePtr cmd,
-                    virJSONValuePtr reply)
+                    virJSONValuePtr reply,
+                    bool report_unsupported)
 {
     if (virJSONValueObjectHasKey(reply, "error")) {
         virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
@@ -1063,15 +1064,25 @@ qemuAgentCheckError(virJSONValuePtr cmd,
                   NULLSTR(cmdstr), NULLSTR(replystr));
 
         /* Only send the user the command name + friendly error */
-        if (!error)
+        if (!error) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unable to execute QEMU agent command '%s'"),
                            qemuAgentCommandName(cmd));
-        else
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("unable to execute QEMU agent command '%s': %s"),
-                           qemuAgentCommandName(cmd),
-                           qemuAgentStringifyError(error));
+            return -1;
+        }
+
+        if (!report_unsupported) {
+            const char *klass = virJSONValueObjectGetString(error, "class");
+
+            if (STREQ_NULLABLE(klass, "CommandNotFound") ||
+                STREQ_NULLABLE(klass, "CommandDisabled"))
+                return -2;
+        }
+
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unable to execute QEMU agent command '%s': %s"),
+                       qemuAgentCommandName(cmd),
+                       qemuAgentStringifyError(error));
 
         return -1;
     } else if (!virJSONValueObjectHasKey(reply, "return")) {
@@ -1089,10 +1100,11 @@ qemuAgentCheckError(virJSONValuePtr cmd,
 }
 
 static int
-qemuAgentCommand(qemuAgentPtr agent,
-                 virJSONValuePtr cmd,
-                 virJSONValuePtr *reply,
-                 int seconds)
+qemuAgentCommandFull(qemuAgentPtr agent,
+                     virJSONValuePtr cmd,
+                     virJSONValuePtr *reply,
+                     int seconds,
+                     bool report_unsupported)
 {
     int ret = -1;
     qemuAgentMessage msg;
@@ -1143,7 +1155,7 @@ qemuAgentCommand(qemuAgentPtr agent,
     }
 
     *reply = msg.rxObject;
-    ret = qemuAgentCheckError(cmd, *reply);
+    ret = qemuAgentCheckError(cmd, *reply, report_unsupported);
 
  cleanup:
     VIR_FREE(cmdstr);
@@ -1153,6 +1165,15 @@ qemuAgentCommand(qemuAgentPtr agent,
     return ret;
 }
 
+static int
+qemuAgentCommand(qemuAgentPtr agent,
+                 virJSONValuePtr cmd,
+                 virJSONValuePtr *reply,
+                 int seconds)
+{
+    return qemuAgentCommandFull(agent, cmd, reply, seconds, true);
+}
+
 static virJSONValuePtr G_GNUC_NULL_TERMINATED
 qemuAgentMakeCommand(const char *cmdname,
                      ...)