aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d
diff options
context:
space:
mode:
authorLukas Nykryn <lnykryn@redhat.com>2016-01-18 13:32:54 +0100
committerLukas Nykryn <lnykryn@redhat.com>2016-01-19 12:02:44 +0100
commit91f8ff5cf5559381f6295eb84374c34de9dbe53c (patch)
treea52b7e11fbb1dd8b18c781b0789d157bad78ee18 /rc.d
parent8f1d77780d59e43e7cc514df9875ccb0ce54944a (diff)
downloadinitscripts-91f8ff5cf5559381f6295eb84374c34de9dbe53c.tar
initscripts-91f8ff5cf5559381f6295eb84374c34de9dbe53c.tar.gz
initscripts-91f8ff5cf5559381f6295eb84374c34de9dbe53c.tar.bz2
initscripts-91f8ff5cf5559381f6295eb84374c34de9dbe53c.tar.xz
initscripts-91f8ff5cf5559381f6295eb84374c34de9dbe53c.zip
netfs: tweak nfs umount
We want to run one round of regular umount before we will look for open descriptors. In the case that there are some stale mounts, without any open file descriptors on them we will avoid blocking stat call later. Resolves: #1296900
Diffstat (limited to 'rc.d')
-rw-r--r--rc.d/init.d/functions70
-rwxr-xr-xrc.d/init.d/netfs63
2 files changed, 75 insertions, 58 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index 45c71f93..7a4fde04 100644
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -111,6 +111,76 @@ __umount_loop() {
done
}
+# Similar to __umount loop above, without calling fuser
+__umount_loop_2() {
+ local remaining=
+ local count
+
+ #call regular umount
+ remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
+ action "$3" fstab-decode umount $remaining
+
+ count=4
+ remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
+ while [ "$count" -gt 0 ]; do
+ [ -z "$remaining" ] && break
+ count=$(($count-1))
+ usleep 500000
+ remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
+ done
+ [ -z "$remaining" ] && return 0
+
+ devs=$(stat -c "%d" $remaining)
+ action "$4" fstab-decode umount "-l" $remaining
+
+ # find fds that don't start with /, are not sockets or pipes or other.
+ # these are potentially detached fds
+ detached_fds=$(find /proc/ -regex '/proc/[0-9]+/fd/.*' -printf "%p %l\n" 2>/dev/null |\
+ grep -Ev '/proc/[0-9]+/fd/[0-9]+ (/.*|inotify|\[.+\]|(socket|pipe):\[[0-9]+\])')
+
+ # check each detached fd to see if it has the same device
+ # as one of our lazy umounted filesystems
+ kill_list=
+ [ -n "$detached_fds" ] && while read fdline; do
+ fd=${fdline%% *}
+ pid=$(echo $fdline | sed -r 's/\/proc\/([0-9]+).+/\1/')
+ fd_dev=$(stat -L -c "%d" $fd)
+ for dev in $devs ; do
+ [ "$dev" = "$fd_dev" ] && kill_list+="$pid "
+ done
+ done <<< "$detached_fds"
+
+ [ -n "$kill_list" ] && kill $kill_list
+
+ # run a little wait/check loop for procs to exit
+ count=4
+ while [ "$count" -gt 0 ] ; do
+ [ -z "$kill_list" ] && break
+ count=$(($count-1))
+ usleep 500000
+ remaining=
+ for pid in $kill_list ; do
+ [ -d "/proc/$pid" ] && remaining+="$pid "
+ done
+ kill_list=$remaining
+ done
+
+ # try to finish the job:
+ if [ -n "$kill_list" ] ; then
+ kill -9 $kill_list
+ usleep 500000
+ # last check
+ remaining=
+ for pid in $kill_list ; do
+ [ -d "/proc/$pid" ] && remaining+="$pid "
+ done
+ kill_list=$remaining
+ fi
+ STRING=$"Killing processes with open filedescriptors on the unmounted disk:"
+ [ -z "$kill_list" ] && success "$STRING" || failure "$STRING"
+ echo
+}
+
# Similar to __umount loop above, specialized for loopback devices
__umount_loopback_loop() {
local remaining devremaining sig=
diff --git a/rc.d/init.d/netfs b/rc.d/init.d/netfs
index acd8f970..1ebcd9e9 100755
--- a/rc.d/init.d/netfs
+++ b/rc.d/init.d/netfs
@@ -121,64 +121,11 @@ case "$1" in
$"Unmounting GLUSTERFS filesystems (retry): "
fi
if [ -n "$NFSMTAB" ]; then
- STRING=$"Unmounting NFS filesystems:"
- echo -n $STRING
- nfs_fs=$(LC_ALL=C awk '/^#/ {next} $3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" {print $2}' /proc/mounts | sort -r)
- if [ -n "$nfs_fs" ]; then
- # create a device id reference
- devs=$(stat -c "%d" $nfs_fs)
-
- # the lazy umount
- for fs in $nfs_fs ; do
- umount -l $fs
- done
-
- # find fds that don't start with /, are not sockets or pipes or other.
- # these are potentially detached fds
- detached_fds=$(find /proc/ -regex '/proc/[0-9]+/fd/.*' -printf "%p %l\n" 2>/dev/null |\
- grep -Ev '/proc/[0-9]+/fd/[0-9]+ (/.*|inotify|\[.+\]|(socket|pipe):\[[0-9]+\])')
-
- # check each detached fd to see if it has the same device
- # as one of our lazy umounted filesystems
- kill_list=
- [ -n "$detached_fds" ] && while read fdline; do
- fd=${fdline%% *}
- pid=$(echo $fdline | sed -r 's/\/proc\/([0-9]+).+/\1/')
- fd_dev=$(stat -L -c "%d" $fd)
- for dev in $devs ; do
- [ "$dev" = "$fd_dev" ] && kill_list+="$pid "
- done
- done <<< "$detached_fds"
-
- [ -n "$kill_list" ] && kill $kill_list
-
- # run a little wait/check loop for procs to exit
- count=4
- while [ "$count" -gt 0 ] ; do
- [ -z "$kill_list" ] && break
- count=$(($count-1))
- usleep 500000
- remaining=
- for pid in $kill_list ; do
- [ -d "/proc/$pid" ] && remaining+="$pid "
- done
- kill_list=$remaining
- done
-
- # try to finish the job:
- if [ -n "$kill_list" ] ; then
- kill -9 $kill_list
- usleep 500000
- # last check
- remaining=
- for pid in $kill_list ; do
- [ -d "/proc/$pid" ] && remaining+="$pid "
- done
- fi
- [ -z "$remaining" ] && success "$STRING" || failure "$STRING"
- echo
- fi
- fi
+ __umount_loop_2 '$3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" {print $2}' \
+ /proc/mounts \
+ $"Unmounting NFS filesystems: " \
+ $"Unmounting NFS filesystems (retry): "
+ fi
[ -n "$CIFSMTAB" ] && action $"Unmounting CIFS filesystems: " umount -a -t cifs
[ -n "$NCPMTAB" ] && action $"Unmounting NCP filesystems: " umount -a -t ncp,ncpfs
rm -f /var/lock/subsys/netfs