dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
3d3dc8
From 5a218b6820be7ffaf21cd42cd4c96b47d18442ee Mon Sep 17 00:00:00 2001
3d3dc8
From: Lennart Poettering <lennart@poettering.net>
3d3dc8
Date: Fri, 12 Nov 2021 09:43:07 +0100
3d3dc8
Subject: [PATCH] pid1: add a manager_trigger_run_queue() helper
3d3dc8
3d3dc8
We have two different places where we re-trigger the run queue now.
3d3dc8
let's unify it under a common function, that is part of the Manager
3d3dc8
code.
3d3dc8
3d3dc8
Follow-up for #20953
3d3dc8
3d3dc8
(cherry picked from commit b0c4b2824693fe6a27ea9439ec7a6328a0e23704)
3d3dc8
3d3dc8
Related: #2036608
3d3dc8
---
3d3dc8
 src/core/job.c     |  5 ++---
3d3dc8
 src/core/manager.c | 12 ++++++++++++
3d3dc8
 src/core/manager.h |  2 ++
3d3dc8
 src/core/mount.c   |  9 +++------
3d3dc8
 4 files changed, 19 insertions(+), 9 deletions(-)
3d3dc8
3d3dc8
diff --git a/src/core/job.c b/src/core/job.c
3d3dc8
index 43ab55ed18..55f36b928f 100644
3d3dc8
--- a/src/core/job.c
3d3dc8
+++ b/src/core/job.c
3d3dc8
@@ -1139,11 +1139,10 @@ void job_add_to_run_queue(Job *j) {
3d3dc8
         if (j->in_run_queue)
3d3dc8
                 return;
3d3dc8
 
3d3dc8
-        if (!j->manager->run_queue)
3d3dc8
-                sd_event_source_set_enabled(j->manager->run_queue_event_source, SD_EVENT_ONESHOT);
3d3dc8
-
3d3dc8
         LIST_PREPEND(run_queue, j->manager->run_queue, j);
3d3dc8
         j->in_run_queue = true;
3d3dc8
+
3d3dc8
+        manager_trigger_run_queue(j->manager);
3d3dc8
 }
3d3dc8
 
3d3dc8
 void job_add_to_dbus_queue(Job *j) {
3d3dc8
diff --git a/src/core/manager.c b/src/core/manager.c
3d3dc8
index ee976f70b3..845c26f498 100644
3d3dc8
--- a/src/core/manager.c
3d3dc8
+++ b/src/core/manager.c
3d3dc8
@@ -2120,6 +2120,18 @@ static int manager_dispatch_run_queue(sd_event_source *source, void *userdata) {
3d3dc8
         return 1;
3d3dc8
 }
3d3dc8
 
3d3dc8
+void manager_trigger_run_queue(Manager *m) {
3d3dc8
+        int r;
3d3dc8
+
3d3dc8
+        assert(m);
3d3dc8
+
3d3dc8
+        r = sd_event_source_set_enabled(
3d3dc8
+                        m->run_queue_event_source,
3d3dc8
+                        m->run_queue ? SD_EVENT_ONESHOT: SD_EVENT_OFF);
3d3dc8
+        if (r < 0)
3d3dc8
+                log_warning_errno(r, "Failed to enable job run queue event source, ignoring: %m");
3d3dc8
+}
3d3dc8
+
3d3dc8
 static unsigned manager_dispatch_dbus_queue(Manager *m) {
3d3dc8
         unsigned n = 0, budget;
3d3dc8
         Unit *u;
3d3dc8
diff --git a/src/core/manager.h b/src/core/manager.h
3d3dc8
index c4b8e80093..7b572c8dfd 100644
3d3dc8
--- a/src/core/manager.h
3d3dc8
+++ b/src/core/manager.h
3d3dc8
@@ -416,6 +416,8 @@ unsigned manager_dispatch_load_queue(Manager *m);
3d3dc8
 int manager_environment_add(Manager *m, char **minus, char **plus);
3d3dc8
 int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit);
3d3dc8
 
3d3dc8
+void manager_trigger_run_queue(Manager *m);
3d3dc8
+
3d3dc8
 int manager_loop(Manager *m);
3d3dc8
 
3d3dc8
 int manager_open_serialization(Manager *m, FILE **_f);
3d3dc8
diff --git a/src/core/mount.c b/src/core/mount.c
3d3dc8
index bdba9e6884..c17154cde1 100644
3d3dc8
--- a/src/core/mount.c
3d3dc8
+++ b/src/core/mount.c
3d3dc8
@@ -1712,15 +1712,12 @@ static bool mount_is_mounted(Mount *m) {
3d3dc8
 
3d3dc8
 static int mount_on_ratelimit_expire(sd_event_source *s, void *userdata) {
3d3dc8
         Manager *m = userdata;
3d3dc8
-        int r;
3d3dc8
 
3d3dc8
         assert(m);
3d3dc8
 
3d3dc8
-        /* By entering ratelimited state we made all mount start jobs not runnable, now rate limit is over so let's
3d3dc8
-         * make sure we dispatch them in the next iteration. */
3d3dc8
-        r = sd_event_source_set_enabled(m->run_queue_event_source, SD_EVENT_ONESHOT);
3d3dc8
-        if (r < 0)
3d3dc8
-                log_debug_errno(r, "Failed to enable run queue event source, ignoring: %m");
3d3dc8
+        /* By entering ratelimited state we made all mount start jobs not runnable, now rate limit is over so
3d3dc8
+         * let's make sure we dispatch them in the next iteration. */
3d3dc8
+        manager_trigger_run_queue(m);
3d3dc8
 
3d3dc8
         return 0;
3d3dc8
 }