]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: add x-systemd.before and x-systemd.after fstab options (#5330)
authorRuslan Bilovol <ruslan.bilovol@gmail.com>
Mon, 13 Feb 2017 19:50:22 +0000 (21:50 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 13 Feb 2017 19:50:22 +0000 (20:50 +0100)
Currently fstab entries with 'nofail' option are mounted
asynchronously and there is no way how to specify dependencies
between such fstab entry and another units. It means that
users are forced to write additional dependency units manually.

The patch introduces new systemd fstab options:

x-systemd.before=<PATH>
x-systemd.after=<PATH>

 - to specify another mount dependency (PATH is translated to unit name)

x-systemd.before=<UNIT>
x-systemd.after=<UNIT>

 - to specify arbitrary UNIT dependency

For example mount where A should be mounted before local-fs.target unit:

 /dev/sdb1    /mnt/test/A     none    nofail,x-systemd.before=local-fs.target

man/systemd.mount.xml
src/fstab-generator/fstab-generator.c

index bb372d788a39f4deefda025bcbad482cda937529..598b5772fd5d2dcdcc3c8b7e2ea7691568c6e789 100644 (file)
         for details.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>x-systemd.before=</option></term>
+        <term><option>x-systemd.after=</option></term>
+
+        <listitem><para>Configures a <varname>Before=</varname>
+        dependency or <varname>After=</varname> between the created
+        mount unit and another systemd unit, such as a mount unit.
+        The argument should be a unit name or an absolute path
+        to a mount point. This option may be specified more than once.
+        This option is particularly useful for mount point declarations
+        with <option>nofail</option> option that are mounted
+        asynchronously but need to be mounted before or after some unit
+        start, for example, before <filename>local-fs.target</filename>
+        unit.
+        See <varname>Before=</varname> and <varname>After=</varname> in
+        <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+        for details.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>x-systemd.requires-mounts-for=</option></term>
 
index d97bafd1fb2a58a4f1506ad78a0195456d9d88b0..c38a5aa2572a43c06e5a667f7e31e51b7c91de4b 100644 (file)
@@ -209,7 +209,8 @@ static int write_mount_timeout(FILE *f, const char *where, const char *opts) {
                              "x-systemd.mount-timeout\0", "TimeoutSec");
 }
 
-static int write_requires_after(FILE *f, const char *opts) {
+static int write_dependency(FILE *f, const char *opts,
+                const char *filter, const char *format) {
         _cleanup_strv_free_ char **names = NULL, **units = NULL;
         _cleanup_free_ char *res = NULL;
         char **s;
@@ -218,7 +219,7 @@ static int write_requires_after(FILE *f, const char *opts) {
         assert(f);
         assert(opts);
 
-        r = fstab_extract_values(opts, "x-systemd.requires", &names);
+        r = fstab_extract_values(opts, filter, &names);
         if (r < 0)
                 return log_warning_errno(r, "Failed to parse options: %m");
         if (r == 0)
@@ -239,12 +240,26 @@ static int write_requires_after(FILE *f, const char *opts) {
                 res = strv_join(units, " ");
                 if (!res)
                         return log_oom();
-                fprintf(f, "After=%1$s\nRequires=%1$s\n", res);
+                fprintf(f, format, res);
         }
 
         return 0;
 }
 
+static int write_after(FILE *f, const char *opts) {
+        return write_dependency(f, opts, "x-systemd.after", "After=%1$s\n");
+}
+
+static int write_requires_after(FILE *f, const char *opts) {
+        return write_dependency(f, opts,
+                                "x-systemd.requires", "After=%1$s\nRequires=%1$s\n");
+}
+
+static int write_before(FILE *f, const char *opts) {
+        return write_dependency(f, opts,
+                                "x-systemd.before", "Before=%1$s\n");
+}
+
 static int write_requires_mounts_for(FILE *f, const char *opts) {
         _cleanup_strv_free_ char **paths = NULL;
         _cleanup_free_ char *res = NULL;
@@ -344,7 +359,13 @@ static int add_mount(
                 fprintf(f, "Before=%s\n", post);
 
         if (!automount && opts) {
+                 r = write_after(f, opts);
+                 if (r < 0)
+                         return r;
                  r = write_requires_after(f, opts);
+                 if (r < 0)
+                         return r;
+                 r = write_before(f, opts);
                  if (r < 0)
                          return r;
                  r = write_requires_mounts_for(f, opts);
@@ -421,7 +442,13 @@ static int add_mount(
                 fprintf(f, "Before=%s\n", post);
 
                 if (opts) {
+                        r = write_after(f, opts);
+                        if (r < 0)
+                                return r;
                         r = write_requires_after(f, opts);
+                        if (r < 0)
+                                return r;
+                        r = write_before(f, opts);
                         if (r < 0)
                                 return r;
                         r = write_requires_mounts_for(f, opts);