From d8ac171718fa74066a53ccb4765304244552125d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 16 Mar 2020 08:37:13 +0100 Subject: [PATCH] qemuAgentGetOSInfo: expose 'report_unsupported' argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use qemuAgentCommandFull so that callers of qemuAgentGetOSInfo can suppress error reports if the function is not supported by the guest agent. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_agent.c | 17 +++++++++-------- src/qemu/qemu_agent.h | 3 ++- src/qemu/qemu_driver.c | 2 +- tests/qemuagenttest.c | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index ffdc94e62f..88847a5ae1 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2404,27 +2404,28 @@ qemuAgentGetUsers(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 qemuAgentGetOSInfo(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; + int rc; if (!(cmd = qemuAgentMakeCommand("guest-get-osinfo", 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 = virJSONValueObjectGetObject(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h index 3702abf593..9cade9ca4c 100644 --- a/src/qemu/qemu_agent.h +++ b/src/qemu/qemu_agent.h @@ -157,7 +157,8 @@ int qemuAgentGetUsers(qemuAgentPtr mon, int qemuAgentGetOSInfo(qemuAgentPtr mon, virTypedParameterPtr *params, int *nparams, - int *maxparams); + int *maxparams, + bool report_unsupported); int qemuAgentGetTimezone(qemuAgentPtr mon, virTypedParameterPtr *params, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5ca50c4b2f..adf9b9054c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -23021,7 +23021,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom, goto exitagent; } if (supportedTypes & VIR_DOMAIN_GUEST_INFO_OS) { - rc = qemuAgentGetOSInfo(agent, params, nparams, &maxparams); + rc = qemuAgentGetOSInfo(agent, params, nparams, &maxparams, true); if (rc < 0 && !(rc == -2 && types == 0)) goto exitagent; } diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index dee9068ce5..57d0f857cc 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -1139,7 +1139,7 @@ testQemuAgentOSInfo(const void *data) /* get osinfo */ if (qemuAgentGetOSInfo(qemuMonitorTestGetAgent(test), - ¶ms, &nparams, &maxparams) < 0) + ¶ms, &nparams, &maxparams, true) < 0) goto cleanup; if (nparams != 8) { @@ -1184,7 +1184,7 @@ testQemuAgentOSInfo(const void *data) /* get users with domain */ if (qemuAgentGetOSInfo(qemuMonitorTestGetAgent(test), - ¶ms, &nparams, &maxparams) < 0) + ¶ms, &nparams, &maxparams, true) < 0) goto cleanup; if (nparams != 10) {