]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename_001_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) 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 #       'zfs rename' should successfully rename valid datasets.
38 #       As a sub-assertion we check to ensure the datasets that can
39 #       be mounted are mounted.
40 #
41 # STRATEGY:
42 #       1. Given a file system, snapshot and volume.
43 #       2. Rename each dataset object to a new name.
44 #       3. Verify that only the new name is displayed by zfs list.
45 #       4. Verify mountable datasets are mounted.
46 #
47 ###############################################################################
48
49 verify_runnable "both"
50
51 set -A dataset "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS1" \
52    "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
53     "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS-clone"
54 set -A mountable "$TESTPOOL/$TESTFS1-new" "$TESTPOOL/$TESTFS@snapshot-new" \
55     "$TESTPOOL/$TESTCTR/$TESTFS1-new" "$TESTPOOL/$TESTFS-clone-new"
56
57 #
58 # cleanup defined in zfs_rename.kshlib
59 #
60 log_onexit cleanup
61
62 log_assert "'zfs rename' should successfully rename valid datasets"
63
64 additional_setup
65
66 typeset -i i=0
67 while (( i < ${#dataset[*]} )); do
68         rename_dataset ${dataset[i]} ${dataset[i]}-new
69
70         ((i = i + 1))
71 done
72
73 log_note "Verify mountable datasets are mounted in their new namespace."
74 typeset mtpt
75 i=0
76 while (( i < ${#mountable[*]} )); do
77         # Snapshot have no mountpoint
78         if [[ ${mountable[i]} != *@* ]]; then
79                 log_must mounted ${mountable[i]}
80                 mtpt=$(get_prop mountpoint ${mountable[i]})
81         else
82                 mtpt=$(snapshot_mountpoint ${mountable[i]})
83         fi
84
85         if ! cmp_data $DATA $mtpt/$TESTFILE0 ; then
86                 log_fail "$mtpt/$TESTFILE0 gets corrupted after rename operation."
87         fi
88
89         ((i = i + 1))
90 done
91
92 #verify the data integrity in zvol
93 if is_global_zone; then
94         log_must eval "dd if=${VOL_R_PATH}-new of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
95         if ! cmp_data $VOLDATA $DATA ; then
96                 log_fail "$VOLDATA gets corrupted after rename operation."
97         fi
98 fi
99
100 # rename back fs
101 typeset -i i=0
102 while ((i < ${#dataset[*]} )); do
103         if datasetexists ${dataset[i]}-new ; then
104                 log_must zfs rename ${dataset[i]}-new ${dataset[i]}
105         fi
106         ((i = i + 1))
107 done
108
109 log_pass "'zfs rename' successfully renamed each dataset type."