rgmanager: Clean up filesystem agents
PATCH 1/1 rgmanager: Clean up filesystem agents
- Make mountpoints with spaces work universally
- Eliminate duplicate code
- Use fuser -kvm in all agents
- Make quotas work
Resolves: rhbz#581533 rhbz#582753 rhbz#582754
Signed-off-by Lon Hohberger <[email protected]>
--- rgmanager/src/resources/clusterfs.sh | 608 +------------------- rgmanager/src/resources/fs.sh.in | 795 +------------------------- rgmanager/src/resources/netfs.sh | 355 ++----------- rgmanager/src/resources/utils/fs-lib.sh | 941 +++++++++++++++++++++++++++++++ 4 files changed, 1019 insertions(+), 1680 deletions(-) create mode 100644 rgmanager/src/resources/utils/fs-lib.sh
rgmanager/src/resources/clusterfs.sh +13 -595
@@ -1,37 +1,12 @@ #!/bin/bash # -# File system (normal) mount/umount/fsck/etc. agent +# Cluster File System mount/umount/fsck/etc. agent # -LC_ALL=C -LANG=C -PATH=/bin:/sbin:/usr/bin:/usr/sbin -export LC_ALL LANG PATH +. $(dirname $0)/utils/fs-lib.sh -# -# XXX todo - search and replace on these -# -SUCCESS=0 -FAIL=2 -YES=0 -NO=1 -YES_STR="yes" - -# Grab nfs lock tricks if available -export NFS_TRICKS=1 -if [ -f "$(dirname $0)/svclib_nfslock" ]; then - . $(dirname $0)/svclib_nfslock - NFS_TRICKS=0 -else - unset OCF_RESKEY_nfslock -fi - - -. $(dirname $0)/ocf-shellfuncs - - -meta_data() +do_metadata() { cat <<EOT <?xml version="1.0" ?>
@@ -182,86 +157,6 @@ EOT } -verify_name() -{ - [ -n "$OCF_RESKEY_name" ] || exit $OCF_ERR_ARGS -} - - -verify_mountpoint() -{ - if [ -z "$OCF_RESKEY_mountpoint" ]; then - ocf_log err "No mount point specified." - return $OCF_ERR_ARGS - fi - - if ! [ -e "$OCF_RESKEY_mountpoint" ]; then - ocf_log info "Mount point $OCF_RESKEY_mountpoint will be " - "created at mount time." - return 0 - fi - - [ -d "$OCF_RESKEY_mountpoint" ] && return 0 - - ocf_log err "$OCF_RESKEY_mountpoint is not a directory" - return $OCF_ERR_ARGS -} - - -real_device() -{ - declare dev=$1 - declare realdev - - [ -z "$dev" ] && return 1 - - if [ -h "$dev" ]; then - realdev=$(readlink -f $dev) - if [ $? -ne 0 ]; then - return 1 - fi - echo $realdev - return 0 - fi - - if [ -b "$dev" ]; then - echo $dev - return 0 - fi - - realdev=$(findfs $dev 2> /dev/null) - if [ -n "$realdev" ] && [ -b "$realdev" ]; then - echo $realdev - return 0 - fi - - return 1 -} - - -verify_device() -{ - declare realdev - - if [ -z "$OCF_RESKEY_device" ]; then - ocf_log err "No device or label specified." - return $OCF_ERR_ARGS - fi - - realdev=$(real_device $OCF_RESKEY_device) - if [ -n "$realdev" ]; then - if [ "$realdev" != "$OCF_RESKEY_device" ]; then - echo "Specified $OCF_RESKEY_device maps to $realdev" - fi - return $OCF_SUCCESS - fi - - ocf_log "Device or label \"$OCF_RESKEY_device\" not valid" - - return $OCF_ERR_ARGS -} - - verify_fstype() { # Auto detect?
@@ -328,7 +223,7 @@ verify_options() } -verify_all() +do_verify() { verify_name || return $OCF_ERR_ARGS verify_fstype || return $OCF_ERR_ARGS
@@ -338,361 +233,7 @@ verify_all() } -# -# mountInUse device mount_point -# -# Check to see if either the device or mount point are in use anywhere on -# the system. It is not required that the device be mounted on the named -# moint point, just if either are in use. -# -mountInUse () { - typeset mp tmp_mp - typeset dev tmp_dev - typeset junk - - if [ $# -ne 2 ]; then - ocf_log err "Usage: mountInUse device mount_point". - return $FAIL - fi - - dev=$1 - mp=$2 - - while read tmp_dev tmp_mp junk; do - if [ -n "$tmp_dev" -a "$tmp_dev" = "$dev" ]; then - return $YES - fi - - if [ -n "$tmp_mp" -a "$tmp_mp" = "$mp" ]; then - return $YES - fi - done < <(mount | awk '{print $1,$3}') - - return $NO -} - - -# -# isMounted device mount_point -# -# Check to see if the device is mounted. Print a warning if its not -# mounted on the directory we expect it to be mounted on. -# -isMounted () { - - typeset mp tmp_mp - typeset dev tmp_dev - - if [ $# -ne 2 ]; then - ocf_log err "Usage: isMounted device mount_point" - return $FAIL - fi - - dev=$(real_device $1) - if [ -z "$dev" ]; then - ocf_log err "isMounted: Could not match $1 with a real device" - return $FAIL - fi - mp=$(readlink -f $2) - - while read tmp_dev tmp_mp - do - #echo "spec=$1 dev=$dev tmp_dev=$tmp_dev" - tmp_dev=$(real_device $tmp_dev) - - if [ -n "$tmp_dev" -a "$tmp_dev" = "$dev" ]; then - # - # Check to see if its mounted in the right - # place - # - if [ -n "$tmp_mp" -a "$tmp_mp" != "$mp" ]; then - ocf_log warn "\ -Device $dev is mounted on $tmp_mp instead of $mp" - fi - return $YES - fi - done < <(mount | awk '{print $1,$3}') - - return $NO -} - - -# -# isAlive mount_point -# -# Check to see if mount_point is alive (testing read/write) -# -isAlive() -{ - declare errcode - declare mount_point - declare file=".writable_test.$(hostname)" - declare rw - - if [ $# -ne 1 ]; then - ocf_log err "Usage: isAlive mount_point" - return $FAIL - fi - mount_point=$1 - - test -d $mount_point - if [ $? -ne 0 ]; then - ocf_log err "$mount_point is not a directory" - return $FAIL - fi - - [ $OCF_CHECK_LEVEL -lt 10 ] && return $YES - - # depth 10 test (read test) - ls $mount_point > /dev/null 2> /dev/null - errcode=$? - if [ $errcode -ne 0 ]; then - ocf_log err "clusterfs:${OCF_RESKEY_name}: isAlive failed read test on [$mount_point]. Return code: $errcode" - return $NO - fi - - [ $OCF_CHECK_LEVEL -lt 20 ] && return $YES - - # depth 20 check (write test) - rw=$YES - for o in `echo $OCF_RESKEY_options | sed -e s/,/\ /g`; do - if [ "$o" = "ro" ]; then - rw=$NO - fi - done - if [ $rw -eq $YES ]; then - file=$mount_point/$file - while true; do - if [ -e "$file" ]; then - file=${file}_tmp - continue - else - break - fi - done - touch $file > /dev/null 2> /dev/null - errcode=$? - if [ $errcode -ne 0 ]; then - ocf_log err "clusterfs:${OCF_RESKEY_name}: isAlive failed write test on [$mount_point]. Return code: $errcode" - return $NO - fi - rm -f $file > /dev/null 2> /dev/null - fi - - return $YES -} - - -# -# startFilesystem -# -startFilesystem() { - typeset -i ret_val=$SUCCESS - typeset mp="" # mount point - typeset dev="" # device - typeset fstype="" - typeset opts="" - typeset device_in_use="" - typeset mount_options="" - - # - # Get the mount point, if it exists. If not, no need to continue. - # - mp=${OCF_RESKEY_mountpoint} - case "$mp" in - ""|"[ ]*") # nothing to mount - return $SUCCESS - ;; - /*) # found it - ;; - *) # invalid format - ocf_log err \ -"startFilesystem: Invalid mount point format (must begin with a '/'): \'$mp\'" - return $FAIL - ;; - esac - - # - # Get the device - # - dev=$(real_device $OCF_RESKEY_device) - if [ -z "$dev" ]; then - ocf_log err "\ -startFilesystem: Could not match $OCF_RESKEY_device with a real device" - return $FAIL - fi - - # - # Ensure we've got a valid directory - # - if [ -e "$mp" ]; then - if ! [ -d "$mp" ]; then - ocf_log err "\ -startFilesystem: Mount point $mp exists but is not a directory" - return $FAIL - fi - else - ocf_log info "\ -startFilesystem: Creating mount point $mp for device $dev" - mkdir -p "$mp" - ret_val=$? - if [ $ret_val -ne 0 ]; then - ocf_log err "\ -startFilesystem: Unable to create $mp. Error code: $ret_val" - return $OCF_ERR_GENERIC - fi - fi - - # - # Get the filesystem type, if specified. - # - fstype_option="" - fstype=${OCF_RESKEY_fstype} - case "$fstype" in - ""|"[ ]*") - fstype="" - ;; - *) # found it - fstype_option="-t $fstype" - ;; - esac - - # - # See if the device is already mounted. - # - isMounted $dev $mp - case $? in - $YES) # already mounted - ocf_log debug "$dev already mounted" - return $SUCCESS - ;; - $NO) # not mounted, continue - ;; - $FAIL) - return $FAIL - ;; - esac - - - # - # Make sure that neither the device nor the mount point are mounted - # (i.e. they may be mounted in a different location). The'mountInUse' - # function checks to see if either the device or mount point are in - # use somewhere else on the system. - # - mountInUse $dev $mp - case $? in - $YES) # uh oh, someone is using the device or mount point - ocf_log err "\ -Cannot mount $dev on $mp, the device or mount point is already in use!" - return $FAIL - ;; - $NO) # good, no one else is using it - ;; - $FAIL) - return $FAIL - ;; - *) - ocf_log err "Unknown return from mountInUse" - return $FAIL - ;; - esac - - # - # Get the mount options, if they exist. - # - mount_options="" - opts=${OCF_RESKEY_options} - case "$opts" in - ""|"[ ]*") - opts="" - ;; - *) # found it - mount_options="-o $opts" - ;; - esac - - # - # Mount the device - # - ocf_log debug "mount $fstype_option $mount_options $dev $mp" - mount $fstype_option $mount_options $dev $mp - ret_val=$? - if [ $ret_val -ne 0 ]; then - ocf_log err "\ -'mount $fstype_option $mount_options $dev $mp' failed, error=$ret_val" - return $FAIL - fi - - return $SUCCESS -} - - -# -# stopFilesystem serviceID deviceID -# -# Run the stop actions -# -stopFilesystem() { - typeset -i ret_val=0 - typeset -i try=1 - typeset -i max_tries=3 # how many times to try umount - typeset -i sleep_time=2 # time between each umount failure - typeset -i refs=0 - typeset done="" - typeset umount_failed="" - typeset force_umount="" - typeset self_fence="" - typeset fstype="" - - - # - # Get the mount point, if it exists. If not, no need to continue. - # - mp=${OCF_RESKEY_mountpoint} - case "$mp" in - ""|"[ ]*") # nothing to mount - return $SUCCESS - ;; - /*) # found it - ;; - *) # invalid format - ocf_log err \ -"stopFilesystem: Invalid mount point format (must begin with a '/'): \'$mp\'" - return $FAIL - ;; - esac - - # - # Get the device - # - dev=$(real_device $OCF_RESKEY_device) - if [ -z "$dev" ]; then - ocf_log err "\ -stop: Could not match $OCF_RESKEY_device with a real device" - return $FAIL - fi - - - # - # Get the force unmount setting if there is a mount point. - # - if [ -n "$mp" ]; then - case ${OCF_RESKEY_force_unmount} in - $YES_STR) force_umount=$YES ;; - 1) force_umount=$YES ;; - *) force_umount="" ;; - esac - fi - - if [ -n "$mp" ]; then - case ${OCF_RESKEY_self_fence} in - $YES_STR) self_fence=$YES ;; - 1) self_fence=$YES ;; - *) self_fence="" ;; - esac - fi - +do_pre_unmount() { # # Check the rgmanager-supplied reference count if one exists. # If the reference count is <= 1, we can safely proceed
@@ -701,10 +242,15 @@ stop: Could not match $OCF_RESKEY_device with a real device" refs=$OCF_RESKEY_RGMANAGER_meta_refcnt if [ $refs -gt 0 ]; then ocf_log debug "Not unmounting $OCF_RESOURCE_INSTANCE - still in use by $refs other service(s)" - return $OCF_SUCCESS + return 2 fi fi + if [ -z "$force_umount" ]; then + ocf_log debug "Not umounting $dev (clustered file system)" + return 2 + fi + # # Always do this hackery on clustered file systems. #
@@ -723,135 +269,7 @@ stop: Could not match $OCF_RESKEY_device with a real device" # Always invalidate buffers on clusterfs resources clubufflush -f $dev - if [ -z "$force_umount" ]; then - ocf_log debug "Not umounting $dev (clustered file system)" - return $SUCCESS - fi - - # - # Unmount the device. - # - while [ ! "$done" ]; do - isMounted $dev $mp - case $? in - $NO) - ocf_log info "$dev is not mounted" - umount_failed= - done=$YES - ;; - $FAIL) - return $FAIL - ;; - $YES) - sync; sync; sync - ocf_log info "unmounting $dev ($mp)" - - umount $mp - if [ $? -eq 0 ]; then - umount_failed= - done=$YES - continue - fi - - umount_failed=yes - - if [ "$force_umount" ]; then - if [ $try -eq 1 ]; then - fuser -TERM -kvm "$mp" - else - fuser -kvm "$mp" - fi - fi - - if [ $try -ge $max_tries ]; then - done=$YES - else - sleep $sleep_time - let try=try+1 - fi - ;; - *) - return $FAIL - ;; - esac - - if [ $try -ge $max_tries ]; then - done=$YES - else - sleep $sleep_time - let try=try+1 - fi - done # while - - if [ -n "$umount_failed" ]; then - ocf_log err "'umount $mp' failed, error=$ret_val" - - if [ "$self_fence" ]; then - ocf_log alert "umount failed - REBOOTING" - sync - reboot -fn - fi - return $FAIL - fi - - return $SUCCESS + return 0 } - -case $1 in -start) - declare tries=0 - declare rv - - while [ $tries -lt 3 ]; do - startFilesystem - rv=$? - if [ $rv -eq 0 ]; then - exit 0 - fi - - ((tries++)) - sleep 3 - done - exit $rv - ;; -stop) - stopFilesystem - exit $? - ;; -status|monitor) - isMounted ${OCF_RESKEY_device} ${OCF_RESKEY_mountpoint} - [ $? -ne $YES ] && exit $OCF_ERR_GENERIC - - isAlive ${OCF_RESKEY_mountpoint} - [ $? -ne $YES ] && exit $OCF_ERR_GENERIC - - exit 0 - ;; -restart) - stopFilesystem - if [ $? -ne 0 ]; then - exit $OCF_ERR_GENERIC - fi - - startFilesystem - if [ $? -ne 0 ]; then - exit $OCF_ERR_GENERIC - fi - - exit 0 - ;; -meta-data) - meta_data - exit 0 - ;; -validate-all) - verify_all - ;; -*) - echo "usage: $0 {start|stop|status|monitor|restart|meta-data|validate-all}" - exit $OCF_ERR_UNIMPLEMENTED - ;; -esac - -exit 0 +main $*
rgmanager/src/resources/fs.sh.in +28 -767
856 lines not on this page · raw message
rgmanager/src/resources/netfs.sh +37 -318
420 lines not on this page · raw message
rgmanager/src/resources/utils/fs-lib.sh new file +941 -0
941 lines not on this page · raw message
Signature · 1 line
1.6.2.5