xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27. $STF_SUITE/include/libtest.shlib
28. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
29
30#
31# DESCRIPTION:
32#       'zfs rename' should fail when the dataset are not within the same pool
33#
34# STRATEGY:
35#       1. Given a file system, snapshot and volume.
36#       2. Rename each dataset object to a different pool.
37#       3. Verify the operation fails, and only the original name
38#	   is displayed by zfs list.
39#
40
41verify_runnable "global"
42
43function my_cleanup
44{
45	poolexists $TESTPOOL1 && \
46		destroy_pool $TESTPOOL1
47	[[ -e $TESTDIR/$TESTFILE1 ]] && \
48		log_must $RM -f $TESTDIR/$TESTFILE1
49	cleanup
50}
51
52set -A src_dataset \
53    "$TESTPOOL/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
54    "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL" \
55    "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS-clone"
56
57#
58# cleanup defined in zfs_rename.kshlib
59#
60log_onexit my_cleanup
61
62log_assert "'zfs rename' should fail while datasets are within different pool."
63
64additional_setup
65
66typeset FILESIZE=64m
67log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1
68create_pool $TESTPOOL1 $TESTDIR/$TESTFILE1
69
70for src in ${src_dataset[@]} ; do
71	dest=${src#$TESTPOOL/}
72	if [[ $dest == *"@"* ]]; then
73		dest=${dest#*@}
74		dest=${TESTPOOL1}@$dest
75	else
76		dest=${TESTPOOL1}/$dest
77	fi
78	log_mustnot $ZFS rename $src $dest
79	log_mustnot $ZFS rename -p $src $dest
80
81	#
82	# Verify original dataset name still in use
83	#
84	log_must datasetexists $src
85done
86
87log_pass "'zfs rename' fail while datasets are within different pool."
88