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