From cf335683de19b29ed071fda738a16f2987c33235 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 12 Feb 2019 14:38:40 +0100 Subject: [PATCH] qemu_process: Don't ignore errors in virQEMUCapsInit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While qemuProcessQMPRun and virQEMUCapsInitQMPMonitor* functions called from virQEMUCapsInit ignore some errors, the caller of virQEMUCapsInit would report an error unless usedQMP is true anyway. And since usedQMP can only be true if the probing code really succeeded (i.e., no errors were ignored), we can just simplify the logic by not ignoring the errors in the first place. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko --- src/qemu/qemu_capabilities.c | 17 +---------------- src/qemu/qemu_process.c | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index b695b23fcc..bb1920146e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4152,7 +4152,6 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, if (qemuMonitorSetCapabilities(mon) < 0) { VIR_DEBUG("Failed to set monitor capabilities %s", virGetLastErrorMessage()); - ret = 0; goto cleanup; } @@ -4161,7 +4160,6 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, &package) < 0) { VIR_DEBUG("Failed to query monitor version %s", virGetLastErrorMessage()); - ret = 0; goto cleanup; } @@ -4338,7 +4336,6 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED, if (qemuMonitorSetCapabilities(mon) < 0) { VIR_DEBUG("Failed to set monitor capabilities %s", virGetLastErrorMessage()); - ret = 0; goto cleanup; } @@ -4364,17 +4361,13 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, { qemuProcessQMPPtr proc = NULL; int ret = -1; - int rc; if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir, runUid, runGid, qmperr, onlyTCG))) goto cleanup; - if ((rc = qemuProcessQMPRun(proc)) != 0) { - if (rc == 1) - ret = 0; + if (qemuProcessQMPRun(proc) < 0) goto cleanup; - } if (onlyTCG) ret = virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon); @@ -4474,14 +4467,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, goto error; } - if (!qemuCaps->usedQMP) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to probe QEMU binary with QMP: %s"), - qmperr ? qmperr : _("unknown error")); - virQEMUCapsLogProbeFailure(binary); - goto error; - } - qemuCaps->libvirtCtime = virGetSelfLastChanged(); qemuCaps->libvirtVersion = LIBVIR_VERSION_NUMBER; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6c0f7165c7..728176bbdf 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8392,10 +8392,6 @@ qemuProcessQMPNew(const char *binary, } -/* Returns -1 on fatal error, - * 0 on success, - * 1 when probing QEMU failed - */ int qemuProcessQMPRun(qemuProcessQMPPtr proc) { @@ -8403,6 +8399,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) const char *machine; int status = 0; int ret = -1; + int rc; if (proc->forceTCG) machine = "none,accel=tcg"; @@ -8444,19 +8441,21 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) virCommandSetErrorBuffer(proc->cmd, proc->qmperr); - /* Log, but otherwise ignore, non-zero status. */ if (virCommandRun(proc->cmd, &status) < 0) goto cleanup; if (status != 0) { - VIR_DEBUG("QEMU %s exited with status %d: %s", - proc->binary, status, *proc->qmperr); - goto ignore; + VIR_DEBUG("QEMU %s exited with status %d", proc->binary, status); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to start QEMU binary %s for probing: %s"), + proc->binary, + *proc->qmperr ? *proc->qmperr : _("unknown error")); + goto cleanup; } - if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) { - VIR_DEBUG("Failed to read pidfile %s", proc->pidfile); - goto ignore; + if ((rc = virPidFileReadPath(proc->pidfile, &proc->pid)) < 0) { + virReportSystemError(-rc, _("Failed to read pidfile %s"), proc->pidfile); + goto cleanup; } if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) || @@ -8467,7 +8466,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) if (!(proc->mon = qemuMonitorOpen(proc->vm, &proc->config, true, true, 0, &callbacks, NULL))) - goto ignore; + goto cleanup; virObjectLock(proc->mon); @@ -8479,10 +8478,6 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) virObjectUnref(xmlopt); return ret; - - ignore: - ret = 1; - goto cleanup; } -- GitLab