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.
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.
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]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
37 # Rename dataset, verify that the data haven't changed.
40 # 1. Create random data and copy to dataset.
41 # 2. Perform renaming commands.
42 # 3. Verify that the data haven't changed.
45 verify_runnable "both"
49 if datasetexists $TESTPOOL/$TESTFS ; then
50 log_must zfs destroy -Rf $TESTPOOL/$TESTFS
52 log_must zfs create $TESTPOOL/$TESTFS
53 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
55 rm -f $SRC_FILE $DST_FILE
63 typeset type=$(get_prop type $dtst)
64 if [[ $type == "filesystem" ]]; then
65 obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/}
66 elif [[ $type == "volume" ]]; then
67 obj=$ZVOL_DEVDIR/$dtst
73 log_assert "Rename dataset, verify that the data haven't changed."
76 # Generate random data
79 SRC_FILE=$TESTDIR/srcfile.$$
80 DST_FILE=$TESTDIR/dstfile.$$
81 log_must dd if=/dev/urandom of=$SRC_FILE bs=$BS count=$CNT
83 fs=$TESTPOOL/$TESTFS/fs.$$
84 fsclone=$TESTPOOL/$TESTFS/fsclone.$$
85 log_must zfs create $fs
88 log_must cp $SRC_FILE $obj
91 log_must zfs snapshot $snap
92 log_must zfs clone $snap $fsclone
94 # Rename dataset & clone
96 log_must zfs rename $fs ${fs}-new
97 log_must zfs rename $fsclone ${fsclone}-new
99 # Compare source file and target file
101 obj=$(target_obj ${fs}-new)
102 log_must diff $SRC_FILE $obj
103 obj=$(target_obj ${fsclone}-new)
104 log_must diff $SRC_FILE $obj
106 # Rename snapshot and re-clone dataset
108 log_must zfs rename ${fs}-new $fs
109 log_must zfs rename $snap ${snap}-new
110 log_must zfs clone ${snap}-new $fsclone
112 # Compare source file and target file
114 obj=$(target_obj $fsclone)
115 log_must diff $SRC_FILE $obj
117 if is_global_zone; then
118 vol=$TESTPOOL/$TESTFS/vol.$$ ; volclone=$TESTPOOL/$TESTFS/volclone.$$
119 log_must zfs create -V 100M $vol
122 obj=$(target_obj $vol)
123 log_must dd if=$SRC_FILE of=$obj bs=$BS count=$CNT
126 log_must zfs snapshot $snap
127 log_must zfs clone $snap $volclone
130 # Rename dataset & clone
131 log_must zfs rename $vol ${vol}-new
132 log_must zfs rename $volclone ${volclone}-new
135 # Compare source file and target file
136 obj=$(target_obj ${vol}-new)
137 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
138 log_must diff $SRC_FILE $DST_FILE
139 obj=$(target_obj ${volclone}-new)
140 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
141 log_must diff $SRC_FILE $DST_FILE
143 # Rename snapshot and re-clone dataset
144 log_must zfs rename ${vol}-new $vol
145 log_must zfs rename $snap ${snap}-new
146 log_must zfs clone ${snap}-new $volclone
149 # Compare source file and target file
150 obj=$(target_obj $volclone)
151 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
152 log_must diff $SRC_FILE $DST_FILE
155 log_pass "Rename dataset, the data haven't changed passed."