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