]> granicus.if.org Git - zfs/blob - tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh
ZTS: zpool_create_002 clean up leftover filedisk
[zfs] / tests / zfs-tests / tests / functional / cli_root / zpool_create / zpool_create_002_pos.ksh
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, 2016 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 -f <pool> <vspec> ...' can successfully create a
38 # new pool in some cases.
39 #
40 # STRATEGY:
41 # 1. Prepare the scenarios for '-f' option
42 # 2. Use -f to override the devices to create new pools
43 # 3. Verify the pool created successfully
44 #
45
46 verify_runnable "global"
47
48 function cleanup
49 {
50         for pool in $TESTPOOL $TESTPOOL1 $TESTPOOL2 $TESTPOOL3 $TESTPOOL4 \
51                 $TESTPOOL5 $TESTPOOL6
52         do
53                 destroy_pool $pool
54         done
55
56         clean_blockfile "$TESTDIR0 $TESTDIR1"
57
58         for file in $FILEDISK0 $FILEDISK1 $FILEDISK2
59         do
60                 if [[ -e $TEST_BASE_DIR/$file ]]; then
61                         rm -f $TEST_BASE_DIR/$file
62                 fi
63         done
64
65         partition_disk $SIZE $disk 6
66 }
67
68 log_onexit cleanup
69
70 log_assert "'zpool create -f <pool> <vspec> ...' can successfully create" \
71         "a new pool in some cases."
72
73 if [[ -n $DISK ]]; then
74         disk=$DISK
75 else
76         disk=$DISK0
77 fi
78 create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE0}"
79 log_must echo "y" | newfs \
80         ${DEV_RDSKDIR}/${disk}${SLICE_PREFIX}${SLICE1} >/dev/null 2>&1
81 create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${disk}${SLICE_PREFIX}${SLICE4}
82 create_blockfile $FILESIZE1 $TESTDIR1/$FILEDISK1 ${disk}${SLICE_PREFIX}${SLICE5}
83 log_must truncate -s $SIZE $TEST_BASE_DIR/$FILEDISK0
84 log_must truncate -s $SIZE $TEST_BASE_DIR/$FILEDISK1
85 log_must truncate -s $SIZE $TEST_BASE_DIR/$FILEDISK2
86
87 unset NOINUSE_CHECK
88 log_must zpool export $TESTPOOL
89 log_note "'zpool create' without '-f' will fail " \
90         "while device is belong to an exported pool."
91 log_mustnot zpool create "$TESTPOOL1" "${disk}${SLICE_PREFIX}${SLICE0}"
92 create_pool "$TESTPOOL1" "${disk}${SLICE_PREFIX}${SLICE0}"
93 log_must poolexists $TESTPOOL1
94
95 log_note "'zpool create' without '-f' will fail " \
96         "while device is using by an ufs filesystem."
97 log_mustnot zpool create "$TESTPOOL2" "${disk}${SLICE_PREFIX}${SLICE1}"
98 create_pool "$TESTPOOL2" "${disk}${SLICE_PREFIX}${SLICE1}"
99 log_must poolexists $TESTPOOL2
100
101 log_note "'zpool create' mirror without '-f' will fail " \
102         "while devices have different size."
103 log_mustnot zpool create "$TESTPOOL3" "mirror" $TESTDIR0/$FILEDISK0 \
104         $TESTDIR1/$FILEDISK1
105 create_pool "$TESTPOOL3" "mirror" $TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1
106 log_must poolexists $TESTPOOL3
107
108 log_note "'zpool create' mirror without '-f' will fail " \
109         "while devices are of different types."
110 log_mustnot zpool create "$TESTPOOL4" "mirror" $TEST_BASE_DIR/$FILEDISK0 \
111         ${disk}${SLICE_PREFIX}${SLICE3}
112 create_pool "$TESTPOOL4" "mirror" \
113         $TEST_BASE_DIR/$FILEDISK0 ${disk}${SLICE_PREFIX}${SLICE3}
114 log_must poolexists $TESTPOOL4
115
116 log_note "'zpool create' without '-f' will fail " \
117         "while device is part of potentially active pool."
118 create_pool "$TESTPOOL5"  "mirror" $TEST_BASE_DIR/$FILEDISK1 \
119         $TEST_BASE_DIR/$FILEDISK2
120 log_must zpool offline $TESTPOOL5 $TEST_BASE_DIR/$FILEDISK2
121 log_must zpool export $TESTPOOL5
122 log_mustnot zpool create "$TESTPOOL6" $TEST_BASE_DIR/$FILEDISK2
123 create_pool $TESTPOOL6 $TEST_BASE_DIR/$FILEDISK2
124 log_must poolexists $TESTPOOL6
125
126 log_pass "'zpool create -f <pool> <vspec> ...' success."