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