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