Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Fixing swap1_stop



On Aug 8,  9:26pm, idleroux%fastmail.fm@localhost ("Ian D. Leroux") wrote:
-- Subject: Re: Fixing swap1_stop

| I append a patch that does just that (almost identical to the code you
| suggested, except that I'm a bit more paranoid when parsing the name of
| the mount point).  I've tested it lightly, but my current system only
| has /var/shm on tmpfs.
| 
| However, after taking a closer look at /etc/rc.d/swap2, I no longer
| understand why /etc/rc.d/swap1 has to unmount any filesystem, ever.  As
| I understood it, the rationale ran:
| - swap can live in files, so we must remove swap before unmounting
| filesystems
| - tmpfs can live in swap, and if it is large then it may exceed
| available (non-swap) RAM, so we must remove the tmpfs filesystems
| before removing swap.
| 
| However, all the swap that lives in the filesystem (i.e. non-block-type
| swap devices) is removed by /etc/rc.d/swap2, while the critical
| filesystems are still mounted.  By the time swap1_stop() runs, most of
| the filesystem (and any swap that lived in files) is already gone.  Why
| can't we then just leave the (remaining, block-type) swap configured
| until the system goes down? And if we do need to unmount tmpfs
| filesystems, why are we doing it in swap1_stop() after we've already
| (potentially) unmounted a chunk of (file-backed) swap rather than in
| swap2, before we start removing swap devices?
| 
| Yours in growing perplexity,
| 
| -- IDL
| 
| --- /etc/rc.d/swap1.orig	2017-02-28 06:51:12.737058550 -0500
| +++ /etc/rc.d/swap1	2017-08-08 20:50:55.065104788 -0400
| @@ -13,6 +13,26 @@
|  start_cmd="swap1_start"
|  stop_cmd="swap1_stop"
|  
| +umount_tmpfs()
| +{
| +	echo -n "Forcibly unmounting tmpfs filesystems:"
| +        mount -t tmpfs | while read -r line
| +        do
| +                dir=${line#tmpfs on }
| +                dir=${dir% type tmpfs*}
| +                case "$dir" in
| +                /dev)
| +                        echo -n " [skipping $dir]"
| +                        ;;
| +                *)
| +                        echo -n " $dir"
| +                        umount -f "$dir"
| +                        ;;
| +                esac
| +        done
| +        echo "."
| +}
| +
|  #		Add all block-type swap devices; these might be necessary
|  #		during disk checks.
|  #
| @@ -31,8 +51,7 @@
|  swap1_stop()
|  {
|  	if checkyesno swapoff || [ -n "$rc_force" ]; then
| -		echo "Forcibly unmounting tmpfs filesystems"
| -		umount -aft tmpfs
| +		umount_tmpfs
|  		echo "Removing block-type swap devices"
|  		swapctl -U -t blk || [ $? = 2 ]
|  	fi

I think it is better to modify mount to either pass a format string
to it or to quote the pathnames so that the output is predictable.

christos


Home | Main Index | Thread Index | Old Index