author | lling |
Tue, 24 Apr 2007 16:07:37 -0700 | |
changeset 4098 | 0a182c2128e6 |
parent 4007 | c6f5c6753018 |
child 4451 | 24fbf2d7a5d7 |
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 |
*/ |
|
21 |
/* |
|
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
22 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
#include <sys/types.h> |
|
29 |
#include <sys/param.h> |
|
30 |
#include <sys/errno.h> |
|
31 |
#include <sys/uio.h> |
|
32 |
#include <sys/buf.h> |
|
33 |
#include <sys/modctl.h> |
|
34 |
#include <sys/open.h> |
|
35 |
#include <sys/file.h> |
|
36 |
#include <sys/kmem.h> |
|
37 |
#include <sys/conf.h> |
|
38 |
#include <sys/cmn_err.h> |
|
39 |
#include <sys/stat.h> |
|
40 |
#include <sys/zfs_ioctl.h> |
|
41 |
#include <sys/zap.h> |
|
42 |
#include <sys/spa.h> |
|
3912 | 43 |
#include <sys/spa_impl.h> |
789 | 44 |
#include <sys/vdev.h> |
3912 | 45 |
#include <sys/vdev_impl.h> |
789 | 46 |
#include <sys/dmu.h> |
47 |
#include <sys/dsl_dir.h> |
|
48 |
#include <sys/dsl_dataset.h> |
|
49 |
#include <sys/dsl_prop.h> |
|
50 |
#include <sys/ddi.h> |
|
51 |
#include <sys/sunddi.h> |
|
52 |
#include <sys/sunldi.h> |
|
53 |
#include <sys/policy.h> |
|
54 |
#include <sys/zone.h> |
|
55 |
#include <sys/nvpair.h> |
|
56 |
#include <sys/pathname.h> |
|
57 |
#include <sys/mount.h> |
|
58 |
#include <sys/sdt.h> |
|
59 |
#include <sys/fs/zfs.h> |
|
60 |
#include <sys/zfs_ctldir.h> |
|
2885 | 61 |
#include <sys/zvol.h> |
789 | 62 |
|
63 |
#include "zfs_namecheck.h" |
|
2676 | 64 |
#include "zfs_prop.h" |
789 | 65 |
|
66 |
extern struct modlfs zfs_modlfs; |
|
67 |
||
68 |
extern void zfs_init(void); |
|
69 |
extern void zfs_fini(void); |
|
70 |
||
71 |
ldi_ident_t zfs_li = NULL; |
|
72 |
dev_info_t *zfs_dip; |
|
73 |
||
74 |
typedef int zfs_ioc_func_t(zfs_cmd_t *); |
|
2676 | 75 |
typedef int zfs_secpolicy_func_t(const char *, cred_t *); |
789 | 76 |
|
77 |
typedef struct zfs_ioc_vec { |
|
78 |
zfs_ioc_func_t *zvec_func; |
|
79 |
zfs_secpolicy_func_t *zvec_secpolicy; |
|
80 |
enum { |
|
81 |
no_name, |
|
82 |
pool_name, |
|
83 |
dataset_name |
|
84 |
} zvec_namecheck; |
|
85 |
} zfs_ioc_vec_t; |
|
86 |
||
87 |
/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */ |
|
88 |
void |
|
89 |
__dprintf(const char *file, const char *func, int line, const char *fmt, ...) |
|
90 |
{ |
|
91 |
const char *newfile; |
|
92 |
char buf[256]; |
|
93 |
va_list adx; |
|
94 |
||
95 |
/* |
|
96 |
* Get rid of annoying "../common/" prefix to filename. |
|
97 |
*/ |
|
98 |
newfile = strrchr(file, '/'); |
|
99 |
if (newfile != NULL) { |
|
100 |
newfile = newfile + 1; /* Get rid of leading / */ |
|
101 |
} else { |
|
102 |
newfile = file; |
|
103 |
} |
|
104 |
||
105 |
va_start(adx, fmt); |
|
106 |
(void) vsnprintf(buf, sizeof (buf), fmt, adx); |
|
107 |
va_end(adx); |
|
108 |
||
109 |
/* |
|
110 |
* To get this data, use the zfs-dprintf probe as so: |
|
111 |
* dtrace -q -n 'zfs-dprintf \ |
|
112 |
* /stringof(arg0) == "dbuf.c"/ \ |
|
113 |
* {printf("%s: %s", stringof(arg1), stringof(arg3))}' |
|
114 |
* arg0 = file name |
|
115 |
* arg1 = function name |
|
116 |
* arg2 = line number |
|
117 |
* arg3 = message |
|
118 |
*/ |
|
119 |
DTRACE_PROBE4(zfs__dprintf, |
|
120 |
char *, newfile, char *, func, int, line, char *, buf); |
|
121 |
} |
|
122 |
||
123 |
/* |
|
124 |
* Policy for top-level read operations (list pools). Requires no privileges, |
|
125 |
* and can be used in the local zone, as there is no associated dataset. |
|
126 |
*/ |
|
127 |
/* ARGSUSED */ |
|
128 |
static int |
|
2676 | 129 |
zfs_secpolicy_none(const char *unused1, cred_t *cr) |
789 | 130 |
{ |
131 |
return (0); |
|
132 |
} |
|
133 |
||
134 |
/* |
|
135 |
* Policy for dataset read operations (list children, get statistics). Requires |
|
136 |
* no privileges, but must be visible in the local zone. |
|
137 |
*/ |
|
138 |
/* ARGSUSED */ |
|
139 |
static int |
|
2676 | 140 |
zfs_secpolicy_read(const char *dataset, cred_t *cr) |
789 | 141 |
{ |
142 |
if (INGLOBALZONE(curproc) || |
|
143 |
zone_dataset_visible(dataset, NULL)) |
|
144 |
return (0); |
|
145 |
||
146 |
return (ENOENT); |
|
147 |
} |
|
148 |
||
149 |
static int |
|
150 |
zfs_dozonecheck(const char *dataset, cred_t *cr) |
|
151 |
{ |
|
152 |
uint64_t zoned; |
|
153 |
int writable = 1; |
|
154 |
||
155 |
/* |
|
156 |
* The dataset must be visible by this zone -- check this first |
|
157 |
* so they don't see EPERM on something they shouldn't know about. |
|
158 |
*/ |
|
159 |
if (!INGLOBALZONE(curproc) && |
|
160 |
!zone_dataset_visible(dataset, &writable)) |
|
161 |
return (ENOENT); |
|
162 |
||
163 |
if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL)) |
|
164 |
return (ENOENT); |
|
165 |
||
166 |
if (INGLOBALZONE(curproc)) { |
|
167 |
/* |
|
168 |
* If the fs is zoned, only root can access it from the |
|
169 |
* global zone. |
|
170 |
*/ |
|
171 |
if (secpolicy_zfs(cr) && zoned) |
|
172 |
return (EPERM); |
|
173 |
} else { |
|
174 |
/* |
|
175 |
* If we are in a local zone, the 'zoned' property must be set. |
|
176 |
*/ |
|
177 |
if (!zoned) |
|
178 |
return (EPERM); |
|
179 |
||
180 |
/* must be writable by this zone */ |
|
181 |
if (!writable) |
|
182 |
return (EPERM); |
|
183 |
} |
|
184 |
return (0); |
|
185 |
} |
|
186 |
||
187 |
/* |
|
188 |
* Policy for dataset write operations (create children, set properties, etc). |
|
189 |
* Requires SYS_MOUNT privilege, and must be writable in the local zone. |
|
190 |
*/ |
|
191 |
int |
|
2676 | 192 |
zfs_secpolicy_write(const char *dataset, cred_t *cr) |
789 | 193 |
{ |
194 |
int error; |
|
195 |
||
196 |
if (error = zfs_dozonecheck(dataset, cr)) |
|
197 |
return (error); |
|
198 |
||
199 |
return (secpolicy_zfs(cr)); |
|
200 |
} |
|
201 |
||
202 |
/* |
|
203 |
* Policy for operations that want to write a dataset's parent: |
|
204 |
* create, destroy, snapshot, clone, restore. |
|
205 |
*/ |
|
206 |
static int |
|
2676 | 207 |
zfs_secpolicy_parent(const char *dataset, cred_t *cr) |
789 | 208 |
{ |
209 |
char parentname[MAXNAMELEN]; |
|
210 |
char *cp; |
|
211 |
||
212 |
/* |
|
213 |
* Remove the @bla or /bla from the end of the name to get the parent. |
|
214 |
*/ |
|
215 |
(void) strncpy(parentname, dataset, sizeof (parentname)); |
|
216 |
cp = strrchr(parentname, '@'); |
|
217 |
if (cp != NULL) { |
|
218 |
cp[0] = '\0'; |
|
219 |
} else { |
|
220 |
cp = strrchr(parentname, '/'); |
|
221 |
if (cp == NULL) |
|
222 |
return (ENOENT); |
|
223 |
cp[0] = '\0'; |
|
224 |
||
225 |
} |
|
226 |
||
2676 | 227 |
return (zfs_secpolicy_write(parentname, cr)); |
789 | 228 |
} |
229 |
||
230 |
/* |
|
231 |
* Policy for pool operations - create/destroy pools, add vdevs, etc. Requires |
|
232 |
* SYS_CONFIG privilege, which is not available in a local zone. |
|
233 |
*/ |
|
234 |
/* ARGSUSED */ |
|
235 |
static int |
|
2676 | 236 |
zfs_secpolicy_config(const char *unused, cred_t *cr) |
789 | 237 |
{ |
238 |
if (secpolicy_sys_config(cr, B_FALSE) != 0) |
|
239 |
return (EPERM); |
|
240 |
||
241 |
return (0); |
|
242 |
} |
|
243 |
||
244 |
/* |
|
1544 | 245 |
* Policy for fault injection. Requires all privileges. |
246 |
*/ |
|
247 |
/* ARGSUSED */ |
|
248 |
static int |
|
2676 | 249 |
zfs_secpolicy_inject(const char *unused, cred_t *cr) |
1544 | 250 |
{ |
251 |
return (secpolicy_zinject(cr)); |
|
252 |
} |
|
253 |
||
254 |
/* |
|
789 | 255 |
* Returns the nvlist as specified by the user in the zfs_cmd_t. |
256 |
*/ |
|
257 |
static int |
|
2676 | 258 |
get_nvlist(zfs_cmd_t *zc, nvlist_t **nvp) |
789 | 259 |
{ |
260 |
char *packed; |
|
261 |
size_t size; |
|
262 |
int error; |
|
263 |
nvlist_t *config = NULL; |
|
264 |
||
265 |
/* |
|
2676 | 266 |
* Read in and unpack the user-supplied nvlist. |
789 | 267 |
*/ |
2676 | 268 |
if ((size = zc->zc_nvlist_src_size) == 0) |
789 | 269 |
return (EINVAL); |
270 |
||
271 |
packed = kmem_alloc(size, KM_SLEEP); |
|
272 |
||
2676 | 273 |
if ((error = xcopyin((void *)(uintptr_t)zc->zc_nvlist_src, packed, |
789 | 274 |
size)) != 0) { |
275 |
kmem_free(packed, size); |
|
276 |
return (error); |
|
277 |
} |
|
278 |
||
279 |
if ((error = nvlist_unpack(packed, size, &config, 0)) != 0) { |
|
280 |
kmem_free(packed, size); |
|
281 |
return (error); |
|
282 |
} |
|
283 |
||
284 |
kmem_free(packed, size); |
|
285 |
||
286 |
*nvp = config; |
|
287 |
return (0); |
|
288 |
} |
|
289 |
||
290 |
static int |
|
2676 | 291 |
put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl) |
292 |
{ |
|
293 |
char *packed = NULL; |
|
294 |
size_t size; |
|
295 |
int error; |
|
296 |
||
297 |
VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0); |
|
298 |
||
299 |
if (size > zc->zc_nvlist_dst_size) { |
|
300 |
error = ENOMEM; |
|
301 |
} else { |
|
302 |
VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE, |
|
303 |
KM_SLEEP) == 0); |
|
304 |
error = xcopyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst, |
|
305 |
size); |
|
306 |
kmem_free(packed, size); |
|
307 |
} |
|
308 |
||
309 |
zc->zc_nvlist_dst_size = size; |
|
310 |
return (error); |
|
311 |
} |
|
312 |
||
313 |
static int |
|
789 | 314 |
zfs_ioc_pool_create(zfs_cmd_t *zc) |
315 |
{ |
|
316 |
int error; |
|
317 |
nvlist_t *config; |
|
318 |
||
2676 | 319 |
if ((error = get_nvlist(zc, &config)) != 0) |
789 | 320 |
return (error); |
321 |
||
2676 | 322 |
error = spa_create(zc->zc_name, config, zc->zc_value[0] == '\0' ? |
323 |
NULL : zc->zc_value); |
|
789 | 324 |
|
325 |
nvlist_free(config); |
|
326 |
||
327 |
return (error); |
|
328 |
} |
|
329 |
||
330 |
static int |
|
331 |
zfs_ioc_pool_destroy(zfs_cmd_t *zc) |
|
332 |
{ |
|
333 |
return (spa_destroy(zc->zc_name)); |
|
334 |
} |
|
335 |
||
336 |
static int |
|
337 |
zfs_ioc_pool_import(zfs_cmd_t *zc) |
|
338 |
{ |
|
339 |
int error; |
|
340 |
nvlist_t *config; |
|
341 |
uint64_t guid; |
|
342 |
||
2676 | 343 |
if ((error = get_nvlist(zc, &config)) != 0) |
789 | 344 |
return (error); |
345 |
||
346 |
if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 || |
|
1544 | 347 |
guid != zc->zc_guid) |
789 | 348 |
error = EINVAL; |
349 |
else |
|
350 |
error = spa_import(zc->zc_name, config, |
|
2676 | 351 |
zc->zc_value[0] == '\0' ? NULL : zc->zc_value); |
789 | 352 |
|
353 |
nvlist_free(config); |
|
354 |
||
355 |
return (error); |
|
356 |
} |
|
357 |
||
358 |
static int |
|
359 |
zfs_ioc_pool_export(zfs_cmd_t *zc) |
|
360 |
{ |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
361 |
return (spa_export(zc->zc_name, NULL)); |
789 | 362 |
} |
363 |
||
364 |
static int |
|
365 |
zfs_ioc_pool_configs(zfs_cmd_t *zc) |
|
366 |
{ |
|
367 |
nvlist_t *configs; |
|
368 |
int error; |
|
369 |
||
370 |
if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL) |
|
371 |
return (EEXIST); |
|
372 |
||
2676 | 373 |
error = put_nvlist(zc, configs); |
789 | 374 |
|
375 |
nvlist_free(configs); |
|
376 |
||
377 |
return (error); |
|
378 |
} |
|
379 |
||
380 |
static int |
|
381 |
zfs_ioc_pool_stats(zfs_cmd_t *zc) |
|
382 |
{ |
|
383 |
nvlist_t *config; |
|
384 |
int error; |
|
1544 | 385 |
int ret = 0; |
789 | 386 |
|
2676 | 387 |
error = spa_get_stats(zc->zc_name, &config, zc->zc_value, |
388 |
sizeof (zc->zc_value)); |
|
789 | 389 |
|
390 |
if (config != NULL) { |
|
2676 | 391 |
ret = put_nvlist(zc, config); |
789 | 392 |
nvlist_free(config); |
1544 | 393 |
|
394 |
/* |
|
395 |
* The config may be present even if 'error' is non-zero. |
|
396 |
* In this case we return success, and preserve the real errno |
|
397 |
* in 'zc_cookie'. |
|
398 |
*/ |
|
399 |
zc->zc_cookie = error; |
|
789 | 400 |
} else { |
1544 | 401 |
ret = error; |
789 | 402 |
} |
403 |
||
1544 | 404 |
return (ret); |
789 | 405 |
} |
406 |
||
407 |
/* |
|
408 |
* Try to import the given pool, returning pool stats as appropriate so that |
|
409 |
* user land knows which devices are available and overall pool health. |
|
410 |
*/ |
|
411 |
static int |
|
412 |
zfs_ioc_pool_tryimport(zfs_cmd_t *zc) |
|
413 |
{ |
|
414 |
nvlist_t *tryconfig, *config; |
|
415 |
int error; |
|
416 |
||
2676 | 417 |
if ((error = get_nvlist(zc, &tryconfig)) != 0) |
789 | 418 |
return (error); |
419 |
||
420 |
config = spa_tryimport(tryconfig); |
|
421 |
||
422 |
nvlist_free(tryconfig); |
|
423 |
||
424 |
if (config == NULL) |
|
425 |
return (EINVAL); |
|
426 |
||
2676 | 427 |
error = put_nvlist(zc, config); |
789 | 428 |
nvlist_free(config); |
429 |
||
430 |
return (error); |
|
431 |
} |
|
432 |
||
433 |
static int |
|
434 |
zfs_ioc_pool_scrub(zfs_cmd_t *zc) |
|
435 |
{ |
|
436 |
spa_t *spa; |
|
437 |
int error; |
|
438 |
||
2926 | 439 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
440 |
return (error); |
|
441 |
||
442 |
error = spa_scrub(spa, zc->zc_cookie, B_FALSE); |
|
443 |
||
444 |
spa_close(spa, FTAG); |
|
445 |
||
789 | 446 |
return (error); |
447 |
} |
|
448 |
||
449 |
static int |
|
450 |
zfs_ioc_pool_freeze(zfs_cmd_t *zc) |
|
451 |
{ |
|
452 |
spa_t *spa; |
|
453 |
int error; |
|
454 |
||
455 |
error = spa_open(zc->zc_name, &spa, FTAG); |
|
456 |
if (error == 0) { |
|
457 |
spa_freeze(spa); |
|
458 |
spa_close(spa, FTAG); |
|
459 |
} |
|
460 |
return (error); |
|
461 |
} |
|
462 |
||
463 |
static int |
|
1760 | 464 |
zfs_ioc_pool_upgrade(zfs_cmd_t *zc) |
465 |
{ |
|
466 |
spa_t *spa; |
|
467 |
int error; |
|
468 |
||
2926 | 469 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
470 |
return (error); |
|
471 |
||
472 |
spa_upgrade(spa); |
|
473 |
||
474 |
spa_close(spa, FTAG); |
|
475 |
||
476 |
return (error); |
|
477 |
} |
|
478 |
||
479 |
static int |
|
480 |
zfs_ioc_pool_get_history(zfs_cmd_t *zc) |
|
481 |
{ |
|
482 |
spa_t *spa; |
|
483 |
char *hist_buf; |
|
484 |
uint64_t size; |
|
485 |
int error; |
|
486 |
||
487 |
if ((size = zc->zc_history_len) == 0) |
|
488 |
return (EINVAL); |
|
489 |
||
490 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
|
491 |
return (error); |
|
492 |
||
3863
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
493 |
if (spa_version(spa) < ZFS_VERSION_ZPOOL_HISTORY) { |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
494 |
spa_close(spa, FTAG); |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
495 |
return (ENOTSUP); |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
496 |
} |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
497 |
|
2926 | 498 |
hist_buf = kmem_alloc(size, KM_SLEEP); |
499 |
if ((error = spa_history_get(spa, &zc->zc_history_offset, |
|
500 |
&zc->zc_history_len, hist_buf)) == 0) { |
|
501 |
error = xcopyout(hist_buf, (char *)(uintptr_t)zc->zc_history, |
|
502 |
zc->zc_history_len); |
|
503 |
} |
|
504 |
||
505 |
spa_close(spa, FTAG); |
|
506 |
kmem_free(hist_buf, size); |
|
507 |
return (error); |
|
508 |
} |
|
509 |
||
510 |
static int |
|
511 |
zfs_ioc_pool_log_history(zfs_cmd_t *zc) |
|
512 |
{ |
|
513 |
spa_t *spa; |
|
514 |
char *history_str = NULL; |
|
515 |
size_t size; |
|
516 |
int error; |
|
517 |
||
518 |
size = zc->zc_history_len; |
|
519 |
if (size == 0 || size > HIS_MAX_RECORD_LEN) |
|
520 |
return (EINVAL); |
|
521 |
||
522 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
|
523 |
return (error); |
|
524 |
||
3863
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
525 |
if (spa_version(spa) < ZFS_VERSION_ZPOOL_HISTORY) { |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
526 |
spa_close(spa, FTAG); |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
527 |
return (ENOTSUP); |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
528 |
} |
d56571426115
6529406 zpool history needs to bump the on-disk version
ek110237
parents:
3741
diff
changeset
|
529 |
|
2926 | 530 |
/* add one for the NULL delimiter */ |
531 |
size++; |
|
532 |
history_str = kmem_alloc(size, KM_SLEEP); |
|
533 |
if ((error = xcopyin((void *)(uintptr_t)zc->zc_history, history_str, |
|
534 |
size)) != 0) { |
|
1760 | 535 |
spa_close(spa, FTAG); |
2926 | 536 |
kmem_free(history_str, size); |
537 |
return (error); |
|
1760 | 538 |
} |
2926 | 539 |
history_str[size - 1] = '\0'; |
540 |
||
541 |
error = spa_history_log(spa, history_str, zc->zc_history_offset); |
|
542 |
||
543 |
spa_close(spa, FTAG); |
|
544 |
kmem_free(history_str, size); |
|
545 |
||
1760 | 546 |
return (error); |
547 |
} |
|
548 |
||
549 |
static int |
|
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
550 |
zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc) |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
551 |
{ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
552 |
int error; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
553 |
|
3912 | 554 |
if (error = dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value)) |
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
555 |
return (error); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
556 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
557 |
return (0); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
558 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
559 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
560 |
static int |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
561 |
zfs_ioc_obj_to_path(zfs_cmd_t *zc) |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
562 |
{ |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
563 |
objset_t *osp; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
564 |
int error; |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
565 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
566 |
if ((error = dmu_objset_open(zc->zc_name, DMU_OST_ZFS, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
567 |
DS_MODE_NONE | DS_MODE_READONLY, &osp)) != 0) |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
568 |
return (error); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
569 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
570 |
error = zfs_obj_to_path(osp, zc->zc_obj, zc->zc_value, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
571 |
sizeof (zc->zc_value)); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
572 |
dmu_objset_close(osp); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
573 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
574 |
return (error); |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
575 |
} |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
576 |
|
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
577 |
static int |
789 | 578 |
zfs_ioc_vdev_add(zfs_cmd_t *zc) |
579 |
{ |
|
580 |
spa_t *spa; |
|
581 |
int error; |
|
582 |
nvlist_t *config; |
|
583 |
||
584 |
error = spa_open(zc->zc_name, &spa, FTAG); |
|
585 |
if (error != 0) |
|
586 |
return (error); |
|
587 |
||
3912 | 588 |
/* |
589 |
* A root pool with concatenated devices is not supported. |
|
590 |
* Thus, can not add a device to a root pool with one device. |
|
591 |
*/ |
|
592 |
if (spa->spa_root_vdev->vdev_children == 1 && spa->spa_bootfs != 0) { |
|
593 |
spa_close(spa, FTAG); |
|
594 |
return (EDOM); |
|
595 |
} |
|
596 |
||
2676 | 597 |
if ((error = get_nvlist(zc, &config)) == 0) { |
789 | 598 |
error = spa_vdev_add(spa, config); |
599 |
nvlist_free(config); |
|
600 |
} |
|
601 |
||
602 |
spa_close(spa, FTAG); |
|
603 |
return (error); |
|
604 |
} |
|
605 |
||
606 |
static int |
|
607 |
zfs_ioc_vdev_remove(zfs_cmd_t *zc) |
|
608 |
{ |
|
2082 | 609 |
spa_t *spa; |
610 |
int error; |
|
611 |
||
612 |
error = spa_open(zc->zc_name, &spa, FTAG); |
|
613 |
if (error != 0) |
|
614 |
return (error); |
|
615 |
error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE); |
|
616 |
spa_close(spa, FTAG); |
|
617 |
return (error); |
|
789 | 618 |
} |
619 |
||
620 |
static int |
|
621 |
zfs_ioc_vdev_online(zfs_cmd_t *zc) |
|
622 |
{ |
|
623 |
spa_t *spa; |
|
624 |
int error; |
|
625 |
||
2926 | 626 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
789 | 627 |
return (error); |
1544 | 628 |
error = vdev_online(spa, zc->zc_guid); |
789 | 629 |
spa_close(spa, FTAG); |
630 |
return (error); |
|
631 |
} |
|
632 |
||
633 |
static int |
|
634 |
zfs_ioc_vdev_offline(zfs_cmd_t *zc) |
|
635 |
{ |
|
636 |
spa_t *spa; |
|
1485 | 637 |
int istmp = zc->zc_cookie; |
789 | 638 |
int error; |
639 |
||
2926 | 640 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
789 | 641 |
return (error); |
1544 | 642 |
error = vdev_offline(spa, zc->zc_guid, istmp); |
789 | 643 |
spa_close(spa, FTAG); |
644 |
return (error); |
|
645 |
} |
|
646 |
||
647 |
static int |
|
648 |
zfs_ioc_vdev_attach(zfs_cmd_t *zc) |
|
649 |
{ |
|
650 |
spa_t *spa; |
|
651 |
int replacing = zc->zc_cookie; |
|
652 |
nvlist_t *config; |
|
653 |
int error; |
|
654 |
||
2926 | 655 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
789 | 656 |
return (error); |
657 |
||
2676 | 658 |
if ((error = get_nvlist(zc, &config)) == 0) { |
1544 | 659 |
error = spa_vdev_attach(spa, zc->zc_guid, config, replacing); |
789 | 660 |
nvlist_free(config); |
661 |
} |
|
662 |
||
663 |
spa_close(spa, FTAG); |
|
664 |
return (error); |
|
665 |
} |
|
666 |
||
667 |
static int |
|
668 |
zfs_ioc_vdev_detach(zfs_cmd_t *zc) |
|
669 |
{ |
|
670 |
spa_t *spa; |
|
671 |
int error; |
|
672 |
||
2926 | 673 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
789 | 674 |
return (error); |
675 |
||
1544 | 676 |
error = spa_vdev_detach(spa, zc->zc_guid, B_FALSE); |
789 | 677 |
|
678 |
spa_close(spa, FTAG); |
|
679 |
return (error); |
|
680 |
} |
|
681 |
||
682 |
static int |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
683 |
zfs_ioc_vdev_setpath(zfs_cmd_t *zc) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
684 |
{ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
685 |
spa_t *spa; |
2676 | 686 |
char *path = zc->zc_value; |
1544 | 687 |
uint64_t guid = zc->zc_guid; |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
688 |
int error; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
689 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
690 |
error = spa_open(zc->zc_name, &spa, FTAG); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
691 |
if (error != 0) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
692 |
return (error); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
693 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
694 |
error = spa_vdev_setpath(spa, guid, path); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
695 |
spa_close(spa, FTAG); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
696 |
return (error); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
697 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
698 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
699 |
static int |
789 | 700 |
zfs_ioc_objset_stats(zfs_cmd_t *zc) |
701 |
{ |
|
702 |
objset_t *os = NULL; |
|
703 |
int error; |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1354
diff
changeset
|
704 |
nvlist_t *nv; |
789 | 705 |
|
706 |
retry: |
|
707 |
error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, |
|
708 |
DS_MODE_STANDARD | DS_MODE_READONLY, &os); |
|
709 |
if (error != 0) { |
|
710 |
/* |
|
711 |
* This is ugly: dmu_objset_open() can return EBUSY if |
|
712 |
* the objset is held exclusively. Fortunately this hold is |
|
713 |
* only for a short while, so we retry here. |
|
714 |
* This avoids user code having to handle EBUSY, |
|
715 |
* for example for a "zfs list". |
|
716 |
*/ |
|
717 |
if (error == EBUSY) { |
|
718 |
delay(1); |
|
719 |
goto retry; |
|
720 |
} |
|
721 |
return (error); |
|
722 |
} |
|
723 |
||
2885 | 724 |
dmu_objset_fast_stat(os, &zc->zc_objset_stats); |
789 | 725 |
|
2856 | 726 |
if (zc->zc_nvlist_dst != 0 && |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1354
diff
changeset
|
727 |
(error = dsl_prop_get_all(os, &nv)) == 0) { |
2885 | 728 |
dmu_objset_stats(os, nv); |
3087 | 729 |
/* |
730 |
* NB: zvol_get_stats() will read the objset contents, |
|
731 |
* which we aren't supposed to do with a |
|
732 |
* DS_MODE_STANDARD open, because it could be |
|
733 |
* inconsistent. So this is a bit of a workaround... |
|
734 |
*/ |
|
735 |
if (!zc->zc_objset_stats.dds_inconsistent && |
|
736 |
dmu_objset_type(os) == DMU_OST_ZVOL) |
|
2885 | 737 |
VERIFY(zvol_get_stats(os, nv) == 0); |
2676 | 738 |
error = put_nvlist(zc, nv); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1354
diff
changeset
|
739 |
nvlist_free(nv); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1354
diff
changeset
|
740 |
} |
789 | 741 |
|
2676 | 742 |
spa_altroot(dmu_objset_spa(os), zc->zc_value, sizeof (zc->zc_value)); |
1544 | 743 |
|
789 | 744 |
dmu_objset_close(os); |
745 |
return (error); |
|
746 |
} |
|
747 |
||
748 |
static int |
|
749 |
zfs_ioc_dataset_list_next(zfs_cmd_t *zc) |
|
750 |
{ |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
751 |
objset_t *os; |
789 | 752 |
int error; |
753 |
char *p; |
|
754 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
755 |
retry: |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
756 |
error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
757 |
DS_MODE_STANDARD | DS_MODE_READONLY, &os); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
758 |
if (error != 0) { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
759 |
/* |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
760 |
* This is ugly: dmu_objset_open() can return EBUSY if |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
761 |
* the objset is held exclusively. Fortunately this hold is |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
762 |
* only for a short while, so we retry here. |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
763 |
* This avoids user code having to handle EBUSY, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
764 |
* for example for a "zfs list". |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
765 |
*/ |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
766 |
if (error == EBUSY) { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
767 |
delay(1); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
768 |
goto retry; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
769 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
770 |
if (error == ENOENT) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
771 |
error = ESRCH; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
772 |
return (error); |
789 | 773 |
} |
774 |
||
775 |
p = strrchr(zc->zc_name, '/'); |
|
776 |
if (p == NULL || p[1] != '\0') |
|
777 |
(void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name)); |
|
778 |
p = zc->zc_name + strlen(zc->zc_name); |
|
779 |
||
780 |
do { |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
781 |
error = dmu_dir_list_next(os, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
782 |
sizeof (zc->zc_name) - (p - zc->zc_name), p, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
783 |
NULL, &zc->zc_cookie); |
789 | 784 |
if (error == ENOENT) |
785 |
error = ESRCH; |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
786 |
} while (error == 0 && !INGLOBALZONE(curproc) && |
789 | 787 |
!zone_dataset_visible(zc->zc_name, NULL)); |
788 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
789 |
/* |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
790 |
* If it's a hidden dataset (ie. with a '$' in its name), don't |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
791 |
* try to get stats for it. Userland will skip over it. |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
792 |
*/ |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
793 |
if (error == 0 && strchr(zc->zc_name, '$') == NULL) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
794 |
error = zfs_ioc_objset_stats(zc); /* fill in the stats */ |
789 | 795 |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
796 |
dmu_objset_close(os); |
789 | 797 |
return (error); |
798 |
} |
|
799 |
||
800 |
static int |
|
801 |
zfs_ioc_snapshot_list_next(zfs_cmd_t *zc) |
|
802 |
{ |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
803 |
objset_t *os; |
789 | 804 |
int error; |
805 |
||
806 |
retry: |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
807 |
error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
808 |
DS_MODE_STANDARD | DS_MODE_READONLY, &os); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
809 |
if (error != 0) { |
789 | 810 |
/* |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
811 |
* This is ugly: dmu_objset_open() can return EBUSY if |
789 | 812 |
* the objset is held exclusively. Fortunately this hold is |
813 |
* only for a short while, so we retry here. |
|
814 |
* This avoids user code having to handle EBUSY, |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
815 |
* for example for a "zfs list". |
789 | 816 |
*/ |
817 |
if (error == EBUSY) { |
|
818 |
delay(1); |
|
819 |
goto retry; |
|
820 |
} |
|
821 |
if (error == ENOENT) |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
822 |
error = ESRCH; |
789 | 823 |
return (error); |
824 |
} |
|
825 |
||
1003 | 826 |
/* |
827 |
* A dataset name of maximum length cannot have any snapshots, |
|
828 |
* so exit immediately. |
|
829 |
*/ |
|
830 |
if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) { |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
831 |
dmu_objset_close(os); |
1003 | 832 |
return (ESRCH); |
789 | 833 |
} |
834 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
835 |
error = dmu_snapshot_list_next(os, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
836 |
sizeof (zc->zc_name) - strlen(zc->zc_name), |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
837 |
zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie); |
789 | 838 |
if (error == ENOENT) |
839 |
error = ESRCH; |
|
840 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
841 |
if (error == 0) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
842 |
error = zfs_ioc_objset_stats(zc); /* fill in the stats */ |
789 | 843 |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
849
diff
changeset
|
844 |
dmu_objset_close(os); |
789 | 845 |
return (error); |
846 |
} |
|
847 |
||
848 |
static int |
|
2676 | 849 |
zfs_set_prop_nvlist(const char *name, dev_t dev, cred_t *cr, nvlist_t *nvl) |
789 | 850 |
{ |
2676 | 851 |
nvpair_t *elem; |
852 |
int error; |
|
853 |
const char *propname; |
|
854 |
zfs_prop_t prop; |
|
855 |
uint64_t intval; |
|
856 |
char *strval; |
|
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
857 |
char buf[MAXNAMELEN]; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
858 |
const char *p; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
859 |
spa_t *spa; |
2676 | 860 |
|
861 |
elem = NULL; |
|
862 |
while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { |
|
863 |
propname = nvpair_name(elem); |
|
864 |
||
865 |
if ((prop = zfs_name_to_prop(propname)) == |
|
866 |
ZFS_PROP_INVAL) { |
|
867 |
/* |
|
868 |
* If this is a user-defined property, it must be a |
|
869 |
* string, and there is no further validation to do. |
|
870 |
*/ |
|
871 |
if (!zfs_prop_user(propname) || |
|
872 |
nvpair_type(elem) != DATA_TYPE_STRING) |
|
873 |
return (EINVAL); |
|
874 |
||
875 |
VERIFY(nvpair_value_string(elem, &strval) == 0); |
|
876 |
error = dsl_prop_set(name, propname, 1, |
|
877 |
strlen(strval) + 1, strval); |
|
878 |
if (error == 0) |
|
879 |
continue; |
|
880 |
else |
|
3741
806e933bf124
6441384 zpool import action message is not correctly localized
mmusante
parents:
3638
diff
changeset
|
881 |
return (error); |
2676 | 882 |
} |
883 |
||
884 |
/* |
|
885 |
* Check permissions for special properties. |
|
886 |
*/ |
|
887 |
switch (prop) { |
|
888 |
case ZFS_PROP_ZONED: |
|
889 |
/* |
|
890 |
* Disallow setting of 'zoned' from within a local zone. |
|
891 |
*/ |
|
892 |
if (!INGLOBALZONE(curproc)) |
|
893 |
return (EPERM); |
|
894 |
break; |
|
895 |
||
896 |
case ZFS_PROP_QUOTA: |
|
897 |
if (error = zfs_dozonecheck(name, cr)) |
|
898 |
return (error); |
|
899 |
||
900 |
if (!INGLOBALZONE(curproc)) { |
|
901 |
uint64_t zoned; |
|
902 |
char setpoint[MAXNAMELEN]; |
|
903 |
int dslen; |
|
904 |
/* |
|
905 |
* Unprivileged users are allowed to modify the |
|
906 |
* quota on things *under* (ie. contained by) |
|
907 |
* the thing they own. |
|
908 |
*/ |
|
909 |
if (dsl_prop_get_integer(name, "zoned", &zoned, |
|
910 |
setpoint)) |
|
911 |
return (EPERM); |
|
912 |
if (!zoned) /* this shouldn't happen */ |
|
913 |
return (EPERM); |
|
914 |
dslen = strlen(name); |
|
915 |
if (dslen <= strlen(setpoint)) |
|
916 |
return (EPERM); |
|
917 |
} |
|
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
918 |
break; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
919 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
920 |
case ZFS_PROP_COMPRESSION: |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
921 |
/* |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
922 |
* If the user specified gzip compression, make sure |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
923 |
* the SPA supports it. We ignore any errors here since |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
924 |
* we'll catch them later. |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
925 |
*/ |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
926 |
if (nvpair_type(elem) == DATA_TYPE_UINT64 && |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
927 |
nvpair_value_uint64(elem, &intval) == 0 && |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
928 |
intval >= ZIO_COMPRESS_GZIP_1 && |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
929 |
intval <= ZIO_COMPRESS_GZIP_9) { |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
930 |
if ((p = strchr(name, '/')) == NULL) { |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
931 |
p = name; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
932 |
} else { |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
933 |
bcopy(name, buf, p - name); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
934 |
buf[p - name] = '\0'; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
935 |
p = buf; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
936 |
} |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
937 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
938 |
if (spa_open(p, &spa, FTAG) == 0) { |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
939 |
if (spa_version(spa) < |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
940 |
ZFS_VERSION_GZIP_COMPRESSION) { |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
941 |
spa_close(spa, FTAG); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
942 |
return (ENOTSUP); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
943 |
} |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
944 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
945 |
spa_close(spa, FTAG); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
946 |
} |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
947 |
} |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3863
diff
changeset
|
948 |
break; |
2676 | 949 |
} |
950 |
||
951 |
switch (prop) { |
|
952 |
case ZFS_PROP_QUOTA: |
|
953 |
if ((error = nvpair_value_uint64(elem, &intval)) != 0 || |
|
954 |
(error = dsl_dir_set_quota(name, |
|
955 |
intval)) != 0) |
|
956 |
return (error); |
|
957 |
break; |
|
958 |
||
959 |
case ZFS_PROP_RESERVATION: |
|
960 |
if ((error = nvpair_value_uint64(elem, &intval)) != 0 || |
|
961 |
(error = dsl_dir_set_reservation(name, |
|
962 |
intval)) != 0) |
|
963 |
return (error); |
|
964 |
break; |
|
789 | 965 |
|
2676 | 966 |
case ZFS_PROP_VOLSIZE: |
967 |
if ((error = nvpair_value_uint64(elem, &intval)) != 0 || |
|
968 |
(error = zvol_set_volsize(name, dev, |
|
969 |
intval)) != 0) |
|
970 |
return (error); |
|
971 |
break; |
|
972 |
||
973 |
case ZFS_PROP_VOLBLOCKSIZE: |
|
974 |
if ((error = nvpair_value_uint64(elem, &intval)) != 0 || |
|
975 |
(error = zvol_set_volblocksize(name, |
|
976 |
intval)) != 0) |
|
977 |
return (error); |
|
978 |
break; |
|
979 |
||
980 |
default: |
|
981 |
if (nvpair_type(elem) == DATA_TYPE_STRING) { |
|
982 |
if (zfs_prop_get_type(prop) != |
|
983 |
prop_type_string) |
|
984 |
return (EINVAL); |
|
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
985 |
VERIFY(nvpair_value_string(elem, &strval) == 0); |
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
986 |
if ((error = dsl_prop_set(name, |
2676 | 987 |
nvpair_name(elem), 1, strlen(strval) + 1, |
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
988 |
strval)) != 0) |
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
989 |
return (error); |
2676 | 990 |
} else if (nvpair_type(elem) == DATA_TYPE_UINT64) { |
2885 | 991 |
const char *unused; |
992 |
||
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
993 |
VERIFY(nvpair_value_uint64(elem, &intval) == 0); |
2676 | 994 |
|
995 |
switch (zfs_prop_get_type(prop)) { |
|
996 |
case prop_type_number: |
|
997 |
break; |
|
998 |
case prop_type_boolean: |
|
999 |
if (intval > 1) |
|
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1000 |
return (EINVAL); |
2676 | 1001 |
break; |
1002 |
case prop_type_string: |
|
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1003 |
return (EINVAL); |
2676 | 1004 |
case prop_type_index: |
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1005 |
if (zfs_prop_index_to_string(prop, |
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1006 |
intval, &unused) != 0) |
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1007 |
return (EINVAL); |
2676 | 1008 |
break; |
1009 |
default: |
|
1010 |
cmn_err(CE_PANIC, "unknown property " |
|
1011 |
"type"); |
|
1012 |
break; |
|
1013 |
} |
|
1014 |
||
2717
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1015 |
if ((error = dsl_prop_set(name, propname, |
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1016 |
8, 1, &intval)) != 0) |
ed589a32259d
6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents:
2676
diff
changeset
|
1017 |
return (error); |
2676 | 1018 |
} else { |
1019 |
return (EINVAL); |
|
1020 |
} |
|
1021 |
break; |
|
1022 |
} |
|
1023 |
} |
|
1024 |
||
1025 |
return (0); |
|
789 | 1026 |
} |
1027 |
||
1028 |
static int |
|
2676 | 1029 |
zfs_ioc_set_prop(zfs_cmd_t *zc) |
789 | 1030 |
{ |
2676 | 1031 |
nvlist_t *nvl; |
1032 |
int error; |
|
1033 |
zfs_prop_t prop; |
|
789 | 1034 |
|
2676 | 1035 |
/* |
1036 |
* If zc_value is set, then this is an attempt to inherit a value. |
|
1037 |
* Otherwise, zc_nvlist refers to a list of properties to set. |
|
1038 |
*/ |
|
1039 |
if (zc->zc_value[0] != '\0') { |
|
1040 |
if (!zfs_prop_user(zc->zc_value) && |
|
1041 |
((prop = zfs_name_to_prop(zc->zc_value)) == |
|
1042 |
ZFS_PROP_INVAL || |
|
1043 |
!zfs_prop_inheritable(prop))) |
|
1044 |
return (EINVAL); |
|
1045 |
||
1046 |
return (dsl_prop_set(zc->zc_name, zc->zc_value, 0, 0, NULL)); |
|
1047 |
} |
|
1048 |
||
1049 |
if ((error = get_nvlist(zc, &nvl)) != 0) |
|
1050 |
return (error); |
|
1051 |
||
1052 |
error = zfs_set_prop_nvlist(zc->zc_name, zc->zc_dev, |
|
1053 |
(cred_t *)(uintptr_t)zc->zc_cred, nvl); |
|
1054 |
nvlist_free(nvl); |
|
1055 |
return (error); |
|
789 | 1056 |
} |
1057 |
||
1058 |
static int |
|
4098
0a182c2128e6
6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents:
4007
diff
changeset
|
1059 |
zfs_ioc_pool_set_props(zfs_cmd_t *zc) |
3912 | 1060 |
{ |
1061 |
nvlist_t *nvl; |
|
1062 |
int error, reset_bootfs = 0; |
|
1063 |
uint64_t objnum; |
|
1064 |
zpool_prop_t prop; |
|
1065 |
nvpair_t *elem; |
|
1066 |
char *propname, *strval; |
|
1067 |
spa_t *spa; |
|
1068 |
vdev_t *rvdev; |
|
1069 |
char *vdev_type; |
|
1070 |
objset_t *os; |
|
1071 |
||
1072 |
if ((error = get_nvlist(zc, &nvl)) != 0) |
|
1073 |
return (error); |
|
1074 |
||
1075 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) { |
|
1076 |
nvlist_free(nvl); |
|
1077 |
return (error); |
|
1078 |
} |
|
1079 |
||
1080 |
if (spa_version(spa) < ZFS_VERSION_BOOTFS) { |
|
1081 |
nvlist_free(nvl); |
|
1082 |
spa_close(spa, FTAG); |
|
1083 |
return (ENOTSUP); |
|
1084 |
} |
|
1085 |
||
1086 |
elem = NULL; |
|
1087 |
while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { |
|
1088 |
||
1089 |
propname = nvpair_name(elem); |
|
1090 |
||
1091 |
if ((prop = zpool_name_to_prop(propname)) == |
|
1092 |
ZFS_PROP_INVAL) { |
|
1093 |
nvlist_free(nvl); |
|
1094 |
spa_close(spa, FTAG); |
|
1095 |
return (EINVAL); |
|
1096 |
} |
|
1097 |
||
1098 |
switch (prop) { |
|
1099 |
case ZFS_PROP_BOOTFS: |
|
1100 |
/* |
|
1101 |
* A bootable filesystem can not be on a RAIDZ pool |
|
1102 |
* nor a striped pool with more than 1 device. |
|
1103 |
*/ |
|
1104 |
rvdev = spa->spa_root_vdev; |
|
1105 |
vdev_type = |
|
1106 |
rvdev->vdev_child[0]->vdev_ops->vdev_op_type; |
|
1107 |
if (strcmp(vdev_type, VDEV_TYPE_RAIDZ) == 0 || |
|
1108 |
(strcmp(vdev_type, VDEV_TYPE_MIRROR) != 0 && |
|
1109 |
rvdev->vdev_children > 1)) { |
|
1110 |
error = ENOTSUP; |
|
1111 |
break; |
|
1112 |
} |
|
1113 |
||
1114 |
reset_bootfs = 1; |
|
1115 |
||
1116 |
VERIFY(nvpair_value_string(elem, &strval) == 0); |
|
1117 |
if (strval == NULL || strval[0] == '\0') { |
|
1118 |
objnum = |
|
1119 |
zfs_prop_default_numeric(ZFS_PROP_BOOTFS); |
|
1120 |
break; |
|
1121 |
} |
|
1122 |
||
1123 |
if (error = dmu_objset_open(strval, DMU_OST_ZFS, |
|
1124 |
DS_MODE_STANDARD | DS_MODE_READONLY, &os)) |
|
1125 |
break; |
|
1126 |
objnum = dmu_objset_id(os); |
|
1127 |
dmu_objset_close(os); |
|
1128 |
break; |
|
1129 |
||
1130 |
default: |
|
1131 |
error = EINVAL; |
|
1132 |
} |
|
1133 |
||
1134 |
if (error) |
|
1135 |
break; |
|
1136 |
} |
|
1137 |
if (error == 0) { |
|
1138 |
if (reset_bootfs) { |
|
1139 |
VERIFY(nvlist_remove(nvl, |
|
1140 |
zpool_prop_to_name(ZFS_PROP_BOOTFS), |
|
1141 |
DATA_TYPE_STRING) == 0); |
|
1142 |
VERIFY(nvlist_add_uint64(nvl, |
|
1143 |
zpool_prop_to_name(ZFS_PROP_BOOTFS), objnum) == 0); |
|
1144 |
} |
|
1145 |
error = spa_set_props(spa, nvl); |
|
1146 |
} |
|
1147 |
||
1148 |
nvlist_free(nvl); |
|
1149 |
spa_close(spa, FTAG); |
|
1150 |
||
1151 |
return (error); |
|
1152 |
} |
|
1153 |
||
1154 |
static int |
|
4098
0a182c2128e6
6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents:
4007
diff
changeset
|
1155 |
zfs_ioc_pool_get_props(zfs_cmd_t *zc) |
3912 | 1156 |
{ |
1157 |
spa_t *spa; |
|
1158 |
int error; |
|
1159 |
nvlist_t *nvp = NULL; |
|
1160 |
||
1161 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
|
1162 |
return (error); |
|
1163 |
||
1164 |
error = spa_get_props(spa, &nvp); |
|
1165 |
||
1166 |
if (error == 0 && zc->zc_nvlist_dst != NULL) |
|
1167 |
error = put_nvlist(zc, nvp); |
|
1168 |
else |
|
1169 |
error = EFAULT; |
|
1170 |
||
1171 |
spa_close(spa, FTAG); |
|
1172 |
||
1173 |
if (nvp) |
|
1174 |
nvlist_free(nvp); |
|
1175 |
return (error); |
|
1176 |
} |
|
1177 |
||
1178 |
static int |
|
789 | 1179 |
zfs_ioc_create_minor(zfs_cmd_t *zc) |
1180 |
{ |
|
2676 | 1181 |
return (zvol_create_minor(zc->zc_name, zc->zc_dev)); |
789 | 1182 |
} |
1183 |
||
1184 |
static int |
|
1185 |
zfs_ioc_remove_minor(zfs_cmd_t *zc) |
|
1186 |
{ |
|
2676 | 1187 |
return (zvol_remove_minor(zc->zc_name)); |
789 | 1188 |
} |
1189 |
||
1190 |
/* |
|
1191 |
* Search the vfs list for a specified resource. Returns a pointer to it |
|
1192 |
* or NULL if no suitable entry is found. The caller of this routine |
|
1193 |
* is responsible for releasing the returned vfs pointer. |
|
1194 |
*/ |
|
1195 |
static vfs_t * |
|
1196 |
zfs_get_vfs(const char *resource) |
|
1197 |
{ |
|
1198 |
struct vfs *vfsp; |
|
1199 |
struct vfs *vfs_found = NULL; |
|
1200 |
||
1201 |
vfs_list_read_lock(); |
|
1202 |
vfsp = rootvfs; |
|
1203 |
do { |
|
1204 |
if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) { |
|
1205 |
VFS_HOLD(vfsp); |
|
1206 |
vfs_found = vfsp; |
|
1207 |
break; |
|
1208 |
} |
|
1209 |
vfsp = vfsp->vfs_next; |
|
1210 |
} while (vfsp != rootvfs); |
|
1211 |
vfs_list_unlock(); |
|
1212 |
return (vfs_found); |
|
1213 |
} |
|
1214 |
||
1215 |
static void |
|
1216 |
zfs_create_cb(objset_t *os, void *arg, dmu_tx_t *tx) |
|
1217 |
{ |
|
2676 | 1218 |
zfs_create_data_t *zc = arg; |
789 | 1219 |
zfs_create_fs(os, (cred_t *)(uintptr_t)zc->zc_cred, tx); |
1220 |
} |
|
1221 |
||
1222 |
static int |
|
1223 |
zfs_ioc_create(zfs_cmd_t *zc) |
|
1224 |
{ |
|
1225 |
objset_t *clone; |
|
1226 |
int error = 0; |
|
2676 | 1227 |
zfs_create_data_t cbdata = { 0 }; |
789 | 1228 |
void (*cbfunc)(objset_t *os, void *arg, dmu_tx_t *tx); |
1229 |
dmu_objset_type_t type = zc->zc_objset_type; |
|
1230 |
||
1231 |
switch (type) { |
|
1232 |
||
1233 |
case DMU_OST_ZFS: |
|
1234 |
cbfunc = zfs_create_cb; |
|
1235 |
break; |
|
1236 |
||
1237 |
case DMU_OST_ZVOL: |
|
1238 |
cbfunc = zvol_create_cb; |
|
1239 |
break; |
|
1240 |
||
1241 |
default: |
|
2199 | 1242 |
cbfunc = NULL; |
1243 |
} |
|
1244 |
if (strchr(zc->zc_name, '@')) |
|
789 | 1245 |
return (EINVAL); |
1246 |
||
2676 | 1247 |
if (zc->zc_nvlist_src != NULL && |
1248 |
(error = get_nvlist(zc, &cbdata.zc_props)) != 0) |
|
1249 |
return (error); |
|
1250 |
||
1251 |
cbdata.zc_cred = (cred_t *)(uintptr_t)zc->zc_cred; |
|
1252 |
cbdata.zc_dev = (dev_t)zc->zc_dev; |
|
1253 |
||
1254 |
if (zc->zc_value[0] != '\0') { |
|
789 | 1255 |
/* |
1256 |
* We're creating a clone of an existing snapshot. |
|
1257 |
*/ |
|
2676 | 1258 |
zc->zc_value[sizeof (zc->zc_value) - 1] = '\0'; |
1259 |
if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) { |
|
1260 |
nvlist_free(cbdata.zc_props); |
|
789 | 1261 |
return (EINVAL); |
2676 | 1262 |
} |
789 | 1263 |
|
2676 | 1264 |
error = dmu_objset_open(zc->zc_value, type, |
789 | 1265 |
DS_MODE_STANDARD | DS_MODE_READONLY, &clone); |
2676 | 1266 |
if (error) { |
1267 |
nvlist_free(cbdata.zc_props); |
|
789 | 1268 |
return (error); |
2676 | 1269 |
} |
789 | 1270 |
error = dmu_objset_create(zc->zc_name, type, clone, NULL, NULL); |
1271 |
dmu_objset_close(clone); |
|
1272 |
} else { |
|
2676 | 1273 |
if (cbfunc == NULL) { |
1274 |
nvlist_free(cbdata.zc_props); |
|
2199 | 1275 |
return (EINVAL); |
2676 | 1276 |
} |
1277 |
||
789 | 1278 |
if (type == DMU_OST_ZVOL) { |
2676 | 1279 |
uint64_t volsize, volblocksize; |
1280 |
||
1281 |
if (cbdata.zc_props == NULL || |
|
1282 |
nvlist_lookup_uint64(cbdata.zc_props, |
|
1283 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE), |
|
1284 |
&volsize) != 0) { |
|
1285 |
nvlist_free(cbdata.zc_props); |
|
1286 |
return (EINVAL); |
|
1287 |
} |
|
1288 |
||
1289 |
if ((error = nvlist_lookup_uint64(cbdata.zc_props, |
|
1290 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), |
|
1291 |
&volblocksize)) != 0 && error != ENOENT) { |
|
1292 |
nvlist_free(cbdata.zc_props); |
|
1293 |
return (EINVAL); |
|
1294 |
} |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
1295 |
|
2676 | 1296 |
if (error != 0) |
1297 |
volblocksize = zfs_prop_default_numeric( |
|
1298 |
ZFS_PROP_VOLBLOCKSIZE); |
|
1299 |
||
1300 |
if ((error = zvol_check_volblocksize( |
|
1301 |
volblocksize)) != 0 || |
|
1302 |
(error = zvol_check_volsize(volsize, |
|
1303 |
volblocksize)) != 0) { |
|
1304 |
nvlist_free(cbdata.zc_props); |
|
789 | 1305 |
return (error); |
2676 | 1306 |
} |
1307 |
} |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
1308 |
|
2676 | 1309 |
error = dmu_objset_create(zc->zc_name, type, NULL, cbfunc, |
1310 |
&cbdata); |
|
789 | 1311 |
} |
2676 | 1312 |
|
1313 |
/* |
|
1314 |
* It would be nice to do this atomically. |
|
1315 |
*/ |
|
1316 |
if (error == 0) { |
|
1317 |
if ((error = zfs_set_prop_nvlist(zc->zc_name, |
|
1318 |
zc->zc_dev, (cred_t *)(uintptr_t)zc->zc_cred, |
|
1319 |
cbdata.zc_props)) != 0) |
|
1320 |
(void) dmu_objset_destroy(zc->zc_name); |
|
1321 |
} |
|
1322 |
||
1323 |
nvlist_free(cbdata.zc_props); |
|
789 | 1324 |
return (error); |
1325 |
} |
|
1326 |
||
1327 |
static int |
|
2199 | 1328 |
zfs_ioc_snapshot(zfs_cmd_t *zc) |
1329 |
{ |
|
2676 | 1330 |
if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0) |
2199 | 1331 |
return (EINVAL); |
1332 |
return (dmu_objset_snapshot(zc->zc_name, |
|
2676 | 1333 |
zc->zc_value, zc->zc_cookie)); |
2199 | 1334 |
} |
1335 |
||
4007 | 1336 |
int |
2199 | 1337 |
zfs_unmount_snap(char *name, void *arg) |
789 | 1338 |
{ |
2199 | 1339 |
char *snapname = arg; |
1340 |
char *cp; |
|
2417 | 1341 |
vfs_t *vfsp = NULL; |
2199 | 1342 |
|
1343 |
/* |
|
1344 |
* Snapshots (which are under .zfs control) must be unmounted |
|
1345 |
* before they can be destroyed. |
|
1346 |
*/ |
|
1347 |
||
1348 |
if (snapname) { |
|
1349 |
(void) strcat(name, "@"); |
|
1350 |
(void) strcat(name, snapname); |
|
1351 |
vfsp = zfs_get_vfs(name); |
|
1352 |
cp = strchr(name, '@'); |
|
1353 |
*cp = '\0'; |
|
2417 | 1354 |
} else if (strchr(name, '@')) { |
2199 | 1355 |
vfsp = zfs_get_vfs(name); |
1356 |
} |
|
1357 |
||
1358 |
if (vfsp) { |
|
1359 |
/* |
|
1360 |
* Always force the unmount for snapshots. |
|
1361 |
*/ |
|
1362 |
int flag = MS_FORCE; |
|
789 | 1363 |
int err; |
1364 |
||
2199 | 1365 |
if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) { |
1366 |
VFS_RELE(vfsp); |
|
1367 |
return (err); |
|
1368 |
} |
|
1369 |
VFS_RELE(vfsp); |
|
1370 |
if ((err = dounmount(vfsp, flag, kcred)) != 0) |
|
1371 |
return (err); |
|
1372 |
} |
|
1373 |
return (0); |
|
1374 |
} |
|
1375 |
||
1376 |
static int |
|
1377 |
zfs_ioc_destroy_snaps(zfs_cmd_t *zc) |
|
1378 |
{ |
|
1379 |
int err; |
|
789 | 1380 |
|
2676 | 1381 |
if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0) |
2199 | 1382 |
return (EINVAL); |
1383 |
err = dmu_objset_find(zc->zc_name, |
|
2676 | 1384 |
zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN); |
2199 | 1385 |
if (err) |
1386 |
return (err); |
|
2676 | 1387 |
return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value)); |
2199 | 1388 |
} |
1389 |
||
1390 |
static int |
|
1391 |
zfs_ioc_destroy(zfs_cmd_t *zc) |
|
1392 |
{ |
|
1393 |
if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) { |
|
1394 |
int err = zfs_unmount_snap(zc->zc_name, NULL); |
|
1395 |
if (err) |
|
1396 |
return (err); |
|
789 | 1397 |
} |
1398 |
||
1399 |
return (dmu_objset_destroy(zc->zc_name)); |
|
1400 |
} |
|
1401 |
||
1402 |
static int |
|
1403 |
zfs_ioc_rollback(zfs_cmd_t *zc) |
|
1404 |
{ |
|
1405 |
return (dmu_objset_rollback(zc->zc_name)); |
|
1406 |
} |
|
1407 |
||
1408 |
static int |
|
1409 |
zfs_ioc_rename(zfs_cmd_t *zc) |
|
1410 |
{ |
|
4007 | 1411 |
int recursive = zc->zc_cookie & 1; |
1412 |
||
2676 | 1413 |
zc->zc_value[sizeof (zc->zc_value) - 1] = '\0'; |
1414 |
if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) |
|
789 | 1415 |
return (EINVAL); |
1416 |
||
4007 | 1417 |
/* |
1418 |
* Unmount snapshot unless we're doing a recursive rename, |
|
1419 |
* in which case the dataset code figures out which snapshots |
|
1420 |
* to unmount. |
|
1421 |
*/ |
|
1422 |
if (!recursive && strchr(zc->zc_name, '@') != NULL && |
|
789 | 1423 |
zc->zc_objset_type == DMU_OST_ZFS) { |
2199 | 1424 |
int err = zfs_unmount_snap(zc->zc_name, NULL); |
1425 |
if (err) |
|
1426 |
return (err); |
|
789 | 1427 |
} |
1428 |
||
4007 | 1429 |
return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive)); |
789 | 1430 |
} |
1431 |
||
1432 |
static int |
|
1433 |
zfs_ioc_recvbackup(zfs_cmd_t *zc) |
|
1434 |
{ |
|
1435 |
file_t *fp; |
|
1436 |
int error, fd; |
|
2885 | 1437 |
offset_t new_off; |
789 | 1438 |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3087
diff
changeset
|
1439 |
if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 || |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3087
diff
changeset
|
1440 |
strchr(zc->zc_value, '@') == NULL) |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3087
diff
changeset
|
1441 |
return (EINVAL); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3087
diff
changeset
|
1442 |
|
789 | 1443 |
fd = zc->zc_cookie; |
1444 |
fp = getf(fd); |
|
1445 |
if (fp == NULL) |
|
1446 |
return (EBADF); |
|
2676 | 1447 |
error = dmu_recvbackup(zc->zc_value, &zc->zc_begin_record, |
1448 |
&zc->zc_cookie, (boolean_t)zc->zc_guid, fp->f_vnode, |
|
2665 | 1449 |
fp->f_offset); |
2885 | 1450 |
|
1451 |
new_off = fp->f_offset + zc->zc_cookie; |
|
1452 |
if (VOP_SEEK(fp->f_vnode, fp->f_offset, &new_off) == 0) |
|
1453 |
fp->f_offset = new_off; |
|
1454 |
||
789 | 1455 |
releasef(fd); |
1456 |
return (error); |
|
1457 |
} |
|
1458 |
||
1459 |
static int |
|
1460 |
zfs_ioc_sendbackup(zfs_cmd_t *zc) |
|
1461 |
{ |
|
1462 |
objset_t *fromsnap = NULL; |
|
1463 |
objset_t *tosnap; |
|
1464 |
file_t *fp; |
|
1465 |
int error; |
|
1466 |
||
1467 |
error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, |
|
1468 |
DS_MODE_STANDARD | DS_MODE_READONLY, &tosnap); |
|
1469 |
if (error) |
|
1470 |
return (error); |
|
1471 |
||
2676 | 1472 |
if (zc->zc_value[0] != '\0') { |
2885 | 1473 |
char buf[MAXPATHLEN]; |
1474 |
char *cp; |
|
1475 |
||
1476 |
(void) strncpy(buf, zc->zc_name, sizeof (buf)); |
|
1477 |
cp = strchr(buf, '@'); |
|
1478 |
if (cp) |
|
1479 |
*(cp+1) = 0; |
|
1480 |
(void) strncat(buf, zc->zc_value, sizeof (buf)); |
|
1481 |
error = dmu_objset_open(buf, DMU_OST_ANY, |
|
789 | 1482 |
DS_MODE_STANDARD | DS_MODE_READONLY, &fromsnap); |
1483 |
if (error) { |
|
1484 |
dmu_objset_close(tosnap); |
|
1485 |
return (error); |
|
1486 |
} |
|
1487 |
} |
|
1488 |
||
1489 |
fp = getf(zc->zc_cookie); |
|
1490 |
if (fp == NULL) { |
|
1491 |
dmu_objset_close(tosnap); |
|
1492 |
if (fromsnap) |
|
1493 |
dmu_objset_close(fromsnap); |
|
1494 |
return (EBADF); |
|
1495 |
} |
|
1496 |
||
1497 |
error = dmu_sendbackup(tosnap, fromsnap, fp->f_vnode); |
|
1498 |
||
1499 |
releasef(zc->zc_cookie); |
|
1500 |
if (fromsnap) |
|
1501 |
dmu_objset_close(fromsnap); |
|
1502 |
dmu_objset_close(tosnap); |
|
1503 |
return (error); |
|
1504 |
} |
|
1505 |
||
1544 | 1506 |
static int |
1507 |
zfs_ioc_inject_fault(zfs_cmd_t *zc) |
|
1508 |
{ |
|
1509 |
int id, error; |
|
1510 |
||
1511 |
error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id, |
|
1512 |
&zc->zc_inject_record); |
|
1513 |
||
1514 |
if (error == 0) |
|
1515 |
zc->zc_guid = (uint64_t)id; |
|
1516 |
||
1517 |
return (error); |
|
1518 |
} |
|
1519 |
||
1520 |
static int |
|
1521 |
zfs_ioc_clear_fault(zfs_cmd_t *zc) |
|
1522 |
{ |
|
1523 |
return (zio_clear_fault((int)zc->zc_guid)); |
|
1524 |
} |
|
1525 |
||
1526 |
static int |
|
1527 |
zfs_ioc_inject_list_next(zfs_cmd_t *zc) |
|
1528 |
{ |
|
1529 |
int id = (int)zc->zc_guid; |
|
1530 |
int error; |
|
1531 |
||
1532 |
error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name), |
|
1533 |
&zc->zc_inject_record); |
|
1534 |
||
1535 |
zc->zc_guid = id; |
|
1536 |
||
1537 |
return (error); |
|
1538 |
} |
|
1539 |
||
1540 |
static int |
|
1541 |
zfs_ioc_error_log(zfs_cmd_t *zc) |
|
1542 |
{ |
|
1543 |
spa_t *spa; |
|
1544 |
int error; |
|
2676 | 1545 |
size_t count = (size_t)zc->zc_nvlist_dst_size; |
1544 | 1546 |
|
1547 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
|
1548 |
return (error); |
|
1549 |
||
2676 | 1550 |
error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst, |
1544 | 1551 |
&count); |
1552 |
if (error == 0) |
|
2676 | 1553 |
zc->zc_nvlist_dst_size = count; |
1544 | 1554 |
else |
2676 | 1555 |
zc->zc_nvlist_dst_size = spa_get_errlog_size(spa); |
1544 | 1556 |
|
1557 |
spa_close(spa, FTAG); |
|
1558 |
||
1559 |
return (error); |
|
1560 |
} |
|
1561 |
||
1562 |
static int |
|
1563 |
zfs_ioc_clear(zfs_cmd_t *zc) |
|
1564 |
{ |
|
1565 |
spa_t *spa; |
|
1566 |
vdev_t *vd; |
|
1567 |
int error; |
|
1568 |
||
1569 |
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) |
|
1570 |
return (error); |
|
1571 |
||
1572 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
1573 |
||
2676 | 1574 |
if (zc->zc_guid == 0) { |
1544 | 1575 |
vd = NULL; |
2676 | 1576 |
} else if ((vd = spa_lookup_by_guid(spa, zc->zc_guid)) == NULL) { |
1544 | 1577 |
spa_config_exit(spa, FTAG); |
1578 |
spa_close(spa, FTAG); |
|
1579 |
return (ENODEV); |
|
1580 |
} |
|
1581 |
||
1582 |
vdev_clear(spa, vd); |
|
1583 |
||
1584 |
spa_config_exit(spa, FTAG); |
|
1585 |
||
1586 |
spa_close(spa, FTAG); |
|
1587 |
||
1588 |
return (0); |
|
1589 |
} |
|
1590 |
||
1591 |
static int |
|
2082 | 1592 |
zfs_ioc_promote(zfs_cmd_t *zc) |
1593 |
{ |
|
2417 | 1594 |
char *cp; |
1595 |
||
1596 |
/* |
|
1597 |
* We don't need to unmount *all* the origin fs's snapshots, but |
|
1598 |
* it's easier. |
|
1599 |
*/ |
|
2676 | 1600 |
cp = strchr(zc->zc_value, '@'); |
2417 | 1601 |
if (cp) |
1602 |
*cp = '\0'; |
|
2676 | 1603 |
(void) dmu_objset_find(zc->zc_value, |
2417 | 1604 |
zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS); |
2082 | 1605 |
return (dsl_dataset_promote(zc->zc_name)); |
1606 |
} |
|
1607 |
||
789 | 1608 |
static zfs_ioc_vec_t zfs_ioc_vec[] = { |
1609 |
{ zfs_ioc_pool_create, zfs_secpolicy_config, pool_name }, |
|
1610 |
{ zfs_ioc_pool_destroy, zfs_secpolicy_config, pool_name }, |
|
1611 |
{ zfs_ioc_pool_import, zfs_secpolicy_config, pool_name }, |
|
1612 |
{ zfs_ioc_pool_export, zfs_secpolicy_config, pool_name }, |
|
1613 |
{ zfs_ioc_pool_configs, zfs_secpolicy_none, no_name }, |
|
1614 |
{ zfs_ioc_pool_stats, zfs_secpolicy_read, pool_name }, |
|
1615 |
{ zfs_ioc_pool_tryimport, zfs_secpolicy_config, no_name }, |
|
1616 |
{ zfs_ioc_pool_scrub, zfs_secpolicy_config, pool_name }, |
|
1617 |
{ zfs_ioc_pool_freeze, zfs_secpolicy_config, no_name }, |
|
1760 | 1618 |
{ zfs_ioc_pool_upgrade, zfs_secpolicy_config, pool_name }, |
2926 | 1619 |
{ zfs_ioc_pool_get_history, zfs_secpolicy_config, pool_name }, |
1620 |
{ zfs_ioc_pool_log_history, zfs_secpolicy_config, pool_name }, |
|
789 | 1621 |
{ zfs_ioc_vdev_add, zfs_secpolicy_config, pool_name }, |
1622 |
{ zfs_ioc_vdev_remove, zfs_secpolicy_config, pool_name }, |
|
1623 |
{ zfs_ioc_vdev_online, zfs_secpolicy_config, pool_name }, |
|
1624 |
{ zfs_ioc_vdev_offline, zfs_secpolicy_config, pool_name }, |
|
1625 |
{ zfs_ioc_vdev_attach, zfs_secpolicy_config, pool_name }, |
|
1626 |
{ zfs_ioc_vdev_detach, zfs_secpolicy_config, pool_name }, |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1133
diff
changeset
|
1627 |
{ zfs_ioc_vdev_setpath, zfs_secpolicy_config, pool_name }, |
789 | 1628 |
{ zfs_ioc_objset_stats, zfs_secpolicy_read, dataset_name }, |
1629 |
{ zfs_ioc_dataset_list_next, zfs_secpolicy_read, dataset_name }, |
|
1630 |
{ zfs_ioc_snapshot_list_next, zfs_secpolicy_read, dataset_name }, |
|
2676 | 1631 |
{ zfs_ioc_set_prop, zfs_secpolicy_write, dataset_name }, |
789 | 1632 |
{ zfs_ioc_create_minor, zfs_secpolicy_config, dataset_name }, |
1633 |
{ zfs_ioc_remove_minor, zfs_secpolicy_config, dataset_name }, |
|
1634 |
{ zfs_ioc_create, zfs_secpolicy_parent, dataset_name }, |
|
1635 |
{ zfs_ioc_destroy, zfs_secpolicy_parent, dataset_name }, |
|
1636 |
{ zfs_ioc_rollback, zfs_secpolicy_write, dataset_name }, |
|
1637 |
{ zfs_ioc_rename, zfs_secpolicy_write, dataset_name }, |
|
1638 |
{ zfs_ioc_recvbackup, zfs_secpolicy_write, dataset_name }, |
|
1639 |
{ zfs_ioc_sendbackup, zfs_secpolicy_write, dataset_name }, |
|
1544 | 1640 |
{ zfs_ioc_inject_fault, zfs_secpolicy_inject, no_name }, |
1641 |
{ zfs_ioc_clear_fault, zfs_secpolicy_inject, no_name }, |
|
1642 |
{ zfs_ioc_inject_list_next, zfs_secpolicy_inject, no_name }, |
|
1643 |
{ zfs_ioc_error_log, zfs_secpolicy_inject, pool_name }, |
|
1644 |
{ zfs_ioc_clear, zfs_secpolicy_config, pool_name }, |
|
2199 | 1645 |
{ zfs_ioc_promote, zfs_secpolicy_write, dataset_name }, |
1646 |
{ zfs_ioc_destroy_snaps, zfs_secpolicy_write, dataset_name }, |
|
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
1647 |
{ zfs_ioc_snapshot, zfs_secpolicy_write, dataset_name }, |
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3265
diff
changeset
|
1648 |
{ zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, pool_name }, |
3912 | 1649 |
{ zfs_ioc_obj_to_path, zfs_secpolicy_config, no_name }, |
4098
0a182c2128e6
6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents:
4007
diff
changeset
|
1650 |
{ zfs_ioc_pool_set_props, zfs_secpolicy_config, pool_name }, |
0a182c2128e6
6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents:
4007
diff
changeset
|
1651 |
{ zfs_ioc_pool_get_props, zfs_secpolicy_read, pool_name }, |
789 | 1652 |
}; |
1653 |
||
1654 |
static int |
|
1655 |
zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) |
|
1656 |
{ |
|
1657 |
zfs_cmd_t *zc; |
|
1658 |
uint_t vec; |
|
2199 | 1659 |
int error, rc; |
789 | 1660 |
|
1661 |
if (getminor(dev) != 0) |
|
1662 |
return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp)); |
|
1663 |
||
1664 |
vec = cmd - ZFS_IOC; |
|
1665 |
||
1666 |
if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0])) |
|
1667 |
return (EINVAL); |
|
1668 |
||
1669 |
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP); |
|
1670 |
||
1671 |
error = xcopyin((void *)arg, zc, sizeof (zfs_cmd_t)); |
|
1672 |
||
1673 |
if (error == 0) { |
|
1674 |
zc->zc_cred = (uintptr_t)cr; |
|
1675 |
zc->zc_dev = dev; |
|
2676 | 1676 |
error = zfs_ioc_vec[vec].zvec_secpolicy(zc->zc_name, cr); |
789 | 1677 |
} |
1678 |
||
1679 |
/* |
|
1680 |
* Ensure that all pool/dataset names are valid before we pass down to |
|
1681 |
* the lower layers. |
|
1682 |
*/ |
|
1683 |
if (error == 0) { |
|
1684 |
zc->zc_name[sizeof (zc->zc_name) - 1] = '\0'; |
|
1685 |
switch (zfs_ioc_vec[vec].zvec_namecheck) { |
|
1686 |
case pool_name: |
|
1687 |
if (pool_namecheck(zc->zc_name, NULL, NULL) != 0) |
|
1688 |
error = EINVAL; |
|
1689 |
break; |
|
1690 |
||
1691 |
case dataset_name: |
|
1692 |
if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0) |
|
1693 |
error = EINVAL; |
|
1694 |
break; |
|
2856 | 1695 |
|
1696 |
case no_name: |
|
1697 |
break; |
|
789 | 1698 |
} |
1699 |
} |
|
1700 |
||
1701 |
if (error == 0) |
|
1702 |
error = zfs_ioc_vec[vec].zvec_func(zc); |
|
1703 |
||
2199 | 1704 |
rc = xcopyout(zc, (void *)arg, sizeof (zfs_cmd_t)); |
1705 |
if (error == 0) |
|
1706 |
error = rc; |
|
789 | 1707 |
|
1708 |
kmem_free(zc, sizeof (zfs_cmd_t)); |
|
1709 |
return (error); |
|
1710 |
} |
|
1711 |
||
1712 |
static int |
|
1713 |
zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) |
|
1714 |
{ |
|
1715 |
if (cmd != DDI_ATTACH) |
|
1716 |
return (DDI_FAILURE); |
|
1717 |
||
1718 |
if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0, |
|
1719 |
DDI_PSEUDO, 0) == DDI_FAILURE) |
|
1720 |
return (DDI_FAILURE); |
|
1721 |
||
1722 |
zfs_dip = dip; |
|
1723 |
||
1724 |
ddi_report_dev(dip); |
|
1725 |
||
1726 |
return (DDI_SUCCESS); |
|
1727 |
} |
|
1728 |
||
1729 |
static int |
|
1730 |
zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) |
|
1731 |
{ |
|
1732 |
if (spa_busy() || zfs_busy() || zvol_busy()) |
|
1733 |
return (DDI_FAILURE); |
|
1734 |
||
1735 |
if (cmd != DDI_DETACH) |
|
1736 |
return (DDI_FAILURE); |
|
1737 |
||
1738 |
zfs_dip = NULL; |
|
1739 |
||
1740 |
ddi_prop_remove_all(dip); |
|
1741 |
ddi_remove_minor_node(dip, NULL); |
|
1742 |
||
1743 |
return (DDI_SUCCESS); |
|
1744 |
} |
|
1745 |
||
1746 |
/*ARGSUSED*/ |
|
1747 |
static int |
|
1748 |
zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) |
|
1749 |
{ |
|
1750 |
switch (infocmd) { |
|
1751 |
case DDI_INFO_DEVT2DEVINFO: |
|
1752 |
*result = zfs_dip; |
|
1753 |
return (DDI_SUCCESS); |
|
1754 |
||
1755 |
case DDI_INFO_DEVT2INSTANCE: |
|
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1756 |
*result = (void *)0; |
789 | 1757 |
return (DDI_SUCCESS); |
1758 |
} |
|
1759 |
||
1760 |
return (DDI_FAILURE); |
|
1761 |
} |
|
1762 |
||
1763 |
/* |
|
1764 |
* OK, so this is a little weird. |
|
1765 |
* |
|
1766 |
* /dev/zfs is the control node, i.e. minor 0. |
|
1767 |
* /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0. |
|
1768 |
* |
|
1769 |
* /dev/zfs has basically nothing to do except serve up ioctls, |
|
1770 |
* so most of the standard driver entry points are in zvol.c. |
|
1771 |
*/ |
|
1772 |
static struct cb_ops zfs_cb_ops = { |
|
1773 |
zvol_open, /* open */ |
|
1774 |
zvol_close, /* close */ |
|
1775 |
zvol_strategy, /* strategy */ |
|
1776 |
nodev, /* print */ |
|
1777 |
nodev, /* dump */ |
|
1778 |
zvol_read, /* read */ |
|
1779 |
zvol_write, /* write */ |
|
1780 |
zfsdev_ioctl, /* ioctl */ |
|
1781 |
nodev, /* devmap */ |
|
1782 |
nodev, /* mmap */ |
|
1783 |
nodev, /* segmap */ |
|
1784 |
nochpoll, /* poll */ |
|
1785 |
ddi_prop_op, /* prop_op */ |
|
1786 |
NULL, /* streamtab */ |
|
1787 |
D_NEW | D_MP | D_64BIT, /* Driver compatibility flag */ |
|
1788 |
CB_REV, /* version */ |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3444
diff
changeset
|
1789 |
nodev, /* async read */ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3444
diff
changeset
|
1790 |
nodev, /* async write */ |
789 | 1791 |
}; |
1792 |
||
1793 |
static struct dev_ops zfs_dev_ops = { |
|
1794 |
DEVO_REV, /* version */ |
|
1795 |
0, /* refcnt */ |
|
1796 |
zfs_info, /* info */ |
|
1797 |
nulldev, /* identify */ |
|
1798 |
nulldev, /* probe */ |
|
1799 |
zfs_attach, /* attach */ |
|
1800 |
zfs_detach, /* detach */ |
|
1801 |
nodev, /* reset */ |
|
1802 |
&zfs_cb_ops, /* driver operations */ |
|
1803 |
NULL /* no bus operations */ |
|
1804 |
}; |
|
1805 |
||
1806 |
static struct modldrv zfs_modldrv = { |
|
2676 | 1807 |
&mod_driverops, "ZFS storage pool version " ZFS_VERSION_STRING, |
1808 |
&zfs_dev_ops |
|
789 | 1809 |
}; |
1810 |
||
1811 |
static struct modlinkage modlinkage = { |
|
1812 |
MODREV_1, |
|
1813 |
(void *)&zfs_modlfs, |
|
1814 |
(void *)&zfs_modldrv, |
|
1815 |
NULL |
|
1816 |
}; |
|
1817 |
||
1818 |
int |
|
1819 |
_init(void) |
|
1820 |
{ |
|
1821 |
int error; |
|
1822 |
||
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1823 |
spa_init(FREAD | FWRITE); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1824 |
zfs_init(); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1825 |
zvol_init(); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1826 |
|
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1827 |
if ((error = mod_install(&modlinkage)) != 0) { |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1828 |
zvol_fini(); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1829 |
zfs_fini(); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1830 |
spa_fini(); |
789 | 1831 |
return (error); |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1832 |
} |
789 | 1833 |
|
1834 |
error = ldi_ident_from_mod(&modlinkage, &zfs_li); |
|
1835 |
ASSERT(error == 0); |
|
1836 |
||
1837 |
return (0); |
|
1838 |
} |
|
1839 |
||
1840 |
int |
|
1841 |
_fini(void) |
|
1842 |
{ |
|
1843 |
int error; |
|
1844 |
||
1544 | 1845 |
if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled) |
789 | 1846 |
return (EBUSY); |
1847 |
||
1848 |
if ((error = mod_remove(&modlinkage)) != 0) |
|
1849 |
return (error); |
|
1850 |
||
1851 |
zvol_fini(); |
|
1852 |
zfs_fini(); |
|
1853 |
spa_fini(); |
|
1854 |
||
1855 |
ldi_ident_release(zfs_li); |
|
1856 |
zfs_li = NULL; |
|
1857 |
||
1858 |
return (error); |
|
1859 |
} |
|
1860 |
||
1861 |
int |
|
1862 |
_info(struct modinfo *modinfop) |
|
1863 |
{ |
|
1864 |
return (mod_info(&modlinkage, modinfop)); |
|
1865 |
} |