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_001_pos
34#
35# DESCRIPTION:
36#       'zfs rename' should successfully rename valid datasets.
37#       As a sub-assertion we check to ensure the datasets that can
38#       be mounted are mounted.
39#
40# STRATEGY:
41#       1. Given a file system, snapshot and volume.
42#       2. Rename each dataset object to a new name.
43#       3. Verify that only the new name is displayed by zfs list.
44#       4. Verify mountable datasets are mounted.
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"
61set -A mountable "$TESTPOOL/$TESTFS1-new" "$TESTPOOL/$TESTFS@snapshot-new" \
62    "$TESTPOOL/$TESTCTR/$TESTFS1-new" "$TESTPOOL/$TESTFS-clone-new"
63
64#
65# cleanup defined in zfs_rename.kshlib
66#
67log_onexit cleanup
68
69log_assert "'zfs rename' should successfully rename valid datasets"
70
71additional_setup
72
73typeset -i i=0
74while (( i < ${#dataset[*]} )); do
75	rename_dataset ${dataset[i]} ${dataset[i]}-new
76
77	((i = i + 1))
78done
79
80log_note "Verify mountable datasets are mounted in their new namespace."
81typeset mtpt
82i=0
83while (( i < ${#mountable[*]} )); do
84	# Snapshot have no mountpoint
85	if [[ ${mountable[i]} != *@* ]]; then
86		log_must mounted ${mountable[i]}
87		mtpt=$(get_prop mountpoint ${mountable[i]})
88	else
89		mtpt=$(snapshot_mountpoint ${mountable[i]})
90	fi
91
92	if ! cmp_data $DATA $mtpt/$TESTFILE0 ; then
93		log_fail "$mtpt/$TESTFILE0 gets corrupted after rename operation."
94	fi
95
96	((i = i + 1))
97done
98
99#verify the data integrity in zvol
100if is_global_zone; then
101	log_must eval "$DD if=${VOL_R_PATH}-new of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
102	if ! cmp_data $VOLDATA $DATA ; then
103		log_fail "$VOLDATA gets corrupted after rename operation."
104	fi
105fi
106
107# rename back fs
108typeset -i i=0
109while ((i < ${#dataset[*]} )); do
110	if datasetexists ${dataset[i]}-new ; then
111                log_must $ZFS rename ${dataset[i]}-new ${dataset[i]}
112	fi
113        ((i = i + 1))
114done
115
116log_pass "'zfs rename' successfully renamed each dataset type."
117