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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)history_008_pos.ksh	1.3	09/01/12 SMI"
30#
31
32. $STF_SUITE/tests/history/history_common.kshlib
33. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib
34
35#################################################################################
36#
37# __stc_assertion_start
38#
39# ID: history_008_pos
40#
41# DESCRIPTION:
42#	Internal journal records all the recursively operations.
43#
44# STRATEGY:
45#	1. Create a filesystem and several sub-filesystems in it.
46#	2. Make recursively snapshot.
47#	3. Verify internal journal records all the recursively operations.
48#	4. Do the same verification to inherit, rollback and destroy.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2006-12-22)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "global"
61
62$ZFS 2>&1 | $GREP "allow" > /dev/null
63(($? != 0)) && log_unsupported
64
65function cleanup
66{
67	[[ -f $REAL_HISTORY ]] && $RM -f $REAL_HISTORY
68	[[ -f $ADD_HISTORY ]] && $RM -f $ADD_HISTORY
69	if datasetexists $root_testfs; then
70		log_must $ZFS destroy -rf $root_testfs
71	fi
72	log_must $ZFS create $root_testfs
73}
74
75log_assert "Internal journal records all the recursively operations."
76log_onexit cleanup
77
78root_testfs=$TESTPOOL/$TESTFS
79fs1=$root_testfs/fs1; fs2=$root_testfs/fs2; fs3=$root_testfs/fs3
80for fs in $fs1 $fs2 $fs3; do
81	log_must $ZFS create $fs
82done
83
84#
85# Verify 'zfs snapshot -r'
86#
87format_history $TESTPOOL $REAL_HISTORY -i
88log_must $ZFS snapshot -r ${root_testfs}@snap
89additional_history $TESTPOOL $ADD_HISTORY -i
90for ds in $fs1 $fs2 $fs3 ; do
91	log_must verify_history $ADD_HISTORY "snapshot" ${ds}@snap
92done
93
94log_must $ZFS snapshot ${root_testfs}@snap2
95log_must $ZFS snapshot ${root_testfs}@snap3
96typeset snap2_id=$(get_dataset_id ${root_testfs}@snap2)
97typeset snap3_id=$(get_dataset_id ${root_testfs}@snap3)
98
99#
100# Verify 'zfs rollback -r'
101#
102format_history $TESTPOOL $REAL_HISTORY -i
103log_must $ZFS rollback -r ${root_testfs}@snap
104additional_history $TESTPOOL $ADD_HISTORY -i
105
106cat $ADD_HISTORY
107for ds_id in ${snap2_id} ${snap3_id}; do
108	log_must verify_destroyed $ADD_HISTORY $ds_id
109done
110log_must verify_direct_history $ADD_HISTORY "rollback -r" $root_testfs
111
112#
113# Verify 'zfs inherit -r'
114#
115format_history $TESTPOOL $REAL_HISTORY -i
116log_must $ZFS inherit -r mountpoint $root_testfs
117additional_history $TESTPOOL $ADD_HISTORY -i
118cat $ADD_HISTORY
119for ds in $fs1 $fs2 $fs3 $root_testfs; do
120	 log_must verify_history $ADD_HISTORY "inherit" $ds
121done
122log_must verify_direct_history $ADD_HISTORY "inherit -r mountpoint" $root_testfs
123
124# Initial original $REAL_HISTORY
125format_history $TESTPOOL $REAL_HISTORY -i
126
127fs1_id=$(get_dataset_id $fs1)
128fs2_id=$(get_dataset_id $fs2)
129fs3_id=$(get_dataset_id $fs3)
130root_id=$(get_dataset_id $root_testfs)
131fs1_snap_id=$(get_dataset_id ${fs1}@snap)
132fs2_snap_id=$(get_dataset_id ${fs2}@snap)
133fs3_snap_id=$(get_dataset_id ${fs3}@snap)
134root_snap_id=$(get_dataset_id ${root_testfs}@snap)
135
136#
137# Verify 'zfs destroy -r'
138#
139log_must $ZFS destroy -r $root_testfs
140additional_history $TESTPOOL $ADD_HISTORY -i
141cat $ADD_HISTORY
142for ds_id in ${fs1_id} ${fs2_id} ${fs3_id} ${root_id} ${fs1_snap_id} ${fs2_snap_id} ${fs3_snap_id} ${root_snap_id}; do
143	log_must verify_destroyed $ADD_HISTORY $ds_id
144done
145log_must verify_direct_history $ADD_HISTORY "destroy -r" $root_testfs
146
147log_pass "Internal journal records all the recursively operations passed."
148