Whamcloud - gitweb
LU-13019 tests: replace usleep in test scripts
[fs/lustre-release.git] / lustre / tests / sanity-lsnapshot.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 ALWAYS_EXCEPT="$SANITY_LSNAPSHOT_EXCEPT"
11 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
15 . $LUSTRE/tests/test-framework.sh
16 init_test_env $@
17 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
18 init_logging
19
20 [[ "$MDS1_VERSION" -lt $(version_code 2.9.55) ]] ||
21 [[ "$OST1_VERSION" -lt $(version_code 2.9.55) ]] &&
22         skip "Need server version at least 2.9.55"
23 [[ "$mds1_FSTYPE" = "ldiskfs" ]] || [[ "$ost1_FSTYPE" = "ldiskfs" ]] &&
24         skip "ZFS only test"
25
26 require_dsh_mds || exit 0
27 require_dsh_ost || exit 0
28
29 check_and_setup_lustre
30
31 do_facet mgs $LCTL set_param debug=+snapshot
32 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=+snapshot
33
34 lss_gen_conf
35 lss_cleanup
36 build_test_filter
37
38 test_0() {
39         echo "Create lss_0_0 with default"
40         lsnapshot_create -n lss_0_0 ||
41                 lss_err "(1) Fail to create lss_0_0 with default"
42
43         echo "List lss_0_0"
44         lsnapshot_list -n lss_0_0 ||
45                 lss_err "(2) Fail to list lss_0_0"
46
47         echo "Create lss_0_1 with barrier off"
48         lsnapshot_create -n lss_0_1 --barrier=off ||
49                 lss_err "(3) Fail to create lss_0_1 with barrier off"
50
51         echo "List lss_0_1"
52         lsnapshot_list -n lss_0_1 ||
53                 lss_err "(4) Fail to list lss_0_1"
54
55         echo "Create lss_0_2 with comment"
56         lsnapshot_create -n lss_0_2 -c "'This is test_0'" ||
57                 lss_err "(5) Fail to create lss_0_2 with comment"
58
59         echo "List lss_0_2"
60         lsnapshot_list -n lss_0_2 | grep "This is test_0" ||
61                 lss_err "(6) Fail to list lss_0_2"
62
63         echo "Create lss_0_2 with barrier on and comment"
64         lsnapshot_create -n lss_0_3 --barrier=on -c "'Another one'" ||
65                 lss_err "(7) Fail to create lss_0_3 with barrier and comment"
66
67         echo "List lss_0_3"
68         lsnapshot_list -n lss_0_3 | grep "Another one" ||
69                 lss_err "(8) Fail to list lss_0_3"
70
71         echo "Try to create lss_0_0 that exist already"
72         lsnapshot_create -n lss_0_0 &&
73                 lss_err "(9) Create snapshot with exist name should fail" ||
74                 true
75 }
76 run_test 0 "create lustre snapshot"
77
78 test_1a() {
79         mkdir -p $DIR/$tdir || lss_err "(1) Fail to mkdir $DIR/$tdir"
80         rm -f $DIR/$tdir/test-framework.sh
81         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
82                 lss_err "(2) Fail to copy"
83
84         cancel_lru_locks mdc
85         cancel_lru_locks osc
86
87         echo "Create lss_1a_0"
88         lsnapshot_create -n lss_1a_0 ||
89                 lss_err "(3) Fail to create lss_1a_0"
90
91         echo "Check whether mounted (1)"
92         lsnapshot_list -n lss_1a_0 -d | grep "mounted" && {
93                 lsnapshot_list -n lss_1a_0 -d
94                 lss_err "(4) Expect 'not mount', got 'mounted' for lss_1a_0"
95         }
96
97         echo "Mount lss_1a_0"
98         lsnapshot_mount -n lss_1a_0 ||
99                 lss_err "(5) Fail to mount lss_1a_0"
100
101         echo "Check whether mounted (2)"
102         local mcount=$(lsnapshot_list -n lss_1a_0 -d | grep "not mount" | wc -l)
103         [[ $mcount -ne 0 ]] && {
104                 if combined_mgs_mds ; then
105                         lsnapshot_list -n lss_1a_0 -d
106                         lss_err "(6.1) Got unexpected 'not mount' for lss_1a_0"
107                 fi
108
109                 [[ $mcount -gt 1 ]] && {
110                         lsnapshot_list -n lss_1a_0 -d
111                         lss_err "(6.2) Got unexpected 'not mount' for lss_1a_0"
112                 }
113
114                 # The first 10 lines contains and only contains MGS mount status
115                 lsnapshot_list -n lss_1a_0 -d | head -n 10 |
116                         grep "not mount" || {
117                         lsnapshot_list -n lss_1a_0 -d
118                         lss_err "(6.3) Got unexpected 'not mount' for lss_1a_0"
119                 }
120         }
121
122         local ss_fsname=$(lsnapshot_list -n lss_1a_0 |
123                         awk '/^snapshot_fsname/ { print $2 }')
124         local mntpt="/mnt/$ss_fsname"
125         local saved_fsname=$FSNAME
126
127         mkdir -p $mntpt ||
128                 lss_err "(7) Fail to create mount point $mntpt"
129         FSNAME=$ss_fsname
130         echo "Mount client"
131         mount_client $mntpt ro || {
132                 FSNAME=$saved_fsname
133                 lss_err "(8) Fail to mount client for lss_1a_0"
134         }
135
136         FSNAME=$saved_fsname
137         echo "Check whether the file in snapshot is the same as original one"
138         diff $DIR/$tdir/test-framework.sh $mntpt/$tdir/test-framework.sh ||
139                 lss_err "(9) files should be the same"
140
141         echo "Modify the original file, and check again"
142         echo dummy >> $DIR/$tdir/test-framework.sh
143         diff $DIR/$tdir/test-framework.sh $mntpt/$tdir/test-framework.sh &&
144                 lss_err "(10) files should be different"
145
146         umount $mntpt ||
147                 lss_err "(11) Fail to umount client for lss_1a_0"
148
149         echo "Umount lss_1a_0"
150         lsnapshot_umount -n lss_1a_0 ||
151                 lss_err "(12) Fail to umount lss_1a_0"
152
153         echo "Check whether mounted (3)"
154         lsnapshot_list -n lss_1a_0 -d | grep "mounted" && {
155                 lsnapshot_list -n lss_1a_0 -d
156                 lss_err "(13) Expect 'not mount', got 'mounted' for lss_1a_0"
157         } || true
158 }
159 run_test 1a "mount/umount lustre snapshot"
160
161 test_1b() {
162         echo "Create lss_1b_0"
163         lsnapshot_create -n lss_1b_0 ||
164                 lss_err "(1) Fail to create lss_1b_0"
165
166         echo "Check whether mounted (1)"
167         lsnapshot_list -n lss_1b_0 -d | grep "mounted" && {
168                 lsnapshot_list -n lss_1b_0 -d
169                 lss_err "(2) Expect 'not mount', got 'mounted' for lss_1b_0"
170         }
171
172         stopall || lss_err "(3) Fail to stopall"
173
174         echo "Mount lss_1b_0"
175         lsnapshot_mount -n lss_1b_0 ||
176                 lss_err "(4) Fail to mount lss_1b_0"
177
178         echo "Check whether mounted (2)"
179         lsnapshot_list -n lss_1b_0 -d | grep "not mount" && {
180                 lsnapshot_list -n lss_1b_0 -d
181                 lss_err "(5) Expect 'mounted', got 'not mount' for lss_1b_0"
182         }
183
184         echo "umount lss_1b_0"
185         lsnapshot_umount -n lss_1b_0 ||
186                 lss_err "(6) Fail to umount lss_1b_0"
187
188         echo "Check whether mounted (3)"
189         lsnapshot_list -n lss_1b_0 -d | grep "mounted" && {
190                 lsnapshot_list -n lss_1b_0 -d
191                 lss_err "(7) Expect 'not mount', got 'mounted' for lss_1b_0"
192         }
193
194         setupall || lss_err "(8) Fail to setupall"
195 }
196 run_test 1b "mount snapshot without original filesystem mounted"
197
198 test_2() {
199         echo "Create lss_2_0"
200         lsnapshot_create -n lss_2_0 --barrier=off ||
201                 lss_err "(1) Fail to create lss_2_0"
202
203         echo "List lss_2_0"
204         lsnapshot_list -n lss_2_0 ||
205                 lss_err "(2) Fail to list lss_2_0"
206
207         echo "Destroy lss_2_0"
208         lsnapshot_destroy -n lss_2_0 ||
209                 lss_err "(3) Fail to destroy lss_2_0"
210
211         echo "Try to list lss_2_0 after destroy"
212         lsnapshot_list -n lss_2_0 &&
213                 lss_err "(4) List lss_2_0 should fail after destroy"
214
215         echo "Create lss_2_1"
216         lsnapshot_create -n lss_2_1 --barrier=off ||
217                 lss_err "(5) Fail to create lss_2_1"
218
219         echo "List lss_2_1"
220         lsnapshot_list -n lss_2_1 ||
221                 lss_err "(6) Fail to list lss_2_1"
222
223         echo "Mount lss_2_1"
224         lsnapshot_mount -n lss_2_1 ||
225                 lss_err "(7) Fail to mount lss_2_1"
226
227         echo "Try to destroy lss_2_1 with mounted"
228         lsnapshot_destroy -n lss_2_1 &&
229                 lss_err "(8) Destroy mounted snapshot without -f should fail"
230
231         echo "Destroy lss_2_1 by force with mounted"
232         lsnapshot_destroy -n lss_2_1 -f ||
233                 lss_err "(9) Destroy mounted snapshot with -f should succeed"
234
235         echo "Try to list lss_2_1 after destroy"
236         lsnapshot_list -n lss_2_1 &&
237                 lss_err "(10) List lss_2_1 should fail after destroy" || true
238 }
239 run_test 2 "destroy lustre snapshot"
240
241 test_3a() {
242         echo "Create lss_3a_0"
243         lsnapshot_create -n lss_3a_0 --barrier=off -c "'It is test_3a'" ||
244                 lss_err "(1) Fail to create lss_3a_0"
245
246         echo "List lss_3a_0"
247         lsnapshot_list -n lss_3a_0 ||
248                 lss_err "(2) Fail to list lss_3a_0"
249
250         local old_mtime=$(lsnapshot_list -n lss_3a_0 |
251                         awk '/^modify_time/ { $1=""; print $0 }')
252
253         echo "Rename lss_3a_0 to lss_3a_1"
254         lsnapshot_modify -n lss_3a_0 -N "lss_3a_1" ||
255                 lss_err "(3) Fail to rename lss_3a_0 to lss_3a_1"
256
257         echo "Try to list lss_3a_0 after rename"
258         lsnapshot_list -n lss_3a_0 &&
259                 lss_err "(4) List lss_3a_0 should fail after rename"
260
261         echo "List lss_3a_1"
262         lsnapshot_list -n lss_3a_1 ||
263                 lss_err "(5) Fail to list lss_3a_1"
264
265         local new_mtime=$(lsnapshot_list -n lss_3a_1 |
266                         awk '/^modify_time/ { $1=""; print $0 }')
267         echo "Check whether mtime has been changed"
268         [ "$old_mtime" != "$new_mtime" ] ||
269                 lss_err "(6) mtime should be changed because of rename"
270
271         echo "Modify lss_3a_1's comment"
272         lsnapshot_modify -n lss_3a_1 -c "'Renamed from lss_3a_0'" ||
273                 lss_err "(7) Fail to change lss_3a_1's comment"
274
275         echo "Check whether comment has been changed"
276         lsnapshot_list -n lss_3a_1 -d | grep "It is test_3a" && {
277                 lsnapshot_list -n lss_3a_1 -d
278                 lss_err "(8) The comment should have been changed"
279         }
280
281         echo "Modify lss_3a_1's name and comment together"
282         lsnapshot_modify -n lss_3a_1 -N "lss_3a_2" -c "'Change again'" ||
283                 lss_err "(9) Fail to modify lss_3a_1"
284
285         echo "Mount lss_3a_2"
286         lsnapshot_mount -n lss_3a_2 ||
287                 lss_err "(10) Fail to mount lss_3a_2"
288
289         echo "Try to rename lss_3a_2 to lss_3a_3 with mounted"
290         lsnapshot_modify -n lss_3a_2 -N "lss_3a_3" &&
291                 lss_err "(11) Rename mounted snapshot lss_3a_2 should fail"
292
293         echo "Modify lss_3a_2's comment with mounted"
294         lsnapshot_modify -n lss_3a_2 -c "'Change comment with mounted'" ||
295                 lss_err "(12) Change comment with mount should succeed"
296
297         echo "Umount lss_3a_2"
298         lsnapshot_umount -n lss_3a_2 ||
299                 lss_err "(13) Fail to umount lss_3a_2"
300 }
301 run_test 3a "modify lustre snapshot"
302
303 test_3b() {
304         echo "Create lss_3b_0"
305         lsnapshot_create -n lss_3b_0 --barrier=off -c "'It is test_3b'" ||
306                 lss_err "(1) Fail to create lss_3b_0"
307
308         echo "List lss_3b_0"
309         lsnapshot_list -n lss_3b_0 ||
310                 lss_err "(2) Fail to list lss_3b_0"
311
312         stopall || lss_err "(3) Fail to stopall"
313
314         echo "Modify lss_3b_0's name and comment together"
315         lsnapshot_modify -n lss_3b_0 -N "lss_3b_1" -c "'Change again'" ||
316                 lss_err "(4) Fail to modify lss_3b_0"
317
318         echo "Try to list lss_3b_0 after rename"
319         lsnapshot_list -n lss_3b_0 &&
320                 lss_err "(5) List lss_3b_0 should fail after rename"
321
322         echo "Check whether comment has been changed"
323         lsnapshot_list -n lss_3b_1 -d | grep "It is test_3b" && {
324                 lsnapshot_list -n lss_3b_1 -d
325                 lss_err "(6) The comment should have been changed"
326         }
327
328         setupall || lss_err "(7) Fail to setupall"
329 }
330 run_test 3b "modify snapshot without original filesystem mounted"
331
332 test_4() { # LU-10843
333         combined_mgs_mds && skip "Combined MGS/MDS" && return
334
335         local rcmd="$LCTL get_param ldlm.namespaces.MGS.resource_count"
336
337         local exports=$(do_facet mgs "$LCTL get_param -n mgs.MGS.num_exports")
338         local rcount=$(do_facet mgs $rcmd)
339
340         echo "Remount MGT"
341         stop mgs || error "stop mgs failed"
342         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
343
344         echo "Wait for all reconnects"
345         local CMD="$LCTL get_param -n mgs.MGS.num_exports"
346         wait_update_facet mgs "$CMD" $exports ||
347                 lss_err "(1) failed to export from mgs"
348
349         wait_update_facet mgs "$rcmd" $rcount ||
350                 lss_err "(2) failed to reconnect mds"
351
352         echo "Create lss_4_0"
353         lsnapshot_create -n lss_4_0 -c "'It is test_4'" ||
354                 lss_err "(3) Fail to create lss_4_0"
355
356         echo "List lss_4_0"
357         lsnapshot_list -n lss_4_0 ||
358                 lss_err "(4) Fail to list lss_4_0"
359
360         echo "Destroy lss_4_0"
361         lsnapshot_destroy -n lss_4_0 ||
362                 lss_err "(5) Fail to destroy lss_4_0"
363
364 }
365 run_test 4 "create/delete snapshot after MGS remount"
366
367 lss_cleanup
368 do_facet mgs $LCTL set_param debug=-snapshot
369 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=-snapshot
370 complete $SECONDS
371 check_and_cleanup_lustre
372 exit_status