Whamcloud - gitweb
LU-14490 lmv: striped directory as subdirectory mount
[fs/lustre-release.git] / lustre / tests / sanity-dom.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
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test:
11 ALWAYS_EXCEPT="$SANITY_DOM_EXCEPT"
12 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
16
17 . $LUSTRE/tests/test-framework.sh
18 CLEANUP=${CLEANUP:-:}
19 SETUP=${SETUP:-:}
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
25 # bug number for skipped test:
26         ALWAYS_EXCEPT+=""
27         if [ $MDSCOUNT -gt 1 ]; then
28 # bug number for skipped test:
29                 ALWAYS_EXCEPT+=""
30         fi
31 fi
32
33 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
34         { skip "Need MDS version at least 2.10.56"; exit 0; }
35
36 MULTIOP=${MULTIOP:-multiop}
37 OPENFILE=${OPENFILE:-openfile}
38 MOUNT_2=${MOUNT_2:-"yes"}
39 FAIL_ON_ERROR=false
40
41 check_and_setup_lustre
42
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45         skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
46 fi
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
48
49 build_test_filter
50
51 DOM="yes"
52 DOM_SIZE=${DOM_SIZE:-"$((1024*1024))"}
53 OSC="mdc"
54
55 save_layout_restore_at_exit $DIR1
56 $LFS setstripe -E $DOM_SIZE -L mdt -E EOF $DIR1
57
58 mkdir -p $MOUNT2
59 mount_client $MOUNT2
60
61 test_1() {
62         dd if=/dev/zero of=$DIR1/$tfile bs=7k count=1 || error "write 1"
63         $TRUNCATE $DIR2/$tfile 1000 || error "truncate"
64         dd if=/dev/zero of=$DIR1/$tfile bs=3k count=1 seek=1 || error "write 2"
65         $CHECKSTAT -t file -s 6144 $DIR2/$tfile || error "stat"
66         rm $DIR1/$tfile
67 }
68 run_test 1 "write a file on one mount, truncate on the other, write again"
69
70 test_2() {
71         SZ1=234852
72         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4 || return 1
73         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
74         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=5 || return 3
75         $CHECKSTAT -t file -s $SZ1 $DIR/${tfile}_left ||
76                 error "Error reading at the end of the file $tfile"
77 }
78 run_test 2 "Write with a seek, append, read from a single mountpoint"
79
80 test_3() {
81         # Write on one node to the DoM stripe and then truncate to over DoM size
82         dd if=/dev/zero of=$DIR1/$tfile bs=$((DOM_SIZE-100)) count=1 ||
83                 return 1
84         truncate $DIR1/$tfile $((DOM_SIZE+700)) || return 2
85         # read on the second node inside DoM stripe to take a lock data from
86         # the first client
87         dd if=$DIR2/$tfile of=/dev/null bs=4096 count=1 seek=1 || return 3
88         $CHECKSTAT -t file -s $((DOM_SIZE+700)) $DIR2/$tfile ||
89                 error "Wrong size after first truncate $tfile on first node"
90         # now do local truncate over DoM size and check size is correct
91         truncate $DIR2/$tfile $((DOM_SIZE+500)) || return 4
92         $CHECKSTAT -t file -s $((DOM_SIZE+500)) $DIR2/$tfile ||
93                 error "Wrong size after second truncate on the same node"
94         $CHECKSTAT -t file -s $((DOM_SIZE+500)) $DIR1/$tfile ||
95                 error "Wrong size after second truncate on other node"
96 }
97 run_test 3 "Truncate over DoM size on different nodes"
98
99 test_4() {
100         local before=0
101         local after=0
102
103         dd if=/dev/zero of=$DIR1/$tfile bs=2M count=1
104         cancel_lru_locks mdc
105
106         #define OBD_FAIL_MDC_GLIMPSE_DDOS 0x808
107         $LCTL set_param fail_loc=0x80000808
108         before=$(lctl get_param -n ldlm.namespaces.*mdc*.lock_count |
109                 gawk '{cnt=cnt+$1}  END{print cnt}')
110         for ((i=1; i < 100; i++))
111         do
112                 tail -n100 $DIR1/$tfile > /dev/null
113                 stat -f $DIR2/$tfile > /dev/null
114         done
115         after=$(lctl get_param -n ldlm.namespaces.*mdc*.lock_count |
116                 gawk '{cnt=cnt+$1}  END{print cnt}')
117         [[ $((after - before)) -ge 20 ]] &&
118                 error "Too many locks found $((after - before))"
119         return 0
120 }
121 run_test 4 "DoM: glimpse doesn't produce duplicated locks"
122
123 test_5() {
124         local before=$(date +%s)
125         local evict
126
127         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 || return 1
128
129         multiop_bg_pause $DIR/$tfile O_Ac || return 1
130         setxattr=$!
131
132         multiop_bg_pause $DIR/$tfile O_Tc || return 1
133         truncate=$!
134
135         multiop $DIR2/$tfile Ow10 || return 1
136
137         getfattr -d $DIR2/$tfile
138
139 #define OBD_FAIL_LLITE_TRUNCATE_INODE_PAUSE        0x1415
140         $LCTL set_param fail_loc=0x80001415 fail_val=5
141         kill -USR1 $truncate
142         sleep 1
143         multiop $DIR2/$tfile Ow10 &
144         sleep 1
145         kill -USR1 $setxattr
146
147         wait
148
149         evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
150           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
151
152         [ -z "$evict" ] || [[ $evict -le $before ]] ||
153                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
154                         error "eviction happened: $evict before:$before")
155 }
156 run_test 5 "DoM truncate deadlock"
157
158 test_6() {
159         $MULTIOP $DIR1/$tfile Oz40960w100_z200w100c &
160         MULTIPID=$!
161
162         # let MULTIPID to create the file
163         sleep 1
164         $MULTIOP $DIR2/$tfile oO_RDWR:Tw100c
165         kill -USR1 $MULTIPID
166         wait
167         $MULTIOP $DIR2/$tfile oO_RDWR:z400w100c
168         $CHECKSTAT -s 500 $DIR2/$tfile || error "wrong size"
169 }
170 run_test 6 "Race two writes, check file size"
171
172 test_7() {
173         dd if=/dev/zero of=$DIR1/$tfile bs=1000 count=1
174         cancel_lru_locks
175
176         $MULTIOP $DIR1/$tfile or1000c
177         dd if=/dev/urandom of=$DIR2/$tfile bs=1000 count=1
178         local md5_1=$(md5sum $DIR/$tfile | awk '{ print $1 }')
179         local md5_2=$(md5sum $DIR2/$tfile | awk '{ print $1 }')
180         [[ $md5_1 == $md5_2 ]] ||
181                 error "Client reads stale page"
182 }
183 run_test 7 "Stale pages after read-on-open"
184
185 test_8() {
186         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 || error "write 10k"
187         $TRUNCATE $DIR1/$tfile 123456 || error "truncate up to 123456"
188         $TRUNCATE $DIR2/$tfile 55555 || error "truncate down to 55555"
189         $CHECKSTAT -t file -s 55555 $DIR1/$tfile || error "stat"
190         $CHECKSTAT -t file -s 55555 $DIR2/$tfile || error "stat"
191         dd if=/dev/zero of=$DIR1/$tfile bs=10k count=1 seek=10 conv=notrunc ||
192                 error "write 10k@1M"
193         $CHECKSTAT -t file -s 112640 $DIR1/$tfile || error "stat"
194         $CHECKSTAT -t file -s 112640 $DIR2/$tfile || error "stat"
195         rm $DIR1/$tfile
196 }
197 run_test 8 "truncate up, truncate down on another mount, write in between"
198
199 test_fsx() {
200         local file1=$DIR1/$tfile
201         local file2=$DIR2/$tfile
202
203         touch $file1
204         fsx -c 50 -p 100 -N 1000 -l $((DOM_SIZE*2)) -S 0 -d -d $file1 $file2
205 }
206 run_test fsx "Dual-mount fsx with DoM files"
207
208 test_sanity()
209 {
210         # XXX: to fix 45. Add 42a, c when LU-9693 fixed.
211         # Add 42b when LU-6493 fixed
212         ONLY="36 39 40 41 42d 42e 43 46 56r 101e 119a 131 150 155a 155b 155c \
213                 155d 207 241 251" OSC="mdc" DOM="yes" bash sanity.sh
214 }
215 run_test sanity "Run sanity with Data-on-MDT files"
216
217 test_sanityn()
218 {
219         # XXX: to fix 60
220         ONLY="1 2 4 5 6 7 8 9 10 11 12 14 17 19 20 23 27 39 51a 51c 51d" \
221                 OSC="mdc" DOM="yes" bash sanityn.sh
222 }
223 run_test sanityn "Run sanityn with Data-on-MDT files"
224
225 complete $SECONDS
226 check_and_cleanup_lustre
227 exit_status