dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
3d3dc8
From b0c226e9fd3e6bfa5388832cc2745d9ec935f3ec Mon Sep 17 00:00:00 2001
3d3dc8
From: Michal Sekletar <msekleta@redhat.com>
3d3dc8
Date: Mon, 4 Oct 2021 20:31:49 +0200
3d3dc8
Subject: [PATCH] mount: retrigger run queue after ratelimit expired to run
3d3dc8
 delayed mount start jobs
3d3dc8
3d3dc8
Fixes #20329
3d3dc8
3d3dc8
(cherry picked from commit edc027b4f1cfaa49e8ecdde763eb8c623402d464)
3d3dc8
3d3dc8
Related: #2036608
3d3dc8
---
3d3dc8
 src/core/mount.c | 21 +++++++++++++++++++++
3d3dc8
 1 file changed, 21 insertions(+)
3d3dc8
3d3dc8
diff --git a/src/core/mount.c b/src/core/mount.c
3d3dc8
index ab09e6fbb0..bdba9e6884 100644
3d3dc8
--- a/src/core/mount.c
3d3dc8
+++ b/src/core/mount.c
3d3dc8
@@ -1710,6 +1710,21 @@ static bool mount_is_mounted(Mount *m) {
3d3dc8
         return UNIT(m)->perpetual || m->is_mounted;
3d3dc8
 }
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
+
3d3dc8
+        return 0;
3d3dc8
+}
3d3dc8
+
3d3dc8
 static void mount_enumerate(Manager *m) {
3d3dc8
         int r;
3d3dc8
 
3d3dc8
@@ -1763,6 +1778,12 @@ static void mount_enumerate(Manager *m) {
3d3dc8
                         goto fail;
3d3dc8
                 }
3d3dc8
 
3d3dc8
+                r = sd_event_source_set_ratelimit_expire_callback(m->mount_event_source, mount_on_ratelimit_expire);
3d3dc8
+                if (r < 0) {
3d3dc8
+                         log_error_errno(r, "Failed to enable rate limit for mount events: %m");
3d3dc8
+                         goto fail;
3d3dc8
+                }
3d3dc8
+
3d3dc8
                 (void) sd_event_source_set_description(m->mount_event_source, "mount-monitor-dispatch");
3d3dc8
         }
3d3dc8