From nobody Tue Jan 21 04:01:21 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 1736365484305516.3819342636419; Wed, 8 Jan 2025 11:44:44 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 428601485; Wed, 8 Jan 2025 14:44:43 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AF946138F; Wed, 8 Jan 2025 14:43:14 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 99E4912BA; Wed, 8 Jan 2025 14:43:07 -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 1C90112A6 for ; Wed, 8 Jan 2025 14:43:07 -0500 (EST) Received: from mx-prod-mc-02.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-690-X5ySxZzgP2ypBDzY2jPmTQ-1; Wed, 08 Jan 2025 14:43:03 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A193219560B3 for ; Wed, 8 Jan 2025 19:43:02 +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 C7BD4300018D; Wed, 8 Jan 2025 19:43:01 +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=1736365386; 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=EmQRX7Zl6FQWPQGPXTo2EZEXPAOJRYei2sHVU5WUyIk=; b=Y/twoTlRlZNVDCloD/oCJ3MCRwadzXYuy1LMSlP3INBxLVKDQIU6qygN04TAqVM9d/3lD3 4YOVBq41FhUWlQIXWjojKRHBGAmpBv3JEsqzMtteRI/q+T+XI3sEcMA0riwmjw8jor1pUM W51eC8HZfdevLxk5WlP3cWv08wdeNZI= X-MC-Unique: X5ySxZzgP2ypBDzY2jPmTQ-1 X-Mimecast-MFC-AGG-ID: X5ySxZzgP2ypBDzY2jPmTQ 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 01/26] util: add APIs for more systemd notifications Date: Wed, 8 Jan 2025 19:42:34 +0000 Message-ID: <20250108194259.1171990-2-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: 311s1b5nJ2SQDR9VYcqFpRynChRM50bIdjmUGK5nZ3I_1736365382 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LW5BE5NEJDNAT6S2WR55CIPS7DMZXY64 X-Message-ID-Hash: LW5BE5NEJDNAT6S2WR55CIPS7DMZXY64 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: 1736365486555116600 Content-Type: text/plain; charset="utf-8" We have a way to notify systemd when we're done starting the daemon. Systemd supports many more notifications, however, and many of them are quite relevant to our needs: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html This renames the existing notification API to better reflect its semantics, and adds new APIs for reporting * Initiation of config file reload * Initiation of daemon shutdown process * Adhoc progress status messages * Request to extend service shutdown timeout Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 6 +++++- src/rpc/virnetdaemon.c | 2 +- src/util/virsystemd.c | 41 +++++++++++++++++++++++++++++++++++++--- src/util/virsystemd.h | 6 +++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 33b93cbd3e..d0c116b78c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3524,7 +3524,11 @@ virSystemdHasResolved; virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; -virSystemdNotifyStartup; +virSystemdNotifyExtendTimeout; +virSystemdNotifyReady; +virSystemdNotifyReload; +virSystemdNotifyStatus; +virSystemdNotifyStopping; virSystemdResolvedRegisterNameServer; virSystemdTerminateMachine; =20 diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index e4c6261536..bb7d2ff9a0 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -749,7 +749,7 @@ virNetDaemonRun(virNetDaemon *dmn) =20 /* We are accepting connections now. Notify systemd * so it can start dependent services. */ - virSystemdNotifyStartup(); + virSystemdNotifyReady(); =20 VIR_DEBUG("dmn=3D%p quit=3D%d", dmn, dmn->quit); while (!dmn->finished) { diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 5b772e29dd..2c09b9ab2b 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -624,12 +624,11 @@ int virSystemdTerminateMachine(const char *name) return 0; } =20 -void -virSystemdNotifyStartup(void) +static void +virSystemdNotify(const char *msg) { #ifndef WIN32 const char *path; - const char *msg =3D "READY=3D1"; int fd; struct sockaddr_un un =3D { .sun_family =3D AF_UNIX, @@ -644,6 +643,8 @@ virSystemdNotifyStartup(void) .msg_iovlen =3D 1, }; =20 + VIR_DEBUG("Notify '%s'", msg); + if (!(path =3D getenv("NOTIFY_SOCKET"))) { VIR_DEBUG("Skipping systemd notify, not requested"); return; @@ -674,6 +675,40 @@ virSystemdNotifyStartup(void) #endif /* !WIN32 */ } =20 +void virSystemdNotifyReady(void) +{ + virSystemdNotify("READY=3D1"); +} + +void virSystemdNotifyReload(void) +{ + virSystemdNotify("RELOAD=3D1"); +} + +void virSystemdNotifyStopping(void) +{ + virSystemdNotify("STOPPING=3D1"); +} + +void virSystemdNotifyExtendTimeout(int secs) +{ + g_autofree char *msg =3D g_strdup_printf("EXTEND_TIMEOUT_USEC=3D%llu", + secs * 1000ull * 1000ul); + virSystemdNotify(msg); +} + +void virSystemdNotifyStatus(const char *fmt, ...) +{ + g_autofree char *msg1 =3D NULL; + g_autofree char *msg2 =3D NULL; + va_list ap; + va_start(ap, fmt); + msg1 =3D g_strdup_vprintf(fmt, ap); + va_end(ap); + msg2 =3D g_strdup_printf("STATUS=3D%s", msg1); + virSystemdNotify(msg2); +} + static int virSystemdPMSupportTarget(const char *methodName, bool *result) { diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index b7fdaf67df..98460dbc3a 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -44,7 +44,11 @@ int virSystemdCreateMachine(const char *name, =20 int virSystemdTerminateMachine(const char *name); =20 -void virSystemdNotifyStartup(void); +void virSystemdNotifyReady(void); +void virSystemdNotifyReload(void); +void virSystemdNotifyStopping(void); +void virSystemdNotifyExtendTimeout(int secs); +void virSystemdNotifyStatus(const char *fmt, ...) G_GNUC_PRINTF(1, 2); =20 int virSystemdHasMachined(void); =20 --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 173636545246296.42215831444241; Wed, 8 Jan 2025 11:44:12 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 696A412A6; Wed, 8 Jan 2025 14:44:11 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CDDB21437; Wed, 8 Jan 2025 14:43:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C063D1287; Wed, 8 Jan 2025 14:43:06 -0500 (EST) 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 4A7F712A6 for ; Wed, 8 Jan 2025 14:43:06 -0500 (EST) Received: from mx-prod-mc-01.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-425-77qx8gazNUahAS6Whso7eg-1; Wed, 08 Jan 2025 14:43:04 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0248D195606B for ; Wed, 8 Jan 2025 19:43:04 +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 13AF03000199; Wed, 8 Jan 2025 19:43:02 +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_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=1736365386; 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=Q3i4u7b9HyqUknQCcUP0RelwFYUkEyxrzyUF6CFj1Hc=; b=QofY2GPhWNJLBdWa1nUq36HFEfECeIh7LnraWiCf3CpQdZZVUyyq7zadB1sCVgNMH9iBGt 38V/E/torH2RPY7+KdspmSjg6M9hwTk+qP+Ui+V4MEln5as5F9RMp9CkLg8OztPodiuG72 60M6N88VuwLF59337ibpigLS5msv8Nw= X-MC-Unique: 77qx8gazNUahAS6Whso7eg-1 X-Mimecast-MFC-AGG-ID: 77qx8gazNUahAS6Whso7eg 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 02/26] remote: notify systemd when reloading config Date: Wed, 8 Jan 2025 19:42:35 +0000 Message-ID: <20250108194259.1171990-3-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: OoN0rf7Zdi_NAPgfhm5UqT5Ve58ImvldjWploVmCXDQ_1736365384 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 24IJBDFL5YTDOSRENV3VI3EYCJLUGATK X-Message-ID-Hash: 24IJBDFL5YTDOSRENV3VI3EYCJLUGATK 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: 1736365454310116600 Content-Type: text/plain; charset="utf-8" Switch to the 'notify-reload' service type and send notifications to systemd when reloading configuration. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/libvirtd.service.in | 2 +- src/remote/remote_daemon.c | 2 ++ src/virtd.service.in | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/remote/libvirtd.service.in b/src/remote/libvirtd.service.in index 250b4a6fc3..b0a062e885 100644 --- a/src/remote/libvirtd.service.in +++ b/src/remote/libvirtd.service.in @@ -26,7 +26,7 @@ After=3Dxencommons.service Conflicts=3Dxendomains.service =20 [Service] -Type=3Dnotify +Type=3Dnotify-reload Environment=3DLIBVIRTD_ARGS=3D"--timeout 120" EnvironmentFile=3D-@initconfdir@/libvirtd ExecStart=3D@sbindir@/libvirtd $LIBVIRTD_ARGS diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 1d079c7e4b..d44a365000 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -452,9 +452,11 @@ static void daemonReloadHandlerThread(void *opaque G_G= NUC_UNUSED) virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL, NULL); =20 + virSystemdNotifyReload(); if (virStateReload() < 0) { VIR_WARN("Error while reloading drivers"); } + virSystemdNotifyReady(); =20 /* Drivers are initialized again. */ g_atomic_int_set(&driversInitialized, 1); diff --git a/src/virtd.service.in b/src/virtd.service.in index 651a8d82d7..7ffb77e339 100644 --- a/src/virtd.service.in +++ b/src/virtd.service.in @@ -15,7 +15,7 @@ After=3Ddbus.service After=3Dapparmor.service =20 [Service] -Type=3Dnotify +Type=3Dnotify-reload Environment=3D@SERVICE@_ARGS=3D"--timeout 120" EnvironmentFile=3D-@initconfdir@/@service@ ExecStart=3D@sbindir@/@service@ $@SERVICE@_ARGS --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365522560856.9576509016429; Wed, 8 Jan 2025 11:45:22 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7EDC41453; Wed, 8 Jan 2025 14:45:21 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E7A4A13D0; Wed, 8 Jan 2025 14:43:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 91D621311; Wed, 8 Jan 2025 14:43:08 -0500 (EST) 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 0D76A1287 for ; Wed, 8 Jan 2025 14:43:08 -0500 (EST) Received: from mx-prod-mc-01.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-3-ps-cwSc1NyiAKVMQMwLSYQ-1; Wed, 08 Jan 2025 14:43:06 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3909819560BD for ; Wed, 8 Jan 2025 19:43:05 +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 5BEB5300018D; Wed, 8 Jan 2025 19:43:04 +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_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=1736365387; 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=AKaQMqoLk8ek2aQNBwYybLUxR/CuWpezCQ7goajjzgk=; b=agrrTIECCZe0zt/jJya1HN+bnP3RL5+qqe9hMY8k3PFG50OLKuINjeoxxDAOYIyt9ol7FZ W1Ru94NdlSVitZBbIcGs8BvruRnp16TFQxk2Z5S/SFo9uM9F2+aNI56fQXAtprTswFX1W3 v3+c2c7wy2RelfAcrVRxldZEgBEEw54= X-MC-Unique: ps-cwSc1NyiAKVMQMwLSYQ-1 X-Mimecast-MFC-AGG-ID: ps-cwSc1NyiAKVMQMwLSYQ 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 03/26] hypervisor: introduce helper for autostart Date: Wed, 8 Jan 2025 19:42:36 +0000 Message-ID: <20250108194259.1171990-4-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: lvuiq76-ju4PFgINKmmFtdiEMfY-fIX_kmPpyq0-cMk_1736365385 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LDNWJYAVLCE2NE3LVTSOZOCWT2UN6XZS X-Message-ID-Hash: LDNWJYAVLCE2NE3LVTSOZOCWT2UN6XZS 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: 1736365524663116600 Content-Type: text/plain; charset="utf-8" There's a common pattern for autostart of iterating over VMs, acquiring a lock and ref count, then checking the autostart & is-active flags. Wrap this all up into a helper method. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 40 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 17 +++++++++++++++ src/libvirt_private.syms | 1 + 3 files changed, 58 insertions(+) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 85d68b056c..c5b082fd00 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -29,9 +29,12 @@ #include "viraccessapicheck.h" #include "datatypes.h" #include "driver.h" +#include "virlog.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 +VIR_LOG_INIT("hypervisor.domain_driver"); + char * virDomainDriverGenerateRootHash(const char *drivername, const char *root) @@ -652,3 +655,40 @@ virDomainDriverGetIOThreadsConfig(virDomainDef *target= Def, =20 return ret; } + +static int +virDomainDriverAutoStartOne(virDomainObj *vm, + void *opaque) +{ + virDomainDriverAutoStartConfig *cfg =3D opaque; + + virObjectLock(vm); + virObjectRef(vm); + + VIR_DEBUG("Autostart %s: autostart=3D%d", + vm->def->name, vm->autostart); + + if (vm->autostart && !virDomainObjIsActive(vm)) { + virResetLastError(); + cfg->callback(vm, cfg->opaque); + } + + virDomainObjEndAPI(&vm); + virResetLastError(); + + return 0; +} + +void virDomainDriverAutoStart(virDomainObjList *domains, + virDomainDriverAutoStartConfig *cfg) +{ + bool autostart; + VIR_DEBUG("Run autostart stateDir=3D%s", cfg->stateDir); + if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0 || + !autostart) { + VIR_DEBUG("Autostart already processed"); + return; + } + + virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, c= fg); +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 9942f58fda..c27ed9155e 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -23,6 +23,7 @@ #include "node_device_conf.h" #include "virhostdev.h" #include "virpci.h" +#include "virdomainobjlist.h" =20 char * virDomainDriverGenerateRootHash(const char *drivername, @@ -71,3 +72,19 @@ int virDomainDriverDelIOThreadCheck(virDomainDef *def, int virDomainDriverGetIOThreadsConfig(virDomainDef *targetDef, virDomainIOThreadInfoPtr **info, unsigned int bitmap_size); + +/* + * Will be called with 'vm' locked and ref count held, + * which will be released when this returns. + */ +typedef void (*virDomainDriverAutoStartCallback)(virDomainObj *vm, + void *opaque); + +typedef struct _virDomainDriverAutoStartConfig { + char *stateDir; + virDomainDriverAutoStartCallback callback; + void *opaque; +} virDomainDriverAutoStartConfig; + +void virDomainDriverAutoStart(virDomainObjList *domains, + virDomainDriverAutoStartConfig *cfg); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d0c116b78c..d90b15e215 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1640,6 +1640,7 @@ virDomainCgroupSetupVcpuBW; =20 # hypervisor/domain_driver.h virDomainDriverAddIOThreadCheck; +virDomainDriverAutoStart; virDomainDriverDelIOThreadCheck; virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365559995259.93029803585523; Wed, 8 Jan 2025 11:45:59 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0EE861489; Wed, 8 Jan 2025 14:45:59 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 54236146C; Wed, 8 Jan 2025 14:43:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id AB24413B7; Wed, 8 Jan 2025 14:43:18 -0500 (EST) 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 B0ED0136C for ; Wed, 8 Jan 2025 14:43:08 -0500 (EST) 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-689-bFtWM42VOguGsb-9lIu00w-1; Wed, 08 Jan 2025 14:43:07 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 821091944D05 for ; Wed, 8 Jan 2025 19:43:06 +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 9441B3000199; Wed, 8 Jan 2025 19:43:05 +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_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=1736365388; 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=IizBvRB5aGXEAqvCKP0/MySTjxHEoYQUcAfXJjjuoLg=; b=GtD1qMr8Q8t+2F7G7lNq+D4/m/RM1cf4X+XLl2z+xd7J2jvm12i79VdXJa8N3k5KHsZm81 neoQhu/fnSqITSd4hB0r4dsbNaTWiYQUy1a5u5BRCLsSa6YipMNEMVSyihCEAsJ2/y4VSa ZApc0Ck9xe0+sK/UL73zLHeI6g/A2To= X-MC-Unique: bFtWM42VOguGsb-9lIu00w-1 X-Mimecast-MFC-AGG-ID: bFtWM42VOguGsb-9lIu00w 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 04/26] src: convert drivers over to use new autostart helper Date: Wed, 8 Jan 2025 19:42:37 +0000 Message-ID: <20250108194259.1171990-5-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: UJgY3nyiGLHs8n6nTNXJ0P-WEoFfycs6eGVGPMdDLNs_1736365386 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VG3QU36B2Y5KTQAKL5HAXLFDPZOXE6BB X-Message-ID-Hash: VG3QU36B2Y5KTQAKL5HAXLFDPZOXE6BB 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: 1736365560717116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_driver.c | 53 ++++++++++++--------------------------- src/libxl/libxl_driver.c | 36 ++++++++------------------- src/lxc/lxc_driver.c | 13 +++++----- src/lxc/lxc_process.c | 18 ++------------ src/lxc/lxc_process.h | 2 ++ src/qemu/qemu_driver.c | 54 ++++++++++++---------------------------- 6 files changed, 53 insertions(+), 123 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 8f97ac032c..ec997a38f5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -71,41 +71,19 @@ VIR_LOG_INIT("bhyve.bhyve_driver"); struct _bhyveConn *bhyve_driver =3D NULL; =20 static int -bhyveAutostartDomain(virDomainObj *vm, void *opaque) +bhyveAutostartDomain(virDomainObj *vm, void *opaque G_GNUC_UNUSED) { - const struct bhyveAutostartData *data =3D opaque; int ret =3D 0; - VIR_LOCK_GUARD lock =3D virObjectLockGuard(vm); - - if (vm->autostart && !virDomainObjIsActive(vm)) { - virResetLastError(); - ret =3D virBhyveProcessStart(data->conn, vm, - VIR_DOMAIN_RUNNING_BOOTED, 0); - if (ret < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to autostart VM '%1$s': %2$s"), - vm->def->name, virGetLastErrorMessage()); - } - } - return ret; -} - -static void -bhyveAutostartDomains(struct _bhyveConn *driver) -{ - /* XXX: Figure out a better way todo this. The domain - * startup code needs a connection handle in order - * to lookup the bridge associated with a virtual - * network - */ - virConnectPtr conn =3D virConnectOpen("bhyve:///system"); - /* Ignoring NULL conn which is mostly harmless here */ =20 - struct bhyveAutostartData data =3D { driver, conn }; - - virDomainObjListForEach(driver->domains, false, bhyveAutostartDomain, = &data); + ret =3D virBhyveProcessStart(NULL, vm, + VIR_DOMAIN_RUNNING_BOOTED, 0); + if (ret < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to autostart VM '%1$s': %2$s"), + vm->def->name, virGetLastErrorMessage()); + } =20 - virObjectUnref(conn); + return ret; } =20 /** @@ -1181,7 +1159,7 @@ bhyveStateInitialize(bool privileged, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { - bool autostart =3D true; + virDomainDriverAutoStartConfig autostartCfg; =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -1266,11 +1244,12 @@ bhyveStateInitialize(bool privileged, =20 virBhyveProcessReconnectAll(bhyve_driver); =20 - if (virDriverShouldAutostart(BHYVE_STATE_DIR, &autostart) < 0) - goto cleanup; - - if (autostart) - bhyveAutostartDomains(bhyve_driver); + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D BHYVE_STATE_DIR, + .callback =3D bhyveAutostartDomain, + .opaque =3D bhyve_driver, + }; + virDomainDriverAutoStart(bhyve_driver->domains, &autostartCfg); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 494b1ad9bc..b6e17b47de 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -315,36 +315,22 @@ libxlDomObjFromDomain(virDomainPtr dom) return vm; } =20 -static int +static void libxlAutostartDomain(virDomainObj *vm, void *opaque) { libxlDriverPrivate *driver =3D opaque; - int ret =3D -1; - - virObjectRef(vm); - virObjectLock(vm); - virResetLastError(); =20 if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) - goto cleanup; + return; =20 - if (vm->autostart && !virDomainObjIsActive(vm) && - libxlDomainStartNew(driver, vm, false) < 0) { + if (libxlDomainStartNew(driver, vm, false) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart VM '%1$s': %2$s"), vm->def->name, virGetLastErrorMessage()); - goto endjob; } =20 - ret =3D 0; - - endjob: virDomainObjEndJob(vm); - cleanup: - virDomainObjEndAPI(&vm); - - return ret; } =20 =20 @@ -654,7 +640,7 @@ libxlStateInitialize(bool privileged, { libxlDriverConfig *cfg; g_autofree char *driverConf =3D NULL; - bool autostart =3D true; + virDomainDriverAutoStartConfig autostartCfg; =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -807,14 +793,12 @@ libxlStateInitialize(bool privileged, NULL, NULL) < 0) goto error; =20 - if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) - goto error; - - if (autostart) { - virDomainObjListForEach(libxl_driver->domains, false, - libxlAutostartDomain, - libxl_driver); - } + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D cfg->stateDir, + .callback =3D libxlAutostartDomain, + .opaque =3D libxl_driver, + }; + virDomainDriverAutoStart(libxl_driver->domains, &autostartCfg); =20 virDomainObjListForEach(libxl_driver->domains, false, libxlDomainManagedSaveLoad, diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4740aeed52..e63732dbea 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1402,8 +1402,8 @@ lxcStateInitialize(bool privileged, void *opaque) { virLXCDriverConfig *cfg =3D NULL; - bool autostart =3D true; const char *defsecmodel; + virDomainDriverAutoStartConfig autostartCfg; =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -1499,11 +1499,12 @@ lxcStateInitialize(bool privileged, NULL, NULL) < 0) goto cleanup; =20 - if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) - goto cleanup; - - if (autostart) - virLXCProcessAutostartAll(lxc_driver); + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D cfg->stateDir, + .callback =3D virLXCProcessAutostartDomain, + .opaque =3D NULL, + }; + virDomainDriverAutoStart(lxc_driver->domains, &autostartCfg); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index c2982244f0..4e152c193c 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1562,19 +1562,14 @@ int virLXCProcessStart(virLXCDriver * driver, } =20 =20 -static int +void virLXCProcessAutostartDomain(virDomainObj *vm, void *opaque G_GNUC_UNUSED) { - VIR_LOCK_GUARD lock =3D virObjectLockGuard(vm); virLXCDomainObjPrivate *priv =3D vm->privateData; virObjectEvent *event; int rc =3D 0; =20 - if (!vm->autostart || - virDomainObjIsActive(vm)) - return 0; - rc =3D virLXCProcessStart(priv->driver, vm, 0, NULL, NULL, VIR_DOMAIN_= RUNNING_BOOTED); virDomainAuditStart(vm, "booted", rc >=3D 0); =20 @@ -1582,22 +1577,13 @@ virLXCProcessAutostartDomain(virDomainObj *vm, VIR_ERROR(_("Failed to autostart VM '%1$s': %2$s"), vm->def->name, virGetLastErrorMessage()); - return -1; + return; } =20 event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_BOO= TED); virObjectEventStateQueue(priv->driver->domainEventState, event); - - return 0; -} - - -void -virLXCProcessAutostartAll(virLXCDriver *driver) -{ - virDomainObjListForEach(driver->domains, false, virLXCProcessAutostart= Domain, NULL); } =20 =20 diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h index 95eacdd1e5..fc464690f8 100644 --- a/src/lxc/lxc_process.h +++ b/src/lxc/lxc_process.h @@ -34,6 +34,8 @@ int virLXCProcessStop(virLXCDriver *driver, unsigned int cleanupFlags); =20 void virLXCProcessAutostartAll(virLXCDriver *driver); +void virLXCProcessAutostartDomain(virDomainObj *vm, + void *opaque); int virLXCProcessReconnectAll(virLXCDriver *driver, virDomainObjList *doms); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2eddbd9ae..45bfbd3727 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -167,52 +167,29 @@ qemuDomObjFromSnapshot(virDomainSnapshotPtr snapshot) =20 =20 =20 -static int +static void qemuAutostartDomain(virDomainObj *vm, void *opaque) { virQEMUDriver *driver =3D opaque; int flags =3D 0; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - int ret =3D -1; =20 if (cfg->autoStartBypassCache) flags |=3D VIR_DOMAIN_START_BYPASS_CACHE; =20 - virObjectLock(vm); - virObjectRef(vm); - virResetLastError(); - if (vm->autostart && - !virDomainObjIsActive(vm)) { - if (qemuProcessBeginJob(vm, VIR_DOMAIN_JOB_OPERATION_START, - flags) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to start job on VM '%1$s': %2$s"), - vm->def->name, virGetLastErrorMessage()); - goto cleanup; - } + if (qemuProcessBeginJob(vm, VIR_DOMAIN_JOB_OPERATION_START, + flags) < 0) + return; =20 - if (qemuDomainObjStart(NULL, driver, vm, flags, - VIR_ASYNC_JOB_START) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to autostart VM '%1$s': %2$s"), + if (qemuDomainObjStart(NULL, driver, vm, flags, + VIR_ASYNC_JOB_START) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to autostart VM '%1$s': %2$s"), vm->def->name, virGetLastErrorMessage()); - } - - qemuProcessEndJob(vm); } =20 - ret =3D 0; - cleanup: - virDomainObjEndAPI(&vm); - return ret; -} - - -static void -qemuAutostartDomains(virQEMUDriver *driver) -{ - virDomainObjListForEach(driver->domains, false, qemuAutostartDomain, d= river); + qemuProcessEndJob(vm); } =20 =20 @@ -557,10 +534,10 @@ qemuStateInitialize(bool privileged, virQEMUDriverConfig *cfg; uid_t run_uid =3D -1; gid_t run_gid =3D -1; - bool autostart =3D true; size_t i; const char *defsecmodel =3D NULL; g_autoptr(virIdentity) identity =3D virIdentityGetCurrent(); + virDomainDriverAutoStartConfig autostartCfg; =20 qemu_driver =3D g_new0(virQEMUDriver, 1); =20 @@ -906,11 +883,12 @@ qemuStateInitialize(bool privileged, =20 qemuProcessReconnectAll(qemu_driver); =20 - if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) - goto error; - - if (autostart) - qemuAutostartDomains(qemu_driver); + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D cfg->stateDir, + .callback =3D qemuAutostartDomain, + .opaque =3D qemu_driver, + }; + virDomainDriverAutoStart(qemu_driver->domains, &autostartCfg); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365591680381.907969918362; Wed, 8 Jan 2025 11:46:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A04D91424; Wed, 8 Jan 2025 14:46:30 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 36A79147D; Wed, 8 Jan 2025 14:43:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C5F6F1471; Wed, 8 Jan 2025 14:43:24 -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 95A59140F for ; Wed, 8 Jan 2025 14:43:10 -0500 (EST) 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-278-XjG5B-BUPiKphijl80FUsQ-1; Wed, 08 Jan 2025 14:43:08 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C16D71944EB6 for ; Wed, 8 Jan 2025 19:43:07 +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 E4DA3300018D; Wed, 8 Jan 2025 19:43:06 +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=1736365390; 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=dCW6gkCrKP3QHYqUd6hi2oNZzGe/XGt9l30+d9QUdPw=; b=C4qqQ881p40yAdLdesV6alNmQI+b+VNQHWsuN5fQ7mvBXWVHvdcOtJwgOGUQBLdLIWEMIb s90pPuFJLTjY+G9+AqSwWN7H0VKz0WwGYPssqDD8X7xVNg+KuQAtgbdxrpYZ93Iif0IGH8 RmkOEtwGEF9JNfH8gG2DJQMYMY6bM2M= X-MC-Unique: XjG5B-BUPiKphijl80FUsQ-1 X-Mimecast-MFC-AGG-ID: XjG5B-BUPiKphijl80FUsQ 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 05/26] hypervisor: add support for delay interval during autostart Date: Wed, 8 Jan 2025 19:42:38 +0000 Message-ID: <20250108194259.1171990-6-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: mqqyrAl_zjyrW_EfROMx4hVKAXqWLszr3sWtmhswmtI_1736365387 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HXISMT5PLGM3RPRAAR43ADLQZGMWSJKV X-Message-ID-Hash: HXISMT5PLGM3RPRAAR43ADLQZGMWSJKV 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: 1736365706800116600 Content-Type: text/plain; charset="utf-8" This delay can reduce the CPU/IO load storm when autostarting many guests. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 20 +++++++++++++++++--- src/hypervisor/domain_driver.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index c5b082fd00..44c8fad4d5 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -656,11 +656,16 @@ virDomainDriverGetIOThreadsConfig(virDomainDef *targe= tDef, return ret; } =20 +typedef struct _virDomainDriverAutoStartState { + virDomainDriverAutoStartConfig *cfg; + bool first; +} virDomainDriverAutoStartState; + static int virDomainDriverAutoStartOne(virDomainObj *vm, void *opaque) { - virDomainDriverAutoStartConfig *cfg =3D opaque; + virDomainDriverAutoStartState *state =3D opaque; =20 virObjectLock(vm); virObjectRef(vm); @@ -670,7 +675,15 @@ virDomainDriverAutoStartOne(virDomainObj *vm, =20 if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); - cfg->callback(vm, cfg->opaque); + if (state->cfg->delayMS) { + if (!state->first) { + g_usleep(state->cfg->delayMS * 1000ull); + } else { + state->first =3D false; + } + } + + state->cfg->callback(vm, state->cfg->opaque); } =20 virDomainObjEndAPI(&vm); @@ -682,6 +695,7 @@ virDomainDriverAutoStartOne(virDomainObj *vm, void virDomainDriverAutoStart(virDomainObjList *domains, virDomainDriverAutoStartConfig *cfg) { + virDomainDriverAutoStartState state =3D { .cfg =3D cfg, .first =3D tru= e }; bool autostart; VIR_DEBUG("Run autostart stateDir=3D%s", cfg->stateDir); if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0 || @@ -690,5 +704,5 @@ void virDomainDriverAutoStart(virDomainObjList *domains, return; } =20 - virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, c= fg); + virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, &= state); } diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index c27ed9155e..d695e26f90 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -84,6 +84,7 @@ typedef struct _virDomainDriverAutoStartConfig { char *stateDir; virDomainDriverAutoStartCallback callback; void *opaque; + int delayMS; /* milliseconds between starting each guest */ } virDomainDriverAutoStartConfig; =20 void virDomainDriverAutoStart(virDomainObjList *domains, --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365617657169.4684091437225; Wed, 8 Jan 2025 11:46:57 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BABC413AD; Wed, 8 Jan 2025 14:46:56 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E3BA31447; Wed, 8 Jan 2025 14:43:32 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 551DA140A; Wed, 8 Jan 2025 14:43:28 -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 64A4B143B for ; Wed, 8 Jan 2025 14:43:11 -0500 (EST) Received: from mx-prod-mc-02.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-32-0RIlWKUkMYqhx6cUQEPKmA-1; Wed, 08 Jan 2025 14:43:09 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E7DF11956087 for ; Wed, 8 Jan 2025 19:43:08 +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 22311300018D; Wed, 8 Jan 2025 19:43:07 +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=1736365391; 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=B+tGe6pP2n+Zuz+1yqtYesLCJEHh7cBeZAsaYH+0goM=; b=Nx7WFqb8xA2Pb8c347a3RmFD6bI1dkg/qht1BqU6OqH5NAcHLKn7BtjhQqQ2wzbskRi6XF exSoMmzXsU4AexlRJ8fNcXhFtFJHtRbmCYsRYiOuPrK/AOTPRviiJOjvCQuHj22dd4XVvS x8cNsp8wxBS76/Sj23KlwJC6hv82eUY= X-MC-Unique: 0RIlWKUkMYqhx6cUQEPKmA-1 X-Mimecast-MFC-AGG-ID: 0RIlWKUkMYqhx6cUQEPKmA 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 06/26] qemu: add 'auto_start_delay' configuration parameter Date: Wed, 8 Jan 2025 19:42:39 +0000 Message-ID: <20250108194259.1171990-7-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: f8zEKH1_mqZ7ysadLqgewdD6NIqgifUtkIbRgtsTAIw_1736365389 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 733XAS6OHIQI6VZ347CKN5U4LZKWTHP7 X-Message-ID-Hash: 733XAS6OHIQI6VZ347CKN5U4LZKWTHP7 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: 1736365712906116600 Content-Type: text/plain; charset="utf-8" This allows a user specified delay between autostart of each VM, giving parity with the equivalent feature of libvirt-guests. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 4 ++++ src/qemu/qemu_conf.c | 2 ++ src/qemu/qemu_conf.h | 1 + src/qemu/qemu_driver.c | 1 + src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 10 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 1377fd89cc..642093c40b 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -97,6 +97,7 @@ module Libvirtd_qemu =3D | str_entry "auto_dump_path" | bool_entry "auto_dump_bypass_cache" | bool_entry "auto_start_bypass_cache" + | int_entry "auto_start_delay" =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 d853136f10..a3e9bbfcf3 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -634,6 +634,10 @@ # #auto_start_bypass_cache =3D 0 =20 +# Delay in milliseconds between starting each VM, during autostart +# +#auto_start_delay =3D 0 + # 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 8b9fe4e381..0b6b923bcb 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -638,6 +638,8 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *c= fg, return -1; if (virConfGetValueBool(conf, "auto_start_bypass_cache", &cfg->autoSta= rtBypassCache) < 0) return -1; + if (virConfGetValueInt(conf, "auto_start_delay", &cfg->autoStartDelayM= S) < 0) + return -1; =20 return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 42cdb6f883..61a2bdce51 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -200,6 +200,7 @@ struct _virQEMUDriverConfig { char *autoDumpPath; bool autoDumpBypassCache; bool autoStartBypassCache; + int autoStartDelayMS; =20 char *lockManagerName; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 45bfbd3727..f689dadc0a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -887,6 +887,7 @@ qemuStateInitialize(bool privileged, .stateDir =3D cfg->stateDir, .callback =3D qemuAutostartDomain, .opaque =3D qemu_driver, + .delayMS =3D cfg->autoStartDelayMS, }; virDomainDriverAutoStart(qemu_driver->domains, &autostartCfg); =20 diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 69fdae215a..c2a1d7d829 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -75,6 +75,7 @@ module Test_libvirtd_qemu =3D { "auto_dump_path" =3D "/var/lib/libvirt/qemu/dump" } { "auto_dump_bypass_cache" =3D "0" } { "auto_start_bypass_cache" =3D "0" } +{ "auto_start_delay" =3D "0" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } { "set_process_name" =3D "1" } --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365644208544.8672427532005; Wed, 8 Jan 2025 11:47:24 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 347D9151C; Wed, 8 Jan 2025 14:47:23 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 53A7B1461; Wed, 8 Jan 2025 14:43:39 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 203B71458; Wed, 8 Jan 2025 14:43:35 -0500 (EST) 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 34C9F13E0 for ; Wed, 8 Jan 2025 14:43:13 -0500 (EST) 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-157-6suwqY6sM5ermWQnCw6lKA-1; Wed, 08 Jan 2025 14:43:11 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 54D6B1955F39 for ; Wed, 8 Jan 2025 19:43:10 +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 77CB0300018D; Wed, 8 Jan 2025 19:43:09 +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_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=1736365392; 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=0a2ihEPf4mx9vDFcWRltgyFAck3gEJnbTLx3gaXDKZ4=; b=YETf5+J2HM60+UOIU/r3NrziVZyUadOo/o/nr7cQ+UsRzMoAVRZx1VwS2UcYiL23PtKb8/ na9zS+wqqtLsMGZYf/bIjh/Iww482TBoEW9KruJttiyAPovW98Cs5sRPGFwivEkVJonw+1 GP/mkAqcpH0Ye9i09do4571HRxrl4PY= X-MC-Unique: 6suwqY6sM5ermWQnCw6lKA-1 X-Mimecast-MFC-AGG-ID: 6suwqY6sM5ermWQnCw6lKA 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 07/26] hypervisor: move support for auto-shutdown out of QEMU driver Date: Wed, 8 Jan 2025 19:42:40 +0000 Message-ID: <20250108194259.1171990-8-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: OdSIh6W-SBAggC84pD4ppBnsNZWcf_4Bq9Xl9fifgLo_1736365390 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LPBT2A46O2DBJTJ4CXZVEDYXBCDIHIYW X-Message-ID-Hash: LPBT2A46O2DBJTJ4CXZVEDYXBCDIHIYW 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: 1736365725811116600 Content-Type: text/plain; charset="utf-8" This is a move of the code that currently exists in the QEMU driver, into the common layer that can be used by multiple drivers. The code currently supports performing managed save of all running guests, ignoring any failures. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 48 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 8 +++++- src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 47 ++++----------------------------- 4 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 44c8fad4d5..949e3d01f1 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -706,3 +706,51 @@ void virDomainDriverAutoStart(virDomainObjList *domain= s, =20 virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, &= state); } + + +void +virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg) +{ + g_autoptr(virConnect) conn =3D NULL; + int numDomains =3D 0; + size_t i; + int state; + virDomainPtr *domains =3D NULL; + g_autofree unsigned int *flags =3D NULL; + + if (!(conn =3D virConnectOpen(cfg->uri))) + goto cleanup; + + if ((numDomains =3D virConnectListAllDomains(conn, + &domains, + VIR_CONNECT_LIST_DOMAINS_AC= TIVE)) < 0) + goto cleanup; + + flags =3D g_new0(unsigned int, numDomains); + + /* First we pause all VMs to make them stop dirtying + pages, etc. We remember if any VMs were paused so + we can restore that on resume. */ + for (i =3D 0; i < numDomains; i++) { + flags[i] =3D VIR_DOMAIN_SAVE_RUNNING; + if (virDomainGetState(domains[i], &state, NULL, 0) =3D=3D 0) { + if (state =3D=3D VIR_DOMAIN_PAUSED) + flags[i] =3D VIR_DOMAIN_SAVE_PAUSED; + } + virDomainSuspend(domains[i]); + } + + /* Then we save the VMs to disk */ + for (i =3D 0; i < numDomains; i++) + if (virDomainManagedSave(domains[i], flags[i]) < 0) + VIR_WARN("Unable to perform managed save of '%s': %s", + virDomainGetName(domains[i]), + virGetLastErrorMessage()); + + cleanup: + if (domains) { + for (i =3D 0; i < numDomains; i++) + virObjectUnref(domains[i]); + VIR_FREE(domains); + } +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index d695e26f90..d1588ea712 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -81,7 +81,7 @@ typedef void (*virDomainDriverAutoStartCallback)(virDomai= nObj *vm, void *opaque); =20 typedef struct _virDomainDriverAutoStartConfig { - char *stateDir; + const char *stateDir; virDomainDriverAutoStartCallback callback; void *opaque; int delayMS; /* milliseconds between starting each guest */ @@ -89,3 +89,9 @@ typedef struct _virDomainDriverAutoStartConfig { =20 void virDomainDriverAutoStart(virDomainObjList *domains, virDomainDriverAutoStartConfig *cfg); + +typedef struct _virDomainDriverAutoShutdownConfig { + const char *uri; +} virDomainDriverAutoShutdownConfig; + +void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d90b15e215..781bb566d2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1640,6 +1640,7 @@ virDomainCgroupSetupVcpuBW; =20 # hypervisor/domain_driver.h virDomainDriverAddIOThreadCheck; +virDomainDriverAutoShutdown; virDomainDriverAutoStart; virDomainDriverDelIOThreadCheck; virDomainDriverGenerateMachineName; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f689dadc0a..8c16566ce8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -944,51 +944,14 @@ qemuStateReload(void) static int qemuStateStop(void) { - int ret =3D -1; - g_autoptr(virConnect) conn =3D NULL; - int numDomains =3D 0; - size_t i; - int state; - virDomainPtr *domains =3D NULL; - g_autofree unsigned int *flags =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(qemu_dri= ver); + virDomainDriverAutoShutdownConfig ascfg =3D { + .uri =3D cfg->uri, + }; =20 - if (!(conn =3D virConnectOpen(cfg->uri))) - goto cleanup; - - if ((numDomains =3D virConnectListAllDomains(conn, - &domains, - VIR_CONNECT_LIST_DOMAINS_AC= TIVE)) < 0) - goto cleanup; - - flags =3D g_new0(unsigned int, numDomains); - - /* First we pause all VMs to make them stop dirtying - pages, etc. We remember if any VMs were paused so - we can restore that on resume. */ - for (i =3D 0; i < numDomains; i++) { - flags[i] =3D VIR_DOMAIN_SAVE_RUNNING; - if (virDomainGetState(domains[i], &state, NULL, 0) =3D=3D 0) { - if (state =3D=3D VIR_DOMAIN_PAUSED) - flags[i] =3D VIR_DOMAIN_SAVE_PAUSED; - } - virDomainSuspend(domains[i]); - } - - ret =3D 0; - /* Then we save the VMs to disk */ - for (i =3D 0; i < numDomains; i++) - if (virDomainManagedSave(domains[i], flags[i]) < 0) - ret =3D -1; - - cleanup: - if (domains) { - for (i =3D 0; i < numDomains; i++) - virObjectUnref(domains[i]); - VIR_FREE(domains); - } + virDomainDriverAutoShutdown(&ascfg); =20 - return ret; + return 0; } =20 =20 --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 173636566589334.8693397218542; Wed, 8 Jan 2025 11:47:45 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E26891509; Wed, 8 Jan 2025 14:47:44 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 238FA149A; Wed, 8 Jan 2025 14:43:41 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 86A2B1381; Wed, 8 Jan 2025 14:43:36 -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 9515E1381 for ; Wed, 8 Jan 2025 14:43:14 -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-18-GX2CeLkhNiOnuHmzHhhgbw-1; Wed, 08 Jan 2025 14:43:12 -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 8AFAB19560A1 for ; Wed, 8 Jan 2025 19:43:11 +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 B1215300018D; Wed, 8 Jan 2025 19:43: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.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=1736365394; 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=g7ChhWyATd1vTshDnrAtLYAqQ31Vf1hHcS6CDXIB0HU=; b=iMLvvGuvTNSzr7yaKZbxDcM/O3vnRLBZipVhzPM8CjSoCOhh72Wlw/ckqAKTXDdBk0XY8n xssI8TXdHjoAJHEkBRIElfkmKjSRvCcektncK69bSrW9hioDplKYg1go7b1Dr2VIuye0HN 2RT0Cfl66imE9wcY3/Uba229/e9RQrw= X-MC-Unique: GX2CeLkhNiOnuHmzHhhgbw-1 X-Mimecast-MFC-AGG-ID: GX2CeLkhNiOnuHmzHhhgbw 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 08/26] remote: always invoke virStateStop for all daemons Date: Wed, 8 Jan 2025 19:42:41 +0000 Message-ID: <20250108194259.1171990-9-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: 1OOA3DmVYQQvV_8KcfgyZFhHTsKt9AE4PQkuHY7J9DE_1736365391 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GK2TZ6LE4TXDPLQKEHFPLWRFA5RZX7RT X-Message-ID-Hash: GK2TZ6LE4TXDPLQKEHFPLWRFA5RZX7RT 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: 1736365727958116600 Content-Type: text/plain; charset="utf-8" Currently the virStateStop method is only wired up to run save for the unprivileged daemons, so there is no functional change. IOW, session exit, or host OS shutdown will trigger VM managed saved for QEMU session daemon, but not the system daemon. This changes the daemon code to always run virStateStop for all daemons. Instead the QEMU driver is responsible for skipping its own logic when running privileged...for now. This means that virStateStop will now be triggered by logind's PrepareForShutdown signal. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_driver.c | 3 ++- src/remote/remote_daemon.c | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8c16566ce8..103369ac93 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -949,7 +949,8 @@ qemuStateStop(void) .uri =3D cfg->uri, }; =20 - virDomainDriverAutoShutdown(&ascfg); + if (!qemu_driver->privileged) + virDomainDriverAutoShutdown(&ascfg); =20 return 0; } diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index d44a365000..c4b930cb70 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -628,27 +628,29 @@ static void daemonRunStateInit(void *opaque) virStateShutdownPrepare, virStateShutdownWait); =20 - /* Tie the non-privileged daemons to the session/shutdown lifecycle */ + /* Signal for VM shutdown when desktop session is terminated, in + * unprivileged daemons */ if (!virNetDaemonIsPrivileged(dmn)) { - sessionBus =3D virGDBusGetSessionBus(); if (sessionBus !=3D NULL) g_dbus_connection_add_filter(sessionBus, handleSessionMessageFunc, dmn, NU= LL); + } =20 - systemBus =3D virGDBusGetSystemBus(); - if (systemBus !=3D NULL) - g_dbus_connection_signal_subscribe(systemBus, - "org.freedesktop.login1", - "org.freedesktop.login1.Man= ager", - "PrepareForShutdown", - NULL, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - handleSystemMessageFunc, + /* Signal for VM shutdown when host OS shutdown is requested, in + * both privileged and unprivileged daemons */ + systemBus =3D virGDBusGetSystemBus(); + if (systemBus !=3D NULL) + g_dbus_connection_signal_subscribe(systemBus, + "org.freedesktop.login1", + "org.freedesktop.login1.Manager= ", + "PrepareForShutdown", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + handleSystemMessageFunc, dmn, NULL); - } =20 /* Only now accept clients from network */ virNetDaemonUpdateServices(dmn, true); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 173636570058227.63068622460787; Wed, 8 Jan 2025 11:48:20 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A37F1144B; Wed, 8 Jan 2025 14:48:19 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 60972136E; Wed, 8 Jan 2025 14:43:45 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 07F241498; Wed, 8 Jan 2025 14:43:41 -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 1DBBD1450 for ; Wed, 8 Jan 2025 14:43:15 -0500 (EST) 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-348-VMhD1aCuMpu08ALjvvOBbw-1; Wed, 08 Jan 2025 14:43:13 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6F6B19772C6 for ; Wed, 8 Jan 2025 19:43:12 +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 DD633300019E; Wed, 8 Jan 2025 19:43:11 +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=1736365394; 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=KWbjacy0MtMTnb+TGOHwusCLs9eR2abQH4k7jHbo4Jk=; b=P0F/3fs91daDOpDHgCd2NxEedI5XiWChaV6o93Tt9IoMrneWKWfc01GLbhmQ8GaH/sUhDZ BASmozvGPYBNIB6XBcJeQqebdyp0rS4Skp1LClKXRZ/HuIOjgFv5m7Nyi7A+Yup+bJ6YHL 1T2XIX5ocoS8o2W6XvKONCks6S5ztdg= X-MC-Unique: VMhD1aCuMpu08ALjvvOBbw-1 X-Mimecast-MFC-AGG-ID: VMhD1aCuMpu08ALjvvOBbw 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 09/26] hypervisor: expand available shutdown actions Date: Wed, 8 Jan 2025 19:42:42 +0000 Message-ID: <20250108194259.1171990-10-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: Nm4o_VWJQ_KoHTSEDPDDKbLv49ikou5sLY_Q79rMMvg_1736365392 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CUCW4ACTPQQX553YBZMYX6FZFP6MVVCZ X-Message-ID-Hash: CUCW4ACTPQQX553YBZMYX6FZFP6MVVCZ 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: 1736365728834116600 Content-Type: text/plain; charset="utf-8" The auto shutdown code can currently only perform managed save, which may fail in some cases, for example when PCI devices are assigned. On failure, shutdown inhibitors remain in place which may be undesirable. This expands the logic to try a sequence of operations * Managed save * Graceful shutdown * Forced poweroff Each of these operations can be enabled or disabled, but they are always applied in this order. With the shutdown option, a configurable time is allowed for shutdown to complete, defaulting to 30 seconds, before moving onto the forced poweroff phase. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 113 +++++++++++++++++++++++++++------ src/hypervisor/domain_driver.h | 4 ++ src/qemu/qemu_driver.c | 3 + 3 files changed, 100 insertions(+), 20 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 949e3d01f1..ea3f1cbfcd 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -714,9 +714,26 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdow= nConfig *cfg) g_autoptr(virConnect) conn =3D NULL; int numDomains =3D 0; size_t i; - int state; virDomainPtr *domains =3D NULL; - g_autofree unsigned int *flags =3D NULL; + + VIR_DEBUG("Run autoshutdown uri=3D%s trySave=3D%d tryShutdown=3D%d pow= eroff=3D%d" + "waitShutdownSecs=3D%d", + cfg->uri, cfg->trySave, cfg->tryShutdown, cfg->poweroff, + cfg->waitShutdownSecs); + + /* + * Ideally guests will shutdown in a few seconds, but it would + * not be unsual for it to take a while longer, especially under + * load, or if the guest OS has inhibitors slowing down shutdown. + * + * If we wait too long, then guests which ignore the shutdown + * request will significantly delay host shutdown. + * + * Pick 30 seconds as a moderately safe default, assuming that + * most guests are well behaved. + */ + if (cfg->waitShutdownSecs <=3D 0) + cfg->waitShutdownSecs =3D 30; =20 if (!(conn =3D virConnectOpen(cfg->uri))) goto cleanup; @@ -726,31 +743,87 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdo= wnConfig *cfg) VIR_CONNECT_LIST_DOMAINS_AC= TIVE)) < 0) goto cleanup; =20 - flags =3D g_new0(unsigned int, numDomains); + VIR_DEBUG("Auto shutdown with %d running domains", numDomains); + if (cfg->trySave) { + g_autofree unsigned int *flags =3D g_new0(unsigned int, numDomains= ); + for (i =3D 0; i < numDomains; i++) { + int state; + /* + * Pause all VMs to make them stop dirtying pages, + * so save is quicker. We remember if any VMs were + * paused so we can restore that on resume. + */ + flags[i] =3D VIR_DOMAIN_SAVE_RUNNING; + if (virDomainGetState(domains[i], &state, NULL, 0) =3D=3D 0) { + if (state =3D=3D VIR_DOMAIN_PAUSED) + flags[i] =3D VIR_DOMAIN_SAVE_PAUSED; + } + virDomainSuspend(domains[i]); + } + + for (i =3D 0; i < numDomains; i++) { + if (virDomainManagedSave(domains[i], flags[i]) < 0) { + VIR_WARN("Unable to perform managed save of '%s': %s", + virDomainGetName(domains[i]), + virGetLastErrorMessage()); + continue; + } + virObjectUnref(domains[i]); + domains[i] =3D NULL; + } + } + + if (cfg->tryShutdown) { + GTimer *timer =3D NULL; + for (i =3D 0; i < numDomains; i++) { + if (domains[i] =3D=3D NULL) + continue; + if (virDomainShutdown(domains[i]) < 0) { + VIR_WARN("Unable to perform graceful shutdown of '%s': %s", + virDomainGetName(domains[i]), + virGetLastErrorMessage()); + break; + } + } + + timer =3D g_timer_new(); + while (1) { + bool anyRunning =3D false; + for (i =3D 0; i < numDomains; i++) { + if (!domains[i]) + continue; =20 - /* First we pause all VMs to make them stop dirtying - pages, etc. We remember if any VMs were paused so - we can restore that on resume. */ - for (i =3D 0; i < numDomains; i++) { - flags[i] =3D VIR_DOMAIN_SAVE_RUNNING; - if (virDomainGetState(domains[i], &state, NULL, 0) =3D=3D 0) { - if (state =3D=3D VIR_DOMAIN_PAUSED) - flags[i] =3D VIR_DOMAIN_SAVE_PAUSED; + if (virDomainIsActive(domains[i]) =3D=3D 1) { + anyRunning =3D true; + } else { + virObjectUnref(domains[i]); + domains[i] =3D NULL; + } + } + + if (!anyRunning) + break; + if (g_timer_elapsed(timer, NULL) > cfg->waitShutdownSecs) + break; + g_usleep(1000*500); } - virDomainSuspend(domains[i]); + g_timer_destroy(timer); } =20 - /* Then we save the VMs to disk */ - for (i =3D 0; i < numDomains; i++) - if (virDomainManagedSave(domains[i], flags[i]) < 0) - VIR_WARN("Unable to perform managed save of '%s': %s", - virDomainGetName(domains[i]), - virGetLastErrorMessage()); + if (cfg->poweroff) { + for (i =3D 0; i < numDomains; i++) { + if (domains[i] =3D=3D NULL) + continue; + virDomainDestroy(domains[i]); + } + } =20 cleanup: if (domains) { - for (i =3D 0; i < numDomains; i++) - virObjectUnref(domains[i]); + for (i =3D 0; i < numDomains; i++) { + if (domains[i]) + virObjectUnref(domains[i]); + } VIR_FREE(domains); } } diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index d1588ea712..25c4b0c664 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -92,6 +92,10 @@ void virDomainDriverAutoStart(virDomainObjList *domains, =20 typedef struct _virDomainDriverAutoShutdownConfig { const char *uri; + bool trySave; + bool tryShutdown; + bool poweroff; + int waitShutdownSecs; } virDomainDriverAutoShutdownConfig; =20 void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 103369ac93..2c97a6fb98 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -947,6 +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, }; =20 if (!qemu_driver->privileged) --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 From nobody Tue Jan 21 04:01:21 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 1736365760111663.8605515292114; Wed, 8 Jan 2025 11:49:20 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0CF8D1524; Wed, 8 Jan 2025 14:49:19 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3DFDEDAD; Wed, 8 Jan 2025 14:43:51 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D78D51481; 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 E4D0113B7 for ; Wed, 8 Jan 2025 14:43:18 -0500 (EST) 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-68-haAoYa0JNayT2MUPhPV5gA-1; Wed, 08 Jan 2025 14:43:17 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 406861979053 for ; Wed, 8 Jan 2025 19:43:15 +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 64E2A300019E; Wed, 8 Jan 2025 19:43:14 +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=1736365398; 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=ZAwE1RsoVKvKownyP4TFIhNAKtM3WlxXUbptcxTeKMI=; b=JrnPgOT1CtT/eVDEdDJuLgIae9fNLqMhEZymuSe91Iuh9gD9ByVxilASezNtnc6fYHUPCF IrLetvwnBVsFPKG4gqDR+et2KYP9MvCKRc3xlcisxA8RezUhey9mjZk7IXYlJ9Q+XFTBYt J8wmc9aqvgCbWQnutXFJC3nUWh49S9U= X-MC-Unique: haAoYa0JNayT2MUPhPV5gA-1 X-Mimecast-MFC-AGG-ID: haAoYa0JNayT2MUPhPV5gA 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 11/26] qemu: support automatic VM managed save in system daemon Date: Wed, 8 Jan 2025 19:42:44 +0000 Message-ID: <20250108194259.1171990-12-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: OZTEQFarHCLrepZU3-QWYTWrTNKuapS1riyKWs5ZmEM_1736365395 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: PBBMMW6IWDPRGKB5ZNJIZBEADL7W726B X-Message-ID-Hash: PBBMMW6IWDPRGKB5ZNJIZBEADL7W726B 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: 1736365762719116600 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 "all" 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 --- src/qemu/libvirtd_qemu.aug | 3 ++ src/qemu/qemu.conf.in | 37 ++++++++++++++++++++++ src/qemu/qemu_conf.c | 51 ++++++++++++++++++++++++++++++ src/qemu/qemu_conf.h | 3 ++ src/qemu/qemu_driver.c | 9 +++--- src/qemu/test_libvirtd_qemu.aug.in | 3 ++ 6 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 642093c40b..e465a231fc 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_powerdown" =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 a3e9bbfcf3..d8890c4c32 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -638,6 +638,43 @@ # #auto_start_delay =3D 0 =20 +# 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). Accepts +# +# * "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 +# +# Defaults to "all" for session daemons and "none" +# for system daemons +# +# 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 "all" + +# 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_powerdown =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 0b6b923bcb..a57eccf569 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -303,6 +303,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= _ALL; + 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 @@ -626,6 +641,8 @@ static int virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *cfg, virConf *conf) { + g_autofree char *autoShutdownScope =3D NULL; + if (virConfGetValueString(conf, "save_image_format", &cfg->saveImageFo= rmat) < 0) return -1; if (virConfGetValueString(conf, "dump_image_format", &cfg->dumpImageFo= rmat) < 0) @@ -640,6 +657,40 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *= cfg, return -1; if (virConfGetValueInt(conf, "auto_start_delay", &cfg->autoStartDelayM= S) < 0) return -1; + if (virConfGetValueString(conf, "auto_shutdown_try_save", &autoShutdow= nScope) < 0) + return -1; + + if (autoShutdownScope !=3D NULL && + (cfg->autoShutdownTrySave =3D + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownScope)= ) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_try_save '%1$s'"), + autoShutdownScope); + return -1; + } + + if (virConfGetValueString(conf, "auto_shutdown_try_shutdown", &autoShu= tdownScope) < 0) + return -1; + + if (autoShutdownScope !=3D NULL && + (cfg->autoShutdownTryShutdown =3D + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownScope)= ) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_try_shutdown '%1$s'"), + autoShutdownScope); + return -1; + } + if (virConfGetValueString(conf, "auto_shutdown_poweroff", &autoShutdow= nScope) < 0) + return -1; + + if (autoShutdownScope !=3D NULL && + (cfg->autoShutdownPoweroff =3D + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownScope)= ) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_poweroff '%1$s'"), + autoShutdownScope); + return -1; + } =20 return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 61a2bdce51..5d9ace6dcc 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -201,6 +201,9 @@ struct _virQEMUDriverConfig { bool autoDumpBypassCache; bool autoStartBypassCache; int autoStartDelayMS; + int autoShutdownTrySave; + int autoShutdownTryShutdown; + int autoShutdownPoweroff; =20 char *lockManagerName; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8e15a77be2..641b45fd8f 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_ALL, - .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..e7137f686f 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 "all" } +{ "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.47.1 From nobody Tue Jan 21 04:01:21 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 1736365795578593.2947637746812; Wed, 8 Jan 2025 11:49:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 92B2E13B3; Wed, 8 Jan 2025 14:49:54 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 800AE1399; Wed, 8 Jan 2025 14:43:55 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id EEB5814B3; Wed, 8 Jan 2025 14:43:49 -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 01E2513C9 for ; Wed, 8 Jan 2025 14:43:18 -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-594-LPQB37c_MvKdwd8uQZK0GA-1; Wed, 08 Jan 2025 14:43:17 -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 71DA119540EB for ; Wed, 8 Jan 2025 19:43:16 +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 978ED300019E; Wed, 8 Jan 2025 19:43:15 +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=1736365398; 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=/dvf/JkyhTC2xr3NBh70YnW4/yiVHXz0lDReNQP9t3c=; b=L7ZFK1aJZUnU7+CB8OeCv3e1kVTRkaxHhY3zQTZl4xiSGWBuS0achlpZT6CSs0tQfkpF9y v+q1zTVb1Q9nTnbCDbURDCz4nQLD0JJx9uw1+80JzBcOAHFjbRyejxqk2C/dc2+GvRkSDs T1SCaAeYePu2XgtN635wOIelU9emkGI= X-MC-Unique: LPQB37c_MvKdwd8uQZK0GA-1 X-Mimecast-MFC-AGG-ID: LPQB37c_MvKdwd8uQZK0GA 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 12/26] qemu: improve shutdown defaults for session daemon Date: Wed, 8 Jan 2025 19:42:45 +0000 Message-ID: <20250108194259.1171990-13-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: 2DA8pf0z0nab5mjSZgTkgn6opsAXFiRiBT2JjnhjD2w_1736365396 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NGXXRLAMZOWTIMQ22U6S2AQGGKSCUDDV X-Message-ID-Hash: NGXXRLAMZOWTIMQ22U6S2AQGGKSCUDDV 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: 1736365796781116600 Content-Type: text/plain; charset="utf-8" Currently the session daemon will try a managed save on all VMs, leaving them running if that fails. This limits the managed save just to persistent VMs, as there will usually not be any way to restore transient VMs later. It also enables graceful shutdown and then forced poweroff, should save fail for some reason. These new defaults can be overridden in the config file if needed. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/libvirtd_qemu.aug | 2 +- src/qemu/qemu.conf.in | 14 ++++++++------ src/qemu/qemu_conf.c | 6 +++--- src/qemu/test_libvirtd_qemu.aug.in | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index e465a231fc..605604a01a 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -100,7 +100,7 @@ module Libvirtd_qemu =3D | int_entry "auto_start_delay" | str_entry "auto_shutdown_try_save" | str_entry "auto_shutdown_try_shutdown" - | str_entry "auto_shutdown_powerdown" + | 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 d8890c4c32..82eae2eecd 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -647,33 +647,35 @@ # * "transient" - only try to save transient running VMs # * "all" - try to save all running VMs # -# Defaults to "all" for session daemons and "none" +# Defaults to "persistent" for session daemons and "none" # for system daemons # # 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 "all" +#auto_shutdown_try_save =3D "persistent" =20 # 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" +# Defaults to "all" for session daemons and "none" for +# system daemons # # 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" +#auto_shutdown_try_shutdown =3D "all" =20 # 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" +# Defaults to "all" for session daemons and "none" for +# system daemons. # # If 'libvirt-guests.service' is enabled, then this must be # set to 'none' for system daemons to avoid dueling actions -#auto_shutdown_powerdown =3D "none" +#auto_shutdown_poweroff =3D "all" =20 # If provided by the host and a hugetlbfs mount point is configured, # a guest may request huge page backing. When this mount point is diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index a57eccf569..76bb3bd888 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -313,9 +313,9 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privil= eged, 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= _ALL; - cfg->autoShutdownTryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_S= COPE_NONE; - cfg->autoShutdownPoweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOP= E_NONE; + cfg->autoShutdownTrySave =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE= _PERSISTENT; + cfg->autoShutdownTryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_S= COPE_ALL; + cfg->autoShutdownPoweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOP= E_ALL; } =20 return g_steal_pointer(&cfg); diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index e7137f686f..3bc8104d7a 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -76,9 +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 "all" } -{ "auto_shutdown_try_shutdown" =3D "none" } -{ "auto_shutdown_poweroff" =3D "none" } +{ "auto_shutdown_try_save" =3D "persistent" } +{ "auto_shutdown_try_shutdown" =3D "all" } +{ "auto_shutdown_poweroff" =3D "all" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } { "set_process_name" =3D "1" } --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365819369707.3100787866815; Wed, 8 Jan 2025 11:50:19 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 691DD1491; Wed, 8 Jan 2025 14:50:18 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7BC0B140A; Wed, 8 Jan 2025 14:43:58 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 14D091446; Wed, 8 Jan 2025 14:43:50 -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 2AFC313AF for ; Wed, 8 Jan 2025 14:43:20 -0500 (EST) Received: from mx-prod-mc-01.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-434-FL3YlHmPOlKSBg5pyk3yRg-1; Wed, 08 Jan 2025 14:43:18 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 94FAC1956053 for ; Wed, 8 Jan 2025 19:43:17 +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 C322C300018D; Wed, 8 Jan 2025 19:43:16 +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=1736365399; 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=kc5r70m2onOdG3ZeM0QSyRLzqVudIsvsmIt4RAe7RWE=; b=RVHKB5LoDLl3vvew1v+mevgVCIpMAnsPUO/pYvyWiAGmLhgKY7pPeRo2IUaaubBcikd53J jhMwL0WGdReMtdNt3tuJ2SBbsB/hk0mRDTTntfCs7tIW3ip6RMm0V6XBNn4oQPL4xsVXIh FJt8OUPpmQs1sbEstSic2dKxRmoBdrk= X-MC-Unique: FL3YlHmPOlKSBg5pyk3yRg-1 X-Mimecast-MFC-AGG-ID: FL3YlHmPOlKSBg5pyk3yRg 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 13/26] qemu: configurable delay for shutdown before poweroff Date: Wed, 8 Jan 2025 19:42:46 +0000 Message-ID: <20250108194259.1171990-14-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: pgAxYrKoJtZzP4K2MhCRdwUEe5sPY5tdzwWr0bf4M9A_1736365397 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ANTJP5ND43JGYLMXOHXZDAU73JLHO7OM X-Message-ID-Hash: ANTJP5ND43JGYLMXOHXZDAU73JLHO7OM 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: 1736365821002116600 Content-Type: text/plain; charset="utf-8" Allow users to control how many seconds libvirt waits for QEMU shutdown before force powering off a guest. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 4 ++++ src/qemu/qemu_conf.c | 4 ++++ src/qemu/qemu_conf.h | 1 + src/qemu/qemu_driver.c | 1 + src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 12 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 605604a01a..8cb1b144b9 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -101,6 +101,7 @@ module Libvirtd_qemu =3D | str_entry "auto_shutdown_try_save" | str_entry "auto_shutdown_try_shutdown" | str_entry "auto_shutdown_poweroff" + | int_entry "auto_shutdown_wait" =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 82eae2eecd..9287196c42 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -677,6 +677,10 @@ # set to 'none' for system daemons to avoid dueling actions #auto_shutdown_poweroff =3D "all" =20 +# How may seconds to wait for running VMs to gracefully shutdown +# when 'auto_shutdown_try_shutdown' is enabled +#auto_shutdown_wait =3D 30 + # 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 76bb3bd888..7ec682e533 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -692,6 +692,10 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *= cfg, return -1; } =20 + if (virConfGetValueInt(conf, "auto_shutdown_wait", + &cfg->autoShutdownWait) < 0) + return -1; + return 0; } =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 5d9ace6dcc..b8f6be110d 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -204,6 +204,7 @@ struct _virQEMUDriverConfig { int autoShutdownTrySave; int autoShutdownTryShutdown; int autoShutdownPoweroff; + int autoShutdownWait; =20 char *lockManagerName; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 641b45fd8f..baa0d51244 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -950,6 +950,7 @@ qemuStateStop(void) .trySave =3D cfg->autoShutdownTrySave, .tryShutdown =3D cfg->autoShutdownTryShutdown, .poweroff =3D cfg->autoShutdownPoweroff, + .waitShutdownSecs =3D cfg->autoShutdownWait, }; =20 virDomainDriverAutoShutdown(&ascfg); diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 3bc8104d7a..4c6de31199 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -79,6 +79,7 @@ module Test_libvirtd_qemu =3D { "auto_shutdown_try_save" =3D "persistent" } { "auto_shutdown_try_shutdown" =3D "all" } { "auto_shutdown_poweroff" =3D "all" } +{ "auto_shutdown_wait" =3D "30" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } { "set_process_name" =3D "1" } --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365839452715.610367748418; Wed, 8 Jan 2025 11:50:39 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8181C14D9; Wed, 8 Jan 2025 14:50:38 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 60FFC14A3; Wed, 8 Jan 2025 14:44:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3079614A6; Wed, 8 Jan 2025 14:43:50 -0500 (EST) 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 2AC7913EE for ; Wed, 8 Jan 2025 14:43:21 -0500 (EST) Received: from mx-prod-mc-02.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-103-aXFCPnjHPKu3ovnoRA_oYw-1; Wed, 08 Jan 2025 14:43:19 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E7CF91956087 for ; Wed, 8 Jan 2025 19:43:18 +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 F31A4300018D; Wed, 8 Jan 2025 19:43:17 +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_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=1736365400; 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=IhD+6cAloA6UdqtrRjS3ePK+gjjyxAbRitWZ0wI3uGo=; b=fq5zpB6WHaJ1JjNgCqcqQ/Nanb9bjW6hmUl2sNzGD31v9vdhkO1e3Hj2Nb86/UxW+nTMgf QWnD6Ra4X2MqzMQsZEgSn/9GMsr9eZSLB5hNl5A0va1X9Y3+lvWgzqr0JlCRQ6754gKF4U 8/x338PFaX+484frK/ul8+/LATaStc0= X-MC-Unique: aXFCPnjHPKu3ovnoRA_oYw-1 X-Mimecast-MFC-AGG-ID: aXFCPnjHPKu3ovnoRA_oYw 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 14/26] hypervisor: support bypassing cache for managed save Date: Wed, 8 Jan 2025 19:42:47 +0000 Message-ID: <20250108194259.1171990-15-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: sGyxtaGTIM27e6gRP-yaZygu4dPuGFkm7NUWsllKVuM_1736365399 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6WK5NL2WPO3JDICNZGWZVNZDFFQTQZBW X-Message-ID-Hash: 6WK5NL2WPO3JDICNZGWZVNZDFFQTQZBW 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: 1736365840886116600 Content-Type: text/plain; charset="utf-8" Bypassing cache can make save performance more predictable and avoids trashing the OS cache with data that will not be read again. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 7 +++++-- src/hypervisor/domain_driver.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 4fecaf7e5c..867ee1ae2a 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -725,9 +725,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) 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", + "waitShutdownSecs=3D%d saveBypassCache=3D%d", cfg->uri, cfg->trySave, cfg->tryShutdown, cfg->poweroff, - cfg->waitShutdownSecs); + cfg->waitShutdownSecs, cfg->saveBypassCache); =20 /* * Ideally guests will shutdown in a few seconds, but it would @@ -784,6 +784,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) if (state =3D=3D VIR_DOMAIN_PAUSED) flags[i] =3D VIR_DOMAIN_SAVE_PAUSED; } + if (cfg->saveBypassCache) + flags[i] |=3D VIR_DOMAIN_SAVE_BYPASS_CACHE; + virDomainSuspend(domains[i]); } =20 diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index acb7a41b5d..16832f2449 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -108,6 +108,7 @@ typedef struct _virDomainDriverAutoShutdownConfig { virDomainDriverAutoShutdownScope tryShutdown; virDomainDriverAutoShutdownScope poweroff; int waitShutdownSecs; + bool saveBypassCache; } virDomainDriverAutoShutdownConfig; =20 void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365864913189.13050259726333; Wed, 8 Jan 2025 11:51:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 03B6112E5; Wed, 8 Jan 2025 14:51:03 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E0979149E; Wed, 8 Jan 2025 14:44:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 626BC13EE; Wed, 8 Jan 2025 14:43:50 -0500 (EST) 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 BF4B912B7 for ; Wed, 8 Jan 2025 14:43:22 -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-637-hOmcozccNu-hk-dC2RTsLg-1; Wed, 08 Jan 2025 14:43:20 -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 2C9A9195608F for ; Wed, 8 Jan 2025 19:43:20 +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 50086300018D; Wed, 8 Jan 2025 19:43:19 +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_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=1736365402; 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=1sfuHaCr2eVnRMkt75nl8hRyLUZS1ax3PJXrywIwmz8=; b=LmCaNwPgiQFZ3inigX0B3h/yhP1sPAD1fu+XNmboqur+0HoYze2ZPJTw9jyOzUUQnxP3gF NbaQ13hmeEmFMDEfjhBUNqhPV8unMyfWn1nRHJjY7Q+VcLtLLqco0dGGc0Bjgk9GTDTXL8 Q0SRqlMTC5YTlbrhS9MQg11CXHKyZ/k= X-MC-Unique: hOmcozccNu-hk-dC2RTsLg-1 X-Mimecast-MFC-AGG-ID: hOmcozccNu-hk-dC2RTsLg 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 15/26] qemu: add config parameter to control auto-save bypass cache Date: Wed, 8 Jan 2025 19:42:48 +0000 Message-ID: <20250108194259.1171990-16-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: AdNeTFUawFhOc7c_Dt5MGkpMOewU9__BNw84yKGP2Uw_1736365400 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: O6YKE5D74JEOEP5VG2HHC4NH3USUZOKV X-Message-ID-Hash: O6YKE5D74JEOEP5VG2HHC4NH3USUZOKV 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: 1736365867043116600 Content-Type: text/plain; charset="utf-8" When doing managed save of VMs, triggered by OS shutdown, it may be desirable to control cache usage. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 8 ++++++++ src/qemu/qemu_conf.c | 3 +++ src/qemu/qemu_conf.h | 1 + src/qemu/qemu_driver.c | 1 + src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 15 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 8cb1b144b9..9fa6398d8d 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -102,6 +102,7 @@ module Libvirtd_qemu =3D | str_entry "auto_shutdown_try_shutdown" | str_entry "auto_shutdown_poweroff" | int_entry "auto_shutdown_wait" + | bool_entry "auto_save_bypass_cache" =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 9287196c42..d26ab4cb57 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -681,6 +681,14 @@ # when 'auto_shutdown_try_shutdown' is enabled #auto_shutdown_wait =3D 30 =20 +# When a domain is configured to be auto-saved on shutdown, enabling +# this flag has the same effect as using the VIR_DOMAIN_SAVE_BYPASS_CACHE +# flag with the virDomainManagedSave API. That is, the system will +# avoid using the file system cache when writing any managed state +# file, but may cause slower operation. +# +#auto_save_bypass_cache =3D 0 + # 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 7ec682e533..af09920869 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -695,6 +695,9 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *c= fg, if (virConfGetValueInt(conf, "auto_shutdown_wait", &cfg->autoShutdownWait) < 0) return -1; + if (virConfGetValueBool(conf, "auto_save_bypass_cache", + &cfg->autoSaveBypassCache) < 0) + return -1; =20 return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index b8f6be110d..9818a8cbb5 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -205,6 +205,7 @@ struct _virQEMUDriverConfig { int autoShutdownTryShutdown; int autoShutdownPoweroff; int autoShutdownWait; + bool autoSaveBypassCache; =20 char *lockManagerName; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index baa0d51244..8729b0fab0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -951,6 +951,7 @@ qemuStateStop(void) .tryShutdown =3D cfg->autoShutdownTryShutdown, .poweroff =3D cfg->autoShutdownPoweroff, .waitShutdownSecs =3D cfg->autoShutdownWait, + .saveBypassCache =3D cfg->autoSaveBypassCache, }; =20 virDomainDriverAutoShutdown(&ascfg); diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 4c6de31199..65d0c20fe1 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -80,6 +80,7 @@ module Test_libvirtd_qemu =3D { "auto_shutdown_try_shutdown" =3D "all" } { "auto_shutdown_poweroff" =3D "all" } { "auto_shutdown_wait" =3D "30" } +{ "auto_save_bypass_cache" =3D "0" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } { "set_process_name" =3D "1" } --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365931958174.5428370178306; Wed, 8 Jan 2025 11:52:11 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 05C82146E; Wed, 8 Jan 2025 14:52:11 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B788D13ED; Wed, 8 Jan 2025 14:44:08 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 70DCC1373; Wed, 8 Jan 2025 14:43:52 -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 D057B140F for ; Wed, 8 Jan 2025 14:43:24 -0500 (EST) Received: from mx-prod-mc-02.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-532-ygoTG9ZvMRyWcvha1XVrSw-1; Wed, 08 Jan 2025 14:43:22 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5E89419560BA for ; Wed, 8 Jan 2025 19:43:21 +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 883C8300018D; Wed, 8 Jan 2025 19:43:20 +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=1736365404; 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=fOqwbJxSWSYhWZm2PdR3eBY/oyRymgJfj/neTJV/odU=; b=FtqDUjHppkks8CwVs2S1frZjr97qVbKWPvmoKtBx973AwdZ8ZIIiJEqur60hfMqnxdVBXL uKWk7FRrSi6QhhrgmEiEzjPK/PJX3FYuxwnRlTMyWZOwk7n4r6KzHtIRIDEnuRI/kM0wFc w2mIm8DKAQoj0SuhqZREhYkQYte5h8c= X-MC-Unique: ygoTG9ZvMRyWcvha1XVrSw-1 X-Mimecast-MFC-AGG-ID: ygoTG9ZvMRyWcvha1XVrSw 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 16/26] src: add new APIs for marking a domain to autostart once Date: Wed, 8 Jan 2025 19:42:49 +0000 Message-ID: <20250108194259.1171990-17-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: veSo-heBqzjrrq-z7am9IkQ9TnP8TqN-GGYbMlIhxvE_1736365401 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WA2MPCDW6E4IVRYBR2LV6NGSJOVDVJ3Y X-Message-ID-Hash: WA2MPCDW6E4IVRYBR2LV6NGSJOVDVJ3Y 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: 1736365933584116600 Content-Type: text/plain; charset="utf-8" When a domain is marked for autostart, it will be started on every subsequent host OS boot. There may be times when it is desirable to mark a domain to be autostarted, on the next boot only. Thus we add virDomainSetAutostartOnce / virDomainGetAutostartOnce. An alternative would have been to overload the existing virDomainSetAutostart method, to accept values '1' or '2' for the autostart flag. This was not done because it is expected that language bindings will have mapped the current autostart flag to a boolean, and thus turning it into an enum would create a compatibility problem. A further alternative would have been to create a new method virDomainSetAutostartFlags, with a VIR_DOMAIN_AUTOSTART_ONCE flag defined. This was not done because it is felt desirable to clearly separate the two flags. Setting the "once" flag should not interfere with existing autostart setting, whether it is enabled or disabled currently. The 'virsh autostart' command, however, is still overloaded by just adding a --once flag, while current state is added to 'virsh dominfo'. No ability to filter by 'autostart once' status is added to the domain list APIs. The most common use of autostart once will be to automatically set it on host shutdown, and it be cleared on host startup. Thus there would rarely be scenarios in which a running app will need to filter on this new flag. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/libvirt/libvirt-domain.h | 4 ++ src/driver-hypervisor.h | 10 ++++ src/libvirt-domain.c | 87 ++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 6 +++ src/remote/remote_driver.c | 2 + src/remote/remote_protocol.x | 30 ++++++++++- src/remote_protocol-structs | 12 +++++ src/rpc/gendispatch.pl | 4 +- tools/virsh-domain-monitor.c | 5 ++ tools/virsh-domain.c | 39 ++++++++++---- 10 files changed, 187 insertions(+), 12 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 2a4b81f4df..6bd3200f37 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2398,6 +2398,10 @@ int virDomainGetAutostart (vir= DomainPtr domain, int *autostart); int virDomainSetAutostart (virDomainPtr domain, int autostart); +int virDomainGetAutostartOnce(virDomainPtr domain, + int *autostart); +int virDomainSetAutostartOnce(virDomainPtr domain, + int autostart); =20 /** * virVcpuState: diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 4ce8da078d..c05c71b9fe 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -478,6 +478,14 @@ typedef int (*virDrvDomainSetAutostart)(virDomainPtr domain, int autostart); =20 +typedef int +(*virDrvDomainGetAutostartOnce)(virDomainPtr domain, + int *autostart); + +typedef int +(*virDrvDomainSetAutostartOnce)(virDomainPtr domain, + int autostart); + typedef char * (*virDrvDomainGetSchedulerType)(virDomainPtr domain, int *nparams); @@ -1564,6 +1572,8 @@ struct _virHypervisorDriver { virDrvDomainDetachDeviceAlias domainDetachDeviceAlias; virDrvDomainGetAutostart domainGetAutostart; virDrvDomainSetAutostart domainSetAutostart; + virDrvDomainGetAutostartOnce domainGetAutostartOnce; + virDrvDomainSetAutostartOnce domainSetAutostartOnce; virDrvDomainGetSchedulerType domainGetSchedulerType; virDrvDomainGetSchedulerParameters domainGetSchedulerParameters; virDrvDomainGetSchedulerParametersFlags domainGetSchedulerParametersFl= ags; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index e8e5379672..7c730fc8de 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -7341,6 +7341,93 @@ virDomainSetAutostart(virDomainPtr domain, } =20 =20 +/** + * virDomainGetAutostartOnce: + * @domain: a domain object + * @autostart: the value returned + * + * Provides a boolean value indicating whether the domain + * is configured to be automatically started the next time + * the host machine boots only. + * + * Returns -1 in case of error, 0 in case of success + * + * Since: 11.0.0 + */ +int +virDomainGetAutostartOnce(virDomainPtr domain, + int *autostart) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "autostart=3D%p", autostart); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + virCheckNonNullArgGoto(autostart, error); + + conn =3D domain->conn; + + if (conn->driver->domainGetAutostartOnce) { + int ret; + ret =3D conn->driver->domainGetAutostartOnce(domain, autostart); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(domain->conn); + return -1; +} + + +/** + * virDomainSetAutostartOnce: + * @domain: a domain object + * @autostart: whether the domain should be automatically started 0 or 1 + * + * Configure the domain to be automatically started + * the next time the host machine boots only. + * + * Returns -1 in case of error, 0 in case of success + * + * Since: 11.0.0 + */ +int +virDomainSetAutostartOnce(virDomainPtr domain, + int autostart) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "autostart=3D%d", autostart); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->driver->domainSetAutostartOnce) { + int ret; + ret =3D conn->driver->domainSetAutostartOnce(domain, autostart); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(domain->conn); + return -1; +} + + /** * virDomainInjectNMI: * @domain: pointer to domain object, or NULL for Domain0 diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 7a3492d9d7..d01ac418d2 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -948,4 +948,10 @@ LIBVIRT_10.2.0 { virDomainGraphicsReload; } LIBVIRT_10.1.0; =20 +LIBVIRT_11.0.0 { + global: + virDomainGetAutostartOnce; + virDomainSetAutostartOnce; +} LIBVIRT_10.2.0; + # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 307f9ca945..a469209a9e 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7672,6 +7672,8 @@ static virHypervisorDriver hypervisor_driver =3D { .domainDetachDeviceAlias =3D remoteDomainDetachDeviceAlias, /* 4.4.0 */ .domainGetAutostart =3D remoteDomainGetAutostart, /* 0.3.0 */ .domainSetAutostart =3D remoteDomainSetAutostart, /* 0.3.0 */ + .domainGetAutostartOnce =3D remoteDomainGetAutostartOnce, /* 11.0.0 */ + .domainSetAutostartOnce =3D remoteDomainSetAutostartOnce, /* 11.0.0 */ .domainGetSchedulerType =3D remoteDomainGetSchedulerType, /* 0.3.0 */ .domainGetSchedulerParameters =3D remoteDomainGetSchedulerParameters, = /* 0.3.0 */ .domainGetSchedulerParametersFlags =3D remoteDomainGetSchedulerParamet= ersFlags, /* 0.9.2 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 41c045ff78..4f873cb4cf 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3973,6 +3973,20 @@ struct remote_domain_fd_associate_args { remote_nonnull_string name; unsigned int flags; }; + +struct remote_domain_get_autostart_once_args { + remote_nonnull_domain dom; +}; + +struct remote_domain_get_autostart_once_ret { + int autostart; +}; + +struct remote_domain_set_autostart_once_args { + remote_nonnull_domain dom; + int autostart; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -7048,5 +7062,19 @@ enum remote_procedure { * @generate: both * @acl: domain:write */ - REMOTE_PROC_DOMAIN_GRAPHICS_RELOAD =3D 448 + REMOTE_PROC_DOMAIN_GRAPHICS_RELOAD =3D 448, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_GET_AUTOSTART_ONCE =3D 449, + + /** + * @generate: both + * @priority: high + * @acl: domain:write + */ + REMOTE_PROC_DOMAIN_SET_AUTOSTART_ONCE =3D 450 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 4d3dc2d249..6337a082ce 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3306,6 +3306,16 @@ struct remote_domain_fd_associate_args { remote_nonnull_string name; u_int flags; }; +struct remote_domain_get_autostart_once_args { + remote_nonnull_domain dom; +}; +struct remote_domain_get_autostart_once_ret { + int autostart; +}; +struct remote_domain_set_autostart_once_args { + remote_nonnull_domain dom; + int autostart; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3755,4 +3765,6 @@ enum remote_procedure { REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446, REMOTE_PROC_NODE_DEVICE_UPDATE =3D 447, REMOTE_PROC_DOMAIN_GRAPHICS_RELOAD =3D 448, + REMOTE_PROC_DOMAIN_GET_AUTOSTART_ONCE =3D 449, + REMOTE_PROC_DOMAIN_SET_AUTOSTART_ONCE =3D 450, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 724a6aed6e..f9fae39fb1 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -839,7 +839,7 @@ elsif ($mode eq "server") { push(@ret_list, "ret->$1 =3D $1;"); $single_ret_var =3D $1; =20 - if ($call->{ProcName} =3D~ m/GetAutostart$/) { + if ($call->{ProcName} =3D~ m/GetAutostart(Once)?$/) { $single_ret_by_ref =3D 1; } else { $single_ret_by_ref =3D 0; @@ -1650,7 +1650,7 @@ elsif ($mode eq "client") { } elsif ($ret_member =3D~ m/^int (\S+);/) { my $arg_name =3D $1; =20 - if ($call->{ProcName} =3D~ m/GetAutostart$/) { + if ($call->{ProcName} =3D~ m/GetAutostart(Once)?$/) { push(@args_list, "int *$arg_name"); push(@ret_list, "if ($arg_name) *$arg_name =3D ret= .$arg_name;"); push(@ret_list, "rv =3D 0;"); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 9ee9090c11..fd5cc80ec2 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1236,6 +1236,11 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("enable") : _("disable")); } + /* Check and display whether the domain autostarts next boot or not */ + if (!virDomainGetAutostartOnce(dom, &autostart)) { + vshPrint(ctl, "%-15s %s\n", _("Autostart Once:"), + autostart ? _("enable") : _("disable")); + } =20 has_managed_save =3D virDomainHasManagedSaveImage(dom, 0); if (has_managed_save < 0) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 546db955a9..8a0111f0af 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1158,6 +1158,10 @@ static const vshCmdOptDef opts_autostart[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("disable autostarting") }, + {.name =3D "once", + .type =3D VSH_OT_BOOL, + .help =3D N_("control next boot state") + }, {.name =3D NULL} }; =20 @@ -1167,24 +1171,41 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom =3D NULL; const char *name; int autostart; + int once; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 autostart =3D !vshCommandOptBool(cmd, "disable"); + once =3D vshCommandOptBool(cmd, "once"); + + if (once) { + if (virDomainSetAutostartOnce(dom, autostart) < 0) { + if (autostart) + vshError(ctl, _("Failed to mark domain '%1$s' as autostart= ed on next boot"), name); + else + vshError(ctl, _("Failed to unmark domain '%1$s' as autosta= rted on next boot"), name); + return false; + } =20 - if (virDomainSetAutostart(dom, autostart) < 0) { if (autostart) - vshError(ctl, _("Failed to mark domain '%1$s' as autostarted")= , name); + vshPrintExtra(ctl, _("Domain '%1$s' marked as autostarted on n= ext boot\n"), name); else - vshError(ctl, _("Failed to unmark domain '%1$s' as autostarted= "), name); - return false; - } + vshPrintExtra(ctl, _("Domain '%1$s' unmarked as autostarted on= next boot\n"), name); + } else { + if (virDomainSetAutostart(dom, autostart) < 0) { + if (autostart) + vshError(ctl, _("Failed to mark domain '%1$s' as autostart= ed"), name); + else + vshError(ctl, _("Failed to unmark domain '%1$s' as autosta= rted"), name); + return false; + } =20 - if (autostart) - vshPrintExtra(ctl, _("Domain '%1$s' marked as autostarted\n"), nam= e); - else - vshPrintExtra(ctl, _("Domain '%1$s' unmarked as autostarted\n"), n= ame); + if (autostart) + vshPrintExtra(ctl, _("Domain '%1$s' marked as autostarted\n"),= name); + else + vshPrintExtra(ctl, _("Domain '%1$s' unmarked as autostarted\n"= ), name); + } =20 return true; } --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365893471917.6776678818803; Wed, 8 Jan 2025 11:51:33 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7A65B138B; Wed, 8 Jan 2025 14:51:32 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 650EE14B0; Wed, 8 Jan 2025 14:44:06 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 58E261223; Wed, 8 Jan 2025 14:43:51 -0500 (EST) 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 325DF1423 for ; Wed, 8 Jan 2025 14:43:25 -0500 (EST) 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-687-UXg27X5MP5m6ISAGbRIRHA-1; Wed, 08 Jan 2025 14:43:23 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 95F951944B2E for ; Wed, 8 Jan 2025 19:43:22 +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 C01023000199; Wed, 8 Jan 2025 19:43:21 +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_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=1736365404; 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=pIzvw8w9TmVCORsgLsVr/a2Fy/g7zoBPs1NFAQsI5tc=; b=cBurkYMbwNelmkTmIznEI9wguhP88mlXMMcKMMeXAZniLof/yLoKkEdHkomYuvvxUT85po 17zVXkdXCaG+uwkk5/Cv2/WolaLHrxX8wazduUpgun4hImPIyF/3llIz/ghNAcMzEMbw6g HYt/68j9qtvRrw7Pn3l13PJiSckaPnY= X-MC-Unique: UXg27X5MP5m6ISAGbRIRHA-1 X-Mimecast-MFC-AGG-ID: UXg27X5MP5m6ISAGbRIRHA 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 17/26] conf: implement support for autostart once feature Date: Wed, 8 Jan 2025 19:42:50 +0000 Message-ID: <20250108194259.1171990-18-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: baQfBpg5iKZt1O9-TQ57JrS8ScBrQlLNZu_ad5DaXhU_1736365402 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Y6ZY5HKI25JOWUJVNN7D2BHVRJDLBYV6 X-Message-ID-Hash: Y6ZY5HKI25JOWUJVNN7D2BHVRJDLBYV6 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: 1736365895148116600 Content-Type: text/plain; charset="utf-8" This is maintained in the same way as the autostart flag, using a symlink. The difference is that instead of '.xml', the symlink suffix is '.xml.once'. The link is also deleted immediately after it has been read. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 6 +++++- src/conf/domain_conf.h | 1 + src/conf/virdomainobjlist.c | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index af88d0bcfd..4a794d1f71 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29083,13 +29083,17 @@ virDomainDeleteConfig(const char *configDir, { g_autofree char *configFile =3D NULL; g_autofree char *autostartLink =3D NULL; + g_autofree char *autostartOnceLink =3D NULL; =20 configFile =3D virDomainConfigFile(configDir, dom->def->name); autostartLink =3D virDomainConfigFile(autostartDir, dom->def->name); + autostartOnceLink =3D g_strdup_printf("%s.once", autostartLink); =20 - /* Not fatal if this doesn't work */ + /* Not fatal if these don't work */ unlink(autostartLink); + unlink(autostartOnceLink); dom->autostart =3D 0; + dom->autostartOnce =3D 0; =20 if (unlink(configFile) < 0 && errno !=3D ENOENT) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 9f7c28343f..f30143e704 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3282,6 +3282,7 @@ struct _virDomainObj { virDomainStateReason state; =20 unsigned int autostart : 1; + unsigned int autostartOnce : 1; unsigned int persistent : 1; unsigned int updated : 1; unsigned int removing : 1; diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 72207450c5..ba2f9f544d 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -487,9 +487,10 @@ virDomainObjListLoadConfig(virDomainObjList *doms, { g_autofree char *configFile =3D NULL; g_autofree char *autostartLink =3D NULL; + g_autofree char *autostartOnceLink =3D NULL; g_autoptr(virDomainDef) def =3D NULL; virDomainObj *dom; - int autostart; + int autostart, autostartOnce; g_autoptr(virDomainDef) oldDef =3D NULL; =20 configFile =3D virDomainConfigFile(configDir, name); @@ -500,13 +501,17 @@ virDomainObjListLoadConfig(virDomainObjList *doms, return NULL; =20 autostartLink =3D virDomainConfigFile(autostartDir, name); + autostartOnceLink =3D g_strdup_printf("%s.once", autostartLink); =20 autostart =3D virFileLinkPointsTo(autostartLink, configFile); + autostartOnce =3D virFileLinkPointsTo(autostartOnceLink, configFile); + unlink(autostartOnceLink); =20 if (!(dom =3D virDomainObjListAddLocked(doms, &def, xmlopt, 0, &oldDef= ))) return NULL; =20 dom->autostart =3D autostart; + dom->autostartOnce =3D autostartOnce; =20 if (notify) (*notify)(dom, oldDef =3D=3D NULL, opaque); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365952481260.77947052604407; Wed, 8 Jan 2025 11:52:32 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8DD5A13C6; Wed, 8 Jan 2025 14:52:31 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DEB1D14C2; Wed, 8 Jan 2025 14:44:10 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DF9FC1424; Wed, 8 Jan 2025 14:43:54 -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 CDD721477 for ; Wed, 8 Jan 2025 14:43:26 -0500 (EST) Received: from mx-prod-mc-01.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-640-BxffwNnxNhi7nCxGxlRX1Q-1; Wed, 08 Jan 2025 14:43:24 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D3EC01956050 for ; Wed, 8 Jan 2025 19:43:23 +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 03660300018D; Wed, 8 Jan 2025 19:43:22 +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=1736365405; 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=3DOlkxmzefDT72zfJ4V0Byx/guyNw2Op4PikNnUTvt4=; b=eV+Hp7BalTkobB0ZyhDgUdi414mNMYsJX/h1vQqp8aOxCU+Bj3SzP1kLKah443CFlaZqYf 8MGSGCTB5/OC91LuiMAn2fJxGyjugYKVHvB2V3Lll90lc0yj+Ble9u69uRlqZxtuMLseP3 WX3zWOeTSbJ5qkK2bt7Ez7zNTm/e658= X-MC-Unique: BxffwNnxNhi7nCxGxlRX1Q-1 X-Mimecast-MFC-AGG-ID: BxffwNnxNhi7nCxGxlRX1Q 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 18/26] hypervisor: wire up support for auto restore of running domains Date: Wed, 8 Jan 2025 19:42:51 +0000 Message-ID: <20250108194259.1171990-19-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: E6cTEZq-J97cCK98U-zBqRQGiZBfeSkVvY0ydI-Yb-0_1736365404 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: D5L26NKYQCVBMYXWJJO6QF6QTDOH2ZKL X-Message-ID-Hash: D5L26NKYQCVBMYXWJJO6QF6QTDOH2ZKL 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: 1736365953270116600 Content-Type: text/plain; charset="utf-8" When performing auto-shutdown of running domains, there is now the option to mark them as "autostart once", so that their state is restored on next boot. This applies on top of the traditional autostart flag. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 27 ++++++++++++++++++++++----- src/hypervisor/domain_driver.h | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 867ee1ae2a..2f89b8c841 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -677,10 +677,11 @@ virDomainDriverAutoStartOne(virDomainObj *vm, virObjectLock(vm); virObjectRef(vm); =20 - VIR_DEBUG("Autostart %s: autostart=3D%d", - vm->def->name, vm->autostart); + VIR_DEBUG("Autostart %s: autostart=3D%d autostartOnce=3D%d", + vm->def->name, vm->autostart, vm->autostartOnce); =20 - if (vm->autostart && !virDomainObjIsActive(vm)) { + if ((vm->autostart || vm->autostartOnce) + && !virDomainObjIsActive(vm)) { virResetLastError(); if (state->cfg->delayMS) { if (!state->first) { @@ -691,6 +692,7 @@ virDomainDriverAutoStartOne(virDomainObj *vm, } =20 state->cfg->callback(vm, state->cfg->opaque); + vm->autostartOnce =3D 0; } =20 virDomainObjEndAPI(&vm); @@ -725,9 +727,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) 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 saveBypassCache=3D%d", + "waitShutdownSecs=3D%d saveBypassCache=3D%d autoRestore=3D%d= ", cfg->uri, cfg->trySave, cfg->tryShutdown, cfg->poweroff, - cfg->waitShutdownSecs, cfg->saveBypassCache); + cfg->waitShutdownSecs, cfg->saveBypassCache, cfg->autoRestor= e); =20 /* * Ideally guests will shutdown in a few seconds, but it would @@ -763,6 +765,21 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdow= nConfig *cfg) for (i =3D 0; i < numDomains; i++) { if (virDomainIsPersistent(domains[i]) =3D=3D 0) transient[i] =3D true; + + if (cfg->autoRestore) { + if (transient[i]) { + VIR_DEBUG("Cannot auto-restore transient VM %s", + virDomainGetName(domains[i])); + } else { + VIR_DEBUG("Mark %s for autostart on next boot", + virDomainGetName(domains[i])); + if (virDomainSetAutostartOnce(domains[i], 1) < 0) { + VIR_WARN("Unable to mark domain '%s' for auto restore:= %s", + virDomainGetName(domains[i]), + virGetLastErrorMessage()); + } + } + } } =20 if (cfg->trySave !=3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) { diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 16832f2449..72152f8054 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -109,6 +109,7 @@ typedef struct _virDomainDriverAutoShutdownConfig { virDomainDriverAutoShutdownScope poweroff; int waitShutdownSecs; bool saveBypassCache; + bool autoRestore; } virDomainDriverAutoShutdownConfig; =20 void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736365971091713.1286428115808; Wed, 8 Jan 2025 11:52:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2658D1558; Wed, 8 Jan 2025 14:52:50 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 32BFF14C7; Wed, 8 Jan 2025 14:44:13 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DD630144B; Wed, 8 Jan 2025 14:43:56 -0500 (EST) 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 799A6140B for ; Wed, 8 Jan 2025 14:43:28 -0500 (EST) Received: from mx-prod-mc-02.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-33--CPRQtUpODSlXnnvc9rkiQ-1; Wed, 08 Jan 2025 14:43:26 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 158AC19560AF for ; Wed, 8 Jan 2025 19:43:25 +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 3B77A300018D; Wed, 8 Jan 2025 19:43:24 +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_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=1736365408; 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=CTpYzGiLEC0+Zjb9NECc7bo9K0bhcZlwebUtFD/JwnA=; b=akAKeP5y/grLTgGsbNMlfUeYdcj76y3FEfJ+KdTKcZGqhWzih+k0i06XhBDWDHQLz9gb5y W10UVjAdo77rspEJMy0/Q9o1EqJDdtVImxGug3tomA8A/QI7qaSgOHeDsLpE6Q0pDasLZc Tlp3LPCVxZQuttFg0Htcvw7khwhRH8Y= X-MC-Unique: -CPRQtUpODSlXnnvc9rkiQ-1 X-Mimecast-MFC-AGG-ID: -CPRQtUpODSlXnnvc9rkiQ 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 19/26] qemu: wire up support for once only autostart Date: Wed, 8 Jan 2025 19:42:52 +0000 Message-ID: <20250108194259.1171990-20-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: LT7WI2csVFTESY2G8qxEm210MWQAR-cPyczZ6RAB7aQ_1736365405 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ORO7G5ERZMIJ64O3YU3SCI7SPYEWLX5L X-Message-ID-Hash: ORO7G5ERZMIJ64O3YU3SCI7SPYEWLX5L 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: 1736365971285116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_driver.c | 95 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8729b0fab0..84bde503dd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7778,6 +7778,99 @@ static int qemuDomainSetAutostart(virDomainPtr dom, } =20 =20 +static int qemuDomainGetAutostartOnce(virDomainPtr dom, + int *autostart) +{ + virDomainObj *vm; + int ret =3D -1; + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + goto cleanup; + + if (virDomainGetAutostartOnceEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + *autostart =3D vm->autostartOnce; + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int qemuDomainSetAutostartOnce(virDomainPtr dom, + int autostart) +{ + virQEMUDriver *driver =3D dom->conn->privateData; + virDomainObj *vm; + g_autofree char *configFile =3D NULL; + g_autofree char *autostartLink =3D NULL; + g_autofree char *autostartOnceLink =3D NULL; + int ret =3D -1; + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainSetAutostartOnceEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (!vm->persistent) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot set autostart for transient domain"= )); + goto cleanup; + } + + autostart =3D (autostart !=3D 0); + + if (vm->autostartOnce !=3D autostart) { + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + configFile =3D virDomainConfigFile(cfg->configDir, vm->def->name); + autostartLink =3D virDomainConfigFile(cfg->autostartDir, vm->def->= name); + autostartOnceLink =3D g_strdup_printf("%s.once", autostartLink); + + if (autostart) { + if (g_mkdir_with_parents(cfg->autostartDir, 0777) < 0) { + virReportSystemError(errno, + _("cannot create autostart directory = %1$s"), + cfg->autostartDir); + goto endjob; + } + + if (symlink(configFile, autostartOnceLink) < 0) { + virReportSystemError(errno, + _("Failed to create symlink '%1$s' to= '%2$s'"), + autostartOnceLink, configFile); + goto endjob; + } + } else { + if (unlink(autostartOnceLink) < 0 && + errno !=3D ENOENT && + errno !=3D ENOTDIR) { + virReportSystemError(errno, + _("Failed to delete symlink '%1$s'"), + autostartOnceLink); + goto endjob; + } + } + + vm->autostartOnce =3D autostart; + + endjob: + virDomainObjEndJob(vm); + } + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static char *qemuDomainGetSchedulerType(virDomainPtr dom, int *nparams) { @@ -20257,6 +20350,8 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainSetLaunchSecurityState =3D qemuDomainSetLaunchSecurityState, /*= 8.0.0 */ .domainFDAssociate =3D qemuDomainFDAssociate, /* 9.0.0 */ .domainGraphicsReload =3D qemuDomainGraphicsReload, /* 10.2.0 */ + .domainGetAutostartOnce =3D qemuDomainGetAutostartOnce, /* 11.0.0 */ + .domainSetAutostartOnce =3D qemuDomainSetAutostartOnce, /* 11.0.0 */ }; =20 =20 --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736366003197609.39497905202; Wed, 8 Jan 2025 11:53:23 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3952112C2; Wed, 8 Jan 2025 14:53:22 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4629613AC; Wed, 8 Jan 2025 14:44:15 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DBFB01477; Wed, 8 Jan 2025 14:43:57 -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 A727E143E for ; Wed, 8 Jan 2025 14:43:28 -0500 (EST) Received: from mx-prod-mc-01.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-654-tamu7SeXPcKM1hYgCd_ByQ-1; Wed, 08 Jan 2025 14:43:27 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4E09C1956064 for ; Wed, 8 Jan 2025 19:43:26 +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 733063000199; Wed, 8 Jan 2025 19:43:25 +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=1736365408; 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=FOOStAgnuBpBigWiNzOKot2+bSC+JMhSGo6EnHy8fDc=; b=dug/2tSYpaTk7whPlhr1dQ4mL8NsMdjQVfKkr0R089qUxQ3FfMaiI19hi0O9xIwvCBY87e Sn/Xa4F4i/wpnDBnJS90NXi/UVwVEtqMPaSxDuhZmHw68PGYqlH+BOARXE0agabwQ4CQqW PIDvOrF3JpTHqy/jXOXKR3R0lB9TSmo= X-MC-Unique: tamu7SeXPcKM1hYgCd_ByQ-1 X-Mimecast-MFC-AGG-ID: tamu7SeXPcKM1hYgCd_ByQ 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 20/26] qemu: add config to control if auto-shutdown VMs are restored Date: Wed, 8 Jan 2025 19:42:53 +0000 Message-ID: <20250108194259.1171990-21-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: wgrhj33Ru0A3zkduYEniWolavFOyp2FpxnwaOdPfm5Y_1736365406 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WM5GVUGACKTIGXTGPF7EDDCBDPBTYGUF X-Message-ID-Hash: WM5GVUGACKTIGXTGPF7EDDCBDPBTYGUF 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: 1736366003529116600 Content-Type: text/plain; charset="utf-8" If shutting down running VMs at host shutdown, it can be useful to automatically start them again on next boot. This adds a config parameter 'auto_shutdown_restore', which defaults to enabled, which leverages the autostart once feature. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 4 ++++ src/qemu/qemu_conf.c | 3 +++ src/qemu/qemu_conf.h | 1 + src/qemu/qemu_driver.c | 1 + src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 11 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 9fa6398d8d..ee39da73b9 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -102,6 +102,7 @@ module Libvirtd_qemu =3D | str_entry "auto_shutdown_try_shutdown" | str_entry "auto_shutdown_poweroff" | int_entry "auto_shutdown_wait" + | bool_entry "auto_shutdown_restore" | bool_entry "auto_save_bypass_cache" =20 let process_entry =3D str_entry "hugetlbfs_mount" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index d26ab4cb57..ace4b20a0c 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -681,6 +681,10 @@ # when 'auto_shutdown_try_shutdown' is enabled #auto_shutdown_wait =3D 30 =20 +# Whether VMs that are automatically shutdown are set to +# automatically restore on next boot +#auto_shutdown_restore =3D 1 + # When a domain is configured to be auto-saved on shutdown, enabling # this flag has the same effect as using the VIR_DOMAIN_SAVE_BYPASS_CACHE # flag with the virDomainManagedSave API. That is, the system will diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index af09920869..458bcb43e6 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -317,6 +317,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privil= eged, cfg->autoShutdownTryShutdown =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_S= COPE_ALL; cfg->autoShutdownPoweroff =3D VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOP= E_ALL; } + cfg->autoShutdownRestore =3D true; =20 return g_steal_pointer(&cfg); } @@ -695,6 +696,8 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *c= fg, if (virConfGetValueInt(conf, "auto_shutdown_wait", &cfg->autoShutdownWait) < 0) return -1; + if (virConfGetValueBool(conf, "auto_shutdown_restore", &cfg->autoShutd= ownRestore) < 0) + return -1; if (virConfGetValueBool(conf, "auto_save_bypass_cache", &cfg->autoSaveBypassCache) < 0) return -1; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 9818a8cbb5..24d7945efb 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -205,6 +205,7 @@ struct _virQEMUDriverConfig { int autoShutdownTryShutdown; int autoShutdownPoweroff; int autoShutdownWait; + bool autoShutdownRestore; bool autoSaveBypassCache; =20 char *lockManagerName; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 84bde503dd..fde6f92761 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -952,6 +952,7 @@ qemuStateStop(void) .poweroff =3D cfg->autoShutdownPoweroff, .waitShutdownSecs =3D cfg->autoShutdownWait, .saveBypassCache =3D cfg->autoSaveBypassCache, + .autoRestore =3D cfg->autoShutdownRestore, }; =20 virDomainDriverAutoShutdown(&ascfg); diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 65d0c20fe1..922cb35db7 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -80,6 +80,7 @@ module Test_libvirtd_qemu =3D { "auto_shutdown_try_shutdown" =3D "all" } { "auto_shutdown_poweroff" =3D "all" } { "auto_shutdown_wait" =3D "30" } +{ "auto_shutdown_restore" =3D "1" } { "auto_save_bypass_cache" =3D "0" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 173636603008596.65348553768024; Wed, 8 Jan 2025 11:53:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0AD8914BC; Wed, 8 Jan 2025 14:53:49 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0926C14D3; Wed, 8 Jan 2025 14:44:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D4DDA141D; Wed, 8 Jan 2025 14:43:58 -0500 (EST) 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 887291441 for ; Wed, 8 Jan 2025 14:43:30 -0500 (EST) 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-353-1bTpjjsDObStiYImB4kwqA-1; Wed, 08 Jan 2025 14:43:28 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 97FAD19560AE for ; Wed, 8 Jan 2025 19:43:27 +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 A53363000199; Wed, 8 Jan 2025 19:43:26 +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_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=1736365410; 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=XIjsi+pt2R/c+xb+tURrlNTgxaI8TSKAEqoQp1CzTjs=; b=OKJMrJo+du/RQIQnIK+WyuUYLq+N/Gh58e4+TBAwyAIfF7lRH/p3V06jrUMhhUOmcA+MrT IG/5Z833b/zQXcm5GqQN3ydLGqkYuXWd1vBYzexdLVSi8Gud74uZUhHCftlE7sObNQ9/Pt I5stpv+jsCRU3yqI1dy14uhc2Pn6Ik4= X-MC-Unique: 1bTpjjsDObStiYImB4kwqA-1 X-Mimecast-MFC-AGG-ID: 1bTpjjsDObStiYImB4kwqA 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 21/26] rpc: move state stop into virNetDaemon class Date: Wed, 8 Jan 2025 19:42:54 +0000 Message-ID: <20250108194259.1171990-22-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: Uhpsn_vfBFlSE9eMKxy6f4E2Deo6_ZcHxHzXGBOBFLI_1736365407 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TFOJWLOQM2QWNVWEWFMDXDTQ5OCOWSHJ X-Message-ID-Hash: TFOJWLOQM2QWNVWEWFMDXDTQ5OCOWSHJ 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: 1736366032488116600 Content-Type: text/plain; charset="utf-8" Currently the remote daemon code is responsible for calling virStateStop in a background thread. The virNetDaemon code wants to synchronize with this during shutdown, however, so the virThreadPtr must be passed over. Even the limited synchronization done currently, however, is flawed and to fix this requires the virNetDaemon code to be responsible for calling virStateStop in a thread more directly. Thus the logic is moved over into virStateStop via a further callback to be registered by the remote daemon. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_remote.syms | 2 +- src/remote/remote_daemon.c | 40 ++------------------------ src/rpc/virnetdaemon.c | 58 ++++++++++++++++++++++++++++---------- src/rpc/virnetdaemon.h | 20 +++++++++++-- 4 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index f0f90815cf..7e87b0bd2a 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -90,12 +90,12 @@ virNetDaemonIsPrivileged; virNetDaemonNew; virNetDaemonNewPostExecRestart; virNetDaemonPreExecRestart; +virNetDaemonPreserve; virNetDaemonQuit; virNetDaemonQuitExecRestart; virNetDaemonRemoveShutdownInhibition; virNetDaemonRun; virNetDaemonSetShutdownCallbacks; -virNetDaemonSetStateStopWorkerThread; virNetDaemonUpdateServices; =20 =20 diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index c4b930cb70..bf91ee5772 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -514,41 +514,6 @@ static void daemonInhibitCallback(bool inhibit, void *= opaque) static GDBusConnection *sessionBus; static GDBusConnection *systemBus; =20 -static void daemonStopWorker(void *opaque) -{ - virNetDaemon *dmn =3D opaque; - - VIR_DEBUG("Begin stop dmn=3D%p", dmn); - - ignore_value(virStateStop()); - - VIR_DEBUG("Completed stop dmn=3D%p", dmn); - - /* Exit daemon cleanly */ - virNetDaemonQuit(dmn); -} - - -/* We do this in a thread to not block the main loop */ -static void daemonStop(virNetDaemon *dmn) -{ - virThread *thr; - virObjectRef(dmn); - - thr =3D g_new0(virThread, 1); - - if (virThreadCreateFull(thr, true, - daemonStopWorker, - "daemon-stop", false, dmn) < 0) { - virObjectUnref(dmn); - g_free(thr); - return; - } - - virNetDaemonSetStateStopWorkerThread(dmn, &thr); -} - - static GDBusMessage * handleSessionMessageFunc(GDBusConnection *connection G_GNUC_UNUSED, GDBusMessage *message, @@ -562,7 +527,7 @@ handleSessionMessageFunc(GDBusConnection *connection G_= GNUC_UNUSED, if (virGDBusMessageIsSignal(message, "org.freedesktop.DBus.Local", "Disconnected")) - daemonStop(dmn); + virNetDaemonPreserve(dmn); =20 return message; } @@ -581,7 +546,7 @@ handleSystemMessageFunc(GDBusConnection *connection G_G= NUC_UNUSED, =20 VIR_DEBUG("dmn=3D%p", dmn); =20 - daemonStop(dmn); + virNetDaemonPreserve(dmn); } =20 =20 @@ -625,6 +590,7 @@ static void daemonRunStateInit(void *opaque) g_atomic_int_set(&driversInitialized, 1); =20 virNetDaemonSetShutdownCallbacks(dmn, + virStateStop, virStateShutdownPrepare, virStateShutdownWait); =20 diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index bb7d2ff9a0..19b19ff834 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -65,9 +65,10 @@ struct _virNetDaemon { GHashTable *servers; virJSONValue *srvObject; =20 + virNetDaemonShutdownCallback shutdownPreserveCb; virNetDaemonShutdownCallback shutdownPrepareCb; virNetDaemonShutdownCallback shutdownWaitCb; - virThread *stateStopThread; + virThread *shutdownPreserveThread; int finishTimer; bool quit; bool finished; @@ -107,7 +108,7 @@ virNetDaemonDispose(void *obj) virEventRemoveHandle(dmn->sigwatch); #endif /* !WIN32 */ =20 - g_free(dmn->stateStopThread); + g_free(dmn->shutdownPreserveThread); =20 g_clear_pointer(&dmn->servers, g_hash_table_unref); =20 @@ -705,8 +706,8 @@ daemonShutdownWait(void *opaque) =20 virHashForEach(dmn->servers, daemonServerShutdownWait, NULL); if (!dmn->shutdownWaitCb || dmn->shutdownWaitCb() >=3D 0) { - if (dmn->stateStopThread) - virThreadJoin(dmn->stateStopThread); + if (dmn->shutdownPreserveThread) + virThreadJoin(dmn->shutdownPreserveThread); =20 graceful =3D true; } @@ -801,17 +802,6 @@ virNetDaemonRun(virNetDaemon *dmn) } =20 =20 -void -virNetDaemonSetStateStopWorkerThread(virNetDaemon *dmn, - virThread **thr) -{ - VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); - - VIR_DEBUG("Setting state stop worker thread on dmn=3D%p to thr=3D%p", = dmn, thr); - dmn->stateStopThread =3D g_steal_pointer(thr); -} - - void virNetDaemonQuit(virNetDaemon *dmn) { @@ -833,6 +823,42 @@ virNetDaemonQuitExecRestart(virNetDaemon *dmn) } =20 =20 +static void virNetDaemonPreserveWorker(void *opaque) +{ + virNetDaemon *dmn =3D opaque; + + VIR_DEBUG("Begin stop dmn=3D%p", dmn); + + dmn->shutdownPreserveCb(); + + VIR_DEBUG("Completed stop dmn=3D%p", dmn); + + virNetDaemonQuit(dmn); + virObjectUnref(dmn); +} + + +void virNetDaemonPreserve(virNetDaemon *dmn) +{ + VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); + + if (!dmn->shutdownPreserveCb || + dmn->shutdownPreserveThread) + return; + + virObjectRef(dmn); + dmn->shutdownPreserveThread =3D g_new0(virThread, 1); + + if (virThreadCreateFull(dmn->shutdownPreserveThread, true, + virNetDaemonPreserveWorker, + "daemon-stop", false, dmn) < 0) { + virObjectUnref(dmn); + g_clear_pointer(&dmn->shutdownPreserveThread, g_free); + return; + } +} + + static int daemonServerClose(void *payload, const char *key G_GNUC_UNUSED, @@ -870,11 +896,13 @@ virNetDaemonHasClients(virNetDaemon *dmn) =20 void virNetDaemonSetShutdownCallbacks(virNetDaemon *dmn, + virNetDaemonShutdownCallback preserveCb, virNetDaemonShutdownCallback prepareCb, virNetDaemonShutdownCallback waitCb) { VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); =20 + dmn->shutdownPreserveCb =3D preserveCb; dmn->shutdownPrepareCb =3D prepareCb; dmn->shutdownWaitCb =3D waitCb; } diff --git a/src/rpc/virnetdaemon.h b/src/rpc/virnetdaemon.h index 31a355adb4..c64f3bdeb1 100644 --- a/src/rpc/virnetdaemon.h +++ b/src/rpc/virnetdaemon.h @@ -66,13 +66,11 @@ int virNetDaemonAddSignalHandler(virNetDaemon *dmn, void virNetDaemonUpdateServices(virNetDaemon *dmn, bool enabled); =20 -void virNetDaemonSetStateStopWorkerThread(virNetDaemon *dmn, - virThread **thr); - void virNetDaemonRun(virNetDaemon *dmn); =20 void virNetDaemonQuit(virNetDaemon *dmn); void virNetDaemonQuitExecRestart(virNetDaemon *dmn); +void virNetDaemonPreserve(virNetDaemon *dmn); =20 bool virNetDaemonHasClients(virNetDaemon *dmn); =20 @@ -84,6 +82,22 @@ bool virNetDaemonHasServer(virNetDaemon *dmn, =20 typedef int (*virNetDaemonShutdownCallback)(void); =20 +/* + * @preserveCb: preserves any active state + * @prepareCb: start shutting down daemon + * @waitCb: wait for shutdown completion + * + * The sequence of operations during shutdown is as follows + * + * - Listener stops accepting new clients + * - Existing clients are closed + * - Delay until @preserveCb is complete (if running) + * - @prepareCb invoked + * - Server worker pool is drained in background + * - @waitCb is invoked in background + * - Main loop terminates + */ void virNetDaemonSetShutdownCallbacks(virNetDaemon *dmn, + virNetDaemonShutdownCallback preserv= eCb, virNetDaemonShutdownCallback prepare= Cb, virNetDaemonShutdownCallback waitCb); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736366047717921.9083328091288; Wed, 8 Jan 2025 11:54:07 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D0E5A1500; Wed, 8 Jan 2025 14:54:06 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DE1CD1311; Wed, 8 Jan 2025 14:44:19 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2C83311AC; Wed, 8 Jan 2025 14:43:59 -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 0E0B81449 for ; Wed, 8 Jan 2025 14:43:31 -0500 (EST) Received: from mx-prod-mc-01.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-448-xaBz7mk8NYqZxYVXiC4UOw-1; Wed, 08 Jan 2025 14:43:29 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D59C41956060 for ; Wed, 8 Jan 2025 19:43:28 +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 08314300018D; Wed, 8 Jan 2025 19:43:27 +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=1736365410; 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=LCxv1P4ZnQDfTYZZZIWKAdXQ4o5+NfNyJ2ds2cvYL9Q=; b=LYzLg+OZG97Sk0Q3DOLc1rVWTfy50yw0ngF65AVO1UH4eEgru/ubKztgKPzmJ9bPmPMWDz Zi2Lh8HVSseeYH1NsXlIJKashBDF2tTLX9WNOZhehB4n3TyKJdNy0rr4Zx6dCVAkzxyBOK Abb/l+hZiVFuhm2ssewoCZx3ya7o7EQ= X-MC-Unique: xaBz7mk8NYqZxYVXiC4UOw-1 X-Mimecast-MFC-AGG-ID: xaBz7mk8NYqZxYVXiC4UOw 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 22/26] rpc: don't unconditionally quit after preserving state Date: Wed, 8 Jan 2025 19:42:55 +0000 Message-ID: <20250108194259.1171990-23-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: QmpgMlQn3At8ClmFmdl6GntFu6i7iQmffHeY2LRRKBo_1736365409 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TRRHFSKFAZKTX47W2STJWIP7OJUZCWB6 X-Message-ID-Hash: TRRHFSKFAZKTX47W2STJWIP7OJUZCWB6 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: 1736366048224116600 Content-Type: text/plain; charset="utf-8" The call to preserve state (ie running VMs) is triggered in response to the desktop session dbus terminating (session daemon), or logind sending a "PrepareForShutdown" signal. In the case of the latter, daemons should only save their state, not actually exit yet. Other things on the system may still expect the daemon to be running at this stage. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon.c | 4 +++- src/rpc/virnetdaemon.c | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index bf91ee5772..e03ee1de5a 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -526,8 +526,10 @@ handleSessionMessageFunc(GDBusConnection *connection G= _GNUC_UNUSED, =20 if (virGDBusMessageIsSignal(message, "org.freedesktop.DBus.Local", - "Disconnected")) + "Disconnected")) { virNetDaemonPreserve(dmn); + virNetDaemonQuit(dmn); + } =20 return message; } diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 19b19ff834..7f14c5420a 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -833,7 +833,6 @@ static void virNetDaemonPreserveWorker(void *opaque) =20 VIR_DEBUG("Completed stop dmn=3D%p", dmn); =20 - virNetDaemonQuit(dmn); virObjectUnref(dmn); } =20 --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736366082892428.7627692193055; Wed, 8 Jan 2025 11:54:42 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E3F861442; Wed, 8 Jan 2025 14:54:41 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 192E814F4; Wed, 8 Jan 2025 14:44:23 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BE87A137A; Wed, 8 Jan 2025 14:44:00 -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 AB5481486 for ; Wed, 8 Jan 2025 14:43:32 -0500 (EST) 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-166-ybu1Enm6MLiX1TSqw7vgqg-1; Wed, 08 Jan 2025 14:43:31 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37DEA1955F3B for ; Wed, 8 Jan 2025 19:43:30 +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 402EF3000199; Wed, 8 Jan 2025 19:43:29 +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=1736365412; 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=sAR/2TRlMpCNXImWb3D2Mk039ZirWkqdWPA91IEFm7U=; b=G/urW0Fg1g5GDo89U7rNZ1JJCsQ1bNI/iQEi8OWhEjYGpnnAy3jCUyacMFsheDQmu1FFPC MGqumUpXfU3QB0S4mQKbYjf4l3hLwqo0RSW8dND9k+rHuW1WVIbVmgtGA2AnsqM2sdrUyu yWo0/f5WTc4d7dS+BzQtV6jMfBvJ1W4= X-MC-Unique: ybu1Enm6MLiX1TSqw7vgqg-1 X-Mimecast-MFC-AGG-ID: ybu1Enm6MLiX1TSqw7vgqg 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 23/26] rpc: fix shutdown sequence when preserving state Date: Wed, 8 Jan 2025 19:42:56 +0000 Message-ID: <20250108194259.1171990-24-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: izrIPjxUTwlAGkegXhCMzAzJ25wKU6aNNF6fJlXctmM_1736365410 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LTH3JGZS3FZR2C5QSSB45GRWFYSA3OUM X-Message-ID-Hash: LTH3JGZS3FZR2C5QSSB45GRWFYSA3OUM 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: 1736366084346116600 Content-Type: text/plain; charset="utf-8" The preserving of state (ie running VMs) requires a fully functional daemon and hypervisor driver. If any part has started shutting down then saving state may fail, or worse, hang. The current shutdown sequence does not guarantee safe ordering, as we synchronize with the state saving thread only after the hypervisor driver has had its 'shutdownPrepare' callback invoked. In the case of QEMU this means that worker threads processing monitor events may well have been stopped. This implements a full state machine that has a well defined ordering that an earlier commit documented as the desired semantics. With this change, nothing will start shutting down if the state saving thread is still running. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon.c | 4 +- src/rpc/virnetdaemon.c | 103 ++++++++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index e03ee1de5a..f64ecad7f5 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -617,8 +617,8 @@ static void daemonRunStateInit(void *opaque) NULL, G_DBUS_SIGNAL_FLAGS_NONE, handleSystemMessageFunc, - dmn, - NULL); + dmn, + NULL); =20 /* Only now accept clients from network */ virNetDaemonUpdateServices(dmn, true); diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 7f14c5420a..d1d7bae569 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -39,6 +39,15 @@ =20 VIR_LOG_INIT("rpc.netdaemon"); =20 +typedef enum { + VIR_NET_DAEMON_QUIT_NONE, + VIR_NET_DAEMON_QUIT_REQUESTED, + VIR_NET_DAEMON_QUIT_PRESERVING, + VIR_NET_DAEMON_QUIT_READY, + VIR_NET_DAEMON_QUIT_WAITING, + VIR_NET_DAEMON_QUIT_COMPLETED, +} virNetDaemonQuitPhase; + #ifndef WIN32 typedef struct _virNetDaemonSignal virNetDaemonSignal; struct _virNetDaemonSignal { @@ -69,9 +78,8 @@ struct _virNetDaemon { virNetDaemonShutdownCallback shutdownPrepareCb; virNetDaemonShutdownCallback shutdownWaitCb; virThread *shutdownPreserveThread; - int finishTimer; - bool quit; - bool finished; + int quitTimer; + virNetDaemonQuitPhase quit; bool graceful; bool execRestart; bool running; /* the daemon has reached the running phase */ @@ -414,7 +422,10 @@ virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSE= D, =20 if (!dmn->autoShutdownInhibitions) { VIR_DEBUG("Automatic shutdown triggered"); - dmn->quit =3D true; + if (dmn->quit =3D=3D VIR_NET_DAEMON_QUIT_NONE) { + VIR_DEBUG("Requesting daemon shutdown"); + dmn->quit =3D VIR_NET_DAEMON_QUIT_REQUESTED; + } } } =20 @@ -705,27 +716,26 @@ daemonShutdownWait(void *opaque) bool graceful =3D false; =20 virHashForEach(dmn->servers, daemonServerShutdownWait, NULL); - if (!dmn->shutdownWaitCb || dmn->shutdownWaitCb() >=3D 0) { - if (dmn->shutdownPreserveThread) - virThreadJoin(dmn->shutdownPreserveThread); - + if (!dmn->shutdownWaitCb || dmn->shutdownWaitCb() >=3D 0) graceful =3D true; - } =20 VIR_WITH_OBJECT_LOCK_GUARD(dmn) { dmn->graceful =3D graceful; - virEventUpdateTimeout(dmn->finishTimer, 0); + dmn->quit =3D VIR_NET_DAEMON_QUIT_COMPLETED; + virEventUpdateTimeout(dmn->quitTimer, 0); + VIR_DEBUG("Shutdown wait completed graceful=3D%d", graceful); } } =20 static void -virNetDaemonFinishTimer(int timerid G_GNUC_UNUSED, - void *opaque) +virNetDaemonQuitTimer(int timerid G_GNUC_UNUSED, + void *opaque) { virNetDaemon *dmn =3D opaque; VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); =20 - dmn->finished =3D true; + dmn->quit =3D VIR_NET_DAEMON_QUIT_COMPLETED; + VIR_DEBUG("Shutdown wait timed out"); } =20 =20 @@ -742,9 +752,8 @@ virNetDaemonRun(virNetDaemon *dmn) goto cleanup; } =20 - dmn->quit =3D false; - dmn->finishTimer =3D -1; - dmn->finished =3D false; + dmn->quit =3D VIR_NET_DAEMON_QUIT_NONE; + dmn->quitTimer =3D -1; dmn->graceful =3D false; dmn->running =3D true; =20 @@ -753,7 +762,7 @@ virNetDaemonRun(virNetDaemon *dmn) virSystemdNotifyReady(); =20 VIR_DEBUG("dmn=3D%p quit=3D%d", dmn, dmn->quit); - while (!dmn->finished) { + while (dmn->quit !=3D VIR_NET_DAEMON_QUIT_COMPLETED) { virNetDaemonShutdownTimerUpdate(dmn); =20 virObjectUnlock(dmn); @@ -767,17 +776,30 @@ virNetDaemonRun(virNetDaemon *dmn) virHashForEach(dmn->servers, daemonServerProcessClients, NULL); =20 /* don't shutdown services when performing an exec-restart */ - if (dmn->quit && dmn->execRestart) + if (dmn->quit =3D=3D VIR_NET_DAEMON_QUIT_REQUESTED && dmn->execRes= tart) goto cleanup; =20 - if (dmn->quit && dmn->finishTimer =3D=3D -1) { + if (dmn->quit =3D=3D VIR_NET_DAEMON_QUIT_REQUESTED) { + VIR_DEBUG("Process quit request"); virHashForEach(dmn->servers, daemonServerClose, NULL); + + if (dmn->shutdownPreserveThread) { + VIR_DEBUG("Shutdown preserve thread running"); + dmn->quit =3D VIR_NET_DAEMON_QUIT_PRESERVING; + } else { + VIR_DEBUG("Ready to shutdown"); + dmn->quit =3D VIR_NET_DAEMON_QUIT_READY; + } + } + + if (dmn->quit =3D=3D VIR_NET_DAEMON_QUIT_READY) { + VIR_DEBUG("Starting shutdown, running prepare"); if (dmn->shutdownPrepareCb && dmn->shutdownPrepareCb() < 0) break; =20 - if ((dmn->finishTimer =3D virEventAddTimeout(30 * 1000, - virNetDaemonFinishT= imer, - dmn, NULL)) < 0) { + if ((dmn->quitTimer =3D virEventAddTimeout(30 * 1000, + virNetDaemonQuitTimer, + dmn, NULL)) < 0) { VIR_WARN("Failed to register finish timer."); break; } @@ -787,6 +809,9 @@ virNetDaemonRun(virNetDaemon *dmn) VIR_WARN("Failed to register join thread."); break; } + + VIR_DEBUG("Waiting for shutdown completion"); + dmn->quit =3D VIR_NET_DAEMON_QUIT_WAITING; } } =20 @@ -808,7 +833,7 @@ virNetDaemonQuit(virNetDaemon *dmn) VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); =20 VIR_DEBUG("Quit requested %p", dmn); - dmn->quit =3D true; + dmn->quit =3D VIR_NET_DAEMON_QUIT_REQUESTED; } =20 =20 @@ -818,7 +843,7 @@ virNetDaemonQuitExecRestart(virNetDaemon *dmn) VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); =20 VIR_DEBUG("Exec-restart requested %p", dmn); - dmn->quit =3D true; + dmn->quit =3D VIR_NET_DAEMON_QUIT_REQUESTED; dmn->execRestart =3D true; } =20 @@ -827,12 +852,21 @@ static void virNetDaemonPreserveWorker(void *opaque) { virNetDaemon *dmn =3D opaque; =20 - VIR_DEBUG("Begin stop dmn=3D%p", dmn); + VIR_DEBUG("Begin preserve dmn=3D%p", dmn); =20 dmn->shutdownPreserveCb(); =20 - VIR_DEBUG("Completed stop dmn=3D%p", dmn); + VIR_DEBUG("Completed preserve dmn=3D%p", dmn); =20 + VIR_WITH_OBJECT_LOCK_GUARD(dmn) { + if (dmn->quit =3D=3D VIR_NET_DAEMON_QUIT_PRESERVING) { + VIR_DEBUG("Marking shutdown as ready"); + dmn->quit =3D VIR_NET_DAEMON_QUIT_READY; + } + g_clear_pointer(&dmn->shutdownPreserveThread, g_free); + } + + VIR_DEBUG("End preserve dmn=3D%p", dmn); virObjectUnref(dmn); } =20 @@ -840,15 +874,26 @@ static void virNetDaemonPreserveWorker(void *opaque) void virNetDaemonPreserve(virNetDaemon *dmn) { VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); + VIR_DEBUG("Preserve state request"); =20 - if (!dmn->shutdownPreserveCb || - dmn->shutdownPreserveThread) + if (!dmn->shutdownPreserveCb) { + VIR_DEBUG("No preserve callback registered"); return; + } + if (dmn->shutdownPreserveThread) { + VIR_DEBUG("Preserve state thread already running"); + return; + } + + if (dmn->quit !=3D VIR_NET_DAEMON_QUIT_NONE) { + VIR_WARN("Already initiated shutdown sequence, unable to preserve = state"); + return; + } =20 virObjectRef(dmn); dmn->shutdownPreserveThread =3D g_new0(virThread, 1); =20 - if (virThreadCreateFull(dmn->shutdownPreserveThread, true, + if (virThreadCreateFull(dmn->shutdownPreserveThread, false, virNetDaemonPreserveWorker, "daemon-stop", false, dmn) < 0) { virObjectUnref(dmn); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736366109130583.1294027960545; Wed, 8 Jan 2025 11:55:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2477C13B3; Wed, 8 Jan 2025 14:55:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B15A513B1; Wed, 8 Jan 2025 14:44:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0D9E91452; Wed, 8 Jan 2025 14:44:02 -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 198B91489 for ; Wed, 8 Jan 2025 14:43:34 -0500 (EST) 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-264-RSyQEZ_DO2OdDuRQDYjxnA-1; Wed, 08 Jan 2025 14:43:32 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5240A19560B0 for ; Wed, 8 Jan 2025 19:43:31 +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 775B0300018D; Wed, 8 Jan 2025 19:43:30 +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=1736365413; 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=AO1qfBGCG9VSI0GAy61IR5y39l9Yxe4wTJsjkgqDCx0=; b=L4cVC/7ptM7sEc0sJMlNV+6Mz4TaUlopuiY0aiVfIbqkJdBSmaao6BTOOLIYAhuuxqAn+1 oHT0ihqZg2vwhNlh88O/nslrQIMCZtbKyZ1Cq5mmoeOvXQ+UoqwLqJGRAYsnaOZcnAdQMr 9dV3VvJiOYnk7Rhbhi1BvBEe8aOGS2o= X-MC-Unique: RSyQEZ_DO2OdDuRQDYjxnA-1 X-Mimecast-MFC-AGG-ID: RSyQEZ_DO2OdDuRQDYjxnA 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 24/26] admin: add 'daemon-shutdown' command Date: Wed, 8 Jan 2025 19:42:57 +0000 Message-ID: <20250108194259.1171990-25-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: -ZcNRJP6mmG0yfzMkrVdC_Tv8fyAMiWt-0RQJ7DrfZc_1736365411 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QFMDI3H5OA7UHNZDKVIEJ4YIWSH43ZZM X-Message-ID-Hash: QFMDI3H5OA7UHNZDKVIEJ4YIWSH43ZZM 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: 1736366110671116600 Content-Type: text/plain; charset="utf-8" The daemons are wired up to shutdown in responsible to UNIX process signals, as well as in response to login1 dbus signals, or loss of desktop session. The latter two options can optionally preserve state (ie running VMs). In non-systemd environments, as well as for testing, it would be useful to have a way to trigger shutdown with state preservation more directly. Thus a new admin protocol API is introduced virAdmConnectDaemonShutdown which will trigger a daemon shutdown, and preserve running VMs if the VIR_DAEMON_SHUTDOWN_PRESERVE flag is set. It has a corresponding 'virt-admin daemon-shutdown [--preserve]' command binding. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/libvirt/libvirt-admin.h | 13 +++++++++ src/admin/admin_protocol.x | 11 +++++++- src/admin/admin_server_dispatch.c | 13 +++++++++ src/admin/libvirt-admin.c | 33 +++++++++++++++++++++++ src/admin/libvirt_admin_public.syms | 5 ++++ src/rpc/virnetdaemon.c | 4 +++ tools/virt-admin.c | 41 +++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admi= n.h index ae4703f89b..1926202e97 100644 --- a/include/libvirt/libvirt-admin.h +++ b/include/libvirt/libvirt-admin.h @@ -484,6 +484,19 @@ int virAdmConnectSetDaemonTimeout(virAdmConnectPtr con= n, unsigned int timeout, unsigned int flags); =20 +/** + * virAdmConnectDaemonShutdownFlags: + * + * Since: 11.0.0 + */ +typedef enum { + /* Preserve state before shutting down daemon (Since: 11.0.0) */ + VIR_DAEMON_SHUTDOWN_PRESERVE =3D (1 << 0), +} virAdmConnectDaemonShutdownFlags; + +int virAdmConnectDaemonShutdown(virAdmConnectPtr conn, + unsigned int flags); + # ifdef __cplusplus } # endif diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x index f3130efd2d..cf5707e62e 100644 --- a/src/admin/admin_protocol.x +++ b/src/admin/admin_protocol.x @@ -219,6 +219,10 @@ struct admin_connect_set_daemon_timeout_args { unsigned int flags; }; =20 +struct admin_connect_daemon_shutdown_args { + unsigned int flags; +}; + /* Define the program number, protocol version and procedure numbers here.= */ const ADMIN_PROGRAM =3D 0x06900690; const ADMIN_PROTOCOL_VERSION =3D 1; @@ -334,5 +338,10 @@ enum admin_procedure { /** * @generate: both */ - ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT =3D 19 + ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT =3D 19, + + /** + * @generate: both + */ + ADMIN_PROC_CONNECT_DAEMON_SHUTDOWN =3D 20 }; diff --git a/src/admin/admin_server_dispatch.c b/src/admin/admin_server_dis= patch.c index ae8a8d4fa6..092cc790e6 100644 --- a/src/admin/admin_server_dispatch.c +++ b/src/admin/admin_server_dispatch.c @@ -474,6 +474,19 @@ adminConnectSetDaemonTimeout(virNetDaemon *dmn, return virNetDaemonAutoShutdown(dmn, timeout); } =20 +static int +adminConnectDaemonShutdown(virNetDaemon *dmn, + unsigned int flags) +{ + virCheckFlags(VIR_DAEMON_SHUTDOWN_PRESERVE, -1); + + if (flags & VIR_DAEMON_SHUTDOWN_PRESERVE) + virNetDaemonPreserve(dmn); + + virNetDaemonQuit(dmn); + + return 0; +} =20 static int adminDispatchConnectGetLoggingOutputs(virNetServer *server G_GNUC_UNUSED, diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c index 3c756eb376..1e2446135c 100644 --- a/src/admin/libvirt-admin.c +++ b/src/admin/libvirt-admin.c @@ -1357,3 +1357,36 @@ virAdmConnectSetDaemonTimeout(virAdmConnectPtr conn, =20 return ret; } + + +/** + * virAdmConnectDaemonShutdown: + * @conn: pointer to an active admin connection + * @flags: optional extra falgs + * + * Trigger shutdown of the daemon, if @flags includes + * VIR_DAEMON_SHUTDOWN_PRESERVE then state will be + * preserved before shutting down + * + * Returns 0 on success, -1 on error. + * + * Since: 11.0.0 + */ +int +virAdmConnectDaemonShutdown(virAdmConnectPtr conn, + unsigned int flags) +{ + int ret; + + VIR_DEBUG("conn=3D%p, flags=3D0x%x", conn, flags); + + virResetLastError(); + virCheckAdmConnectReturn(conn, -1); + + if ((ret =3D remoteAdminConnectDaemonShutdown(conn, flags)) < 0) { + virDispatchError(NULL); + return -1; + } + + return ret; +} diff --git a/src/admin/libvirt_admin_public.syms b/src/admin/libvirt_admin_= public.syms index 17930e4fac..d39656bc53 100644 --- a/src/admin/libvirt_admin_public.syms +++ b/src/admin/libvirt_admin_public.syms @@ -53,3 +53,8 @@ LIBVIRT_ADMIN_8.6.0 { global: virAdmConnectSetDaemonTimeout; } LIBVIRT_ADMIN_3.0.0; + +LIBVIRT_ADMIN_11.0.0 { + global: + virAdmConnectDaemonShutdown; +} LIBVIRT_ADMIN_8.6.0; diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index d1d7bae569..8cc7af1182 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -815,8 +815,10 @@ virNetDaemonRun(virNetDaemon *dmn) } } =20 + VIR_DEBUG("Main loop exited"); if (dmn->graceful) { virThreadJoin(&shutdownThread); + VIR_DEBUG("Graceful shutdown complete"); } else { VIR_WARN("Make forcefull daemon shutdown"); exit(EXIT_FAILURE); @@ -946,6 +948,8 @@ virNetDaemonSetShutdownCallbacks(virNetDaemon *dmn, { VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); =20 + VIR_DEBUG("Shutdown callbacks preserve=3D%p prepare=3D%p wait=3D%p", + preserveCb, prepareCb, waitCb); dmn->shutdownPreserveCb =3D preserveCb; dmn->shutdownPrepareCb =3D prepareCb; dmn->shutdownWaitCb =3D waitCb; diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 325b7aa827..54dc36a564 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1077,6 +1077,41 @@ cmdDaemonTimeout(vshControl *ctl, const vshCmd *cmd) } =20 =20 +/* -------------------------- + * Command daemon-shutdown + * -------------------------- + */ +static const vshCmdInfo info_daemon_shutdown =3D { + .help =3D N_("stop the daemon"), + .desc =3D N_("stop the daemon"), +}; + +static const vshCmdOptDef opts_daemon_shutdown[] =3D { + {.name =3D "preserve", + .type =3D VSH_OT_BOOL, + .required =3D false, + .positional =3D false, + .help =3D N_("preserve state before shutting down"), + }, + {.name =3D NULL} +}; + +static bool +cmdDaemonShutdown(vshControl *ctl, const vshCmd *cmd) +{ + vshAdmControl *priv =3D ctl->privData; + unsigned int flags =3D 0; + + if (vshCommandOptBool(cmd, "preserve")) + flags |=3D VIR_DAEMON_SHUTDOWN_PRESERVE; + + if (virAdmConnectDaemonShutdown(priv->conn, flags) < 0) + return false; + + return true; +} + + static void * vshAdmConnectionHandler(vshControl *ctl) { @@ -1469,6 +1504,12 @@ static const vshCmdDef managementCmds[] =3D { .info =3D &info_daemon_timeout, .flags =3D 0 }, + {.name =3D "daemon-shutdown", + .handler =3D cmdDaemonShutdown, + .opts =3D opts_daemon_shutdown, + .info =3D &info_daemon_shutdown, + .flags =3D 0 + }, {.name =3D NULL} }; =20 --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736366132579397.5926869262613; Wed, 8 Jan 2025 11:55:32 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A14F11576; Wed, 8 Jan 2025 14:55:31 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2374314F5; Wed, 8 Jan 2025 14:44:28 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 72440137A; Wed, 8 Jan 2025 14:44:02 -0500 (EST) 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 DCF7A145E for ; Wed, 8 Jan 2025 14:43:34 -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-119-B_TFWNptMoGeI8tI53LDiA-1; Wed, 08 Jan 2025 14:43:33 -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 9C2A3195609E for ; Wed, 8 Jan 2025 19:43:32 +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 AF20D300018D; Wed, 8 Jan 2025 19:43:31 +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_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=1736365414; 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=13BMsvxHaPqn/D0JnXmEXMtjO5PiJEM69W9JCsO7I0w=; b=hoVToOxEX9bDMwAp+ag3q3xMeprEcqeP/GHoe/RQvEzDpatfCncDrlsYvNcimWZKpY2WxY X69bGE5NoeMc8qouGhsgIQXUjPxx2nwtNVdUHw/KvJ0fvR1xxgWgxTuQBEDPtYiaLiztn/ yqPKvWNoM7naBTT4DJNJQXMxXN4eWis= X-MC-Unique: B_TFWNptMoGeI8tI53LDiA-1 X-Mimecast-MFC-AGG-ID: B_TFWNptMoGeI8tI53LDiA 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 25/26] rpc: don't let systemd shutdown daemon while saving VMs Date: Wed, 8 Jan 2025 19:42:58 +0000 Message-ID: <20250108194259.1171990-26-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: vgjQ5TZDvEu2-cC2Haame1CCQM2U7QDbewHUmCCLNwA_1736365412 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Y76KJ335L2NUA2AMYD7ETDJGUSJKB46E X-Message-ID-Hash: Y76KJ335L2NUA2AMYD7ETDJGUSJKB46E 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: 1736366134551116600 Content-Type: text/plain; charset="utf-8" The service unit "TimeoutStopSec" setting controls how long systemd waits for a service to stop before aggressively killing it, defaulting to 30 seconds if not set. When we're processing shutdown of VMs in response to OS shutdown, we very likely need more than 30 seconds to complete this job, and can not stop the daemon during this time. To avoid being prematurely killed, setup a timer that repeatedly extends the "TimeoutStopSec" value while stop of running VMs is arranged. This does mean if libvirt hangs while stoppping VMs, systemd won't get to kill the libvirt daemon, but this is considered less harmful that forcefully killing running VMs. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/virnetdaemon.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 8cc7af1182..3ddb9b5404 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -78,6 +78,9 @@ struct _virNetDaemon { virNetDaemonShutdownCallback shutdownPrepareCb; virNetDaemonShutdownCallback shutdownWaitCb; virThread *shutdownPreserveThread; + unsigned long long preserveStart; + unsigned int preserveExtended; + int preserveTimer; int quitTimer; virNetDaemonQuitPhase quit; bool graceful; @@ -93,6 +96,14 @@ struct _virNetDaemon { =20 static virClass *virNetDaemonClass; =20 +/* + * The minimum additional shutdown time (secs) we should ask + * systemd to allow, while state preservation operations + * are running. A timer will run every 5 seconds, and + * ensure at least this much extra time is requested + */ +#define VIR_NET_DAEMON_PRESERVE_MIN_TIME 30 + static int daemonServerClose(void *payload, const char *key G_GNUC_UNUSED, @@ -162,6 +173,7 @@ virNetDaemonNew(void) if (virEventRegisterDefaultImpl() < 0) goto error; =20 + dmn->preserveTimer =3D -1; dmn->autoShutdownTimerID =3D -1; =20 #ifndef WIN32 @@ -727,6 +739,42 @@ daemonShutdownWait(void *opaque) } } =20 +static void +virNetDaemonPreserveTimer(int timerid G_GNUC_UNUSED, + void *opaque) +{ + virNetDaemon *dmn =3D opaque; + VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); + unsigned long long now =3D g_get_monotonic_time(); + unsigned long long delta; + + if (dmn->quit !=3D VIR_NET_DAEMON_QUIT_PRESERVING) + return; + + VIR_DEBUG("Started at %llu now %llu extended %u", + dmn->preserveStart, now, dmn->preserveExtended); + + /* Time since start of preserving state in usec */ + delta =3D now - dmn->preserveStart; + /* Converts to secs */ + delta /=3D (1000ull * 1000ull); + + /* Want extra seconds grace to ensure this timer fires + * again before system timeout expires, under high + * load conditions */ + delta +=3D VIR_NET_DAEMON_PRESERVE_MIN_TIME; + + /* Deduct any extension we've previously asked for */ + delta -=3D dmn->preserveExtended; + + /* Tell systemd how much more we need to extend by */ + virSystemdNotifyExtendTimeout(delta); + dmn->preserveExtended +=3D delta; + + VIR_DEBUG("Extended by %llu", delta); +} + + static void virNetDaemonQuitTimer(int timerid G_GNUC_UNUSED, void *opaque) @@ -781,11 +829,21 @@ virNetDaemonRun(virNetDaemon *dmn) =20 if (dmn->quit =3D=3D VIR_NET_DAEMON_QUIT_REQUESTED) { VIR_DEBUG("Process quit request"); + virSystemdNotifyStopping(); virHashForEach(dmn->servers, daemonServerClose, NULL); =20 if (dmn->shutdownPreserveThread) { VIR_DEBUG("Shutdown preserve thread running"); dmn->quit =3D VIR_NET_DAEMON_QUIT_PRESERVING; + dmn->preserveStart =3D g_get_monotonic_time(); + dmn->preserveExtended =3D VIR_NET_DAEMON_PRESERVE_MIN_TIME; + virSystemdNotifyExtendTimeout(dmn->preserveExtended); + if ((dmn->preserveTimer =3D virEventAddTimeout(5 * 1000, + virNetDaemonP= reserveTimer, + dmn, NULL)) <= 0) { + VIR_WARN("Failed to register preservation timer"); + /* hope for the best */ + } } else { VIR_DEBUG("Ready to shutdown"); dmn->quit =3D VIR_NET_DAEMON_QUIT_READY; @@ -866,6 +924,10 @@ static void virNetDaemonPreserveWorker(void *opaque) dmn->quit =3D VIR_NET_DAEMON_QUIT_READY; } g_clear_pointer(&dmn->shutdownPreserveThread, g_free); + if (dmn->preserveTimer !=3D -1) { + virEventRemoveTimeout(dmn->preserveTimer); + dmn->preserveTimer =3D -1; + } } =20 VIR_DEBUG("End preserve dmn=3D%p", dmn); --=20 2.47.1 From nobody Tue Jan 21 04:01:21 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 1736366150384864.9787005219476; Wed, 8 Jan 2025 11:55:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6AFE9139E; Wed, 8 Jan 2025 14:55:49 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E0475145F; Wed, 8 Jan 2025 14:44:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9A3401380; Wed, 8 Jan 2025 14:44:03 -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 6FDA71488 for ; Wed, 8 Jan 2025 14:43:36 -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-44-9beh5W4OND6cO9VFB2EI5g-1; Wed, 08 Jan 2025 14:43:34 -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 C531719560A2 for ; Wed, 8 Jan 2025 19:43:33 +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 D57FC3000199; Wed, 8 Jan 2025 19:43:32 +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=1736365416; 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=Hb/b6zQ1MRKhieNTTNc4AZJTyIlH1DmSyL8FmuqWYRM=; b=fkf5IShijyun7U0FfoAoelzhSeicG5ZDlCxMmPHMhmvRJltdpgr7o3CVMKc5XOpiPrjuez wGA+YT+S6upz5PhF8nozTVFgyS0zPX60xTnCva8jr8FFuYEr+jAa+lh/aSFKuGbUTYxcL0 0LSVYFe+yB7oRjajwskfjgNxH8Osoe0= X-MC-Unique: 9beh5W4OND6cO9VFB2EI5g-1 X-Mimecast-MFC-AGG-ID: 9beh5W4OND6cO9VFB2EI5g 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 26/26] hypervisor: send systemd status messages while saving Date: Wed, 8 Jan 2025 19:42:59 +0000 Message-ID: <20250108194259.1171990-27-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: RJnbk4Ru3cbcQYAsYDiODZpkQRcwVUqautTCyMAK16g_1736365413 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: PTDUG56ZIPJY4JZQDX2FZESC7ZY57IF2 X-Message-ID-Hash: PTDUG56ZIPJY4JZQDX2FZESC7ZY57IF2 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: 1736366152660116600 Content-Type: text/plain; charset="utf-8" Since processing running VMs on OS shutdown can take a while, it is beneficial to send systemd status messages about the progress. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 2f89b8c841..421cc16574 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -30,6 +30,7 @@ #include "datatypes.h" #include "driver.h" #include "virlog.h" +#include "virsystemd.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -791,6 +792,8 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) (!transient[i] && cfg->trySave =3D=3D VIR_DOMAIN_DRIVER_AU= TO_SHUTDOWN_SCOPE_TRANSIENT)) continue; =20 + virSystemdNotifyStatus("Suspending '%s' (%zu of %d)", + virDomainGetName(domains[i]), i + 1, nu= mDomains); /* * Pause all VMs to make them stop dirtying pages, * so save is quicker. We remember if any VMs were @@ -808,6 +811,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) } =20 for (i =3D 0; i < numDomains; i++) { + virSystemdNotifyStatus("Saving '%s' (%zu of %d)", + virDomainGetName(domains[i]), i + 1, nu= mDomains); + if (virDomainManagedSave(domains[i], flags[i]) < 0) { VIR_WARN("Unable to perform managed save of '%s': %s", virDomainGetName(domains[i]), @@ -829,6 +835,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) (!transient[i] && cfg->tryShutdown =3D=3D VIR_DOMAIN_DRIVE= R_AUTO_SHUTDOWN_SCOPE_TRANSIENT)) continue; =20 + virSystemdNotifyStatus("Shutting down '%s' (%zu of %d)", + virDomainGetName(domains[i]), i + 1, nu= mDomains); + if (virDomainShutdown(domains[i]) < 0) { VIR_WARN("Unable to perform graceful shutdown of '%s': %s", virDomainGetName(domains[i]), @@ -838,6 +847,8 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdown= Config *cfg) } =20 timer =3D g_timer_new(); + virSystemdNotifyStatus("Waiting %d secs for VM shutdown completion= ", + cfg->waitShutdownSecs); while (1) { bool anyRunning =3D false; for (i =3D 0; i < numDomains; i++) { @@ -874,10 +885,14 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdo= wnConfig *cfg) (!transient[i] && cfg->poweroff =3D=3D VIR_DOMAIN_DRIVER_A= UTO_SHUTDOWN_SCOPE_TRANSIENT)) continue; =20 + virSystemdNotifyStatus("Destroying '%s' (%zu of %d)", + virDomainGetName(domains[i]), i + 1, nu= mDomains); virDomainDestroy(domains[i]); } } =20 + virSystemdNotifyStatus("Processed %d domains", numDomains); + cleanup: if (domains) { for (i =3D 0; i < numDomains; i++) { --=20 2.47.1