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.
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.
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]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
37 # 'zfs rename' should fail when this dataset was changed to an existed
38 # dataset name or datasets are of different types.
39 # For example, a filesystem cannot be renamed as a volume.
42 # 1. Given a file system, snapshot and volume.
43 # 2. Rename each dataset object to a different type.
44 # 3. Verify that only the original name is displayed by zfs list.
47 verify_runnable "both"
50 # This array is a list of pairs:
51 # item i: original type
52 # item i + 1: new type
54 set -A bad_dataset $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR1 \
55 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR/$TESTFS1 \
56 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
57 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS1 \
58 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \
59 $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTVOL \
60 $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS@snapshot \
61 $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS1 \
62 $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTCTR/$TESTFS1 \
63 $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTVOL \
64 $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \
65 $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS1 \
66 $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTCTR1 \
67 $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR1 \
68 $TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS@snapshot \
69 $TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS1 \
70 $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR/$TESTFS1 \
71 $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR1 \
72 $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTVOL \
73 $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS1 \
74 $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR/$TESTFS1 \
75 $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%c \
76 $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%d \
77 $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%x \
78 $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%p \
79 $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%s \
80 $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS@snapshot/fs \
81 $TESTPOOL/$RECVFS/%recv $TESTPOOL/renamed.$$
84 # cleanup defined in zfs_rename.kshlib
88 log_assert "'zfs rename' should fail when datasets are of a different type."
93 while ((i < ${#bad_dataset[*]} )); do
94 log_mustnot zfs rename ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
95 log_must datasetexists ${bad_dataset[i]}
97 log_mustnot zfs rename -p ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
98 log_must datasetexists ${bad_dataset[i]}
103 #verify 'rename -p' can not work with snapshots
105 log_mustnot zfs rename -p $TESTPOOL/$TESTFS@snapshot \
106 $TESTPOOL/$TESTFS@snapshot2
107 log_must datasetexists $TESTPOOL/$TESTFS@snapshot
108 log_mustnot zfs rename -p $TESTPOOL/$TESTFS@snapshot \
109 $TESTPOOL/$TESTFS/$TESTFS@snapshot2
110 log_must datasetexists $TESTPOOL/$TESTFS@snapshot
112 log_pass "'zfs rename' fails as expected when given different dataset types."