]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename.kshlib
1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
25 #
26
27 #
28 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29 #
30
31 . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.cfg
32
33 function additional_setup
34 {
35         # Create testfile
36         log_must cp $DATA $TESTDIR/$TESTFILE0
37         log_must cp $DATA $TESTDIR1/$TESTFILE0
38
39         # Create snapshot
40         if ! snapexists $TESTPOOL/$TESTFS@snapshot; then
41                 log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot
42                 log_must zfs clone $TESTPOOL/$TESTFS@snapshot \
43                     $TESTPOOL/$TESTFS-clone
44         fi
45
46         # Create file system
47         datasetexists $TESTPOOL/$TESTFS1 || \
48                 log_must zfs create $TESTPOOL/$TESTFS1
49
50         # Create testfile
51         log_must cp $DATA $(get_prop mountpoint $TESTPOOL/$TESTFS1)/$TESTFILE0
52
53         # Create container
54         datasetexists $TESTPOOL/$TESTCTR1 || \
55                 log_must zfs create $TESTPOOL/$TESTCTR1
56         log_must cp $DATA $(get_prop mountpoint $TESTPOOL/$TESTCTR1)/$TESTFILE0
57
58         # Create data in zvol
59         if is_global_zone; then
60                 log_must eval "dd if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT \
61                                 >/dev/null 2>&1"
62         else
63                 log_must cp $DATA $(get_prop mountpoint $TESTPOOL/$TESTVOL)/$TESTFILE0
64         fi
65
66         # Create temporary %recv clone
67         create_recv_clone $TESTPOOL/$RECVFS
68 }
69
70 function rename_dataset # src dest
71 {
72         typeset src=$1
73         typeset dest=$2
74
75         log_must zfs rename $src $dest
76         block_device_wait
77
78         #
79         # Verify src name no longer in use
80         #
81         log_mustnot datasetexists $src
82         log_must datasetexists $dest
83 }
84
85 function cleanup
86 {
87         typeset -i i=0
88         while ((i < ${#dataset[*]} )); do
89                 if ! datasetexists ${dataset[i]}-new ; then
90                         ((i = i + 1))
91                         continue
92                 fi
93
94                 if [[ ${dataset[i]}-new != *@* ]] ; then
95                         zfs rename ${dataset[i]}-new ${dataset[i]}
96                         if [[ $? -ne 0 ]]; then
97                                 typeset newfs=${dataset[i]}-new
98                                 typeset oldfs=${dataset[i]}
99                                 typeset mntp=$(get_prop mountpoint  $newfs)
100                                 log_must zfs destroy -f $newfs
101                                 log_must zfs create -p $oldfs
102                                 log_must zfs set mountpoint=$mntp $oldfs
103                         fi
104                 else
105                         log_must zfs destroy -fR ${dataset[i]}-new
106                 fi
107
108                 ((i = i + 1))
109         done
110
111         if snapexists $TESTPOOL/$TESTFS@snapshot; then
112                 log_must zfs destroy -fR $TESTPOOL/$TESTFS@snapshot
113         fi
114
115         if datasetexists $TESTPOOL/$RECVFS; then
116                 log_must zfs destroy -r $TESTPOOL/$RECVFS
117         fi
118 }
119
120 function cmp_data #<$1 src data, $2 tgt data>
121 {
122         typeset src=$1
123         typeset tgt=$2
124
125         cmp $src $tgt >/dev/null 2>&1
126
127         return $?
128 }
129