]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentGetHostname: expose 'report_unsupported' argument
authorPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2020 07:26:34 +0000 (08:26 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Mar 2020 12:13:18 +0000 (13:13 +0100)
Use qemuAgentCommandFull in qemuAgentGetHostname so that we can suppress
error reports if the caller will not require them. Callers for now
always require error reporting but will be fixed later.

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

index 3a40084f309de7ac950948d4cc55bcf35ad6d316..5c6910aa9bb9f821b2cf81344c9d0bf8e96d67e8 100644 (file)
@@ -1716,24 +1716,32 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
 }
 
 
+/**
+ * qemuAgentGetHostname:
+ *
+ * Gets the guest hostname using the guest agent.
+ *
+ * Returns 0 on success and fills @hostname. On error -1 is returned with an
+ * error reported and if '@report_unsupported' is false -2 is returned if the
+ * guest agent does not support the command without reporting an error
+ */
 int
 qemuAgentGetHostname(qemuAgentPtr agent,
-                     char **hostname)
+                     char **hostname,
+                     bool report_unsupported)
 {
     g_autoptr(virJSONValue) cmd = qemuAgentMakeCommand("guest-get-host-name", NULL);
     g_autoptr(virJSONValue) reply = NULL;
     virJSONValuePtr data = NULL;
     const char *result = NULL;
+    int rc;
 
     if (!cmd)
         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 = virJSONValueObjectGet(reply, "return"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
index 67fe9fcde948188f65162b02959fe5ea511a253f..7cf38d7091db34cd3bf153a2c08f32ad47799ed0 100644 (file)
@@ -129,7 +129,8 @@ int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
 
 int
 qemuAgentGetHostname(qemuAgentPtr mon,
-                     char **hostname);
+                     char **hostname,
+                     bool report_unsupported);
 
 int qemuAgentGetTime(qemuAgentPtr mon,
                      long long *seconds,
index fcd7bb2fafa8b53487db60c6b9c93bee661f312b..8ef2dee677598b4a132da1c34fc06ad87f9be330 100644 (file)
@@ -20237,7 +20237,7 @@ qemuDomainGetHostnameAgent(virQEMUDriverPtr driver,
         goto endjob;
 
     agent = qemuDomainObjEnterAgent(vm);
-    ignore_value(qemuAgentGetHostname(agent, hostname));
+    ignore_value(qemuAgentGetHostname(agent, hostname, true));
     qemuDomainObjExitAgent(vm, agent);
 
     ret = 0;
@@ -23031,7 +23031,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
             goto exitagent;
     }
     if (supportedTypes & VIR_DOMAIN_GUEST_INFO_HOSTNAME) {
-        rc = qemuAgentGetHostname(agent, &hostname);
+        rc = qemuAgentGetHostname(agent, &hostname, true);
         if (rc < 0 && !(rc == -2 && types == 0))
             goto exitagent;
     }