]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentGetUsers: expose 'report_unsupported' argument
authorPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2020 07:37:13 +0000 (08:37 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Mar 2020 12:13:18 +0000 (13:13 +0100)
Use qemuAgentCommandFull so that callers of qemuAgentGetUsers can
suppress error reports if the function is not supported by the guest
agent.

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

index 5c6910aa9bb9f821b2cf81344c9d0bf8e96d67e8..ffdc94e62fd6a7790936870c95951908ff9b8b19 100644 (file)
@@ -2312,29 +2312,30 @@ qemuAgentSetUserPassword(qemuAgentPtr agent,
 }
 
 /* Returns: 0 on success
- *          -2 when agent command is not supported by the agent
- *          -1 otherwise
+ *          -2 when agent command is not supported by the agent and
+ *             'report_unsupported' is false (libvirt error is not reported)
+ *          -1 otherwise (libvirt error is reported)
  */
 int
 qemuAgentGetUsers(qemuAgentPtr agent,
                   virTypedParameterPtr *params,
                   int *nparams,
-                  int *maxparams)
+                  int *maxparams,
+                  bool report_unsupported)
 {
     g_autoptr(virJSONValue) cmd = NULL;
     g_autoptr(virJSONValue) reply = NULL;
     virJSONValuePtr data = NULL;
     size_t ndata;
     size_t i;
+    int rc;
 
     if (!(cmd = qemuAgentMakeCommand("guest-get-users", NULL)))
         return -1;
 
-    if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
-        if (qemuAgentErrorCommandUnsupported(reply))
-            return -2;
-        return -1;
-    }
+    if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
+                                   report_unsupported)) < 0)
+        return rc;
 
     if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
index 7cf38d7091db34cd3bf153a2c08f32ad47799ed0..3702abf59321d9f674b0fe2144dd12a04481303b 100644 (file)
@@ -151,7 +151,8 @@ int qemuAgentSetUserPassword(qemuAgentPtr mon,
 int qemuAgentGetUsers(qemuAgentPtr mon,
                       virTypedParameterPtr *params,
                       int *nparams,
-                      int *maxparams);
+                      int *maxparams,
+                      bool report_unsupported);
 
 int qemuAgentGetOSInfo(qemuAgentPtr mon,
                        virTypedParameterPtr *params,
index 8ef2dee677598b4a132da1c34fc06ad87f9be330..5ca50c4b2ff42276ed873ec23e78870fa13b3753 100644 (file)
@@ -23016,7 +23016,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
      * 'unsupported' errors and gather as much information as we can. In all
      * other cases, abort on error. */
     if (supportedTypes & VIR_DOMAIN_GUEST_INFO_USERS) {
-        rc = qemuAgentGetUsers(agent, params, nparams, &maxparams);
+        rc = qemuAgentGetUsers(agent, params, nparams, &maxparams, true);
         if (rc < 0 && !(rc == -2 && types == 0))
             goto exitagent;
     }
index 86fbfbaa4cb5543f219a8907557edcaf60d4be13..dee9068ce5755e4405093b187cbcbc482c7b3248 100644 (file)
@@ -1040,7 +1040,7 @@ testQemuAgentUsers(const void *data)
 
     /* get users */
     if (qemuAgentGetUsers(qemuMonitorTestGetAgent(test),
-                          &params, &nparams, &maxparams) < 0)
+                          &params, &nparams, &maxparams, true) < 0)
         goto cleanup;
 
     if (virTypedParamsGetUInt(params, nparams, "user.count", &count) < 0)
@@ -1069,7 +1069,7 @@ testQemuAgentUsers(const void *data)
 
     /* get users with domain */
     if (qemuAgentGetUsers(qemuMonitorTestGetAgent(test),
-                          &params, &nparams, &maxparams) < 0)
+                          &params, &nparams, &maxparams, true) < 0)
         goto cleanup;
 
     if (virTypedParamsGetUInt(params, nparams, "user.count", &count) < 0)