]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/cgroup: skip freezer action wholly if current == objective
authorMike Yuan <me@yhndnzj.com>
Sat, 25 May 2024 10:46:55 +0000 (18:46 +0800)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Jul 2025 11:08:03 +0000 (13:08 +0200)
(cherry picked from commit a9dc19617943d1db4f137005f5e467188c66e5a9)

src/core/cgroup.c

index 54bf353f0ae5b0fe76f14800a5f19523f548376c..f6bf8d6e7463f1a17fe2b4074ed1b8b84149d5cb 100644 (file)
@@ -5136,19 +5136,18 @@ int unit_cgroup_freezer_action(Unit *u, FreezerAction action) {
         unit_next_freezer_state(u, action, &next, &objective);
 
         CGroupRuntime *crt = unit_get_cgroup_runtime(u);
-        if (!crt || !crt->cgroup_path) {
+        if (!crt || !crt->cgroup_path)
                 /* No realized cgroup = nothing to freeze */
-                u->freezer_state = freezer_state_finish(next);
-                return 0;
-        }
+                goto skip;
 
         r = unit_cgroup_freezer_kernel_state(u, &current);
         if (r < 0)
                 return r;
 
         if (current == objective)
-                next = freezer_state_finish(next);
-        else if (next == freezer_state_finish(next)) {
+                goto skip;
+
+        if (next == freezer_state_finish(next)) {
                 /* We're directly transitioning into a finished state, which in theory means that
                  * the cgroup's current state already matches the objective and thus we'd return 0.
                  * But, reality shows otherwise (such case would have been handled by current == objective
@@ -5166,6 +5165,8 @@ int unit_cgroup_freezer_action(Unit *u, FreezerAction action) {
                         next = FREEZER_FREEZING_BY_PARENT;
                 else if (next == FREEZER_RUNNING)
                         next = FREEZER_THAWING;
+                else
+                        assert_not_reached();
         }
 
         r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, "cgroup.freeze", &path);
@@ -5181,7 +5182,11 @@ int unit_cgroup_freezer_action(Unit *u, FreezerAction action) {
                 return r;
 
         u->freezer_state = next;
-        return current != objective;
+        return 1; /* Wait for cgroup event before replying */
+
+skip:
+        u->freezer_state = freezer_state_finish(next);
+        return 0;
 }
 
 int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) {