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 "not mount" | wc -l)
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 "umount lss_1b_0"
183 lsnapshot_umount -n lss_1b_0 ||
184 lss_err "(6) Fail to umount lss_1b_0"
186 echo "Check whether mounted (3)"
187 lsnapshot_list -n lss_1b_0 -d | grep "mounted" && {
188 lsnapshot_list -n lss_1b_0 -d
189 lss_err "(7) Expect 'not mount', got 'mounted' for lss_1b_0"
192 setupall || lss_err "(8) Fail to setupall"
194 run_test 1b "mount snapshot without original filesystem mounted"
197 echo "Create lss_2_0"
198 lsnapshot_create -n lss_2_0 --barrier=off ||
199 lss_err "(1) Fail to create lss_2_0"
202 lsnapshot_list -n lss_2_0 ||
203 lss_err "(2) Fail to list lss_2_0"
205 echo "Destroy lss_2_0"
206 lsnapshot_destroy -n lss_2_0 ||
207 lss_err "(3) Fail to destroy lss_2_0"
209 echo "Try to list lss_2_0 after destroy"
210 lsnapshot_list -n lss_2_0 &&
211 lss_err "(4) List lss_2_0 should fail after destroy"
213 echo "Create lss_2_1"
214 lsnapshot_create -n lss_2_1 --barrier=off ||
215 lss_err "(5) Fail to create lss_2_1"
218 lsnapshot_list -n lss_2_1 ||
219 lss_err "(6) Fail to list lss_2_1"
222 lsnapshot_mount -n lss_2_1 ||
223 lss_err "(7) Fail to mount lss_2_1"
225 echo "Try to destroy lss_2_1 with mounted"
226 lsnapshot_destroy -n lss_2_1 &&
227 lss_err "(8) Destroy mounted snapshot without -f should fail"
229 echo "Destroy lss_2_1 by force with mounted"
230 lsnapshot_destroy -n lss_2_1 -f ||
231 lss_err "(9) Destroy mounted snapshot with -f should succeed"
233 echo "Try to list lss_2_1 after destroy"
234 lsnapshot_list -n lss_2_1 &&
235 lss_err "(10) List lss_2_1 should fail after destroy" || true
237 run_test 2 "destroy lustre snapshot"
240 echo "Create lss_3a_0"
241 lsnapshot_create -n lss_3a_0 --barrier=off -c "'It is test_3a'" ||
242 lss_err "(1) Fail to create lss_3a_0"
245 lsnapshot_list -n lss_3a_0 ||
246 lss_err "(2) Fail to list lss_3a_0"
248 local old_mtime=$(lsnapshot_list -n lss_3a_0 |
249 awk '/^modify_time/ { $1=""; print $0 }')
251 echo "Rename lss_3a_0 to lss_3a_1"
252 lsnapshot_modify -n lss_3a_0 -N "lss_3a_1" ||
253 lss_err "(3) Fail to rename lss_3a_0 to lss_3a_1"
255 echo "Try to list lss_3a_0 after rename"
256 lsnapshot_list -n lss_3a_0 &&
257 lss_err "(4) List lss_3a_0 should fail after rename"
260 lsnapshot_list -n lss_3a_1 ||
261 lss_err "(5) Fail to list lss_3a_1"
263 local new_mtime=$(lsnapshot_list -n lss_3a_1 |
264 awk '/^modify_time/ { $1=""; print $0 }')
265 echo "Check whether mtime has been changed"
266 [ "$old_mtime" != "$new_mtime" ] ||
267 lss_err "(6) mtime should be changed because of rename"
269 echo "Modify lss_3a_1's comment"
270 lsnapshot_modify -n lss_3a_1 -c "'Renamed from lss_3a_0'" ||
271 lss_err "(7) Fail to change lss_3a_1's comment"
273 echo "Check whether comment has been changed"
274 lsnapshot_list -n lss_3a_1 -d | grep "It is test_3a" && {
275 lsnapshot_list -n lss_3a_1 -d
276 lss_err "(8) The comment should have been changed"
279 echo "Modify lss_3a_1's name and comment together"
280 lsnapshot_modify -n lss_3a_1 -N "lss_3a_2" -c "'Change again'" ||
281 lss_err "(9) Fail to modify lss_3a_1"
283 echo "Mount lss_3a_2"
284 lsnapshot_mount -n lss_3a_2 ||
285 lss_err "(10) Fail to mount lss_3a_2"
287 echo "Try to rename lss_3a_2 to lss_3a_3 with mounted"
288 lsnapshot_modify -n lss_3a_2 -N "lss_3a_3" &&
289 lss_err "(11) Rename mounted snapshot lss_3a_2 should fail"
291 echo "Modify lss_3a_2's comment with mounted"
292 lsnapshot_modify -n lss_3a_2 -c "'Change comment with mounted'" ||
293 lss_err "(12) Change comment with mount should succeed"
295 echo "Umount lss_3a_2"
296 lsnapshot_umount -n lss_3a_2 ||
297 lss_err "(13) Fail to umount lss_3a_2"
299 run_test 3a "modify lustre snapshot"
302 echo "Create lss_3b_0"
303 lsnapshot_create -n lss_3b_0 --barrier=off -c "'It is test_3b'" ||
304 lss_err "(1) Fail to create lss_3b_0"
307 lsnapshot_list -n lss_3b_0 ||
308 lss_err "(2) Fail to list lss_3b_0"
310 stopall || lss_err "(3) Fail to stopall"
312 echo "Modify lss_3b_0's name and comment together"
313 lsnapshot_modify -n lss_3b_0 -N "lss_3b_1" -c "'Change again'" ||
314 lss_err "(4) Fail to modify lss_3b_0"
316 echo "Try to list lss_3b_0 after rename"
317 lsnapshot_list -n lss_3b_0 &&
318 lss_err "(5) List lss_3b_0 should fail after rename"
320 echo "Check whether comment has been changed"
321 lsnapshot_list -n lss_3b_1 -d | grep "It is test_3b" && {
322 lsnapshot_list -n lss_3b_1 -d
323 lss_err "(6) The comment should have been changed"
326 setupall || lss_err "(7) Fail to setupall"
328 run_test 3b "modify snapshot without original filesystem mounted"
330 test_4() { # LU-10843
331 combined_mgs_mds && skip "Combined MGS/MDS" && return
333 local rcmd="$LCTL get_param ldlm.namespaces.MGS.resource_count"
335 local exports=$(do_facet mgs "$LCTL get_param -n mgs.MGS.num_exports")
336 local rcount=$(do_facet mgs $rcmd)
339 stop mgs || error "stop mgs failed"
340 start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
342 echo "Wait for all reconnects"
343 local CMD="$LCTL get_param -n mgs.MGS.num_exports"
344 wait_update_facet mgs "$CMD" $exports ||
345 lss_err "(1) failed to export from mgs"
347 wait_update_facet mgs "$rcmd" $rcount ||
348 lss_err "(2) failed to reconnect mds"
350 echo "Create lss_4_0"
351 lsnapshot_create -n lss_4_0 -c "'It is test_4'" ||
352 lss_err "(3) Fail to create lss_4_0"
355 lsnapshot_list -n lss_4_0 ||
356 lss_err "(4) Fail to list lss_4_0"
358 echo "Destroy lss_4_0"
359 lsnapshot_destroy -n lss_4_0 ||
360 lss_err "(5) Fail to destroy lss_4_0"
363 run_test 4 "create/delete snapshot after MGS remount"
366 do_facet mgs $LCTL set_param debug=-snapshot
367 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=-snapshot
369 check_and_cleanup_lustre