12fae26bdSAlan Somers# vim: filetype=sh 22fae26bdSAlan Somers# 32fae26bdSAlan Somers# CDDL HEADER START 42fae26bdSAlan Somers# 52fae26bdSAlan Somers# The contents of this file are subject to the terms of the 62fae26bdSAlan Somers# Common Development and Distribution License (the "License"). 72fae26bdSAlan Somers# You may not use this file except in compliance with the License. 82fae26bdSAlan Somers# 92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing. 112fae26bdSAlan Somers# See the License for the specific language governing permissions 122fae26bdSAlan Somers# and limitations under the License. 132fae26bdSAlan Somers# 142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each 152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the 172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying 182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner] 192fae26bdSAlan Somers# 202fae26bdSAlan Somers# CDDL HEADER END 212fae26bdSAlan Somers# 222fae26bdSAlan Somers 232fae26bdSAlan Somers# 242fae26bdSAlan Somers# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 252fae26bdSAlan Somers# Use is subject to license terms. 262fae26bdSAlan Somers 272fae26bdSAlan Somersfunction additional_setup 282fae26bdSAlan Somers{ 292fae26bdSAlan Somers # Create testfile 302fae26bdSAlan Somers log_must $CP $DATA $TESTDIR/$TESTFILE0 312fae26bdSAlan Somers log_must $CP $DATA $TESTDIR1/$TESTFILE0 322fae26bdSAlan Somers 332fae26bdSAlan Somers # Create snapshot 342fae26bdSAlan Somers if ! snapexists $TESTPOOL/$TESTFS@snapshot; then 352fae26bdSAlan Somers log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot 362fae26bdSAlan Somers log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot \ 372fae26bdSAlan Somers $TESTPOOL/$TESTFS-clone 382fae26bdSAlan Somers fi 392fae26bdSAlan Somers 402fae26bdSAlan Somers # Create file system 412fae26bdSAlan Somers datasetexists $TESTPOOL/$TESTFS1 || \ 422fae26bdSAlan Somers log_must $ZFS create $TESTPOOL/$TESTFS1 432fae26bdSAlan Somers 442fae26bdSAlan Somers # Create testfile 452fae26bdSAlan Somers log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTFS1)/$TESTFILE0 462fae26bdSAlan Somers 472fae26bdSAlan Somers # Create container 482fae26bdSAlan Somers datasetexists $TESTPOOL/$TESTCTR1 || \ 492fae26bdSAlan Somers log_must $ZFS create $TESTPOOL/$TESTCTR1 502fae26bdSAlan Somers log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTCTR1)/$TESTFILE0 512fae26bdSAlan Somers 522fae26bdSAlan Somers # Create data in zvol 532fae26bdSAlan Somers if is_global_zone; then 542fae26bdSAlan Somers log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT \ 552fae26bdSAlan Somers >/dev/null 2>&1" 562fae26bdSAlan Somers else 572fae26bdSAlan Somers log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTVOL)/$TESTFILE0 582fae26bdSAlan Somers fi 592fae26bdSAlan Somers 602fae26bdSAlan Somers} 612fae26bdSAlan Somers 622fae26bdSAlan Somersfunction rename_dataset # src dest 632fae26bdSAlan Somers{ 642fae26bdSAlan Somers typeset src=$1 652fae26bdSAlan Somers typeset dest=$2 662fae26bdSAlan Somers 672fae26bdSAlan Somers log_must $ZFS rename $src $dest 682fae26bdSAlan Somers 692fae26bdSAlan Somers # 702fae26bdSAlan Somers # Verify src name no longer in use 712fae26bdSAlan Somers # 722fae26bdSAlan Somers log_mustnot datasetexists $src 732fae26bdSAlan Somers log_must datasetexists $dest 742fae26bdSAlan Somers} 752fae26bdSAlan Somers 762fae26bdSAlan Somersfunction cleanup 772fae26bdSAlan Somers{ 782fae26bdSAlan Somers typeset -i i=0 792fae26bdSAlan Somers while ((i < ${#dataset[*]} )); do 802fae26bdSAlan Somers if ! datasetexists ${dataset[i]}-new ; then 812fae26bdSAlan Somers ((i = i + 1)) 822fae26bdSAlan Somers continue 832fae26bdSAlan Somers fi 842fae26bdSAlan Somers 852fae26bdSAlan Somers if [[ ${dataset[i]}-new != *@* ]] ; then 862fae26bdSAlan Somers $ZFS rename ${dataset[i]}-new ${dataset[i]} 872fae26bdSAlan Somers if [[ $? -ne 0 ]]; then 882fae26bdSAlan Somers typeset newfs=${dataset[i]}-new 892fae26bdSAlan Somers typeset oldfs=${dataset[i]} 902fae26bdSAlan Somers typeset mntp=$(get_prop mountpoint $newfs) 912fae26bdSAlan Somers log_must $ZFS destroy -f $newfs 922fae26bdSAlan Somers log_must $ZFS create -p $oldfs 932fae26bdSAlan Somers log_must $ZFS set mountpoint=$mntp $oldfs 942fae26bdSAlan Somers fi 952fae26bdSAlan Somers else 962fae26bdSAlan Somers log_must $ZFS destroy -fR ${dataset[i]}-new 972fae26bdSAlan Somers fi 982fae26bdSAlan Somers 992fae26bdSAlan Somers ((i = i + 1)) 1002fae26bdSAlan Somers done 1012fae26bdSAlan Somers} 1022fae26bdSAlan Somers 1032fae26bdSAlan Somersfunction cmp_data #<$1 src data, $2 tgt data> 1042fae26bdSAlan Somers{ 1052fae26bdSAlan Somers typeset src=$1 1062fae26bdSAlan Somers typeset tgt=$2 1072fae26bdSAlan Somers 1082fae26bdSAlan Somers $CMP $src $tgt >/dev/null 2>&1 1092fae26bdSAlan Somers 1102fae26bdSAlan Somers return $? 1112fae26bdSAlan Somers} 1122fae26bdSAlan Somers 113