summaryrefslogtreecommitdiffstats
path: root/src/home/homectl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-04 17:38:13 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-25 18:28:44 +0100
commit6d6d4459ab969cfd0b6fcb7afea1c76496f8788a (patch)
tree3d2b84ffb0283c7b02ae1be65f71bc67ff03f714 /src/home/homectl.c
parenthomed: add explicit API for requesting rebalancing too (diff)
downloadsystemd-6d6d4459ab969cfd0b6fcb7afea1c76496f8788a.tar.xz
systemd-6d6d4459ab969cfd0b6fcb7afea1c76496f8788a.zip
homectl: add new "homectl rebalance" command
Let's add an explicit, synchronous command to request immediate rebalancing and wait for it.
Diffstat (limited to 'src/home/homectl.c')
-rw-r--r--src/home/homectl.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/home/homectl.c b/src/home/homectl.c
index 0c69299c84..6057c04bae 100644
--- a/src/home/homectl.c
+++ b/src/home/homectl.c
@@ -2103,6 +2103,32 @@ static int deactivate_all_homes(int argc, char *argv[], void *userdata) {
return 0;
}
+static int rebalance(int argc, char *argv[], void *userdata) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+ int r;
+
+ r = acquire_bus(&bus);
+ if (r < 0)
+ return r;
+
+ r = bus_message_new_method_call(bus, &m, bus_mgr, "Rebalance");
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_call(bus, m, HOME_SLOW_BUS_CALL_TIMEOUT_USEC, &error, NULL);
+ if (r < 0) {
+ if (sd_bus_error_has_name(&error, BUS_ERROR_REBALANCE_NOT_NEEDED))
+ log_info("No homes needed rebalancing.");
+ else
+ return log_error_errno(r, "Failed to rebalance: %s", bus_error_message(&error, r));
+ } else
+ log_info("Completed rebalancing.");
+
+ return 0;
+}
+
static int drop_from_identity(const char *field) {
int r;
@@ -2157,6 +2183,7 @@ static int help(int argc, char *argv[], void *userdata) {
" unlock USER… Unlock a temporarily locked home area\n"
" lock-all Lock all suitable home areas\n"
" deactivate-all Deactivate all active home areas\n"
+ " rebalance Rebalance free space between home areas\n"
" with USER [COMMAND…] Run shell or command with access to a home area\n"
"\n%4$sOptions:%5$s\n"
" -h --help Show this help\n"
@@ -3746,6 +3773,7 @@ static int run(int argc, char *argv[]) {
{ "with", 2, VERB_ANY, 0, with_home },
{ "lock-all", VERB_ANY, 1, 0, lock_all_homes },
{ "deactivate-all", VERB_ANY, 1, 0, deactivate_all_homes },
+ { "rebalance", VERB_ANY, 1, 0, rebalance },
{}
};