1#!/usr/local/bin/ksh93 -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# ident	"@(#)history_002_pos.ksh	1.5	09/01/12 SMI"
28#
29
30. $STF_SUITE/tests/history/history_common.kshlib
31. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib
32
33#################################################################################
34#
35# __stc_assertion_start
36#
37# ID: history_002_pos
38#
39# DESCRIPTION:
40#	Create a  scenario to verify the following zfs subcommands are logged.
41# 	    create, destroy, clone, rename, snapshot, rollback,
42#	    set, inherit, receive, promote.
43#
44# STRATEGY:
45#	1. Format zpool history to file $EXPECT_HISTORY.
46#	2. Invoke every sub-commands to this mirror.
47#	3. Compare 'zpool history' log with expected log.
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2006-07-05)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "global"
60
61function cleanup
62{
63	for FileToRm in $EXPECT_HISTORY $REAL_HISTORY $tmpfile $tmpfile2; do
64		[[ -f $FileToRm ]] && log_must $RM -f $FileToRm
65	done
66	for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do
67		datasetexists $dataset && $ZFS destroy -Rf $dataset
68	done
69	log_must $RM -rf /history.${TESTCASE_ID}
70}
71
72log_assert "Verify zfs sub-commands which modify state are logged."
73log_onexit cleanup
74
75format_history $TESTPOOL $EXPECT_HISTORY
76
77fs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone
78vol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone
79fssnap=$fs@fssnap; fssnap2=$fs@fssnap2
80volsnap=$vol@volsnap; volsnap2=$vol@volsnap2
81
82#	property	value		property	value
83#
84set -A props \
85	quota		64M		recordsize	512		\
86	reservation	32M		reservation	none		\
87	mountpoint	/history.${TESTCASE_ID}	mountpoint	legacy		\
88	mountpoint	none		sharenfs	on		\
89	sharenfs	off	\
90	compression	on		compression	off		\
91	compression	lzjb 		aclmode		discard		\
92	aclmode		groupmask	aclmode		passthrough	\
93	atime		on		atime		off		\
94	exec		on		exec		off		\
95	setuid		on		setuid		off		\
96	readonly	on		readonly	off		\
97	snapdir		hidden		snapdir		visible		\
98	aclinherit	discard		aclinherit	noallow		\
99	aclinherit	secure		aclinherit	passthrough	\
100	canmount	off		canmount	on		\
101	compression	gzip		compression	gzip-$((RANDOM%9 + 1)) \
102	copies		$((RANDOM%3 +1))
103
104# Add a few extra properties not supported on FreeBSD, if applicable.  The
105# currently unsupported list is in the source in libzfs_dataset.c.
106if [[ $os_name != "FreeBSD" ]]; then
107	set +A props \
108		devices		on	devices		off		\
109		zoned		on	zoned		off		\
110		shareiscsi	on	shareiscsi	off		\
111		xattr		on	xattr		off
112fi
113
114tmpfile=$TMPDIR/tmpfile.${TESTCASE_ID} ; tmpfile2=$TMPDIR/tmpfile2.${TESTCASE_ID}
115
116exec_record $ZFS create $fs
117
118typeset enc=""
119enc=$(get_prop encryption $fs)
120if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || [[ "$enc" == "off" ]]; then
121	typeset -i n=${#props[@]}
122
123	props[$n]=checksum ;		props[((n+1))]="on"
124	props[((n+2))]=checksum ;	props[((n+3))]="off"
125	props[((n+4))]=checksum ;	props[((n+5))]="fletcher2"
126	props[((n+6))]=checksum ;	props[((n+7))]="fletcher4"
127	props[((n+8))]=checksum ;	props[((n+9))]="sha256"
128fi
129
130# Set all the property for filesystem
131typeset -i i=0
132while ((i < ${#props[@]})) ; do
133	exec_record $ZFS set ${props[$i]}=${props[((i+1))]} $fs
134
135	# quota, reservation, canmount can not be inherited.
136	#
137	if [[ ${props[$i]} != "quota" && \
138	      ${props[$i]} != "reservation" && \
139	      ${props[$i]} != "canmount" ]];
140	then
141		exec_record $ZFS inherit ${props[$i]} $fs
142	fi
143
144	((i += 2))
145done
146exec_record $ZFS create -V 64M $vol
147exec_record $ZFS set volsize=32M $vol
148exec_record $ZFS snapshot $fssnap
149exec_record $ZFS snapshot $volsnap
150exec_record $ZFS snapshot $fssnap2
151exec_record $ZFS snapshot $volsnap2
152log_must eval "$ZFS send -i $fssnap $fssnap2 > $tmpfile"
153log_must eval "$ZFS send -i $volsnap $volsnap2 > $tmpfile2"
154exec_record $ZFS destroy $fssnap2
155exec_record $ZFS destroy $volsnap2
156exec_record eval "$ZFS receive $fs < $tmpfile"
157exec_record eval "$ZFS receive $vol < $tmpfile2"
158exec_record $ZFS rollback -r $fssnap
159exec_record $ZFS rollback -r $volsnap
160exec_record $ZFS clone $fssnap $fsclone
161exec_record $ZFS clone $volsnap $volclone
162exec_record $ZFS rename $fs $newfs
163exec_record $ZFS rename $vol $newvol
164exec_record $ZFS promote $fsclone
165exec_record $ZFS promote $volclone
166exec_record $ZFS destroy $newfs
167exec_record $ZFS destroy $newvol
168exec_record $ZFS destroy -rf $fsclone
169exec_record $ZFS destroy -rf $volclone
170
171format_history $TESTPOOL $REAL_HISTORY
172
173log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY
174
175log_pass "zfs sub-commands which modify state are logged passed."
176