From nobody Mon Dec 15 09:42:41 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741799972972718.4053189041814; Wed, 12 Mar 2025 10:19:32 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E35ED1CC7; Wed, 12 Mar 2025 13:19:31 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 671D11C39; Wed, 12 Mar 2025 13:18:20 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ED21A1AC5; Wed, 12 Mar 2025 13:18:15 -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 EECBE1A12 for ; Wed, 12 Mar 2025 13:18:14 -0400 (EDT) Received: from mx-prod-mc-03.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-457-arW7pMVFPaqFTUPIEp4Sew-1; Wed, 12 Mar 2025 13:18:13 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 503131954B36 for ; Wed, 12 Mar 2025 17:18:12 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2D41718001D4; Wed, 12 Mar 2025 17:18:10 +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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741799894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l7GOHc8kUHsRjvGZbrlsBwgNghnb5dXSLg23DtFgLYU=; b=WTwd2unM5srWQthNMwloE2gbBkkAMey39yGiNOgh/z0qdCG0DIHG5013FW72blqy/ilVk0 IUzguRQxI+OZRczY/k8SYniusT5rkr++NKnXN3Wwa8RfoKty2eEcPmyitJ6RQG9vYiqC6s TD12h+6hGR7XCiPAQOMa8e1jzpuVE2A= X-MC-Unique: arW7pMVFPaqFTUPIEp4Sew-1 X-Mimecast-MFC-AGG-ID: arW7pMVFPaqFTUPIEp4Sew_1741799892 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v2 05/22] qemu: support automatic VM managed save in system daemon Date: Wed, 12 Mar 2025 17:17:45 +0000 Message-ID: <20250312171802.1854985-6-berrange@redhat.com> In-Reply-To: <20250312171802.1854985-1-berrange@redhat.com> References: <20250312171802.1854985-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VSTRT8oEMCwWgx3cK3ilmVigBcJzHoOHJbswkCVj3Bs_1741799892 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QOEZRZDQ75WTTQF2HKY4FSANGXX26F5S X-Message-ID-Hash: QOEZRZDQ75WTTQF2HKY4FSANGXX26F5S X-MailFrom: berrange@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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1741799975113019100 Content-Type: text/plain; charset="utf-8" Currently automatic VM managed save is only performed in session daemons, on desktop session close, or host OS shutdown request. With this change it is possible to control shutdown behaviour for all daemons. A recommended setup might be: auto_shutdown_try_save =3D "persistent" auto_shutdown_try_shutdown =3D "all" auto_shutdown_poweroff =3D "all" Each setting accepts 'none', 'persistent', 'transient', and 'all' to control what types of guest it applies to. For historical compatibility, for the system daemon, the settings currently default to: auto_shutdown_try_save =3D "none" auto_shutdown_try_shutdown =3D "none" auto_shutdown_poweroff =3D "none" while for the session daemon they currently default to auto_shutdown_try_save =3D "persistent" auto_shutdown_try_shutdown =3D "none" auto_shutdown_poweroff =3D "none" The system daemon settings should NOT be enabled if the traditional libvirt-guests.service is already enabled. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/qemu/libvirtd_qemu.aug | 3 ++ src/qemu/qemu.conf.in | 42 +++++++++++++++++++ src/qemu/qemu_conf.c | 65 ++++++++++++++++++++++++++++++ src/qemu/qemu_conf.h | 4 ++ src/qemu/qemu_driver.c | 9 ++--- src/qemu/test_libvirtd_qemu.aug.in | 3 ++ 6 files changed, 121 insertions(+), 5 deletions(-) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 642093c40b..605604a01a 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -98,6 +98,9 @@ module Libvirtd_qemu =3D | bool_entry "auto_dump_bypass_cache" | bool_entry "auto_start_bypass_cache" | int_entry "auto_start_delay" + | str_entry "auto_shutdown_try_save" + | str_entry "auto_shutdown_try_shutdown" + | str_entry "auto_shutdown_poweroff" =20 let process_entry =3D str_entry "hugetlbfs_mount" | str_entry "bridge_helper" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 31172303dc..a674e11388 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -639,6 +639,48 @@ # #auto_start_delay =3D 0 =20 +# The settings for auto shutdown actions accept one of +# four possible options: +# +# * "none" - do not try to save any running VMs +# * "persistent" - only try to save persistent running VMs +# * "transient" - only try to save transient running VMs +# * "all" - try to save all running VMs +# +# Whether to perform managed save of running VMs if a host OS +# shutdown is requested (system/session daemons), or the desktop +# session terminates (session daemon only). +# +# Defaults to "persistent" for session daemons and "none" +# for system daemons. The values "all" and "transient" are +# not permitted for this setting, since managed save is not +# implemented for transient VMs. +# +# If 'libvirt-guests.service' is enabled, then this must be +# set to 'none' for system daemons to avoid dueling actions +#auto_shutdown_try_save =3D "persistent" + +# As above, but with a graceful shutdown action instead of +# managed save. If managed save is enabled, shutdown will +# be tried only on failure to perform managed save. +# +# Defaults to "none" +# +# If 'libvirt-guests.service' is enabled, then this must be +# set to 'none' for system daemons to avoid dueling actions +#auto_shutdown_try_shutdown =3D "none" + +# As above, but with a forced poweroff instead of managed +# save. If managed save or graceful shutdown are enabled, +# forced poweroff will be tried only on failure of the +# other options. +# +# Defaults to "none" +# +# If 'libvirt-guests.service' is enabled, then this must be +# set to 'none' for system daemons to avoid dueling actions +#auto_shutdown_poweroff =3D "none" + # If provided by the host and a hugetlbfs mount point is configured, # a guest may request huge page backing. When this mount point is # unspecified here, determination of a host mount point in /proc/mounts diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index b376841388..8554558201 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -304,6 +304,21 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privi= leged, cfg->dumpGuestCore =3D true; #endif =20 + if (privileged) { + /* + * Defer to libvirt-guests.service. + * + * XXX, or query if libvirt-guests.service is enabled perhaps ? + */ + cfg->autoShutdownTrySave =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE= _NONE; + cfg->autoShutdownTryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_S= COPE_NONE; + cfg->autoShutdownPoweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOP= E_NONE; + } else { + cfg->autoShutdownTrySave =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE= _PERSISTENT; + cfg->autoShutdownTryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_S= COPE_NONE; + cfg->autoShutdownPoweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOP= E_NONE; + } + return g_steal_pointer(&cfg); } =20 @@ -627,6 +642,8 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *c= fg, g_autofree char *savestr =3D NULL; g_autofree char *dumpstr =3D NULL; g_autofree char *snapstr =3D NULL; + g_autofree char *autoShutdownScope =3D NULL; + int autoShutdownScopeVal; =20 if (virConfGetValueString(conf, "save_image_format", &savestr) < 0) return -1; @@ -663,6 +680,54 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *= cfg, return -1; if (virConfGetValueUInt(conf, "auto_start_delay", &cfg->autoStartDelay= MS) < 0) return -1; + if (virConfGetValueString(conf, "auto_shutdown_try_save", &autoShutdow= nScope) < 0) + return -1; + + if (autoShutdownScope !=3D NULL) { + if ((autoShutdownScopeVal =3D + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownSc= ope)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_try_save '%1$s'"), + autoShutdownScope); + return -1; + } + cfg->autoShutdownTrySave =3D autoShutdownScopeVal; + } + + if (cfg->autoShutdownTrySave =3D=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SC= OPE_ALL || + cfg->autoShutdownTrySave =3D=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SC= OPE_TRANSIENT) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("managed save cannot be requested for transient d= omains")); + return -1; + } + + if (virConfGetValueString(conf, "auto_shutdown_try_shutdown", &autoShu= tdownScope) < 0) + return -1; + + if (autoShutdownScope !=3D NULL) { + if ((autoShutdownScopeVal =3D + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownSc= ope)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_try_shutdown '%1$s'"), + autoShutdownScope); + return -1; + } + cfg->autoShutdownTryShutdown =3D autoShutdownScopeVal; + } + + if (virConfGetValueString(conf, "auto_shutdown_poweroff", &autoShutdow= nScope) < 0) + return -1; + + if (autoShutdownScope !=3D NULL) { + if ((autoShutdownScopeVal =3D + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownSc= ope)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_poweroff '%1$s'"), + autoShutdownScope); + return -1; + } + cfg->autoShutdownPoweroff =3D autoShutdownScopeVal; + } =20 return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 3e1b41af73..3450f277f0 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -43,6 +43,7 @@ #include "virfilecache.h" #include "virfirmware.h" #include "virinhibitor.h" +#include "domain_driver.h" =20 #define QEMU_DRIVER_NAME "QEMU" =20 @@ -201,6 +202,9 @@ struct _virQEMUDriverConfig { bool autoDumpBypassCache; bool autoStartBypassCache; unsigned int autoStartDelayMS; + virDomainDriverAutoShutdownScope autoShutdownTrySave; + virDomainDriverAutoShutdownScope autoShutdownTryShutdown; + virDomainDriverAutoShutdownScope autoShutdownPoweroff; =20 char *lockManagerName; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ec389453e7..cb7b03e391 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -947,13 +947,12 @@ qemuStateStop(void) g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(qemu_dri= ver); virDomainDriverAutoShutdownConfig ascfg =3D { .uri =3D cfg->uri, - .trySave =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_PERSISTENT, - .tryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE, - .poweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE + .trySave =3D cfg->autoShutdownTrySave, + .tryShutdown =3D cfg->autoShutdownTryShutdown, + .poweroff =3D cfg->autoShutdownPoweroff, }; =20 - if (!qemu_driver->privileged) - virDomainDriverAutoShutdown(&ascfg); + virDomainDriverAutoShutdown(&ascfg); =20 return 0; } diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index c2a1d7d829..bb216483a7 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -76,6 +76,9 @@ module Test_libvirtd_qemu =3D { "auto_dump_bypass_cache" =3D "0" } { "auto_start_bypass_cache" =3D "0" } { "auto_start_delay" =3D "0" } +{ "auto_shutdown_try_save" =3D "persistent" } +{ "auto_shutdown_try_shutdown" =3D "none" } +{ "auto_shutdown_poweroff" =3D "none" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } { "set_process_name" =3D "1" } --=20 2.48.1