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 https://opensource.org/licenses/CDDL-1.0. 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 datasetexists $TESTPOOL/$TESTFS && \ 50 destroy_dataset $TESTPOOL/$TESTFS -Rf 51 log_must zfs create $TESTPOOL/$TESTFS 52 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 53 54 rm -f $SRC_FILE $DST_FILE 55} 56 57function target_obj 58{ 59 typeset dtst=$1 60 61 typeset obj 62 typeset type=$(get_prop type $dtst) 63 if [[ $type == "filesystem" ]]; then 64 obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/} 65 elif [[ $type == "volume" ]]; then 66 obj=$ZVOL_DEVDIR/$dtst 67 fi 68 69 echo $obj 70} 71 72log_assert "Rename dataset, verify that the data haven't changed." 73log_onexit cleanup 74 75# Generate random data 76# 77BS=512 ; CNT=2048 78SRC_FILE=$TESTDIR/srcfile.$$ 79DST_FILE=$TESTDIR/dstfile.$$ 80log_must dd if=/dev/urandom of=$SRC_FILE bs=$BS count=$CNT 81 82fs=$TESTPOOL/$TESTFS/fs.$$ 83fsclone=$TESTPOOL/$TESTFS/fsclone.$$ 84log_must zfs create $fs 85 86obj=$(target_obj $fs) 87log_must cp $SRC_FILE $obj 88 89snap=${fs}@snap.$$ 90log_must zfs snapshot $snap 91log_must zfs clone $snap $fsclone 92 93# Rename dataset & clone 94# 95log_must zfs rename $fs ${fs}-new 96log_must zfs rename $fsclone ${fsclone}-new 97 98# Compare source file and target file 99# 100obj=$(target_obj ${fs}-new) 101log_must diff $SRC_FILE $obj 102obj=$(target_obj ${fsclone}-new) 103log_must diff $SRC_FILE $obj 104 105# Rename snapshot and re-clone dataset 106# 107log_must zfs rename ${fs}-new $fs 108log_must zfs rename $snap ${snap}-new 109log_must zfs clone ${snap}-new $fsclone 110 111# Compare source file and target file 112# 113obj=$(target_obj $fsclone) 114log_must diff $SRC_FILE $obj 115 116if is_global_zone; then 117 vol=$TESTPOOL/$TESTFS/vol.$$ ; volclone=$TESTPOOL/$TESTFS/volclone.$$ 118 log_must zfs create -V 100M $vol 119 120 obj=$(target_obj $vol) 121 block_device_wait $obj 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 block_device_wait $obj 135 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT 136 log_must diff $SRC_FILE $DST_FILE 137 obj=$(target_obj ${volclone}-new) 138 block_device_wait $obj 139 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT 140 log_must diff $SRC_FILE $DST_FILE 141 142 # Rename snapshot and re-clone dataset 143 log_must zfs rename ${vol}-new $vol 144 log_must zfs rename $snap ${snap}-new 145 log_must zfs clone ${snap}-new $volclone 146 147 # Compare source file and target file 148 obj=$(target_obj $volclone) 149 block_device_wait $obj 150 log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT 151 log_must diff $SRC_FILE $DST_FILE 152fi 153 154log_pass "Rename dataset, the data haven't changed passed." 155