1 # set of functions used to test policy framework with assemble, incremental and Monitor
4 #create links to be able to use domains
5 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
7 eval ln -s \$dev$d /dev/disk/by-path/loop$d
9 eval mdadm --zero-superblock \$dev$d
12 devices="/dev/loop[0-9] /dev/loop10 /dev/loop11 /dev/loop12"
14 # on failure print out few things before exit
15 # uses testdsc and platform global variables
18 cat $config >&2 || true
20 [ -z "$testdsc" ] || { echo >&2 $platform: $testdsc "- failed"; }
21 ps -e | grep mdadm >&2 || true
22 if [ $listfailed == "yes" ]; then
23 [ "$verbose" != "yes" ] || echo ---FAILED---
24 flist="$flist \n $platform $testdsc"
31 # set test description
35 [ "$verbose" != "yes" ] || echo $testdsc
39 [ -z "$monitorpid" ] || { kill -9 $monitorpid; unset monitorpid; }
46 mdadm --zero-superblock $devices || true
51 trap tidyup 0 1 2 3 15
53 # create a RAID 1 array or container and subarray(s) on 2 disks
54 # if platform not specified imsm is used
55 # if subsize is given, first subarray is created with given size and second one on remaining space
57 # mddevno used to name created array
59 # numbers of devices to be used in array
65 [ -n "$platform" ] || platform="imsm"
66 if [ "$platform" == "imsm" ] || [ "$platform" == "ddf" ]; then
67 eval mdadm -CR /dev/md/con$mddevno -e $platform -n 2 \$dev$devno1 \$dev$devno2
69 [ -z "$subsize" ] || eval mdadm -CR sub$mddevno"_" -l 1 -n 2 /dev/md/con$mddevno -z $subsize
70 [ -n "$onearray" ] || eval mdadm -CR sub$mddevno -l 1 -n 2 /dev/md/con$mddevno
72 [ -z "$subsize" ] || sizepar="-z $subsize"
73 eval mdadm -CR arr$mddevno -e $platform -l 1 -n 2 \$dev$devno1 \$dev$devno2 $sizepar
78 # get container and subarray using given device from mdstat
79 # sets global variables c and v
81 local devname=`basename $1`
82 local platformtype=`grep -A 1 $devname /proc/mdstat | awk '/active/ {getline; print $4 }' | awk -F ":" 'END {print $1}'`
83 c=`grep "inactive.*$devname" /proc/mdstat | awk -F " " '{print $1}'`
84 v=`grep " active.*$devname" /proc/mdstat | awk -F " " '{print $1}'`
85 [ "$platformtype" == "external" ] || c=$v
88 # check if given device belongs to any container and subarray
89 # if $2 given then only container checked
94 [ -n "$c" ] || err "$devname not in any container"
95 [ -n "$subcheck" ] || [ -n "$v" ] || err " $devname not in subarray"
98 # test if two devices in the same container/subarray
100 # $3 don't check subarrays, only containers
102 local device1=`basename $1`
103 local device2=`basename $2`
105 chkarray $device1 $subcheck
108 chkarray $device2 $subcheck
109 [ "$c" == "$x" ] || err "$device1 and $device2 not in the same container"
110 [ -n "$subcheck" ] || [ "$v" == "$y" ] || err "$device1 and $device2 not in the same subarray"
113 # same as tst, just use numbers of devices instead of names as parameters
118 eval tst \$dev$devno1 \$dev$devno2 $subcheck
121 # create containers/subarrays, check if created properly,
122 # set global variables c$mddevno v$mddevno, usually c0=md127, v0=md126 , etc.
130 [ -n "$p" ] || p=$platform
131 ccv $mddevno $devno1 $devno2 $p $subsize $onearray
133 eval c$mddevno=\"$c\"
134 eval v$mddevno=\"$v\"
137 # check if given spare in container
138 # usage: chkspare container spare [n] (n if spare shouldn't be in container)
140 local container=`basename $1`
144 [ -n "$expected" ] || expected="y"
145 if [ "$expected" == "y" ]; then
146 [ "$c" == "$container" ] || err "$spare not in container $container"
148 [ "$c" != "$container" ] || err "$spare in container $container"
152 #check if spare was moved from one container to another
153 # args: from_container to_container spare [yn]
154 # n when spare should remain in original container
161 [ -n "$expected" ] || expected="y"
162 notexpected="n"; [ "$expected" == "y" ] || notexpected="y"
163 chkspare $from_container $spare $notexpected
164 [ $failed -eq 1 ] || chkspare $to_container $spare $expected
168 # for domains defined through policy
170 if [ "$1" != "a" ]; then
175 while [ -n "$4" ]; do
176 echo="policy domain=$domain"
177 [ "$metadata" == "noplatform" ] || echo="$echo metadata=$metadata"
178 echo="$echo path=loop$4"
179 echo="$echo action=$action"
186 echo "DEVICES $devlist /dev/md1*"
190 #[ "$verbose" != "yes" ] || cat $config | grep policy || true