1#!/usr/local/bin/ksh93 -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# ident	"@(#)zfs_rename_004_neg.ksh	1.4	07/07/31 SMI"
28#
29. $STF_SUITE/include/libtest.kshlib
30. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib
31
32################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfs_rename_004_neg
37#
38# DESCRIPTION:
39#       'zfs rename' should fail when this dataset was changed to an existed
40#	dataset name or datasets are of different types.
41#       For example, a filesystem cannot be renamed as a volume.
42#
43# STRATEGY:
44#       1. Given a file system, snapshot and volume.
45#       2. Rename each dataset object to a different type.
46#       3. Verify that only the original name is displayed by zfs list.
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2005-06-29)
53#
54# __stc_assertion_end
55#
56###############################################################################
57
58verify_runnable "both"
59
60#
61# This array is a list of pairs:
62# 	item i: original type
63# 	item i + 1: new type
64#
65set -A bad_dataset $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR1 \
66	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR/$TESTFS1 \
67	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
68	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS1 \
69	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \
70	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTVOL \
71	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS@snapshot \
72	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS1 \
73	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTCTR/$TESTFS1 \
74	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTVOL \
75	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTFS@snapshot \
76	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTFS1 \
77	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTCTR1 \
78	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR1 \
79	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS@snapshot \
80	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS1 \
81	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR/$TESTFS1 \
82	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR1 \
83	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTVOL \
84	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS1 \
85	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR/$TESTFS1 \
86	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%c \
87	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%d \
88	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%x \
89	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%p \
90	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%s \
91	$TESTPOOL/$TESTFS@snapshot \
92	$TESTPOOL/$TESTFS@snapshot/fs
93
94#
95# cleanup defined in zfs_rename.kshlib
96#
97log_onexit cleanup
98
99log_assert "'zfs rename' should fail when datasets are of a different type."
100
101additional_setup
102
103typeset -i i=0
104while ((i < ${#bad_dataset[*]} )); do
105        log_mustnot $ZFS rename ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
106        log_must datasetexists ${bad_dataset[i]}
107
108        log_mustnot $ZFS rename -p ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
109        log_must datasetexists ${bad_dataset[i]}
110
111	((i = i + 2))
112done
113
114#verify 'rename -p' can not work with snapshots
115
116log_mustnot $ZFS rename -p $TESTPOOL/$TESTFS@snapshot \
117		$TESTPOOL/$TESTFS@snapshot2
118log_must datasetexists $TESTPOOL/$TESTFS@snapshot
119log_mustnot $ZFS rename -p $TESTPOOL/$TESTFS@snapshot \
120		$TESTPOOL/$TESTFS/$TESTFS@snapshot2
121log_must datasetexists $TESTPOOL/$TESTFS@snapshot
122
123log_pass "'zfs rename' fails as expected when given different dataset types."
124