From e39b6492eb458d201e3a464126332cf2fe81b2ff Mon Sep 17 00:00:00 2001 From: Lars Ellenberg Date: Tue, 23 Feb 2010 18:49:37 +0100 Subject: [PATCH 04/16] snapshot-resync-target handler: fix endless loop in option parsing Get shifting of option arguments right, if someone used the --percent option, we went in an endless loop. Also source the $DEFAULT file first, and let explicit command line options override. Finally, use drbdadm sh-minor (and support stacked devices!) instead of indirectly guessing the minor number from the device name, which may fail -- device names now are "arbitrary". --- scripts/snapshot-resync-target-lvm.sh | 53 +++++++++++++++++---------------- 1 files changed, 27 insertions(+), 26 deletions(-) diff --git a/scripts/snapshot-resync-target-lvm.sh b/scripts/snapshot-resync-target-lvm.sh index 8457e18..fcda09b 100755 --- a/scripts/snapshot-resync-target-lvm.sh +++ b/scripts/snapshot-resync-target-lvm.sh @@ -39,38 +39,39 @@ BE_VERBOSE=0 SNAP_NAME=${BACKING_BDEV##*/}-before-resync DEFAULTFILE="/etc/default/drbd-snapshot" +if [ -f $DEFAULTFILE ]; then + . $DEFAULTFILE +fi + +## command line parameters override default file + eval set -- "$TEMP" while true; do case $1 in - -p|--percent) - SNAP_PERC="$2" - shift - ;; - -a|--additional) - SNAP_ADDITIONAL="$2" - shift 2 - ;; - -n|--disconnect-on-error) - DISCONNECT_ON_ERROR=1 - shift - ;; - -v|--verbose) - BE_VERBOSE=1 - shift - ;; - --) - shift - break - ;; + -p|--percent) + SNAP_PERC="$2" + shift + ;; + -a|--additional) + SNAP_ADDITIONAL="$2" + shift + ;; + -n|--disconnect-on-error) + DISCONNECT_ON_ERROR=1 + ;; + -v|--verbose) + BE_VERBOSE=1 + ;; + --) + break + ;; esac + shift done +shift # the -- LVC_OPTIONS="$@" -if [ -f $DEFAULTFILE ]; then - . $DEFAULTFILE -fi - if [[ $0 == *unsnapshot* ]]; then [ $BE_VERBOSE = 1 ] && set -x VG_PATH=${BACKING_BDEV%/*} @@ -80,8 +81,8 @@ else ( set -e [ $BE_VERBOSE = 1 ] && set -x - DRBD_DEV=$(drbdadm sh-dev $DRBD_RESOURCE) - DRBD_MINOR=${DRBD_DEV##/dev/drbd} + # it may even be a stacked resource :-/ + DRBD_MINOR=$(drbdadm sh-minor $DRBD_RESOURCE || drbdadm -S sh-minor $DRBD_RESOURCE) OUT_OF_SYNC=$(sed -ne "/^ *$DRBD_MINOR:/ "'{ n; s/^.* oos:\([0-9]*\).*$/\1/; -- 1.6.3.3