author | Lin Ling <Lin.Ling@Sun.COM> |
Mon, 03 May 2010 14:54:08 -0700 | |
changeset 12296 | 7cf402a7f374 |
parent 11814 | 09d130965476 |
child 12383 | c8a3959209ef |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1485 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
2082 | 21 |
|
789 | 22 |
/* |
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
23 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
789 | 24 |
*/ |
25 |
||
26 |
#include <ctype.h> |
|
27 |
#include <errno.h> |
|
28 |
#include <devid.h> |
|
29 |
#include <fcntl.h> |
|
30 |
#include <libintl.h> |
|
31 |
#include <stdio.h> |
|
32 |
#include <stdlib.h> |
|
3126 | 33 |
#include <strings.h> |
789 | 34 |
#include <unistd.h> |
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
35 |
#include <sys/efi_partition.h> |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
36 |
#include <sys/vtoc.h> |
789 | 37 |
#include <sys/zfs_ioctl.h> |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
38 |
#include <dlfcn.h> |
789 | 39 |
|
40 |
#include "zfs_namecheck.h" |
|
3912 | 41 |
#include "zfs_prop.h" |
789 | 42 |
#include "libzfs_impl.h" |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
43 |
#include "zfs_comutil.h" |
789 | 44 |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
45 |
static int read_efi_label(nvlist_t *config, diskaddr_t *sb); |
5094 | 46 |
|
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
47 |
#if defined(__i386) || defined(__amd64) |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
48 |
#define BOOTCMD "installgrub(1M)" |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
49 |
#else |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
50 |
#define BOOTCMD "installboot(1M)" |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
51 |
#endif |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
52 |
|
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
53 |
#define DISK_ROOT "/dev/dsk" |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
54 |
#define RDISK_ROOT "/dev/rdsk" |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
55 |
#define BACKUP_SLICE "s2" |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
56 |
|
5094 | 57 |
/* |
58 |
* ==================================================================== |
|
59 |
* zpool property functions |
|
60 |
* ==================================================================== |
|
61 |
*/ |
|
62 |
||
63 |
static int |
|
64 |
zpool_get_all_props(zpool_handle_t *zhp) |
|
65 |
{ |
|
66 |
zfs_cmd_t zc = { 0 }; |
|
67 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
68 |
||
69 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
70 |
||
71 |
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0) |
|
72 |
return (-1); |
|
73 |
||
74 |
while (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_PROPS, &zc) != 0) { |
|
75 |
if (errno == ENOMEM) { |
|
76 |
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) { |
|
77 |
zcmd_free_nvlists(&zc); |
|
78 |
return (-1); |
|
79 |
} |
|
80 |
} else { |
|
81 |
zcmd_free_nvlists(&zc); |
|
82 |
return (-1); |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
if (zcmd_read_dst_nvlist(hdl, &zc, &zhp->zpool_props) != 0) { |
|
87 |
zcmd_free_nvlists(&zc); |
|
88 |
return (-1); |
|
89 |
} |
|
90 |
||
91 |
zcmd_free_nvlists(&zc); |
|
92 |
||
93 |
return (0); |
|
94 |
} |
|
95 |
||
96 |
static int |
|
97 |
zpool_props_refresh(zpool_handle_t *zhp) |
|
98 |
{ |
|
99 |
nvlist_t *old_props; |
|
100 |
||
101 |
old_props = zhp->zpool_props; |
|
102 |
||
103 |
if (zpool_get_all_props(zhp) != 0) |
|
104 |
return (-1); |
|
105 |
||
106 |
nvlist_free(old_props); |
|
107 |
return (0); |
|
108 |
} |
|
109 |
||
110 |
static char * |
|
111 |
zpool_get_prop_string(zpool_handle_t *zhp, zpool_prop_t prop, |
|
112 |
zprop_source_t *src) |
|
113 |
{ |
|
114 |
nvlist_t *nv, *nvl; |
|
115 |
uint64_t ival; |
|
116 |
char *value; |
|
117 |
zprop_source_t source; |
|
118 |
||
119 |
nvl = zhp->zpool_props; |
|
120 |
if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) { |
|
121 |
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &ival) == 0); |
|
122 |
source = ival; |
|
123 |
verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0); |
|
124 |
} else { |
|
125 |
source = ZPROP_SRC_DEFAULT; |
|
126 |
if ((value = (char *)zpool_prop_default_string(prop)) == NULL) |
|
127 |
value = "-"; |
|
128 |
} |
|
129 |
||
130 |
if (src) |
|
131 |
*src = source; |
|
132 |
||
133 |
return (value); |
|
134 |
} |
|
135 |
||
136 |
uint64_t |
|
137 |
zpool_get_prop_int(zpool_handle_t *zhp, zpool_prop_t prop, zprop_source_t *src) |
|
138 |
{ |
|
139 |
nvlist_t *nv, *nvl; |
|
140 |
uint64_t value; |
|
141 |
zprop_source_t source; |
|
142 |
||
7294 | 143 |
if (zhp->zpool_props == NULL && zpool_get_all_props(zhp)) { |
144 |
/* |
|
145 |
* zpool_get_all_props() has most likely failed because |
|
146 |
* the pool is faulted, but if all we need is the top level |
|
147 |
* vdev's guid then get it from the zhp config nvlist. |
|
148 |
*/ |
|
149 |
if ((prop == ZPOOL_PROP_GUID) && |
|
150 |
(nvlist_lookup_nvlist(zhp->zpool_config, |
|
151 |
ZPOOL_CONFIG_VDEV_TREE, &nv) == 0) && |
|
152 |
(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &value) |
|
153 |
== 0)) { |
|
154 |
return (value); |
|
155 |
} |
|
5094 | 156 |
return (zpool_prop_default_numeric(prop)); |
7294 | 157 |
} |
5094 | 158 |
|
159 |
nvl = zhp->zpool_props; |
|
160 |
if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) { |
|
161 |
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &value) == 0); |
|
162 |
source = value; |
|
163 |
verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0); |
|
164 |
} else { |
|
165 |
source = ZPROP_SRC_DEFAULT; |
|
166 |
value = zpool_prop_default_numeric(prop); |
|
167 |
} |
|
168 |
||
169 |
if (src) |
|
170 |
*src = source; |
|
171 |
||
172 |
return (value); |
|
173 |
} |
|
174 |
||
175 |
/* |
|
176 |
* Map VDEV STATE to printed strings. |
|
177 |
*/ |
|
178 |
char * |
|
179 |
zpool_state_to_name(vdev_state_t state, vdev_aux_t aux) |
|
180 |
{ |
|
181 |
switch (state) { |
|
182 |
case VDEV_STATE_CLOSED: |
|
183 |
case VDEV_STATE_OFFLINE: |
|
184 |
return (gettext("OFFLINE")); |
|
185 |
case VDEV_STATE_REMOVED: |
|
186 |
return (gettext("REMOVED")); |
|
187 |
case VDEV_STATE_CANT_OPEN: |
|
7294 | 188 |
if (aux == VDEV_AUX_CORRUPT_DATA || aux == VDEV_AUX_BAD_LOG) |
5094 | 189 |
return (gettext("FAULTED")); |
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
190 |
else if (aux == VDEV_AUX_SPLIT_POOL) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
191 |
return (gettext("SPLIT")); |
5094 | 192 |
else |
193 |
return (gettext("UNAVAIL")); |
|
194 |
case VDEV_STATE_FAULTED: |
|
195 |
return (gettext("FAULTED")); |
|
196 |
case VDEV_STATE_DEGRADED: |
|
197 |
return (gettext("DEGRADED")); |
|
198 |
case VDEV_STATE_HEALTHY: |
|
199 |
return (gettext("ONLINE")); |
|
200 |
} |
|
201 |
||
202 |
return (gettext("UNKNOWN")); |
|
203 |
} |
|
204 |
||
205 |
/* |
|
206 |
* Get a zpool property value for 'prop' and return the value in |
|
207 |
* a pre-allocated buffer. |
|
208 |
*/ |
|
209 |
int |
|
210 |
zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len, |
|
211 |
zprop_source_t *srctype) |
|
212 |
{ |
|
213 |
uint64_t intval; |
|
214 |
const char *strval; |
|
215 |
zprop_source_t src = ZPROP_SRC_NONE; |
|
216 |
nvlist_t *nvroot; |
|
217 |
vdev_stat_t *vs; |
|
218 |
uint_t vsc; |
|
219 |
||
220 |
if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) { |
|
8525
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
221 |
switch (prop) { |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
222 |
case ZPOOL_PROP_NAME: |
5094 | 223 |
(void) strlcpy(buf, zpool_get_name(zhp), len); |
8525
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
224 |
break; |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
225 |
|
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
226 |
case ZPOOL_PROP_HEALTH: |
5094 | 227 |
(void) strlcpy(buf, "FAULTED", len); |
8525
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
228 |
break; |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
229 |
|
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
230 |
case ZPOOL_PROP_GUID: |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
231 |
intval = zpool_get_prop_int(zhp, prop, &src); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
232 |
(void) snprintf(buf, len, "%llu", intval); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
233 |
break; |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
234 |
|
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
235 |
case ZPOOL_PROP_ALTROOT: |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
236 |
case ZPOOL_PROP_CACHEFILE: |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
237 |
if (zhp->zpool_props != NULL || |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
238 |
zpool_get_all_props(zhp) == 0) { |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
239 |
(void) strlcpy(buf, |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
240 |
zpool_get_prop_string(zhp, prop, &src), |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
241 |
len); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
242 |
if (srctype != NULL) |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
243 |
*srctype = src; |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
244 |
return (0); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
245 |
} |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
246 |
/* FALLTHROUGH */ |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
247 |
default: |
5094 | 248 |
(void) strlcpy(buf, "-", len); |
8525
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
249 |
break; |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
250 |
} |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
251 |
|
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
252 |
if (srctype != NULL) |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
8211
diff
changeset
|
253 |
*srctype = src; |
5094 | 254 |
return (0); |
255 |
} |
|
256 |
||
257 |
if (zhp->zpool_props == NULL && zpool_get_all_props(zhp) && |
|
258 |
prop != ZPOOL_PROP_NAME) |
|
259 |
return (-1); |
|
260 |
||
261 |
switch (zpool_prop_get_type(prop)) { |
|
262 |
case PROP_TYPE_STRING: |
|
263 |
(void) strlcpy(buf, zpool_get_prop_string(zhp, prop, &src), |
|
264 |
len); |
|
265 |
break; |
|
266 |
||
267 |
case PROP_TYPE_NUMBER: |
|
268 |
intval = zpool_get_prop_int(zhp, prop, &src); |
|
269 |
||
270 |
switch (prop) { |
|
271 |
case ZPOOL_PROP_SIZE: |
|
10956
0c81acaaf614
6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents:
10922
diff
changeset
|
272 |
case ZPOOL_PROP_ALLOCATED: |
0c81acaaf614
6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents:
10922
diff
changeset
|
273 |
case ZPOOL_PROP_FREE: |
5094 | 274 |
(void) zfs_nicenum(intval, buf, len); |
275 |
break; |
|
276 |
||
277 |
case ZPOOL_PROP_CAPACITY: |
|
278 |
(void) snprintf(buf, len, "%llu%%", |
|
279 |
(u_longlong_t)intval); |
|
280 |
break; |
|
281 |
||
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
282 |
case ZPOOL_PROP_DEDUPRATIO: |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
283 |
(void) snprintf(buf, len, "%llu.%02llux", |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
284 |
(u_longlong_t)(intval / 100), |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
285 |
(u_longlong_t)(intval % 100)); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
286 |
break; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
287 |
|
5094 | 288 |
case ZPOOL_PROP_HEALTH: |
289 |
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL), |
|
290 |
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); |
|
291 |
verify(nvlist_lookup_uint64_array(nvroot, |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
292 |
ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &vsc) |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
293 |
== 0); |
5094 | 294 |
|
295 |
(void) strlcpy(buf, zpool_state_to_name(intval, |
|
296 |
vs->vs_aux), len); |
|
297 |
break; |
|
298 |
default: |
|
299 |
(void) snprintf(buf, len, "%llu", intval); |
|
300 |
} |
|
301 |
break; |
|
302 |
||
303 |
case PROP_TYPE_INDEX: |
|
304 |
intval = zpool_get_prop_int(zhp, prop, &src); |
|
305 |
if (zpool_prop_index_to_string(prop, intval, &strval) |
|
306 |
!= 0) |
|
307 |
return (-1); |
|
308 |
(void) strlcpy(buf, strval, len); |
|
309 |
break; |
|
310 |
||
311 |
default: |
|
312 |
abort(); |
|
313 |
} |
|
314 |
||
315 |
if (srctype) |
|
316 |
*srctype = src; |
|
317 |
||
318 |
return (0); |
|
319 |
} |
|
320 |
||
321 |
/* |
|
322 |
* Check if the bootfs name has the same pool name as it is set to. |
|
323 |
* Assuming bootfs is a valid dataset name. |
|
324 |
*/ |
|
325 |
static boolean_t |
|
326 |
bootfs_name_valid(const char *pool, char *bootfs) |
|
327 |
{ |
|
328 |
int len = strlen(pool); |
|
329 |
||
7300
3f0c3af330d3
6667976 support booting up a snapshot root dataset
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
330 |
if (!zfs_name_valid(bootfs, ZFS_TYPE_FILESYSTEM|ZFS_TYPE_SNAPSHOT)) |
5094 | 331 |
return (B_FALSE); |
332 |
||
333 |
if (strncmp(pool, bootfs, len) == 0 && |
|
334 |
(bootfs[len] == '/' || bootfs[len] == '\0')) |
|
335 |
return (B_TRUE); |
|
336 |
||
337 |
return (B_FALSE); |
|
338 |
} |
|
339 |
||
340 |
/* |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
341 |
* Inspect the configuration to determine if any of the devices contain |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
342 |
* an EFI label. |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
343 |
*/ |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
344 |
static boolean_t |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
345 |
pool_uses_efi(nvlist_t *config) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
346 |
{ |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
347 |
nvlist_t **child; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
348 |
uint_t c, children; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
349 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
350 |
if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN, |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
351 |
&child, &children) != 0) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
352 |
return (read_efi_label(config, NULL) >= 0); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
353 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
354 |
for (c = 0; c < children; c++) { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
355 |
if (pool_uses_efi(child[c])) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
356 |
return (B_TRUE); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
357 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
358 |
return (B_FALSE); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
359 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
360 |
|
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
361 |
static boolean_t |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
362 |
pool_is_bootable(zpool_handle_t *zhp) |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
363 |
{ |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
364 |
char bootfs[ZPOOL_MAXNAMELEN]; |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
365 |
|
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
366 |
return (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs, |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
367 |
sizeof (bootfs), NULL) == 0 && strncmp(bootfs, "-", |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
368 |
sizeof (bootfs)) != 0); |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
369 |
} |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
370 |
|
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
371 |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
372 |
/* |
5094 | 373 |
* Given an nvlist of zpool properties to be set, validate that they are |
374 |
* correct, and parse any numeric properties (index, boolean, etc) if they are |
|
375 |
* specified as strings. |
|
376 |
*/ |
|
377 |
static nvlist_t * |
|
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
378 |
zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, |
5094 | 379 |
nvlist_t *props, uint64_t version, boolean_t create_or_import, char *errbuf) |
380 |
{ |
|
381 |
nvpair_t *elem; |
|
382 |
nvlist_t *retprops; |
|
383 |
zpool_prop_t prop; |
|
384 |
char *strval; |
|
385 |
uint64_t intval; |
|
5363 | 386 |
char *slash; |
387 |
struct stat64 statbuf; |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
388 |
zpool_handle_t *zhp; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
389 |
nvlist_t *nvroot; |
5094 | 390 |
|
391 |
if (nvlist_alloc(&retprops, NV_UNIQUE_NAME, 0) != 0) { |
|
392 |
(void) no_memory(hdl); |
|
393 |
return (NULL); |
|
394 |
} |
|
395 |
||
396 |
elem = NULL; |
|
397 |
while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { |
|
398 |
const char *propname = nvpair_name(elem); |
|
399 |
||
400 |
/* |
|
401 |
* Make sure this property is valid and applies to this type. |
|
402 |
*/ |
|
403 |
if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) { |
|
404 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
405 |
"invalid property '%s'"), propname); |
|
406 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
407 |
goto error; |
|
408 |
} |
|
409 |
||
410 |
if (zpool_prop_readonly(prop)) { |
|
411 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' " |
|
412 |
"is readonly"), propname); |
|
413 |
(void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf); |
|
414 |
goto error; |
|
415 |
} |
|
416 |
||
417 |
if (zprop_parse_value(hdl, elem, prop, ZFS_TYPE_POOL, retprops, |
|
418 |
&strval, &intval, errbuf) != 0) |
|
419 |
goto error; |
|
420 |
||
421 |
/* |
|
422 |
* Perform additional checking for specific properties. |
|
423 |
*/ |
|
424 |
switch (prop) { |
|
425 |
case ZPOOL_PROP_VERSION: |
|
426 |
if (intval < version || intval > SPA_VERSION) { |
|
427 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
428 |
"property '%s' number %d is invalid."), |
|
429 |
propname, intval); |
|
430 |
(void) zfs_error(hdl, EZFS_BADVERSION, errbuf); |
|
431 |
goto error; |
|
432 |
} |
|
433 |
break; |
|
434 |
||
435 |
case ZPOOL_PROP_BOOTFS: |
|
436 |
if (create_or_import) { |
|
437 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
438 |
"property '%s' cannot be set at creation " |
|
439 |
"or import time"), propname); |
|
440 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
441 |
goto error; |
|
442 |
} |
|
443 |
||
444 |
if (version < SPA_VERSION_BOOTFS) { |
|
445 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
446 |
"pool must be upgraded to support " |
|
447 |
"'%s' property"), propname); |
|
448 |
(void) zfs_error(hdl, EZFS_BADVERSION, errbuf); |
|
449 |
goto error; |
|
450 |
} |
|
451 |
||
452 |
/* |
|
453 |
* bootfs property value has to be a dataset name and |
|
454 |
* the dataset has to be in the same pool as it sets to. |
|
455 |
*/ |
|
456 |
if (strval[0] != '\0' && !bootfs_name_valid(poolname, |
|
457 |
strval)) { |
|
458 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' " |
|
459 |
"is an invalid name"), strval); |
|
460 |
(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf); |
|
461 |
goto error; |
|
462 |
} |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
463 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
464 |
if ((zhp = zpool_open_canfail(hdl, poolname)) == NULL) { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
465 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
466 |
"could not open pool '%s'"), poolname); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
467 |
(void) zfs_error(hdl, EZFS_OPENFAILED, errbuf); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
468 |
goto error; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
469 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
470 |
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL), |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
471 |
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
472 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
473 |
/* |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
474 |
* bootfs property cannot be set on a disk which has |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
475 |
* been EFI labeled. |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
476 |
*/ |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
477 |
if (pool_uses_efi(nvroot)) { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
478 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
479 |
"property '%s' not supported on " |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
480 |
"EFI labeled devices"), propname); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
481 |
(void) zfs_error(hdl, EZFS_POOL_NOTSUP, errbuf); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
482 |
zpool_close(zhp); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
483 |
goto error; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
484 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
485 |
zpool_close(zhp); |
5094 | 486 |
break; |
487 |
||
488 |
case ZPOOL_PROP_ALTROOT: |
|
489 |
if (!create_or_import) { |
|
490 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
491 |
"property '%s' can only be set during pool " |
|
492 |
"creation or import"), propname); |
|
493 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
494 |
goto error; |
|
495 |
} |
|
496 |
||
497 |
if (strval[0] != '/') { |
|
498 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
499 |
"bad alternate root '%s'"), strval); |
|
500 |
(void) zfs_error(hdl, EZFS_BADPATH, errbuf); |
|
501 |
goto error; |
|
502 |
} |
|
503 |
break; |
|
5363 | 504 |
|
505 |
case ZPOOL_PROP_CACHEFILE: |
|
506 |
if (strval[0] == '\0') |
|
507 |
break; |
|
508 |
||
509 |
if (strcmp(strval, "none") == 0) |
|
510 |
break; |
|
511 |
||
512 |
if (strval[0] != '/') { |
|
513 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
514 |
"property '%s' must be empty, an " |
|
515 |
"absolute path, or 'none'"), propname); |
|
516 |
(void) zfs_error(hdl, EZFS_BADPATH, errbuf); |
|
517 |
goto error; |
|
518 |
} |
|
519 |
||
520 |
slash = strrchr(strval, '/'); |
|
521 |
||
522 |
if (slash[1] == '\0' || strcmp(slash, "/.") == 0 || |
|
523 |
strcmp(slash, "/..") == 0) { |
|
524 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
525 |
"'%s' is not a valid file"), strval); |
|
526 |
(void) zfs_error(hdl, EZFS_BADPATH, errbuf); |
|
527 |
goto error; |
|
528 |
} |
|
529 |
||
530 |
*slash = '\0'; |
|
531 |
||
5621
cd0984d5b1c1
6627006 setting cachefile to default value confuses ZFS
eschrock
parents:
5450
diff
changeset
|
532 |
if (strval[0] != '\0' && |
cd0984d5b1c1
6627006 setting cachefile to default value confuses ZFS
eschrock
parents:
5450
diff
changeset
|
533 |
(stat64(strval, &statbuf) != 0 || |
cd0984d5b1c1
6627006 setting cachefile to default value confuses ZFS
eschrock
parents:
5450
diff
changeset
|
534 |
!S_ISDIR(statbuf.st_mode))) { |
5363 | 535 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
536 |
"'%s' is not a valid directory"), |
|
537 |
strval); |
|
538 |
(void) zfs_error(hdl, EZFS_BADPATH, errbuf); |
|
539 |
goto error; |
|
540 |
} |
|
541 |
||
542 |
*slash = '/'; |
|
543 |
break; |
|
5094 | 544 |
} |
545 |
} |
|
546 |
||
547 |
return (retprops); |
|
548 |
error: |
|
549 |
nvlist_free(retprops); |
|
550 |
return (NULL); |
|
551 |
} |
|
552 |
||
553 |
/* |
|
554 |
* Set zpool property : propname=propval. |
|
555 |
*/ |
|
556 |
int |
|
557 |
zpool_set_prop(zpool_handle_t *zhp, const char *propname, const char *propval) |
|
558 |
{ |
|
559 |
zfs_cmd_t zc = { 0 }; |
|
560 |
int ret = -1; |
|
561 |
char errbuf[1024]; |
|
562 |
nvlist_t *nvl = NULL; |
|
563 |
nvlist_t *realprops; |
|
564 |
uint64_t version; |
|
565 |
||
566 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
567 |
dgettext(TEXT_DOMAIN, "cannot set property for '%s'"), |
|
568 |
zhp->zpool_name); |
|
569 |
||
570 |
if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) |
|
571 |
return (no_memory(zhp->zpool_hdl)); |
|
572 |
||
573 |
if (nvlist_add_string(nvl, propname, propval) != 0) { |
|
574 |
nvlist_free(nvl); |
|
575 |
return (no_memory(zhp->zpool_hdl)); |
|
576 |
} |
|
577 |
||
578 |
version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL); |
|
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
579 |
if ((realprops = zpool_valid_proplist(zhp->zpool_hdl, |
5094 | 580 |
zhp->zpool_name, nvl, version, B_FALSE, errbuf)) == NULL) { |
581 |
nvlist_free(nvl); |
|
582 |
return (-1); |
|
583 |
} |
|
584 |
||
585 |
nvlist_free(nvl); |
|
586 |
nvl = realprops; |
|
587 |
||
588 |
/* |
|
589 |
* Execute the corresponding ioctl() to set this property. |
|
590 |
*/ |
|
591 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
592 |
||
593 |
if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, nvl) != 0) { |
|
594 |
nvlist_free(nvl); |
|
595 |
return (-1); |
|
596 |
} |
|
597 |
||
598 |
ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_SET_PROPS, &zc); |
|
599 |
||
600 |
zcmd_free_nvlists(&zc); |
|
601 |
nvlist_free(nvl); |
|
602 |
||
603 |
if (ret) |
|
604 |
(void) zpool_standard_error(zhp->zpool_hdl, errno, errbuf); |
|
605 |
else |
|
606 |
(void) zpool_props_refresh(zhp); |
|
607 |
||
608 |
return (ret); |
|
609 |
} |
|
610 |
||
611 |
int |
|
612 |
zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp) |
|
613 |
{ |
|
614 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
615 |
zprop_list_t *entry; |
|
616 |
char buf[ZFS_MAXPROPLEN]; |
|
617 |
||
618 |
if (zprop_expand_list(hdl, plp, ZFS_TYPE_POOL) != 0) |
|
619 |
return (-1); |
|
620 |
||
621 |
for (entry = *plp; entry != NULL; entry = entry->pl_next) { |
|
622 |
||
623 |
if (entry->pl_fixed) |
|
624 |
continue; |
|
625 |
||
626 |
if (entry->pl_prop != ZPROP_INVAL && |
|
627 |
zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf), |
|
628 |
NULL) == 0) { |
|
629 |
if (strlen(buf) > entry->pl_width) |
|
630 |
entry->pl_width = strlen(buf); |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
return (0); |
|
635 |
} |
|
636 |
||
637 |
||
789 | 638 |
/* |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
639 |
* Don't start the slice at the default block of 34; many storage |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
640 |
* devices will use a stripe width of 128k, so start there instead. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
641 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
642 |
#define NEW_START_BLOCK 256 |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
643 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
644 |
/* |
789 | 645 |
* Validate the given pool name, optionally putting an extended error message in |
646 |
* 'buf'. |
|
647 |
*/ |
|
6423 | 648 |
boolean_t |
2082 | 649 |
zpool_name_valid(libzfs_handle_t *hdl, boolean_t isopen, const char *pool) |
789 | 650 |
{ |
651 |
namecheck_err_t why; |
|
652 |
char what; |
|
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
653 |
int ret; |
789 | 654 |
|
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
655 |
ret = pool_namecheck(pool, &why, &what); |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
656 |
|
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
657 |
/* |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
658 |
* The rules for reserved pool names were extended at a later point. |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
659 |
* But we need to support users with existing pools that may now be |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
660 |
* invalid. So we only check for this expanded set of names during a |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
661 |
* create (or import), and only in userland. |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
662 |
*/ |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
663 |
if (ret == 0 && !isopen && |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
664 |
(strncmp(pool, "mirror", 6) == 0 || |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
665 |
strncmp(pool, "raidz", 5) == 0 || |
4527 | 666 |
strncmp(pool, "spare", 5) == 0 || |
667 |
strcmp(pool, "log") == 0)) { |
|
6423 | 668 |
if (hdl != NULL) |
669 |
zfs_error_aux(hdl, |
|
670 |
dgettext(TEXT_DOMAIN, "name is reserved")); |
|
2082 | 671 |
return (B_FALSE); |
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
672 |
} |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
673 |
|
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
674 |
|
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1760
diff
changeset
|
675 |
if (ret != 0) { |
2082 | 676 |
if (hdl != NULL) { |
789 | 677 |
switch (why) { |
1003 | 678 |
case NAME_ERR_TOOLONG: |
2082 | 679 |
zfs_error_aux(hdl, |
1003 | 680 |
dgettext(TEXT_DOMAIN, "name is too long")); |
681 |
break; |
|
682 |
||
789 | 683 |
case NAME_ERR_INVALCHAR: |
2082 | 684 |
zfs_error_aux(hdl, |
789 | 685 |
dgettext(TEXT_DOMAIN, "invalid character " |
686 |
"'%c' in pool name"), what); |
|
687 |
break; |
|
688 |
||
689 |
case NAME_ERR_NOLETTER: |
|
2082 | 690 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
691 |
"name must begin with a letter")); |
|
789 | 692 |
break; |
693 |
||
694 |
case NAME_ERR_RESERVED: |
|
2082 | 695 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
696 |
"name is reserved")); |
|
789 | 697 |
break; |
698 |
||
699 |
case NAME_ERR_DISKLIKE: |
|
2082 | 700 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
701 |
"pool name is reserved")); |
|
789 | 702 |
break; |
2856 | 703 |
|
704 |
case NAME_ERR_LEADING_SLASH: |
|
705 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
706 |
"leading slash in name")); |
|
707 |
break; |
|
708 |
||
709 |
case NAME_ERR_EMPTY_COMPONENT: |
|
710 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
711 |
"empty component in name")); |
|
712 |
break; |
|
713 |
||
714 |
case NAME_ERR_TRAILING_SLASH: |
|
715 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
716 |
"trailing slash in name")); |
|
717 |
break; |
|
718 |
||
719 |
case NAME_ERR_MULTIPLE_AT: |
|
720 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
721 |
"multiple '@' delimiters in name")); |
|
722 |
break; |
|
723 |
||
789 | 724 |
} |
725 |
} |
|
2082 | 726 |
return (B_FALSE); |
789 | 727 |
} |
728 |
||
2082 | 729 |
return (B_TRUE); |
789 | 730 |
} |
731 |
||
732 |
/* |
|
733 |
* Open a handle to the given pool, even if the pool is currently in the FAULTED |
|
734 |
* state. |
|
735 |
*/ |
|
736 |
zpool_handle_t * |
|
2082 | 737 |
zpool_open_canfail(libzfs_handle_t *hdl, const char *pool) |
789 | 738 |
{ |
739 |
zpool_handle_t *zhp; |
|
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
740 |
boolean_t missing; |
789 | 741 |
|
742 |
/* |
|
743 |
* Make sure the pool name is valid. |
|
744 |
*/ |
|
2082 | 745 |
if (!zpool_name_valid(hdl, B_TRUE, pool)) { |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
746 |
(void) zfs_error_fmt(hdl, EZFS_INVALIDNAME, |
2082 | 747 |
dgettext(TEXT_DOMAIN, "cannot open '%s'"), |
748 |
pool); |
|
789 | 749 |
return (NULL); |
750 |
} |
|
751 |
||
2082 | 752 |
if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL) |
753 |
return (NULL); |
|
789 | 754 |
|
2082 | 755 |
zhp->zpool_hdl = hdl; |
789 | 756 |
(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name)); |
757 |
||
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
758 |
if (zpool_refresh_stats(zhp, &missing) != 0) { |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
759 |
zpool_close(zhp); |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
760 |
return (NULL); |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
761 |
} |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
762 |
|
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
763 |
if (missing) { |
5094 | 764 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "no such pool")); |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
765 |
(void) zfs_error_fmt(hdl, EZFS_NOENT, |
5094 | 766 |
dgettext(TEXT_DOMAIN, "cannot open '%s'"), pool); |
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
767 |
zpool_close(zhp); |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
768 |
return (NULL); |
789 | 769 |
} |
770 |
||
771 |
return (zhp); |
|
772 |
} |
|
773 |
||
774 |
/* |
|
775 |
* Like the above, but silent on error. Used when iterating over pools (because |
|
776 |
* the configuration cache may be out of date). |
|
777 |
*/ |
|
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
778 |
int |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
779 |
zpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret) |
789 | 780 |
{ |
781 |
zpool_handle_t *zhp; |
|
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
782 |
boolean_t missing; |
789 | 783 |
|
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
784 |
if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL) |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
785 |
return (-1); |
789 | 786 |
|
2082 | 787 |
zhp->zpool_hdl = hdl; |
789 | 788 |
(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name)); |
789 |
||
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
790 |
if (zpool_refresh_stats(zhp, &missing) != 0) { |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
791 |
zpool_close(zhp); |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
792 |
return (-1); |
789 | 793 |
} |
794 |
||
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
795 |
if (missing) { |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
796 |
zpool_close(zhp); |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
797 |
*ret = NULL; |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
798 |
return (0); |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
799 |
} |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
800 |
|
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
801 |
*ret = zhp; |
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
802 |
return (0); |
789 | 803 |
} |
804 |
||
805 |
/* |
|
806 |
* Similar to zpool_open_canfail(), but refuses to open pools in the faulted |
|
807 |
* state. |
|
808 |
*/ |
|
809 |
zpool_handle_t * |
|
2082 | 810 |
zpool_open(libzfs_handle_t *hdl, const char *pool) |
789 | 811 |
{ |
812 |
zpool_handle_t *zhp; |
|
813 |
||
2082 | 814 |
if ((zhp = zpool_open_canfail(hdl, pool)) == NULL) |
789 | 815 |
return (NULL); |
816 |
||
817 |
if (zhp->zpool_state == POOL_STATE_UNAVAIL) { |
|
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
818 |
(void) zfs_error_fmt(hdl, EZFS_POOLUNAVAIL, |
2082 | 819 |
dgettext(TEXT_DOMAIN, "cannot open '%s'"), zhp->zpool_name); |
789 | 820 |
zpool_close(zhp); |
821 |
return (NULL); |
|
822 |
} |
|
823 |
||
824 |
return (zhp); |
|
825 |
} |
|
826 |
||
827 |
/* |
|
828 |
* Close the handle. Simply frees the memory associated with the handle. |
|
829 |
*/ |
|
830 |
void |
|
831 |
zpool_close(zpool_handle_t *zhp) |
|
832 |
{ |
|
833 |
if (zhp->zpool_config) |
|
834 |
nvlist_free(zhp->zpool_config); |
|
952
12ec54aa046e
6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents:
789
diff
changeset
|
835 |
if (zhp->zpool_old_config) |
12ec54aa046e
6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents:
789
diff
changeset
|
836 |
nvlist_free(zhp->zpool_old_config); |
3912 | 837 |
if (zhp->zpool_props) |
838 |
nvlist_free(zhp->zpool_props); |
|
789 | 839 |
free(zhp); |
840 |
} |
|
841 |
||
842 |
/* |
|
843 |
* Return the name of the pool. |
|
844 |
*/ |
|
845 |
const char * |
|
846 |
zpool_get_name(zpool_handle_t *zhp) |
|
847 |
{ |
|
848 |
return (zhp->zpool_name); |
|
849 |
} |
|
850 |
||
851 |
||
852 |
/* |
|
853 |
* Return the state of the pool (ACTIVE or UNAVAILABLE) |
|
854 |
*/ |
|
855 |
int |
|
856 |
zpool_get_state(zpool_handle_t *zhp) |
|
857 |
{ |
|
858 |
return (zhp->zpool_state); |
|
859 |
} |
|
860 |
||
861 |
/* |
|
862 |
* Create the named pool, using the provided vdev list. It is assumed |
|
863 |
* that the consumer has already validated the contents of the nvlist, so we |
|
864 |
* don't have to worry about error semantics. |
|
865 |
*/ |
|
866 |
int |
|
2082 | 867 |
zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot, |
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
868 |
nvlist_t *props, nvlist_t *fsprops) |
789 | 869 |
{ |
870 |
zfs_cmd_t zc = { 0 }; |
|
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
871 |
nvlist_t *zc_fsprops = NULL; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
872 |
nvlist_t *zc_props = NULL; |
2082 | 873 |
char msg[1024]; |
5094 | 874 |
char *altroot; |
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
875 |
int ret = -1; |
2082 | 876 |
|
877 |
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, |
|
878 |
"cannot create '%s'"), pool); |
|
789 | 879 |
|
2082 | 880 |
if (!zpool_name_valid(hdl, B_FALSE, pool)) |
881 |
return (zfs_error(hdl, EZFS_INVALIDNAME, msg)); |
|
882 |
||
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
883 |
if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0) |
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
884 |
return (-1); |
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
885 |
|
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
886 |
if (props) { |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
887 |
if ((zc_props = zpool_valid_proplist(hdl, pool, props, |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
888 |
SPA_VERSION_1, B_TRUE, msg)) == NULL) { |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
889 |
goto create_failed; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
890 |
} |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
891 |
} |
789 | 892 |
|
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
893 |
if (fsprops) { |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
894 |
uint64_t zoned; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
895 |
char *zonestr; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
896 |
|
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
897 |
zoned = ((nvlist_lookup_string(fsprops, |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
898 |
zfs_prop_to_name(ZFS_PROP_ZONED), &zonestr) == 0) && |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
899 |
strcmp(zonestr, "on") == 0); |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
900 |
|
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
901 |
if ((zc_fsprops = zfs_valid_proplist(hdl, |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
902 |
ZFS_TYPE_FILESYSTEM, fsprops, zoned, NULL, msg)) == NULL) { |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
903 |
goto create_failed; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
904 |
} |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
905 |
if (!zc_props && |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
906 |
(nvlist_alloc(&zc_props, NV_UNIQUE_NAME, 0) != 0)) { |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
907 |
goto create_failed; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
908 |
} |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
909 |
if (nvlist_add_nvlist(zc_props, |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
910 |
ZPOOL_ROOTFS_PROPS, zc_fsprops) != 0) { |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
911 |
goto create_failed; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
912 |
} |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
913 |
} |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
914 |
|
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
915 |
if (zc_props && zcmd_write_src_nvlist(hdl, &zc, zc_props) != 0) |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
916 |
goto create_failed; |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
917 |
|
789 | 918 |
(void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name)); |
919 |
||
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
920 |
if ((ret = zfs_ioctl(hdl, ZFS_IOC_POOL_CREATE, &zc)) != 0) { |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
921 |
|
2676 | 922 |
zcmd_free_nvlists(&zc); |
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
923 |
nvlist_free(zc_props); |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
924 |
nvlist_free(zc_fsprops); |
2082 | 925 |
|
789 | 926 |
switch (errno) { |
927 |
case EBUSY: |
|
928 |
/* |
|
929 |
* This can happen if the user has specified the same |
|
930 |
* device multiple times. We can't reliably detect this |
|
931 |
* until we try to add it and see we already have a |
|
932 |
* label. |
|
933 |
*/ |
|
2082 | 934 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
935 |
"one or more vdevs refer to the same device")); |
|
936 |
return (zfs_error(hdl, EZFS_BADDEV, msg)); |
|
789 | 937 |
|
938 |
case EOVERFLOW: |
|
939 |
/* |
|
2082 | 940 |
* This occurs when one of the devices is below |
789 | 941 |
* SPA_MINDEVSIZE. Unfortunately, we can't detect which |
942 |
* device was the problem device since there's no |
|
943 |
* reliable way to determine device size from userland. |
|
944 |
*/ |
|
945 |
{ |
|
946 |
char buf[64]; |
|
947 |
||
948 |
zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf)); |
|
949 |
||
2082 | 950 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
951 |
"one or more devices is less than the " |
|
952 |
"minimum size (%s)"), buf); |
|
789 | 953 |
} |
2082 | 954 |
return (zfs_error(hdl, EZFS_BADDEV, msg)); |
789 | 955 |
|
956 |
case ENOSPC: |
|
2082 | 957 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
958 |
"one or more devices is out of space")); |
|
959 |
return (zfs_error(hdl, EZFS_BADDEV, msg)); |
|
789 | 960 |
|
5450 | 961 |
case ENOTBLK: |
962 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
963 |
"cache device must be a disk or disk slice")); |
|
964 |
return (zfs_error(hdl, EZFS_BADDEV, msg)); |
|
965 |
||
789 | 966 |
default: |
2082 | 967 |
return (zpool_standard_error(hdl, errno, msg)); |
789 | 968 |
} |
969 |
} |
|
970 |
||
971 |
/* |
|
972 |
* If this is an alternate root pool, then we automatically set the |
|
2676 | 973 |
* mountpoint of the root dataset to be '/'. |
789 | 974 |
*/ |
5094 | 975 |
if (nvlist_lookup_string(props, zpool_prop_to_name(ZPOOL_PROP_ALTROOT), |
976 |
&altroot) == 0) { |
|
789 | 977 |
zfs_handle_t *zhp; |
978 |
||
5094 | 979 |
verify((zhp = zfs_open(hdl, pool, ZFS_TYPE_DATASET)) != NULL); |
2676 | 980 |
verify(zfs_prop_set(zhp, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT), |
981 |
"/") == 0); |
|
789 | 982 |
|
983 |
zfs_close(zhp); |
|
984 |
} |
|
985 |
||
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
986 |
create_failed: |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
987 |
zcmd_free_nvlists(&zc); |
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
988 |
nvlist_free(zc_props); |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
989 |
nvlist_free(zc_fsprops); |
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
990 |
return (ret); |
789 | 991 |
} |
992 |
||
993 |
/* |
|
994 |
* Destroy the given pool. It is up to the caller to ensure that there are no |
|
995 |
* datasets left in the pool. |
|
996 |
*/ |
|
997 |
int |
|
998 |
zpool_destroy(zpool_handle_t *zhp) |
|
999 |
{ |
|
1000 |
zfs_cmd_t zc = { 0 }; |
|
1001 |
zfs_handle_t *zfp = NULL; |
|
2082 | 1002 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
1003 |
char msg[1024]; |
|
789 | 1004 |
|
1005 |
if (zhp->zpool_state == POOL_STATE_ACTIVE && |
|
2082 | 1006 |
(zfp = zfs_open(zhp->zpool_hdl, zhp->zpool_name, |
1007 |
ZFS_TYPE_FILESYSTEM)) == NULL) |
|
789 | 1008 |
return (-1); |
1009 |
||
1010 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
1011 |
||
4543 | 1012 |
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_DESTROY, &zc) != 0) { |
2082 | 1013 |
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, |
1014 |
"cannot destroy '%s'"), zhp->zpool_name); |
|
789 | 1015 |
|
2082 | 1016 |
if (errno == EROFS) { |
1017 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
1018 |
"one or more devices is read only")); |
|
1019 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
|
1020 |
} else { |
|
1021 |
(void) zpool_standard_error(hdl, errno, msg); |
|
789 | 1022 |
} |
1023 |
||
1024 |
if (zfp) |
|
1025 |
zfs_close(zfp); |
|
1026 |
return (-1); |
|
1027 |
} |
|
1028 |
||
1029 |
if (zfp) { |
|
1030 |
remove_mountpoint(zfp); |
|
1031 |
zfs_close(zfp); |
|
1032 |
} |
|
1033 |
||
1034 |
return (0); |
|
1035 |
} |
|
1036 |
||
1037 |
/* |
|
1038 |
* Add the given vdevs to the pool. The caller must have already performed the |
|
1039 |
* necessary verification to ensure that the vdev specification is well-formed. |
|
1040 |
*/ |
|
1041 |
int |
|
1042 |
zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot) |
|
1043 |
{ |
|
2676 | 1044 |
zfs_cmd_t zc = { 0 }; |
2082 | 1045 |
int ret; |
1046 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
1047 |
char msg[1024]; |
|
5450 | 1048 |
nvlist_t **spares, **l2cache; |
1049 |
uint_t nspares, nl2cache; |
|
2082 | 1050 |
|
1051 |
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, |
|
1052 |
"cannot add to '%s'"), zhp->zpool_name); |
|
1053 |
||
5450 | 1054 |
if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) < |
1055 |
SPA_VERSION_SPARES && |
|
2082 | 1056 |
nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, |
1057 |
&spares, &nspares) == 0) { |
|
1058 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be " |
|
1059 |
"upgraded to add hot spares")); |
|
1060 |
return (zfs_error(hdl, EZFS_BADVERSION, msg)); |
|
1061 |
} |
|
789 | 1062 |
|
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1063 |
if (pool_is_bootable(zhp) && nvlist_lookup_nvlist_array(nvroot, |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1064 |
ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1065 |
uint64_t s; |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1066 |
|
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1067 |
for (s = 0; s < nspares; s++) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1068 |
char *path; |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1069 |
|
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1070 |
if (nvlist_lookup_string(spares[s], ZPOOL_CONFIG_PATH, |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1071 |
&path) == 0 && pool_uses_efi(spares[s])) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1072 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1073 |
"device '%s' contains an EFI label and " |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1074 |
"cannot be used on root pools."), |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1075 |
zpool_vdev_name(hdl, NULL, spares[s], |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1076 |
B_FALSE)); |
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1077 |
return (zfs_error(hdl, EZFS_POOL_NOTSUP, msg)); |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1078 |
} |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1079 |
} |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1080 |
} |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
1081 |
|
5450 | 1082 |
if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) < |
1083 |
SPA_VERSION_L2CACHE && |
|
1084 |
nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, |
|
1085 |
&l2cache, &nl2cache) == 0) { |
|
1086 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be " |
|
1087 |
"upgraded to add cache devices")); |
|
1088 |
return (zfs_error(hdl, EZFS_BADVERSION, msg)); |
|
1089 |
} |
|
1090 |
||
5094 | 1091 |
if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0) |
2082 | 1092 |
return (-1); |
789 | 1093 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
1094 |
||
4543 | 1095 |
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_ADD, &zc) != 0) { |
789 | 1096 |
switch (errno) { |
1097 |
case EBUSY: |
|
1098 |
/* |
|
1099 |
* This can happen if the user has specified the same |
|
1100 |
* device multiple times. We can't reliably detect this |
|
1101 |
* until we try to add it and see we already have a |
|
1102 |
* label. |
|
1103 |
*/ |
|
2082 | 1104 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1105 |
"one or more vdevs refer to the same device")); |
|
1106 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
|
789 | 1107 |
break; |
1108 |
||
1109 |
case EOVERFLOW: |
|
1110 |
/* |
|
1111 |
* This occurrs when one of the devices is below |
|
1112 |
* SPA_MINDEVSIZE. Unfortunately, we can't detect which |
|
1113 |
* device was the problem device since there's no |
|
1114 |
* reliable way to determine device size from userland. |
|
1115 |
*/ |
|
1116 |
{ |
|
1117 |
char buf[64]; |
|
1118 |
||
1119 |
zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf)); |
|
1120 |
||
2082 | 1121 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1122 |
"device is less than the minimum " |
|
1123 |
"size (%s)"), buf); |
|
789 | 1124 |
} |
2082 | 1125 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
1126 |
break; |
|
1127 |
||
1128 |
case ENOTSUP: |
|
1129 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
4527 | 1130 |
"pool must be upgraded to add these vdevs")); |
2082 | 1131 |
(void) zfs_error(hdl, EZFS_BADVERSION, msg); |
789 | 1132 |
break; |
1133 |
||
3912 | 1134 |
case EDOM: |
1135 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
4527 | 1136 |
"root pool can not have multiple vdevs" |
1137 |
" or separate logs")); |
|
3912 | 1138 |
(void) zfs_error(hdl, EZFS_POOL_NOTSUP, msg); |
1139 |
break; |
|
1140 |
||
5450 | 1141 |
case ENOTBLK: |
1142 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
1143 |
"cache device must be a disk or disk slice")); |
|
1144 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
|
1145 |
break; |
|
1146 |
||
789 | 1147 |
default: |
2082 | 1148 |
(void) zpool_standard_error(hdl, errno, msg); |
789 | 1149 |
} |
1150 |
||
2082 | 1151 |
ret = -1; |
1152 |
} else { |
|
1153 |
ret = 0; |
|
789 | 1154 |
} |
1155 |
||
2676 | 1156 |
zcmd_free_nvlists(&zc); |
789 | 1157 |
|
2082 | 1158 |
return (ret); |
789 | 1159 |
} |
1160 |
||
1161 |
/* |
|
1162 |
* Exports the pool from the system. The caller must ensure that there are no |
|
1163 |
* mounted datasets in the pool. |
|
1164 |
*/ |
|
1165 |
int |
|
8211
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1166 |
zpool_export_common(zpool_handle_t *zhp, boolean_t force, boolean_t hardforce) |
789 | 1167 |
{ |
1168 |
zfs_cmd_t zc = { 0 }; |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1169 |
char msg[1024]; |
789 | 1170 |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1171 |
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1172 |
"cannot export '%s'"), zhp->zpool_name); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1173 |
|
789 | 1174 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1175 |
zc.zc_cookie = force; |
8211
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1176 |
zc.zc_guid = hardforce; |
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1177 |
|
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1178 |
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_EXPORT, &zc) != 0) { |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1179 |
switch (errno) { |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1180 |
case EXDEV: |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1181 |
zfs_error_aux(zhp->zpool_hdl, dgettext(TEXT_DOMAIN, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1182 |
"use '-f' to override the following errors:\n" |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1183 |
"'%s' has an active shared spare which could be" |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1184 |
" used by other pools once '%s' is exported."), |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1185 |
zhp->zpool_name, zhp->zpool_name); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1186 |
return (zfs_error(zhp->zpool_hdl, EZFS_ACTIVE_SPARE, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1187 |
msg)); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1188 |
default: |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1189 |
return (zpool_standard_error_fmt(zhp->zpool_hdl, errno, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1190 |
msg)); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1191 |
} |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1192 |
} |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1193 |
|
789 | 1194 |
return (0); |
1195 |
} |
|
1196 |
||
8211
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1197 |
int |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1198 |
zpool_export(zpool_handle_t *zhp, boolean_t force) |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1199 |
{ |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1200 |
return (zpool_export_common(zhp, force, B_FALSE)); |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1201 |
} |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1202 |
|
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1203 |
int |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1204 |
zpool_export_force(zpool_handle_t *zhp) |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1205 |
{ |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1206 |
return (zpool_export_common(zhp, B_TRUE, B_TRUE)); |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1207 |
} |
32722be6ad3b
6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents:
8084
diff
changeset
|
1208 |
|
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1209 |
static void |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1210 |
zpool_rewind_exclaim(libzfs_handle_t *hdl, const char *name, boolean_t dryrun, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1211 |
nvlist_t *rbi) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1212 |
{ |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1213 |
uint64_t rewindto; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1214 |
int64_t loss = -1; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1215 |
struct tm t; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1216 |
char timestr[128]; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1217 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1218 |
if (!hdl->libzfs_printerr || rbi == NULL) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1219 |
return; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1220 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1221 |
if (nvlist_lookup_uint64(rbi, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1222 |
return; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1223 |
(void) nvlist_lookup_int64(rbi, ZPOOL_CONFIG_REWIND_TIME, &loss); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1224 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1225 |
if (localtime_r((time_t *)&rewindto, &t) != NULL && |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1226 |
strftime(timestr, 128, 0, &t) != 0) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1227 |
if (dryrun) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1228 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1229 |
"Would be able to return %s " |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1230 |
"to its state as of %s.\n"), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1231 |
name, timestr); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1232 |
} else { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1233 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1234 |
"Pool %s returned to its state as of %s.\n"), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1235 |
name, timestr); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1236 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1237 |
if (loss > 120) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1238 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1239 |
"%s approximately %lld "), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1240 |
dryrun ? "Would discard" : "Discarded", |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1241 |
(loss + 30) / 60); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1242 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1243 |
"minutes of transactions.\n")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1244 |
} else if (loss > 0) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1245 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1246 |
"%s approximately %lld "), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1247 |
dryrun ? "Would discard" : "Discarded", loss); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1248 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1249 |
"seconds of transactions.\n")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1250 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1251 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1252 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1253 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1254 |
void |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1255 |
zpool_explain_recover(libzfs_handle_t *hdl, const char *name, int reason, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1256 |
nvlist_t *config) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1257 |
{ |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1258 |
int64_t loss = -1; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1259 |
uint64_t edata = UINT64_MAX; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1260 |
uint64_t rewindto; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1261 |
struct tm t; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1262 |
char timestr[128]; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1263 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1264 |
if (!hdl->libzfs_printerr) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1265 |
return; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1266 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1267 |
if (reason >= 0) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1268 |
(void) printf(dgettext(TEXT_DOMAIN, "action: ")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1269 |
else |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1270 |
(void) printf(dgettext(TEXT_DOMAIN, "\t")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1271 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1272 |
/* All attempted rewinds failed if ZPOOL_CONFIG_LOAD_TIME missing */ |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1273 |
if (nvlist_lookup_uint64(config, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1274 |
ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1275 |
goto no_info; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1276 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1277 |
(void) nvlist_lookup_int64(config, ZPOOL_CONFIG_REWIND_TIME, &loss); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1278 |
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_LOAD_DATA_ERRORS, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1279 |
&edata); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1280 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1281 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1282 |
"Recovery is possible, but will result in some data loss.\n")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1283 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1284 |
if (localtime_r((time_t *)&rewindto, &t) != NULL && |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1285 |
strftime(timestr, 128, 0, &t) != 0) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1286 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1287 |
"\tReturning the pool to its state as of %s\n" |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1288 |
"\tshould correct the problem. "), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1289 |
timestr); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1290 |
} else { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1291 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1292 |
"\tReverting the pool to an earlier state " |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1293 |
"should correct the problem.\n\t")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1294 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1295 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1296 |
if (loss > 120) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1297 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1298 |
"Approximately %lld minutes of data\n" |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1299 |
"\tmust be discarded, irreversibly. "), (loss + 30) / 60); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1300 |
} else if (loss > 0) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1301 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1302 |
"Approximately %lld seconds of data\n" |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1303 |
"\tmust be discarded, irreversibly. "), loss); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1304 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1305 |
if (edata != 0 && edata != UINT64_MAX) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1306 |
if (edata == 1) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1307 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1308 |
"After rewind, at least\n" |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1309 |
"\tone persistent user-data error will remain. ")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1310 |
} else { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1311 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1312 |
"After rewind, several\n" |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1313 |
"\tpersistent user-data errors will remain. ")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1314 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1315 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1316 |
(void) printf(dgettext(TEXT_DOMAIN, |
11026
e8e10df16a8f
6899159 injection isn't trashing pools
Tim Haley <Tim.Haley@Sun.COM>
parents:
10956
diff
changeset
|
1317 |
"Recovery can be attempted\n\tby executing 'zpool %s -F %s'. "), |
e8e10df16a8f
6899159 injection isn't trashing pools
Tim Haley <Tim.Haley@Sun.COM>
parents:
10956
diff
changeset
|
1318 |
reason >= 0 ? "clear" : "import", name); |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1319 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1320 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1321 |
"A scrub of the pool\n" |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1322 |
"\tis strongly recommended after recovery.\n")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1323 |
return; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1324 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1325 |
no_info: |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1326 |
(void) printf(dgettext(TEXT_DOMAIN, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1327 |
"Destroy and re-create the pool from\n\ta backup source.\n")); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1328 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1329 |
|
789 | 1330 |
/* |
5094 | 1331 |
* zpool_import() is a contracted interface. Should be kept the same |
1332 |
* if possible. |
|
1333 |
* |
|
1334 |
* Applications should use zpool_import_props() to import a pool with |
|
1335 |
* new properties value to be set. |
|
789 | 1336 |
*/ |
1337 |
int |
|
2082 | 1338 |
zpool_import(libzfs_handle_t *hdl, nvlist_t *config, const char *newname, |
5094 | 1339 |
char *altroot) |
1340 |
{ |
|
1341 |
nvlist_t *props = NULL; |
|
1342 |
int ret; |
|
1343 |
||
1344 |
if (altroot != NULL) { |
|
1345 |
if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { |
|
1346 |
return (zfs_error_fmt(hdl, EZFS_NOMEM, |
|
1347 |
dgettext(TEXT_DOMAIN, "cannot import '%s'"), |
|
1348 |
newname)); |
|
1349 |
} |
|
1350 |
||
1351 |
if (nvlist_add_string(props, |
|
8084
b811cc60d650
6769612 zpool_import() will continue to write to cachefile even if altroot is set
George Wilson <George.Wilson@Sun.COM>
parents:
7965
diff
changeset
|
1352 |
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), altroot) != 0 || |
b811cc60d650
6769612 zpool_import() will continue to write to cachefile even if altroot is set
George Wilson <George.Wilson@Sun.COM>
parents:
7965
diff
changeset
|
1353 |
nvlist_add_string(props, |
b811cc60d650
6769612 zpool_import() will continue to write to cachefile even if altroot is set
George Wilson <George.Wilson@Sun.COM>
parents:
7965
diff
changeset
|
1354 |
zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), "none") != 0) { |
5094 | 1355 |
nvlist_free(props); |
1356 |
return (zfs_error_fmt(hdl, EZFS_NOMEM, |
|
1357 |
dgettext(TEXT_DOMAIN, "cannot import '%s'"), |
|
1358 |
newname)); |
|
1359 |
} |
|
1360 |
} |
|
1361 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6423
diff
changeset
|
1362 |
ret = zpool_import_props(hdl, config, newname, props, B_FALSE); |
5094 | 1363 |
if (props) |
1364 |
nvlist_free(props); |
|
1365 |
return (ret); |
|
1366 |
} |
|
1367 |
||
1368 |
/* |
|
1369 |
* Import the given pool using the known configuration and a list of |
|
1370 |
* properties to be set. The configuration should have come from |
|
1371 |
* zpool_find_import(). The 'newname' parameters control whether the pool |
|
1372 |
* is imported with a different name. |
|
1373 |
*/ |
|
1374 |
int |
|
1375 |
zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname, |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6423
diff
changeset
|
1376 |
nvlist_t *props, boolean_t importfaulted) |
789 | 1377 |
{ |
2676 | 1378 |
zfs_cmd_t zc = { 0 }; |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1379 |
zpool_rewind_policy_t policy; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1380 |
nvlist_t *nvi = NULL; |
789 | 1381 |
char *thename; |
1382 |
char *origname; |
|
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1383 |
uint64_t returned_size; |
789 | 1384 |
int ret; |
5094 | 1385 |
char errbuf[1024]; |
789 | 1386 |
|
1387 |
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, |
|
1388 |
&origname) == 0); |
|
1389 |
||
5094 | 1390 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
1391 |
"cannot import pool '%s'"), origname); |
|
1392 |
||
789 | 1393 |
if (newname != NULL) { |
2082 | 1394 |
if (!zpool_name_valid(hdl, B_FALSE, newname)) |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
1395 |
return (zfs_error_fmt(hdl, EZFS_INVALIDNAME, |
2082 | 1396 |
dgettext(TEXT_DOMAIN, "cannot import '%s'"), |
1397 |
newname)); |
|
789 | 1398 |
thename = (char *)newname; |
1399 |
} else { |
|
1400 |
thename = origname; |
|
1401 |
} |
|
1402 |
||
5094 | 1403 |
if (props) { |
1404 |
uint64_t version; |
|
1405 |
||
1406 |
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, |
|
1407 |
&version) == 0); |
|
1408 |
||
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7042
diff
changeset
|
1409 |
if ((props = zpool_valid_proplist(hdl, origname, |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1410 |
props, version, B_TRUE, errbuf)) == NULL) { |
5094 | 1411 |
return (-1); |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1412 |
} else if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) { |
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1413 |
nvlist_free(props); |
5094 | 1414 |
return (-1); |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1415 |
} |
5094 | 1416 |
} |
789 | 1417 |
|
1418 |
(void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name)); |
|
1419 |
||
1420 |
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, |
|
1544 | 1421 |
&zc.zc_guid) == 0); |
789 | 1422 |
|
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1423 |
if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) { |
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1424 |
nvlist_free(props); |
2082 | 1425 |
return (-1); |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1426 |
} |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1427 |
returned_size = zc.zc_nvlist_conf_size + 512; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1428 |
if (zcmd_alloc_dst_nvlist(hdl, &zc, returned_size) != 0) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1429 |
nvlist_free(props); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1430 |
return (-1); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1431 |
} |
789 | 1432 |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6423
diff
changeset
|
1433 |
zc.zc_cookie = (uint64_t)importfaulted; |
789 | 1434 |
ret = 0; |
4543 | 1435 |
if (zfs_ioctl(hdl, ZFS_IOC_POOL_IMPORT, &zc) != 0) { |
789 | 1436 |
char desc[1024]; |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1437 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1438 |
(void) zcmd_read_dst_nvlist(hdl, &zc, &nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1439 |
zpool_get_rewind_policy(config, &policy); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1440 |
/* |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1441 |
* Dry-run failed, but we print out what success |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1442 |
* looks like if we found a best txg |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1443 |
*/ |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1444 |
if ((policy.zrp_request & ZPOOL_TRY_REWIND) && nvi) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1445 |
zpool_rewind_exclaim(hdl, newname ? origname : thename, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1446 |
B_TRUE, nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1447 |
nvlist_free(nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1448 |
return (-1); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1449 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1450 |
|
789 | 1451 |
if (newname == NULL) |
1452 |
(void) snprintf(desc, sizeof (desc), |
|
1453 |
dgettext(TEXT_DOMAIN, "cannot import '%s'"), |
|
1454 |
thename); |
|
1455 |
else |
|
1456 |
(void) snprintf(desc, sizeof (desc), |
|
1457 |
dgettext(TEXT_DOMAIN, "cannot import '%s' as '%s'"), |
|
1458 |
origname, thename); |
|
1459 |
||
1460 |
switch (errno) { |
|
1544 | 1461 |
case ENOTSUP: |
1462 |
/* |
|
1463 |
* Unsupported version. |
|
1464 |
*/ |
|
2082 | 1465 |
(void) zfs_error(hdl, EZFS_BADVERSION, desc); |
1544 | 1466 |
break; |
1467 |
||
2174
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2142
diff
changeset
|
1468 |
case EINVAL: |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2142
diff
changeset
|
1469 |
(void) zfs_error(hdl, EZFS_INVALCONFIG, desc); |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2142
diff
changeset
|
1470 |
break; |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2142
diff
changeset
|
1471 |
|
11814
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11422
diff
changeset
|
1472 |
case EROFS: |
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11422
diff
changeset
|
1473 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11422
diff
changeset
|
1474 |
"one or more devices is read only")); |
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11422
diff
changeset
|
1475 |
(void) zfs_error(hdl, EZFS_BADDEV, desc); |
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11422
diff
changeset
|
1476 |
break; |
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11422
diff
changeset
|
1477 |
|
789 | 1478 |
default: |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1479 |
(void) zcmd_read_dst_nvlist(hdl, &zc, &nvi); |
2082 | 1480 |
(void) zpool_standard_error(hdl, errno, desc); |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1481 |
zpool_explain_recover(hdl, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1482 |
newname ? origname : thename, -errno, nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1483 |
nvlist_free(nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1484 |
break; |
789 | 1485 |
} |
1486 |
||
1487 |
ret = -1; |
|
1488 |
} else { |
|
1489 |
zpool_handle_t *zhp; |
|
4543 | 1490 |
|
789 | 1491 |
/* |
1492 |
* This should never fail, but play it safe anyway. |
|
1493 |
*/ |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9816
diff
changeset
|
1494 |
if (zpool_open_silent(hdl, thename, &zhp) != 0) |
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
1495 |
ret = -1; |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9816
diff
changeset
|
1496 |
else if (zhp != NULL) |
789 | 1497 |
zpool_close(zhp); |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1498 |
(void) zcmd_read_dst_nvlist(hdl, &zc, &nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1499 |
zpool_get_rewind_policy(config, &policy); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1500 |
if (policy.zrp_request & |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1501 |
(ZPOOL_DO_REWIND | ZPOOL_TRY_REWIND)) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1502 |
zpool_rewind_exclaim(hdl, newname ? origname : thename, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1503 |
((policy.zrp_request & ZPOOL_TRY_REWIND) != 0), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1504 |
nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1505 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1506 |
nvlist_free(nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
1507 |
return (0); |
789 | 1508 |
} |
1509 |
||
2676 | 1510 |
zcmd_free_nvlists(&zc); |
5320
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1511 |
nvlist_free(props); |
43bde2b01a59
6614232 results of zpool_validate_properties() are consistently leaked
lling
parents:
5094
diff
changeset
|
1512 |
|
789 | 1513 |
return (ret); |
1514 |
} |
|
1515 |
||
1516 |
/* |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1517 |
* Scan the pool. |
789 | 1518 |
*/ |
1519 |
int |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1520 |
zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func) |
789 | 1521 |
{ |
1522 |
zfs_cmd_t zc = { 0 }; |
|
1523 |
char msg[1024]; |
|
2082 | 1524 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
789 | 1525 |
|
1526 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1527 |
zc.zc_cookie = func; |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1528 |
|
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1529 |
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_SCAN, &zc) == 0 || |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1530 |
(errno == ENOENT && func != POOL_SCAN_NONE)) |
789 | 1531 |
return (0); |
1532 |
||
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1533 |
if (func == POOL_SCAN_SCRUB) { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1534 |
(void) snprintf(msg, sizeof (msg), |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1535 |
dgettext(TEXT_DOMAIN, "cannot scrub %s"), zc.zc_name); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1536 |
} else if (func == POOL_SCAN_NONE) { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1537 |
(void) snprintf(msg, sizeof (msg), |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1538 |
dgettext(TEXT_DOMAIN, "cannot cancel scrubbing %s"), |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1539 |
zc.zc_name); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1540 |
} else { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1541 |
assert(!"unexpected result"); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1542 |
} |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1543 |
|
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1544 |
if (errno == EBUSY) { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1545 |
nvlist_t *nvroot; |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1546 |
pool_scan_stat_t *ps = NULL; |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1547 |
uint_t psc; |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1548 |
|
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1549 |
verify(nvlist_lookup_nvlist(zhp->zpool_config, |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1550 |
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1551 |
(void) nvlist_lookup_uint64_array(nvroot, |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1552 |
ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &psc); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1553 |
if (ps && ps->pss_func == POOL_SCAN_SCRUB) |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1554 |
return (zfs_error(hdl, EZFS_SCRUBBING, msg)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1555 |
else |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1556 |
return (zfs_error(hdl, EZFS_RESILVERING, msg)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1557 |
} else if (errno == ENOENT) { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1558 |
return (zfs_error(hdl, EZFS_NO_SCRUB, msg)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1559 |
} else { |
2082 | 1560 |
return (zpool_standard_error(hdl, errno, msg)); |
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
1561 |
} |
789 | 1562 |
} |
1563 |
||
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1564 |
/* |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1565 |
* Find a vdev that matches the search criteria specified. We use the |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1566 |
* the nvpair name to determine how we should look for the device. |
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1567 |
* 'avail_spare' is set to TRUE if the provided guid refers to an AVAIL |
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1568 |
* spare; but FALSE if its an INUSE spare. |
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1569 |
*/ |
2082 | 1570 |
static nvlist_t * |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1571 |
vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1572 |
boolean_t *l2cache, boolean_t *log) |
1544 | 1573 |
{ |
1574 |
uint_t c, children; |
|
1575 |
nvlist_t **child; |
|
2082 | 1576 |
nvlist_t *ret; |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1577 |
uint64_t is_log; |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1578 |
char *srchkey; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1579 |
nvpair_t *pair = nvlist_next_nvpair(search, NULL); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1580 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1581 |
/* Nothing to look for */ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1582 |
if (search == NULL || pair == NULL) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1583 |
return (NULL); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1584 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1585 |
/* Obtain the key we will use to search */ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1586 |
srchkey = nvpair_name(pair); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1587 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1588 |
switch (nvpair_type(pair)) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1589 |
case DATA_TYPE_UINT64: { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1590 |
uint64_t srchval, theguid, present; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1591 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1592 |
verify(nvpair_value_uint64(pair, &srchval) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1593 |
if (strcmp(srchkey, ZPOOL_CONFIG_GUID) == 0) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1594 |
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1595 |
&present) == 0) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1596 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1597 |
* If the device has never been present since |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1598 |
* import, the only reliable way to match the |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1599 |
* vdev is by GUID. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1600 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1601 |
verify(nvlist_lookup_uint64(nv, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1602 |
ZPOOL_CONFIG_GUID, &theguid) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1603 |
if (theguid == srchval) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1604 |
return (nv); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1605 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1606 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1607 |
break; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1608 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1609 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1610 |
case DATA_TYPE_STRING: { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1611 |
char *srchval, *val; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1612 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1613 |
verify(nvpair_value_string(pair, &srchval) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1614 |
if (nvlist_lookup_string(nv, srchkey, &val) != 0) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1615 |
break; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1616 |
|
1544 | 1617 |
/* |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1618 |
* Search for the requested value. We special case the search |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1619 |
* for ZPOOL_CONFIG_PATH when it's a wholedisk and when |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1620 |
* Looking for a top-level vdev name (i.e. ZPOOL_CONFIG_TYPE). |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1621 |
* Otherwise, all other searches are simple string compares. |
1544 | 1622 |
*/ |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1623 |
if (strcmp(srchkey, ZPOOL_CONFIG_PATH) == 0 && val) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1624 |
uint64_t wholedisk = 0; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1625 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1626 |
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1627 |
&wholedisk); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1628 |
if (wholedisk) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1629 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1630 |
* For whole disks, the internal path has 's0', |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1631 |
* but the path passed in by the user doesn't. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1632 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1633 |
if (strlen(srchval) == strlen(val) - 2 && |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1634 |
strncmp(srchval, val, strlen(srchval)) == 0) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1635 |
return (nv); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1636 |
break; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1637 |
} |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1638 |
} else if (strcmp(srchkey, ZPOOL_CONFIG_TYPE) == 0 && val) { |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1639 |
char *type, *idx, *end, *p; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1640 |
uint64_t id, vdev_id; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1641 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1642 |
/* |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1643 |
* Determine our vdev type, keeping in mind |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1644 |
* that the srchval is composed of a type and |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1645 |
* vdev id pair (i.e. mirror-4). |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1646 |
*/ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1647 |
if ((type = strdup(srchval)) == NULL) |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1648 |
return (NULL); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1649 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1650 |
if ((p = strrchr(type, '-')) == NULL) { |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1651 |
free(type); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1652 |
break; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1653 |
} |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1654 |
idx = p + 1; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1655 |
*p = '\0'; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1656 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1657 |
/* |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1658 |
* If the types don't match then keep looking. |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1659 |
*/ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1660 |
if (strncmp(val, type, strlen(val)) != 0) { |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1661 |
free(type); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1662 |
break; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1663 |
} |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1664 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1665 |
verify(strncmp(type, VDEV_TYPE_RAIDZ, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1666 |
strlen(VDEV_TYPE_RAIDZ)) == 0 || |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1667 |
strncmp(type, VDEV_TYPE_MIRROR, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1668 |
strlen(VDEV_TYPE_MIRROR)) == 0); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1669 |
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1670 |
&id) == 0); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1671 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1672 |
errno = 0; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1673 |
vdev_id = strtoull(idx, &end, 10); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1674 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1675 |
free(type); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1676 |
if (errno != 0) |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1677 |
return (NULL); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1678 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1679 |
/* |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1680 |
* Now verify that we have the correct vdev id. |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1681 |
*/ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1682 |
if (vdev_id == id) |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1683 |
return (nv); |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1684 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1685 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1686 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1687 |
* Common case |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1688 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1689 |
if (strcmp(srchval, val) == 0) |
2082 | 1690 |
return (nv); |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1691 |
break; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1692 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1693 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1694 |
default: |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1695 |
break; |
1544 | 1696 |
} |
1697 |
||
1698 |
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, |
|
1699 |
&child, &children) != 0) |
|
2082 | 1700 |
return (NULL); |
1544 | 1701 |
|
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1702 |
for (c = 0; c < children; c++) { |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1703 |
if ((ret = vdev_to_nvlist_iter(child[c], search, |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1704 |
avail_spare, l2cache, NULL)) != NULL) { |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1705 |
/* |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1706 |
* The 'is_log' value is only set for the toplevel |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1707 |
* vdev, not the leaf vdevs. So we always lookup the |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1708 |
* log device from the root of the vdev tree (where |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1709 |
* 'log' is non-NULL). |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1710 |
*/ |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1711 |
if (log != NULL && |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1712 |
nvlist_lookup_uint64(child[c], |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1713 |
ZPOOL_CONFIG_IS_LOG, &is_log) == 0 && |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1714 |
is_log) { |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1715 |
*log = B_TRUE; |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1716 |
} |
1544 | 1717 |
return (ret); |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1718 |
} |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1719 |
} |
1544 | 1720 |
|
2082 | 1721 |
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES, |
1722 |
&child, &children) == 0) { |
|
1723 |
for (c = 0; c < children; c++) { |
|
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1724 |
if ((ret = vdev_to_nvlist_iter(child[c], search, |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1725 |
avail_spare, l2cache, NULL)) != NULL) { |
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1726 |
*avail_spare = B_TRUE; |
2082 | 1727 |
return (ret); |
1728 |
} |
|
1729 |
} |
|
1730 |
} |
|
1731 |
||
5450 | 1732 |
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE, |
1733 |
&child, &children) == 0) { |
|
1734 |
for (c = 0; c < children; c++) { |
|
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1735 |
if ((ret = vdev_to_nvlist_iter(child[c], search, |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1736 |
avail_spare, l2cache, NULL)) != NULL) { |
5450 | 1737 |
*l2cache = B_TRUE; |
1738 |
return (ret); |
|
1739 |
} |
|
1740 |
} |
|
1741 |
} |
|
1742 |
||
2082 | 1743 |
return (NULL); |
1544 | 1744 |
} |
1745 |
||
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1746 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1747 |
* Given a physical path (minus the "/devices" prefix), find the |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1748 |
* associated vdev. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1749 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1750 |
nvlist_t * |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1751 |
zpool_find_vdev_by_physpath(zpool_handle_t *zhp, const char *ppath, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1752 |
boolean_t *avail_spare, boolean_t *l2cache, boolean_t *log) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1753 |
{ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1754 |
nvlist_t *search, *nvroot, *ret; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1755 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1756 |
verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1757 |
verify(nvlist_add_string(search, ZPOOL_CONFIG_PHYS_PATH, ppath) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1758 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1759 |
verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1760 |
&nvroot) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1761 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1762 |
*avail_spare = B_FALSE; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1763 |
ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1764 |
nvlist_free(search); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1765 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1766 |
return (ret); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1767 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1768 |
|
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1769 |
/* |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1770 |
* Determine if we have an "interior" top-level vdev (i.e mirror/raidz). |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1771 |
*/ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1772 |
boolean_t |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1773 |
zpool_vdev_is_interior(const char *name) |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1774 |
{ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1775 |
if (strncmp(name, VDEV_TYPE_RAIDZ, strlen(VDEV_TYPE_RAIDZ)) == 0 || |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1776 |
strncmp(name, VDEV_TYPE_MIRROR, strlen(VDEV_TYPE_MIRROR)) == 0) |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1777 |
return (B_TRUE); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1778 |
return (B_FALSE); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1779 |
} |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1780 |
|
2082 | 1781 |
nvlist_t * |
5450 | 1782 |
zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare, |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1783 |
boolean_t *l2cache, boolean_t *log) |
1544 | 1784 |
{ |
1785 |
char buf[MAXPATHLEN]; |
|
1786 |
char *end; |
|
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1787 |
nvlist_t *nvroot, *search, *ret; |
1544 | 1788 |
uint64_t guid; |
1789 |
||
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1790 |
verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1791 |
|
1613
aca102a242d3
6396628 zpool offline does not recognize c0d0 patten recently
eschrock
parents:
1544
diff
changeset
|
1792 |
guid = strtoull(path, &end, 10); |
1544 | 1793 |
if (guid != 0 && *end == '\0') { |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1794 |
verify(nvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid) == 0); |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1795 |
} else if (zpool_vdev_is_interior(path)) { |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
1796 |
verify(nvlist_add_string(search, ZPOOL_CONFIG_TYPE, path) == 0); |
1544 | 1797 |
} else if (path[0] != '/') { |
1798 |
(void) snprintf(buf, sizeof (buf), "%s%s", "/dev/dsk/", path); |
|
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1799 |
verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, buf) == 0); |
1544 | 1800 |
} else { |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1801 |
verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, path) == 0); |
1544 | 1802 |
} |
1803 |
||
1804 |
verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE, |
|
1805 |
&nvroot) == 0); |
|
1806 |
||
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1807 |
*avail_spare = B_FALSE; |
5450 | 1808 |
*l2cache = B_FALSE; |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1809 |
if (log != NULL) |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
1810 |
*log = B_FALSE; |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1811 |
ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1812 |
nvlist_free(search); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1813 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1814 |
return (ret); |
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1815 |
} |
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1816 |
|
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1817 |
static int |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1818 |
vdev_online(nvlist_t *nv) |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1819 |
{ |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1820 |
uint64_t ival; |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1821 |
|
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1822 |
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE, &ival) == 0 || |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1823 |
nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED, &ival) == 0 || |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1824 |
nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED, &ival) == 0) |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1825 |
return (0); |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1826 |
|
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1827 |
return (1); |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1828 |
} |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1829 |
|
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1830 |
/* |
9790
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1831 |
* Helper function for zpool_get_physpaths(). |
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1832 |
*/ |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1833 |
static int |
9790
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1834 |
vdev_get_one_physpath(nvlist_t *config, char *physpath, size_t physpath_size, |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1835 |
size_t *bytes_written) |
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1836 |
{ |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1837 |
size_t bytes_left, pos, rsz; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1838 |
char *tmppath; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1839 |
const char *format; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1840 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1841 |
if (nvlist_lookup_string(config, ZPOOL_CONFIG_PHYS_PATH, |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1842 |
&tmppath) != 0) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1843 |
return (EZFS_NODEVICE); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1844 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1845 |
pos = *bytes_written; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1846 |
bytes_left = physpath_size - pos; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1847 |
format = (pos == 0) ? "%s" : " %s"; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1848 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1849 |
rsz = snprintf(physpath + pos, bytes_left, format, tmppath); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1850 |
*bytes_written += rsz; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1851 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1852 |
if (rsz >= bytes_left) { |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1853 |
/* if physpath was not copied properly, clear it */ |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1854 |
if (bytes_left != 0) { |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1855 |
physpath[pos] = 0; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1856 |
} |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1857 |
return (EZFS_NOSPC); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1858 |
} |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1859 |
return (0); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1860 |
} |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1861 |
|
9790
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1862 |
static int |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1863 |
vdev_get_physpaths(nvlist_t *nv, char *physpath, size_t phypath_size, |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1864 |
size_t *rsz, boolean_t is_spare) |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1865 |
{ |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1866 |
char *type; |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1867 |
int ret; |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1868 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1869 |
if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0) |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1870 |
return (EZFS_INVALCONFIG); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1871 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1872 |
if (strcmp(type, VDEV_TYPE_DISK) == 0) { |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1873 |
/* |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1874 |
* An active spare device has ZPOOL_CONFIG_IS_SPARE set. |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1875 |
* For a spare vdev, we only want to boot from the active |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1876 |
* spare device. |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1877 |
*/ |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1878 |
if (is_spare) { |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1879 |
uint64_t spare = 0; |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1880 |
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE, |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1881 |
&spare); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1882 |
if (!spare) |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1883 |
return (EZFS_INVALCONFIG); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1884 |
} |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1885 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1886 |
if (vdev_online(nv)) { |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1887 |
if ((ret = vdev_get_one_physpath(nv, physpath, |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1888 |
phypath_size, rsz)) != 0) |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1889 |
return (ret); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1890 |
} |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1891 |
} else if (strcmp(type, VDEV_TYPE_MIRROR) == 0 || |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1892 |
strcmp(type, VDEV_TYPE_REPLACING) == 0 || |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1893 |
(is_spare = (strcmp(type, VDEV_TYPE_SPARE) == 0))) { |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1894 |
nvlist_t **child; |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1895 |
uint_t count; |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1896 |
int i, ret; |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1897 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1898 |
if (nvlist_lookup_nvlist_array(nv, |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1899 |
ZPOOL_CONFIG_CHILDREN, &child, &count) != 0) |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1900 |
return (EZFS_INVALCONFIG); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1901 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1902 |
for (i = 0; i < count; i++) { |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1903 |
ret = vdev_get_physpaths(child[i], physpath, |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1904 |
phypath_size, rsz, is_spare); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1905 |
if (ret == EZFS_NOSPC) |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1906 |
return (ret); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1907 |
} |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1908 |
} |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1909 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1910 |
return (EZFS_POOL_INVALARG); |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1911 |
} |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1912 |
|
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1913 |
/* |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1914 |
* Get phys_path for a root pool config. |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1915 |
* Return 0 on success; non-zero on failure. |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1916 |
*/ |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1917 |
static int |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1918 |
zpool_get_config_physpath(nvlist_t *config, char *physpath, size_t phypath_size) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1919 |
{ |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1920 |
size_t rsz; |
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1921 |
nvlist_t *vdev_root; |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1922 |
nvlist_t **child; |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1923 |
uint_t count; |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1924 |
char *type; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1925 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1926 |
rsz = 0; |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1927 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1928 |
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1929 |
&vdev_root) != 0) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1930 |
return (EZFS_INVALCONFIG); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1931 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1932 |
if (nvlist_lookup_string(vdev_root, ZPOOL_CONFIG_TYPE, &type) != 0 || |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1933 |
nvlist_lookup_nvlist_array(vdev_root, ZPOOL_CONFIG_CHILDREN, |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1934 |
&child, &count) != 0) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1935 |
return (EZFS_INVALCONFIG); |
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1936 |
|
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1937 |
/* |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1938 |
* root pool can not have EFI labeled disks and can only have |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1939 |
* a single top-level vdev. |
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1940 |
*/ |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1941 |
if (strcmp(type, VDEV_TYPE_ROOT) != 0 || count != 1 || |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1942 |
pool_uses_efi(vdev_root)) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1943 |
return (EZFS_POOL_INVALARG); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1944 |
|
9790
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1945 |
(void) vdev_get_physpaths(child[0], physpath, phypath_size, &rsz, |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
1946 |
B_FALSE); |
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1947 |
|
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1948 |
/* No online devices */ |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1949 |
if (rsz == 0) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1950 |
return (EZFS_NODEVICE); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1951 |
|
7656
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1952 |
return (0); |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1953 |
} |
2621e50fdf4a
PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
7326
diff
changeset
|
1954 |
|
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
1955 |
/* |
9160
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1956 |
* Get phys_path for a root pool |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1957 |
* Return 0 on success; non-zero on failure. |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1958 |
*/ |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1959 |
int |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1960 |
zpool_get_physpath(zpool_handle_t *zhp, char *physpath, size_t phypath_size) |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1961 |
{ |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1962 |
return (zpool_get_config_physpath(zhp->zpool_config, physpath, |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1963 |
phypath_size)); |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1964 |
} |
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1965 |
|
1517e6edbc6f
PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents:
8525
diff
changeset
|
1966 |
/* |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1967 |
* If the device has being dynamically expanded then we need to relabel |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1968 |
* the disk to use the new unallocated space. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1969 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1970 |
static int |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1971 |
zpool_relabel_disk(libzfs_handle_t *hdl, const char *name) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1972 |
{ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1973 |
char path[MAXPATHLEN]; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1974 |
char errbuf[1024]; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1975 |
int fd, error; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1976 |
int (*_efi_use_whole_disk)(int); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1977 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1978 |
if ((_efi_use_whole_disk = (int (*)(int))dlsym(RTLD_DEFAULT, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1979 |
"efi_use_whole_disk")) == NULL) |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1980 |
return (-1); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1981 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1982 |
(void) snprintf(path, sizeof (path), "%s/%s", RDISK_ROOT, name); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1983 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1984 |
if ((fd = open(path, O_RDWR | O_NDELAY)) < 0) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1985 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot " |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1986 |
"relabel '%s': unable to open device"), name); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1987 |
return (zfs_error(hdl, EZFS_OPENFAILED, errbuf)); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1988 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1989 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1990 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1991 |
* It's possible that we might encounter an error if the device |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1992 |
* does not have any unallocated space left. If so, we simply |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1993 |
* ignore that error and continue on. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1994 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1995 |
error = _efi_use_whole_disk(fd); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1996 |
(void) close(fd); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1997 |
if (error && error != VT_ENOSPC) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1998 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot " |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
1999 |
"relabel '%s': unable to read disk capacity"), name); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2000 |
return (zfs_error(hdl, EZFS_NOCAP, errbuf)); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2001 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2002 |
return (0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2003 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2004 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2005 |
/* |
4451 | 2006 |
* Bring the specified vdev online. The 'flags' parameter is a set of the |
2007 |
* ZFS_ONLINE_* flags. |
|
789 | 2008 |
*/ |
2009 |
int |
|
4451 | 2010 |
zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags, |
2011 |
vdev_state_t *newstate) |
|
789 | 2012 |
{ |
2013 |
zfs_cmd_t zc = { 0 }; |
|
2014 |
char msg[1024]; |
|
2082 | 2015 |
nvlist_t *tgt; |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2016 |
boolean_t avail_spare, l2cache, islog; |
2082 | 2017 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
789 | 2018 |
|
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2019 |
if (flags & ZFS_ONLINE_EXPAND) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2020 |
(void) snprintf(msg, sizeof (msg), |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2021 |
dgettext(TEXT_DOMAIN, "cannot expand %s"), path); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2022 |
} else { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2023 |
(void) snprintf(msg, sizeof (msg), |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2024 |
dgettext(TEXT_DOMAIN, "cannot online %s"), path); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2025 |
} |
789 | 2026 |
|
1544 | 2027 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2028 |
if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache, |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2029 |
&islog)) == NULL) |
2082 | 2030 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
789 | 2031 |
|
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2032 |
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); |
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2033 |
|
10817
7dfde45252f0
6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10685
diff
changeset
|
2034 |
if (avail_spare) |
2082 | 2035 |
return (zfs_error(hdl, EZFS_ISSPARE, msg)); |
2036 |
||
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2037 |
if (flags & ZFS_ONLINE_EXPAND || |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2038 |
zpool_get_prop_int(zhp, ZPOOL_PROP_AUTOEXPAND, NULL)) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2039 |
char *pathname = NULL; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2040 |
uint64_t wholedisk = 0; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2041 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2042 |
(void) nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_WHOLE_DISK, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2043 |
&wholedisk); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2044 |
verify(nvlist_lookup_string(tgt, ZPOOL_CONFIG_PATH, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2045 |
&pathname) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2046 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2047 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2048 |
* XXX - L2ARC 1.0 devices can't support expansion. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2049 |
*/ |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2050 |
if (l2cache) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2051 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2052 |
"cannot expand cache devices")); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2053 |
return (zfs_error(hdl, EZFS_VDEVNOTSUP, msg)); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2054 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2055 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2056 |
if (wholedisk) { |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2057 |
pathname += strlen(DISK_ROOT) + 1; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2058 |
(void) zpool_relabel_disk(zhp->zpool_hdl, pathname); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2059 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2060 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
2061 |
|
4451 | 2062 |
zc.zc_cookie = VDEV_STATE_ONLINE; |
2063 |
zc.zc_obj = flags; |
|
2064 |
||
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2065 |
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_SET_STATE, &zc) != 0) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2066 |
if (errno == EINVAL) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2067 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "was split " |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2068 |
"from this pool into a new one. Use '%s' " |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2069 |
"instead"), "zpool detach"); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2070 |
return (zfs_error(hdl, EZFS_POSTSPLIT_ONLINE, msg)); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2071 |
} |
4451 | 2072 |
return (zpool_standard_error(hdl, errno, msg)); |
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2073 |
} |
4451 | 2074 |
|
2075 |
*newstate = zc.zc_cookie; |
|
2076 |
return (0); |
|
789 | 2077 |
} |
2078 |
||
2079 |
/* |
|
2080 |
* Take the specified vdev offline |
|
2081 |
*/ |
|
2082 |
int |
|
4451 | 2083 |
zpool_vdev_offline(zpool_handle_t *zhp, const char *path, boolean_t istmp) |
789 | 2084 |
{ |
2085 |
zfs_cmd_t zc = { 0 }; |
|
2086 |
char msg[1024]; |
|
2082 | 2087 |
nvlist_t *tgt; |
5450 | 2088 |
boolean_t avail_spare, l2cache; |
2082 | 2089 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
789 | 2090 |
|
1544 | 2091 |
(void) snprintf(msg, sizeof (msg), |
2092 |
dgettext(TEXT_DOMAIN, "cannot offline %s"), path); |
|
2093 |
||
789 | 2094 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2095 |
if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache, |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2096 |
NULL)) == NULL) |
2082 | 2097 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
2098 |
||
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2099 |
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); |
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2100 |
|
10817
7dfde45252f0
6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10685
diff
changeset
|
2101 |
if (avail_spare) |
2082 | 2102 |
return (zfs_error(hdl, EZFS_ISSPARE, msg)); |
2103 |
||
4451 | 2104 |
zc.zc_cookie = VDEV_STATE_OFFLINE; |
2105 |
zc.zc_obj = istmp ? ZFS_OFFLINE_TEMPORARY : 0; |
|
1485 | 2106 |
|
4543 | 2107 |
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_SET_STATE, &zc) == 0) |
789 | 2108 |
return (0); |
2109 |
||
2110 |
switch (errno) { |
|
2082 | 2111 |
case EBUSY: |
789 | 2112 |
|
2113 |
/* |
|
2114 |
* There are no other replicas of this device. |
|
2115 |
*/ |
|
2082 | 2116 |
return (zfs_error(hdl, EZFS_NOREPLICAS, msg)); |
2117 |
||
9701
cc5b64682e64
6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents:
9160
diff
changeset
|
2118 |
case EEXIST: |
cc5b64682e64
6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents:
9160
diff
changeset
|
2119 |
/* |
cc5b64682e64
6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents:
9160
diff
changeset
|
2120 |
* The log device has unplayed logs |
cc5b64682e64
6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents:
9160
diff
changeset
|
2121 |
*/ |
cc5b64682e64
6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents:
9160
diff
changeset
|
2122 |
return (zfs_error(hdl, EZFS_UNPLAYED_LOGS, msg)); |
cc5b64682e64
6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents:
9160
diff
changeset
|
2123 |
|
2082 | 2124 |
default: |
2125 |
return (zpool_standard_error(hdl, errno, msg)); |
|
2126 |
} |
|
2127 |
} |
|
789 | 2128 |
|
2082 | 2129 |
/* |
4451 | 2130 |
* Mark the given vdev faulted. |
2131 |
*/ |
|
2132 |
int |
|
10817
7dfde45252f0
6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10685
diff
changeset
|
2133 |
zpool_vdev_fault(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux) |
4451 | 2134 |
{ |
2135 |
zfs_cmd_t zc = { 0 }; |
|
2136 |
char msg[1024]; |
|
2137 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
2138 |
||
2139 |
(void) snprintf(msg, sizeof (msg), |
|
2140 |
dgettext(TEXT_DOMAIN, "cannot fault %llu"), guid); |
|
2141 |
||
2142 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
2143 |
zc.zc_guid = guid; |
|
2144 |
zc.zc_cookie = VDEV_STATE_FAULTED; |
|
10817
7dfde45252f0
6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10685
diff
changeset
|
2145 |
zc.zc_obj = aux; |
4451 | 2146 |
|
2147 |
if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SET_STATE, &zc) == 0) |
|
2148 |
return (0); |
|
2149 |
||
2150 |
switch (errno) { |
|
2151 |
case EBUSY: |
|
2152 |
||
2153 |
/* |
|
2154 |
* There are no other replicas of this device. |
|
2155 |
*/ |
|
2156 |
return (zfs_error(hdl, EZFS_NOREPLICAS, msg)); |
|
2157 |
||
2158 |
default: |
|
2159 |
return (zpool_standard_error(hdl, errno, msg)); |
|
2160 |
} |
|
2161 |
||
2162 |
} |
|
2163 |
||
2164 |
/* |
|
2165 |
* Mark the given vdev degraded. |
|
2166 |
*/ |
|
2167 |
int |
|
10817
7dfde45252f0
6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10685
diff
changeset
|
2168 |
zpool_vdev_degrade(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux) |
4451 | 2169 |
{ |
2170 |
zfs_cmd_t zc = { 0 }; |
|
2171 |
char msg[1024]; |
|
2172 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
2173 |
||
2174 |
(void) snprintf(msg, sizeof (msg), |
|
2175 |
dgettext(TEXT_DOMAIN, "cannot degrade %llu"), guid); |
|
2176 |
||
2177 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
2178 |
zc.zc_guid = guid; |
|
2179 |
zc.zc_cookie = VDEV_STATE_DEGRADED; |
|
10817
7dfde45252f0
6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10685
diff
changeset
|
2180 |
zc.zc_obj = aux; |
4451 | 2181 |
|
2182 |
if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SET_STATE, &zc) == 0) |
|
2183 |
return (0); |
|
2184 |
||
2185 |
return (zpool_standard_error(hdl, errno, msg)); |
|
2186 |
} |
|
2187 |
||
2188 |
/* |
|
2082 | 2189 |
* Returns TRUE if the given nvlist is a vdev that was originally swapped in as |
2190 |
* a hot spare. |
|
2191 |
*/ |
|
2192 |
static boolean_t |
|
2193 |
is_replacing_spare(nvlist_t *search, nvlist_t *tgt, int which) |
|
2194 |
{ |
|
2195 |
nvlist_t **child; |
|
2196 |
uint_t c, children; |
|
2197 |
char *type; |
|
2198 |
||
2199 |
if (nvlist_lookup_nvlist_array(search, ZPOOL_CONFIG_CHILDREN, &child, |
|
2200 |
&children) == 0) { |
|
2201 |
verify(nvlist_lookup_string(search, ZPOOL_CONFIG_TYPE, |
|
2202 |
&type) == 0); |
|
2203 |
||
2204 |
if (strcmp(type, VDEV_TYPE_SPARE) == 0 && |
|
2205 |
children == 2 && child[which] == tgt) |
|
2206 |
return (B_TRUE); |
|
2207 |
||
2208 |
for (c = 0; c < children; c++) |
|
2209 |
if (is_replacing_spare(child[c], tgt, which)) |
|
2210 |
return (B_TRUE); |
|
789 | 2211 |
} |
2082 | 2212 |
|
2213 |
return (B_FALSE); |
|
789 | 2214 |
} |
2215 |
||
2216 |
/* |
|
2217 |
* Attach new_disk (fully described by nvroot) to old_disk. |
|
4527 | 2218 |
* If 'replacing' is specified, the new disk will replace the old one. |
789 | 2219 |
*/ |
2220 |
int |
|
2221 |
zpool_vdev_attach(zpool_handle_t *zhp, |
|
2222 |
const char *old_disk, const char *new_disk, nvlist_t *nvroot, int replacing) |
|
2223 |
{ |
|
2224 |
zfs_cmd_t zc = { 0 }; |
|
2225 |
char msg[1024]; |
|
2226 |
int ret; |
|
2082 | 2227 |
nvlist_t *tgt; |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2228 |
boolean_t avail_spare, l2cache, islog; |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2229 |
uint64_t val; |
7041
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2230 |
char *path, *newname; |
2082 | 2231 |
nvlist_t **child; |
2232 |
uint_t children; |
|
2233 |
nvlist_t *config_root; |
|
2234 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2235 |
boolean_t rootpool = pool_is_bootable(zhp); |
789 | 2236 |
|
1544 | 2237 |
if (replacing) |
2238 |
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, |
|
2239 |
"cannot replace %s with %s"), old_disk, new_disk); |
|
2240 |
else |
|
2241 |
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, |
|
2242 |
"cannot attach %s to %s"), new_disk, old_disk); |
|
2243 |
||
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2244 |
/* |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2245 |
* If this is a root pool, make sure that we're not attaching an |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2246 |
* EFI labeled device. |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2247 |
*/ |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2248 |
if (rootpool && pool_uses_efi(nvroot)) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2249 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2250 |
"EFI labeled devices are not supported on root pools.")); |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2251 |
return (zfs_error(hdl, EZFS_POOL_NOTSUP, msg)); |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2252 |
} |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2253 |
|
789 | 2254 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2255 |
if ((tgt = zpool_find_vdev(zhp, old_disk, &avail_spare, &l2cache, |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2256 |
&islog)) == 0) |
2082 | 2257 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
2258 |
||
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2259 |
if (avail_spare) |
2082 | 2260 |
return (zfs_error(hdl, EZFS_ISSPARE, msg)); |
2261 |
||
5450 | 2262 |
if (l2cache) |
2263 |
return (zfs_error(hdl, EZFS_ISL2CACHE, msg)); |
|
2264 |
||
2082 | 2265 |
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); |
2266 |
zc.zc_cookie = replacing; |
|
2267 |
||
2268 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN, |
|
2269 |
&child, &children) != 0 || children != 1) { |
|
2270 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2271 |
"new device must be a single disk")); |
|
2272 |
return (zfs_error(hdl, EZFS_INVALCONFIG, msg)); |
|
1544 | 2273 |
} |
2082 | 2274 |
|
2275 |
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL), |
|
2276 |
ZPOOL_CONFIG_VDEV_TREE, &config_root) == 0); |
|
2277 |
||
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2278 |
if ((newname = zpool_vdev_name(NULL, NULL, child[0], B_FALSE)) == NULL) |
7041
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2279 |
return (-1); |
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2280 |
|
2082 | 2281 |
/* |
2282 |
* If the target is a hot spare that has been swapped in, we can only |
|
2283 |
* replace it with another hot spare. |
|
2284 |
*/ |
|
2285 |
if (replacing && |
|
2286 |
nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_IS_SPARE, &val) == 0 && |
|
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2287 |
(zpool_find_vdev(zhp, newname, &avail_spare, &l2cache, |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2288 |
NULL) == NULL || !avail_spare) && |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2289 |
is_replacing_spare(config_root, tgt, 1)) { |
2082 | 2290 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2291 |
"can only be replaced by another hot spare")); |
|
7041
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2292 |
free(newname); |
2082 | 2293 |
return (zfs_error(hdl, EZFS_BADTARGET, msg)); |
2294 |
} |
|
2295 |
||
2296 |
/* |
|
2297 |
* If we are attempting to replace a spare, it canot be applied to an |
|
2298 |
* already spared device. |
|
2299 |
*/ |
|
2300 |
if (replacing && |
|
2301 |
nvlist_lookup_string(child[0], ZPOOL_CONFIG_PATH, &path) == 0 && |
|
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2302 |
zpool_find_vdev(zhp, newname, &avail_spare, |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2303 |
&l2cache, NULL) != NULL && avail_spare && |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2304 |
is_replacing_spare(config_root, tgt, 0)) { |
2082 | 2305 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2306 |
"device has already been replaced with a spare")); |
|
7041
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2307 |
free(newname); |
2082 | 2308 |
return (zfs_error(hdl, EZFS_BADTARGET, msg)); |
2309 |
} |
|
789 | 2310 |
|
7041
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2311 |
free(newname); |
b4c5fe87fad8
6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents:
6643
diff
changeset
|
2312 |
|
5094 | 2313 |
if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0) |
2082 | 2314 |
return (-1); |
789 | 2315 |
|
4543 | 2316 |
ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_ATTACH, &zc); |
789 | 2317 |
|
2676 | 2318 |
zcmd_free_nvlists(&zc); |
789 | 2319 |
|
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2320 |
if (ret == 0) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2321 |
if (rootpool) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2322 |
/* |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2323 |
* XXX - This should be removed once we can |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2324 |
* automatically install the bootblocks on the |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2325 |
* newly attached disk. |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2326 |
*/ |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2327 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Please " |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2328 |
"be sure to invoke %s to make '%s' bootable.\n"), |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2329 |
BOOTCMD, new_disk); |
9790
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2330 |
|
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2331 |
/* |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2332 |
* XXX need a better way to prevent user from |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2333 |
* booting up a half-baked vdev. |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2334 |
*/ |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2335 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Make " |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2336 |
"sure to wait until resilver is done " |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9701
diff
changeset
|
2337 |
"before rebooting.\n")); |
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2338 |
} |
789 | 2339 |
return (0); |
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
2340 |
} |
789 | 2341 |
|
2342 |
switch (errno) { |
|
1544 | 2343 |
case ENOTSUP: |
789 | 2344 |
/* |
2345 |
* Can't attach to or replace this type of vdev. |
|
2346 |
*/ |
|
4527 | 2347 |
if (replacing) { |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2348 |
if (islog) |
4527 | 2349 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2350 |
"cannot replace a log with a spare")); |
|
2351 |
else |
|
2352 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2353 |
"cannot replace a replacing device")); |
|
2354 |
} else { |
|
2082 | 2355 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2356 |
"can only attach to mirrors and top-level " |
|
2357 |
"disks")); |
|
4527 | 2358 |
} |
2082 | 2359 |
(void) zfs_error(hdl, EZFS_BADTARGET, msg); |
789 | 2360 |
break; |
2361 |
||
1544 | 2362 |
case EINVAL: |
789 | 2363 |
/* |
2364 |
* The new device must be a single disk. |
|
2365 |
*/ |
|
2082 | 2366 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2367 |
"new device must be a single disk")); |
|
2368 |
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg); |
|
789 | 2369 |
break; |
2370 |
||
1544 | 2371 |
case EBUSY: |
2082 | 2372 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "%s is busy"), |
2373 |
new_disk); |
|
2374 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
|
789 | 2375 |
break; |
2376 |
||
1544 | 2377 |
case EOVERFLOW: |
789 | 2378 |
/* |
2379 |
* The new device is too small. |
|
2380 |
*/ |
|
2082 | 2381 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2382 |
"device is too small")); |
|
2383 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
|
789 | 2384 |
break; |
2385 |
||
1544 | 2386 |
case EDOM: |
789 | 2387 |
/* |
2388 |
* The new device has a different alignment requirement. |
|
2389 |
*/ |
|
2082 | 2390 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2391 |
"devices have different sector alignment")); |
|
2392 |
(void) zfs_error(hdl, EZFS_BADDEV, msg); |
|
789 | 2393 |
break; |
2394 |
||
1544 | 2395 |
case ENAMETOOLONG: |
789 | 2396 |
/* |
2397 |
* The resulting top-level vdev spec won't fit in the label. |
|
2398 |
*/ |
|
2082 | 2399 |
(void) zfs_error(hdl, EZFS_DEVOVERFLOW, msg); |
789 | 2400 |
break; |
2401 |
||
1544 | 2402 |
default: |
2082 | 2403 |
(void) zpool_standard_error(hdl, errno, msg); |
789 | 2404 |
} |
2405 |
||
2082 | 2406 |
return (-1); |
789 | 2407 |
} |
2408 |
||
2409 |
/* |
|
2410 |
* Detach the specified device. |
|
2411 |
*/ |
|
2412 |
int |
|
2413 |
zpool_vdev_detach(zpool_handle_t *zhp, const char *path) |
|
2414 |
{ |
|
2415 |
zfs_cmd_t zc = { 0 }; |
|
2416 |
char msg[1024]; |
|
2082 | 2417 |
nvlist_t *tgt; |
5450 | 2418 |
boolean_t avail_spare, l2cache; |
2082 | 2419 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
789 | 2420 |
|
1544 | 2421 |
(void) snprintf(msg, sizeof (msg), |
2422 |
dgettext(TEXT_DOMAIN, "cannot detach %s"), path); |
|
2423 |
||
789 | 2424 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2425 |
if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache, |
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2426 |
NULL)) == 0) |
2082 | 2427 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
789 | 2428 |
|
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2429 |
if (avail_spare) |
2082 | 2430 |
return (zfs_error(hdl, EZFS_ISSPARE, msg)); |
2431 |
||
5450 | 2432 |
if (l2cache) |
2433 |
return (zfs_error(hdl, EZFS_ISL2CACHE, msg)); |
|
2434 |
||
2082 | 2435 |
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); |
2436 |
||
4543 | 2437 |
if (zfs_ioctl(hdl, ZFS_IOC_VDEV_DETACH, &zc) == 0) |
789 | 2438 |
return (0); |
2439 |
||
2440 |
switch (errno) { |
|
2441 |
||
1544 | 2442 |
case ENOTSUP: |
789 | 2443 |
/* |
2444 |
* Can't detach from this type of vdev. |
|
2445 |
*/ |
|
2082 | 2446 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "only " |
2447 |
"applicable to mirror and replacing vdevs")); |
|
2448 |
(void) zfs_error(zhp->zpool_hdl, EZFS_BADTARGET, msg); |
|
789 | 2449 |
break; |
2450 |
||
1544 | 2451 |
case EBUSY: |
789 | 2452 |
/* |
2453 |
* There are no other replicas of this device. |
|
2454 |
*/ |
|
2082 | 2455 |
(void) zfs_error(hdl, EZFS_NOREPLICAS, msg); |
789 | 2456 |
break; |
2457 |
||
1544 | 2458 |
default: |
2082 | 2459 |
(void) zpool_standard_error(hdl, errno, msg); |
1544 | 2460 |
} |
2461 |
||
2082 | 2462 |
return (-1); |
2463 |
} |
|
2464 |
||
2465 |
/* |
|
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2466 |
* Find a mirror vdev in the source nvlist. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2467 |
* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2468 |
* The mchild array contains a list of disks in one of the top-level mirrors |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2469 |
* of the source pool. The schild array contains a list of disks that the |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2470 |
* user specified on the command line. We loop over the mchild array to |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2471 |
* see if any entry in the schild array matches. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2472 |
* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2473 |
* If a disk in the mchild array is found in the schild array, we return |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2474 |
* the index of that entry. Otherwise we return -1. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2475 |
*/ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2476 |
static int |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2477 |
find_vdev_entry(zpool_handle_t *zhp, nvlist_t **mchild, uint_t mchildren, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2478 |
nvlist_t **schild, uint_t schildren) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2479 |
{ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2480 |
uint_t mc; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2481 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2482 |
for (mc = 0; mc < mchildren; mc++) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2483 |
uint_t sc; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2484 |
char *mpath = zpool_vdev_name(zhp->zpool_hdl, zhp, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2485 |
mchild[mc], B_FALSE); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2486 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2487 |
for (sc = 0; sc < schildren; sc++) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2488 |
char *spath = zpool_vdev_name(zhp->zpool_hdl, zhp, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2489 |
schild[sc], B_FALSE); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2490 |
boolean_t result = (strcmp(mpath, spath) == 0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2491 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2492 |
free(spath); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2493 |
if (result) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2494 |
free(mpath); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2495 |
return (mc); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2496 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2497 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2498 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2499 |
free(mpath); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2500 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2501 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2502 |
return (-1); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2503 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2504 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2505 |
/* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2506 |
* Split a mirror pool. If newroot points to null, then a new nvlist |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2507 |
* is generated and it is the responsibility of the caller to free it. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2508 |
*/ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2509 |
int |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2510 |
zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2511 |
nvlist_t *props, splitflags_t flags) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2512 |
{ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2513 |
zfs_cmd_t zc = { 0 }; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2514 |
char msg[1024]; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2515 |
nvlist_t *tree, *config, **child, **newchild, *newconfig = NULL; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2516 |
nvlist_t **varray = NULL, *zc_props = NULL; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2517 |
uint_t c, children, newchildren, lastlog = 0, vcount, found = 0; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2518 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2519 |
uint64_t vers; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2520 |
boolean_t freelist = B_FALSE, memory_err = B_TRUE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2521 |
int retval = 0; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2522 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2523 |
(void) snprintf(msg, sizeof (msg), |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2524 |
dgettext(TEXT_DOMAIN, "Unable to split %s"), zhp->zpool_name); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2525 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2526 |
if (!zpool_name_valid(hdl, B_FALSE, newname)) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2527 |
return (zfs_error(hdl, EZFS_INVALIDNAME, msg)); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2528 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2529 |
if ((config = zpool_get_config(zhp, NULL)) == NULL) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2530 |
(void) fprintf(stderr, gettext("Internal error: unable to " |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2531 |
"retrieve pool configuration\n")); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2532 |
return (-1); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2533 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2534 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2535 |
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &tree) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2536 |
== 0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2537 |
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, &vers) == 0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2538 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2539 |
if (props) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2540 |
if ((zc_props = zpool_valid_proplist(hdl, zhp->zpool_name, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2541 |
props, vers, B_TRUE, msg)) == NULL) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2542 |
return (-1); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2543 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2544 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2545 |
if (nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN, &child, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2546 |
&children) != 0) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2547 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2548 |
"Source pool is missing vdev tree")); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2549 |
if (zc_props) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2550 |
nvlist_free(zc_props); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2551 |
return (-1); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2552 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2553 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2554 |
varray = zfs_alloc(hdl, children * sizeof (nvlist_t *)); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2555 |
vcount = 0; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2556 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2557 |
if (*newroot == NULL || |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2558 |
nvlist_lookup_nvlist_array(*newroot, ZPOOL_CONFIG_CHILDREN, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2559 |
&newchild, &newchildren) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2560 |
newchildren = 0; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2561 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2562 |
for (c = 0; c < children; c++) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2563 |
uint64_t is_log = B_FALSE, is_hole = B_FALSE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2564 |
char *type; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2565 |
nvlist_t **mchild, *vdev; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2566 |
uint_t mchildren; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2567 |
int entry; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2568 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2569 |
/* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2570 |
* Unlike cache & spares, slogs are stored in the |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2571 |
* ZPOOL_CONFIG_CHILDREN array. We filter them out here. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2572 |
*/ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2573 |
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2574 |
&is_log); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2575 |
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2576 |
&is_hole); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2577 |
if (is_log || is_hole) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2578 |
/* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2579 |
* Create a hole vdev and put it in the config. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2580 |
*/ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2581 |
if (nvlist_alloc(&vdev, NV_UNIQUE_NAME, 0) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2582 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2583 |
if (nvlist_add_string(vdev, ZPOOL_CONFIG_TYPE, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2584 |
VDEV_TYPE_HOLE) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2585 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2586 |
if (nvlist_add_uint64(vdev, ZPOOL_CONFIG_IS_HOLE, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2587 |
1) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2588 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2589 |
if (lastlog == 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2590 |
lastlog = vcount; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2591 |
varray[vcount++] = vdev; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2592 |
continue; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2593 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2594 |
lastlog = 0; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2595 |
verify(nvlist_lookup_string(child[c], ZPOOL_CONFIG_TYPE, &type) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2596 |
== 0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2597 |
if (strcmp(type, VDEV_TYPE_MIRROR) != 0) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2598 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2599 |
"Source pool must be composed only of mirrors\n")); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2600 |
retval = zfs_error(hdl, EZFS_INVALCONFIG, msg); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2601 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2602 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2603 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2604 |
verify(nvlist_lookup_nvlist_array(child[c], |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2605 |
ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren) == 0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2606 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2607 |
/* find or add an entry for this top-level vdev */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2608 |
if (newchildren > 0 && |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2609 |
(entry = find_vdev_entry(zhp, mchild, mchildren, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2610 |
newchild, newchildren)) >= 0) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2611 |
/* We found a disk that the user specified. */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2612 |
vdev = mchild[entry]; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2613 |
++found; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2614 |
} else { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2615 |
/* User didn't specify a disk for this vdev. */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2616 |
vdev = mchild[mchildren - 1]; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2617 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2618 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2619 |
if (nvlist_dup(vdev, &varray[vcount++], 0) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2620 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2621 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2622 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2623 |
/* did we find every disk the user specified? */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2624 |
if (found != newchildren) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2625 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "Device list must " |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2626 |
"include at most one disk from each mirror")); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2627 |
retval = zfs_error(hdl, EZFS_INVALCONFIG, msg); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2628 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2629 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2630 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2631 |
/* Prepare the nvlist for populating. */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2632 |
if (*newroot == NULL) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2633 |
if (nvlist_alloc(newroot, NV_UNIQUE_NAME, 0) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2634 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2635 |
freelist = B_TRUE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2636 |
if (nvlist_add_string(*newroot, ZPOOL_CONFIG_TYPE, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2637 |
VDEV_TYPE_ROOT) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2638 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2639 |
} else { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2640 |
verify(nvlist_remove_all(*newroot, ZPOOL_CONFIG_CHILDREN) == 0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2641 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2642 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2643 |
/* Add all the children we found */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2644 |
if (nvlist_add_nvlist_array(*newroot, ZPOOL_CONFIG_CHILDREN, varray, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2645 |
lastlog == 0 ? vcount : lastlog) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2646 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2647 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2648 |
/* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2649 |
* If we're just doing a dry run, exit now with success. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2650 |
*/ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2651 |
if (flags.dryrun) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2652 |
memory_err = B_FALSE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2653 |
freelist = B_FALSE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2654 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2655 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2656 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2657 |
/* now build up the config list & call the ioctl */ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2658 |
if (nvlist_alloc(&newconfig, NV_UNIQUE_NAME, 0) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2659 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2660 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2661 |
if (nvlist_add_nvlist(newconfig, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2662 |
ZPOOL_CONFIG_VDEV_TREE, *newroot) != 0 || |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2663 |
nvlist_add_string(newconfig, |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2664 |
ZPOOL_CONFIG_POOL_NAME, newname) != 0 || |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2665 |
nvlist_add_uint64(newconfig, ZPOOL_CONFIG_VERSION, vers) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2666 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2667 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2668 |
/* |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2669 |
* The new pool is automatically part of the namespace unless we |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2670 |
* explicitly export it. |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2671 |
*/ |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2672 |
if (!flags.import) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2673 |
zc.zc_cookie = ZPOOL_EXPORT_AFTER_SPLIT; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2674 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2675 |
(void) strlcpy(zc.zc_string, newname, sizeof (zc.zc_string)); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2676 |
if (zcmd_write_conf_nvlist(hdl, &zc, newconfig) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2677 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2678 |
if (zc_props != NULL && zcmd_write_src_nvlist(hdl, &zc, zc_props) != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2679 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2680 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2681 |
if (zfs_ioctl(hdl, ZFS_IOC_VDEV_SPLIT, &zc) != 0) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2682 |
retval = zpool_standard_error(hdl, errno, msg); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2683 |
goto out; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2684 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2685 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2686 |
freelist = B_FALSE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2687 |
memory_err = B_FALSE; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2688 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2689 |
out: |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2690 |
if (varray != NULL) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2691 |
int v; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2692 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2693 |
for (v = 0; v < vcount; v++) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2694 |
nvlist_free(varray[v]); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2695 |
free(varray); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2696 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2697 |
zcmd_free_nvlists(&zc); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2698 |
if (zc_props) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2699 |
nvlist_free(zc_props); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2700 |
if (newconfig) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2701 |
nvlist_free(newconfig); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2702 |
if (freelist) { |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2703 |
nvlist_free(*newroot); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2704 |
*newroot = NULL; |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2705 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2706 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2707 |
if (retval != 0) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2708 |
return (retval); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2709 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2710 |
if (memory_err) |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2711 |
return (no_memory(hdl)); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2712 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2713 |
return (0); |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2714 |
} |
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2715 |
|
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11026
diff
changeset
|
2716 |
/* |
5450 | 2717 |
* Remove the given device. Currently, this is supported only for hot spares |
2718 |
* and level 2 cache devices. |
|
2082 | 2719 |
*/ |
2720 |
int |
|
2721 |
zpool_vdev_remove(zpool_handle_t *zhp, const char *path) |
|
2722 |
{ |
|
2723 |
zfs_cmd_t zc = { 0 }; |
|
2724 |
char msg[1024]; |
|
2725 |
nvlist_t *tgt; |
|
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2726 |
boolean_t avail_spare, l2cache, islog; |
2082 | 2727 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2728 |
uint64_t version; |
2082 | 2729 |
|
2730 |
(void) snprintf(msg, sizeof (msg), |
|
2731 |
dgettext(TEXT_DOMAIN, "cannot remove %s"), path); |
|
2732 |
||
2733 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2734 |
if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache, |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2735 |
&islog)) == 0) |
2082 | 2736 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2737 |
/* |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2738 |
* XXX - this should just go away. |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2739 |
*/ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2740 |
if (!avail_spare && !l2cache && !islog) { |
2082 | 2741 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2742 |
"only inactive hot spares, cache, top-level, " |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2743 |
"or log devices can be removed")); |
2082 | 2744 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
2745 |
} |
|
2746 |
||
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2747 |
version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2748 |
if (islog && version < SPA_VERSION_HOLES) { |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2749 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2750 |
"pool must be upgrade to support log removal")); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2751 |
return (zfs_error(hdl, EZFS_BADVERSION, msg)); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2752 |
} |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2753 |
|
2082 | 2754 |
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); |
2755 |
||
4543 | 2756 |
if (zfs_ioctl(hdl, ZFS_IOC_VDEV_REMOVE, &zc) == 0) |
2082 | 2757 |
return (0); |
2758 |
||
2759 |
return (zpool_standard_error(hdl, errno, msg)); |
|
1544 | 2760 |
} |
2761 |
||
2762 |
/* |
|
2763 |
* Clear the errors for the pool, or the particular device if specified. |
|
2764 |
*/ |
|
2765 |
int |
|
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2766 |
zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl) |
1544 | 2767 |
{ |
2768 |
zfs_cmd_t zc = { 0 }; |
|
2769 |
char msg[1024]; |
|
2082 | 2770 |
nvlist_t *tgt; |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2771 |
zpool_rewind_policy_t policy; |
5450 | 2772 |
boolean_t avail_spare, l2cache; |
2082 | 2773 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2774 |
nvlist_t *nvi = NULL; |
1544 | 2775 |
|
2776 |
if (path) |
|
2777 |
(void) snprintf(msg, sizeof (msg), |
|
2778 |
dgettext(TEXT_DOMAIN, "cannot clear errors for %s"), |
|
2676 | 2779 |
path); |
1544 | 2780 |
else |
2781 |
(void) snprintf(msg, sizeof (msg), |
|
2782 |
dgettext(TEXT_DOMAIN, "cannot clear errors for %s"), |
|
2783 |
zhp->zpool_name); |
|
2784 |
||
2785 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
2082 | 2786 |
if (path) { |
5450 | 2787 |
if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, |
7326
a3c803100a09
6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7300
diff
changeset
|
2788 |
&l2cache, NULL)) == 0) |
2082 | 2789 |
return (zfs_error(hdl, EZFS_NODEVICE, msg)); |
2790 |
||
5450 | 2791 |
/* |
2792 |
* Don't allow error clearing for hot spares. Do allow |
|
2793 |
* error clearing for l2cache devices. |
|
2794 |
*/ |
|
2468
b5038d012f66
6433208 should not be able to offline/online a spare
ek110237
parents:
2174
diff
changeset
|
2795 |
if (avail_spare) |
2082 | 2796 |
return (zfs_error(hdl, EZFS_ISSPARE, msg)); |
2797 |
||
2798 |
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, |
|
2799 |
&zc.zc_guid) == 0); |
|
1544 | 2800 |
} |
2801 |
||
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2802 |
zpool_get_rewind_policy(rewindnvl, &policy); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2803 |
zc.zc_cookie = policy.zrp_request; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2804 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2805 |
if (zcmd_alloc_dst_nvlist(hdl, &zc, 8192) != 0) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2806 |
return (-1); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2807 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2808 |
if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, rewindnvl) != 0) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2809 |
return (-1); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2810 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2811 |
if (zfs_ioctl(hdl, ZFS_IOC_CLEAR, &zc) == 0 || |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2812 |
((policy.zrp_request & ZPOOL_TRY_REWIND) && |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2813 |
errno != EPERM && errno != EACCES)) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2814 |
if (policy.zrp_request & |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2815 |
(ZPOOL_DO_REWIND | ZPOOL_TRY_REWIND)) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2816 |
(void) zcmd_read_dst_nvlist(hdl, &zc, &nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2817 |
zpool_rewind_exclaim(hdl, zc.zc_name, |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2818 |
((policy.zrp_request & ZPOOL_TRY_REWIND) != 0), |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2819 |
nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2820 |
nvlist_free(nvi); |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2821 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2822 |
zcmd_free_nvlists(&zc); |
1544 | 2823 |
return (0); |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2824 |
} |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2825 |
|
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10817
diff
changeset
|
2826 |
zcmd_free_nvlists(&zc); |
2082 | 2827 |
return (zpool_standard_error(hdl, errno, msg)); |
789 | 2828 |
} |
2829 |
||
3126 | 2830 |
/* |
4451 | 2831 |
* Similar to zpool_clear(), but takes a GUID (used by fmd). |
2832 |
*/ |
|
2833 |
int |
|
2834 |
zpool_vdev_clear(zpool_handle_t *zhp, uint64_t guid) |
|
2835 |
{ |
|
2836 |
zfs_cmd_t zc = { 0 }; |
|
2837 |
char msg[1024]; |
|
2838 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
2839 |
||
2840 |
(void) snprintf(msg, sizeof (msg), |
|
2841 |
dgettext(TEXT_DOMAIN, "cannot clear errors for %llx"), |
|
2842 |
guid); |
|
2843 |
||
2844 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
2845 |
zc.zc_guid = guid; |
|
2846 |
||
2847 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_CLEAR, &zc) == 0) |
|
2848 |
return (0); |
|
2849 |
||
2850 |
return (zpool_standard_error(hdl, errno, msg)); |
|
2851 |
} |
|
2852 |
||
2853 |
/* |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2854 |
* Convert from a devid string to a path. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2855 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2856 |
static char * |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2857 |
devid_to_path(char *devid_str) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2858 |
{ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2859 |
ddi_devid_t devid; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2860 |
char *minor; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2861 |
char *path; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2862 |
devid_nmlist_t *list = NULL; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2863 |
int ret; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2864 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2865 |
if (devid_str_decode(devid_str, &devid, &minor) != 0) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2866 |
return (NULL); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2867 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2868 |
ret = devid_deviceid_to_nmlist("/dev", devid, minor, &list); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2869 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2870 |
devid_str_free(minor); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2871 |
devid_free(devid); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2872 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2873 |
if (ret != 0) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2874 |
return (NULL); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2875 |
|
2082 | 2876 |
if ((path = strdup(list[0].devname)) == NULL) |
2877 |
return (NULL); |
|
2878 |
||
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2879 |
devid_free_nmlist(list); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2880 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2881 |
return (path); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2882 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2883 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2884 |
/* |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2885 |
* Convert from a path to a devid string. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2886 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2887 |
static char * |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2888 |
path_to_devid(const char *path) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2889 |
{ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2890 |
int fd; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2891 |
ddi_devid_t devid; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2892 |
char *minor, *ret; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2893 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2894 |
if ((fd = open(path, O_RDONLY)) < 0) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2895 |
return (NULL); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2896 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2897 |
minor = NULL; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2898 |
ret = NULL; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2899 |
if (devid_get(fd, &devid) == 0) { |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2900 |
if (devid_get_minor_name(fd, &minor) == 0) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2901 |
ret = devid_str_encode(devid, minor); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2902 |
if (minor != NULL) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2903 |
devid_str_free(minor); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2904 |
devid_free(devid); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2905 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2906 |
(void) close(fd); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2907 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2908 |
return (ret); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2909 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2910 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2911 |
/* |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2912 |
* Issue the necessary ioctl() to update the stored path value for the vdev. We |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2913 |
* ignore any failure here, since a common case is for an unprivileged user to |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2914 |
* type 'zpool status', and we'll display the correct information anyway. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2915 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2916 |
static void |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2917 |
set_path(zpool_handle_t *zhp, nvlist_t *nv, const char *path) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2918 |
{ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2919 |
zfs_cmd_t zc = { 0 }; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2920 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2921 |
(void) strncpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
2676 | 2922 |
(void) strncpy(zc.zc_value, path, sizeof (zc.zc_value)); |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2923 |
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, |
1544 | 2924 |
&zc.zc_guid) == 0); |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2925 |
|
2082 | 2926 |
(void) ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SETPATH, &zc); |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2927 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2928 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2929 |
/* |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2930 |
* Given a vdev, return the name to display in iostat. If the vdev has a path, |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2931 |
* we use that, stripping off any leading "/dev/dsk/"; if not, we use the type. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2932 |
* We also check if this is a whole disk, in which case we strip off the |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2933 |
* trailing 's0' slice name. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2934 |
* |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2935 |
* This routine is also responsible for identifying when disks have been |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2936 |
* reconfigured in a new location. The kernel will have opened the device by |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2937 |
* devid, but the path will still refer to the old location. To catch this, we |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2938 |
* first do a path -> devid translation (which is fast for the common case). If |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2939 |
* the devid matches, we're done. If not, we do a reverse devid -> path |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2940 |
* translation and issue the appropriate ioctl() to update the path of the vdev. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2941 |
* If 'zhp' is NULL, then this is an exported pool, and we don't need to do any |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2942 |
* of these checks. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2943 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2944 |
char * |
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2945 |
zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
2946 |
boolean_t verbose) |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2947 |
{ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2948 |
char *path, *devid; |
1544 | 2949 |
uint64_t value; |
2950 |
char buf[64]; |
|
4451 | 2951 |
vdev_stat_t *vs; |
2952 |
uint_t vsc; |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2953 |
|
1544 | 2954 |
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, |
2955 |
&value) == 0) { |
|
2956 |
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, |
|
2957 |
&value) == 0); |
|
2856 | 2958 |
(void) snprintf(buf, sizeof (buf), "%llu", |
2959 |
(u_longlong_t)value); |
|
1544 | 2960 |
path = buf; |
2961 |
} else if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) { |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2962 |
|
4451 | 2963 |
/* |
2964 |
* If the device is dead (faulted, offline, etc) then don't |
|
2965 |
* bother opening it. Otherwise we may be forcing the user to |
|
2966 |
* open a misbehaving device, which can have undesirable |
|
2967 |
* effects. |
|
2968 |
*/ |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11814
diff
changeset
|
2969 |
if ((nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS, |
4451 | 2970 |
(uint64_t **)&vs, &vsc) != 0 || |
2971 |
vs->vs_state >= VDEV_STATE_DEGRADED) && |
|
2972 |
zhp != NULL && |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2973 |
nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &devid) == 0) { |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2974 |
/* |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2975 |
* Determine if the current path is correct. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2976 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2977 |
char *newdevid = path_to_devid(path); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2978 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2979 |
if (newdevid == NULL || |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2980 |
strcmp(devid, newdevid) != 0) { |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2981 |
char *newpath; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2982 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2983 |
if ((newpath = devid_to_path(devid)) != NULL) { |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2984 |
/* |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2985 |
* Update the path appropriately. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2986 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2987 |
set_path(zhp, nv, newpath); |
2082 | 2988 |
if (nvlist_add_string(nv, |
2989 |
ZPOOL_CONFIG_PATH, newpath) == 0) |
|
2990 |
verify(nvlist_lookup_string(nv, |
|
2991 |
ZPOOL_CONFIG_PATH, |
|
2992 |
&path) == 0); |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2993 |
free(newpath); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2994 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2995 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2996 |
|
2082 | 2997 |
if (newdevid) |
2998 |
devid_str_free(newdevid); |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
2999 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3000 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3001 |
if (strncmp(path, "/dev/dsk/", 9) == 0) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3002 |
path += 9; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3003 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3004 |
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK, |
1544 | 3005 |
&value) == 0 && value) { |
2082 | 3006 |
char *tmp = zfs_strdup(hdl, path); |
3007 |
if (tmp == NULL) |
|
3008 |
return (NULL); |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3009 |
tmp[strlen(path) - 2] = '\0'; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3010 |
return (tmp); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3011 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3012 |
} else { |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3013 |
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &path) == 0); |
2082 | 3014 |
|
3015 |
/* |
|
3016 |
* If it's a raidz device, we need to stick in the parity level. |
|
3017 |
*/ |
|
3018 |
if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) { |
|
3019 |
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY, |
|
3020 |
&value) == 0); |
|
3021 |
(void) snprintf(buf, sizeof (buf), "%s%llu", path, |
|
2856 | 3022 |
(u_longlong_t)value); |
2082 | 3023 |
path = buf; |
3024 |
} |
|
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3025 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3026 |
/* |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3027 |
* We identify each top-level vdev by using a <type-id> |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3028 |
* naming convention. |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3029 |
*/ |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3030 |
if (verbose) { |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3031 |
uint64_t id; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3032 |
|
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3033 |
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3034 |
&id) == 0); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3035 |
(void) snprintf(buf, sizeof (buf), "%s-%llu", path, |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3036 |
(u_longlong_t)id); |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3037 |
path = buf; |
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3038 |
} |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3039 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3040 |
|
2082 | 3041 |
return (zfs_strdup(hdl, path)); |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1003
diff
changeset
|
3042 |
} |
1544 | 3043 |
|
3044 |
static int |
|
3045 |
zbookmark_compare(const void *a, const void *b) |
|
3046 |
{ |
|
3047 |
return (memcmp(a, b, sizeof (zbookmark_t))); |
|
3048 |
} |
|
3049 |
||
3050 |
/* |
|
3051 |
* Retrieve the persistent error log, uniquify the members, and return to the |
|
3052 |
* caller. |
|
3053 |
*/ |
|
3054 |
int |
|
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3055 |
zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp) |
1544 | 3056 |
{ |
3057 |
zfs_cmd_t zc = { 0 }; |
|
3058 |
uint64_t count; |
|
2676 | 3059 |
zbookmark_t *zb = NULL; |
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3060 |
int i; |
1544 | 3061 |
|
3062 |
/* |
|
3063 |
* Retrieve the raw error list from the kernel. If the number of errors |
|
3064 |
* has increased, allocate more space and continue until we get the |
|
3065 |
* entire list. |
|
3066 |
*/ |
|
3067 |
verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT, |
|
3068 |
&count) == 0); |
|
4820
acbb57436af2
6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents:
4715
diff
changeset
|
3069 |
if (count == 0) |
acbb57436af2
6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents:
4715
diff
changeset
|
3070 |
return (0); |
2676 | 3071 |
if ((zc.zc_nvlist_dst = (uintptr_t)zfs_alloc(zhp->zpool_hdl, |
2856 | 3072 |
count * sizeof (zbookmark_t))) == (uintptr_t)NULL) |
2082 | 3073 |
return (-1); |
2676 | 3074 |
zc.zc_nvlist_dst_size = count; |
1544 | 3075 |
(void) strcpy(zc.zc_name, zhp->zpool_name); |
3076 |
for (;;) { |
|
2082 | 3077 |
if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_ERROR_LOG, |
3078 |
&zc) != 0) { |
|
2676 | 3079 |
free((void *)(uintptr_t)zc.zc_nvlist_dst); |
1544 | 3080 |
if (errno == ENOMEM) { |
3823 | 3081 |
count = zc.zc_nvlist_dst_size; |
2676 | 3082 |
if ((zc.zc_nvlist_dst = (uintptr_t) |
3823 | 3083 |
zfs_alloc(zhp->zpool_hdl, count * |
3084 |
sizeof (zbookmark_t))) == (uintptr_t)NULL) |
|
2082 | 3085 |
return (-1); |
1544 | 3086 |
} else { |
3087 |
return (-1); |
|
3088 |
} |
|
3089 |
} else { |
|
3090 |
break; |
|
3091 |
} |
|
3092 |
} |
|
3093 |
||
3094 |
/* |
|
3095 |
* Sort the resulting bookmarks. This is a little confusing due to the |
|
3096 |
* implementation of ZFS_IOC_ERROR_LOG. The bookmarks are copied last |
|
2676 | 3097 |
* to first, and 'zc_nvlist_dst_size' indicates the number of boomarks |
1544 | 3098 |
* _not_ copied as part of the process. So we point the start of our |
3099 |
* array appropriate and decrement the total number of elements. |
|
3100 |
*/ |
|
2676 | 3101 |
zb = ((zbookmark_t *)(uintptr_t)zc.zc_nvlist_dst) + |
3102 |
zc.zc_nvlist_dst_size; |
|
3103 |
count -= zc.zc_nvlist_dst_size; |
|
1544 | 3104 |
|
3105 |
qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare); |
|
3106 |
||
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3107 |
verify(nvlist_alloc(nverrlistp, 0, KM_SLEEP) == 0); |
1544 | 3108 |
|
3109 |
/* |
|
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3110 |
* Fill in the nverrlistp with nvlist's of dataset and object numbers. |
1544 | 3111 |
*/ |
3112 |
for (i = 0; i < count; i++) { |
|
3113 |
nvlist_t *nv; |
|
3114 |
||
3700
3a7e0afcf1b4
6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents:
3444
diff
changeset
|
3115 |
/* ignoring zb_blkid and zb_level for now */ |
3a7e0afcf1b4
6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents:
3444
diff
changeset
|
3116 |
if (i > 0 && zb[i-1].zb_objset == zb[i].zb_objset && |
3a7e0afcf1b4
6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents:
3444
diff
changeset
|
3117 |
zb[i-1].zb_object == zb[i].zb_object) |
1544 | 3118 |
continue; |
3119 |
||
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3120 |
if (nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) != 0) |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3121 |
goto nomem; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3122 |
if (nvlist_add_uint64(nv, ZPOOL_ERR_DATASET, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3123 |
zb[i].zb_objset) != 0) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3124 |
nvlist_free(nv); |
2082 | 3125 |
goto nomem; |
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3126 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3127 |
if (nvlist_add_uint64(nv, ZPOOL_ERR_OBJECT, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3128 |
zb[i].zb_object) != 0) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3129 |
nvlist_free(nv); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3130 |
goto nomem; |
1544 | 3131 |
} |
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3132 |
if (nvlist_add_nvlist(*nverrlistp, "ejk", nv) != 0) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3133 |
nvlist_free(nv); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3134 |
goto nomem; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3135 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3136 |
nvlist_free(nv); |
1544 | 3137 |
} |
3138 |
||
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3139 |
free((void *)(uintptr_t)zc.zc_nvlist_dst); |
1544 | 3140 |
return (0); |
2082 | 3141 |
|
3142 |
nomem: |
|
2676 | 3143 |
free((void *)(uintptr_t)zc.zc_nvlist_dst); |
2082 | 3144 |
return (no_memory(zhp->zpool_hdl)); |
1544 | 3145 |
} |
1760 | 3146 |
|
3147 |
/* |
|
3148 |
* Upgrade a ZFS pool to the latest on-disk version. |
|
3149 |
*/ |
|
3150 |
int |
|
5094 | 3151 |
zpool_upgrade(zpool_handle_t *zhp, uint64_t new_version) |
1760 | 3152 |
{ |
3153 |
zfs_cmd_t zc = { 0 }; |
|
2082 | 3154 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
1760 | 3155 |
|
3156 |
(void) strcpy(zc.zc_name, zhp->zpool_name); |
|
5094 | 3157 |
zc.zc_cookie = new_version; |
3158 |
||
4543 | 3159 |
if (zfs_ioctl(hdl, ZFS_IOC_POOL_UPGRADE, &zc) != 0) |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
3160 |
return (zpool_standard_error_fmt(hdl, errno, |
2082 | 3161 |
dgettext(TEXT_DOMAIN, "cannot upgrade '%s'"), |
3162 |
zhp->zpool_name)); |
|
1760 | 3163 |
return (0); |
3164 |
} |
|
2926 | 3165 |
|
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3166 |
void |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3167 |
zpool_set_history_str(const char *subcommand, int argc, char **argv, |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3168 |
char *history_str) |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3169 |
{ |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3170 |
int i; |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3171 |
|
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3172 |
(void) strlcpy(history_str, subcommand, HIS_MAX_RECORD_LEN); |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3173 |
for (i = 1; i < argc; i++) { |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3174 |
if (strlen(history_str) + 1 + strlen(argv[i]) > |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3175 |
HIS_MAX_RECORD_LEN) |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3176 |
break; |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3177 |
(void) strlcat(history_str, " ", HIS_MAX_RECORD_LEN); |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3178 |
(void) strlcat(history_str, argv[i], HIS_MAX_RECORD_LEN); |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3179 |
} |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3180 |
} |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3181 |
|
2926 | 3182 |
/* |
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3183 |
* Stage command history for logging. |
2926 | 3184 |
*/ |
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3185 |
int |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3186 |
zpool_stage_history(libzfs_handle_t *hdl, const char *history_str) |
2926 | 3187 |
{ |
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3188 |
if (history_str == NULL) |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3189 |
return (EINVAL); |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3190 |
|
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3191 |
if (strlen(history_str) > HIS_MAX_RECORD_LEN) |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3192 |
return (EINVAL); |
2926 | 3193 |
|
4715
e8d212dda064
6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents:
4657
diff
changeset
|
3194 |
if (hdl->libzfs_log_str != NULL) |
4543 | 3195 |
free(hdl->libzfs_log_str); |
2926 | 3196 |
|
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3197 |
if ((hdl->libzfs_log_str = strdup(history_str)) == NULL) |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3198 |
return (no_memory(hdl)); |
4543 | 3199 |
|
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4820
diff
changeset
|
3200 |
return (0); |
2926 | 3201 |
} |
3202 |
||
3203 |
/* |
|
3204 |
* Perform ioctl to get some command history of a pool. |
|
3205 |
* |
|
3206 |
* 'buf' is the buffer to fill up to 'len' bytes. 'off' is the |
|
3207 |
* logical offset of the history buffer to start reading from. |
|
3208 |
* |
|
3209 |
* Upon return, 'off' is the next logical offset to read from and |
|
3210 |
* 'len' is the actual amount of bytes read into 'buf'. |
|
3211 |
*/ |
|
3212 |
static int |
|
3213 |
get_history(zpool_handle_t *zhp, char *buf, uint64_t *off, uint64_t *len) |
|
3214 |
{ |
|
3215 |
zfs_cmd_t zc = { 0 }; |
|
3216 |
libzfs_handle_t *hdl = zhp->zpool_hdl; |
|
3217 |
||
3218 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
|
3219 |
||
3220 |
zc.zc_history = (uint64_t)(uintptr_t)buf; |
|
3221 |
zc.zc_history_len = *len; |
|
3222 |
zc.zc_history_offset = *off; |
|
3223 |
||
3224 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_HISTORY, &zc) != 0) { |
|
3225 |
switch (errno) { |
|
3226 |
case EPERM: |
|
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
3227 |
return (zfs_error_fmt(hdl, EZFS_PERM, |
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
3228 |
dgettext(TEXT_DOMAIN, |
2926 | 3229 |
"cannot show history for pool '%s'"), |
3230 |
zhp->zpool_name)); |
|
3231 |
case ENOENT: |
|
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
3232 |
return (zfs_error_fmt(hdl, EZFS_NOHISTORY, |
2926 | 3233 |
dgettext(TEXT_DOMAIN, "cannot get history for pool " |
3234 |
"'%s'"), zhp->zpool_name)); |
|
3863
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3823
diff
changeset
|
3235 |
case ENOTSUP: |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3823
diff
changeset
|
3236 |
return (zfs_error_fmt(hdl, EZFS_BADVERSION, |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3823
diff
changeset
|
3237 |
dgettext(TEXT_DOMAIN, "cannot get history for pool " |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3823
diff
changeset
|
3238 |
"'%s', pool must be upgraded"), zhp->zpool_name)); |
2926 | 3239 |
default: |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3126
diff
changeset
|
3240 |
return (zpool_standard_error_fmt(hdl, errno, |
2926 | 3241 |
dgettext(TEXT_DOMAIN, |
3242 |
"cannot get history for '%s'"), zhp->zpool_name)); |
|
3243 |
} |
|
3244 |
} |
|
3245 |
||
3246 |
*len = zc.zc_history_len; |
|
3247 |
*off = zc.zc_history_offset; |
|
3248 |
||
3249 |
return (0); |
|
3250 |
} |
|
3251 |
||
3252 |
/* |
|
3253 |
* Process the buffer of nvlists, unpacking and storing each nvlist record |
|
3254 |
* into 'records'. 'leftover' is set to the number of bytes that weren't |
|
3255 |
* processed as there wasn't a complete record. |
|
3256 |
*/ |
|
10685
931790026ac6
6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents:
10594
diff
changeset
|
3257 |
int |
2926 | 3258 |
zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover, |
3259 |
nvlist_t ***records, uint_t *numrecords) |
|
3260 |
{ |
|
3261 |
uint64_t reclen; |
|
3262 |
nvlist_t *nv; |
|
3263 |
int i; |
|
3264 |
||
3265 |
while (bytes_read > sizeof (reclen)) { |
|
3266 |
||
3267 |
/* get length of packed record (stored as little endian) */ |
|
3268 |
for (i = 0, reclen = 0; i < sizeof (reclen); i++) |
|
3269 |
reclen += (uint64_t)(((uchar_t *)buf)[i]) << (8*i); |
|
3270 |
||
3271 |
if (bytes_read < sizeof (reclen) + reclen) |
|
3272 |
break; |
|
3273 |
||
3274 |
/* unpack record */ |
|
3275 |
if (nvlist_unpack(buf + sizeof (reclen), reclen, &nv, 0) != 0) |
|
3276 |
return (ENOMEM); |
|
3277 |
bytes_read -= sizeof (reclen) + reclen; |
|
3278 |
buf += sizeof (reclen) + reclen; |
|
3279 |
||
3280 |
/* add record to nvlist array */ |
|
3281 |
(*numrecords)++; |
|
3282 |
if (ISP2(*numrecords + 1)) { |
|
3283 |
*records = realloc(*records, |
|
3284 |
*numrecords * 2 * sizeof (nvlist_t *)); |
|
3285 |
} |
|
3286 |
(*records)[*numrecords - 1] = nv; |
|
3287 |
} |
|
3288 |
||
3289 |
*leftover = bytes_read; |
|
3290 |
return (0); |
|
3291 |
} |
|
3292 |
||
3293 |
#define HIS_BUF_LEN (128*1024) |
|
3294 |
||
3295 |
/* |
|
3296 |
* Retrieve the command history of a pool. |
|
3297 |
*/ |
|
3298 |
int |
|
3299 |
zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp) |
|
3300 |
{ |
|
3301 |
char buf[HIS_BUF_LEN]; |
|
3302 |
uint64_t off = 0; |
|
3303 |
nvlist_t **records = NULL; |
|
3304 |
uint_t numrecords = 0; |
|
3305 |
int err, i; |
|
3306 |
||
3307 |
do { |
|
3308 |
uint64_t bytes_read = sizeof (buf); |
|
3309 |
uint64_t leftover; |
|
3310 |
||
3311 |
if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0) |
|
3312 |
break; |
|
3313 |
||
3314 |
/* if nothing else was read in, we're at EOF, just return */ |
|
3315 |
if (!bytes_read) |
|
3316 |
break; |
|
3317 |
||
3318 |
if ((err = zpool_history_unpack(buf, bytes_read, |
|
3319 |
&leftover, &records, &numrecords)) != 0) |
|
3320 |
break; |
|
3321 |
off -= leftover; |
|
3322 |
||
3323 |
/* CONSTCOND */ |
|
3324 |
} while (1); |
|
3325 |
||
3326 |
if (!err) { |
|
3327 |
verify(nvlist_alloc(nvhisp, NV_UNIQUE_NAME, 0) == 0); |
|
3328 |
verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD, |
|
3329 |
records, numrecords) == 0); |
|
3330 |
} |
|
3331 |
for (i = 0; i < numrecords; i++) |
|
3332 |
nvlist_free(records[i]); |
|
3333 |
free(records); |
|
3334 |
||
3335 |
return (err); |
|
3336 |
} |
|
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3337 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3338 |
void |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3339 |
zpool_obj_to_path(zpool_handle_t *zhp, uint64_t dsobj, uint64_t obj, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3340 |
char *pathname, size_t len) |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3341 |
{ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3342 |
zfs_cmd_t zc = { 0 }; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3343 |
boolean_t mounted = B_FALSE; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3344 |
char *mntpnt = NULL; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3345 |
char dsname[MAXNAMELEN]; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3346 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3347 |
if (dsobj == 0) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3348 |
/* special case for the MOS */ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3349 |
(void) snprintf(pathname, len, "<metadata>:<0x%llx>", obj); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3350 |
return; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3351 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3352 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3353 |
/* get the dataset's name */ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3354 |
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3355 |
zc.zc_obj = dsobj; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3356 |
if (ioctl(zhp->zpool_hdl->libzfs_fd, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3357 |
ZFS_IOC_DSOBJ_TO_DSNAME, &zc) != 0) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3358 |
/* just write out a path of two object numbers */ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3359 |
(void) snprintf(pathname, len, "<0x%llx>:<0x%llx>", |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3360 |
dsobj, obj); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3361 |
return; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3362 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3363 |
(void) strlcpy(dsname, zc.zc_value, sizeof (dsname)); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3364 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3365 |
/* find out if the dataset is mounted */ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3366 |
mounted = is_mounted(zhp->zpool_hdl, dsname, &mntpnt); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3367 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3368 |
/* get the corrupted object's path */ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3369 |
(void) strlcpy(zc.zc_name, dsname, sizeof (zc.zc_name)); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3370 |
zc.zc_obj = obj; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3371 |
if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_OBJ_TO_PATH, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3372 |
&zc) == 0) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3373 |
if (mounted) { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3374 |
(void) snprintf(pathname, len, "%s%s", mntpnt, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3375 |
zc.zc_value); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3376 |
} else { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3377 |
(void) snprintf(pathname, len, "%s:%s", |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3378 |
dsname, zc.zc_value); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3379 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3380 |
} else { |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3381 |
(void) snprintf(pathname, len, "%s:<0x%llx>", dsname, obj); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3382 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3383 |
free(mntpnt); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3377
diff
changeset
|
3384 |
} |
3912 | 3385 |
|
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3386 |
/* |
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3387 |
* Read the EFI label from the config, if a label does not exist then |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3388 |
* pass back the error to the caller. If the caller has passed a non-NULL |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3389 |
* diskaddr argument then we set it to the starting address of the EFI |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3390 |
* partition. |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3391 |
*/ |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3392 |
static int |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3393 |
read_efi_label(nvlist_t *config, diskaddr_t *sb) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3394 |
{ |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3395 |
char *path; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3396 |
int fd; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3397 |
char diskname[MAXPATHLEN]; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3398 |
int err = -1; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3399 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3400 |
if (nvlist_lookup_string(config, ZPOOL_CONFIG_PATH, &path) != 0) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3401 |
return (err); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3402 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3403 |
(void) snprintf(diskname, sizeof (diskname), "%s%s", RDISK_ROOT, |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3404 |
strrchr(path, '/')); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3405 |
if ((fd = open(diskname, O_RDONLY|O_NDELAY)) >= 0) { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3406 |
struct dk_gpt *vtoc; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3407 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3408 |
if ((err = efi_alloc_and_read(fd, &vtoc)) >= 0) { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3409 |
if (sb != NULL) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3410 |
*sb = vtoc->efi_parts[0].p_start; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3411 |
efi_free(vtoc); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3412 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3413 |
(void) close(fd); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3414 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3415 |
return (err); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3416 |
} |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3417 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3418 |
/* |
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3419 |
* determine where a partition starts on a disk in the current |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3420 |
* configuration |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3421 |
*/ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3422 |
static diskaddr_t |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3423 |
find_start_block(nvlist_t *config) |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3424 |
{ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3425 |
nvlist_t **child; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3426 |
uint_t c, children; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3427 |
diskaddr_t sb = MAXOFFSET_T; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3428 |
uint64_t wholedisk; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3429 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3430 |
if (nvlist_lookup_nvlist_array(config, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3431 |
ZPOOL_CONFIG_CHILDREN, &child, &children) != 0) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3432 |
if (nvlist_lookup_uint64(config, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3433 |
ZPOOL_CONFIG_WHOLE_DISK, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3434 |
&wholedisk) != 0 || !wholedisk) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3435 |
return (MAXOFFSET_T); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3436 |
} |
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3437 |
if (read_efi_label(config, &sb) < 0) |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
7041
diff
changeset
|
3438 |
sb = MAXOFFSET_T; |
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3439 |
return (sb); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3440 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3441 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3442 |
for (c = 0; c < children; c++) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3443 |
sb = find_start_block(child[c]); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3444 |
if (sb != MAXOFFSET_T) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3445 |
return (sb); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3446 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3447 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3448 |
return (MAXOFFSET_T); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3449 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3450 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3451 |
/* |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3452 |
* Label an individual disk. The name provided is the short name, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3453 |
* stripped of any leading /dev path. |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3454 |
*/ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3455 |
int |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3456 |
zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, char *name) |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3457 |
{ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3458 |
char path[MAXPATHLEN]; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3459 |
struct dk_gpt *vtoc; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3460 |
int fd; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3461 |
size_t resv = EFI_MIN_RESV_SIZE; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3462 |
uint64_t slice_size; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3463 |
diskaddr_t start_block; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3464 |
char errbuf[1024]; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3465 |
|
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3466 |
/* prepare an error message just in case */ |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3467 |
(void) snprintf(errbuf, sizeof (errbuf), |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3468 |
dgettext(TEXT_DOMAIN, "cannot label '%s'"), name); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3469 |
|
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3470 |
if (zhp) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3471 |
nvlist_t *nvroot; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3472 |
|
7965
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3473 |
if (pool_is_bootable(zhp)) { |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3474 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3475 |
"EFI labeled devices are not supported on root " |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3476 |
"pools.")); |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3477 |
return (zfs_error(hdl, EZFS_POOL_NOTSUP, errbuf)); |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3478 |
} |
b795da521357
6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents:
7656
diff
changeset
|
3479 |
|
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3480 |
verify(nvlist_lookup_nvlist(zhp->zpool_config, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3481 |
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3482 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3483 |
if (zhp->zpool_start_block == 0) |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3484 |
start_block = find_start_block(nvroot); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3485 |
else |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3486 |
start_block = zhp->zpool_start_block; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3487 |
zhp->zpool_start_block = start_block; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3488 |
} else { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3489 |
/* new pool */ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3490 |
start_block = NEW_START_BLOCK; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3491 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3492 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3493 |
(void) snprintf(path, sizeof (path), "%s/%s%s", RDISK_ROOT, name, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3494 |
BACKUP_SLICE); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3495 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3496 |
if ((fd = open(path, O_RDWR | O_NDELAY)) < 0) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3497 |
/* |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3498 |
* This shouldn't happen. We've long since verified that this |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3499 |
* is a valid device. |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3500 |
*/ |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3501 |
zfs_error_aux(hdl, |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3502 |
dgettext(TEXT_DOMAIN, "unable to open device")); |
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3503 |
return (zfs_error(hdl, EZFS_OPENFAILED, errbuf)); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3504 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3505 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3506 |
if (efi_alloc_and_init(fd, EFI_NUMPAR, &vtoc) != 0) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3507 |
/* |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3508 |
* The only way this can fail is if we run out of memory, or we |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3509 |
* were unable to read the disk's capacity |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3510 |
*/ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3511 |
if (errno == ENOMEM) |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3512 |
(void) no_memory(hdl); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3513 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3514 |
(void) close(fd); |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3515 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3516 |
"unable to read disk capacity"), name); |
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3517 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3518 |
return (zfs_error(hdl, EZFS_NOCAP, errbuf)); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3519 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3520 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3521 |
slice_size = vtoc->efi_last_u_lba + 1; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3522 |
slice_size -= EFI_MIN_RESV_SIZE; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3523 |
if (start_block == MAXOFFSET_T) |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3524 |
start_block = NEW_START_BLOCK; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3525 |
slice_size -= start_block; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3526 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3527 |
vtoc->efi_parts[0].p_start = start_block; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3528 |
vtoc->efi_parts[0].p_size = slice_size; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3529 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3530 |
/* |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3531 |
* Why we use V_USR: V_BACKUP confuses users, and is considered |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3532 |
* disposable by some EFI utilities (since EFI doesn't have a backup |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3533 |
* slice). V_UNASSIGNED is supposed to be used only for zero size |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3534 |
* partitions, and efi_write() will fail if we use it. V_ROOT, V_BOOT, |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3535 |
* etc. were all pretty specific. V_USR is as close to reality as we |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3536 |
* can get, in the absence of V_OTHER. |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3537 |
*/ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3538 |
vtoc->efi_parts[0].p_tag = V_USR; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3539 |
(void) strcpy(vtoc->efi_parts[0].p_name, "zfs"); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3540 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3541 |
vtoc->efi_parts[8].p_start = slice_size + start_block; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3542 |
vtoc->efi_parts[8].p_size = resv; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3543 |
vtoc->efi_parts[8].p_tag = V_RESERVED; |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3544 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3545 |
if (efi_write(fd, vtoc) != 0) { |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3546 |
/* |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3547 |
* Some block drivers (like pcata) may not support EFI |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3548 |
* GPT labels. Print out a helpful error message dir- |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3549 |
* ecting the user to manually label the disk and give |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3550 |
* a specific slice. |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3551 |
*/ |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3552 |
(void) close(fd); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3553 |
efi_free(vtoc); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3554 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3555 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
5621
diff
changeset
|
3556 |
"try using fdisk(1M) and then provide a specific slice")); |
4276
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3557 |
return (zfs_error(hdl, EZFS_LABELFAILED, errbuf)); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3558 |
} |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3559 |
|
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3560 |
(void) close(fd); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3561 |
efi_free(vtoc); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3562 |
return (0); |
c42d49ffb16f
6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents:
3912
diff
changeset
|
3563 |
} |
6423 | 3564 |
|
3565 |
static boolean_t |
|
3566 |
supported_dump_vdev_type(libzfs_handle_t *hdl, nvlist_t *config, char *errbuf) |
|
3567 |
{ |
|
3568 |
char *type; |
|
3569 |
nvlist_t **child; |
|
3570 |
uint_t children, c; |
|
3571 |
||
3572 |
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_TYPE, &type) == 0); |
|
3573 |
if (strcmp(type, VDEV_TYPE_RAIDZ) == 0 || |
|
3574 |
strcmp(type, VDEV_TYPE_FILE) == 0 || |
|
3575 |
strcmp(type, VDEV_TYPE_LOG) == 0 || |
|
10594
986cb68d2347
6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents:
10588
diff
changeset
|
3576 |
strcmp(type, VDEV_TYPE_HOLE) == 0 || |
6423 | 3577 |
strcmp(type, VDEV_TYPE_MISSING) == 0) { |
3578 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3579 |
"vdev type '%s' is not supported"), type); |
|
3580 |
(void) zfs_error(hdl, EZFS_VDEVNOTSUP, errbuf); |
|
3581 |
return (B_FALSE); |
|
3582 |
} |
|
3583 |
if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN, |
|
3584 |
&child, &children) == 0) { |
|
3585 |
for (c = 0; c < children; c++) { |
|
3586 |
if (!supported_dump_vdev_type(hdl, child[c], errbuf)) |
|
3587 |
return (B_FALSE); |
|
3588 |
} |
|
3589 |
} |
|
3590 |
return (B_TRUE); |
|
3591 |
} |
|
3592 |
||
3593 |
/* |
|
3594 |
* check if this zvol is allowable for use as a dump device; zero if |
|
3595 |
* it is, > 0 if it isn't, < 0 if it isn't a zvol |
|
3596 |
*/ |
|
3597 |
int |
|
3598 |
zvol_check_dump_config(char *arg) |
|
3599 |
{ |
|
3600 |
zpool_handle_t *zhp = NULL; |
|
3601 |
nvlist_t *config, *nvroot; |
|
3602 |
char *p, *volname; |
|
3603 |
nvlist_t **top; |
|
3604 |
uint_t toplevels; |
|
3605 |
libzfs_handle_t *hdl; |
|
3606 |
char errbuf[1024]; |
|
3607 |
char poolname[ZPOOL_MAXNAMELEN]; |
|
3608 |
int pathlen = strlen(ZVOL_FULL_DEV_DIR); |
|
3609 |
int ret = 1; |
|
3610 |
||
3611 |
if (strncmp(arg, ZVOL_FULL_DEV_DIR, pathlen)) { |
|
3612 |
return (-1); |
|
3613 |
} |
|
3614 |
||
3615 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
3616 |
"dump is not supported on device '%s'"), arg); |
|
3617 |
||
3618 |
if ((hdl = libzfs_init()) == NULL) |
|
3619 |
return (1); |
|
3620 |
libzfs_print_on_error(hdl, B_TRUE); |
|
3621 |
||
3622 |
volname = arg + pathlen; |
|
3623 |
||
3624 |
/* check the configuration of the pool */ |
|
3625 |
if ((p = strchr(volname, '/')) == NULL) { |
|
3626 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3627 |
"malformed dataset name")); |
|
3628 |
(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf); |
|
3629 |
return (1); |
|
3630 |
} else if (p - volname >= ZFS_MAXNAMELEN) { |
|
3631 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3632 |
"dataset name is too long")); |
|
3633 |
(void) zfs_error(hdl, EZFS_NAMETOOLONG, errbuf); |
|
3634 |
return (1); |
|
3635 |
} else { |
|
3636 |
(void) strncpy(poolname, volname, p - volname); |
|
3637 |
poolname[p - volname] = '\0'; |
|
3638 |
} |
|
3639 |
||
3640 |
if ((zhp = zpool_open(hdl, poolname)) == NULL) { |
|
3641 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3642 |
"could not open pool '%s'"), poolname); |
|
3643 |
(void) zfs_error(hdl, EZFS_OPENFAILED, errbuf); |
|
3644 |
goto out; |
|
3645 |
} |
|
3646 |
config = zpool_get_config(zhp, NULL); |
|
3647 |
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, |
|
3648 |
&nvroot) != 0) { |
|
3649 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3650 |
"could not obtain vdev configuration for '%s'"), poolname); |
|
3651 |
(void) zfs_error(hdl, EZFS_INVALCONFIG, errbuf); |
|
3652 |
goto out; |
|
3653 |
} |
|
3654 |
||
3655 |
verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN, |
|
3656 |
&top, &toplevels) == 0); |
|
3657 |
if (toplevels != 1) { |
|
3658 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3659 |
"'%s' has multiple top level vdevs"), poolname); |
|
3660 |
(void) zfs_error(hdl, EZFS_DEVOVERFLOW, errbuf); |
|
3661 |
goto out; |
|
3662 |
} |
|
3663 |
||
3664 |
if (!supported_dump_vdev_type(hdl, top[0], errbuf)) { |
|
3665 |
goto out; |
|
3666 |
} |
|
3667 |
ret = 0; |
|
3668 |
||
3669 |
out: |
|
3670 |
if (zhp) |
|
3671 |
zpool_close(zhp); |
|
3672 |
libzfs_fini(hdl); |
|
3673 |
return (ret); |
|
3674 |
} |