1#!/bin/ksh -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 28# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib 34 35# 36# DESCRIPTION: 37# Rename dataset, verify that the data haven't changed. 38# 39# STRATEGY: 40# 1. Create random data and copy to dataset. 41# 2. Perform renaming commands. 42# 3. Verify that the data haven't changed. 43# 44 45verify_runnable "both" 46 47function cleanup 48{ 49 if datasetexists $TESTPOOL/$TESTFS ; then 50 log_must zfs destroy -Rf $TESTPOOL/$TESTFS 51 fi 52 log_must zfs create $TESTPOOL/$TESTFS 53 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 54 55 rm -f $SRC_FILE $DST_FILE 56} 57 58function target_obj 59{ 60 typeset dtst=$1 61 62 typeset obj 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=/dev/zvol/dsk/$dtst 68 fi 69 70 echo $obj 71} 72 73log_assert "Rename dataset, verify that the data haven't changed." 74log_onexit cleanup 75 76# Generate random data 77# 78BS=512 ; CNT=2048 79SRC_FILE=/tmp/srcfile.$$ 80DST_FILE=/tmp/dstfile.$$ 81log_must dd if=/dev/random of=$SRC_FILE bs=$BS count=$CNT 82 83fs=$TESTPOOL/$TESTFS/fs.$$ 84fsclone=$TESTPOOL/$TESTFS/fsclone.$$ 85log_must zfs create $fs 86 87obj=$(target_obj $fs) 88log_must cp $SRC_FILE $obj 89 90snap=${fs}@snap.$$ 91log_must zfs snapshot $snap 92log_must zfs clone $snap $fsclone 93 94# Rename dataset & clone 95# 96log_must zfs rename $fs ${fs}-new 97log_must zfs rename $fsclone ${fsclone}-new 98 99# Compare source file and target file 100# 101obj=$(target_obj ${fs}-new) 102log_must diff $SRC_FILE $obj 103obj=$(target_obj ${fsclone}-new) 104log_must diff $SRC_FILE $obj 105 106# Rename snapshot and re-clone dataset 107# 108log_must zfs rename ${fs}-new $fs 109log_must zfs rename $snap ${snap}-new 110log_must zfs clone ${snap}-new $fsclone 111 112# Compare source file and target file 113# 114obj=$(target_obj $fsclone) 115log_must diff $SRC_FILE $obj 116 117if is_global_zone; then 118 vol=$TESTPOOL/$TESTFS/vol.$$ ; volclone=$TESTPOOL/$TESTFS/volclone.$$ 119 log_must zfs create -V 100M $vol 120 121 obj=$(target_obj $vol) 122 log_must dd if=$SRC_FILE of=$obj bs=$BS count=$CNT 123 124 snap=${vol}@snap.$$ 125 log_must zfs snapshot $snap 126 log_must zfs clone $snap $volclone 127 128 # Rename dataset & clone 129 log_must zfs rename $vol ${vol}-new 130 log_must zfs rename $volclone ${volclone}-new 131 132 # Compare source file and target file 133 obj=$(target_obj ${vol}-new) 134 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT 135 log_must diff $SRC_FILE $DST_FILE 136 obj=$(target_obj ${volclone}-new) 137 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT 138 log_must diff $SRC_FILE $DST_FILE 139 140 # Rename snapshot and re-clone dataset 141 log_must zfs rename ${vol}-new $vol 142 log_must zfs rename $snap ${snap}-new 143 log_must zfs clone ${snap}-new $volclone 144 145 # Compare source file and target file 146 obj=$(target_obj $volclone) 147 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT 148 log_must diff $SRC_FILE $DST_FILE 149fi 150 151log_pass "Rename dataset, the data haven't changed passed." 152