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