From nobody Wed Nov 27 19:29:11 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 1541966464275909.7955270503637; Sun, 11 Nov 2018 12:01:04 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2115C30034B4; Sun, 11 Nov 2018 20:01:02 +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 5E8C35C1B4; Sun, 11 Nov 2018 20:01:01 +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 CD34D181A86C; Sun, 11 Nov 2018 20:01:00 +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 wABK0ald023748 for ; Sun, 11 Nov 2018 15:00:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5825B5C269; Sun, 11 Nov 2018 20:00:36 +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 5A1B35C238; Sun, 11 Nov 2018 20:00:35 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Sun, 11 Nov 2018 13:59:18 -0600 Message-Id: <20181111195930.17185-11-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 10/22] qemu_process: Introduce qemuProcessStartQmp 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 11 Nov 2018 20:01:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Move a step closer to the function structure used elsewhere in qemu_process where qemuProcessStart and qemuProcessStop are the exposed functions. qemuProcessStartQmp mirrors qemuProcessStart in calling sub functions to intialize, launch the process and connect the monitor to the QEMU process. static functions qemuProcessInitQmp, qemuProcessLaunchQmp and qemuConnectMonitorQmp are also introduced. qemuProcessLaunchQmp is just renamed from qemuProcessRun and encapsulates all of the original code. qemuProcessInitQmp and qemuProcessMonitorQmp are introduced as empty wrappers into which subsequent patches will partition code from qemuProcessLaunchQmp. Signed-off-by: Chris Venteicher --- src/qemu/qemu_capabilities.c | 4 +- src/qemu/qemu_process.c | 96 +++++++++++++++++++++++++++++++++++- src/qemu/qemu_process.h | 2 +- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index fbb4336201..7168c470f6 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4230,7 +4230,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, goto cleanup; =20 =20 - if (qemuProcessRun(proc) < 0) + if (qemuProcessStartQmp(proc) < 0) goto cleanup; =20 if (!(mon =3D QEMU_PROCESS_MONITOR(proc))) { @@ -4249,7 +4249,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, forceTCG =3D true; proc_kvm =3D qemuProcessNew(qemuCaps->binary, libDir, runUid, runG= id, forceTCG); =20 - if (qemuProcessRun(proc_kvm) < 0) + if (qemuProcessStartQmp(proc_kvm) < 0) goto cleanup; =20 if (!(mon_kvm =3D QEMU_PROCESS_MONITOR(proc_kvm))) { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2640ec2b32..b6aa3a9af3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8148,8 +8148,29 @@ qemuProcessNew(const char *binary, } =20 =20 -int -qemuProcessRun(qemuProcessPtr proc){ +/* Initialize configuration and paths prior to starting QEMU + */ +static int +qemuProcessInitQmp(qemuProcessPtr proc) +{ + int ret =3D -1; + + VIR_DEBUG("Beginning VM startup process" + "emulator=3D%s", + proc->binary); + + ret =3D 0; + + VIR_DEBUG("ret=3D%i", ret); + return ret; +} + + +/* Launch QEMU Process + */ +static int +qemuProcessLaunchQmp(qemuProcessPtr proc) +{ virDomainXMLOptionPtr xmlopt =3D NULL; const char *machine; int status =3D 0; @@ -8226,6 +8247,77 @@ qemuProcessRun(qemuProcessPtr proc){ } =20 =20 +/* Connect Monitor to QEMU Process + */ +static int +qemuConnectMonitorQmp(qemuProcessPtr proc) +{ + int ret =3D -1; + + VIR_DEBUG("proc=3D%p, emulator=3D%s, proc->pid=3D%lld", + proc, NULLSTR(proc->binary), (long long) proc->pid); + + ret =3D 0; + + VIR_DEBUG("ret=3D%i", ret); + return ret; +} + + +/** + * qemuProcessStartQmp: + * @proc: Stores Process and Connection State + * + * Start and connect to QEMU binary so QMP queries can be made. + * + * Usage: + * proc =3D qemuProcessNew(binary, forceTCG, libDir, runUid, runGid); + * qemuProcessStartQmp(proc); + * mon =3D QEMU_PROCESS_MONITOR(proc); + * ** Send QMP Queries to QEMU using monitor ** + * qemuProcessStopQmp(proc); + * qemuProcessFree(proc); + * + * Check monitor is not NULL before using. + * + * QEMU probing failure results in monitor being NULL but is not considered + * an error case and does not result in a negative return value. + * + * Both qemuProcessStopQmp and qemuProcessFree must be called to cleanup a= nd + * free resources, even in activation failure cases. + * + * Process error output (proc->qmperr) remains available in qemuProcess st= ruct + * until qemuProcessFree is called. + */ +int +qemuProcessStartQmp(qemuProcessPtr proc) +{ + int ret =3D -1; + + VIR_DEBUG("emulator=3D%s", + proc->binary); + + if (qemuProcessInitQmp(proc) < 0) + goto cleanup; + + if (qemuProcessLaunchQmp(proc) < 0) + goto stop; + + if (qemuConnectMonitorQmp(proc) < 0) + goto stop; + + ret =3D 0; + + cleanup: + VIR_DEBUG("ret=3D%i", ret); + return ret; + + stop: + qemuProcessStopQmp(proc); + goto cleanup; +} + + void qemuProcessStopQmp(qemuProcessPtr proc) { diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 37194e2501..c34ca52ef5 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -246,7 +246,7 @@ qemuProcessPtr qemuProcessNew(const char *binary, =20 void qemuProcessFree(qemuProcessPtr proc); =20 -int qemuProcessRun(qemuProcessPtr proc); +int qemuProcessStartQmp(qemuProcessPtr proc); =20 void qemuProcessStopQmp(qemuProcessPtr proc); =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list