3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
16 ALWAYS_EXCEPT="$SANITY_LSNAPSHOT_EXCEPT "
19 [[ "$MDS1_VERSION" -lt $(version_code 2.9.55) ]] ||
20 [[ "$OST1_VERSION" -lt $(version_code 2.9.55) ]] &&
21 skip "Need server version at least 2.9.55"
22 [[ "$mds1_FSTYPE" = "ldiskfs" ]] || [[ "$ost1_FSTYPE" = "ldiskfs" ]] &&
25 require_dsh_mds || exit 0
26 require_dsh_ost || exit 0
28 check_and_setup_lustre
30 do_facet mgs $LCTL set_param debug=+snapshot
31 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=+snapshot
37 echo "Create lss_0_0 with default"
38 lsnapshot_create -n lss_0_0 ||
39 lss_err "(1) Fail to create lss_0_0 with default"
42 lsnapshot_list -n lss_0_0 ||
43 lss_err "(2) Fail to list lss_0_0"
45 echo "Create lss_0_1 with barrier off"
46 lsnapshot_create -n lss_0_1 --barrier=off ||
47 lss_err "(3) Fail to create lss_0_1 with barrier off"
50 lsnapshot_list -n lss_0_1 ||
51 lss_err "(4) Fail to list lss_0_1"
53 echo "Create lss_0_2 with comment"
54 lsnapshot_create -n lss_0_2 -c "'This is test_0'" ||
55 lss_err "(5) Fail to create lss_0_2 with comment"
58 lsnapshot_list -n lss_0_2 | grep "This is test_0" ||
59 lss_err "(6) Fail to list lss_0_2"
61 echo "Create lss_0_2 with barrier on and comment"
62 lsnapshot_create -n lss_0_3 --barrier=on -c "'Another one'" ||
63 lss_err "(7) Fail to create lss_0_3 with barrier and comment"
66 lsnapshot_list -n lss_0_3 | grep "Another one" ||
67 lss_err "(8) Fail to list lss_0_3"
69 echo "Try to create lss_0_0 that exist already"
70 lsnapshot_create -n lss_0_0 &&
71 lss_err "(9) Create snapshot with exist name should fail" ||
74 run_test 0 "create lustre snapshot"
77 mkdir -p $DIR/$tdir || lss_err "(1) Fail to mkdir $DIR/$tdir"
78 rm -f $DIR/$tdir/test-framework.sh
79 cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
80 lss_err "(2) Fail to copy"
85 echo "Create lss_1a_0"
86 lsnapshot_create -n lss_1a_0 ||
87 lss_err "(3) Fail to create lss_1a_0"
89 echo "Check whether mounted (1)"
90 lsnapshot_list -n lss_1a_0 -d | grep "mounted" && {
91 lsnapshot_list -n lss_1a_0 -d
92 lss_err "(4) Expect 'not mount', got 'mounted' for lss_1a_0"
96 lsnapshot_mount -n lss_1a_0 ||
97 lss_err "(5) Fail to mount lss_1a_0"
99 echo "Check whether mounted (2)"
100 local mcount=$(lsnapshot_list -n lss_1a_0 -d | grep -c "not mount")
101 [[ $mcount -ne 0 ]] && {
102 if combined_mgs_mds ; then
103 lsnapshot_list -n lss_1a_0 -d
104 lss_err "(6.1) Got unexpected 'not mount' for lss_1a_0"
107 [[ $mcount -gt 1 ]] && {
108 lsnapshot_list -n lss_1a_0 -d
109 lss_err "(6.2) Got unexpected 'not mount' for lss_1a_0"
112 # The first 10 lines contains and only contains MGS mount status
113 lsnapshot_list -n lss_1a_0 -d | head -n 10 |
114 grep "not mount" || {
115 lsnapshot_list -n lss_1a_0 -d
116 lss_err "(6.3) Got unexpected 'not mount' for lss_1a_0"
120 local ss_fsname=$(lsnapshot_list -n lss_1a_0 |
121 awk '/^snapshot_fsname/ { print $2 }')
122 local mntpt="/mnt/$ss_fsname"
123 local saved_fsname=$FSNAME
126 lss_err "(7) Fail to create mount point $mntpt"
129 mount_client $mntpt ro || {
131 lss_err "(8) Fail to mount client for lss_1a_0"
135 echo "Check whether the file in snapshot is the same as original one"
136 diff $DIR/$tdir/test-framework.sh $mntpt/$tdir/test-framework.sh ||
137 lss_err "(9) files should be the same"
139 echo "Modify the original file, and check again"
140 echo dummy >> $DIR/$tdir/test-framework.sh
141 diff $DIR/$tdir/test-framework.sh $mntpt/$tdir/test-framework.sh &&
142 lss_err "(10) files should be different"
145 lss_err "(11) Fail to umount client for lss_1a_0"
147 echo "Umount lss_1a_0"
148 lsnapshot_umount -n lss_1a_0 ||
149 lss_err "(12) Fail to umount lss_1a_0"
151 echo "Check whether mounted (3)"
152 lsnapshot_list -n lss_1a_0 -d | grep "mounted" && {
153 lsnapshot_list -n lss_1a_0 -d
154 lss_err "(13) Expect 'not mount', got 'mounted' for lss_1a_0"
157 run_test 1a "mount/umount lustre snapshot"
160 echo "Create lss_1b_0"
161 lsnapshot_create -n lss_1b_0 ||
162 lss_err "(1) Fail to create lss_1b_0"
164 echo "Check whether mounted (1)"
165 lsnapshot_list -n lss_1b_0 -d | grep "mounted" && {
166 lsnapshot_list -n lss_1b_0 -d
167 lss_err "(2) Expect 'not mount', got 'mounted' for lss_1b_0"
170 stopall || lss_err "(3) Fail to stopall"
172 echo "Mount lss_1b_0"
173 lsnapshot_mount -n lss_1b_0 ||
174 lss_err "(4) Fail to mount lss_1b_0"
176 echo "Check whether mounted (2)"
177 lsnapshot_list -n lss_1b_0 -d | grep "not mount" && {
178 lsnapshot_list -n lss_1b_0 -d
179 lss_err "(5) Expect 'mounted', got 'not mount' for lss_1b_0"
182 echo "Remount lss_1b_0"
183 lsnapshot_mount -n lss_1b_0 &&
184 lss_err "(6) Mount already mounted snapshot should fail"
186 echo "Check whether mounted (3)"
187 lsnapshot_list -n lss_1b_0 -d | grep "not mount" && {
188 lsnapshot_list -n lss_1b_0 -d
189 lss_err "(7) Expect 'mounted', got 'not mount' for lss_1b_0"
192 echo "umount lss_1b_0"
193 lsnapshot_umount -n lss_1b_0 ||
194 lss_err "(8) Fail to umount lss_1b_0"
196 echo "Check whether mounted (4)"
197 lsnapshot_list -n lss_1b_0 -d | grep "mounted" && {
198 lsnapshot_list -n lss_1b_0 -d
199 lss_err "(9) Expect 'not mount', got 'mounted' for lss_1b_0"
202 setupall || lss_err "(10) Fail to setupall"
204 run_test 1b "mount snapshot without original filesystem mounted"
207 echo "Create lss_2_0"
208 lsnapshot_create -n lss_2_0 --barrier=off ||
209 lss_err "(1) Fail to create lss_2_0"
212 lsnapshot_list -n lss_2_0 ||
213 lss_err "(2) Fail to list lss_2_0"
215 echo "Destroy lss_2_0"
216 lsnapshot_destroy -n lss_2_0 ||
217 lss_err "(3) Fail to destroy lss_2_0"
219 echo "Try to list lss_2_0 after destroy"
220 lsnapshot_list -n lss_2_0 &&
221 lss_err "(4) List lss_2_0 should fail after destroy"
223 echo "Create lss_2_1"
224 lsnapshot_create -n lss_2_1 --barrier=off ||
225 lss_err "(5) Fail to create lss_2_1"
228 lsnapshot_list -n lss_2_1 ||
229 lss_err "(6) Fail to list lss_2_1"
232 lsnapshot_mount -n lss_2_1 ||
233 lss_err "(7) Fail to mount lss_2_1"
235 echo "Try to destroy lss_2_1 with mounted"
236 lsnapshot_destroy -n lss_2_1 &&
237 lss_err "(8) Destroy mounted snapshot without -f should fail"
239 echo "Destroy lss_2_1 by force with mounted"
240 lsnapshot_destroy -n lss_2_1 -f ||
241 lss_err "(9) Destroy mounted snapshot with -f should succeed"
243 echo "Try to list lss_2_1 after destroy"
244 lsnapshot_list -n lss_2_1 &&
245 lss_err "(10) List lss_2_1 should fail after destroy" || true
247 run_test 2 "destroy lustre snapshot"
250 echo "Create lss_3a_0"
251 lsnapshot_create -n lss_3a_0 --barrier=off -c "'It is test_3a'" ||
252 lss_err "(1) Fail to create lss_3a_0"
255 lsnapshot_list -n lss_3a_0 ||
256 lss_err "(2) Fail to list lss_3a_0"
258 local old_mtime=$(lsnapshot_list -n lss_3a_0 |
259 awk '/^modify_time/ { $1=""; print $0 }')
261 echo "Rename lss_3a_0 to lss_3a_1"
262 lsnapshot_modify -n lss_3a_0 -N "lss_3a_1" ||
263 lss_err "(3) Fail to rename lss_3a_0 to lss_3a_1"
265 echo "Try to list lss_3a_0 after rename"
266 lsnapshot_list -n lss_3a_0 &&
267 lss_err "(4) List lss_3a_0 should fail after rename"
270 lsnapshot_list -n lss_3a_1 ||
271 lss_err "(5) Fail to list lss_3a_1"
273 local new_mtime=$(lsnapshot_list -n lss_3a_1 |
274 awk '/^modify_time/ { $1=""; print $0 }')
275 echo "Check whether mtime has been changed"
276 [ "$old_mtime" != "$new_mtime" ] ||
277 lss_err "(6) mtime should be changed because of rename"
279 echo "Modify lss_3a_1's comment"
280 lsnapshot_modify -n lss_3a_1 -c "'Renamed from lss_3a_0'" ||
281 lss_err "(7) Fail to change lss_3a_1's comment"
283 echo "Check whether comment has been changed"
284 lsnapshot_list -n lss_3a_1 -d | grep "It is test_3a" && {
285 lsnapshot_list -n lss_3a_1 -d
286 lss_err "(8) The comment should have been changed"
289 echo "Modify lss_3a_1's name and comment together"
290 lsnapshot_modify -n lss_3a_1 -N "lss_3a_2" -c "'Change again'" ||
291 lss_err "(9) Fail to modify lss_3a_1"
293 echo "Mount lss_3a_2"
294 lsnapshot_mount -n lss_3a_2 ||
295 lss_err "(10) Fail to mount lss_3a_2"
297 echo "Try to rename lss_3a_2 to lss_3a_3 with mounted"
298 lsnapshot_modify -n lss_3a_2 -N "lss_3a_3" &&
299 lss_err "(11) Rename mounted snapshot lss_3a_2 should fail"
301 echo "Modify lss_3a_2's comment with mounted"
302 lsnapshot_modify -n lss_3a_2 -c "'Change comment with mounted'" ||
303 lss_err "(12) Change comment with mount should succeed"
305 echo "Umount lss_3a_2"
306 lsnapshot_umount -n lss_3a_2 ||
307 lss_err "(13) Fail to umount lss_3a_2"
309 run_test 3a "modify lustre snapshot"
312 echo "Create lss_3b_0"
313 lsnapshot_create -n lss_3b_0 --barrier=off -c "'It is test_3b'" ||
314 lss_err "(1) Fail to create lss_3b_0"
317 lsnapshot_list -n lss_3b_0 ||
318 lss_err "(2) Fail to list lss_3b_0"
320 stopall || lss_err "(3) Fail to stopall"
322 echo "Modify lss_3b_0's name and comment together"
323 lsnapshot_modify -n lss_3b_0 -N "lss_3b_1" -c "'Change again'" ||
324 lss_err "(4) Fail to modify lss_3b_0"
326 echo "Try to list lss_3b_0 after rename"
327 lsnapshot_list -n lss_3b_0 &&
328 lss_err "(5) List lss_3b_0 should fail after rename"
330 echo "Check whether comment has been changed"
331 lsnapshot_list -n lss_3b_1 -d | grep "It is test_3b" && {
332 lsnapshot_list -n lss_3b_1 -d
333 lss_err "(6) The comment should have been changed"
336 setupall || lss_err "(7) Fail to setupall"
338 run_test 3b "modify snapshot without original filesystem mounted"
340 test_4() { # LU-10843
341 combined_mgs_mds && skip "Combined MGS/MDS" && return
343 local rcmd="$LCTL get_param ldlm.namespaces.MGS.resource_count"
345 local exports=$(do_facet mgs "$LCTL get_param -n mgs.MGS.num_exports")
346 local rcount=$(do_facet mgs $rcmd)
349 stop mgs || error "stop mgs failed"
350 start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
352 echo "Wait for all reconnects"
353 local CMD="$LCTL get_param -n mgs.MGS.num_exports"
354 wait_update_facet mgs "$CMD" $exports ||
355 lss_err "(1) failed to export from mgs"
357 wait_update_facet mgs "$rcmd" $rcount ||
358 lss_err "(2) failed to reconnect mds"
360 echo "Create lss_4_0"
361 lsnapshot_create -n lss_4_0 -c "'It is test_4'" ||
362 lss_err "(3) Fail to create lss_4_0"
365 lsnapshot_list -n lss_4_0 ||
366 lss_err "(4) Fail to list lss_4_0"
368 echo "Destroy lss_4_0"
369 lsnapshot_destroy -n lss_4_0 ||
370 lss_err "(5) Fail to destroy lss_4_0"
373 run_test 4 "create/delete snapshot after MGS remount"
376 do_facet mgs $LCTL set_param debug=-snapshot
377 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=-snapshot
378 complete_test $SECONDS
379 check_and_cleanup_lustre