mount: add "-G" as shortcut for "--property=CollectMode=inactive-or-failed"

This commit is contained in:
Yu Watanabe 2017-11-16 15:40:25 +09:00
parent 83123ab8fd
commit dc3364832c
2 changed files with 30 additions and 2 deletions

View file

@ -264,6 +264,21 @@
supported.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-G</option></term>
<term><option>--collect</option></term>
<listitem><para>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
<command>systemctl reset-failed</command> 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
<command>--property=CollectMode=inactive-or-failed</command>, see the explanation for
<varname>CollectMode=</varname> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for further
information.</para></listitem>
</varlistentry>
<xi:include href="user-system-options.xml" xpointer="user" />
<xi:include href="user-system-options.xml" xpointer="system" />
<xi:include href="user-system-options.xml" xpointer="host" />

View file

@ -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;