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