[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] swapon: adhere swap priority in fstab
From:       Dennis Groenen <tj.groenen () gmail ! com>
Date:       2013-08-04 12:08:54
Message-ID: CAGbXzieez15KteoSua+AGLQWimp99uV4qaL55KFnn7EM_jM+tA () mail ! gmail ! com
[Download RAW message or body]

We already had the mount opts from fstab, but didn't do anything with them.

Check mnt_opts and set g_flags accordingly prior to enabling the swapspace when
we do_em_all().

Signed-off-by: Dennis Groenen <tj.groenen at gmail.com>
---
 util-linux/Config.src  |    5 +++--
 util-linux/swaponoff.c |   13 +++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/util-linux/Config.src b/util-linux/Config.src
index 5a8b006..b90873d 100644
--- a/util-linux/Config.src
+++ b/util-linux/Config.src
@@ -600,11 +600,12 @@ config SWAPONOFF
 	  option disabled.

 config FEATURE_SWAPON_PRI
-	bool "Support priority option -p"
+	bool "Support priority options"
 	default y
 	depends on SWAPONOFF
 	help
-	  Enable support for setting swap device priority in swapon.
+	  Enable support for setting swap device priority in swapon. Also makes
+	  swapon respect 'pri=n' when enabling all swaps from /etc/fstab.

 config SWITCH_ROOT
 	bool "switch_root"
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 54867ec..97f668e 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -95,6 +95,19 @@ static int do_em_all(void)
 			if (applet_name[5] != 'n'
 			 || hasmntopt(m, MNTOPT_NOAUTO) == NULL
 			) {
+#if ENABLE_FEATURE_SWAPON_PRI /* from util-linux-ng 2.17.2 */
+				char *opt, *opts;
+
+				g_flags = 0; /* each swap space might have different flags */
+				opts = strdup(m->mnt_opts);
+				for (opt = strtok(opts, ","); opt != NULL;
+					 opt = strtok(NULL, ",")) {
+					if (strncmp(opt, "pri=", 4) == 0)
+						g_flags = SWAP_FLAG_PREFER |
+							((atoi(opt+4) & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
+				}
+				if (ENABLE_FEATURE_CLEAN_UP) free(opts);
+#endif
 				err += swap_enable_disable(m->mnt_fsname);
 			}
 		}
-- 
1.7.9.5
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic