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 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_rename_007_pos.ksh	1.2	07/10/09 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_rename_007_pos
39#
40# DESCRIPTION:
41#	Rename dataset, verify that the data haven't changed.
42#
43# STRATEGY:
44#	1. Create random data and copy to dataset.
45#	2. Perform renaming commands.
46#	3. Verify that the data haven't changed.
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2007-03-15)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60# Check if current system support recursive rename
61$ZFS rename 2>&1 | grep "rename -r" >/dev/null 2>&1
62if (($? != 0)); then
63	log_unsupported
64fi
65
66function cleanup
67{
68	if datasetexists $TESTPOOL/$TESTFS ; then
69		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
70	fi
71	log_must $ZFS create $TESTPOOL/$TESTFS
72	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
73
74	$RM -f $SRC_FILE $DST_FILE
75}
76
77function target_obj
78{
79	typeset dtst=$1
80
81	typeset obj
82	typeset type=$(get_prop type $dtst)
83	if [[ $type == "filesystem" ]]; then
84		obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/}
85	elif [[ $type == "volume" ]]; then
86		obj=/dev/zvol/$dtst
87	fi
88
89	print $obj
90}
91
92log_assert "Rename dataset, verify that the data haven't changed."
93log_onexit cleanup
94
95# Generate random data
96#
97BS=512 ; CNT=2048
98SRC_FILE=$TMPDIR/srcfile.${TESTCASE_ID}
99DST_FILE=$TMPDIR/dstfile.${TESTCASE_ID}
100log_must $DD if=/dev/random of=$SRC_FILE bs=$BS count=$CNT
101
102fs=$TESTPOOL/$TESTFS/fs.${TESTCASE_ID}
103fsclone=$TESTPOOL/$TESTFS/fsclone.${TESTCASE_ID}
104log_must $ZFS create $fs
105
106obj=$(target_obj $fs)
107log_must $CP $SRC_FILE $obj
108
109snap=${fs}@snap.${TESTCASE_ID}
110log_must $ZFS snapshot $snap
111log_must $ZFS clone $snap $fsclone
112
113# Rename dataset & clone
114#
115log_must $ZFS rename $fs ${fs}-new
116log_must $ZFS rename $fsclone ${fsclone}-new
117
118# Compare source file and target file
119#
120obj=$(target_obj ${fs}-new)
121log_must $DIFF $SRC_FILE $obj
122obj=$(target_obj ${fsclone}-new)
123log_must $DIFF $SRC_FILE $obj
124
125# Rename snapshot and re-clone dataset
126#
127log_must $ZFS rename ${fs}-new $fs
128log_must $ZFS rename $snap ${snap}-new
129log_must $ZFS clone ${snap}-new $fsclone
130
131# Compare source file and target file
132#
133obj=$(target_obj $fsclone)
134log_must $DIFF $SRC_FILE $obj
135
136if is_global_zone; then
137	vol=$TESTPOOL/$TESTFS/vol.${TESTCASE_ID} ;	volclone=$TESTPOOL/$TESTFS/volclone.${TESTCASE_ID}
138	log_must $ZFS create -V 100M $vol
139
140	obj=$(target_obj $vol)
141	log_must $DD if=$SRC_FILE of=$obj bs=$BS count=$CNT
142
143	snap=${vol}@snap.${TESTCASE_ID}
144	log_must $ZFS snapshot $snap
145	log_must $ZFS clone $snap $volclone
146
147	# Rename dataset & clone
148	log_must $ZFS rename $vol ${vol}-new
149	log_must $ZFS rename $volclone ${volclone}-new
150
151	# Compare source file and target file
152	obj=$(target_obj ${vol}-new)
153	log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT
154	log_must $DIFF $SRC_FILE $DST_FILE
155	obj=$(target_obj ${volclone}-new)
156	log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT
157	log_must $DIFF $SRC_FILE $DST_FILE
158
159	# Rename snapshot and re-clone dataset
160	log_must $ZFS rename ${vol}-new $vol
161	log_must $ZFS rename $snap ${snap}-new
162	log_must $ZFS clone ${snap}-new $volclone
163
164	# Compare source file and target file
165	obj=$(target_obj $volclone)
166	log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT
167	log_must $DIFF $SRC_FILE $DST_FILE
168fi
169
170log_pass "Rename dataset, the data haven't changed passed."
171