1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26
27 #
28 # Copyright (c) 2013 by Delphix. All rights reserved.
29 #
30
31 . $STF_SUITE/tests/functional/history/history_common.kshlib
32
33 #
34 # DESCRIPTION:
35 # Create a scenario to verify the following zfs subcommands are logged.
36 # create, destroy, clone, rename, snapshot, rollback, set, inherit,
37 # receive, promote, hold and release.
38 #
39 # STRATEGY:
40 # 1. Verify that all the zfs commands listed (barring send) produce an
41 # entry in the pool history.
42 #
43
44 verify_runnable "global"
45
46 function cleanup
47 {
48
49 [[ -f $tmpfile ]] && $RM -f $tmpfile
50 [[ -f $tmpfile2 ]] && $RM -f $tmpfile2
51 for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do
52 datasetexists $dataset && $ZFS destroy -Rf $dataset
53 done
54 $RM -rf /history.$$
55 }
56
57 log_assert "Verify zfs sub-commands which modify state are logged."
58 log_onexit cleanup
59
60 fs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone
61 vol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone
62 fssnap=$fs@fssnap; fssnap2=$fs@fssnap2
63 volsnap=$vol@volsnap; volsnap2=$vol@volsnap2
64 tmpfile=/tmp/tmpfile.$$ ; tmpfile2=/tmp/tmpfile2.$$
65
66 # property value property value
67 #
68 props=(
69 quota 64M recordsize 512
70 reservation 32M reservation none
71 mountpoint /history.$$ mountpoint legacy
72 mountpoint none sharenfs on
73 sharenfs off
74 compression on compression off
75 compression lzjb aclmode discard
76 aclmode groupmask aclmode passthrough
77 atime on atime off
78 devices on devices off
79 exec on exec off
80 setuid on setuid off
81 readonly on readonly off
82 zoned on zoned off
83 snapdir hidden snapdir visible
84 aclinherit discard aclinherit noallow
85 aclinherit secure aclinherit passthrough
86 canmount off canmount on
87 xattr on xattr off
88 compression gzip compression gzip-$((RANDOM%9 + 1))
89 copies $((RANDOM%3 + 1))
90 )
91
92 run_and_verify "$ZFS create $fs"
93 # Set all the property for filesystem
94 typeset -i i=0
95 while ((i < ${#props[@]})) ; do
96 run_and_verify "$ZFS set ${props[$i]}=${props[((i+1))]} $fs"
97
98 # quota, reservation, canmount can not be inherited.
99 #
100 if [[ ${props[$i]} != "quota" && ${props[$i]} != "reservation" && \
101 ${props[$i]} != "canmount" ]];
102 then
103 run_and_verify "$ZFS inherit ${props[$i]} $fs"
104 fi
105
106 ((i += 2))
107 done
108
109 run_and_verify "$ZFS create -V 64M $vol"
110 run_and_verify "$ZFS set volsize=32M $vol"
111 run_and_verify "$ZFS snapshot $fssnap"
112 run_and_verify "$ZFS hold tag $fssnap"
113 run_and_verify "$ZFS release tag $fssnap"
114 run_and_verify "$ZFS snapshot $volsnap"
115 run_and_verify "$ZFS snapshot $fssnap2"
116 run_and_verify "$ZFS snapshot $volsnap2"
117
118 # Send isn't logged...
119 log_must $ZFS send -i $fssnap $fssnap2 > $tmpfile
120 log_must $ZFS send -i $volsnap $volsnap2 > $tmpfile2
121 # Verify that's true
122 $ZPOOL history $TESTPOOL | $GREP 'zfs send' >/dev/null 2>&1 && \
123 log_fail "'zfs send' found in history of \"$TESTPOOL\""
124
125 run_and_verify "$ZFS destroy $fssnap2"
126 run_and_verify "$ZFS destroy $volsnap2"
127 run_and_verify "$ZFS receive $fs < $tmpfile"
128 run_and_verify "$ZFS receive $vol < $tmpfile2"
129 run_and_verify "$ZFS rollback -r $fssnap"
130 run_and_verify "$ZFS rollback -r $volsnap"
131 run_and_verify "$ZFS clone $fssnap $fsclone"
132 run_and_verify "$ZFS clone $volsnap $volclone"
133 run_and_verify "$ZFS rename $fs $newfs"
134 run_and_verify "$ZFS rename $vol $newvol"
135 run_and_verify "$ZFS promote $fsclone"
136 run_and_verify "$ZFS promote $volclone"
137 run_and_verify "$ZFS destroy $newfs"
138 run_and_verify "$ZFS destroy $newvol"
139 run_and_verify "$ZFS destroy -rf $fsclone"
140 run_and_verify "$ZFS destroy -rf $volclone"
141
142 log_pass "zfs sub-commands which modify state are logged passed."