diff options
author | Karel Zak <kzak@redhat.com> | 2015-05-25 12:11:23 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-05-25 17:06:15 +0200 |
commit | bf1d7ba70aceddb5dae0cd2e370b8afaf0c81b05 (patch) | |
tree | 76ad4d459f83627376e4d21fd651d44637f6bf90 /src/fstab-generator/fstab-generator.c | |
parent | 49f582c0a09100e7b282a32af2b2da66828ddcde (diff) | |
download | systemd-bf1d7ba70aceddb5dae0cd2e370b8afaf0c81b05.tar.gz |
swap: use swapon -o
This patch simplify swapon usage in systemd. The command swapon(8)
since util-linux v2.26 supports "-o <list>". The idea is exactly the
same like for mount(8). The -o specifies options in fstab-compatible
way. For systemd it means that it does not have to care about things
like "discard" or another swapon specific options.
swapon -o <options-from-fstab>
For backward compatibility the code cares about "Priority:" swap unit
field (for a case when Priority: is set, but pri= in the Options: is
missing).
References: http://lists.freedesktop.org/archives/systemd-devel/2014-October/023576.html
Diffstat (limited to 'src/fstab-generator/fstab-generator.c')
-rw-r--r-- | src/fstab-generator/fstab-generator.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 302fad37bb..a88b68e2c0 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -53,10 +53,9 @@ static int add_swap( bool noauto, bool nofail) { - _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *filtered = NULL; + _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL; _cleanup_fclose_ FILE *f = NULL; - int r, pri = -1; - const char *opts; + int r; assert(what); assert(me); @@ -71,18 +70,6 @@ static int add_swap( return 0; } - opts = me->mnt_opts; - r = fstab_find_pri(opts, &pri); - if (r < 0) { - log_error_errno(r, "Failed to parse priority, ignoring: %m"); - - /* Remove invalid pri field */ - r = fstab_filter_options(opts, "pri\0", NULL, NULL, &filtered); - if (r < 0) - return log_error_errno(r, "Failed to parse options: %m"); - opts = filtered; - } - r = unit_name_from_path(what, ".swap", &name); if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); @@ -109,20 +96,15 @@ static int add_swap( "What=%s\n", what); - /* Note that we currently pass the priority field twice, once - * in Priority=, and once in Options= */ - if (pri >= 0) - fprintf(f, "Priority=%i\n", pri); - - if (!isempty(opts) && !streq(opts, "defaults")) - fprintf(f, "Options=%s\n", opts); + if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults")) + fprintf(f, "Options=%s\n", me->mnt_opts); r = fflush_and_check(f); if (r < 0) return log_error_errno(r, "Failed to write unit file %s: %m", unit); /* use what as where, to have a nicer error message */ - r = generator_write_timeouts(arg_dest, what, what, opts, NULL); + r = generator_write_timeouts(arg_dest, what, what, me->mnt_opts, NULL); if (r < 0) return r; |