#
# It supports a 'time budget' such that any incomplete 'check'
# will be checkpointed when that time has expired.
-# A subsequent invocation can allow the 'check' to continue.
+# A subsequent invocation will allow the 'check' to continue.
#
# Options are:
-# --continue Don't start new checks, only continue old ones.
+# --continue Don't start new checks, only continue previously started ones.
+# --restart: Enable restarting the array checks
# --duration This is passed to "date --date=$duration" to find out
# when to finish
#
-# To support '--continue', arrays are identified by UUID and the 'sync_completed'
-# value is stored in /var/lib/mdcheck/$UUID
+# Arrays are identified by UUID and the 'sync_completed' value is stored
+# in /var/lib/mdcheck/MD_UUID_$UUID. If this file exists on startup of
+# the script, the check will continue where the previous check left off.
+# After the check completes, /var/lib/mdcheck/Checked_$UUID will be created.
+# Another full check will be started after this file is removed.
+# Use "mdcheck --restart" to remove these markers and re-enable checking
+# all arrays.
# If the script is run from systemd, simply write to the journal on stderr.
# Otherwise, use logger.
echo -n "/dev/$dev"
}
-args=$(getopt -o "" -l help,continue,duration: -n mdcheck -- "$@")
+args=$(getopt -o "" -l help,continue,restart,duration: -n mdcheck -- "$@")
rv=$?
if [ $rv -ne 0 ]; then exit $rv; fi
eval set -- $args
cont=
+restart=
endtime=
while [ " $1" != " --" ]
do
case $1 in
--help )
- echo >&2 'Usage: mdcheck [--continue] [--duration time-offset]'
+ echo >&2 'Usage: mdcheck [--restart|--continue] [--duration time-offset]'
echo >&2 ' time-offset must be understood by "date --date"'
exit 0
;;
- --continue ) cont=yes ;;
- --duration ) shift; dur=$1
+ --continue )
+ cont=yes ;;
+ --restart )
+ restart=yes ;;
+ --duration )
+ shift; dur=$1
endtime=$(date --date "$dur" "+%s")
;;
esac
done
shift
+if [ "$cont" = yes ]; then
+ if [ "$restart" = yes ]; then
+ echo 'ERROR: --restart and --continue cannot be combined' >&2
+ exit 1
+ fi
+elif [ "$restart" = yes ]; then
+ log 'Re-enabling array checks for all arrays'
+ rm -f /var/lib/mdcheck/Checked_*
+ exit $?
+fi
+
# We need a temp file occasionally...
tmp=/var/lib/mdcheck/.md-check-$$
cnt=0
[[ "$MD_UUID" ]] || continue
fl="/var/lib/mdcheck/MD_UUID_$MD_UUID"
- if [ -z "$cont" ]
- then
+ checked="${fl/MD_UUID_/Checked_}"
+ if [[ -f "$fl" ]]; then
+ [[ ! -f "$checked" ]] || {
+ log "WARNING: $checked exists, continuing anyway"
+ }
+ start=`cat "$fl"`
+ elif [[ ! -f "$checked" && -z "$cont" ]]; then
start=0
- log start checking $dev
- elif [ -z "$MD_UUID" -o ! -f "$fl" ]
- then
- # Nothing to continue here
+ else # nothing to do
continue
- else
- start=`cat "$fl"`
- log continue checking $dev from $start
fi
: "$((cnt+=1))"
echo $start > $fl
echo $start > $sys/md/sync_min
echo check > $sys/md/sync_action
+ log checking $dev from $start
done
if [ -z "$endtime" ]
then
log finished checking $dev
eval MD_${i}_fl=
- rm -f $fl
+ rm -f "$fl"
+ touch "${fl/MD_UUID_/Checked_}"
continue;
fi
read a rest < $sys/md/sync_completed