From nobody Sun Dec 14 06:37: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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1751547197; cv=none; d=zohomail.com; s=zohoarc; b=Hdx2UQRok059LQo7KTk6jnSONEkDYBVvzYqeu5D2u+9N1X1Qxz1IPxjqKkqH1y2km58WyEBIabwLkflLZ2G/LrI63tb1KcOasurP8uqnA2CXmdmip9ShJIyEhsS9GjpRvBb8AGHNYNWbX6faG+bUJZZRJ4/7qm7CHfHt8ebAs2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751547197; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=+KvD0DePf0D6pFkl5mLm/d9pibNfU4jrYCNg06uuOfc=; b=aToo3lfi7vgTYXQP2S9Z0XoftDeHA3xQsJ1WZ4p9hi5J/r/j+qtpTXHVQp8ebXPjW/feBVX0Cqhw7DgBeXBcXWg8mi7Apkm9QdoN+EryIuLaP+yUzOZ9tFzm9h9gznr+/DZgDDvYVT8FEjVoxPC3Uyjo1XQ9MbJBxTPi8jkizfg= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1751547197271219.33535849788996; Thu, 3 Jul 2025 05:53:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3644912AC; Thu, 3 Jul 2025 08:53:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 37BF31358; Thu, 3 Jul 2025 08:51:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 165391279; Thu, 3 Jul 2025 08:50:55 -0400 (EDT) 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 3325212C7 for ; Thu, 3 Jul 2025 08:50:45 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-28-PRU8xw1qNwCQQB37svCb_A-1; Thu, 03 Jul 2025 08:50:43 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 A3D7218DA5C7 for ; Thu, 3 Jul 2025 12:50:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DC514195608F for ; Thu, 3 Jul 2025 12:50:41 +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=2.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751547044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cYe7PdRdt+ahv3Ql4nykgGTczjf2w7ZcUGnI0NSEeGc=; b=OAvqXpKEdCjlH854z0K73r6qP/KilWJFNo8moXRjzKOJu8rphqHmdiU8ZLKag4zLtspr/6 dj3XVOIOe0AXhb8pj15vUXCjmOUWm8lJloJcSDJsyeQGPIfrVMWO8jrUNqGtJkOAKxqqBd GLW7LmmIGmbbWcKgQTvWLmhq10/azFs= X-MC-Unique: PRU8xw1qNwCQQB37svCb_A-1 X-Mimecast-MFC-AGG-ID: PRU8xw1qNwCQQB37svCb_A_1751547042 To: devel@lists.libvirt.org Subject: [PATCH 05/10] virSystemdCreateMachine: Add flag to invert machined unit dependencies Date: Thu, 3 Jul 2025 14:50:28 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: LoJ-68Jamt1q7OgPagiBdGz3qZPjwQjjeVIbF6_Qqs8_1751547042 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EQU6IOAHWDHXA5RBEGPFBTOBPI6G7F7K X-Message-ID-Hash: EQU6IOAHWDHXA5RBEGPFBTOBPI6G7F7K X-MailFrom: pkrempa@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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751547199061116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa The existing dependency order of the 'machined' unit file for the domain we're starting ("After libvirtd/virtqemud"->thus shuts down *before* the daemon) is intended to work with 'libvirt-guests.service' which requires the daemon to be around to shut down the VMs. If we want to use the integrated auto shutdown done by the daemon itself we need to be able to instruct the domains (thus the corresponding machined units to shut down *after* virtqemud/libvirt. This means that we need to be able to invert the ordering relationship to "Before". This patch adds a parameter to virSystemdCreateMachine so that when starting the VM we'll be able to tell the daemon to use the proper relationship. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/util/vircgroup.c | 3 ++- src/util/virsystemd.c | 27 +++++++++++++++++++++------ src/util/virsystemd.h | 3 ++- tests/virsystemdtest.c | 15 +++++++++------ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 1daa95e178..fc5dca4858 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1293,7 +1293,8 @@ virCgroupNewMachineSystemd(const char *name, nnicindexes, nicindexes, partition, - maxthreads)) < 0) + maxthreads, + false)) < 0) return rv; if (controllers !=3D -1) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 4f8424ae32..bd174c683e 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -358,6 +358,8 @@ virSystemdGetMachineUnitByPID(pid_t pid) * @nicindexes: list of network interface indexes * @partition: name of the slice to place the machine in * @maxthreads: maximum number of threads the VM process can use + * @daemonDomainShutdown: shutdown of domains on host shutdown is done by = the + * daemon instead of the libvirt-guests script * * Returns 0 on success, -1 on fatal error, or -2 if systemd-machine is no= t available */ @@ -370,7 +372,8 @@ int virSystemdCreateMachine(const char *name, size_t nnicindexes, int *nicindexes, const char *partition, - unsigned int maxthreads) + unsigned int maxthreads, + bool daemonDomainShutdown) { int rc; GDBusConnection *conn; @@ -462,11 +465,23 @@ int virSystemdCreateMachine(const char *name, uuid, 16, sizeof(unsigned char)); gnicindexes =3D g_variant_new_fixed_array(G_VARIANT_TYPE("i"), nicindexes, nnicindexes, s= izeof(int)); - gprops =3D g_variant_new_parsed("[('Slice', <%s>)," - " ('After', <['libvirtd.service', %s= ]>)," - " ('Before', <['virt-guest-shutdown.= target']>)]", - slicename, - servicename); + + if (daemonDomainShutdown) { + /* When domains are shut down by the daemon rather than the + * "libvirt-guests" script we need ensure that their unit + * is ordered so that it's shutdown after the libvirt daemon i= tself */ + gprops =3D g_variant_new_parsed("[('Slice', <%s>)," + " ('Before', <['libvirtd.service= ', %s]>)]", + slicename, + servicename); + } else { + gprops =3D g_variant_new_parsed("[('Slice', <%s>)," + " ('After', <['libvirtd.service'= , %s]>)," + " ('Before', <['virt-guest-shutd= own.target']>)]", + slicename, + servicename); + } + message =3D g_variant_new("(s@ayssus@ai@a(sv))", name, guuid, diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index 98460dbc3a..620d9a9645 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -40,7 +40,8 @@ int virSystemdCreateMachine(const char *name, size_t nnicindexes, int *nicindexes, const char *partition, - unsigned int maxthreads); + unsigned int maxthreads, + bool daemonDomainShutdown); int virSystemdTerminateMachine(const char *name); diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 004b0549ce..24c118a409 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -170,7 +170,8 @@ static int testCreateContainer(const void *opaque G_GNU= C_UNUSED) 123, true, 0, NULL, - "highpriority.slice", 0) < 0) { + "highpriority.slice", 0, + false) < 0) { fprintf(stderr, "%s", "Failed to create LXC machine\n"); return -1; } @@ -203,7 +204,9 @@ static int testCreateMachine(const void *opaque G_GNUC_= UNUSED) 123, false, 0, NULL, - NULL, 0) < 0) { + NULL, + 0, + true) < 0) { fprintf(stderr, "%s", "Failed to create KVM machine\n"); return -1; } @@ -240,7 +243,7 @@ static int testCreateNoSystemd(const void *opaque G_GNU= C_UNUSED) 123, false, 0, NULL, - NULL, 0)) =3D=3D 0) { + NULL, 0, false)) =3D=3D 0) { g_unsetenv("FAIL_NO_SERVICE"); fprintf(stderr, "%s", "Unexpected create machine success\n"); return -1; @@ -274,7 +277,7 @@ static int testCreateSystemdNotRunning(const void *opaq= ue G_GNUC_UNUSED) 123, false, 0, NULL, - NULL, 0)) =3D=3D 0) { + NULL, 0, false)) =3D=3D 0) { g_unsetenv("FAIL_NOT_REGISTERED"); fprintf(stderr, "%s", "Unexpected create machine success\n"); return -1; @@ -308,7 +311,7 @@ static int testCreateBadSystemd(const void *opaque G_GN= UC_UNUSED) 123, false, 0, NULL, - NULL, 0)) =3D=3D 0) { + NULL, 0, false)) =3D=3D 0) { g_unsetenv("FAIL_BAD_SERVICE"); fprintf(stderr, "%s", "Unexpected create machine success\n"); return -1; @@ -343,7 +346,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_= UNUSED) 123, true, nnicindexes, nicindexes, - "highpriority.slice", 2) < 0) { + "highpriority.slice", 2, false) < 0) { fprintf(stderr, "%s", "Failed to create LXC machine\n"); return -1; } --=20 2.49.0