commit 03e0c0fad83a7a6fc0033ead0f1805d6bda4d855
Author: Elan Ruusamäe <[email protected]>
Date:   Thu Jun 19 22:58:35 2014 +0300

    add AUTOSWAP feature
    
    inspired from initscripts 9.39-1

 doc/sysconfig.txt |  7 +++++++
 lib/functions     |  3 +--
 rc.d/rc.sysinit   | 47 +++++++++++++++++++++++++++++++++++++++++++----
 sysconfig/system  |  3 +++
 4 files changed, 54 insertions(+), 6 deletions(-)
---
diff --git a/doc/sysconfig.txt b/doc/sysconfig.txt
index 063a332..635d054 100644
--- a/doc/sysconfig.txt
+++ b/doc/sysconfig.txt
@@ -1,6 +1,13 @@
 Files in /etc/sysconfig
 =======================
 
+/etc/sysconfig/system:
+
+  AUTOSWAP=yes|no
+     Set to 'yes' to enable automatic swapon of all partitions with
+     the proper swap magic. This allows setting up swap without editing
+     /etc/fstab.
+
 /etc/sysconfig/keyboard:
 
   KEYTABLE=<keytable file>
diff --git a/lib/functions b/lib/functions
index e32f2d0..1b1b972 100644
--- a/lib/functions
+++ b/lib/functions
@@ -174,8 +174,7 @@ is_empty_file() {
 
 # returns OK if $1 contains $2
 strstr() {
-       local a=$2
-       [ "${1#*$a*}" = "$1" ] && return 1
+       [ "${1#*$2*}" = "$1" ] && return 1
        return 0
 }
 
diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit
index 0b9d5c7..e14ad74 100755
--- a/rc.d/rc.sysinit
+++ b/rc.d/rc.sysinit
@@ -102,6 +102,21 @@ parse_cmdline() {
        done
 }
 
+# resolve a device node to its major:minor numbers in decimal or hex
+get_numeric_dev() {
+       local dev=$1 enc=${2:-hex} res
+
+       res=$(stat -Lc "%t:%T" "$dev")
+       if [ "$enc" = dec ]; then
+               local oifs=$IFS
+               IFS=":"
+               set -- $res
+               IFS=$oifs
+               res=$((0x$1)):$((0x$2))
+       fi
+       echo -n $res
+}
+
 # setup SELINUX variable
 init_selinux() {
        # user knows!
@@ -162,6 +177,32 @@ relabel_selinux() {
        echo $SELINUX > $selinuxfs/enforce
 }
 
+# Enable automatic swapon of all partitions with the proper swap magic.
+# This allows setting up swap without editing /etc/fstab.
+enable_autoswap() {
+       local swappartitions=$(blkid -t TYPE=swap -o device)
+       if [ -z "$swappartitions" ]; then
+               return
+       fi
+
+       local curswap=$(awk '/^\/dev/ { print $1 }' /proc/swaps | while read x; 
do echo -n " "; get_numeric_dev $x; echo -n " "; done)
+
+       local partition
+       for partition in $swappartitions; do
+               [ ! -e $partition ] && continue
+               majmin=$(get_numeric_dev $partition)
+               if ! strstr "$curswap" " $majmin "; then
+                       run_cmd "$(nls 'Enabling local swap partitions: %s' 
$partition)" swapon $partition
+               fi
+       done
+}
+
+
+enable_swap() {
+       run_cmd "Activating swap" swapon -a "$@"
+       is_yes "$AUTOSWAP" && enable_autoswap
+}
+
 # Remove duplicate entries from mtab (for vserver guest use only)
 clean_vserver_mtab() {
        > /etc/mtab.clean
@@ -494,7 +535,7 @@ if ! is_yes "$VSERVER" && [[ "$container" != lxc* ]]; then
        fi
 
        # Start up swapping
-       run_cmd "Activating swap partitions" swapon -a -e
+       enable_swap -e
 
        # Initialize USB controllers
        usb=0
@@ -1005,9 +1046,7 @@ chown root:root /tmp/.ICE-unix
 is_yes "$SELINUX" && restorecon /tmp/.ICE-unix >/dev/null 2>&1
 
 if ! is_yes "$VSERVER"; then
-       run_cmd "Enabling swap space" true
-       # Right, now turn on swap in case we swap to files
-       swapon -a >/dev/null 2>&1
+       enable_swap
        emit --no-wait all-swaps
 
        # If a SCSI tape has been detected, load the st module unconditionally
diff --git a/sysconfig/system b/sysconfig/system
index f86eb73..0734c41 100644
--- a/sysconfig/system
+++ b/sysconfig/system
@@ -80,6 +80,9 @@ EVMS_AIX=no
 # EVMS OS/2 LVM volumes
 EVMS_OS2=no
 
+# Set to 'yes' to allow probing for devices with swap signatures
+AUTOSWAP=no
+
 # LVM2
 # disable if your only LVM volume is rootfs started on initrd and want faster 
startup
 LVM2=yes
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/rc-scripts.git/commitdiff/03e0c0fad83a7a6fc0033ead0f1805d6bda4d855

_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to