From nobody Wed Nov 27 19:41:44 2024 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 1541966451092386.21088802442773; Sun, 11 Nov 2018 12:00:51 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF70B2D808; Sun, 11 Nov 2018 20:00:48 +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 99375104C53F; Sun, 11 Nov 2018 20:00:48 +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 4515A181A132; Sun, 11 Nov 2018 20:00:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wABK0ZRq023738 for ; Sun, 11 Nov 2018 15:00:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 21D365C227; Sun, 11 Nov 2018 20:00:35 +0000 (UTC) Received: from cv1.redhat.com (ovpn-121-41.rdu2.redhat.com [10.10.121.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 310005C238; Sun, 11 Nov 2018 20:00:02 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Sun, 11 Nov 2018 13:59:17 -0600 Message-Id: <20181111195930.17185-10-cventeic@redhat.com> In-Reply-To: <20181111195930.17185-1-cventeic@redhat.com> References: <20181111195930.17185-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , jdenemar@redhat.com, david@redhat.com Subject: [libvirt] [PATCH RFC 09/22] qemu_capabilities: Detect caps probe failure by checking monitor ptr 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 11 Nov 2018 20:00:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Failure to connect to QEMU to probe capabilities is not considered a error = case and does not result in a negative return value. Check for a NULL monitor connection pointer before trying to send capabilit= ies commands to QEMU rather than depending on a special positive return value. This simplifies logic and is more consistent with the operation of existing qemu_process functions. A macro is introduced to easily obtain the monitor pointer from the qemuProcess structure. Signed-off-by: Chris Venteicher --- src/qemu/qemu_capabilities.c | 28 ++++++++++++++++++---------- src/qemu/qemu_process.c | 9 +-------- src/qemu/qemu_process.h | 3 +++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f5e327097e..fbb4336201 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4220,43 +4220,51 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, { qemuProcessPtr proc =3D NULL; qemuProcessPtr proc_kvm =3D NULL; + qemuMonitorPtr mon =3D NULL; + qemuMonitorPtr mon_kvm =3D NULL; int ret =3D -1; - int rc; bool forceTCG =3D false; =20 if (!(proc =3D qemuProcessNew(qemuCaps->binary, libDir, runUid, runGid, forceTCG))) goto cleanup; =20 - if ((rc =3D qemuProcessRun(proc)) !=3D 0) { - if (rc =3D=3D 1) - ret =3D 0; + + if (qemuProcessRun(proc) < 0) + goto cleanup; + + if (!(mon =3D QEMU_PROCESS_MONITOR(proc))) { + ret =3D 0; /* Failure probing QEMU not considered error case */ goto cleanup; } =20 - if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0) + /* Pull capabilities from QEMU */ + if (virQEMUCapsInitQMPMonitor(qemuCaps, mon) < 0) goto cleanup; =20 + /* Pull capabilities again if KVM supported */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { qemuProcessStopQmp(proc); =20 forceTCG =3D true; proc_kvm =3D qemuProcessNew(qemuCaps->binary, libDir, runUid, runG= id, forceTCG); =20 - if ((rc =3D qemuProcessRun(proc_kvm)) !=3D 0) { - if (rc =3D=3D 1) - ret =3D 0; + if (qemuProcessRun(proc_kvm) < 0) + goto cleanup; + + if (!(mon_kvm =3D QEMU_PROCESS_MONITOR(proc_kvm))) { + ret =3D 0; /* Failure probing QEMU not considered error case */ goto cleanup; } =20 - if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc_kvm->mon) < 0) + if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, mon_kvm) < 0) goto cleanup; } =20 ret =3D 0; =20 cleanup: - if (proc && !proc->mon) { + if (!mon) { char *err =3D QEMU_PROCESS_ERROR(proc) ? QEMU_PROCESS_ERROR(proc) = : _("unknown error"); =20 virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a741d1cf91..2640ec2b32 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8148,10 +8148,6 @@ qemuProcessNew(const char *binary, } =20 =20 -/* Returns -1 on fatal error, - * 0 on success, - * 1 when probing QEMU failed - */ int qemuProcessRun(qemuProcessPtr proc){ virDomainXMLOptionPtr xmlopt =3D NULL; @@ -8218,6 +8214,7 @@ qemuProcessRun(qemuProcessPtr proc){ =20 virObjectLock(proc->mon); =20 + ignore: ret =3D 0; =20 cleanup: @@ -8226,10 +8223,6 @@ qemuProcessRun(qemuProcessPtr proc){ virObjectUnref(xmlopt); =20 return ret; - - ignore: - ret =3D 1; - goto cleanup; } =20 =20 diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index abd80baf5c..37194e2501 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -235,6 +235,9 @@ struct _qemuProcess { #define QEMU_PROCESS_ERROR(proc) \ ((char *) (proc ? proc->qmperr: NULL)) =20 +#define QEMU_PROCESS_MONITOR(proc) \ + ((qemuMonitorPtr) (proc ? proc->mon : NULL)) + qemuProcessPtr qemuProcessNew(const char *binary, const char *libDir, uid_t runUid, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list