提交 09aac3b6 编写于 作者: P Peter Krempa

qemuAgentCommand: Wire up suppressing of error reporting for unsupported commands

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 f145df50
...@@ -1051,7 +1051,8 @@ qemuAgentCommandName(virJSONValuePtr cmd) ...@@ -1051,7 +1051,8 @@ qemuAgentCommandName(virJSONValuePtr cmd)
static int static int
qemuAgentCheckError(virJSONValuePtr cmd, qemuAgentCheckError(virJSONValuePtr cmd,
virJSONValuePtr reply) virJSONValuePtr reply,
bool report_unsupported)
{ {
if (virJSONValueObjectHasKey(reply, "error")) { if (virJSONValueObjectHasKey(reply, "error")) {
virJSONValuePtr error = virJSONValueObjectGet(reply, "error"); virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
...@@ -1063,11 +1064,21 @@ qemuAgentCheckError(virJSONValuePtr cmd, ...@@ -1063,11 +1064,21 @@ qemuAgentCheckError(virJSONValuePtr cmd,
NULLSTR(cmdstr), NULLSTR(replystr)); NULLSTR(cmdstr), NULLSTR(replystr));
/* Only send the user the command name + friendly error */ /* Only send the user the command name + friendly error */
if (!error) if (!error) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to execute QEMU agent command '%s'"), _("unable to execute QEMU agent command '%s'"),
qemuAgentCommandName(cmd)); qemuAgentCommandName(cmd));
else 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, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to execute QEMU agent command '%s': %s"), _("unable to execute QEMU agent command '%s': %s"),
qemuAgentCommandName(cmd), qemuAgentCommandName(cmd),
...@@ -1089,10 +1100,11 @@ qemuAgentCheckError(virJSONValuePtr cmd, ...@@ -1089,10 +1100,11 @@ qemuAgentCheckError(virJSONValuePtr cmd,
} }
static int static int
qemuAgentCommand(qemuAgentPtr agent, qemuAgentCommandFull(qemuAgentPtr agent,
virJSONValuePtr cmd, virJSONValuePtr cmd,
virJSONValuePtr *reply, virJSONValuePtr *reply,
int seconds) int seconds,
bool report_unsupported)
{ {
int ret = -1; int ret = -1;
qemuAgentMessage msg; qemuAgentMessage msg;
...@@ -1143,7 +1155,7 @@ qemuAgentCommand(qemuAgentPtr agent, ...@@ -1143,7 +1155,7 @@ qemuAgentCommand(qemuAgentPtr agent,
} }
*reply = msg.rxObject; *reply = msg.rxObject;
ret = qemuAgentCheckError(cmd, *reply); ret = qemuAgentCheckError(cmd, *reply, report_unsupported);
cleanup: cleanup:
VIR_FREE(cmdstr); VIR_FREE(cmdstr);
...@@ -1153,6 +1165,15 @@ qemuAgentCommand(qemuAgentPtr agent, ...@@ -1153,6 +1165,15 @@ qemuAgentCommand(qemuAgentPtr agent,
return ret; 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 static virJSONValuePtr G_GNUC_NULL_TERMINATED
qemuAgentMakeCommand(const char *cmdname, qemuAgentMakeCommand(const char *cmdname,
...) ...)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册