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 28# 29# Copyright (c) 2012 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib 34 35# 36# DESCRIPTION: 37# 'zpool create' have to use '-f' scenarios 38# 39# STRATEGY: 40# 1. Prepare the scenarios 41# 2. Create pool without '-f' and verify it fails 42# 3. Create pool with '-f' and verify it succeeds 43# 44 45verify_runnable "global" 46 47function cleanup 48{ 49 if [[ $exported_pool == true ]]; then 50 if [[ $force_pool == true ]]; then 51 log_must $ZPOOL create -f $TESTPOOL ${disk}s${SLICE0} 52 else 53 log_must $ZPOOL import $TESTPOOL 54 fi 55 fi 56 57 if poolexists $TESTPOOL ; then 58 destroy_pool $TESTPOOL 59 fi 60 61 if poolexists $TESTPOOL1 ; then 62 destroy_pool $TESTPOOL1 63 fi 64 65 # 66 # recover it back to EFI label 67 # 68 create_pool $TESTPOOL $disk 69 destroy_pool $TESTPOOL 70 71 partition_disk $SIZE $disk 6 72} 73 74# 75# create overlap slice 0 and 1 on $disk 76# 77function create_overlap_slice 78{ 79 typeset format_file=/var/tmp/format_overlap.$$ 80 typeset disk=$1 81 82 $ECHO "partition" >$format_file 83 $ECHO "0" >> $format_file 84 $ECHO "" >> $format_file 85 $ECHO "" >> $format_file 86 $ECHO "0" >> $format_file 87 $ECHO "200m" >> $format_file 88 $ECHO "1" >> $format_file 89 $ECHO "" >> $format_file 90 $ECHO "" >> $format_file 91 $ECHO "0" >> $format_file 92 $ECHO "400m" >> $format_file 93 $ECHO "label" >> $format_file 94 $ECHO "" >> $format_file 95 $ECHO "q" >> $format_file 96 $ECHO "q" >> $format_file 97 98 $FORMAT -e -s -d $disk -f $format_file 99 typeset -i ret=$? 100 $RM -fr $format_file 101 102 if (( ret != 0 )); then 103 log_fail "unable to create overlap slice." 104 fi 105 106 return 0 107} 108 109log_assert "'zpool create' have to use '-f' scenarios" 110log_onexit cleanup 111 112typeset exported_pool=false 113typeset force_pool=false 114 115if [[ -n $DISK ]]; then 116 disk=$DISK 117else 118 disk=$DISK0 119fi 120 121# overlapped slices as vdev need -f to create pool 122 123# Make the disk is EFI labeled first via pool creation 124create_pool $TESTPOOL $disk 125destroy_pool $TESTPOOL 126 127# Make the disk is VTOC labeled since only VTOC label supports overlap 128log_must labelvtoc $disk 129log_must create_overlap_slice $disk 130 131log_mustnot $ZPOOL create $TESTPOOL ${disk}s${SLICE0} 132log_must $ZPOOL create -f $TESTPOOL ${disk}s${SLICE0} 133destroy_pool $TESTPOOL 134 135# exported device to be as spare vdev need -f to create pool 136 137log_must $ZPOOL create -f $TESTPOOL $disk 138destroy_pool $TESTPOOL 139log_must partition_disk $SIZE $disk 6 140create_pool $TESTPOOL ${disk}s${SLICE0} ${disk}s${SLICE1} 141log_must $ZPOOL export $TESTPOOL 142exported_pool=true 143log_mustnot $ZPOOL create $TESTPOOL1 ${disk}s${SLICE3} spare ${disk}s${SLICE1} 144create_pool $TESTPOOL1 ${disk}s${SLICE3} spare ${disk}s${SLICE1} 145force_pool=true 146destroy_pool $TESTPOOL1 147 148log_pass "'zpool create' have to use '-f' scenarios" 149