From nobody Tue Jan 21 07:36:38 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