core: when isolating to a unit, also keep units running that are triggered by units we keep running

Signed-off-by: zhaoxiaohu <zhaoxiaohu@kuaishou.com>
This commit is contained in:
zhaoxiaohu 2024-08-28 20:10:41 +08:00 committed by zhangyao
parent 67dca7721d
commit c1e2e5ce0b
2 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,84 @@
From 74e95a3ccec4ce594618190c9eed7d97c287eafd Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Fri, 10 Feb 2023 13:38:08 +0100
Subject: [PATCH] core: when isolating to a unit, also keep units running that
are triggered by units we keep running
Inspired by: #26364
(this might even "fix" #26364, but without debug logs it's hard to make
such claims)
Fixes: #23055
Reference: https://github.com/systemd/systemd/pull/26388/commits/06543a608a7d6ef1b8264ddfe3657c43ece96fc3
Signed-off-by: zhaoxiaohu <zhaoxiaohu@kuaishou.com>
Signed-off-by: yuwang <yuwang@kuaishou.com>
---
src/core/transaction.c | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/core/transaction.c b/src/core/transaction.c
index d6b7af2..8a9b233 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -1104,6 +1104,20 @@ fail:
return r;
}
+static bool shall_stop_on_isolate(Transaction *tr, Unit *u) {
+ assert(tr);
+ assert(u);
+
+ if (u->ignore_on_isolate)
+ return false;
+
+ /* Is there already something listed for this? */
+ if (hashmap_get(tr->jobs, u))
+ return false;
+
+ return true;
+}
+
int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
Unit *u;
char *k;
@@ -1113,20 +1127,27 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
assert(m);
HASHMAP_FOREACH_KEY(u, k, m->units) {
+ Unit *o;
- /* ignore aliases */
+ /* Ignore aliases */
if (u->id != k)
continue;
- if (u->ignore_on_isolate)
+ /* No need to stop inactive units */
+ if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
continue;
- /* No need to stop inactive jobs */
- if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
+ if (!shall_stop_on_isolate(tr, u))
continue;
- /* Is there already something listed for this? */
- if (hashmap_get(tr->jobs, u))
+ /* Keep units that are triggered by units we want to keep around. */
+ bool keep = false;
+ UNIT_FOREACH_DEPENDENCY(o, u, UNIT_ATOM_TRIGGERED_BY)
+ if (!shall_stop_on_isolate(tr, o)) {
+ keep = true;
+ break;
+ }
+ if (keep)
continue;
r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, NULL);
--
2.33.0

View File

@ -25,7 +25,7 @@
Name: systemd Name: systemd
Url: https://systemd.io/ Url: https://systemd.io/
Version: 249 Version: 249
Release: 89 Release: 90
License: MIT and LGPLv2+ and GPLv2+ License: MIT and LGPLv2+ and GPLv2+
Summary: System and Service Manager Summary: System and Service Manager
@ -686,6 +686,7 @@ Patch6633: backport-import-use-CURLOPT_PROTOCOLS_STR-with-libcurl-7.85.0.pa
Patch6634: backport-man-fix-directory-for-user-home-bind-mounts.patch Patch6634: backport-man-fix-directory-for-user-home-bind-mounts.patch
Patch6635: backport-nspawn-fix-directory-in-logged-error.patch Patch6635: backport-nspawn-fix-directory-in-logged-error.patch
Patch6636: backport-test-boot-timestamp-Handle-ERANGE-error.patch Patch6636: backport-test-boot-timestamp-Handle-ERANGE-error.patch
Patch6637: backport-core-when-isolating-to-a-unit-also-keep-units-runnin.patch
Patch9001: update-rtc-with-system-clock-when-shutdown.patch Patch9001: update-rtc-with-system-clock-when-shutdown.patch
Patch9002: udev-add-actions-while-rename-netif-failed.patch Patch9002: udev-add-actions-while-rename-netif-failed.patch
@ -2200,6 +2201,9 @@ grep -q -E '^KEYMAP="?fi-latin[19]"?' /etc/vconsole.conf 2>/dev/null &&
/usr/bin/systemd-cryptenroll /usr/bin/systemd-cryptenroll
%changelog %changelog
* Wed Dec 04 2024 zhangyao <zhangyao108@huawei.com> - 249-90
- add backport-core-when-isolating-to-a-unit-also-keep-units-runnin.patch
* Tue Dec 3 2024 zhangyao <zhangyao108@huawei.com> - 249-89 * Tue Dec 3 2024 zhangyao <zhangyao108@huawei.com> - 249-89
- add backport-man-fix-directory-for-user-home-bind-mounts.patch - add backport-man-fix-directory-for-user-home-bind-mounts.patch
backport-nspawn-fix-directory-in-logged-error.patch backport-nspawn-fix-directory-in-logged-error.patch