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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_rename_005_neg.ksh	1.3	09/06/22 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_005_neg
37#
38# DESCRIPTION:
39#       'zfs rename' should fail when the dataset are not within the same pool
40#
41# STRATEGY:
42#       1. Given a file system, snapshot and volume.
43#       2. Rename each dataset object to a different pool.
44#       3. Verify the operation fails, and only the original name
45#	   is displayed by zfs list.
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2005-09-13)
52#
53# __stc_assertion_end
54#
55###############################################################################
56
57verify_runnable "global"
58
59function my_cleanup
60{
61	poolexists $TESTPOOL1 && \
62		destroy_pool $TESTPOOL1
63	[[ -e $TESTDIR/$TESTFILE1 ]] && \
64		log_must $RM -f $TESTDIR/$TESTFILE1
65	cleanup
66}
67
68set -A src_dataset \
69    "$TESTPOOL/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
70    "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL" \
71    "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS-clone"
72
73#
74# cleanup defined in zfs_rename.kshlib
75#
76log_onexit my_cleanup
77
78log_assert "'zfs rename' should fail while datasets are within different pool."
79
80additional_setup
81
82typeset FILESIZE=64m
83log_must $TRUNCATE -s $FILESIZE $TESTDIR/$TESTFILE1
84create_pool $TESTPOOL1 $TESTDIR/$TESTFILE1
85
86for src in ${src_dataset[@]} ; do
87	dest=${src#$TESTPOOL/}
88	if [[ $dest == *"@"* ]]; then
89		dest=${dest#*@}
90		dest=${TESTPOOL1}@$dest
91	else
92		dest=${TESTPOOL1}/$dest
93	fi
94	log_mustnot $ZFS rename $src $dest
95	log_mustnot $ZFS rename -p $src $dest
96
97	#
98	# Verify original dataset name still in use
99	#
100	log_must datasetexists $src
101done
102
103log_pass "'zfs rename' fail while datasets are within different pool."
104