]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_export / zpool_export_004_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
34 #
35 # DESCRIPTION:
36 #       Verify zpool export succeed or fail with spare.
37 #
38 # STRATEGY:
39 #       1. Create two mirror pools with same spare.
40 #       2. Verify zpool export one pool succeed.
41 #       3. Import the pool.
42 #       4. Replace one device with the spare and detach it in one pool.
43 #       5. Verify zpool export the pool succeed.
44 #       6. Import the pool.
45 #       7. Replace one device with the spare in one pool.
46 #       8. Verify zpool export the pool fail.
47 #       9. Verify zpool export the pool with "-f" succeed.
48 #       10. Import the pool.
49 #
50
51 verify_runnable "global"
52
53 function cleanup
54 {
55         mntpnt=$TESTDIR0
56         datasetexists $TESTPOOL1 || log_must zpool import -d $mntpnt $TESTPOOL1
57         datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
58         datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2
59         typeset -i i=0
60         while ((i < 5)); do
61                 if [[ -e $mntpnt/vdev$i ]]; then
62                         log_must rm -f $mntpnt/vdev$i
63                 fi
64                 ((i += 1))
65         done
66         log_must rmdir $mntpnt
67 }
68
69
70 log_assert "Verify zpool export succeed or fail with spare."
71 log_onexit cleanup
72
73 mntpnt=$TESTDIR0
74 log_must mkdir -p $mntpnt
75
76 # mntpnt=$(get_prop mountpoint $TESTPOOL)
77
78 typeset -i i=0
79 while ((i < 5)); do
80         log_must truncate -s $MINVDEVSIZE $mntpnt/vdev$i
81         eval vdev$i=$mntpnt/vdev$i
82         ((i += 1))
83 done
84
85 log_must zpool create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4
86 log_must zpool create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4
87
88 log_must zpool export $TESTPOOL1
89 log_must zpool import -d $mntpnt $TESTPOOL1
90
91 log_must zpool replace $TESTPOOL1 $vdev0 $vdev4
92 log_must zpool detach $TESTPOOL1 $vdev4
93 log_must zpool export $TESTPOOL1
94 log_must zpool import -d $mntpnt $TESTPOOL1
95
96 log_must zpool replace $TESTPOOL1 $vdev0 $vdev4
97 log_mustnot zpool export $TESTPOOL1
98
99 log_must zpool export -f $TESTPOOL1
100 log_must zpool import -d $mntpnt  $TESTPOOL1
101
102 log_pass "Verify zpool export succeed or fail with spare."
103