-
Notifications
You must be signed in to change notification settings - Fork 3
/
mr_detail.sh
executable file
·99 lines (84 loc) · 2.26 KB
/
mr_detail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -e
if [ "$#" -ne "2" ]; then
echo "$0: <MAP> <NAME>"
exit 1
fi
MAP="$1"
NAME="$2"
if [ `id -u` -ne "0" ]; then
echo "Got Root?"
exit 2
fi
if [ ! -r ${MAP} ]; then
echo "${MAP} is not readable!"
exit 3
fi
LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup`
if [ "$?" != "0" ]; then
echo "losetup not found!"
exit 4
fi
MDBIN=`PATH="/sbin:/usr/sbin:$PATH" which mdadm`
if [ "$?" != "0" ]; then
echo "mdadm not found!"
exit 5
fi
# Walk through each disk image, finding loop devices and raid device (if active)
INDEX="0"
declare -a dimg_array
declare -a loop_array
declare -a raid_array
while read -r LINE; do
DIMG=`ls -1 ${LINE}/${NAME}/${NAME}.?.rimg`
if [ ! -r "${DIMG}" ]; then
echo "Could not find disk images for ${NAME} using this map!"
exit 6
fi
dimg_array[${INDEX}]="${DIMG}"
LOOP=`${LOBIN} -a | grep -w ${DIMG} | cut -d: -f1`
if [ -n "${LOOP}" ]; then
loop_array[${INDEX}]="${LOOP}"
BN=`basename ${LOOP}`
RD=`grep -w ${BN} /proc/mdstat | awk '{print $1}'`
if [ -n "${RD}" ]; then
raid_array[${INDEX}]="${RD}"
fi
fi
INDEX=$(( INDEX+1 ))
done < ${MAP}
# echo "dimg_array: ${dimg_array[@]}"
# echo "loop_array: ${loop_array[@]}"
# echo "raid_array: ${raid_array[@]}"
# echo "INDEX: ${INDEX}"
# If ${NAME} has no loops, we are done here
if [ "${#loop_array[@]}" == "0" ]; then
echo "${NAME} has no loops active!"
exit 7
fi
# If the LOOP is greater than the DIMG count, we have a problem
# LOOP count can be less, in the case of a degraded array
if [ "${#loop_array[@]}" -gt "${#dimg_array[@]}" ]; then
echo "Expected ${#dimg_array[@]} loop devices, found ${#loop_array[@]}!"
exit 8
fi
# If we have no active raid, we cannot get detailed information
if [ "${#raid_array[@]}" == "0" ]; then
echo "${NAME} has no assembled raid!"
exit 9
fi
# Check to make sure we are about to detail the correct raid device
UNIQUERAIDCOUNT=`echo "${raid_array[@]}" | xargs -n1 echo | sort -u | wc -l`
if [ "${UNIQUERAIDCOUNT}" != "1" ]; then
echo "${NAME} appears to be attached to multiple devices?"
echo "${raid_array[@]}"
exit 10
fi
MD=${raid_array[0]}
RAIDDEV="/dev/${MD}"
if [ ! -b ${RAIDDEV} ]; then
echo "${RAIDDEV} is not a block device!"
exit 11
fi
# Whew, we finally got here
${MDBIN} --detail ${RAIDDEV}