mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
mount: make unit_start() mount ratelimiting check generic
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.)
This commit is contained in:
parent
56d83b74d4
commit
472619672a
@ -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 = {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user