1 #!/bin/ksh
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright (c) 2012 by Delphix. All rights reserved.
15 #
16
17 #
18 # DESCRIPTION
19 # verify 'zfs snapshot <list of snapshots>' works correctly
20 #
21 # STRATEGY
22 # 1. Create multiple datasets
23 # 2. Create mutiple snapshots with a list of valid and invalid
24 # snapshot names
25 # 3. Verify the valid snpashot creation
26
27 . $STF_SUITE/include/libtest.shlib
28
29 function cleanup
30 {
31 for ds in $datasets; do
32 datasetexists $ds && log_must $ZFS destroy -r $ds
33 done
34 $ZFS destroy -r $TESTPOOL/TESTFS4
35 }
36 datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2
37 $TESTPOOL/$TESTFS3"
38
39 invalid_args=("$TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2@now \
40 $TESTPOOL/$TESTFS@blah?" "$TESTPOOL/$TESTFS1@blah* \
41 $TESTPOOL/$TESTFS2@blah? $TESTPOOL/$TESTFS3@blah%" \
42 "$TESTPOOL/$TESTFS1@$($PYTHON -c 'print "x" * 300') $TESTPOOL/$TESTFS2@300 \
43 $TESTPOOL/$TESTFS3@300")
44
45 valid_args=("$TESTPOOL/$TESTFS1@snap $TESTPOOL/$TESTFS2@snap \
46 $TESTPOOL/$TESTFS3@snap" "$TESTPOOL/$TESTFS1@$($PYTHON -c 'print "x" * 200')\
47 $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS3@s")
48
49 log_assert "verify zfs supports multiple consistent snapshots"
50 log_onexit cleanup
51 typeset -i i=1
52 test_data=$STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles
53
54 log_note "destroy a list of valid snapshots"
55 for ds in $datasets; do
56 log_must $ZFS create $ds
57 log_must $CP -r $test_data /$ds
58 done
59 i=0
60 while (( i < ${#valid_args[*]} )); do
61 log_must $ZFS snapshot ${valid_args[i]}
62 for token in ${valid_args[i]}; do
63 log_must snapexists $token && \
64 log_must $ZFS destroy $token
65 done
66 ((i = i + 1))
67 done
68 log_note "destroy a list of invalid snapshots"
69 i=0
70 while (( i < ${#invalid_args[*]} )); do
71 log_mustnot $ZFS snapshot ${invalid_args[i]}
72 for token in ${invalid_args[i]}; do
73 log_mustnot snapexists $token
74 done
75 ((i = i + 1))
76 done
77 log_note "verify multiple snapshot transaction group"
78 txg_group=$($ZDB -Pd $TESTPOOL | $GREP snap | $AWK '{print $7}')
79 for i in 1 2 3; do
80 txg_tag=$($ECHO "$txg_group" | $AWK -v j=$i 'FNR == j {print}')
81 [[ $txg_tag != $($ECHO "$txg_group" | \
82 $AWK -v j=$i 'FNR == j {print}') ]] \
83 && log_fail "snapshots belong to differnt transaction groups"
84 done
85 log_note "verify snapshot contents"
86 for ds in $datasets; do
87 status=$($DIRCMP /$ds /$ds/.zfs/snapshot/snap | $GREP "different")
88 [[ -z $status ]] || log_fail "snapshot contents are different from" \
89 "the filesystem"
90 done
91
92 log_note "verify multiple snapshot with -r option"
93 log_must $ZFS create $TESTPOOL/TESTFS4
94 log_must $ZFS create -p $TESTPOOL/$TESTFS3/TESTFSA$($PYTHON -c 'print "x" * 210')/TESTFSB
95 log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
96 $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
97 log_must $ZFS rename $TESTPOOL/$TESTFS3/TESTFSA$($PYTHON -c 'print "x" * 210') \
98 $TESTPOOL/$TESTFS3/TESTFSA
99 log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
100 $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
101
102 log_pass "zfs multiple snapshot verified correctly"