From nobody Tue May 7 06:26:51 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 1550842757976155.35432824508075; Fri, 22 Feb 2019 05:39:17 -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 566E6C057EC3; Fri, 22 Feb 2019 13:39:16 +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 220271001E9D; Fri, 22 Feb 2019 13:39:16 +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 D9A11181A12A; Fri, 22 Feb 2019 13:39:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95Gq0016196 for ; Tue, 19 Feb 2019 04:05:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6C13B6013D; Tue, 19 Feb 2019 09:05:16 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4BBF6013C for ; Tue, 19 Feb 2019 09:05:10 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 4DCE510008B; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:44 +0100 Message-Id: <928534efaa1a61efa043a406a8354fc64e4b41c6.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/20] qemu_process: Move process code from qemu_capabilities 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: , 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.32]); Fri, 22 Feb 2019 13:39:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher QEMU process code in qemu_capabilities.c is moved to qemu_process.c in order to make the code usable outside the original capabilities use cases. The moved code activates and manages QEMU processes without establishing a guest domain. This patch is a straight cut/paste move between files. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - rebased src/qemu/qemu_capabilities.c | 230 +---------------------------------- src/qemu/qemu_process.c | 211 ++++++++++++++++++++++++++++++++ src/qemu/qemu_process.h | 30 +++++ 3 files changed, 242 insertions(+), 229 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 9d9c8096ba..26f83eb1d3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -45,6 +45,7 @@ #define LIBVIRT_QEMU_CAPSPRIV_H_ALLOW #include "qemu_capspriv.h" #include "qemu_qapi.h" +#include "qemu_process.h" =20 #include #include @@ -53,10 +54,6 @@ #include #include =20 -#if WITH_CAPNG -# include -#endif - #define VIR_FROM_THIS VIR_FROM_QEMU =20 VIR_LOG_INIT("qemu.qemu_capabilities"); @@ -4049,18 +4046,6 @@ virQEMUCapsIsValid(void *data, } =20 =20 -static void virQEMUCapsMonitorNotify(qemuMonitorPtr mon ATTRIBUTE_UNUSED, - virDomainObjPtr vm ATTRIBUTE_UNUSED, - void *opaque ATTRIBUTE_UNUSED) -{ -} - -static qemuMonitorCallbacks callbacks =3D { - .eofNotify =3D virQEMUCapsMonitorNotify, - .errorNotify =3D virQEMUCapsMonitorNotify, -}; - - /** * virQEMUCapsInitQMPArch: * @qemuCaps: QEMU capabilities @@ -4369,219 +4354,6 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCap= s ATTRIBUTE_UNUSED, } =20 =20 -typedef struct _virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommand; -typedef virQEMUCapsInitQMPCommand *virQEMUCapsInitQMPCommandPtr; -struct _virQEMUCapsInitQMPCommand { - char *binary; - uid_t runUid; - gid_t runGid; - char **qmperr; - char *monarg; - char *monpath; - char *pidfile; - virCommandPtr cmd; - qemuMonitorPtr mon; - virDomainChrSourceDef config; - pid_t pid; - virDomainObjPtr vm; -}; - - -static void -virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPCommandPtr cmd) -{ - if (cmd->mon) - virObjectUnlock(cmd->mon); - qemuMonitorClose(cmd->mon); - cmd->mon =3D NULL; - - virCommandAbort(cmd->cmd); - virCommandFree(cmd->cmd); - cmd->cmd =3D NULL; - - if (cmd->monpath) - unlink(cmd->monpath); - - virDomainObjEndAPI(&cmd->vm); - - if (cmd->pid !=3D 0) { - char ebuf[1024]; - - VIR_DEBUG("Killing QMP caps process %lld", (long long)cmd->pid); - if (virProcessKill(cmd->pid, SIGKILL) < 0 && errno !=3D ESRCH) - VIR_ERROR(_("Failed to kill process %lld: %s"), - (long long)cmd->pid, - virStrerror(errno, ebuf, sizeof(ebuf))); - - VIR_FREE(*cmd->qmperr); - } - if (cmd->pidfile) - unlink(cmd->pidfile); - cmd->pid =3D 0; -} - - -static void -virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd) -{ - if (!cmd) - return; - - virQEMUCapsInitQMPCommandAbort(cmd); - VIR_FREE(cmd->binary); - VIR_FREE(cmd->monpath); - VIR_FREE(cmd->monarg); - VIR_FREE(cmd->pidfile); - VIR_FREE(cmd); -} - - -static virQEMUCapsInitQMPCommandPtr -virQEMUCapsInitQMPCommandNew(char *binary, - const char *libDir, - uid_t runUid, - gid_t runGid, - char **qmperr) -{ - virQEMUCapsInitQMPCommandPtr cmd =3D NULL; - - if (VIR_ALLOC(cmd) < 0) - goto error; - - if (VIR_STRDUP(cmd->binary, binary) < 0) - goto error; - - cmd->runUid =3D runUid; - cmd->runGid =3D runGid; - cmd->qmperr =3D qmperr; - - /* the ".sock" sufix is important to avoid a possible clash with a qemu - * domain called "capabilities" - */ - if (virAsprintf(&cmd->monpath, "%s/%s", libDir, - "capabilities.monitor.sock") < 0) - goto error; - if (virAsprintf(&cmd->monarg, "unix:%s,server,nowait", cmd->monpath) <= 0) - goto error; - - /* ".pidfile" suffix is used rather than ".pid" to avoid a possible cl= ash - * with a qemu domain called "capabilities" - * Normally we'd use runDir for pid files, but because we're using - * -daemonize we need QEMU to be allowed to create them, rather - * than libvirtd. So we're using libDir which QEMU can write to - */ - if (virAsprintf(&cmd->pidfile, "%s/%s", libDir, "capabilities.pidfile"= ) < 0) - goto error; - - virPidFileForceCleanupPath(cmd->pidfile); - - cmd->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; - cmd->config.data.nix.path =3D cmd->monpath; - cmd->config.data.nix.listen =3D false; - - return cmd; - - error: - virQEMUCapsInitQMPCommandFree(cmd); - return NULL; -} - - -/* Returns -1 on fatal error, - * 0 on success, - * 1 when probing QEMU failed - */ -static int -virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, - bool forceTCG) -{ - virDomainXMLOptionPtr xmlopt =3D NULL; - const char *machine; - int status =3D 0; - int ret =3D -1; - - if (forceTCG) - machine =3D "none,accel=3Dtcg"; - else - machine =3D "none,accel=3Dkvm:tcg"; - - VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s", - cmd->binary, machine); - - /* - * We explicitly need to use -daemonize here, rather than - * virCommandDaemonize, because we need to synchronize - * with QEMU creating its monitor socket API. Using - * daemonize guarantees control won't return to libvirt - * until the socket is present. - */ - cmd->cmd =3D virCommandNewArgList(cmd->binary, - "-S", - "-no-user-config", - "-nodefaults", - "-nographic", - "-machine", machine, - "-qmp", cmd->monarg, - "-pidfile", cmd->pidfile, - "-daemonize", - NULL); - virCommandAddEnvPassCommon(cmd->cmd); - virCommandClearCaps(cmd->cmd); - -#if WITH_CAPNG - /* QEMU might run into permission issues, e.g. /dev/sev (0600), overri= de - * them just for the purpose of probing */ - if (geteuid() =3D=3D 0) - virCommandAllowCap(cmd->cmd, CAP_DAC_OVERRIDE); -#endif - - virCommandSetGID(cmd->cmd, cmd->runGid); - virCommandSetUID(cmd->cmd, cmd->runUid); - - virCommandSetErrorBuffer(cmd->cmd, cmd->qmperr); - - /* Log, but otherwise ignore, non-zero status. */ - if (virCommandRun(cmd->cmd, &status) < 0) - goto cleanup; - - if (status !=3D 0) { - VIR_DEBUG("QEMU %s exited with status %d: %s", - cmd->binary, status, *cmd->qmperr); - goto ignore; - } - - if (virPidFileReadPath(cmd->pidfile, &cmd->pid) < 0) { - VIR_DEBUG("Failed to read pidfile %s", cmd->pidfile); - goto ignore; - } - - if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || - !(cmd->vm =3D virDomainObjNew(xmlopt))) - goto cleanup; - - cmd->vm->pid =3D cmd->pid; - - if (!(cmd->mon =3D qemuMonitorOpen(cmd->vm, &cmd->config, true, true, - 0, &callbacks, NULL))) - goto ignore; - - virObjectLock(cmd->mon); - - ret =3D 0; - - cleanup: - if (!cmd->mon) - virQEMUCapsInitQMPCommandAbort(cmd); - virObjectUnref(xmlopt); - - return ret; - - ignore: - ret =3D 1; - goto cleanup; -} - - static int virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, const char *libDir, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a62d89320b..c45a15a1c1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -34,6 +34,10 @@ =20 #include =20 +#if WITH_CAPNG +# include +#endif + #include "qemu_process.h" #define LIBVIRT_QEMU_PROCESSPRIV_H_ALLOW #include "qemu_processpriv.h" @@ -8306,3 +8310,210 @@ qemuProcessReconnectAll(virQEMUDriverPtr driver) struct qemuProcessReconnectData data =3D {.driver =3D driver}; virDomainObjListForEach(driver->domains, qemuProcessReconnectHelper, &= data); } + + +static void virQEMUCapsMonitorNotify(qemuMonitorPtr mon ATTRIBUTE_UNUSED, + virDomainObjPtr vm ATTRIBUTE_UNUSED, + void *opaque ATTRIBUTE_UNUSED) +{ +} + +static qemuMonitorCallbacks callbacks =3D { + .eofNotify =3D virQEMUCapsMonitorNotify, + .errorNotify =3D virQEMUCapsMonitorNotify, +}; + + +void +virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd) +{ + if (!cmd) + return; + + virQEMUCapsInitQMPCommandAbort(cmd); + VIR_FREE(cmd->binary); + VIR_FREE(cmd->monpath); + VIR_FREE(cmd->monarg); + VIR_FREE(cmd->pidfile); + VIR_FREE(cmd); +} + + +virQEMUCapsInitQMPCommandPtr +virQEMUCapsInitQMPCommandNew(char *binary, + const char *libDir, + uid_t runUid, + gid_t runGid, + char **qmperr) +{ + virQEMUCapsInitQMPCommandPtr cmd =3D NULL; + + if (VIR_ALLOC(cmd) < 0) + goto error; + + if (VIR_STRDUP(cmd->binary, binary) < 0) + goto error; + + cmd->runUid =3D runUid; + cmd->runGid =3D runGid; + cmd->qmperr =3D qmperr; + + /* the ".sock" sufix is important to avoid a possible clash with a qemu + * domain called "capabilities" + */ + if (virAsprintf(&cmd->monpath, "%s/%s", libDir, + "capabilities.monitor.sock") < 0) + goto error; + if (virAsprintf(&cmd->monarg, "unix:%s,server,nowait", cmd->monpath) <= 0) + goto error; + + /* ".pidfile" suffix is used rather than ".pid" to avoid a possible cl= ash + * with a qemu domain called "capabilities" + * Normally we'd use runDir for pid files, but because we're using + * -daemonize we need QEMU to be allowed to create them, rather + * than libvirtd. So we're using libDir which QEMU can write to + */ + if (virAsprintf(&cmd->pidfile, "%s/%s", libDir, "capabilities.pidfile"= ) < 0) + goto error; + + virPidFileForceCleanupPath(cmd->pidfile); + + cmd->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; + cmd->config.data.nix.path =3D cmd->monpath; + cmd->config.data.nix.listen =3D false; + + return cmd; + + error: + virQEMUCapsInitQMPCommandFree(cmd); + return NULL; +} + + +/* Returns -1 on fatal error, + * 0 on success, + * 1 when probing QEMU failed + */ +int +virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, + bool forceTCG) +{ + virDomainXMLOptionPtr xmlopt =3D NULL; + const char *machine; + int status =3D 0; + int ret =3D -1; + + if (forceTCG) + machine =3D "none,accel=3Dtcg"; + else + machine =3D "none,accel=3Dkvm:tcg"; + + VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s", + cmd->binary, machine); + + /* + * We explicitly need to use -daemonize here, rather than + * virCommandDaemonize, because we need to synchronize + * with QEMU creating its monitor socket API. Using + * daemonize guarantees control won't return to libvirt + * until the socket is present. + */ + cmd->cmd =3D virCommandNewArgList(cmd->binary, + "-S", + "-no-user-config", + "-nodefaults", + "-nographic", + "-machine", machine, + "-qmp", cmd->monarg, + "-pidfile", cmd->pidfile, + "-daemonize", + NULL); + virCommandAddEnvPassCommon(cmd->cmd); + virCommandClearCaps(cmd->cmd); + +#if WITH_CAPNG + /* QEMU might run into permission issues, e.g. /dev/sev (0600), overri= de + * them just for the purpose of probing */ + if (geteuid() =3D=3D 0) + virCommandAllowCap(cmd->cmd, CAP_DAC_OVERRIDE); +#endif + + virCommandSetGID(cmd->cmd, cmd->runGid); + virCommandSetUID(cmd->cmd, cmd->runUid); + + virCommandSetErrorBuffer(cmd->cmd, cmd->qmperr); + + /* Log, but otherwise ignore, non-zero status. */ + if (virCommandRun(cmd->cmd, &status) < 0) + goto cleanup; + + if (status !=3D 0) { + VIR_DEBUG("QEMU %s exited with status %d: %s", + cmd->binary, status, *cmd->qmperr); + goto ignore; + } + + if (virPidFileReadPath(cmd->pidfile, &cmd->pid) < 0) { + VIR_DEBUG("Failed to read pidfile %s", cmd->pidfile); + goto ignore; + } + + if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || + !(cmd->vm =3D virDomainObjNew(xmlopt))) + goto cleanup; + + cmd->vm->pid =3D cmd->pid; + + if (!(cmd->mon =3D qemuMonitorOpen(cmd->vm, &cmd->config, true, true, + 0, &callbacks, NULL))) + goto ignore; + + virObjectLock(cmd->mon); + + ret =3D 0; + + cleanup: + if (!cmd->mon) + virQEMUCapsInitQMPCommandAbort(cmd); + virObjectUnref(xmlopt); + + return ret; + + ignore: + ret =3D 1; + goto cleanup; +} + + +void +virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPCommandPtr cmd) +{ + if (cmd->mon) + virObjectUnlock(cmd->mon); + qemuMonitorClose(cmd->mon); + cmd->mon =3D NULL; + + virCommandAbort(cmd->cmd); + virCommandFree(cmd->cmd); + cmd->cmd =3D NULL; + + if (cmd->monpath) + unlink(cmd->monpath); + + virDomainObjEndAPI(&cmd->vm); + + if (cmd->pid !=3D 0) { + char ebuf[1024]; + + VIR_DEBUG("Killing QMP caps process %lld", (long long)cmd->pid); + if (virProcessKill(cmd->pid, SIGKILL) < 0 && errno !=3D ESRCH) + VIR_ERROR(_("Failed to kill process %lld: %s"), + (long long)cmd->pid, + virStrerror(errno, ebuf, sizeof(ebuf))); + + VIR_FREE(*cmd->qmperr); + } + if (cmd->pidfile) + unlink(cmd->pidfile); + cmd->pid =3D 0; +} diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 67a4d7139f..f76613a7f7 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -214,4 +214,34 @@ int qemuProcessStartManagedPRDaemon(virDomainObjPtr vm= ); =20 void qemuProcessKillManagedPRDaemon(virDomainObjPtr vm); =20 +typedef struct _virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommand; +typedef virQEMUCapsInitQMPCommand *virQEMUCapsInitQMPCommandPtr; +struct _virQEMUCapsInitQMPCommand { + char *binary; + uid_t runUid; + gid_t runGid; + char **qmperr; + char *monarg; + char *monpath; + char *pidfile; + virCommandPtr cmd; + qemuMonitorPtr mon; + virDomainChrSourceDef config; + pid_t pid; + virDomainObjPtr vm; +}; + +virQEMUCapsInitQMPCommandPtr virQEMUCapsInitQMPCommandNew(char *binary, + const char *libD= ir, + uid_t runUid, + gid_t runGid, + char **qmperr); + +void virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd); + +int virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, + bool forceTCG); + +void virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPCommandPtr cmd); + #endif /* LIBVIRT_QEMU_PROCESS_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 155084258482891.25948296810054; Fri, 22 Feb 2019 05:36:24 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E11E300440C; Fri, 22 Feb 2019 13:36:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD26A27CC1; Fri, 22 Feb 2019 13:36:22 +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 806873D386; Fri, 22 Feb 2019 13:36:22 +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 x1J95B4X016144 for ; Tue, 19 Feb 2019 04:05:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id F402A5C21F; Tue, 19 Feb 2019 09:05:10 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A05961B7C for ; Tue, 19 Feb 2019 09:05:10 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 507E11000FD; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:45 +0100 Message-Id: <38e39eb4498c2aa21c4e2af43fa37c43388d8575.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/20] qemu_process: Rename identifiers moved from qemu_capabilities 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: , 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 22 Feb 2019 13:36:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher s/virQEMUCapsInitQMPCommand/qemuProcessQMP/ Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_capabilities.c | 14 +++++++------- src/qemu/qemu_process.c | 28 ++++++++++++++-------------- src/qemu/qemu_process.h | 24 ++++++++++++------------ 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 26f83eb1d3..e7442ac010 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4361,15 +4361,15 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, gid_t runGid, char **qmperr) { - virQEMUCapsInitQMPCommandPtr cmd =3D NULL; + qemuProcessQMPPtr cmd =3D NULL; int ret =3D -1; int rc; =20 - if (!(cmd =3D virQEMUCapsInitQMPCommandNew(qemuCaps->binary, libDir, - runUid, runGid, qmperr))) + if (!(cmd =3D qemuProcessQMPNew(qemuCaps->binary, libDir, + runUid, runGid, qmperr))) goto cleanup; =20 - if ((rc =3D virQEMUCapsInitQMPCommandRun(cmd, false)) !=3D 0) { + if ((rc =3D qemuProcessQMPRun(cmd, false)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; goto cleanup; @@ -4379,8 +4379,8 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, goto cleanup; =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { - virQEMUCapsInitQMPCommandAbort(cmd); - if ((rc =3D virQEMUCapsInitQMPCommandRun(cmd, true)) !=3D 0) { + qemuProcessQMPAbort(cmd); + if ((rc =3D qemuProcessQMPRun(cmd, true)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; goto cleanup; @@ -4393,7 +4393,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, ret =3D 0; =20 cleanup: - virQEMUCapsInitQMPCommandFree(cmd); + qemuProcessQMPFree(cmd); return ret; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c45a15a1c1..05acdc6013 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8325,12 +8325,12 @@ static qemuMonitorCallbacks callbacks =3D { =20 =20 void -virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd) +qemuProcessQMPFree(qemuProcessQMPPtr cmd) { if (!cmd) return; =20 - virQEMUCapsInitQMPCommandAbort(cmd); + qemuProcessQMPAbort(cmd); VIR_FREE(cmd->binary); VIR_FREE(cmd->monpath); VIR_FREE(cmd->monarg); @@ -8339,14 +8339,14 @@ virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCom= mandPtr cmd) } =20 =20 -virQEMUCapsInitQMPCommandPtr -virQEMUCapsInitQMPCommandNew(char *binary, - const char *libDir, - uid_t runUid, - gid_t runGid, - char **qmperr) +qemuProcessQMPPtr +qemuProcessQMPNew(char *binary, + const char *libDir, + uid_t runUid, + gid_t runGid, + char **qmperr) { - virQEMUCapsInitQMPCommandPtr cmd =3D NULL; + qemuProcessQMPPtr cmd =3D NULL; =20 if (VIR_ALLOC(cmd) < 0) goto error; @@ -8385,7 +8385,7 @@ virQEMUCapsInitQMPCommandNew(char *binary, return cmd; =20 error: - virQEMUCapsInitQMPCommandFree(cmd); + qemuProcessQMPFree(cmd); return NULL; } =20 @@ -8395,8 +8395,8 @@ virQEMUCapsInitQMPCommandNew(char *binary, * 1 when probing QEMU failed */ int -virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, - bool forceTCG) +qemuProcessQMPRun(qemuProcessQMPPtr cmd, + bool forceTCG) { virDomainXMLOptionPtr xmlopt =3D NULL; const char *machine; @@ -8474,7 +8474,7 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPComman= dPtr cmd, =20 cleanup: if (!cmd->mon) - virQEMUCapsInitQMPCommandAbort(cmd); + qemuProcessQMPAbort(cmd); virObjectUnref(xmlopt); =20 return ret; @@ -8486,7 +8486,7 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPComman= dPtr cmd, =20 =20 void -virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPCommandPtr cmd) +qemuProcessQMPAbort(qemuProcessQMPPtr cmd) { if (cmd->mon) virObjectUnlock(cmd->mon); diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index f76613a7f7..4843210f76 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -214,9 +214,9 @@ int qemuProcessStartManagedPRDaemon(virDomainObjPtr vm); =20 void qemuProcessKillManagedPRDaemon(virDomainObjPtr vm); =20 -typedef struct _virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommand; -typedef virQEMUCapsInitQMPCommand *virQEMUCapsInitQMPCommandPtr; -struct _virQEMUCapsInitQMPCommand { +typedef struct _qemuProcessQMP qemuProcessQMP; +typedef qemuProcessQMP *qemuProcessQMPPtr; +struct _qemuProcessQMP { char *binary; uid_t runUid; gid_t runGid; @@ -231,17 +231,17 @@ struct _virQEMUCapsInitQMPCommand { virDomainObjPtr vm; }; =20 -virQEMUCapsInitQMPCommandPtr virQEMUCapsInitQMPCommandNew(char *binary, - const char *libD= ir, - uid_t runUid, - gid_t runGid, - char **qmperr); +qemuProcessQMPPtr qemuProcessQMPNew(char *binary, + const char *libDir, + uid_t runUid, + gid_t runGid, + char **qmperr); =20 -void virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd); +void qemuProcessQMPFree(qemuProcessQMPPtr cmd); =20 -int virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, - bool forceTCG); +int qemuProcessQMPRun(qemuProcessQMPPtr cmd, + bool forceTCG); =20 -void virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPCommandPtr cmd); +void qemuProcessQMPAbort(qemuProcessQMPPtr cmd); =20 #endif /* LIBVIRT_QEMU_PROCESS_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567141266719.4023114216444; Tue, 19 Feb 2019 01:05:41 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D31A88311; Tue, 19 Feb 2019 09:05:38 +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 ACC526013C; Tue, 19 Feb 2019 09:05:37 +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 67898181A00B; Tue, 19 Feb 2019 09:05:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95EDR016159 for ; Tue, 19 Feb 2019 04:05:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 06BB119C57; Tue, 19 Feb 2019 09:05:14 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD1D319C5A for ; Tue, 19 Feb 2019 09:05:10 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 52BDC100102; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:46 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/20] qemu_process: Limit qemuProcessQMPNew to const input strings 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: , 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Feb 2019 09:05:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher Add the const qualifier on non modified strings (string only copied inside qemuProcessQMPNew) so that const strings can be used directly in calls to qemuProcessQMPNew in future patches. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_process.c | 2 +- src/qemu/qemu_process.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 05acdc6013..6b698c0622 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8340,7 +8340,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr cmd) =20 =20 qemuProcessQMPPtr -qemuProcessQMPNew(char *binary, +qemuProcessQMPNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 4843210f76..fe79873967 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -231,7 +231,7 @@ struct _qemuProcessQMP { virDomainObjPtr vm; }; =20 -qemuProcessQMPPtr qemuProcessQMPNew(char *binary, +qemuProcessQMPPtr qemuProcessQMPNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567158889410.25740701252903; Tue, 19 Feb 2019 01:05:58 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3619460B2; Tue, 19 Feb 2019 09:05:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6CC46600C8; Tue, 19 Feb 2019 09:05:55 +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 260BC3FA4D; Tue, 19 Feb 2019 09:05:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95GkC016199 for ; Tue, 19 Feb 2019 04:05:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7888C61080; Tue, 19 Feb 2019 09:05:16 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 260DB60BE8 for ; Tue, 19 Feb 2019 09:05:10 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 555D8100104; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:47 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/20] qemu_process: Refer to proc not cmd in process 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: , 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Feb 2019 09:05:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher s/cmd/proc/ in process code imported from qemu_capabilities. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - s/cmd/proc/ in qemuProcessQMPRun prototype src/qemu/qemu_capabilities.c | 18 ++--- src/qemu/qemu_process.c | 140 +++++++++++++++++------------------ src/qemu/qemu_process.h | 6 +- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e7442ac010..aa6571457e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4361,39 +4361,39 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, gid_t runGid, char **qmperr) { - qemuProcessQMPPtr cmd =3D NULL; + qemuProcessQMPPtr proc =3D NULL; int ret =3D -1; int rc; =20 - if (!(cmd =3D qemuProcessQMPNew(qemuCaps->binary, libDir, - runUid, runGid, qmperr))) + if (!(proc =3D qemuProcessQMPNew(qemuCaps->binary, libDir, + runUid, runGid, qmperr))) goto cleanup; =20 - if ((rc =3D qemuProcessQMPRun(cmd, false)) !=3D 0) { + if ((rc =3D qemuProcessQMPRun(proc, false)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; goto cleanup; } =20 - if (virQEMUCapsInitQMPMonitor(qemuCaps, cmd->mon) < 0) + if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0) goto cleanup; =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { - qemuProcessQMPAbort(cmd); - if ((rc =3D qemuProcessQMPRun(cmd, true)) !=3D 0) { + qemuProcessQMPAbort(proc); + if ((rc =3D qemuProcessQMPRun(proc, true)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; goto cleanup; } =20 - if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, cmd->mon) < 0) + if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon) < 0) goto cleanup; } =20 ret =3D 0; =20 cleanup: - qemuProcessQMPFree(cmd); + qemuProcessQMPFree(proc); return ret; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6b698c0622..8e45dbc0ce 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8325,17 +8325,17 @@ static qemuMonitorCallbacks callbacks =3D { =20 =20 void -qemuProcessQMPFree(qemuProcessQMPPtr cmd) +qemuProcessQMPFree(qemuProcessQMPPtr proc) { - if (!cmd) + if (!proc) return; =20 - qemuProcessQMPAbort(cmd); - VIR_FREE(cmd->binary); - VIR_FREE(cmd->monpath); - VIR_FREE(cmd->monarg); - VIR_FREE(cmd->pidfile); - VIR_FREE(cmd); + qemuProcessQMPAbort(proc); + VIR_FREE(proc->binary); + VIR_FREE(proc->monpath); + VIR_FREE(proc->monarg); + VIR_FREE(proc->pidfile); + VIR_FREE(proc); } =20 =20 @@ -8346,25 +8346,25 @@ qemuProcessQMPNew(const char *binary, gid_t runGid, char **qmperr) { - qemuProcessQMPPtr cmd =3D NULL; + qemuProcessQMPPtr proc =3D NULL; =20 - if (VIR_ALLOC(cmd) < 0) + if (VIR_ALLOC(proc) < 0) goto error; =20 - if (VIR_STRDUP(cmd->binary, binary) < 0) + if (VIR_STRDUP(proc->binary, binary) < 0) goto error; =20 - cmd->runUid =3D runUid; - cmd->runGid =3D runGid; - cmd->qmperr =3D qmperr; + proc->runUid =3D runUid; + proc->runGid =3D runGid; + proc->qmperr =3D qmperr; =20 /* the ".sock" sufix is important to avoid a possible clash with a qemu * domain called "capabilities" */ - if (virAsprintf(&cmd->monpath, "%s/%s", libDir, + if (virAsprintf(&proc->monpath, "%s/%s", libDir, "capabilities.monitor.sock") < 0) goto error; - if (virAsprintf(&cmd->monarg, "unix:%s,server,nowait", cmd->monpath) <= 0) + if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath)= < 0) goto error; =20 /* ".pidfile" suffix is used rather than ".pid" to avoid a possible cl= ash @@ -8373,19 +8373,19 @@ qemuProcessQMPNew(const char *binary, * -daemonize we need QEMU to be allowed to create them, rather * than libvirtd. So we're using libDir which QEMU can write to */ - if (virAsprintf(&cmd->pidfile, "%s/%s", libDir, "capabilities.pidfile"= ) < 0) + if (virAsprintf(&proc->pidfile, "%s/%s", libDir, "capabilities.pidfile= ") < 0) goto error; =20 - virPidFileForceCleanupPath(cmd->pidfile); + virPidFileForceCleanupPath(proc->pidfile); =20 - cmd->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; - cmd->config.data.nix.path =3D cmd->monpath; - cmd->config.data.nix.listen =3D false; + proc->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; + proc->config.data.nix.path =3D proc->monpath; + proc->config.data.nix.listen =3D false; =20 - return cmd; + return proc; =20 error: - qemuProcessQMPFree(cmd); + qemuProcessQMPFree(proc); return NULL; } =20 @@ -8395,7 +8395,7 @@ qemuProcessQMPNew(const char *binary, * 1 when probing QEMU failed */ int -qemuProcessQMPRun(qemuProcessQMPPtr cmd, +qemuProcessQMPRun(qemuProcessQMPPtr proc, bool forceTCG) { virDomainXMLOptionPtr xmlopt =3D NULL; @@ -8409,7 +8409,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr cmd, machine =3D "none,accel=3Dkvm:tcg"; =20 VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s", - cmd->binary, machine); + proc->binary, machine); =20 /* * We explicitly need to use -daemonize here, rather than @@ -8418,63 +8418,63 @@ qemuProcessQMPRun(qemuProcessQMPPtr cmd, * daemonize guarantees control won't return to libvirt * until the socket is present. */ - cmd->cmd =3D virCommandNewArgList(cmd->binary, - "-S", - "-no-user-config", - "-nodefaults", - "-nographic", - "-machine", machine, - "-qmp", cmd->monarg, - "-pidfile", cmd->pidfile, - "-daemonize", + proc->cmd =3D virCommandNewArgList(proc->binary, + "-S", + "-no-user-config", + "-nodefaults", + "-nographic", + "-machine", machine, + "-qmp", proc->monarg, + "-pidfile", proc->pidfile, + "-daemonize", NULL); - virCommandAddEnvPassCommon(cmd->cmd); - virCommandClearCaps(cmd->cmd); + virCommandAddEnvPassCommon(proc->cmd); + virCommandClearCaps(proc->cmd); =20 #if WITH_CAPNG /* QEMU might run into permission issues, e.g. /dev/sev (0600), overri= de * them just for the purpose of probing */ if (geteuid() =3D=3D 0) - virCommandAllowCap(cmd->cmd, CAP_DAC_OVERRIDE); + virCommandAllowCap(proc->cmd, CAP_DAC_OVERRIDE); #endif =20 - virCommandSetGID(cmd->cmd, cmd->runGid); - virCommandSetUID(cmd->cmd, cmd->runUid); + virCommandSetGID(proc->cmd, proc->runGid); + virCommandSetUID(proc->cmd, proc->runUid); =20 - virCommandSetErrorBuffer(cmd->cmd, cmd->qmperr); + virCommandSetErrorBuffer(proc->cmd, proc->qmperr); =20 /* Log, but otherwise ignore, non-zero status. */ - if (virCommandRun(cmd->cmd, &status) < 0) + if (virCommandRun(proc->cmd, &status) < 0) goto cleanup; =20 if (status !=3D 0) { VIR_DEBUG("QEMU %s exited with status %d: %s", - cmd->binary, status, *cmd->qmperr); + proc->binary, status, *proc->qmperr); goto ignore; } =20 - if (virPidFileReadPath(cmd->pidfile, &cmd->pid) < 0) { - VIR_DEBUG("Failed to read pidfile %s", cmd->pidfile); + if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) { + VIR_DEBUG("Failed to read pidfile %s", proc->pidfile); goto ignore; } =20 if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || - !(cmd->vm =3D virDomainObjNew(xmlopt))) + !(proc->vm =3D virDomainObjNew(xmlopt))) goto cleanup; =20 - cmd->vm->pid =3D cmd->pid; + proc->vm->pid =3D proc->pid; =20 - if (!(cmd->mon =3D qemuMonitorOpen(cmd->vm, &cmd->config, true, true, - 0, &callbacks, NULL))) + if (!(proc->mon =3D qemuMonitorOpen(proc->vm, &proc->config, true, tru= e, + 0, &callbacks, NULL))) goto ignore; =20 - virObjectLock(cmd->mon); + virObjectLock(proc->mon); =20 ret =3D 0; =20 cleanup: - if (!cmd->mon) - qemuProcessQMPAbort(cmd); + if (!proc->mon) + qemuProcessQMPAbort(proc); virObjectUnref(xmlopt); =20 return ret; @@ -8486,34 +8486,34 @@ qemuProcessQMPRun(qemuProcessQMPPtr cmd, =20 =20 void -qemuProcessQMPAbort(qemuProcessQMPPtr cmd) +qemuProcessQMPAbort(qemuProcessQMPPtr proc) { - if (cmd->mon) - virObjectUnlock(cmd->mon); - qemuMonitorClose(cmd->mon); - cmd->mon =3D NULL; + if (proc->mon) + virObjectUnlock(proc->mon); + qemuMonitorClose(proc->mon); + proc->mon =3D NULL; =20 - virCommandAbort(cmd->cmd); - virCommandFree(cmd->cmd); - cmd->cmd =3D NULL; + virCommandAbort(proc->cmd); + virCommandFree(proc->cmd); + proc->cmd =3D NULL; =20 - if (cmd->monpath) - unlink(cmd->monpath); + if (proc->monpath) + unlink(proc->monpath); =20 - virDomainObjEndAPI(&cmd->vm); + virDomainObjEndAPI(&proc->vm); =20 - if (cmd->pid !=3D 0) { + if (proc->pid !=3D 0) { char ebuf[1024]; =20 - VIR_DEBUG("Killing QMP caps process %lld", (long long)cmd->pid); - if (virProcessKill(cmd->pid, SIGKILL) < 0 && errno !=3D ESRCH) + VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid); + if (virProcessKill(proc->pid, SIGKILL) < 0 && errno !=3D ESRCH) VIR_ERROR(_("Failed to kill process %lld: %s"), - (long long)cmd->pid, + (long long)proc->pid, virStrerror(errno, ebuf, sizeof(ebuf))); =20 - VIR_FREE(*cmd->qmperr); + VIR_FREE(*proc->qmperr); } - if (cmd->pidfile) - unlink(cmd->pidfile); - cmd->pid =3D 0; + if (proc->pidfile) + unlink(proc->pidfile); + proc->pid =3D 0; } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index fe79873967..a480d006f9 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -237,11 +237,11 @@ qemuProcessQMPPtr qemuProcessQMPNew(const char *binar= y, gid_t runGid, char **qmperr); =20 -void qemuProcessQMPFree(qemuProcessQMPPtr cmd); +void qemuProcessQMPFree(qemuProcessQMPPtr proc); =20 -int qemuProcessQMPRun(qemuProcessQMPPtr cmd, +int qemuProcessQMPRun(qemuProcessQMPPtr proc, bool forceTCG); =20 -void qemuProcessQMPAbort(qemuProcessQMPPtr cmd); +void qemuProcessQMPAbort(qemuProcessQMPPtr proc); =20 #endif /* LIBVIRT_QEMU_PROCESS_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567123395685.7734720763435; Tue, 19 Feb 2019 01:05:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7837315D3B; Tue, 19 Feb 2019 09:05:17 +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 4F1C117CC8; Tue, 19 Feb 2019 09:05:17 +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 3CD85181A00A; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95Ewp016160 for ; Tue, 19 Feb 2019 04:05:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 09CB419C5A; Tue, 19 Feb 2019 09:05:14 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD94019C5B for ; Tue, 19 Feb 2019 09:05:12 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 57806100105; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:48 +0100 Message-Id: <5955f057149ad060ccd2757394ecef85f8ff5872.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/20] qemu_process: Use consistent name for stop process function 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 19 Feb 2019 09:05:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher s/qemuProcessQMPAbort/qemuProcessQMPStop/ applied to change function name used to stop QEMU processes in process code moved from qemu_capabilities. No functionality change. The new name, qemuProcessQMPStop, is consistent with the existing function qemuProcessStop used to stop Domain processes. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_process.c | 6 +++--- src/qemu/qemu_process.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index aa6571457e..d187e35a38 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4379,7 +4379,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, goto cleanup; =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { - qemuProcessQMPAbort(proc); + qemuProcessQMPStop(proc); if ((rc =3D qemuProcessQMPRun(proc, true)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8e45dbc0ce..d463a41ca0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8330,7 +8330,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc) if (!proc) return; =20 - qemuProcessQMPAbort(proc); + qemuProcessQMPStop(proc); VIR_FREE(proc->binary); VIR_FREE(proc->monpath); VIR_FREE(proc->monarg); @@ -8474,7 +8474,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc, =20 cleanup: if (!proc->mon) - qemuProcessQMPAbort(proc); + qemuProcessQMPStop(proc); virObjectUnref(xmlopt); =20 return ret; @@ -8486,7 +8486,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc, =20 =20 void -qemuProcessQMPAbort(qemuProcessQMPPtr proc) +qemuProcessQMPStop(qemuProcessQMPPtr proc) { if (proc->mon) virObjectUnlock(proc->mon); diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index a480d006f9..c59379facb 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -242,6 +242,6 @@ void qemuProcessQMPFree(qemuProcessQMPPtr proc); int qemuProcessQMPRun(qemuProcessQMPPtr proc, bool forceTCG); =20 -void qemuProcessQMPAbort(qemuProcessQMPPtr proc); +void qemuProcessQMPStop(qemuProcessQMPPtr proc); =20 #endif /* LIBVIRT_QEMU_PROCESS_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567155222358.08994174201166; Tue, 19 Feb 2019 01:05:55 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B780C81F19; Tue, 19 Feb 2019 09:05:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F55417DF3; Tue, 19 Feb 2019 09:05:51 +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 F3B7D3FAF6; Tue, 19 Feb 2019 09:05:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95Gj8016198 for ; Tue, 19 Feb 2019 04:05:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7510D5D717; Tue, 19 Feb 2019 09:05:16 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40AAC5D6AA for ; Tue, 19 Feb 2019 09:05:12 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 5A0E5100106; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:49 +0100 Message-Id: <92cb10f8c35e6558aebeff075f8220411ee580ec.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/20] qemu_capabilities: Stop QEMU process before freeing 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 19 Feb 2019 09:05:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher virQEMUCapsInitQMP now stops QEMU process in all execution paths, before freeing the process structure. The qemuProcessQMPStop function can be called multiple times without problems... Won't attempt to stop processes and free resources multiple times. Follow the convention established in qemu_process of 1) alloc process structure 2) start process 3) use process 4) stop process 5) free process data structure The process data structure persists after the process activation fails or the process dies or is killed so stderr strings can be retrieved until the process data structure is freed. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_capabilities.c | 1 + src/qemu/qemu_process.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d187e35a38..f578d4a5ae 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4393,6 +4393,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, ret =3D 0; =20 cleanup: + qemuProcessQMPStop(proc); qemuProcessQMPFree(proc); return ret; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d463a41ca0..4ae2067782 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8488,14 +8488,20 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc, void qemuProcessQMPStop(qemuProcessQMPPtr proc) { - if (proc->mon) - virObjectUnlock(proc->mon); - qemuMonitorClose(proc->mon); - proc->mon =3D NULL; + if (!proc) + return; =20 - virCommandAbort(proc->cmd); - virCommandFree(proc->cmd); - proc->cmd =3D NULL; + if (proc->mon) { + virObjectUnlock(proc->mon); + qemuMonitorClose(proc->mon); + proc->mon =3D NULL; + } + + if (proc->cmd) { + virCommandAbort(proc->cmd); + virCommandFree(proc->cmd); + proc->cmd =3D NULL; + } =20 if (proc->monpath) unlink(proc->monpath); @@ -8512,8 +8518,10 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc) virStrerror(errno, ebuf, sizeof(ebuf))); =20 VIR_FREE(*proc->qmperr); + + proc->pid =3D 0; } + if (proc->pidfile) unlink(proc->pidfile); - proc->pid =3D 0; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567149677347.82260932857344; Tue, 19 Feb 2019 01:05:49 -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 F183181138; Tue, 19 Feb 2019 09:05:46 +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 C299D61B6B; Tue, 19 Feb 2019 09:05:46 +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 7D964181A13B; Tue, 19 Feb 2019 09:05:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95FIq016191 for ; Tue, 19 Feb 2019 04:05:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id EA4C0101E5B1; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94E3E104811E for ; Tue, 19 Feb 2019 09:05:12 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 5C382100107; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:50 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/20] qemu_process: Use qemuProcessQMP struct for a single process 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: , 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.27]); Tue, 19 Feb 2019 09:05:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher In new process code, move from model where qemuProcessQMP struct can be used to activate a series of Qemu processes to model where one qemuProcessQMP struct is used for one and only one Qemu process. By allowing only one process activation per qemuProcessQMP struct, the struct can safely store process outputs like status and stderr, without being overwritten, until qemuProcessQMPFree is called. By doing this, process outputs like status and stderr can remain stored in the qemuProcessQMP struct without being overwritten by subsequent process activations. The forceTCG parameter (use / don't use KVM) will be passed when the qemuProcessQMP struct is initialized since the qemuProcessQMP struct won't be reused. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_capabilities.c | 19 +++++++++++++++---- src/qemu/qemu_process.c | 9 +++++---- src/qemu/qemu_process.h | 7 ++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f578d4a5ae..6716e62e4a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4362,14 +4362,15 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, char **qmperr) { qemuProcessQMPPtr proc =3D NULL; + qemuProcessQMPPtr procTCG =3D NULL; int ret =3D -1; int rc; =20 if (!(proc =3D qemuProcessQMPNew(qemuCaps->binary, libDir, - runUid, runGid, qmperr))) + runUid, runGid, qmperr, false))) goto cleanup; =20 - if ((rc =3D qemuProcessQMPRun(proc, false)) !=3D 0) { + if ((rc =3D qemuProcessQMPRun(proc)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; goto cleanup; @@ -4379,14 +4380,22 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, goto cleanup; =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { + /* The second QEMU process probes for TCG capabilities + * in case the first process reported KVM as enabled + * (otherwise the first one already reported TCG capabilities). */ + qemuProcessQMPStop(proc); - if ((rc =3D qemuProcessQMPRun(proc, true)) !=3D 0) { + + procTCG =3D qemuProcessQMPNew(qemuCaps->binary, libDir, + runUid, runGid, NULL, true); + + if ((rc =3D qemuProcessQMPRun(procTCG)) !=3D 0) { if (rc =3D=3D 1) ret =3D 0; goto cleanup; } =20 - if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon) < 0) + if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, procTCG->mon) < 0) goto cleanup; } =20 @@ -4394,7 +4403,9 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, =20 cleanup: qemuProcessQMPStop(proc); + qemuProcessQMPStop(procTCG); qemuProcessQMPFree(proc); + qemuProcessQMPFree(procTCG); return ret; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4ae2067782..6c0f7165c7 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8344,7 +8344,8 @@ qemuProcessQMPNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, - char **qmperr) + char **qmperr, + bool forceTCG) { qemuProcessQMPPtr proc =3D NULL; =20 @@ -8357,6 +8358,7 @@ qemuProcessQMPNew(const char *binary, proc->runUid =3D runUid; proc->runGid =3D runGid; proc->qmperr =3D qmperr; + proc->forceTCG =3D forceTCG; =20 /* the ".sock" sufix is important to avoid a possible clash with a qemu * domain called "capabilities" @@ -8395,15 +8397,14 @@ qemuProcessQMPNew(const char *binary, * 1 when probing QEMU failed */ int -qemuProcessQMPRun(qemuProcessQMPPtr proc, - bool forceTCG) +qemuProcessQMPRun(qemuProcessQMPPtr proc) { virDomainXMLOptionPtr xmlopt =3D NULL; const char *machine; int status =3D 0; int ret =3D -1; =20 - if (forceTCG) + if (proc->forceTCG) machine =3D "none,accel=3Dtcg"; else machine =3D "none,accel=3Dkvm:tcg"; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index c59379facb..46a0bd2475 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -229,18 +229,19 @@ struct _qemuProcessQMP { virDomainChrSourceDef config; pid_t pid; virDomainObjPtr vm; + bool forceTCG; }; =20 qemuProcessQMPPtr qemuProcessQMPNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, - char **qmperr); + char **qmperr, + bool forceTCG); =20 void qemuProcessQMPFree(qemuProcessQMPPtr proc); =20 -int qemuProcessQMPRun(qemuProcessQMPPtr proc, - bool forceTCG); +int qemuProcessQMPRun(qemuProcessQMPPtr proc); =20 void qemuProcessQMPStop(qemuProcessQMPPtr proc); =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567145951472.1932585138728; Tue, 19 Feb 2019 01:05:45 -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 E5C3C2DE41D; Tue, 19 Feb 2019 09:05:42 +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 ADD4861B80; Tue, 19 Feb 2019 09:05:42 +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 62537181A010; Tue, 19 Feb 2019 09:05:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95FHs016181 for ; Tue, 19 Feb 2019 04:05:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id C50BB101E5B1; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96A5C1048125 for ; Tue, 19 Feb 2019 09:05:12 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 5E722100109; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:51 +0100 Message-Id: <75b43282d7fbb9ff92deb8b135f3a896e9068c11.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/20] qemu_capabilities: Refactor virQEMUCapsInitQMP 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: , 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.29]); Tue, 19 Feb 2019 09:05:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function contains two almost identical parts. Let's consolidate them into a single helper function and call it twice. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - new patch src/qemu/qemu_capabilities.c | 67 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6716e62e4a..b695b23fcc 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4355,19 +4355,19 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCap= s ATTRIBUTE_UNUSED, =20 =20 static int -virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, - const char *libDir, - uid_t runUid, - gid_t runGid, - char **qmperr) +virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, + const char *libDir, + uid_t runUid, + gid_t runGid, + char **qmperr, + bool onlyTCG) { qemuProcessQMPPtr proc =3D NULL; - qemuProcessQMPPtr procTCG =3D NULL; int ret =3D -1; int rc; =20 if (!(proc =3D qemuProcessQMPNew(qemuCaps->binary, libDir, - runUid, runGid, qmperr, false))) + runUid, runGid, qmperr, onlyTCG))) goto cleanup; =20 if ((rc =3D qemuProcessQMPRun(proc)) !=3D 0) { @@ -4376,40 +4376,41 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, goto cleanup; } =20 - if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0) - goto cleanup; - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { - /* The second QEMU process probes for TCG capabilities - * in case the first process reported KVM as enabled - * (otherwise the first one already reported TCG capabilities). */ - - qemuProcessQMPStop(proc); - - procTCG =3D qemuProcessQMPNew(qemuCaps->binary, libDir, - runUid, runGid, NULL, true); - - if ((rc =3D qemuProcessQMPRun(procTCG)) !=3D 0) { - if (rc =3D=3D 1) - ret =3D 0; - goto cleanup; - } - - if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, procTCG->mon) < 0) - goto cleanup; - } - - ret =3D 0; + if (onlyTCG) + ret =3D virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon); + else + ret =3D virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon); =20 cleanup: qemuProcessQMPStop(proc); - qemuProcessQMPStop(procTCG); qemuProcessQMPFree(proc); - qemuProcessQMPFree(procTCG); return ret; } =20 =20 +static int +virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, + const char *libDir, + uid_t runUid, + gid_t runGid, + char **qmperr) +{ + if (virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, qmperr,= false) < 0) + return -1; + + /* + * If KVM was enabled during the first probe, we need to explicitly pr= obe + * for TCG capabilities by asking the same binary again and turning KVM + * off. + */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && + virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, NULL, t= rue) < 0) + return -1; + + return 0; +} + + #define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa36= 1" =20 static void --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567163769968.6487668697005; Tue, 19 Feb 2019 01:06:03 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6DE08E693; Tue, 19 Feb 2019 09:05:59 +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 5B3F7600C8; Tue, 19 Feb 2019 09:05: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 0F4CB181A266; Tue, 19 Feb 2019 09:05:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95GPm016213 for ; Tue, 19 Feb 2019 04:05:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 982535D6AA; Tue, 19 Feb 2019 09:05:16 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41E9C5D70E for ; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 60E3E10010B; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:52 +0100 Message-Id: <1b8f3f137d3fd88bddd19578c1ae61e4b190d859.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/20] qemu_process: Don't ignore errors in virQEMUCapsInit 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: , 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 19 Feb 2019 09:06:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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=C3=A1n Tomko --- Notes: Version 7: - this is a rewritten version of [PATCH 08/33] qemu_process: All ProcessQMP errors are fatal from version 6 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 =3D 0; goto cleanup; } =20 @@ -4161,7 +4160,6 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, &package) < 0) { VIR_DEBUG("Failed to query monitor version %s", virGetLastErrorMessage()); - ret =3D 0; goto cleanup; } =20 @@ -4338,7 +4336,6 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps = ATTRIBUTE_UNUSED, if (qemuMonitorSetCapabilities(mon) < 0) { VIR_DEBUG("Failed to set monitor capabilities %s", virGetLastErrorMessage()); - ret =3D 0; goto cleanup; } =20 @@ -4364,17 +4361,13 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, { qemuProcessQMPPtr proc =3D NULL; int ret =3D -1; - int rc; =20 if (!(proc =3D qemuProcessQMPNew(qemuCaps->binary, libDir, runUid, runGid, qmperr, onlyTCG))) goto cleanup; =20 - if ((rc =3D qemuProcessQMPRun(proc)) !=3D 0) { - if (rc =3D=3D 1) - ret =3D 0; + if (qemuProcessQMPRun(proc) < 0) goto cleanup; - } =20 if (onlyTCG) ret =3D virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon); @@ -4474,14 +4467,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, goto error; } =20 - 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 =3D virGetSelfLastChanged(); qemuCaps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; =20 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, } =20 =20 -/* 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 =3D 0; int ret =3D -1; + int rc; =20 if (proc->forceTCG) machine =3D "none,accel=3Dtcg"; @@ -8444,19 +8441,21 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) =20 virCommandSetErrorBuffer(proc->cmd, proc->qmperr); =20 - /* Log, but otherwise ignore, non-zero status. */ if (virCommandRun(proc->cmd, &status) < 0) goto cleanup; =20 if (status !=3D 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; } =20 - if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) { - VIR_DEBUG("Failed to read pidfile %s", proc->pidfile); - goto ignore; + if ((rc =3D virPidFileReadPath(proc->pidfile, &proc->pid)) < 0) { + virReportSystemError(-rc, _("Failed to read pidfile %s"), proc->pi= dfile); + goto cleanup; } =20 if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || @@ -8467,7 +8466,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) =20 if (!(proc->mon =3D qemuMonitorOpen(proc->vm, &proc->config, true, tru= e, 0, &callbacks, NULL))) - goto ignore; + goto cleanup; =20 virObjectLock(proc->mon); =20 @@ -8479,10 +8478,6 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) virObjectUnref(xmlopt); =20 return ret; - - ignore: - ret =3D 1; - goto cleanup; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 15505671608641016.2563190271097; Tue, 19 Feb 2019 01:06:00 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F418E5D608; Tue, 19 Feb 2019 09:05:58 +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 C0CB6648DE; Tue, 19 Feb 2019 09:05:58 +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 79EBF181A13D; Tue, 19 Feb 2019 09:05:58 +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 x1J95LBD016285 for ; Tue, 19 Feb 2019 04:05:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1B3AB17DC4; Tue, 19 Feb 2019 09:05:21 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEEDA17CEC for ; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 637F910010C; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:53 +0100 Message-Id: <2cb64fcea247a0acde3699ef805e28284e9c58fd.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/20] qemu_capabilities: Log probe failure in virQEMUCapsInitQMPSingle 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 19 Feb 2019 09:05:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's push the call to virQEMUCapsLogProbeFailure down the stack to where the probing failure is detected. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - this patch was originally included in [PATCH 09/33] qemu_process: Expose process exit status code in version 6 with a bunch of other unrelated changes - modified after virQEMUCapsInitQMP was refactored src/qemu/qemu_capabilities.c | 47 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index bb1920146e..264dcae983 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4351,6 +4351,26 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps= 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 virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, const char *libDir, @@ -4375,6 +4395,9 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, ret =3D virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon); =20 cleanup: + if (ret < 0) + virQEMUCapsLogProbeFailure(qemuCaps->binary); + qemuProcessQMPStop(proc); qemuProcessQMPFree(proc); return ret; @@ -4404,26 +4427,6 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, } =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, @@ -4462,10 +4465,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, goto error; } =20 - if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0)= { - virQEMUCapsLogProbeFailure(binary); + if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0) goto error; - } =20 qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); qemuCaps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567142387190.4966281850792; Tue, 19 Feb 2019 01:05:42 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFA6FAB423; Tue, 19 Feb 2019 09:05:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BCE85ED46; Tue, 19 Feb 2019 09:05:38 +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 289C43FB13; Tue, 19 Feb 2019 09:05:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95FLZ016176 for ; Tue, 19 Feb 2019 04:05:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id B059C19C5B; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CB2719C5A for ; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 65D5510010D; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:54 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/20] qemu_process: Hide qmperr inside qemuProcessQMP 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Feb 2019 09:05:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Keep the pointer to QEMU stderr output in qemuProcessQMP struct instead of requiring the caller to provide it (and free it). Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - this is a combination of the relevant parts of [PATCH 09/33] qemu_process: Expose process exit status code and [PATCH 10/33] qemu_process: Persist stderr in qemuProcessQMP struct adapted to the changes made in the previous patches src/qemu/qemu_capabilities.c | 14 +++++--------- src/qemu/qemu_process.c | 9 +++------ src/qemu/qemu_process.h | 3 +-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 264dcae983..7460b452a0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4376,14 +4376,13 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, const char *libDir, uid_t runUid, gid_t runGid, - char **qmperr, bool onlyTCG) { qemuProcessQMPPtr proc =3D NULL; int ret =3D -1; =20 if (!(proc =3D qemuProcessQMPNew(qemuCaps->binary, libDir, - runUid, runGid, qmperr, onlyTCG))) + runUid, runGid, onlyTCG))) goto cleanup; =20 if (qemuProcessQMPRun(proc) < 0) @@ -4408,10 +4407,9 @@ static int virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, const char *libDir, uid_t runUid, - gid_t runGid, - char **qmperr) + gid_t runGid) { - if (virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, qmperr,= false) < 0) + if (virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, false) = < 0) return -1; =20 /* @@ -4420,7 +4418,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, * off. */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && - virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, NULL, t= rue) < 0) + virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, true) <= 0) return -1; =20 return 0; @@ -4438,7 +4436,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, { virQEMUCapsPtr qemuCaps; struct stat sb; - char *qmperr =3D NULL; =20 if (!(qemuCaps =3D virQEMUCapsNew())) goto error; @@ -4465,7 +4462,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, goto error; } =20 - if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0) + if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0) goto error; =20 qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); @@ -4484,7 +4481,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 728176bbdf..d2859da2ec 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8335,6 +8335,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc) VIR_FREE(proc->monpath); VIR_FREE(proc->monarg); VIR_FREE(proc->pidfile); + VIR_FREE(proc->stderr); VIR_FREE(proc); } =20 @@ -8344,7 +8345,6 @@ qemuProcessQMPNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, - char **qmperr, bool forceTCG) { qemuProcessQMPPtr proc =3D NULL; @@ -8357,7 +8357,6 @@ qemuProcessQMPNew(const char *binary, =20 proc->runUid =3D runUid; proc->runGid =3D runGid; - proc->qmperr =3D qmperr; proc->forceTCG =3D forceTCG; =20 /* the ".sock" sufix is important to avoid a possible clash with a qemu @@ -8439,7 +8438,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) virCommandSetGID(proc->cmd, proc->runGid); virCommandSetUID(proc->cmd, proc->runUid); =20 - virCommandSetErrorBuffer(proc->cmd, proc->qmperr); + virCommandSetErrorBuffer(proc->cmd, &(proc->stderr)); =20 if (virCommandRun(proc->cmd, &status) < 0) goto cleanup; @@ -8449,7 +8448,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to start QEMU binary %s for probing: %s"), proc->binary, - *proc->qmperr ? *proc->qmperr : _("unknown error")); + proc->stderr ? proc->stderr : _("unknown error")); goto cleanup; } =20 @@ -8513,8 +8512,6 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc) (long long)proc->pid, virStrerror(errno, ebuf, sizeof(ebuf))); =20 - VIR_FREE(*proc->qmperr); - proc->pid =3D 0; } =20 diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 46a0bd2475..e7d4ca0c92 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -220,7 +220,7 @@ struct _qemuProcessQMP { char *binary; uid_t runUid; gid_t runGid; - char **qmperr; + char *stderr; char *monarg; char *monpath; char *pidfile; @@ -236,7 +236,6 @@ qemuProcessQMPPtr qemuProcessQMPNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, - char **qmperr, bool forceTCG); =20 void qemuProcessQMPFree(qemuProcessQMPPtr proc); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550842763239976.5598276785296; Fri, 22 Feb 2019 05:39:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7238D7F36B; Fri, 22 Feb 2019 13:39:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C2D725279; Fri, 22 Feb 2019 13:39:21 +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 E1317247E2; Fri, 22 Feb 2019 13:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95Iea016263 for ; Tue, 19 Feb 2019 04:05:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id A49544139; Tue, 19 Feb 2019 09:05:18 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51DE717C7B for ; Tue, 19 Feb 2019 09:05:15 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 684DC10010E; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:55 +0100 Message-Id: <90f1efdc2355c8d18ce691a456fbcdabee0a442e.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/20] qemu_process: Introduce qemuProcessQMPStart 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: , 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 22 Feb 2019 13:39:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher This is a replacement for qemuProcessQMPRun to make the name consistent with qemuProcessStart. The original qemuProcessQMPRun function is renamed as qemuProcessQMPLaunch and becomes one of the simpler functions called from the main qemuProcessQMPStart entry point. The following patches will move parts of the code in qemuProcessQMPLaunch to the other functions (qemuProcessQMPInit and qemuProcessQMPConnectMonitor). Signed-off-by: Chris Venteicher Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - removed some fairy tales from the commit message and the documentation of qemuProcessQMPStart src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_process.c | 74 +++++++++++++++++++++++++++++++++++- src/qemu/qemu_process.h | 2 +- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 7460b452a0..4fd2169d49 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4385,7 +4385,7 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, runUid, runGid, onlyTCG))) goto cleanup; =20 - if (qemuProcessQMPRun(proc) < 0) + if (qemuProcessQMPStart(proc) < 0) goto cleanup; =20 if (onlyTCG) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d2859da2ec..19bc804d18 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8391,8 +8391,21 @@ qemuProcessQMPNew(const char *binary, } =20 =20 -int -qemuProcessQMPRun(qemuProcessQMPPtr proc) +static int +qemuProcessQMPInit(qemuProcessQMPPtr proc) +{ + int ret =3D -1; + + VIR_DEBUG("proc=3D%p, emulator=3D%s", proc, proc->binary); + + ret =3D 0; + + return ret; +} + + +static int +qemuProcessQMPLaunch(qemuProcessQMPPtr proc) { virDomainXMLOptionPtr xmlopt =3D NULL; const char *machine; @@ -8480,6 +8493,63 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc) } =20 =20 +static int +qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) +{ + int ret =3D -1; + + VIR_DEBUG("proc=3D%p, emulator=3D%s, proc->pid=3D%lld", + proc, proc->binary, (long long)proc->pid); + + ret =3D 0; + + return ret; +} + + +/** + * qemuProcessQMPStart: + * @proc: QEMU process and connection state created by qemuProcessQMPNew() + * + * Start and connect to QEMU binary so QMP queries can be made. + * + * Usage: + * proc =3D qemuProcessQMPNew(binary, libDir, runUid, runGid, forceTCG); + * qemuProcessQMPStart(proc); + * ** Send QMP Queries to QEMU using monitor (proc->mon) ** + * qemuProcessQMPStop(proc); + * qemuProcessQMPFree(proc); + * + * Process error output (proc->stderr) remains available in qemuProcessQMP + * struct until qemuProcessQMPFree is called. + */ +int +qemuProcessQMPStart(qemuProcessQMPPtr proc) +{ + int ret =3D -1; + + VIR_DEBUG("proc=3D%p, emulator=3D%s", proc, proc->binary); + + if (qemuProcessQMPInit(proc) < 0) + goto cleanup; + + if (qemuProcessQMPLaunch(proc) < 0) + goto stop; + + if (qemuProcessQMPConnectMonitor(proc) < 0) + goto stop; + + ret =3D 0; + + cleanup: + return ret; + + stop: + qemuProcessQMPStop(proc); + goto cleanup; +} + + void qemuProcessQMPStop(qemuProcessQMPPtr proc) { diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index e7d4ca0c92..c075ae6445 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -240,7 +240,7 @@ qemuProcessQMPPtr qemuProcessQMPNew(const char *binary, =20 void qemuProcessQMPFree(qemuProcessQMPPtr proc); =20 -int qemuProcessQMPRun(qemuProcessQMPPtr proc); +int qemuProcessQMPStart(qemuProcessQMPPtr proc); =20 void qemuProcessQMPStop(qemuProcessQMPPtr proc); =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567144274845.5748931670861; Tue, 19 Feb 2019 01:05:44 -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 1B6037F769; Tue, 19 Feb 2019 09:05:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC06161480; Tue, 19 Feb 2019 09:05:41 +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 8426A3FB15; Tue, 19 Feb 2019 09:05:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95HjH016220 for ; Tue, 19 Feb 2019 04:05:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 450841048104; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16323101E5B1 for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 6A4E510010F; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:56 +0100 Message-Id: <1a8578e04fc2d178ba8284d3c2a9efcf945e73bf.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/20] qemu_process: Move monitor code to qemuProcessQMPConnectMonitor 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: , 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.27]); Tue, 19 Feb 2019 09:05:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher All code related to QEMU monitor is moved from qemuProcessQMPNew and qemuProcessQMPInit into qemuProcessQMPConnectMonitor. Signed-off-by: Chris Venteicher Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - simplified commit message - adapted to changes in the preceding patches src/qemu/qemu_process.c | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 19bc804d18..85079c8c15 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8379,10 +8379,6 @@ qemuProcessQMPNew(const char *binary, =20 virPidFileForceCleanupPath(proc->pidfile); =20 - proc->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; - proc->config.data.nix.path =3D proc->monpath; - proc->config.data.nix.listen =3D false; - return proc; =20 error: @@ -8407,7 +8403,6 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc) static int qemuProcessQMPLaunch(qemuProcessQMPPtr proc) { - virDomainXMLOptionPtr xmlopt =3D NULL; const char *machine; int status =3D 0; int ret =3D -1; @@ -8470,6 +8465,26 @@ qemuProcessQMPLaunch(qemuProcessQMPPtr proc) goto cleanup; } =20 + ret =3D 0; + + cleanup: + return ret; +} + + +static int +qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) +{ + virDomainXMLOptionPtr xmlopt =3D NULL; + int ret =3D -1; + + VIR_DEBUG("proc=3D%p, emulator=3D%s, proc->pid=3D%lld", + proc, proc->binary, (long long)proc->pid); + + proc->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; + proc->config.data.nix.path =3D proc->monpath; + proc->config.data.nix.listen =3D false; + if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || !(proc->vm =3D virDomainObjNew(xmlopt))) goto cleanup; @@ -8485,24 +8500,7 @@ qemuProcessQMPLaunch(qemuProcessQMPPtr proc) ret =3D 0; =20 cleanup: - if (!proc->mon) - qemuProcessQMPStop(proc); virObjectUnref(xmlopt); - - return ret; -} - - -static int -qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) -{ - int ret =3D -1; - - VIR_DEBUG("proc=3D%p, emulator=3D%s, proc->pid=3D%lld", - proc, proc->binary, (long long)proc->pid); - - ret =3D 0; - return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567167622758.5774757656174; Tue, 19 Feb 2019 01:06:07 -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 A03CFC070E03; Tue, 19 Feb 2019 09:06:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4301E610FC; Tue, 19 Feb 2019 09:06:04 +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 E4A783FA4F; Tue, 19 Feb 2019 09:06:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95H3M016219 for ; Tue, 19 Feb 2019 04:05:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4120260142; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10C2E6013D for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 6CC6A100110; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:57 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/20] qemu_process: Store libDir in qemuProcessQMP struct 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: , 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.31]); Tue, 19 Feb 2019 09:06:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher Store libDir path in the qemuProcessQMP struct in anticipation of moving path construction code into qemuProcessQMPInit function. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_process.c | 8 +++++--- src/qemu/qemu_process.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 85079c8c15..c4cbd7c807 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8332,6 +8332,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc) =20 qemuProcessQMPStop(proc); VIR_FREE(proc->binary); + VIR_FREE(proc->libDir); VIR_FREE(proc->monpath); VIR_FREE(proc->monarg); VIR_FREE(proc->pidfile); @@ -8352,7 +8353,8 @@ qemuProcessQMPNew(const char *binary, if (VIR_ALLOC(proc) < 0) goto error; =20 - if (VIR_STRDUP(proc->binary, binary) < 0) + if (VIR_STRDUP(proc->binary, binary) < 0 || + VIR_STRDUP(proc->libDir, libDir) < 0) goto error; =20 proc->runUid =3D runUid; @@ -8362,7 +8364,7 @@ qemuProcessQMPNew(const char *binary, /* the ".sock" sufix is important to avoid a possible clash with a qemu * domain called "capabilities" */ - if (virAsprintf(&proc->monpath, "%s/%s", libDir, + if (virAsprintf(&proc->monpath, "%s/%s", proc->libDir, "capabilities.monitor.sock") < 0) goto error; if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath)= < 0) @@ -8374,7 +8376,7 @@ qemuProcessQMPNew(const char *binary, * -daemonize we need QEMU to be allowed to create them, rather * than libvirtd. So we're using libDir which QEMU can write to */ - if (virAsprintf(&proc->pidfile, "%s/%s", libDir, "capabilities.pidfile= ") < 0) + if (virAsprintf(&proc->pidfile, "%s/%s", proc->libDir, "capabilities.p= idfile") < 0) goto error; =20 virPidFileForceCleanupPath(proc->pidfile); diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index c075ae6445..9ab885c6c3 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -218,6 +218,7 @@ typedef struct _qemuProcessQMP qemuProcessQMP; typedef qemuProcessQMP *qemuProcessQMPPtr; struct _qemuProcessQMP { char *binary; + char *libDir; uid_t runUid; gid_t runGid; char *stderr; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567171051959.859138124242; Tue, 19 Feb 2019 01:06:11 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE93E5A1E3; Tue, 19 Feb 2019 09:06:08 +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 9E38C6014C; Tue, 19 Feb 2019 09:06:08 +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 56471181A010; Tue, 19 Feb 2019 09:06:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95H1G016226 for ; Tue, 19 Feb 2019 04:05:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 524626013D; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 256D360140 for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 6F0B9100111; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:58 +0100 Message-Id: <03311109fbf57b8cc057e732799f4c3d2d35dd69.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/20] qemu_process: Setup paths within qemuProcessQMPInit 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: , 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Feb 2019 09:06:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher Move code for setting paths and prepping file system from qemuProcessQMPNew to qemuProcessQMPInit. This keeps qemuProcessQMPNew limited to data structures and path initialization is done in qemuProcessQMPInit. The patch is a non-functional, cut / paste change, however goto is now "cleanup" rather than "error". Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_process.c | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c4cbd7c807..9341aa43a7 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8361,26 +8361,6 @@ qemuProcessQMPNew(const char *binary, proc->runGid =3D runGid; proc->forceTCG =3D forceTCG; =20 - /* the ".sock" sufix is important to avoid a possible clash with a qemu - * domain called "capabilities" - */ - if (virAsprintf(&proc->monpath, "%s/%s", proc->libDir, - "capabilities.monitor.sock") < 0) - goto error; - if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath)= < 0) - goto error; - - /* ".pidfile" suffix is used rather than ".pid" to avoid a possible cl= ash - * with a qemu domain called "capabilities" - * Normally we'd use runDir for pid files, but because we're using - * -daemonize we need QEMU to be allowed to create them, rather - * than libvirtd. So we're using libDir which QEMU can write to - */ - if (virAsprintf(&proc->pidfile, "%s/%s", proc->libDir, "capabilities.p= idfile") < 0) - goto error; - - virPidFileForceCleanupPath(proc->pidfile); - return proc; =20 error: @@ -8396,8 +8376,30 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc) =20 VIR_DEBUG("proc=3D%p, emulator=3D%s", proc, proc->binary); =20 + /* the ".sock" sufix is important to avoid a possible clash with a qemu + * domain called "capabilities" + */ + if (virAsprintf(&proc->monpath, "%s/%s", proc->libDir, + "capabilities.monitor.sock") < 0) + goto cleanup; + + if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath)= < 0) + goto cleanup; + + /* ".pidfile" suffix is used rather than ".pid" to avoid a possible cl= ash + * with a qemu domain called "capabilities" + * Normally we'd use runDir for pid files, but because we're using + * -daemonize we need QEMU to be allowed to create them, rather + * than libvirtd. So we're using libDir which QEMU can write to + */ + if (virAsprintf(&proc->pidfile, "%s/%s", proc->libDir, "capabilities.p= idfile") < 0) + goto cleanup; + + virPidFileForceCleanupPath(proc->pidfile); + ret =3D 0; =20 + cleanup: return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567151656216.8088177459157; Tue, 19 Feb 2019 01:05:51 -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 B1A3387632; Tue, 19 Feb 2019 09:05:46 +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 58AC6610C7; Tue, 19 Feb 2019 09:05:46 +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 C7F9A181A135; Tue, 19 Feb 2019 09:05:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95HKb016227 for ; Tue, 19 Feb 2019 04:05:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5606A1024968; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 291971048125 for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 719CC100112; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:04:59 +0100 Message-Id: <715969225885685bc883c884aa908cb5d60ac2e3.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/20] qemu_process: Stop retaining monitor config in qemuProcessQMP 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: , 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.26]); Tue, 19 Feb 2019 09:05:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher The monitor config data is removed from the qemuProcessQMP struct. The monitor config data can be initialized immediately before call to qemuMonitorOpen and does not need to be maintained after the call because qemuMonitorOpen copies any strings it needs. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - no change src/qemu/qemu_process.c | 9 +++++---- src/qemu/qemu_process.h | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9341aa43a7..79896b6232 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8480,14 +8480,15 @@ static int qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) { virDomainXMLOptionPtr xmlopt =3D NULL; + virDomainChrSourceDef monConfig; int ret =3D -1; =20 VIR_DEBUG("proc=3D%p, emulator=3D%s, proc->pid=3D%lld", proc, proc->binary, (long long)proc->pid); =20 - proc->config.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; - proc->config.data.nix.path =3D proc->monpath; - proc->config.data.nix.listen =3D false; + monConfig.type =3D VIR_DOMAIN_CHR_TYPE_UNIX; + monConfig.data.nix.path =3D proc->monpath; + monConfig.data.nix.listen =3D false; =20 if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || !(proc->vm =3D virDomainObjNew(xmlopt))) @@ -8495,7 +8496,7 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) =20 proc->vm->pid =3D proc->pid; =20 - if (!(proc->mon =3D qemuMonitorOpen(proc->vm, &proc->config, true, tru= e, + if (!(proc->mon =3D qemuMonitorOpen(proc->vm, &monConfig, true, true, 0, &callbacks, NULL))) goto cleanup; =20 diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 9ab885c6c3..2422d1eb7c 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -227,7 +227,6 @@ struct _qemuProcessQMP { char *pidfile; virCommandPtr cmd; qemuMonitorPtr mon; - virDomainChrSourceDef config; pid_t pid; virDomainObjPtr vm; bool forceTCG; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567153504887.2071803122375; Tue, 19 Feb 2019 01:05:53 -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 E2741C007341; Tue, 19 Feb 2019 09:05:50 +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 54E141048104; Tue, 19 Feb 2019 09:05:50 +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 05DE9181A13E; Tue, 19 Feb 2019 09:05:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95HIv016239 for ; Tue, 19 Feb 2019 04:05:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7C9301024968; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EF1A101E5B1 for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 7411E100113; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:05:00 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 17/20] qemu_process: Document and cleanup qemuProcessQMPNew 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: , 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.32]); Tue, 19 Feb 2019 09:05:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher qemuProcessQMPNew is one of the public functions used to create and manage a QEMU process for QMP command exchanges outside of domain operations. Add descriptive comment block, debug statement and make source consistent with the cleanup / VIR_STEAL_PTR format used elsewhere. Signed-off-by: Chris Venteicher Reviewed-by: Jiri Denemark Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - just a few small tweaks, mainly in the commit message and comments src/qemu/qemu_process.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 79896b6232..b5d127b7d3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8341,6 +8341,17 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc) } =20 =20 +/** + * qemuProcessQMPNew: + * @binary: QEMU binary + * @libDir: Directory for process and connection artifacts + * @runUid: UserId for QEMU process + * @runGid: GroupId for QEMU process + * @forceTCG: Force TCG mode if true + * + * Allocate and initialize domain structure encapsulating QEMU process sta= te + * and monitor connection for completing QMP queries. + */ qemuProcessQMPPtr qemuProcessQMPNew(const char *binary, const char *libDir, @@ -8348,24 +8359,28 @@ qemuProcessQMPNew(const char *binary, gid_t runGid, bool forceTCG) { + qemuProcessQMPPtr ret =3D NULL; qemuProcessQMPPtr proc =3D NULL; =20 + VIR_DEBUG("exec=3D%s, libDir=3D%s, runUid=3D%u, runGid=3D%u, forceTCG= =3D%d", + binary, libDir, runUid, runGid, forceTCG); + if (VIR_ALLOC(proc) < 0) - goto error; + goto cleanup; =20 if (VIR_STRDUP(proc->binary, binary) < 0 || VIR_STRDUP(proc->libDir, libDir) < 0) - goto error; + goto cleanup; =20 proc->runUid =3D runUid; proc->runGid =3D runGid; proc->forceTCG =3D forceTCG; =20 - return proc; + VIR_STEAL_PTR(ret, proc); =20 - error: + cleanup: qemuProcessQMPFree(proc); - return NULL; + return ret; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567175153422.77371152329704; Tue, 19 Feb 2019 01:06:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DE1C315FDD; Tue, 19 Feb 2019 09:06:13 +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 EB03D17CF1; Tue, 19 Feb 2019 09:06:12 +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 96120181A13B; Tue, 19 Feb 2019 09:06:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95Hpo016245 for ; Tue, 19 Feb 2019 04:05:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id A25C060BE8; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F7CA60FE5 for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 76849100114; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:05:01 +0100 Message-Id: <1bdec0a7caa88641bd83810cd056b7e9c2e61ac3.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/20] qemu_process: Hide qemuProcessQMPStop 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 19 Feb 2019 09:06:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Users qemuProcessQMP struct were always forced to call both qemuProcessQMPStop and qemuProcessQMPFree when they are done with the process. We can just call qemuProcessQMPStop from qemuProcessQMPFree and let users call qemuProcessQMPFree only. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - new patch src/qemu/qemu_capabilities.c | 1 - src/qemu/qemu_process.c | 92 ++++++++++++++++++------------------ src/qemu/qemu_process.h | 2 - 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 4fd2169d49..a546d9b5a1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4397,7 +4397,6 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, if (ret < 0) virQEMUCapsLogProbeFailure(qemuCaps->binary); =20 - qemuProcessQMPStop(proc); qemuProcessQMPFree(proc); return ret; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b5d127b7d3..ca5911bacd 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8324,6 +8324,49 @@ static qemuMonitorCallbacks callbacks =3D { }; =20 =20 +static void +qemuProcessQMPStop(qemuProcessQMPPtr proc) +{ + if (proc->mon) { + virObjectUnlock(proc->mon); + qemuMonitorClose(proc->mon); + proc->mon =3D NULL; + } + + if (proc->cmd) { + virCommandAbort(proc->cmd); + virCommandFree(proc->cmd); + proc->cmd =3D NULL; + } + + if (proc->monpath) + unlink(proc->monpath); + + virDomainObjEndAPI(&proc->vm); + + if (proc->pid !=3D 0) { + char ebuf[1024]; + + VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid); + if (virProcessKill(proc->pid, SIGKILL) < 0 && errno !=3D ESRCH) + VIR_ERROR(_("Failed to kill process %lld: %s"), + (long long)proc->pid, + virStrerror(errno, ebuf, sizeof(ebuf))); + + proc->pid =3D 0; + } + + if (proc->pidfile) + unlink(proc->pidfile); +} + + +/** + * qemuProcessQMPFree: + * @proc: Stores process and connection state + * + * Kill QEMU process and free process data structure. + */ void qemuProcessQMPFree(qemuProcessQMPPtr proc) { @@ -8535,7 +8578,6 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) * proc =3D qemuProcessQMPNew(binary, libDir, runUid, runGid, forceTCG); * qemuProcessQMPStart(proc); * ** Send QMP Queries to QEMU using monitor (proc->mon) ** - * qemuProcessQMPStop(proc); * qemuProcessQMPFree(proc); * * Process error output (proc->stderr) remains available in qemuProcessQMP @@ -8552,57 +8594,13 @@ qemuProcessQMPStart(qemuProcessQMPPtr proc) goto cleanup; =20 if (qemuProcessQMPLaunch(proc) < 0) - goto stop; + goto cleanup; =20 if (qemuProcessQMPConnectMonitor(proc) < 0) - goto stop; + goto cleanup; =20 ret =3D 0; =20 cleanup: return ret; - - stop: - qemuProcessQMPStop(proc); - goto cleanup; -} - - -void -qemuProcessQMPStop(qemuProcessQMPPtr proc) -{ - if (!proc) - return; - - if (proc->mon) { - virObjectUnlock(proc->mon); - qemuMonitorClose(proc->mon); - proc->mon =3D NULL; - } - - if (proc->cmd) { - virCommandAbort(proc->cmd); - virCommandFree(proc->cmd); - proc->cmd =3D NULL; - } - - if (proc->monpath) - unlink(proc->monpath); - - virDomainObjEndAPI(&proc->vm); - - if (proc->pid !=3D 0) { - char ebuf[1024]; - - VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid); - if (virProcessKill(proc->pid, SIGKILL) < 0 && errno !=3D ESRCH) - VIR_ERROR(_("Failed to kill process %lld: %s"), - (long long)proc->pid, - virStrerror(errno, ebuf, sizeof(ebuf))); - - proc->pid =3D 0; - } - - if (proc->pidfile) - unlink(proc->pidfile); } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 2422d1eb7c..c435a19726 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -242,6 +242,4 @@ void qemuProcessQMPFree(qemuProcessQMPPtr proc); =20 int qemuProcessQMPStart(qemuProcessQMPPtr proc); =20 -void qemuProcessQMPStop(qemuProcessQMPPtr proc); - #endif /* LIBVIRT_QEMU_PROCESS_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567157591600.5227501014692; Tue, 19 Feb 2019 01:05:57 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32C0A87621; Tue, 19 Feb 2019 09:05:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAADC19C68; Tue, 19 Feb 2019 09:05:54 +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 6E31D3FA49; Tue, 19 Feb 2019 09:05:54 +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 x1J95L8B016286 for ; Tue, 19 Feb 2019 04:05:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1B837648B9; Tue, 19 Feb 2019 09:05:21 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB5D160A9D for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 78D42100115; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:05:02 +0100 Message-Id: <2c792e6e7b272b5bc8082dcc83afbbebc412356b.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/20] qemu_process: Use unique directories for QMP processes 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: , 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 19 Feb 2019 09:05:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher Multiple QEMU processes for QMP commands can operate concurrently. Use a unique directory under libDir for each QEMU process to avoid pidfile and unix socket collision between processes. The pid file name is changed from "capabilities.pidfile" to "qmp.pid" because we no longer need to avoid a possible clash with a qemu domain called "capabilities" now that the processes artifacts are stored in their own unique temporary directories. "Capabilities" was changed to "qmp" in the pid file name because these processes are no longer specific to the capabilities usecase and are more generic in terms of being used for any general purpose QMP message exchanges with a QEMU process that is not associated with a domain. Signed-off-by: Chris Venteicher Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - report error if mkdtemp fails src/qemu/qemu_process.c | 30 ++++++++++++++++++++---------- src/qemu/qemu_process.h | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ca5911bacd..820476dbb1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8358,6 +8358,9 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc) =20 if (proc->pidfile) unlink(proc->pidfile); + + if (proc->uniqDir) + rmdir(proc->uniqDir); } =20 =20 @@ -8376,6 +8379,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc) qemuProcessQMPStop(proc); VIR_FREE(proc->binary); VIR_FREE(proc->libDir); + VIR_FREE(proc->uniqDir); VIR_FREE(proc->monpath); VIR_FREE(proc->monarg); VIR_FREE(proc->pidfile); @@ -8430,31 +8434,37 @@ qemuProcessQMPNew(const char *binary, static int qemuProcessQMPInit(qemuProcessQMPPtr proc) { + char *template =3D NULL; int ret =3D -1; =20 VIR_DEBUG("proc=3D%p, emulator=3D%s", proc, proc->binary); =20 - /* the ".sock" sufix is important to avoid a possible clash with a qemu - * domain called "capabilities" - */ - if (virAsprintf(&proc->monpath, "%s/%s", proc->libDir, - "capabilities.monitor.sock") < 0) + if (virAsprintf(&template, "%s/qmp-XXXXXX", proc->libDir) < 0) + goto cleanup; + + if (!(proc->uniqDir =3D mkdtemp(template))) { + virReportSystemError(errno, + _("Failed to create unique directory with " + "template '%s' for probing QEMU"), + template); + goto cleanup; + } + + if (virAsprintf(&proc->monpath, "%s/%s", proc->uniqDir, + "qmp.monitor") < 0) goto cleanup; =20 if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath)= < 0) goto cleanup; =20 - /* ".pidfile" suffix is used rather than ".pid" to avoid a possible cl= ash - * with a qemu domain called "capabilities" + /* * Normally we'd use runDir for pid files, but because we're using * -daemonize we need QEMU to be allowed to create them, rather * than libvirtd. So we're using libDir which QEMU can write to */ - if (virAsprintf(&proc->pidfile, "%s/%s", proc->libDir, "capabilities.p= idfile") < 0) + if (virAsprintf(&proc->pidfile, "%s/%s", proc->uniqDir, "qmp.pid") < 0) goto cleanup; =20 - virPidFileForceCleanupPath(proc->pidfile); - ret =3D 0; =20 cleanup: diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index c435a19726..3367cd3fe5 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -225,6 +225,7 @@ struct _qemuProcessQMP { char *monarg; char *monpath; char *pidfile; + char *uniqDir; virCommandPtr cmd; qemuMonitorPtr mon; pid_t pid; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 06:26:51 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 1550567182845825.6664893786663; Tue, 19 Feb 2019 01:06:22 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 839BC787F0; Tue, 19 Feb 2019 09:06:17 +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 422915D722; Tue, 19 Feb 2019 09:06:17 +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 D6490181A26B; Tue, 19 Feb 2019 09:06:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1J95IDE016253 for ; Tue, 19 Feb 2019 04:05:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 246435D6AA; Tue, 19 Feb 2019 09:05:18 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C45CD5D706 for ; Tue, 19 Feb 2019 09:05:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 7B38D100116; Tue, 19 Feb 2019 10:05:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 10:05:03 +0100 Message-Id: <9cbad94431aec33c4278fd8cdcc7c9e940082b4a.1550566126.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 20/20] qemu_process: Enter QMP command mode when starting QEMU Process 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: , 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 19 Feb 2019 09:06:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Chris Venteicher qemuProcessQMPStart starts a QEMU process and monitor connection that can be used by multiple functions possibly for multiple QMP commands. The QMP exchange to exit capabilities negotiation mode and enter command mode can only be performed once after the monitor connection is established. Move responsibility for entering QMP command mode into the qemuProcessQMP code so multiple functions can issue QMP commands in arbitrary orders. This also simplifies the functions using the connection provided by qemuProcessQMPStart to issue QMP commands. Test code now needs to call qemuMonitorSetCapabilities to send the message to switch to command mode because the test code does not use the qemuProcessQMP command that internally calls qemuMonitorSetCapabilities. Signed-off-by: Chris Venteicher Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 7: - qemuMonitorSetCapabilities call was moved into a new qemuProcessQMPInitMonitor function, which is called from qemuProcessQMPConnectMonitor and the tests src/qemu/qemu_capabilities.c | 12 ------------ src/qemu/qemu_process.c | 16 ++++++++++++++++ src/qemu/qemu_processpriv.h | 2 ++ tests/qemucapabilitiestest.c | 9 +++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a546d9b5a1..b48bcbebee 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4149,12 +4149,6 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, =20 /* @mon is supposed to be locked by callee */ =20 - if (qemuMonitorSetCapabilities(mon) < 0) { - VIR_DEBUG("Failed to set monitor capabilities %s", - virGetLastErrorMessage()); - goto cleanup; - } - if (qemuMonitorGetVersion(mon, &major, &minor, µ, &package) < 0) { @@ -4333,12 +4327,6 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps= ATTRIBUTE_UNUSED, { int ret =3D -1; =20 - if (qemuMonitorSetCapabilities(mon) < 0) { - VIR_DEBUG("Failed to set monitor capabilities %s", - virGetLastErrorMessage()); - goto cleanup; - } - if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, mon, true) < 0) goto cleanup; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 820476dbb1..85952b9975 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8544,6 +8544,19 @@ qemuProcessQMPLaunch(qemuProcessQMPPtr proc) } =20 =20 +int +qemuProcessQMPInitMonitor(qemuMonitorPtr mon) +{ + if (qemuMonitorSetCapabilities(mon) < 0) { + VIR_DEBUG("Failed to set monitor capabilities %s", + virGetLastErrorMessage()); + return -1; + } + + return 0; +} + + static int qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) { @@ -8570,6 +8583,9 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) =20 virObjectLock(proc->mon); =20 + if (qemuProcessQMPInitMonitor(proc->mon) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: diff --git a/src/qemu/qemu_processpriv.h b/src/qemu/qemu_processpriv.h index 17f981829b..237d7bad58 100644 --- a/src/qemu/qemu_processpriv.h +++ b/src/qemu/qemu_processpriv.h @@ -38,4 +38,6 @@ int qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon, const char *devAlias, void *opaque); =20 +int qemuProcessQMPInitMonitor(qemuMonitorPtr mon); + #endif /* LIBVIRT_QEMU_PROCESSPRIV_H */ diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index fab77db7ce..8d47133e6f 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -26,6 +26,8 @@ #include "qemu/qemu_capspriv.h" #define LIBVIRT_QEMU_MONITOR_PRIV_H_ALLOW #include "qemu/qemu_monitor_priv.h" +#define LIBVIRT_QEMU_PROCESSPRIV_H_ALLOW +#include "qemu/qemu_processpriv.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -60,6 +62,9 @@ testQemuCaps(const void *opaque) if (!(mon =3D qemuMonitorTestNewFromFileFull(repliesFile, &data->drive= r, NULL))) goto cleanup; =20 + if (qemuProcessQMPInitMonitor(qemuMonitorTestGetMonitor(mon)) < 0) + goto cleanup; + if (!(capsActual =3D virQEMUCapsNew()) || virQEMUCapsInitQMPMonitor(capsActual, qemuMonitorTestGetMonitor(mon)) < 0) @@ -67,6 +72,10 @@ testQemuCaps(const void *opaque) =20 if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM)) { qemuMonitorResetCommandID(qemuMonitorTestGetMonitor(mon)); + + if (qemuProcessQMPInitMonitor(qemuMonitorTestGetMonitor(mon)) < 0) + goto cleanup; + if (virQEMUCapsInitQMPMonitorTCG(capsActual, qemuMonitorTestGetMonitor(mon)) <= 0) goto cleanup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list