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

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