From nobody Tue Feb 10 16:18:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1547341022169705.6659996461435; Sat, 12 Jan 2019 16:57:02 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1042F796E5; Sun, 13 Jan 2019 00:57:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6D3CBA74; Sun, 13 Jan 2019 00:56:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7FEC218436BF; Sun, 13 Jan 2019 00:56:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0D0urBI001491 for ; Sat, 12 Jan 2019 19:56:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6D69B81658; Sun, 13 Jan 2019 00:56:53 +0000 (UTC) Received: from cv1.lan (ovpn-126-68.rdu2.redhat.com [10.10.126.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBB2881659; Sun, 13 Jan 2019 00:56:51 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Sat, 12 Jan 2019 18:50:08 -0600 Message-Id: <20190113005032.17880-10-cventeic@redhat.com> In-Reply-To: <20190113005032.17880-1-cventeic@redhat.com> References: <20190113005032.17880-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com, mprivozn@redhat.com, jdenemar@redhat.com, chris@venteicher.org Subject: [libvirt] [PATCH v6 09/33] qemu_process: Expose process exit status code X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 13 Jan 2019 00:57:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 --- 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 qemuCap= s ATTRIBUTE_UNUSED, } =20 =20 +#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa36= 1" + +static void +virQEMUCapsLogProbeFailure(const char *binary) +{ + virLogMetadata meta[] =3D { + { .key =3D "MESSAGE_ID", .s =3D MESSAGE_ID_CAPS_PROBE_FAILURE, .iv= =3D 0 }, + { .key =3D "LIBVIRT_QEMU_BINARY", .s =3D binary, .iv =3D 0 }, + { .key =3D 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 =3D NULL; qemuProcessQMPPtr procTCG =3D NULL; + char *qmperr =3D NULL; int ret =3D -1; =20 if (!(proc =3D qemuProcessQMPNew(qemuCaps->binary, libDir, - runUid, runGid, qmperr, false))) + runUid, runGid, &qmperr, false))) goto cleanup; =20 - if (qemuProcessQMPRun(proc) < 0) + if (qemuProcessQMPRun(proc) < 0) { + if (proc->status !=3D 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to probe QEMU binary with QMP: %s"), + qmperr ? qmperr : _("uknown error")); + goto cleanup; + } =20 if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0) goto cleanup; @@ -4390,34 +4416,19 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, ret =3D 0; =20 cleanup: + if (ret < 0) + virQEMUCapsLogProbeFailure(qemuCaps->binary); + qemuProcessQMPStop(proc); qemuProcessQMPStop(procTCG); qemuProcessQMPFree(proc); qemuProcessQMPFree(procTCG); + VIR_FREE(qmperr); + return ret; } =20 =20 -#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa36= 1" - -static void -virQEMUCapsLogProbeFailure(const char *binary) -{ - virLogMetadata meta[] =3D { - { .key =3D "MESSAGE_ID", .s =3D MESSAGE_ID_CAPS_PROBE_FAILURE, .iv= =3D 0 }, - { .key =3D "LIBVIRT_QEMU_BINARY", .s =3D binary, .iv =3D 0 }, - { .key =3D 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 =3D NULL; =20 if (!(qemuCaps =3D virQEMUCapsNew())) goto error; @@ -4456,18 +4466,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, goto error; } =20 - 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; - } =20 qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); qemuCaps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; @@ -4485,7 +4485,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, } =20 cleanup: - VIR_FREE(qmperr); return qemuCaps; =20 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 =3D NULL; const char *machine; - int status =3D 0; int ret =3D -1; =20 if (proc->forceTCG) @@ -8311,12 +8310,14 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) =20 virCommandSetErrorBuffer(proc->cmd, proc->qmperr); =20 - if (virCommandRun(proc->cmd, &status) < 0) + proc->status =3D 0; + + if (virCommandRun(proc->cmd, &proc->status) < 0) goto cleanup; =20 - if (status !=3D 0) { + if (proc->status !=3D 0) { VIR_DEBUG("QEMU %s exited with status %d: %s", - proc->binary, status, *proc->qmperr); + proc->binary, proc->status, *proc->qmperr); goto cleanup; } =20 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; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list