8f24f2
From 4dbe6568d5bcc082b13f3ef4d323d1669f16095c Mon Sep 17 00:00:00 2001
8f24f2
From: Michal Sekletar <msekleta@redhat.com>
8f24f2
Date: Mon, 30 May 2022 11:55:41 +0200
8f24f2
Subject: [PATCH] unit: check for mount rate limiting before checking active
8f24f2
 state
8f24f2
8f24f2
Having this check as part of mount_can_start() is too late because
8f24f2
UNIT(u)->can_start() virtual method is called after checking the active
8f24f2
state of unit in unit_start().
8f24f2
8f24f2
We need to hold off running mount start jobs when /p/s/mountinfo monitor
8f24f2
is rate limited even when given mount unit is already active.
8f24f2
8f24f2
Fixes #20329
8f24f2
8f24f2
(cherry picked from commit b161bc394b2cc8b271dda9208e310cc2af0cc29d)
8f24f2
8f24f2
Resolves: #2095744
8f24f2
---
8f24f2
 src/core/mount.c | 3 ---
8f24f2
 src/core/unit.c  | 4 ++++
8f24f2
 2 files changed, 4 insertions(+), 3 deletions(-)
8f24f2
8f24f2
diff --git a/src/core/mount.c b/src/core/mount.c
8f24f2
index 9547cb9b29..d37b5731f8 100644
8f24f2
--- a/src/core/mount.c
8f24f2
+++ b/src/core/mount.c
8f24f2
@@ -1999,9 +1999,6 @@ static int mount_can_start(Unit *u) {
8f24f2
 
8f24f2
         assert(m);
8f24f2
 
8f24f2
-        if (sd_event_source_is_ratelimited(u->manager->mount_event_source))
8f24f2
-                return -EAGAIN;
8f24f2
-
8f24f2
         r = unit_test_start_limit(u);
8f24f2
         if (r < 0) {
8f24f2
                 mount_enter_dead(m, MOUNT_FAILURE_START_LIMIT_HIT);
8f24f2
diff --git a/src/core/unit.c b/src/core/unit.c
8f24f2
index c00d30e837..0810bf5a58 100644
8f24f2
--- a/src/core/unit.c
8f24f2
+++ b/src/core/unit.c
8f24f2
@@ -1729,6 +1729,10 @@ int unit_start(Unit *u) {
8f24f2
 
8f24f2
         assert(u);
8f24f2
 
8f24f2
+        /* Let's hold off running start jobs for mount units when /proc/self/mountinfo monitor is rate limited. */
8f24f2
+        if (u->type == UNIT_MOUNT && sd_event_source_is_ratelimited(u->manager->mount_event_source))
8f24f2
+                return -EAGAIN;
8f24f2
+
8f24f2
         /* If this is already started, then this will succeed. Note that this will even succeed if this unit
8f24f2
          * is not startable by the user. This is relied on to detect when we need to wait for units and when
8f24f2
          * waiting is finished. */