qemuMonitorJSONCheckError: Allow suppressing of error reporting

In some cases we'll need to check whether there was an error but avoid
reporting an actual libvirt error. Rename qemuMonitorJSONCheckError to
qemuMonitorJSONCheckErrorFull with a new flag to suppress the error
reporting and add a wrapper with the original name so that callers don't
need to be fixed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-03-18 11:08:58 +01:00
parent cda31f3dba
commit 103bfbfd74

View File

@ -388,8 +388,9 @@ qemuMonitorJSONCommandName(virJSONValuePtr cmd)
}
static int
qemuMonitorJSONCheckError(virJSONValuePtr cmd,
virJSONValuePtr reply)
qemuMonitorJSONCheckErrorFull(virJSONValuePtr cmd,
virJSONValuePtr reply,
bool report)
{
if (virJSONValueObjectHasKey(reply, "error")) {
virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
@ -400,6 +401,9 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
VIR_DEBUG("unable to execute QEMU command %s: %s",
NULLSTR(cmdstr), NULLSTR(replystr));
if (!report)
return -1;
/* Only send the user the command name + friendly error */
if (!error)
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -418,6 +422,10 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
NULLSTR(cmdstr), NULLSTR(replystr));
if (!report)
return -1;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to execute QEMU command '%s'"),
qemuMonitorJSONCommandName(cmd));
@ -427,6 +435,14 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
}
static int
qemuMonitorJSONCheckError(virJSONValuePtr cmd,
virJSONValuePtr reply)
{
return qemuMonitorJSONCheckErrorFull(cmd, reply, true);
}
static int
qemuMonitorJSONCheckReply(virJSONValuePtr cmd,
virJSONValuePtr reply,