From nobody Tue Jan 21 07:34:09 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