]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename_007_pos.ksh
1 #!/bin/ksh -p
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
28 #
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
34
35 #
36 # DESCRIPTION:
37 #       Rename dataset, verify that the data haven't changed.
38 #
39 # STRATEGY:
40 #       1. Create random data and copy to dataset.
41 #       2. Perform renaming commands.
42 #       3. Verify that the data haven't changed.
43 #
44
45 verify_runnable "both"
46
47 function cleanup
48 {
49         if datasetexists $TESTPOOL/$TESTFS ; then
50                 log_must zfs destroy -Rf $TESTPOOL/$TESTFS
51         fi
52         log_must zfs create $TESTPOOL/$TESTFS
53         log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
54
55         rm -f $SRC_FILE $DST_FILE
56 }
57
58 function target_obj
59 {
60         typeset dtst=$1
61
62         typeset obj
63         typeset type=$(get_prop type $dtst)
64         if [[ $type == "filesystem" ]]; then
65                 obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/}
66         elif [[ $type == "volume" ]]; then
67                 obj=$ZVOL_DEVDIR/$dtst
68         fi
69
70         echo $obj
71 }
72
73 log_assert "Rename dataset, verify that the data haven't changed."
74 log_onexit cleanup
75
76 # Generate random data
77 #
78 BS=512 ; CNT=2048
79 SRC_FILE=$TESTDIR/srcfile.$$
80 DST_FILE=$TESTDIR/dstfile.$$
81 log_must dd if=/dev/urandom of=$SRC_FILE bs=$BS count=$CNT
82
83 fs=$TESTPOOL/$TESTFS/fs.$$
84 fsclone=$TESTPOOL/$TESTFS/fsclone.$$
85 log_must zfs create $fs
86
87 obj=$(target_obj $fs)
88 log_must cp $SRC_FILE $obj
89
90 snap=${fs}@snap.$$
91 log_must zfs snapshot $snap
92 log_must zfs clone $snap $fsclone
93
94 # Rename dataset & clone
95 #
96 log_must zfs rename $fs ${fs}-new
97 log_must zfs rename $fsclone ${fsclone}-new
98
99 # Compare source file and target file
100 #
101 obj=$(target_obj ${fs}-new)
102 log_must diff $SRC_FILE $obj
103 obj=$(target_obj ${fsclone}-new)
104 log_must diff $SRC_FILE $obj
105
106 # Rename snapshot and re-clone dataset
107 #
108 log_must zfs rename ${fs}-new $fs
109 log_must zfs rename $snap ${snap}-new
110 log_must zfs clone ${snap}-new $fsclone
111
112 # Compare source file and target file
113 #
114 obj=$(target_obj $fsclone)
115 log_must diff $SRC_FILE $obj
116
117 if is_global_zone; then
118         vol=$TESTPOOL/$TESTFS/vol.$$ ;  volclone=$TESTPOOL/$TESTFS/volclone.$$
119         log_must zfs create -V 100M $vol
120         block_device_wait
121
122         obj=$(target_obj $vol)
123         log_must dd if=$SRC_FILE of=$obj bs=$BS count=$CNT
124
125         snap=${vol}@snap.$$
126         log_must zfs snapshot $snap
127         log_must zfs clone $snap $volclone
128         block_device_wait
129
130         # Rename dataset & clone
131         log_must zfs rename $vol ${vol}-new
132         log_must zfs rename $volclone ${volclone}-new
133         block_device_wait
134
135         # Compare source file and target file
136         obj=$(target_obj ${vol}-new)
137         log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
138         log_must diff $SRC_FILE $DST_FILE
139         obj=$(target_obj ${volclone}-new)
140         log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
141         log_must diff $SRC_FILE $DST_FILE
142
143         # Rename snapshot and re-clone dataset
144         log_must zfs rename ${vol}-new $vol
145         log_must zfs rename $snap ${snap}-new
146         log_must zfs clone ${snap}-new $volclone
147         block_device_wait
148
149         # Compare source file and target file
150         obj=$(target_obj $volclone)
151         log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
152         log_must diff $SRC_FILE $DST_FILE
153 fi
154
155 log_pass "Rename dataset, the data haven't changed passed."