]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount: make unit_start() mount ratelimiting check generic 28211/head
authorLennart Poettering <lennart@poettering.net>
Fri, 30 Jun 2023 13:56:40 +0000 (15:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 30 Jun 2023 20:01:02 +0000 (22:01 +0200)
Let's move this into a vtable callout, so that unit.c doesn't check for
explicit unit types anymore.

(This is preparation for a future where we do a similar check for the
automount logic, or the swap logic.)

src/core/mount.c
src/core/unit.c
src/core/unit.h

index 1424ad2bf474aea8752dab3b11d5f1e04c3f848d..765c9899ef6cd90512628b4714b1731348e6e56d 100644 (file)
@@ -2299,6 +2299,15 @@ static int mount_can_start(Unit *u) {
         return 1;
 }
 
+static int mount_subsystem_ratelimited(Manager *m) {
+        assert(m);
+
+        if (!m->mount_event_source)
+                return false;
+
+        return sd_event_source_is_ratelimited(m->mount_event_source);
+}
+
 static const char* const mount_exec_command_table[_MOUNT_EXEC_COMMAND_MAX] = {
         [MOUNT_EXEC_MOUNT]   = "ExecMount",
         [MOUNT_EXEC_UNMOUNT] = "ExecUnmount",
@@ -2379,6 +2388,7 @@ const UnitVTable mount_vtable = {
         .enumerate_perpetual = mount_enumerate_perpetual,
         .enumerate = mount_enumerate,
         .shutdown = mount_shutdown,
+        .subsystem_ratelimited = mount_subsystem_ratelimited,
 
         .status_message_formats = {
                 .starting_stopping = {
index 6e0702a87420509675467b7dfb1291133888b7d5..5904c9f4b598c4a5749f2c73a077685024e1fb4c 100644 (file)
@@ -1920,9 +1920,14 @@ int unit_start(Unit *u, ActivationDetails *details) {
 
         assert(u);
 
-        /* Let's hold off running start jobs for mount units when /proc/self/mountinfo monitor is rate limited. */
-        if (u->type == UNIT_MOUNT && sd_event_source_is_ratelimited(u->manager->mount_event_source))
-                return -EAGAIN;
+        /* Let's hold off running start jobs for mount units when /proc/self/mountinfo monitor is ratelimited. */
+        if (UNIT_VTABLE(u)->subsystem_ratelimited) {
+                r = UNIT_VTABLE(u)->subsystem_ratelimited(u->manager);
+                if (r < 0)
+                        return r;
+                if (r > 0)
+                        return -EAGAIN;
+        }
 
         /* If this is already started, then this will succeed. Note that this will even succeed if this unit
          * is not startable by the user. This is relied on to detect when we need to wait for units and when
index 3a7330c24ff954c507dc635c8a210407ae2af769..c0710299a54a964b68fb9284b97049876c8ddaa6 100644 (file)
@@ -756,6 +756,10 @@ typedef struct UnitVTable {
          * limiting checks to occur before we do anything else. */
         int (*can_start)(Unit *u);
 
+        /* Returns > 0 if the whole subsystem is ratelimited, and new start operations should not be started
+         * for this unit type right now. */
+        int (*subsystem_ratelimited)(Manager *m);
+
         /* The strings to print in status messages */
         UnitStatusMessageFormats status_message_formats;