]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / 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; do
51                 poolexists $pool && destroy_pool $pool
52         done
53
54         rm -f $disk1 $disk2
55         if is_freebsd; then
56                 umount -f $TESTDIR
57                 rm -rf $TESTDIR
58         fi
59 }
60
61 log_onexit cleanup
62
63 log_assert "'zpool create -f <pool> <vspec> ...' can successfully create" \
64         "a new pool in some cases."
65
66 create_pool $TESTPOOL $DISK0
67 log_must eval "new_fs ${DEV_RDSKDIR}/${DISK1} >/dev/null 2>&1"
68 typeset disk1=$(create_blockfile $FILESIZE)
69 typeset disk2=$(create_blockfile $FILESIZE1)
70
71 unset NOINUSE_CHECK
72 log_must zpool export $TESTPOOL
73 log_note "'zpool create' without '-f' will fail " \
74         "while device belongs to an exported pool."
75 log_mustnot zpool create $TESTPOOL1 $DISK0
76 create_pool $TESTPOOL1 $DISK0
77 log_must poolexists $TESTPOOL1
78
79 log_must destroy_pool $TESTPOOL1
80
81 log_note "'zpool create' without '-f' will fail " \
82         "while device is in use by a ufs filesystem."
83 if is_freebsd; then
84         # fs must be mounted for create to fail on FreeBSD
85         log_must mkdir -p $TESTDIR
86         log_must mount ${DEV_DSKDIR}/${DISK1} $TESTDIR
87 fi
88 log_mustnot zpool create $TESTPOOL $DISK1
89 if is_freebsd; then
90         # fs must not be mounted to create pool even with -f
91         log_must umount -f $TESTDIR
92         log_must rm -rf $TESTDIR
93 fi
94 create_pool $TESTPOOL $DISK1
95 log_must poolexists $TESTPOOL
96
97 log_must destroy_pool $TESTPOOL
98
99 log_note "'zpool create' mirror without '-f' will fail " \
100         "while devices have different size."
101 log_mustnot zpool create $TESTPOOL mirror $disk1 $disk2
102 create_pool $TESTPOOL mirror $disk1 $disk2
103 log_must poolexists $TESTPOOL
104
105 log_must destroy_pool $TESTPOOL
106
107 if ! is_freebsd; then
108         log_note "'zpool create' mirror without '-f' will fail " \
109                 "while devices are of different types."
110         log_mustnot zpool create $TESTPOOL mirror $disk1 $DISK0
111         create_pool $TESTPOOL mirror $disk1 $DISK0
112         log_must poolexists $TESTPOOL
113
114         log_must destroy_pool $TESTPOOL
115 fi
116
117 log_note "'zpool create' without '-f' will fail " \
118         "while a device is part of a potentially active pool."
119 create_pool $TESTPOOL mirror $DISK0 $DISK1
120 log_must zpool offline $TESTPOOL $DISK0
121 log_must zpool export $TESTPOOL
122 log_mustnot zpool create $TESTPOOL1 $DISK0
123 create_pool $TESTPOOL1 $DISK0
124 log_must poolexists $TESTPOOL1
125
126 log_must destroy_pool $TESTPOOL1
127
128 log_pass "'zpool create -f <pool> <vspec> ...' success."