]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh
ZFS: MFV 2.0-rc1-gfd20a8
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename_004_neg.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 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.
40 #
41 # STRATEGY:
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.
45 #
46
47 verify_runnable "both"
48
49 #
50 # This array is a list of pairs:
51 #       item i: original type
52 #       item i + 1: new type
53 #
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.$$
82
83 #
84 # cleanup defined in zfs_rename.kshlib
85 #
86 log_onexit cleanup
87
88 log_assert "'zfs rename' should fail when datasets are of a different type."
89
90 additional_setup
91
92 typeset -i i=0
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]}
96
97         log_mustnot zfs rename -p ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
98         log_must datasetexists ${bad_dataset[i]}
99
100         ((i = i + 2))
101 done
102
103 #verify 'rename -p' can not work with snapshots
104
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
111
112 log_pass "'zfs rename' fails as expected when given different dataset types."