3 # checkarray -- initiates a check run of an MD array's redundancy information.
5 # Copyright © martin f. krafft <madduck@debian.org>
6 # distributed under the terms of the Artistic Licence 2.0
14 echo "$PROGNAME -- MD array (RAID) redundancy checker tool"
16 echo "Copyright (C) martin f. krafft <madduck@debian.org>"
17 echo "Released under the terms of the Artistic Licence 2.0"
24 echo "Usage: $PROGNAME [options] [arrays]"
26 echo "Valid options are:"
27 cat <<-_eof | column -s\& -t
28 -a|--all & check all assembled arrays (check /proc/mdstat).
29 -c|--cron & honour AUTOCHECK setting in /etc/sysconfig/mdadm.
30 -s|--status & print redundancy check status of devices.
31 -x|--cancel & queue a request to cancel a running redundancy check.
32 -q|--quiet & suppress informational messages.
33 -Q|--real-quiet & suppress all output messages, including warnings and errors.
34 -h|--help & show this output.
35 -V|--version & show version information.
39 echo " $PROGNAME --all"
40 echo " $PROGNAME --quiet /dev/md[123]"
42 echo " $PROGNAME -x --all"
44 echo "Devices can be specified in almost any format. The following are"
45 echo "all equivalent:"
46 echo " /dev/md0, md0, /dev/md/0, /sys/block/md0"
48 echo "The --all option overrides all arrays passed to the script."
50 echo "You can also control the status of a check with /proc/mdstat ."
54 LONGOPTS=all,cron,help,version,quiet,real-quiet,status,cancel
61 eval set -- $(getopt -o $SHORTOPTS -l $LONGOPTS -n $PROGNAME -- "$@")
74 -s|--status) action=status;;
75 -x|--cancel) action=idle;;
76 -h|--help) usage; exit 0;;
78 -Q|--real-quiet) quiet=2;;
79 -V|--version) about; exit 0;;
80 /dev/md/*|md/*) arrays="${arrays:+$arrays }md${opt#*md/}";;
81 /dev/md*|md*) arrays="${arrays:+$arrays }${opt#/dev/}";;
82 /sys/block/md*) arrays="${arrays:+$arrays }${opt#/sys/block/}";;
84 *) echo "$PROGNAME: E: invalid option: $opt" >&2; usage >&2; exit 0;;
91 [Yy]es|[Yy]|1|[Tt]rue|[Tt]) return 0;;
96 DEBIANCONFIG=/etc/sysconfig/mdadm
97 [ -r $DEBIANCONFIG ] && . $DEBIANCONFIG
98 if [ $cron = 1 ] && ! is_true ${AUTOCHECK:-false}; then
99 [ $quiet -lt 1 ] && echo "$PROGNAME: I: disabled in $DEBIANCONFIG ." >&2
103 if [ ! -f /proc/mdstat ]; then
104 [ $quiet -lt 2 ] && echo "$PROGNAME: E: MD subsystem not loaded, or /proc unavailable." >&2
108 if [ ! -d /sys/block ]; then
109 [ $quiet -lt 2 ] && echo "$PROGNAME: E: /sys filesystem not available." >&2
113 if [ -z "$(ls /sys/block/md* 2>/dev/null)" ]; then
114 if [ $quiet -lt 2 ] && [ $cron != 1 ]; then
115 echo "$PROGNAME: W: no active MD arrays found." >&2
116 echo "$PROGNAME: W: (maybe uninstall the mdadm package?)" >&2
121 if [ -z "$(ls /sys/block/md*/md/level 2>/dev/null)" ]; then
122 [ $quiet -lt 2 ] && echo "$PROGNAME: E: kernel too old, no support for redundancy checks." >&2
126 if ! egrep -q '^raid([1456]|10)$' /sys/block/md*/md/level 2>/dev/null; then
127 [ $quiet -lt 1 ] && echo "$PROGNAME: I: no redundant arrays present; skipping checks..." >&2
131 if [ -z "$(ls /sys/block/md*/md/sync_action 2>/dev/null)" ]; then
132 [ $quiet -lt 2 ] && echo "$PROGNAME: E: no kernel support for redundancy checks." >&2
136 if [ $all = 1 ]; then
137 arrays="$(ls -d1 /sys/block/md* | cut -d/ -f4)"
138 elif [ -z "$arrays" ]; then
139 echo "$PROGNAME: E: specify array devices in command line." >&2
143 for array in $arrays; do
144 SYNC_ACTION_CTL=/sys/block/$array/md/sync_action
146 if [ ! -e $SYNC_ACTION_CTL ]; then
147 [ $quiet -lt 1 ] && echo "$PROGNAME: I: skipping non-redundant array $array." >&2
151 cur_status="$(cat $SYNC_ACTION_CTL)"
153 if [ $action = status ]; then
154 echo "$array: $cur_status"
158 if [ ! -w $SYNC_ACTION_CTL ]; then
159 [ $quiet -lt 2 ] && echo "$PROGNAME: E: $SYNC_ACTION_CTL not writeable." >&2
165 echo $action > $SYNC_ACTION_CTL
166 [ $quiet -lt 1 ] && echo "$PROGNAME: I: cancel request queued for array $array." >&2
170 if [ "$cur_status" != idle ]; then
171 [ $quiet -lt 2 ] && echo "$PROGNAME: W: array $array not idle, skipping..." >&2
175 # queue request for the array. The kernel will make sure that these requests
176 # are properly queued so as to not kill one of the array.
177 echo $action > $SYNC_ACTION_CTL
178 [ $quiet -lt 1 ] && echo "$PROGNAME: I: check queued for array $array." >&2