Whamcloud - gitweb
LU-14095 gss: use RCU protection for sunrpc cache
[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
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
13 init_test_env $@
14 init_logging
15
16 ALWAYS_EXCEPT="$SANITY_LSNAPSHOT_EXCEPT "
17 build_test_filter
18
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" ]] &&
23         skip "ZFS only test"
24
25 require_dsh_mds || exit 0
26 require_dsh_ost || exit 0
27
28 check_and_setup_lustre
29
30 do_facet mgs $LCTL set_param debug=+snapshot
31 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=+snapshot
32
33 lss_gen_conf
34 lss_cleanup
35
36 test_0() {
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"
40
41         echo "List lss_0_0"
42         lsnapshot_list -n lss_0_0 ||
43                 lss_err "(2) Fail to list lss_0_0"
44
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"
48
49         echo "List lss_0_1"
50         lsnapshot_list -n lss_0_1 ||
51                 lss_err "(4) Fail to list lss_0_1"
52
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"
56
57         echo "List lss_0_2"
58         lsnapshot_list -n lss_0_2 | grep "This is test_0" ||
59                 lss_err "(6) Fail to list lss_0_2"
60
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"
64
65         echo "List lss_0_3"
66         lsnapshot_list -n lss_0_3 | grep "Another one" ||
67                 lss_err "(8) Fail to list lss_0_3"
68
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" ||
72                 true
73 }
74 run_test 0 "create lustre snapshot"
75
76 test_1a() {
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"
81
82         cancel_lru_locks mdc
83         cancel_lru_locks osc
84
85         echo "Create lss_1a_0"
86         lsnapshot_create -n lss_1a_0 ||
87                 lss_err "(3) Fail to create lss_1a_0"
88
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"
93         }
94
95         echo "Mount lss_1a_0"
96         lsnapshot_mount -n lss_1a_0 ||
97                 lss_err "(5) Fail to mount lss_1a_0"
98
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"
105                 fi
106
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"
110                 }
111
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"
117                 }
118         }
119
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
124
125         mkdir -p $mntpt ||
126                 lss_err "(7) Fail to create mount point $mntpt"
127         FSNAME=$ss_fsname
128         echo "Mount client"
129         mount_client $mntpt ro || {
130                 FSNAME=$saved_fsname
131                 lss_err "(8) Fail to mount client for lss_1a_0"
132         }
133
134         FSNAME=$saved_fsname
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"
138
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"
143
144         umount $mntpt ||
145                 lss_err "(11) Fail to umount client for lss_1a_0"
146
147         echo "Umount lss_1a_0"
148         lsnapshot_umount -n lss_1a_0 ||
149                 lss_err "(12) Fail to umount lss_1a_0"
150
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"
155         } || true
156 }
157 run_test 1a "mount/umount lustre snapshot"
158
159 test_1b() {
160         echo "Create lss_1b_0"
161         lsnapshot_create -n lss_1b_0 ||
162                 lss_err "(1) Fail to create lss_1b_0"
163
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"
168         }
169
170         stopall || lss_err "(3) Fail to stopall"
171
172         echo "Mount lss_1b_0"
173         lsnapshot_mount -n lss_1b_0 ||
174                 lss_err "(4) Fail to mount lss_1b_0"
175
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"
180         }
181
182         echo "umount lss_1b_0"
183         lsnapshot_umount -n lss_1b_0 ||
184                 lss_err "(6) Fail to umount lss_1b_0"
185
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"
190         }
191
192         setupall || lss_err "(8) Fail to setupall"
193 }
194 run_test 1b "mount snapshot without original filesystem mounted"
195
196 test_2() {
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"
200
201         echo "List lss_2_0"
202         lsnapshot_list -n lss_2_0 ||
203                 lss_err "(2) Fail to list lss_2_0"
204
205         echo "Destroy lss_2_0"
206         lsnapshot_destroy -n lss_2_0 ||
207                 lss_err "(3) Fail to destroy lss_2_0"
208
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"
212
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"
216
217         echo "List lss_2_1"
218         lsnapshot_list -n lss_2_1 ||
219                 lss_err "(6) Fail to list lss_2_1"
220
221         echo "Mount lss_2_1"
222         lsnapshot_mount -n lss_2_1 ||
223                 lss_err "(7) Fail to mount lss_2_1"
224
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"
228
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"
232
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
236 }
237 run_test 2 "destroy lustre snapshot"
238
239 test_3a() {
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"
243
244         echo "List lss_3a_0"
245         lsnapshot_list -n lss_3a_0 ||
246                 lss_err "(2) Fail to list lss_3a_0"
247
248         local old_mtime=$(lsnapshot_list -n lss_3a_0 |
249                         awk '/^modify_time/ { $1=""; print $0 }')
250
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"
254
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"
258
259         echo "List lss_3a_1"
260         lsnapshot_list -n lss_3a_1 ||
261                 lss_err "(5) Fail to list lss_3a_1"
262
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"
268
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"
272
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"
277         }
278
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"
282
283         echo "Mount lss_3a_2"
284         lsnapshot_mount -n lss_3a_2 ||
285                 lss_err "(10) Fail to mount lss_3a_2"
286
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"
290
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"
294
295         echo "Umount lss_3a_2"
296         lsnapshot_umount -n lss_3a_2 ||
297                 lss_err "(13) Fail to umount lss_3a_2"
298 }
299 run_test 3a "modify lustre snapshot"
300
301 test_3b() {
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"
305
306         echo "List lss_3b_0"
307         lsnapshot_list -n lss_3b_0 ||
308                 lss_err "(2) Fail to list lss_3b_0"
309
310         stopall || lss_err "(3) Fail to stopall"
311
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"
315
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"
319
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"
324         }
325
326         setupall || lss_err "(7) Fail to setupall"
327 }
328 run_test 3b "modify snapshot without original filesystem mounted"
329
330 test_4() { # LU-10843
331         combined_mgs_mds && skip "Combined MGS/MDS" && return
332
333         local rcmd="$LCTL get_param ldlm.namespaces.MGS.resource_count"
334
335         local exports=$(do_facet mgs "$LCTL get_param -n mgs.MGS.num_exports")
336         local rcount=$(do_facet mgs $rcmd)
337
338         echo "Remount MGT"
339         stop mgs || error "stop mgs failed"
340         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
341
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"
346
347         wait_update_facet mgs "$rcmd" $rcount ||
348                 lss_err "(2) failed to reconnect mds"
349
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"
353
354         echo "List lss_4_0"
355         lsnapshot_list -n lss_4_0 ||
356                 lss_err "(4) Fail to list lss_4_0"
357
358         echo "Destroy lss_4_0"
359         lsnapshot_destroy -n lss_4_0 ||
360                 lss_err "(5) Fail to destroy lss_4_0"
361
362 }
363 run_test 4 "create/delete snapshot after MGS remount"
364
365 lss_cleanup
366 do_facet mgs $LCTL set_param debug=-snapshot
367 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=-snapshot
368 complete $SECONDS
369 check_and_cleanup_lustre
370 exit_status