diff --git a/man/systemd-mount.xml b/man/systemd-mount.xml
index 40dc70fe702..a27326d2460 100644
--- a/man/systemd-mount.xml
+++ b/man/systemd-mount.xml
@@ -264,6 +264,21 @@
supported.
+
+
+
+
+ Unload the transient unit after it completed, even if it failed. Normally, without this option,
+ all mount units that mount and failed are kept in memory until the user explicitly resets their failure state with
+ systemctl reset-failed or an equivalent command. On the other hand, units that stopped
+ successfully are unloaded immediately. If this option is turned on the "garbage collection" of units is more
+ agressive, and unloads units regardless if they exited successfully or failed. This option is a shortcut for
+ --property=CollectMode=inactive-or-failed, see the explanation for
+ CollectMode= in
+ systemd.unit5 for further
+ information.
+
+
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
index 79dab5037a2..3a659654c25 100644
--- a/src/mount/mount-tool.c
+++ b/src/mount/mount-tool.c
@@ -68,6 +68,7 @@ static bool arg_timeout_idle_set = false;
static char **arg_automount_property = NULL;
static int arg_bind_device = -1;
static bool arg_fsck = true;
+static bool arg_aggressive_gc = false;
static void help(void) {
printf("systemd-mount [OPTIONS...] WHAT [WHERE]\n"
@@ -95,7 +96,8 @@ static void help(void) {
" Set automount unit property\n"
" --bind-device Bind automount unit to device\n"
" --list List mountable block devices\n"
- " -u --umount Unmount mount points\n",
+ " -u --umount Unmount mount points\n"
+ " -G --collect Unload unit after it stopped, even when failed\n",
program_invocation_short_name,
streq(program_invocation_short_name, "systemd-umount") ? "" : "--umount ");
}
@@ -145,6 +147,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "list", no_argument, NULL, ARG_LIST },
{ "umount", no_argument, NULL, 'u' },
{ "unmount", no_argument, NULL, 'u' },
+ { "collect", no_argument, NULL, 'G' },
{},
};
@@ -156,7 +159,7 @@ static int parse_argv(int argc, char *argv[]) {
if (strstr(program_invocation_short_name, "systemd-umount"))
arg_action = ACTION_UMOUNT;
- while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:Au", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:AuG", options, NULL)) >= 0)
switch (c) {
@@ -271,6 +274,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_action = ACTION_UMOUNT;
break;
+ case 'G':
+ arg_aggressive_gc = true;
+ break;
+
case '?':
return -EINVAL;
@@ -410,6 +417,12 @@ static int transient_unit_set_properties(sd_bus_message *m, char **properties) {
return r;
}
+ if (arg_aggressive_gc) {
+ r = sd_bus_message_append(m, "(sv)", "CollectMode", "s", "inactive-or-failed");
+ if (r < 0)
+ return r;
+ }
+
r = bus_append_unit_property_assignment_many(m, properties);
if (r < 0)
return r;