From nobody Sun Dec 14 06:37:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1751547246; cv=none; d=zohomail.com; s=zohoarc; b=b5g3tzrRRzQJ9JTj99U3TOMlRpwF8AdE+0UwtZ+stbBskg0Z5xD/mIDdnXStm6mpZ8Wi5ipTQRs5QdDAVevHXeGl+/gFlql8cjZq7epH4ZtrmG8zE3oC5QLzX3Jp8b8JT5yEkXKljI4UvMRvnQ2iyyZvzfSK1PCYBkHcdipduXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751547246; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=a1af8Nu/ynFi8wKOnasn9q0cbgPqLCy1mSTv2hQMCgs=; b=fYhIAliox7QYywFlbMcS6cgEjRcEArMcwt6ZLgPoLHa1g/sqokWSwxXA1j7KvmDkz8ua/WgGYxGFWe7pW02gz4gDlGjen9Xd9gsAh9TYQCs1otN/DnYy6Pt/2NY9H6S3PmWIhqmmiD3O3JQbkoES4lv8hOB6EwiAmtVUPrR/s5g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 175154724689649.557806220674934; Thu, 3 Jul 2025 05:54:06 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D91A6973; Thu, 3 Jul 2025 08:54:05 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DCF08130D; Thu, 3 Jul 2025 08:51:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 30F0D1268; Thu, 3 Jul 2025 08:51:01 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 773D212C9 for ; Thu, 3 Jul 2025 08:50:47 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-qHYaXS6eNIKFzmryLPRi2w-1; Thu, 03 Jul 2025 08:50:45 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 24F241979057 for ; Thu, 3 Jul 2025 12:50:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EAA4195608F for ; Thu, 3 Jul 2025 12:50:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: ** X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751547047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7WF+019XT5VibaUPnIS+kw9OaEF5qFkTamTMirF4cD8=; b=arCW0dFRx1LEg+cbT5Qm828W628Trs8h4IFJaITmgtBm7jlzhYntd3/jvK1Qu3snxk4G/h RR0LW1o9FFsYhFXN4fCyGrlHOM2P6gvpkbetbgOQbYqrSo1C8zXsWjU3LoCQPG3Y42Ut3Q 6/1bhAAFgwAcykuaqLzffOEv+CP2hJc= X-MC-Unique: qHYaXS6eNIKFzmryLPRi2w-1 X-Mimecast-MFC-AGG-ID: qHYaXS6eNIKFzmryLPRi2w_1751547045 To: devel@lists.libvirt.org Subject: [PATCH 07/10] qemu: Fix auto-shutdown of qemu VMs by the qemu driver Date: Thu, 3 Jul 2025 14:50:30 +0200 Message-ID: <8e2f59d9d78f5cae2a98f8b179ee1e29accd760d.1751546915.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BQg7HQ5_0mE7Lg1onhoL-E_QxaIqHCh_aSOQo7tqNzo_1751547045 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: X34AGBABJHQHR3KBF7LD3BBHMGCT7ZXC X-Message-ID-Hash: X34AGBABJHQHR3KBF7LD3BBHMGCT7ZXC X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751547247473116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa When auto-shutdown via the qemu driver is requested (rather than via libvirt guests) we need to start the VMs in a way that they will be kept around for libvirt to terminate them. This involves inverting the dependancy relationship for the machined unit file. Since the setup is done at startup of the VM, add a disclaimer to qemu.conf that switching between the two modes with VMs running will not work properly. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu.conf.in | 15 ++++++++++++++- src/qemu/qemu_cgroup.c | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 221bfa8095..6358a45ae2 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -663,7 +663,10 @@ # implemented for transient VMs. # # If 'libvirt-guests.service' is enabled, then this must be -# set to 'none' for system daemons to avoid dueling actions +# set to 'none' for system daemons to avoid dueling actions. +# Warning: Switching between 'libvirt-guests.service' and this option +# causes VMs running at that point to misbehave on host shutdown unless +# they are restarted, or saved and restored. #auto_shutdown_try_save =3D "persistent" # As above, but with a graceful shutdown action instead of @@ -675,6 +678,9 @@ # # If 'libvirt-guests.service' is enabled, then this must be # set to 'none' for system daemons to avoid dueling actions +# Warning: Switching between 'libvirt-guests.service' and this option +# causes VMs running at that point to misbehave on host shutdown unless +# they are restarted, or saved and restored. #auto_shutdown_try_shutdown =3D "all" # As above, but with a forced poweroff instead of managed @@ -687,6 +693,13 @@ # # If 'libvirt-guests.service' is enabled, then this must be # set to 'none' for system daemons to avoid dueling actions +# +# Warning: Switching between 'libvirt-guests.service' and this option +# causes VMs running at that point to misbehave on host shutdown unless +# they are restarted, or saved and restored. +# +# When using any 'auto_shutdown_try_save', 'auto_shutdown_try_shutdown' th= is +# feature should to be enabled as well to ensure proper cleanup of the VMs. #auto_shutdown_poweroff =3D "all" # How may seconds to wait for running VMs to gracefully shutdown diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 04d6370011..25e42ebfc6 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -910,6 +910,12 @@ qemuSetupCgroup(virDomainObj *vm, { qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); + /* When users wants to auto-shutdown the VMs via the qemu daemon itself + * we need to instruct machined to create dependencies for the units + * in such way that the VMs will not be killed before the auto shutdown + * code is reached. + */ + bool daemonAutoShutdown =3D virDomainDriverAutoShutdownActive(&cfg->au= toShutdown); if (virDomainCgroupSetupCgroup("qemu", vm, @@ -919,7 +925,7 @@ qemuSetupCgroup(virDomainObj *vm, cfg->cgroupControllers, cfg->maxThreadsPerProc, priv->driver->privileged, - false, + daemonAutoShutdown, priv->machineName) < 0) return -1; --=20 2.49.0