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