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