1 From 568f3f41b734f410dcd1913e25b57dde17959233 Mon Sep 17 00:00:00 2001
2 From: Dennis Groenen <tj.groenen@gmail.com>
3 Date: Sun, 4 Aug 2013 14:00:59 +0200
4 Subject: [PATCH] swapon: adhere swap priority in fstab
6 We already had the mount opts from fstab, but didn't do anything with them.
8 Check mnt_opts and set g_flags accordingly prior to enabling the swapspace when
11 Signed-off-by: Dennis Groenen <tj.groenen at gmail.com>
13 util-linux/Config.src | 5 +++--
14 util-linux/swaponoff.c | 13 +++++++++++++
15 2 files changed, 16 insertions(+), 2 deletions(-)
17 diff --git a/util-linux/Config.src b/util-linux/Config.src
18 index 5a8b006..b90873d 100644
19 --- a/util-linux/Config.src
20 +++ b/util-linux/Config.src
21 @@ -600,11 +600,12 @@ config SWAPONOFF
24 config FEATURE_SWAPON_PRI
25 - bool "Support priority option -p"
26 + bool "Support priority options"
30 - Enable support for setting swap device priority in swapon.
31 + Enable support for setting swap device priority in swapon. Also makes
32 + swapon respect 'pri=n' when enabling all swaps from /etc/fstab.
36 diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
37 index 54867ec..97f668e 100644
38 --- a/util-linux/swaponoff.c
39 +++ b/util-linux/swaponoff.c
40 @@ -95,6 +95,19 @@ static int do_em_all(void)
41 if (applet_name[5] != 'n'
42 || hasmntopt(m, MNTOPT_NOAUTO) == NULL
44 +#if ENABLE_FEATURE_SWAPON_PRI /* from util-linux-ng 2.17.2 */
47 + g_flags = 0; /* each swap space might have different flags */
48 + opts = strdup(m->mnt_opts);
49 + for (opt = strtok(opts, ","); opt != NULL;
50 + opt = strtok(NULL, ",")) {
51 + if (strncmp(opt, "pri=", 4) == 0)
52 + g_flags = SWAP_FLAG_PREFER |
53 + ((atoi(opt+4) & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
55 + if (ENABLE_FEATURE_CLEAN_UP) free(opts);
57 err += swap_enable_disable(m->mnt_fsname);