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