Whamcloud - gitweb
LU-16073 utils: double snapshot_mount fix
[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 -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"
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 "Remount lss_1b_0"
183         lsnapshot_mount -n lss_1b_0 &&
184                 lss_err "(6) Mount already mounted snapshot should fail"
185
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"
190         }
191
192         echo "umount lss_1b_0"
193         lsnapshot_umount -n lss_1b_0 ||
194                 lss_err "(8) Fail to umount lss_1b_0"
195
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"
200         }
201
202         setupall || lss_err "(10) Fail to setupall"
203 }
204 run_test 1b "mount snapshot without original filesystem mounted"
205
206 test_2() {
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"
210
211         echo "List lss_2_0"
212         lsnapshot_list -n lss_2_0 ||
213                 lss_err "(2) Fail to list lss_2_0"
214
215         echo "Destroy lss_2_0"
216         lsnapshot_destroy -n lss_2_0 ||
217                 lss_err "(3) Fail to destroy lss_2_0"
218
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"
222
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"
226
227         echo "List lss_2_1"
228         lsnapshot_list -n lss_2_1 ||
229                 lss_err "(6) Fail to list lss_2_1"
230
231         echo "Mount lss_2_1"
232         lsnapshot_mount -n lss_2_1 ||
233                 lss_err "(7) Fail to mount lss_2_1"
234
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"
238
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"
242
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
246 }
247 run_test 2 "destroy lustre snapshot"
248
249 test_3a() {
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"
253
254         echo "List lss_3a_0"
255         lsnapshot_list -n lss_3a_0 ||
256                 lss_err "(2) Fail to list lss_3a_0"
257
258         local old_mtime=$(lsnapshot_list -n lss_3a_0 |
259                         awk '/^modify_time/ { $1=""; print $0 }')
260
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"
264
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"
268
269         echo "List lss_3a_1"
270         lsnapshot_list -n lss_3a_1 ||
271                 lss_err "(5) Fail to list lss_3a_1"
272
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"
278
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"
282
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"
287         }
288
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"
292
293         echo "Mount lss_3a_2"
294         lsnapshot_mount -n lss_3a_2 ||
295                 lss_err "(10) Fail to mount lss_3a_2"
296
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"
300
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"
304
305         echo "Umount lss_3a_2"
306         lsnapshot_umount -n lss_3a_2 ||
307                 lss_err "(13) Fail to umount lss_3a_2"
308 }
309 run_test 3a "modify lustre snapshot"
310
311 test_3b() {
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"
315
316         echo "List lss_3b_0"
317         lsnapshot_list -n lss_3b_0 ||
318                 lss_err "(2) Fail to list lss_3b_0"
319
320         stopall || lss_err "(3) Fail to stopall"
321
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"
325
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"
329
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"
334         }
335
336         setupall || lss_err "(7) Fail to setupall"
337 }
338 run_test 3b "modify snapshot without original filesystem mounted"
339
340 test_4() { # LU-10843
341         combined_mgs_mds && skip "Combined MGS/MDS" && return
342
343         local rcmd="$LCTL get_param ldlm.namespaces.MGS.resource_count"
344
345         local exports=$(do_facet mgs "$LCTL get_param -n mgs.MGS.num_exports")
346         local rcount=$(do_facet mgs $rcmd)
347
348         echo "Remount MGT"
349         stop mgs || error "stop mgs failed"
350         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
351
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"
356
357         wait_update_facet mgs "$rcmd" $rcount ||
358                 lss_err "(2) failed to reconnect mds"
359
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"
363
364         echo "List lss_4_0"
365         lsnapshot_list -n lss_4_0 ||
366                 lss_err "(4) Fail to list lss_4_0"
367
368         echo "Destroy lss_4_0"
369         lsnapshot_destroy -n lss_4_0 ||
370                 lss_err "(5) Fail to destroy lss_4_0"
371
372 }
373 run_test 4 "create/delete snapshot after MGS remount"
374
375 lss_cleanup
376 do_facet mgs $LCTL set_param debug=-snapshot
377 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param debug=-snapshot
378 complete $SECONDS
379 check_and_cleanup_lustre
380 exit_status