diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-04 16:32:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-25 18:28:44 +0100 |
commit | 4950591627de2e859fb5fd1ae6d67e9c2e1b395e (patch) | |
tree | 94fd8b819585369d4ea9ec54834cf4177043782c /src/home/homed-manager.c | |
parent | d357b80d331ebed709b7a9d71e014c319ba5bd79 (diff) | |
download | systemd-4950591627de2e859fb5fd1ae6d67e9c2e1b395e.tar.gz |
homed: add explicit API for requesting rebalancing too
Diffstat (limited to 'src/home/homed-manager.c')
-rw-r--r-- | src/home/homed-manager.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 3851234a37..3e5bd9c29d 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1985,6 +1985,24 @@ static int manager_rebalance_apply(Manager *m) { return c; } +static void manager_rebalance_reply_messages(Manager *m) { + int r; + + assert(m); + + for (;;) { + _cleanup_(sd_bus_message_unrefp) sd_bus_message *msg = + set_steal_first(m->rebalance_pending_method_calls); + + if (!msg) + break; + + r = sd_bus_reply_method_return(msg, NULL); + if (r < 0) + log_debug_errno(r, "Failed to reply to rebalance method call, ignoring: %m"); + } +} + static int manager_rebalance_now(Manager *m) { RebalanceState busy_state; /* the state to revert to when operation fails if busy */ int r; @@ -2006,6 +2024,13 @@ static int manager_rebalance_now(Manager *m) { /* First shrink large home dirs */ m->rebalance_state = REBALANCE_SHRINKING; busy_state = REBALANCE_PENDING; + + /* We are initiating the next rebalancing cycle now, let's make the queued methods + * calls the pending ones, and flush out any pending ones (which shouldn't exist at + * this time anyway) */ + set_clear(m->rebalance_pending_method_calls); + SWAP_TWO(m->rebalance_pending_method_calls, m->rebalance_queued_method_calls); + log_debug("Shrinking phase.."); break; @@ -2055,6 +2080,7 @@ static int manager_rebalance_now(Manager *m) { finish: /* Reset state and schedule next rebalance */ m->rebalance_state = REBALANCE_IDLE; + manager_rebalance_reply_messages(m); (void) manager_schedule_rebalance(m, /* immediately= */ false); return r; } @@ -2078,6 +2104,7 @@ int manager_schedule_rebalance(Manager *m, bool immediately) { /* Check if there are any records where rebalancing is requested */ if (!manager_shall_rebalance(m)) { log_debug("Not scheduling rebalancing, not needed."); + r = 0; /* report that we didn't schedule anything because nothing needed it */ goto turn_off; } @@ -2118,13 +2145,13 @@ int manager_schedule_rebalance(Manager *m, bool immediately) { m->rebalance_state = REBALANCE_PENDING; log_debug("Scheduled immediate rebalancing..."); - return 0; + return 1; /* report that we scheduled something */ } /* If we are told to schedule a rebalancing eventually, then do so only if we are not executing * anything yet. Also if we have something scheduled already, leave it in place */ if (!IN_SET(m->rebalance_state, REBALANCE_OFF, REBALANCE_IDLE)) - return 0; + return 1; /* report that there's already something scheduled */ if (m->rebalance_event_source) { r = sd_event_source_set_time_relative(m->rebalance_event_source, m->rebalance_interval_usec); @@ -2156,11 +2183,12 @@ int manager_schedule_rebalance(Manager *m, bool immediately) { m->rebalance_state = REBALANCE_WAITING; /* We managed to enqueue a timer event, we now wait until it fires */ log_debug("Scheduled rebalancing in %s...", FORMAT_TIMESPAN(m->rebalance_interval_usec, 0)); - return 0; + return 1; /* report that we scheduled something */ turn_off: m->rebalance_event_source = sd_event_source_disable_unref(m->rebalance_event_source); m->rebalance_state = REBALANCE_OFF; + manager_rebalance_reply_messages(m); return r; } |