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