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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_rename_008_pos
34#
35# DESCRIPTION:
36#	zfs rename -r can rename snapshot recursively.
37#
38# STRATEGY:
39#	1. Create snapshot recursively.
40#	2. Rename snapshot recursively.
41#	3. Verify rename -r snapshot correctly.
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2007-03-15)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "both"
54
55# Check if current system support recursive rename
56$ZFS rename 2>&1 | grep "rename -r" > /dev/null 2>&1
57if (($? != 0)); then
58	log_unsupported
59fi
60
61function cleanup
62{
63	typeset -i i=0
64	while ((i < ${#datasets[@]})); do
65		if datasetexists ${datasets[$i]}@snap ; then
66			log_must $ZFS destroy ${datasets[$i]}@snap
67		fi
68		if datasetexists ${datasets[$i]}@snap-new ; then
69			log_must $ZFS destroy ${datasets[$i]}@snap-new
70		fi
71
72		((i += 1))
73	done
74}
75
76log_assert "zfs rename -r can rename snapshot recursively."
77log_onexit cleanup
78
79set -A datasets $TESTPOOL		$TESTPOOL/$TESTCTR \
80	$TESTPOOL/$TESTCTR/$TESTFS1	$TESTPOOL/$TESTFS
81if is_global_zone; then
82	datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL
83fi
84
85log_must $ZFS snapshot -r ${TESTPOOL}@snap
86typeset -i i=0
87while ((i < ${#datasets[@]})); do
88	log_must datasetexists ${datasets[$i]}@snap
89
90	((i += 1))
91done
92
93log_must $ZFS rename -r ${TESTPOOL}@snap ${TESTPOOL}@snap-new
94i=0
95while ((i < ${#datasets[@]})); do
96	log_must datasetexists ${datasets[$i]}@snap-new
97
98	((i += 1))
99done
100
101log_must $ZFS destroy -rf ${TESTPOOL}@snap-new
102
103log_pass "Verify zfs rename -r passed."
104