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. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_rename_002_pos
34#
35# DESCRIPTION:
36#       'zfs rename' should successfully be capable of renaming
37#       valid datasets back and forth multiple times.
38#
39# STRATEGY:
40#       1. Given a file system, snapshot and volume.
41#       2. Rename each dataset object to a new name.
42#       3. Rename each dataset back to its original name.
43#       4. Repeat steps 2 and 3 multiple times.
44#       5. Verify that the correct name is displayed by zfs list.
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2005-06-29)
51#
52# __stc_assertion_end
53#
54###############################################################################
55
56verify_runnable "both"
57
58set -A dataset "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS1" \
59   "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
60    "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS-clone"
61
62#
63# cleanup defined in zfs_rename.kshlib
64#
65log_onexit cleanup
66
67log_assert "'zfs rename' should successfully rename valid datasets"
68
69additional_setup
70
71typeset -i i=0
72typeset -i iters=10
73
74while ((i < ${#dataset[*]} )); do
75	j=0
76	while ((j < iters )); do
77		rename_dataset ${dataset[i]} ${dataset[i]}-new
78		rename_dataset ${dataset[i]}-new ${dataset[i]}
79
80		((j = j + 1))
81	done
82
83	if [[ ${dataset[i]} == *@* ]]; then
84		data=$(snapshot_mountpoint ${dataset[i]})/$TESTFILE0
85	elif [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" ]] && is_global_zone; then
86		log_must eval "$DD if=$VOL_R_PATH of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
87		data=$VOLDATA
88	else
89		data=$(get_prop mountpoint ${dataset[i]})/$TESTFILE0
90	fi
91
92	if ! cmp_data $DATA $data; then
93		log_fail "$data gets corrupted after $iters times rename operations."
94	fi
95
96	((i = i + 1))
97done
98
99log_pass "'zfs rename' renamed each dataset type multiple times as expected."
100