~xnox/ubuntu/quantal/mdadm/merge

« back to all changes in this revision

Viewing changes to tests/utils

  • Committer: Dmitrijs Ledkovs
  • Author(s): Clint Byrum
  • Date: 2011-12-16 11:06:12 UTC
  • mfrom: (1.1.26 sid)
  • Revision ID: dmitrijs.ledkovs@canonical.com-20111216110612-f91bfvyfvxc1t0rq
Tags: 3.2.2-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Call checks in local-premount to avoid race condition with udev
    and opening a degraded array.
  - d/initramfs/mdadm-functions: Record in /run when boot-degraded 
    question has been asked so that it is only asked once
  - pass --test to mdadm to enable result codes for degraded arrays. 
  - Build udeb with -O2 on ppc64, working around a link error.
  - debian/control: we need udev and util-linux in the right version. We
    also remove the build dependency from quilt and docbook-to-man as both
    are not used in Ubuntus mdadm.
  - debian/initramfs/hook: kept the Ubuntus version for handling the absence
    of active raid arrays in <initramfs>/etc/mdadm/mdadm.conf
  - debian/initramfs/script.local-top.DEBIAN, debian/mdadm-startall,
    debian/mdadm.raid.DEBIAN: removed. udev does its job now instead.
  - debian/mdadm-startall.sgml, debian/mdadm-startall.8: documentation of
    unused startall script
  - debian/mdadm.config, debian/mdadm.postinst - let udev do the handling
    instead. Resolved merge conflict by keeping Ubuntu's version.
  - debian/mdadm.postinst, debian/mdadm.config, initramfs/init-premount:
    boot-degraded enablement; maintain udev starting of RAID devices;
    init-premount hook script for the initramfs, to provide information at
    boot
  - debian/mkconf.in is the older mkconf. Kept the Ubuntu version.
  - debian/rules: Kept Ubuntus version for installing apport hooks, not
    installing un-used startall script and for adding a udev rule
    corresponding to mdadm.
  - debian/install-rc, check.d/_numbers, check.d/root_on_raid: Ubuntu partman
    installer changes
  - debian/presubj: Dropped this unused bug reporting file. Instead use
    source_mdadm.py act as an apport hook for bug handling.
  - rename debian/mdadm.vol_id.udev to debian/mdadm.mdadm-blkid.udev so that
    the rules file ends up with a more reasonable name
  - d/p/debian-changes-3.1.4-1+8efb9d1ubuntu4: mdadm udev rule
    incrementally adds mdadm member when detected. Starting such an
    array in degraded mode is possible by mdadm -IRs. Using mdadm
    -ARs without stopping the array first does nothing when no
    mdarray-unassociated device is available. Using mdadm -IRs to
    start a previously partially assembled array through incremental
    mode. Keeping the mdadm -ARs for assembling arrays which were for
    some reason not assembled through incremental mode (i.e through
    mdadm's udev rule).
* Disabling -fno-strict-aliasing as according to debian bug 375876 it
  has been unnecessary since mdadm 2.5.2
* Dropped changes:
  - applied upstream
  - d/rules: fix FTBFS by adding -Wno-unused-but-set-variable to
    compiler flags until upstream solves the issue. (fixed upstream)
  - d/control: add dependency on initscripts >= 2.88dsf-13.3 to ensure
    /run exists per http://wiki.debian.org/ReleaseGoals/RunDirectory
    (change also done in debian)
* d/rules: add 'man' to build mdadm.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# set of functions used to test policy framework with assemble, incremental and Monitor
 
2
 
 
3
set +e
 
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
 
6
do
 
7
       eval ln -s \$dev$d /dev/disk/by-path/loop$d
 
8
       eval d$d="loop$d"
 
9
       eval mdadm --zero-superblock \$dev$d
 
10
done
 
11
 
 
12
devices="/dev/loop[0-9] /dev/loop10 /dev/loop11 /dev/loop12"
 
13
 
 
14
# on failure print out few things before exit
 
15
# uses testdsc and platform global variables
 
16
err(){
 
17
       echo >&2 "ERROR: $*"
 
18
       cat $config >&2 || true
 
19
       cat /proc/mdstat >&2
 
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"
 
25
               failed=1
 
26
       else
 
27
               exit 1
 
28
       fi
 
29
}
 
30
 
 
31
# set test description
 
32
dsc(){
 
33
       failed=0
 
34
       testdsc="$*"
 
35
       [ "$verbose" != "yes" ] || echo $testdsc
 
36
}
 
37
 
 
38
killmonitor(){
 
39
       [ -z "$monitorpid" ] || { kill -9 $monitorpid; unset monitorpid; }
 
40
}
 
41
 
 
42
tidyup(){
 
43
       killmonitor
 
44
       mdadm -Ss || true
 
45
       mdadm -Ss
 
46
       mdadm --zero-superblock $devices || true
 
47
       udevadm settle
 
48
       rm -f $config
 
49
}
 
50
 
 
51
trap tidyup 0 1 2 3 15
 
52
 
 
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
 
56
ccv(){
 
57
       # mddevno used to name created array
 
58
       local mddevno="$1"
 
59
       # numbers of devices to be used in array
 
60
       local devno1="$2"
 
61
       local devno2="$3"
 
62
       local platform="$4"
 
63
       local subsize="$5"
 
64
       local onearray="$6"
 
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
 
68
               udevadm settle
 
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
 
71
       else
 
72
               [ -z "$subsize" ] || sizepar="-z $subsize"
 
73
               eval mdadm -CR arr$mddevno -e $platform -l 1 -n 2 \$dev$devno1 \$dev$devno2 $sizepar
 
74
               unset sizepar
 
75
       fi
 
76
}
 
77
 
 
78
# get container and subarray using given device from mdstat
 
79
# sets global variables c and v
 
80
getarray(){
 
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
 
86
}
 
87
 
 
88
# check if given device belongs to any container and subarray
 
89
# if $2 given then only container checked
 
90
chkarray(){
 
91
       local devname="$1"
 
92
       local subcheck="$2"
 
93
       getarray $devname
 
94
       [ -n "$c" ] || err "$devname not in any container"
 
95
       [ -n "$subcheck" ] || [ -n "$v" ] || err " $devname not in subarray"
 
96
}
 
97
 
 
98
# test if two devices in the same container/subarray
 
99
# $1 $2 - devices
 
100
# $3 don't check subarrays, only containers
 
101
tst(){
 
102
       local device1=`basename $1`
 
103
       local device2=`basename $2`
 
104
       local subcheck="$3"
 
105
       chkarray $device1 $subcheck
 
106
       local x="$c"
 
107
       local y="$v"
 
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"
 
111
}
 
112
 
 
113
# same as tst, just use numbers of devices instead of names as parameters
 
114
dtst(){
 
115
       local devno1="$1"
 
116
       local devno2="$2"
 
117
       local subcheck="$3"
 
118
       eval tst \$dev$devno1 \$dev$devno2 $subcheck
 
119
}
 
120
 
 
121
# create containers/subarrays, check if created properly,
 
122
# set global variables c$mddevno v$mddevno, usually c0=md127, v0=md126 , etc.
 
123
setupdevs(){
 
124
       local mddevno="$1"
 
125
       local devno1="$2"
 
126
       local devno2="$3"
 
127
       local p="$4"
 
128
       local subsize="$5"
 
129
       local onearray="$6"
 
130
       [ -n "$p" ] || p=$platform
 
131
       ccv $mddevno $devno1 $devno2 $p $subsize $onearray
 
132
       dtst $devno1 $devno2
 
133
       eval c$mddevno=\"$c\"
 
134
       eval v$mddevno=\"$v\"
 
135
}
 
136
 
 
137
# check if given spare in container
 
138
# usage: chkspare container spare [n]  (n if spare shouldn't be in container)
 
139
chkspare(){
 
140
       local container=`basename $1`
 
141
       local spare=$2
 
142
       local expected=$3
 
143
       getarray $spare
 
144
       [ -n "$expected" ] || expected="y"
 
145
       if [ "$expected" == "y" ]; then
 
146
               [ "$c" == "$container" ] || err "$spare not in container $container"
 
147
       else
 
148
               [ "$c" != "$container" ] || err "$spare in container $container"
 
149
       fi
 
150
}
 
151
 
 
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
 
155
chksparemoved(){
 
156
       sleep $sleeptime
 
157
       from_container="$1"
 
158
       to_container="$2"
 
159
       spare="$3"
 
160
       expected="$4"
 
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
 
165
}
 
166
 
 
167
 
 
168
# for domains defined through policy
 
169
createconfig(){
 
170
if [ "$1" != "a" ]; then
 
171
{
 
172
       domain=$1
 
173
       metadata=$2
 
174
       action=$3
 
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"
 
180
               echo "$echo"
 
181
               shift
 
182
       done
 
183
} >> $config
 
184
else
 
185
{
 
186
       echo "DEVICES $devlist /dev/md1*"
 
187
       mdadm -Ebs
 
188
} >  $config
 
189
fi
 
190
#[ "$verbose" != "yes" ] || cat $config | grep policy || true
 
191
}