From nobody Thu May 15 13:34:48 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508152047237877.6726814132783; Mon, 16 Oct 2017 04:07:27 -0700 (PDT) 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 3FD1D81DF0; Mon, 16 Oct 2017 11:07:26 +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 1DAD960636; Mon, 16 Oct 2017 11:07:26 +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 D9FCD18355E3; Mon, 16 Oct 2017 11:07:25 +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 v9GB6feB008764 for ; Mon, 16 Oct 2017 07:06:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id D075C5D965; Mon, 16 Oct 2017 11:06:41 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58D135D964 for ; Mon, 16 Oct 2017 11:06:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3FD1D81DF0 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 16 Oct 2017 13:06:25 +0200 Message-Id: <8a1bcfdff526314123899ba4a09609280c4cadb8.1508151956.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/14] qemu: move detection whether to use -no-reboot to qemu_domain X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 16 Oct 2017 11:07:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will be used later on in implementation of new API virDomainSetLifecycleAction(). In order to use it, we need to store the value in status XML to not lose the information if libvirtd is restarted. If some guest was started by old libvirt where it was not possible to change the lifecycle action for running guest, we can safely detect it based on the current actions from the status XML. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_command.c | 10 ++-------- src/qemu/qemu_domain.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 1 + src/qemu/qemu_process.c | 30 ++++++++++++++++++++++++++++++ tests/qemuxml2xmltest.c | 3 ++- 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index db6cc55495..046a8fc78f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6484,23 +6484,17 @@ qemuBuildPMCommandLine(virCommandPtr cmd, const virDomainDef *def, qemuDomainObjPrivatePtr priv) { - bool allowReboot =3D true; virQEMUCapsPtr qemuCaps =3D priv->qemuCaps; =20 /* Only add -no-reboot option if each event destroys domain */ - if (def->onReboot =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && - def->onPoweroff =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && - (def->onCrash =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || - def->onCrash =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY)= ) { - allowReboot =3D false; + if (priv->allowReboot =3D=3D VIR_TRISTATE_BOOL_NO) virCommandAddArg(cmd, "-no-reboot"); - } =20 /* If JSON monitor is enabled, we can receive an event * when QEMU stops. If we use no-shutdown, then we can * watch for this event and do a soft/warm reboot. */ - if (priv->monJSON && allowReboot && + if (priv->monJSON && priv->allowReboot =3D=3D VIR_TRISTATE_BOOL_YES && virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_SHUTDOWN)) { virCommandAddArg(cmd, "-no-shutdown"); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ed27a91fa6..2630b73221 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1767,6 +1767,7 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) priv->namespaces =3D NULL; =20 priv->reconnectBlockjobs =3D VIR_TRISTATE_BOOL_ABSENT; + priv->allowReboot =3D VIR_TRISTATE_BOOL_ABSENT; } =20 =20 @@ -1876,6 +1877,16 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr = buf, } =20 =20 +static void +qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf, + virTristateBool allowReboot) +{ + virBufferAsprintf(buf, "\n", + virTristateBoolTypeToString(allowReboot)); + +} + + static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, virDomainObjPtr vm) @@ -1998,6 +2009,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, if (priv->chardevStdioLogd) virBufferAddLit(buf, "\n"); =20 + qemuDomainObjPrivateXMLFormatAllowReboot(buf, priv->allowReboot); + if (qemuDomainObjPrivateXMLFormatBlockjobs(buf, vm) < 0) return -1; =20 @@ -2109,6 +2122,31 @@ qemuDomainObjPrivateXMLParseBlockjobs(qemuDomainObjP= rivatePtr priv, =20 =20 static int +qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt, + virTristateBool *allowReboot) +{ + int ret =3D -1; + int val; + char *valStr; + + if ((valStr =3D virXPathString("string(./allowReboot/@value)", ctxt)))= { + if ((val =3D virTristateBoolTypeFromString(valStr)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid allowReboot value '%s'"), valStr); + goto cleanup; + } + *allowReboot =3D val; + } + + ret =3D 0; + + cleanup: + VIR_FREE(valStr); + return ret; +} + + +static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, virDomainObjPtr vm, virDomainDefParserConfigPtr config) @@ -2323,6 +2361,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, priv->chardevStdioLogd =3D virXPathBoolean("boolean(./chardevStdioLogd= )", ctxt) =3D=3D 1; =20 + qemuDomainObjPrivateXMLParseAllowReboot(ctxt, &priv->allowReboot); + if (qemuDomainObjPrivateXMLParseBlockjobs(priv, ctxt) < 0) goto error; =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 00226a3fc8..be4aaa5613 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -261,6 +261,7 @@ struct _qemuDomainObjPrivate { char *lockState; =20 bool fakeReboot; + virTristateBool allowReboot; =20 int jobs_queued; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 11914a72f3..e555ec9c96 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5309,6 +5309,26 @@ qemuProcessPrepareDomainStorage(virConnectPtr conn, } =20 =20 +static void +qemuProcessPrepareAllowReboot(virDomainObjPtr vm) +{ + virDomainDefPtr def =3D vm->def; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + if (priv->allowReboot !=3D VIR_TRISTATE_BOOL_ABSENT) + return; + + if (def->onReboot =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && + def->onPoweroff =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && + (def->onCrash =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || + def->onCrash =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY)= ) { + priv->allowReboot =3D VIR_TRISTATE_BOOL_NO; + } else { + priv->allowReboot =3D VIR_TRISTATE_BOOL_YES; + } +} + + /** * qemuProcessPrepareDomain: * @conn: connection object (for looking up storage volumes) @@ -5365,6 +5385,8 @@ qemuProcessPrepareDomain(virConnectPtr conn, priv->chardevStdioLogd =3D true; } =20 + qemuProcessPrepareAllowReboot(vm); + /* * Normally PCI addresses are assigned in the virDomainCreate * or virDomainDefine methods. We might still need to assign @@ -6618,6 +6640,10 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_U= NUSED, =20 priv->gotShutdown =3D false; =20 + /* Attaching to running QEMU so we need to detect whether it was start= ed + * with -no-reboot. */ + qemuProcessPrepareAllowReboot(vm); + /* * Normally PCI addresses are assigned in the virDomainCreate * or virDomainDefine methods. We might still need to assign @@ -6934,6 +6960,10 @@ qemuProcessReconnect(void *opaque) if (qemuDomainMasterKeyReadFile(priv) < 0) goto error; =20 + /* If we are connecting to a guest started by old libvirt there is no + * allowReboot in status XML and we need to initialize it. */ + qemuProcessPrepareAllowReboot(obj); + VIR_DEBUG("Reconnect monitor to %p '%s'", obj, obj->def->name); =20 /* XXX check PID liveliness & EXE path */ diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 14f5b58fe9..2185532a6c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -109,7 +109,8 @@ static const char testStatusXMLPrefixBodyStatic[] =3D "\n" "\n" "\n" -"\n"; +"\n" +"\n"; =20 static const char testStatusXMLSuffix[] =3D "\n"; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list