From nobody Tue Jan 21 07:35:47 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 1736365728144634.4491717120402; Wed, 8 Jan 2025 11:48:48 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2BF6A1518; Wed, 8 Jan 2025 14:48:47 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4DF3F1402; Wed, 8 Jan 2025 14:43:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 12944143C; Wed, 8 Jan 2025 14:43:44 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 A9EB8144E for ; Wed, 8 Jan 2025 14:43:16 -0500 (EST) Received: from mx-prod-mc-05.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-520-9PjpF46gNB6ZvkJfA7zQAQ-1; Wed, 08 Jan 2025 14:43:14 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 06BD51953972 for ; Wed, 8 Jan 2025 19:43:14 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.103]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2CEF9300018D; Wed, 8 Jan 2025 19:43:12 +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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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=1736365396; 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=CSAfX6JAUUlsP4gAHRpRdLSz1GapVyIBFXxqk8pJ5m4=; b=ZnoJeUSZF/Xo1RKIltxTVsER7S30D0yzTU+Eo8kIWoFXLZxpK26olVYmWmAWaK8V3IF99d d45PFr0Gr37G6PUCYKY+M/UnTtZ5NAKUdm/gElEjzJprh33OqYSFT0gLX04IGwGRP7YTqq GibHyGM7AxOlxdULk+Mk9k/rCqk52sQ= X-MC-Unique: 9PjpF46gNB6ZvkJfA7zQAQ-1 X-Mimecast-MFC-AGG-ID: 9PjpF46gNB6ZvkJfA7zQAQ 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 10/26] hypervisor: custom shutdown actions for transient vs persistent VMs Date: Wed, 8 Jan 2025 19:42:43 +0000 Message-ID: <20250108194259.1171990-11-berrange@redhat.com> In-Reply-To: <20250108194259.1171990-1-berrange@redhat.com> References: <20250108194259.1171990-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DihwUwp3xDknsmy5tGmx0Zkbw3gz7e_9LmsdZgd8SdM_1736365394 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4J7UZLULLJTE3AYVUBRLSJID62HNU6UA X-Message-ID-Hash: 4J7UZLULLJTE3AYVUBRLSJID62HNU6UA 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: 1736365731682116600 Content-Type: text/plain; charset="utf-8" It may be desirable to treat transient VMs differently from persistent VMs. For example, while performing managed save on persistent VMs makes sense, the same not usually true of transient VMs, since by their nature they will have no config to restore from. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 46 +++++++++++++++++++++++++++++++--- src/hypervisor/domain_driver.h | 18 ++++++++++--- src/libvirt_private.syms | 2 ++ src/qemu/qemu_driver.c | 6 ++--- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index ea3f1cbfcd..4fecaf7e5c 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -35,6 +35,13 @@ =20 VIR_LOG_INIT("hypervisor.domain_driver"); =20 +VIR_ENUM_IMPL(virDomainDriverAutoShutdownScope, + VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_LAST, + "none", + "persistent", + "transient", + "all"); + char * virDomainDriverGenerateRootHash(const char *drivername, const char *root) @@ -715,6 +722,7 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) int numDomains =3D 0; size_t i; virDomainPtr *domains =3D NULL; + g_autofree bool *transient =3D NULL; =20 VIR_DEBUG("Run autoshutdown uri=3D%s trySave=3D%d tryShutdown=3D%d pow= eroff=3D%d" "waitShutdownSecs=3D%d", @@ -735,6 +743,12 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdow= nConfig *cfg) if (cfg->waitShutdownSecs <=3D 0) cfg->waitShutdownSecs =3D 30; =20 + /* Short-circuit if all actions are disabled */ + if (cfg->trySave =3D=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE && + cfg->tryShutdown =3D=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE= && + cfg->poweroff =3D=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) + return; + if (!(conn =3D virConnectOpen(cfg->uri))) goto cleanup; =20 @@ -744,10 +758,22 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdo= wnConfig *cfg) goto cleanup; =20 VIR_DEBUG("Auto shutdown with %d running domains", numDomains); - if (cfg->trySave) { + + transient =3D g_new0(bool, numDomains); + for (i =3D 0; i < numDomains; i++) { + if (virDomainIsPersistent(domains[i]) =3D=3D 0) + transient[i] =3D true; + } + + if (cfg->trySave !=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) { g_autofree unsigned int *flags =3D g_new0(unsigned int, numDomains= ); for (i =3D 0; i < numDomains; i++) { int state; + + if ((transient[i] && cfg->trySave =3D=3D VIR_DOMAIN_DRIVER_AUT= O_SHUTDOWN_SCOPE_PERSISTENT) || + (!transient[i] && cfg->trySave =3D=3D VIR_DOMAIN_DRIVER_AU= TO_SHUTDOWN_SCOPE_TRANSIENT)) + continue; + /* * Pause all VMs to make them stop dirtying pages, * so save is quicker. We remember if any VMs were @@ -773,11 +799,16 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdo= wnConfig *cfg) } } =20 - if (cfg->tryShutdown) { + if (cfg->tryShutdown !=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) { GTimer *timer =3D NULL; for (i =3D 0; i < numDomains; i++) { if (domains[i] =3D=3D NULL) continue; + + if ((transient[i] && cfg->tryShutdown =3D=3D VIR_DOMAIN_DRIVER= _AUTO_SHUTDOWN_SCOPE_PERSISTENT) || + (!transient[i] && cfg->tryShutdown =3D=3D VIR_DOMAIN_DRIVE= R_AUTO_SHUTDOWN_SCOPE_TRANSIENT)) + continue; + if (virDomainShutdown(domains[i]) < 0) { VIR_WARN("Unable to perform graceful shutdown of '%s': %s", virDomainGetName(domains[i]), @@ -793,6 +824,10 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdow= nConfig *cfg) if (!domains[i]) continue; =20 + if ((transient[i] && cfg->tryShutdown =3D=3D VIR_DOMAIN_DR= IVER_AUTO_SHUTDOWN_SCOPE_PERSISTENT) || + (!transient[i] && cfg->tryShutdown =3D=3D VIR_DOMAIN_D= RIVER_AUTO_SHUTDOWN_SCOPE_TRANSIENT)) + continue; + if (virDomainIsActive(domains[i]) =3D=3D 1) { anyRunning =3D true; } else { @@ -810,10 +845,15 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdo= wnConfig *cfg) g_timer_destroy(timer); } =20 - if (cfg->poweroff) { + if (cfg->poweroff !=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) { for (i =3D 0; i < numDomains; i++) { if (domains[i] =3D=3D NULL) continue; + + if ((transient[i] && cfg->poweroff =3D=3D VIR_DOMAIN_DRIVER_AU= TO_SHUTDOWN_SCOPE_PERSISTENT) || + (!transient[i] && cfg->poweroff =3D=3D VIR_DOMAIN_DRIVER_A= UTO_SHUTDOWN_SCOPE_TRANSIENT)) + continue; + virDomainDestroy(domains[i]); } } diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 25c4b0c664..acb7a41b5d 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -24,6 +24,7 @@ #include "virhostdev.h" #include "virpci.h" #include "virdomainobjlist.h" +#include "virenum.h" =20 char * virDomainDriverGenerateRootHash(const char *drivername, @@ -90,11 +91,22 @@ typedef struct _virDomainDriverAutoStartConfig { void virDomainDriverAutoStart(virDomainObjList *domains, virDomainDriverAutoStartConfig *cfg); =20 +typedef enum { + VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE, + VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_PERSISTENT, + VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_TRANSIENT, + VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_ALL, + + VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_LAST, +} virDomainDriverAutoShutdownScope; + +VIR_ENUM_DECL(virDomainDriverAutoShutdownScope); + typedef struct _virDomainDriverAutoShutdownConfig { const char *uri; - bool trySave; - bool tryShutdown; - bool poweroff; + virDomainDriverAutoShutdownScope trySave; + virDomainDriverAutoShutdownScope tryShutdown; + virDomainDriverAutoShutdownScope poweroff; int waitShutdownSecs; } virDomainDriverAutoShutdownConfig; =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 781bb566d2..301240452d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1641,6 +1641,8 @@ virDomainCgroupSetupVcpuBW; # hypervisor/domain_driver.h virDomainDriverAddIOThreadCheck; virDomainDriverAutoShutdown; +virDomainDriverAutoShutdownScopeTypeFromString; +virDomainDriverAutoShutdownScopeTypeToString; virDomainDriverAutoStart; virDomainDriverDelIOThreadCheck; virDomainDriverGenerateMachineName; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2c97a6fb98..8e15a77be2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -947,9 +947,9 @@ qemuStateStop(void) g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(qemu_dri= ver); virDomainDriverAutoShutdownConfig ascfg =3D { .uri =3D cfg->uri, - .trySave =3D true, - .tryShutdown =3D false, - .poweroff =3D false, + .trySave =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_ALL, + .tryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE, + .poweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE }; =20 if (!qemu_driver->privileged) --=20 2.47.1