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_007_pos 34# 35# DESCRIPTION: 36# Rename dataset, verify that the data haven't changed. 37# 38# STRATEGY: 39# 1. Create random data and copy to dataset. 40# 2. Perform renaming commands. 41# 3. Verify that the data haven't changed. 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 if datasetexists $TESTPOOL/$TESTFS ; then 64 log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS 65 fi 66 log_must $ZFS create $TESTPOOL/$TESTFS 67 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 68 69 $RM -f $SRC_FILE $DST_FILE 70} 71 72function target_obj 73{ 74 typeset dtst=$1 75 76 typeset obj 77 typeset type=$(get_prop type $dtst) 78 if [[ $type == "filesystem" ]]; then 79 obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/} 80 elif [[ $type == "volume" ]]; then 81 obj=/dev/zvol/$dtst 82 fi 83 84 print $obj 85} 86 87log_assert "Rename dataset, verify that the data haven't changed." 88log_onexit cleanup 89 90# Generate random data 91# 92BS=512 ; CNT=2048 93SRC_FILE=$TMPDIR/srcfile.${TESTCASE_ID} 94DST_FILE=$TMPDIR/dstfile.${TESTCASE_ID} 95log_must $DD if=/dev/random of=$SRC_FILE bs=$BS count=$CNT 96 97fs=$TESTPOOL/$TESTFS/fs.${TESTCASE_ID} 98fsclone=$TESTPOOL/$TESTFS/fsclone.${TESTCASE_ID} 99log_must $ZFS create $fs 100 101obj=$(target_obj $fs) 102log_must $CP $SRC_FILE $obj 103 104snap=${fs}@snap.${TESTCASE_ID} 105log_must $ZFS snapshot $snap 106log_must $ZFS clone $snap $fsclone 107 108# Rename dataset & clone 109# 110log_must $ZFS rename $fs ${fs}-new 111log_must $ZFS rename $fsclone ${fsclone}-new 112 113# Compare source file and target file 114# 115obj=$(target_obj ${fs}-new) 116log_must $DIFF $SRC_FILE $obj 117obj=$(target_obj ${fsclone}-new) 118log_must $DIFF $SRC_FILE $obj 119 120# Rename snapshot and re-clone dataset 121# 122log_must $ZFS rename ${fs}-new $fs 123log_must $ZFS rename $snap ${snap}-new 124log_must $ZFS clone ${snap}-new $fsclone 125 126# Compare source file and target file 127# 128obj=$(target_obj $fsclone) 129log_must $DIFF $SRC_FILE $obj 130 131if is_global_zone; then 132 vol=$TESTPOOL/$TESTFS/vol.${TESTCASE_ID} ; volclone=$TESTPOOL/$TESTFS/volclone.${TESTCASE_ID} 133 log_must $ZFS create -V 100M $vol 134 135 obj=$(target_obj $vol) 136 log_must $DD if=$SRC_FILE of=$obj bs=$BS count=$CNT 137 138 snap=${vol}@snap.${TESTCASE_ID} 139 log_must $ZFS snapshot $snap 140 log_must $ZFS clone $snap $volclone 141 142 # Rename dataset & clone 143 log_must $ZFS rename $vol ${vol}-new 144 log_must $ZFS rename $volclone ${volclone}-new 145 146 # Compare source file and target file 147 obj=$(target_obj ${vol}-new) 148 log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT 149 log_must $DIFF $SRC_FILE $DST_FILE 150 obj=$(target_obj ${volclone}-new) 151 log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT 152 log_must $DIFF $SRC_FILE $DST_FILE 153 154 # Rename snapshot and re-clone dataset 155 log_must $ZFS rename ${vol}-new $vol 156 log_must $ZFS rename $snap ${snap}-new 157 log_must $ZFS clone ${snap}-new $volclone 158 159 # Compare source file and target file 160 obj=$(target_obj $volclone) 161 log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT 162 log_must $DIFF $SRC_FILE $DST_FILE 163fi 164 165log_pass "Rename dataset, the data haven't changed passed." 166