Whamcloud - gitweb
LU-9771 flr: lfs setstripe to create a new mirror
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # Run test by setting NOSETUP=true when ltest has setup env for us
7 set -e
8 set +o posix
9
10 SRCDIR=$(dirname $0)
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
12
13 ONLY=${ONLY:-"$*"}
14 # Bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
19         echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
20
21 TMP=${TMP:-/tmp}
22 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
23 LFS=${LFS:-lfs}
24 LCTL=${LCTL:-lctl}
25 MULTIOP=${MULTIOP:-multiop}
26
27 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
28 . $LUSTRE/tests/test-framework.sh
29 init_test_env $@
30 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
31 init_logging
32
33 check_and_setup_lustre
34 DIR=${DIR:-$MOUNT}
35 assert_DIR
36
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ]]; then
38         skip_env "Need MDS version at least 2.7.64" && exit
39 fi
40
41 build_test_filter
42
43 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
44         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
46
47 # global array to store mirror IDs
48 declare -a mirror_array
49 get_mirror_ids() {
50         local tf=$1
51         local id
52         local array
53
54         array=()
55         for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
56                 array[${#array[@]}]=$((id >> 16))
57         done
58
59         mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
60
61         echo ${#mirror_array[@]}
62 }
63
64 # command line test cases
65 test_1() {
66         local tf=$DIR/$tfile
67         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
68
69         $LFS setstripe -E EOF -c -1 $tf
70
71         local stripes[0]=$OSTCOUNT
72
73         for ((i = 1; i < $mirror_count; i++)); do
74                 # add mirrors with different stripes to the file
75                 stripes[$i]=$((RANDOM % OSTCOUNT))
76                 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
77
78                 $LFS setstripe --component-add --mirror -c ${stripes[$i]} $tf
79         done
80
81         [ $(get_mirror_ids $tf) -ne $mirror_count ] &&
82                 error "mirror count error"
83
84         # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
85         $LFS setstripe --component-add --mirror $tf &&
86                 error "Creating the $((mirror_count+1))th mirror succeeded"
87
88         local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
89                         tr '\n' ' '))
90
91         # verify the range of components and stripe counts
92         for ((i = 0; i < $mirror_count; i++)); do
93                 local sc=$($LFS getstripe -I${ids[$i]} -c $tf)
94                 local start=$($LFS getstripe -I${ids[$i]} --component-start $tf)
95                 local end=$($LFS getstripe -I${ids[$i]} --component-end $tf)
96
97                 [[ ${stripes[$i]} = $sc ]] || {
98                         $LFS getstripe -v $tf;
99                         error "$i: sc error: id: ${ids[$i]}, ${stripes[$i]}";
100                 }
101                 [ $start -eq 0 ] || {
102                         $LFS getstripe -v $tf;
103                         error "$i: start error id: ${ids[$i]}";
104                 }
105                 [ $end = "EOF" ] || {
106                         $LFS getstripe -v $tf;
107                         error "$i: end error id: ${ids[$i]}";
108                 }
109         done
110 }
111 run_test 1 "create components with setstripe options"
112
113 test_2() {
114         local tf=$DIR/$tfile
115         local tf2=$DIR/$tfile-2
116
117         $LFS setstripe -E 1M -E EOF -c 1 $tf
118         $LFS setstripe -E 2M -E EOF -c -1 $tf2
119
120         local layout=$($LFS getstripe $tf2 | grep -A 4 lmm_objects)
121
122         $LFS setstripe --component-add --mirror=$tf2 $tf
123
124         [ $(get_mirror_ids $tf) -ne 2 ] && error "mirror count should be 2"
125         $LFS getstripe $tf2 | grep -q 'no stripe info' ||
126                 error "$tf2 still has stripe info"
127 }
128 run_test 2 "create components from existing files"
129
130 test_3() {
131         [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
132
133         for ((i = 0; i < 2; i++)); do
134                 $LFS mkdir -i $i $DIR/$tdir-$i
135                 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
136         done
137
138         $LFS setstripe --component-add --mirror=$DIR/$tdir-1/$tfile \
139                 $DIR/$tdir-0/$tfile || error "creating mirrors"
140
141         # mdt doesn't support to cancel layout lock for remote objects, do
142         # it here manually.
143         cancel_lru_locks mdc
144
145         # make sure the mirrorted file was created successfully
146         [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
147                 { $LFS getstripe $DIR/$tdir-0/$tfile;
148                         error "expected 2 components"; }
149
150         # cleanup
151         rm -rf $DIR/$tdir-*
152 }
153 run_test 3 "create components from files located on different MDTs"
154
155 complete $SECONDS
156 check_and_cleanup_lustre
157 exit_status