1# vim: filetype=sh 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# ident "@(#)zfs_rename.kshlib 1.5 07/10/09 SMI" 28# 29 30function additional_setup 31{ 32 # Create testfile 33 log_must $CP $DATA $TESTDIR/$TESTFILE0 34 log_must $CP $DATA $TESTDIR1/$TESTFILE0 35 36 # Create snapshot 37 if ! snapexists $TESTPOOL/$TESTFS@snapshot; then 38 log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot 39 log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot \ 40 $TESTPOOL/$TESTFS-clone 41 fi 42 43 # Create file system 44 datasetexists $TESTPOOL/$TESTFS1 || \ 45 log_must $ZFS create $TESTPOOL/$TESTFS1 46 47 # Create testfile 48 log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTFS1)/$TESTFILE0 49 50 # Create container 51 datasetexists $TESTPOOL/$TESTCTR1 || \ 52 log_must $ZFS create $TESTPOOL/$TESTCTR1 53 log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTCTR1)/$TESTFILE0 54 55 # Create data in zvol 56 if is_global_zone; then 57 log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT \ 58 >/dev/null 2>&1" 59 else 60 log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTVOL)/$TESTFILE0 61 fi 62 63} 64 65function rename_dataset # src dest 66{ 67 typeset src=$1 68 typeset dest=$2 69 70 log_must $ZFS rename $src $dest 71 72 # 73 # Verify src name no longer in use 74 # 75 log_mustnot datasetexists $src 76 log_must datasetexists $dest 77} 78 79function cleanup 80{ 81 typeset -i i=0 82 while ((i < ${#dataset[*]} )); do 83 if ! datasetexists ${dataset[i]}-new ; then 84 ((i = i + 1)) 85 continue 86 fi 87 88 if [[ ${dataset[i]}-new != *@* ]] ; then 89 $ZFS rename ${dataset[i]}-new ${dataset[i]} 90 if [[ $? -ne 0 ]]; then 91 typeset newfs=${dataset[i]}-new 92 typeset oldfs=${dataset[i]} 93 typeset mntp=$(get_prop mountpoint $newfs) 94 log_must $ZFS destroy -f $newfs 95 log_must $ZFS create -p $oldfs 96 log_must $ZFS set mountpoint=$mntp $oldfs 97 fi 98 else 99 log_must $ZFS destroy -fR ${dataset[i]}-new 100 fi 101 102 ((i = i + 1)) 103 done 104} 105 106function cmp_data #<$1 src data, $2 tgt data> 107{ 108 typeset src=$1 109 typeset tgt=$2 110 111 $CMP $src $tgt >/dev/null 2>&1 112 113 return $? 114} 115 116