Expose the process exit status code so the status code can be used to
determine if stderr (qmperr) should be logged.
In the case of virQEMUCapsInitQmp,
we only log stderr (qmperr) if the -first- query process fails with a
non zero status code.
Logging functions are pulled inside virQEMUCapsInitQmp where we can
detect that the -first- (not subsequent) QEMU process activation failed
with nonzero status.
Signed-off-by: Chris Venteicher <cventeic(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 73 ++++++++++++++++++------------------
src/qemu/qemu_process.c | 9 +++--
src/qemu/qemu_process.h | 1 +
3 files changed, 42 insertions(+), 41 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 502bac5e43..12c4ed2eb5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4349,23 +4349,49 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps
ATTRIBUTE_UNUSED,
}
+#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa361"
+
+static void
+virQEMUCapsLogProbeFailure(const char *binary)
+{
+ virLogMetadata meta[] = {
+ { .key = "MESSAGE_ID", .s = MESSAGE_ID_CAPS_PROBE_FAILURE, .iv = 0 },
+ { .key = "LIBVIRT_QEMU_BINARY", .s = binary, .iv = 0 },
+ { .key = NULL },
+ };
+
+ virLogMessage(&virLogSelf,
+ VIR_LOG_WARN,
+ __FILE__, __LINE__, __func__,
+ meta,
+ _("Failed to probe capabilities for %s: %s"),
+ binary, virGetLastErrorMessage());
+}
+
+
static int
virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
const char *libDir,
uid_t runUid,
- gid_t runGid,
- char **qmperr)
+ gid_t runGid)
{
qemuProcessQMPPtr proc = NULL;
qemuProcessQMPPtr procTCG = NULL;
+ char *qmperr = NULL;
int ret = -1;
if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
- runUid, runGid, qmperr, false)))
+ runUid, runGid, &qmperr, false)))
goto cleanup;
- if (qemuProcessQMPRun(proc) < 0)
+ if (qemuProcessQMPRun(proc) < 0) {
+ if (proc->status != 0)
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to probe QEMU binary with QMP: %s"),
+ qmperr ? qmperr : _("uknown error"));
+
goto cleanup;
+ }
if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0)
goto cleanup;
@@ -4390,34 +4416,19 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
ret = 0;
cleanup:
+ if (ret < 0)
+ virQEMUCapsLogProbeFailure(qemuCaps->binary);
+
qemuProcessQMPStop(proc);
qemuProcessQMPStop(procTCG);
qemuProcessQMPFree(proc);
qemuProcessQMPFree(procTCG);
+ VIR_FREE(qmperr);
+
return ret;
}
-#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa361"
-
-static void
-virQEMUCapsLogProbeFailure(const char *binary)
-{
- virLogMetadata meta[] = {
- { .key = "MESSAGE_ID", .s = MESSAGE_ID_CAPS_PROBE_FAILURE, .iv = 0 },
- { .key = "LIBVIRT_QEMU_BINARY", .s = binary, .iv = 0 },
- { .key = NULL },
- };
-
- virLogMessage(&virLogSelf,
- VIR_LOG_WARN,
- __FILE__, __LINE__, __func__,
- meta,
- _("Failed to probe capabilities for %s: %s"),
- binary, virGetLastErrorMessage());
-}
-
-
virQEMUCapsPtr
virQEMUCapsNewForBinaryInternal(virArch hostArch,
const char *binary,
@@ -4429,7 +4440,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
{
virQEMUCapsPtr qemuCaps;
struct stat sb;
- char *qmperr = NULL;
if (!(qemuCaps = virQEMUCapsNew()))
goto error;
@@ -4456,18 +4466,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
goto error;
}
- if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0) {
- virQEMUCapsLogProbeFailure(binary);
+ if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0)
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;
@@ -4485,7 +4485,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
}
cleanup:
- VIR_FREE(qmperr);
return qemuCaps;
error:
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f662b7d2ce..10e7bc5f11 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8276,7 +8276,6 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc)
{
virDomainXMLOptionPtr xmlopt = NULL;
const char *machine;
- int status = 0;
int ret = -1;
if (proc->forceTCG)
@@ -8311,12 +8310,14 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc)
virCommandSetErrorBuffer(proc->cmd, proc->qmperr);
- if (virCommandRun(proc->cmd, &status) < 0)
+ proc->status = 0;
+
+ if (virCommandRun(proc->cmd, &proc->status) < 0)
goto cleanup;
- if (status != 0) {
+ if (proc->status != 0) {
VIR_DEBUG("QEMU %s exited with status %d: %s",
- proc->binary, status, *proc->qmperr);
+ proc->binary, proc->status, *proc->qmperr);
goto cleanup;
}
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index ccbdb33679..149829df52 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -220,6 +220,7 @@ struct _qemuProcessQMP {
char *binary;
uid_t runUid;
gid_t runGid;
+ int status;
char **qmperr;
char *monarg;
char *monpath;
--
2.17.1