anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0752-pid1-rename-unit_check_gc-to-unit_may_gc.patch

923a60
From 1716821fc5b93667a0bf821b25905de00818aec9 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Tue, 13 Feb 2018 10:50:13 +0100
923a60
Subject: [PATCH] pid1: rename unit_check_gc to unit_may_gc
923a60
923a60
"check" is unclear: what is true, what is false? Let's rename to "can_gc" and
923a60
revert the return value ("positive" values are easier to grok).
923a60
923a60
v2:
923a60
- rename from unit_can_gc to unit_may_gc
923a60
923a60
(cherry picked from commit f2f725e5cc950e84ebfd09bd64bc01c0ebdb6734)
923a60
923a60
Related: #1718953
923a60
---
923a60
 src/core/automount.c | 13 ++++++++-----
923a60
 src/core/manager.c   |  2 +-
923a60
 src/core/mount.c     |  9 ++++++---
923a60
 src/core/scope.c     |  8 ++++----
923a60
 src/core/service.c   |  8 ++++----
923a60
 src/core/socket.c    |  6 +++---
923a60
 src/core/socket.h    |  4 ++--
923a60
 src/core/swap.c      |  9 ++++++---
923a60
 src/core/unit.c      | 31 +++++++++++++++++--------------
923a60
 src/core/unit.h      |  9 ++++-----
923a60
 10 files changed, 55 insertions(+), 44 deletions(-)
923a60
923a60
diff --git a/src/core/automount.c b/src/core/automount.c
923a60
index 590b1952e0..2d6f5f3a77 100644
923a60
--- a/src/core/automount.c
923a60
+++ b/src/core/automount.c
923a60
@@ -934,13 +934,16 @@ static const char *automount_sub_state_to_string(Unit *u) {
923a60
         return automount_state_to_string(AUTOMOUNT(u)->state);
923a60
 }
923a60
 
923a60
-static bool automount_check_gc(Unit *u) {
923a60
+static bool automount_may_gc(Unit *u) {
923a60
+        Unit *t;
923a60
+
923a60
         assert(u);
923a60
 
923a60
-        if (!UNIT_TRIGGER(u))
923a60
-                return false;
923a60
+        t = UNIT_TRIGGER(u);
923a60
+        if (!t)
923a60
+                return true;
923a60
 
923a60
-        return UNIT_VTABLE(UNIT_TRIGGER(u))->check_gc(UNIT_TRIGGER(u));
923a60
+        return UNIT_VTABLE(t)->may_gc(t);
923a60
 }
923a60
 
923a60
 static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, void *userdata) {
923a60
@@ -1113,7 +1116,7 @@ const UnitVTable automount_vtable = {
923a60
         .active_state = automount_active_state,
923a60
         .sub_state_to_string = automount_sub_state_to_string,
923a60
 
923a60
-        .check_gc = automount_check_gc,
923a60
+        .may_gc = automount_may_gc,
923a60
 
923a60
         .reset_failed = automount_reset_failed,
923a60
 
923a60
diff --git a/src/core/manager.c b/src/core/manager.c
923a60
index 3bca61d0b1..9dfdd67860 100644
923a60
--- a/src/core/manager.c
923a60
+++ b/src/core/manager.c
923a60
@@ -871,7 +871,7 @@ static void unit_gc_sweep(Unit *u, unsigned gc_marker) {
923a60
         if (u->in_cleanup_queue)
923a60
                 goto bad;
923a60
 
923a60
-        if (unit_check_gc(u))
923a60
+        if (!unit_may_gc(u))
923a60
                 goto good;
923a60
 
923a60
         u->gc_marker = gc_marker + GC_OFFSET_IN_PATH;
923a60
diff --git a/src/core/mount.c b/src/core/mount.c
923a60
index c7aed2333f..8a25ebd163 100644
923a60
--- a/src/core/mount.c
923a60
+++ b/src/core/mount.c
923a60
@@ -1180,12 +1180,15 @@ _pure_ static const char *mount_sub_state_to_string(Unit *u) {
923a60
         return mount_state_to_string(MOUNT(u)->state);
923a60
 }
923a60
 
923a60
-_pure_ static bool mount_check_gc(Unit *u) {
923a60
+_pure_ static bool mount_may_gc(Unit *u) {
923a60
         Mount *m = MOUNT(u);
923a60
 
923a60
         assert(m);
923a60
 
923a60
-        return m->from_proc_self_mountinfo;
923a60
+        if (m->from_proc_self_mountinfo)
923a60
+                return false;
923a60
+
923a60
+        return true;
923a60
 }
923a60
 
923a60
 static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
923a60
@@ -1954,7 +1957,7 @@ const UnitVTable mount_vtable = {
923a60
         .active_state = mount_active_state,
923a60
         .sub_state_to_string = mount_sub_state_to_string,
923a60
 
923a60
-        .check_gc = mount_check_gc,
923a60
+        .may_gc = mount_may_gc,
923a60
 
923a60
         .sigchld_event = mount_sigchld_event,
923a60
 
923a60
diff --git a/src/core/scope.c b/src/core/scope.c
923a60
index 29954ba285..e9b45aa3f8 100644
923a60
--- a/src/core/scope.c
923a60
+++ b/src/core/scope.c
923a60
@@ -381,7 +381,7 @@ static int scope_deserialize_item(Unit *u, const char *key, const char *value, F
923a60
         return 0;
923a60
 }
923a60
 
923a60
-static bool scope_check_gc(Unit *u) {
923a60
+static bool scope_may_gc(Unit *u) {
923a60
         assert(u);
923a60
 
923a60
         /* Never clean up scopes that still have a process around,
923a60
@@ -392,10 +392,10 @@ static bool scope_check_gc(Unit *u) {
923a60
 
923a60
                 r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, true);
923a60
                 if (r <= 0)
923a60
-                        return true;
923a60
+                        return false;
923a60
         }
923a60
 
923a60
-        return false;
923a60
+        return true;
923a60
 }
923a60
 
923a60
 static void scope_notify_cgroup_empty_event(Unit *u) {
923a60
@@ -547,7 +547,7 @@ const UnitVTable scope_vtable = {
923a60
         .active_state = scope_active_state,
923a60
         .sub_state_to_string = scope_sub_state_to_string,
923a60
 
923a60
-        .check_gc = scope_check_gc,
923a60
+        .may_gc = scope_may_gc,
923a60
 
923a60
         .sigchld_event = scope_sigchld_event,
923a60
 
923a60
diff --git a/src/core/service.c b/src/core/service.c
923a60
index 957c6f37cc..69ec916f2d 100644
923a60
--- a/src/core/service.c
923a60
+++ b/src/core/service.c
923a60
@@ -2436,7 +2436,7 @@ static const char *service_sub_state_to_string(Unit *u) {
923a60
         return service_state_to_string(SERVICE(u)->state);
923a60
 }
923a60
 
923a60
-static bool service_check_gc(Unit *u) {
923a60
+static bool service_may_gc(Unit *u) {
923a60
         Service *s = SERVICE(u);
923a60
 
923a60
         assert(s);
923a60
@@ -2446,9 +2446,9 @@ static bool service_check_gc(Unit *u) {
923a60
         if (cgroup_good(s) > 0 ||
923a60
             main_pid_good(s) > 0 ||
923a60
             control_pid_good(s) > 0)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
-        return false;
923a60
+        return true;
923a60
 }
923a60
 
923a60
 _pure_ static bool service_check_snapshot(Unit *u) {
923a60
@@ -3461,7 +3461,7 @@ const UnitVTable service_vtable = {
923a60
         .active_state = service_active_state,
923a60
         .sub_state_to_string = service_sub_state_to_string,
923a60
 
923a60
-        .check_gc = service_check_gc,
923a60
+        .may_gc = service_may_gc,
923a60
         .check_snapshot = service_check_snapshot,
923a60
 
923a60
         .sigchld_event = service_sigchld_event,
923a60
diff --git a/src/core/socket.c b/src/core/socket.c
923a60
index efefe7ce5d..3e4cdd467f 100644
923a60
--- a/src/core/socket.c
923a60
+++ b/src/core/socket.c
923a60
@@ -2269,12 +2269,12 @@ const char* socket_port_type_to_string(SocketPort *p) {
923a60
         }
923a60
 }
923a60
 
923a60
-_pure_ static bool socket_check_gc(Unit *u) {
923a60
+_pure_ static bool socket_may_gc(Unit *u) {
923a60
         Socket *s = SOCKET(u);
923a60
 
923a60
         assert(u);
923a60
 
923a60
-        return s->n_connections > 0;
923a60
+        return s->n_connections == 0;
923a60
 }
923a60
 
923a60
 static int socket_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
923a60
@@ -2713,7 +2713,7 @@ const UnitVTable socket_vtable = {
923a60
         .active_state = socket_active_state,
923a60
         .sub_state_to_string = socket_sub_state_to_string,
923a60
 
923a60
-        .check_gc = socket_check_gc,
923a60
+        .may_gc = socket_may_gc,
923a60
 
923a60
         .sigchld_event = socket_sigchld_event,
923a60
 
923a60
diff --git a/src/core/socket.h b/src/core/socket.h
923a60
index a2e08998c0..cc1428b3f7 100644
923a60
--- a/src/core/socket.h
923a60
+++ b/src/core/socket.h
923a60
@@ -114,8 +114,8 @@ struct Socket {
923a60
         ExecRuntime *exec_runtime;
923a60
 
923a60
         /* For Accept=no sockets refers to the one service we'll
923a60
-        activate. For Accept=yes sockets is either NULL, or filled
923a60
-        when the next service we spawn. */
923a60
+         * activate. For Accept=yes sockets is either NULL, or filled
923a60
+         * to refer to the next service we spawn. */
923a60
         UnitRef service;
923a60
 
923a60
         SocketState state, deserialized_state;
923a60
diff --git a/src/core/swap.c b/src/core/swap.c
923a60
index e71de4e657..1f69736aa3 100644
923a60
--- a/src/core/swap.c
923a60
+++ b/src/core/swap.c
923a60
@@ -949,12 +949,15 @@ _pure_ static const char *swap_sub_state_to_string(Unit *u) {
923a60
         return swap_state_to_string(SWAP(u)->state);
923a60
 }
923a60
 
923a60
-_pure_ static bool swap_check_gc(Unit *u) {
923a60
+_pure_ static bool swap_may_gc(Unit *u) {
923a60
         Swap *s = SWAP(u);
923a60
 
923a60
         assert(s);
923a60
 
923a60
-        return s->from_proc_swaps;
923a60
+        if (s->from_proc_swaps)
923a60
+                return false;
923a60
+
923a60
+        return true;
923a60
 }
923a60
 
923a60
 static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
923a60
@@ -1497,7 +1500,7 @@ const UnitVTable swap_vtable = {
923a60
         .active_state = swap_active_state,
923a60
         .sub_state_to_string = swap_sub_state_to_string,
923a60
 
923a60
-        .check_gc = swap_check_gc,
923a60
+        .may_gc = swap_may_gc,
923a60
 
923a60
         .sigchld_event = swap_sigchld_event,
923a60
 
923a60
diff --git a/src/core/unit.c b/src/core/unit.c
923a60
index b004aa8fcd..1b8ec9a20e 100644
923a60
--- a/src/core/unit.c
923a60
+++ b/src/core/unit.c
923a60
@@ -282,15 +282,19 @@ int unit_set_description(Unit *u, const char *description) {
923a60
         return 0;
923a60
 }
923a60
 
923a60
-bool unit_check_gc(Unit *u) {
923a60
+bool unit_may_gc(Unit *u) {
923a60
         UnitActiveState state;
923a60
         assert(u);
923a60
 
923a60
+        /* Checks whether the unit is ready to be unloaded for garbage collection.
923a60
+         * Returns true when the unit may be collected, and false if there's some
923a60
+         * reason to keep it loaded. */
923a60
+
923a60
         if (u->job)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
         if (u->nop_job)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
         state = unit_active_state(u);
923a60
 
923a60
@@ -303,22 +307,21 @@ bool unit_check_gc(Unit *u) {
923a60
         /* But we keep the unit object around for longer when it is
923a60
          * referenced or configured to not be gc'ed */
923a60
         if (state != UNIT_INACTIVE)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
         if (UNIT_VTABLE(u)->no_gc)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
         if (u->no_gc)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
         if (u->refs)
923a60
-                return true;
923a60
+                return false;
923a60
 
923a60
-        if (UNIT_VTABLE(u)->check_gc)
923a60
-                if (UNIT_VTABLE(u)->check_gc(u))
923a60
-                        return true;
923a60
+        if (UNIT_VTABLE(u)->may_gc && !UNIT_VTABLE(u)->may_gc(u))
923a60
+                return false;
923a60
 
923a60
-        return false;
923a60
+        return true;
923a60
 }
923a60
 
923a60
 void unit_add_to_load_queue(Unit *u) {
923a60
@@ -348,7 +351,7 @@ void unit_add_to_gc_queue(Unit *u) {
923a60
         if (u->in_gc_queue || u->in_cleanup_queue)
923a60
                 return;
923a60
 
923a60
-        if (unit_check_gc(u))
923a60
+        if (!unit_may_gc(u))
923a60
                 return;
923a60
 
923a60
         LIST_PREPEND(gc_queue, u->manager->gc_queue, u);
923a60
@@ -888,7 +891,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
923a60
                 "%s\tActive Enter Timestamp: %s\n"
923a60
                 "%s\tActive Exit Timestamp: %s\n"
923a60
                 "%s\tInactive Enter Timestamp: %s\n"
923a60
-                "%s\tGC Check Good: %s\n"
923a60
+                "%s\tMay GC: %s\n"
923a60
                 "%s\tNeed Daemon Reload: %s\n"
923a60
                 "%s\tTransient: %s\n"
923a60
                 "%s\tSlice: %s\n"
923a60
@@ -905,7 +908,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
923a60
                 prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->active_enter_timestamp.realtime)),
923a60
                 prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->active_exit_timestamp.realtime)),
923a60
                 prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->inactive_enter_timestamp.realtime)),
923a60
-                prefix, yes_no(unit_check_gc(u)),
923a60
+                prefix, yes_no(unit_may_gc(u)),
923a60
                 prefix, yes_no(unit_need_daemon_reload(u)),
923a60
                 prefix, yes_no(u->transient),
923a60
                 prefix, strna(unit_slice_name(u)),
923a60
diff --git a/src/core/unit.h b/src/core/unit.h
923a60
index 091ef7596e..3f411a1793 100644
923a60
--- a/src/core/unit.h
923a60
+++ b/src/core/unit.h
923a60
@@ -353,10 +353,9 @@ struct UnitVTable {
923a60
          * unit is in. */
923a60
         const char* (*sub_state_to_string)(Unit *u);
923a60
 
923a60
-        /* Return true when there is reason to keep this entry around
923a60
-         * even nothing references it and it isn't active in any
923a60
-         * way */
923a60
-        bool (*check_gc)(Unit *u);
923a60
+        /* Return false when there is a reason to prevent this unit from being gc'ed
923a60
+         * even though nothing references it and it isn't active in any way. */
923a60
+        bool (*may_gc)(Unit *u);
923a60
 
923a60
         /* When the unit is not running and no job for it queued we
923a60
          * shall release its runtime resources */
923a60
@@ -496,7 +495,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c);
923a60
 int unit_choose_id(Unit *u, const char *name);
923a60
 int unit_set_description(Unit *u, const char *description);
923a60
 
923a60
-bool unit_check_gc(Unit *u);
923a60
+bool unit_may_gc(Unit *u);
923a60
 
923a60
 void unit_add_to_load_queue(Unit *u);
923a60
 void unit_add_to_dbus_queue(Unit *u);