xref: /freebsd/tools/regression/zfs/zpool/replace/mirror.t (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1#!/bin/sh
2# $FreeBSD$
3
4dir=`dirname $0`
5. ${dir}/../../misc.sh
6
7echo "1..27"
8
9disks_create 3
10names_create 1
11
12expect_ok ${ZPOOL} create ${name0} mirror ${disk0} ${disk1}
13expect_ok ${ZPOOL} export ${name0}
14dname0=${disk0}
15fdname0=${fdisk0}
16guid0=`get_guid ${fdisk0}`
17disk_destroy 0
18disk_create 0 ${dname0}
19expect_ok ${ZPOOL} import ${import_flags} ${name0}
20exp=`(
21  echo "  pool: ${name0}"
22  echo " state: DEGRADED"
23  echo "status: One or more devices could not be used because the label is missing or"
24  echo "      invalid.  Sufficient replicas exist for the pool to continue"
25  echo "      functioning in a degraded state."
26  echo "action: Replace the device using 'zpool replace'."
27  echo "   see: http://www.sun.com/msg/ZFS-8000-4J"
28  echo " scrub: none requested"
29  echo "config:"
30  echo "	NAME          STATE     READ WRITE CKSUM"
31  echo "	${name0}      DEGRADED     0     0     0"
32  echo "	  mirror      DEGRADED     0     0     0"
33  echo "	    ${guid0}  UNAVAIL      0     0     0 was ${fdname0}"
34  echo "	    ${disk1}  ONLINE       0     0     0"
35  echo "errors: No known data errors"
36)`
37expect "${exp}" ${ZPOOL} status ${name0}
38expect_ok ${ZPOOL} replace ${name0} ${disk0} ${disk2}
39wait_for_resilver ${name0}
40exp=`(
41  echo "  pool: ${name0}"
42  echo " state: ONLINE"
43  echo " scrub: (scrub|resilver) completed after [0-9]+h[0-9]+m with 0 errors on .*"
44  echo "config:"
45  echo "	NAME          STATE   READ WRITE CKSUM"
46  echo "	${name0}      ONLINE     0     0     0"
47  echo "	  mirror      ONLINE     0     0     0"
48  echo "	    ${disk2}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
49  echo "	    ${disk1}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
50  echo "errors: No known data errors"
51)`
52expect "${exp}" ${ZPOOL} status ${name0}
53expect_ok ${ZPOOL} destroy ${name0}
54expect_fl ${ZPOOL} status -x ${name0}
55
56expect_ok ${ZPOOL} create ${name0} mirror ${disk0} ${disk1}
57expect_ok ${ZPOOL} replace ${name0} ${disk1} ${disk2}
58wait_for_resilver ${name0}
59exp=`(
60  echo "  pool: ${name0}"
61  echo " state: ONLINE"
62  echo " scrub: (scrub|resilver) completed after [0-9]+h[0-9]+m with 0 errors on .*"
63  echo "config:"
64  echo "	NAME          STATE   READ WRITE CKSUM"
65  echo "	${name0}      ONLINE     0     0     0"
66  echo "	  mirror      ONLINE     0     0     0"
67  echo "	    ${disk0}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
68  echo "	    ${disk2}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
69  echo "errors: No known data errors"
70)`
71expect "${exp}" ${ZPOOL} status ${name0}
72expect_ok ${ZPOOL} destroy ${name0}
73expect_fl ${ZPOOL} status -x ${name0}
74
75expect_ok ${ZPOOL} create ${name0} mirror ${disk0} ${disk1}
76expect_ok ${ZPOOL} export ${name0}
77dname0=${disk0}
78fdname0=${fdisk0}
79guid0=`get_guid ${fdisk0}`
80disk_destroy 0
81expect_ok ${ZPOOL} import ${import_flags} ${name0}
82exp=`(
83  echo "  pool: ${name0}"
84  echo " state: DEGRADED"
85  echo " scrub: none requested"
86  echo "config:"
87  echo "	NAME           STATE     READ WRITE CKSUM"
88  echo "	${name0}       DEGRADED     0     0     0"
89  echo "	  mirror       DEGRADED     0     0     0"
90  echo "	    ${guid0}   REMOVED      0     0     0  was ${fdname0}"
91  echo "	    ${disk1}   ONLINE       0     0     0"
92  echo "errors: No known data errors"
93)`
94expect "${exp}" ${ZPOOL} status ${name0}
95expect_ok ${ZPOOL} replace ${name0} ${dname0} ${disk2}
96wait_for_resilver ${name0}
97exp=`(
98  echo "  pool: ${name0}"
99  echo " state: ONLINE"
100  echo " scrub: (scrub|resilver) completed after [0-9]+h[0-9]+m with 0 errors on .*"
101  echo "config:"
102  echo "	NAME          STATE   READ WRITE CKSUM"
103  echo "	${name0}      ONLINE     0     0     0"
104  echo "	  mirror      ONLINE     0     0     0"
105  echo "	    ${disk2}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
106  echo "	    ${disk1}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
107  echo "errors: No known data errors"
108)`
109expect "${exp}" ${ZPOOL} status ${name0}
110expect_ok ${ZPOOL} destroy ${name0}
111expect_fl ${ZPOOL} status -x ${name0}
112disk_create 0 ${dname0}
113
114expect_ok ${ZPOOL} create ${name0} mirror ${disk0} ${disk1}
115expect_ok ${ZPOOL} offline ${name0} ${disk1}
116expect_ok ${ZPOOL} replace ${name0} ${disk1} ${disk2}
117wait_for_resilver ${name0}
118exp=`(
119  echo "  pool: ${name0}"
120  echo " state: ONLINE"
121  echo " scrub: (scrub|resilver) completed after [0-9]+h[0-9]+m with 0 errors on .*"
122  echo "config:"
123  echo "	NAME          STATE   READ WRITE CKSUM"
124  echo "	${name0}      ONLINE     0     0     0"
125  echo "	  mirror      ONLINE     0     0     0"
126  echo "	    ${disk0}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
127  echo "	    ${disk2}  ONLINE     0     0     0(  [0-9.]+[A-Z] resilvered)?"
128  echo "errors: No known data errors"
129)`
130expect "${exp}" ${ZPOOL} status ${name0}
131expect_ok ${ZPOOL} destroy ${name0}
132expect_fl ${ZPOOL} status -x ${name0}
133
134disks_destroy
135