annotate usr/src/uts/common/fs/zfs/zfs_ioctl.c @ 5378:111aa1baa84a onnv_77

PSARC 2007/555 zfs fs-only quotas and reservations 6431277 want filesystem-only quotas 6483677 need immediate reservation
author ck153898
date Mon, 29 Oct 2007 22:45:33 -0700
parents c682f8c5f5e3
children 51fbc14b301d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
3 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1356
diff changeset
5 * Common Development and Distribution License (the "License").
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1356
diff changeset
6 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
7 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
10 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
11 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
12 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
18 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
19 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
20 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
23 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
24 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
26 #pragma ident "%Z%%M% %I% %E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
28 #include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
29 #include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
30 #include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
31 #include <sys/uio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
32 #include <sys/buf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
33 #include <sys/modctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
34 #include <sys/open.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
35 #include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
36 #include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
37 #include <sys/conf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
38 #include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
39 #include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
40 #include <sys/zfs_ioctl.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
41 #include <sys/zfs_i18n.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
42 #include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
43 #include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
44 #include <sys/spa.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
45 #include <sys/spa_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
46 #include <sys/vdev.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
47 #include <sys/vdev_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
48 #include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
49 #include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
50 #include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
51 #include <sys/dsl_prop.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
52 #include <sys/dsl_deleg.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
53 #include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
54 #include <sys/ddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
55 #include <sys/sunddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
56 #include <sys/sunldi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
57 #include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
58 #include <sys/zone.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
59 #include <sys/nvpair.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
60 #include <sys/pathname.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
61 #include <sys/mount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
62 #include <sys/sdt.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
63 #include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
64 #include <sys/zfs_ctldir.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
65 #include <sys/zfs_dir.h>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
66 #include <sys/zvol.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
67 #include <sharefs/share.h>
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
68 #include <sys/zfs_znode.h>
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
69 #include <sys/zfs_vfsops.h>
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
70 #include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
72 #include "zfs_namecheck.h"
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
73 #include "zfs_prop.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
74 #include "zfs_deleg.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
75
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
76 extern struct modlfs zfs_modlfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
77
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
78 extern void zfs_init(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
79 extern void zfs_fini(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
80
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
81 ldi_ident_t zfs_li = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
82 dev_info_t *zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
84 typedef int zfs_ioc_func_t(zfs_cmd_t *);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
85 typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
87 typedef struct zfs_ioc_vec {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
88 zfs_ioc_func_t *zvec_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
89 zfs_secpolicy_func_t *zvec_secpolicy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
90 enum {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
91 NO_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
92 POOL_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
93 DATASET_NAME
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
94 } zvec_namecheck;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
95 boolean_t zvec_his_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
96 } zfs_ioc_vec_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
97
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
98 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
99 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
100 __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
101 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
102 const char *newfile;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
103 char buf[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
104 va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
106 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
107 * Get rid of annoying "../common/" prefix to filename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
108 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
109 newfile = strrchr(file, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
110 if (newfile != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
111 newfile = newfile + 1; /* Get rid of leading / */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
112 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
113 newfile = file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
114 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
115
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
116 va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
117 (void) vsnprintf(buf, sizeof (buf), fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
118 va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
119
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
120 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
121 * To get this data, use the zfs-dprintf probe as so:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
122 * dtrace -q -n 'zfs-dprintf \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
123 * /stringof(arg0) == "dbuf.c"/ \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
124 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
125 * arg0 = file name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
126 * arg1 = function name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
127 * arg2 = line number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
128 * arg3 = message
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
129 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
130 DTRACE_PROBE4(zfs__dprintf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
131 char *, newfile, char *, func, int, line, char *, buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
132 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
133
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
134 static void
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
135 history_str_free(char *buf)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
136 {
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
137 kmem_free(buf, HIS_MAX_RECORD_LEN);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
138 }
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
139
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
140 static char *
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
141 history_str_get(zfs_cmd_t *zc)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
142 {
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
143 char *buf;
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
144
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
145 if (zc->zc_history == NULL)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
146 return (NULL);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
147
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
148 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
149 if (copyinstr((void *)(uintptr_t)zc->zc_history,
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
150 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
151 history_str_free(buf);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
152 return (NULL);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
153 }
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
154
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
155 buf[HIS_MAX_RECORD_LEN -1] = '\0';
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
156
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
157 return (buf);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
158 }
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
159
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
160 /*
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
161 * zfs_check_version
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
162 *
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
163 * Return non-zero if the spa version is less than requested version.
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
164 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
165 static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
166 zfs_check_version(const char *name, int version)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
167 {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
168
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
169 spa_t *spa;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
170
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
171 if (spa_open(name, &spa, FTAG) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
172 if (spa_version(spa) < version) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
173 spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
174 return (1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
175 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
176 spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
177 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
178 return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
179 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
180
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
181 static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
182 zfs_log_history(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
183 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
184 spa_t *spa;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
185 char *buf;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
186
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
187 if ((buf = history_str_get(zc)) == NULL)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
188 return;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
189
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
190 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
191 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
192 (void) spa_history_log(spa, buf, LOG_CMD_NORMAL);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
193 spa_close(spa, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
194 }
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
195 history_str_free(buf);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
196 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
197
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
198 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
199 * Policy for top-level read operations (list pools). Requires no privileges,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
200 * and can be used in the local zone, as there is no associated dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
201 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
202 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
203 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
204 zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
205 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
206 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
207 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
209 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
210 * Policy for dataset read operations (list children, get statistics). Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
211 * no privileges, but must be visible in the local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
212 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
213 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
214 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
215 zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
216 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
217 if (INGLOBALZONE(curproc) ||
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
218 zone_dataset_visible(zc->zc_name, NULL))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
219 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
221 return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
222 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
223
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
224 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
225 zfs_dozonecheck(const char *dataset, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
226 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
227 uint64_t zoned;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
228 int writable = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
229
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
230 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
231 * The dataset must be visible by this zone -- check this first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
232 * so they don't see EPERM on something they shouldn't know about.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
233 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
234 if (!INGLOBALZONE(curproc) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
235 !zone_dataset_visible(dataset, &writable))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
236 return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
238 if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
239 return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
240
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
241 if (INGLOBALZONE(curproc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
242 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
243 * If the fs is zoned, only root can access it from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
244 * global zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
245 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
246 if (secpolicy_zfs(cr) && zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
247 return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
248 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
249 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
250 * If we are in a local zone, the 'zoned' property must be set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
251 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
252 if (!zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
253 return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
255 /* must be writable by this zone */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
256 if (!writable)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
257 return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
258 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
259 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
260 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
261
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
262 int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
263 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
264 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
265 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
266
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
267 error = zfs_dozonecheck(name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
268 if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
269 error = secpolicy_zfs(cr);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
270 if (error)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
271 error = dsl_deleg_access(name, perm, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
272 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
273 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
274 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
275
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
276 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
277 zfs_secpolicy_setprop(const char *name, zfs_prop_t prop, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
278 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
279 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
280 * Check permissions for special properties.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
281 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
282 switch (prop) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
283 case ZFS_PROP_ZONED:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
284 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
285 * Disallow setting of 'zoned' from within a local zone.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
286 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
287 if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
288 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
289 break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
290
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
291 case ZFS_PROP_QUOTA:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
292 if (!INGLOBALZONE(curproc)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
293 uint64_t zoned;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
294 char setpoint[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
295 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
296 * Unprivileged users are allowed to modify the
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
297 * quota on things *under* (ie. contained by)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
298 * the thing they own.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
299 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
300 if (dsl_prop_get_integer(name, "zoned", &zoned,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
301 setpoint))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
302 return (EPERM);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
303 if (!zoned || strlen(name) <= strlen(setpoint))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
304 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
305 }
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
306 break;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
307 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
308
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
309 return (zfs_secpolicy_write_perms(name, zfs_prop_to_name(prop), cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
310 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
311
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
312 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
313 zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
314 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
315 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
316
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
317 error = zfs_dozonecheck(zc->zc_name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
318 if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
319 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
320
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
321 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
322 * permission to set permissions will be evaluated later in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
323 * dsl_deleg_can_allow()
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
324 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
325 return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
326 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
327
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
328 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
329 zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
330 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
331 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
332 error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
333 ZFS_DELEG_PERM_ROLLBACK, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
334 if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
335 error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
336 ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
337 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
338 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
339
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
340 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
341 zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
342 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
343 return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
344 ZFS_DELEG_PERM_SEND, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
345 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
346
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
347 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
348 zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
349 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
350 if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
351 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
352
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
353 if (secpolicy_nfs(cr) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
354 return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
355 } else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
356 vnode_t *vp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
357 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
358
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
359 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
360 NO_FOLLOW, NULL, &vp)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
361 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
362
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
363 /* Now make sure mntpnt and dataset are ZFS */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
364
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
365 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
366 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
367 zc->zc_name) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
368 VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
369 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
370 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
371
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
372 VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
373 return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
374 ZFS_DELEG_PERM_SHARE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
375 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
376 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
377
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
378 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
379 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
380 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
381 char *cp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
382
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
383 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
384 * Remove the @bla or /bla from the end of the name to get the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
385 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
386 (void) strncpy(parent, datasetname, parentsize);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
387 cp = strrchr(parent, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
388 if (cp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
389 cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
390 } else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
391 cp = strrchr(parent, '/');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
392 if (cp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
393 return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
394 cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
395 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
396
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
397 return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
398 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
399
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
400 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
401 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
402 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
403 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
404
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
405 if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
406 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
407 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
408
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
409 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
410 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
411
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
412 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
413 zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
414 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
415 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
416 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
417
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
418 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
419 * Must have sys_config privilege to check the iscsi permission
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
420 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
421 /* ARGSUSED */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
422 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
423 zfs_secpolicy_iscsi(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
424 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
425 return (secpolicy_zfs(cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
426 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
427
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
428 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
429 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
430 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
431 char parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
432 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
433
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
434 if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
435 ZFS_DELEG_PERM_RENAME, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
436 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
437
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
438 if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
439 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
440 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
441
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
442 if ((error = zfs_get_parent(to, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
443 sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
444 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
445
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
446 if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
447 ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
448 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
449
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
450 if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
451 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
452 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
453
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
454 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
455 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
456
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
457 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
458 zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
459 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
460 return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
461 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
462
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
463 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
464 zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
465 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
466 char parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
467 objset_t *clone;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
468 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
469
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
470 error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
471 ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
472 if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
473 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
474
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
475 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
476 DS_MODE_STANDARD | DS_MODE_READONLY, &clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
477
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
478 if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
479 dsl_dataset_t *pclone = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
480 dsl_dir_t *dd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
481 dd = clone->os->os_dsl_dataset->ds_dir;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
482
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
483 rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
484 error = dsl_dataset_open_obj(dd->dd_pool,
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
485 dd->dd_phys->dd_origin_obj, NULL,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
486 DS_MODE_NONE, FTAG, &pclone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
487 rw_exit(&dd->dd_pool->dp_config_rwlock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
488 if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
489 dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
490 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
491 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
492
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
493 error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
494 ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
495
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
496 dsl_dataset_name(pclone, parentname);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
497 dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
498 dsl_dataset_close(pclone, DS_MODE_NONE, FTAG);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
499 if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
500 error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
501 ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
502 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
503 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
504 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
505
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
506 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
507 zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
508 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
509 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
510
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
511 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
512 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
513 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
514
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
515 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
516 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
517 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
518
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
519 return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
520 ZFS_DELEG_PERM_CREATE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
521 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
522
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
523 int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
524 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
525 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
526 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
527
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
528 if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
529 ZFS_DELEG_PERM_SNAPSHOT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
530 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
531
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
532 error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
533 ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
534
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
535 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
536 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
537
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
538 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
539 zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
540 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
541
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
542 return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
543 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
544
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
545 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
546 zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
547 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
548 char parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
549 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
550
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
551 if ((error = zfs_get_parent(zc->zc_name, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
552 sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
553 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
554
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
555 if (zc->zc_value[0] != '\0') {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
556 if ((error = zfs_secpolicy_write_perms(zc->zc_value,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
557 ZFS_DELEG_PERM_CLONE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
558 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
559 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
560
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
561 if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
562 ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
563 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
564
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
565 error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
566 ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
567
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
568 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
569 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
570
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
571 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
572 zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
573 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
574 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
575
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
576 error = secpolicy_fs_unmount(cr, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
577 if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
578 error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
579 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
580 return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
581 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
582
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
583 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
584 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
585 * SYS_CONFIG privilege, which is not available in a local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
586 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
587 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
588 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
589 zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
590 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
591 if (secpolicy_sys_config(cr, B_FALSE) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
592 return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
593
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
594 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
595 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
596
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
597 /*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
598 * Just like zfs_secpolicy_config, except that we will check for
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
599 * mount permission on the dataset for permission to create/remove
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
600 * the minor nodes.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
601 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
602 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
603 zfs_secpolicy_minor(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
604 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
605 if (secpolicy_sys_config(cr, B_FALSE) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
606 return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
607 ZFS_DELEG_PERM_MOUNT, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
608 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
609
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
610 return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
611 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
612
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
613 /*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
614 * Policy for fault injection. Requires all privileges.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
615 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
616 /* ARGSUSED */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
617 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
618 zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
619 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
620 return (secpolicy_zinject(cr));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
621 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
622
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
623 static int
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
624 zfs_secpolicy_inherit(zfs_cmd_t *zc, cred_t *cr)
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
625 {
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
626 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
627
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
628 if (prop == ZPROP_INVAL) {
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
629 if (!zfs_prop_user(zc->zc_value))
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
630 return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
631 return (zfs_secpolicy_write_perms(zc->zc_name,
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
632 ZFS_DELEG_PERM_USERPROP, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
633 } else {
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
634 if (!zfs_prop_inheritable(prop))
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
635 return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
636 return (zfs_secpolicy_setprop(zc->zc_name, prop, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
637 }
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
638 }
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
639
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
640 /*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
641 * Returns the nvlist as specified by the user in the zfs_cmd_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
642 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
643 static int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
644 get_nvlist(uint64_t nvl, uint64_t size, nvlist_t **nvp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
645 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
646 char *packed;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
647 int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
648 nvlist_t *list = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
649
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
650 /*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
651 * Read in and unpack the user-supplied nvlist.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
652 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
653 if (size == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
654 return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
655
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
656 packed = kmem_alloc(size, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
657
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
658 if ((error = xcopyin((void *)(uintptr_t)nvl, packed, size)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
659 kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
660 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
661 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
662
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
663 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
664 kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
665 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
666 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
667
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
668 kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
669
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
670 *nvp = list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
671 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
672 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
673
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
674 static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
675 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
676 {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
677 char *packed = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
678 size_t size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
679 int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
680
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
681 VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
682
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
683 if (size > zc->zc_nvlist_dst_size) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
684 error = ENOMEM;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
685 } else {
4611
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4603
diff changeset
686 packed = kmem_alloc(size, KM_SLEEP);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
687 VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
688 KM_SLEEP) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
689 error = xcopyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
690 size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
691 kmem_free(packed, size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
692 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
693
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
694 zc->zc_nvlist_dst_size = size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
695 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
696 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
697
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
698 static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
699 zfs_ioc_pool_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
700 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
701 int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
702 nvlist_t *config, *props = NULL;
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
703 char *buf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
704
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
705 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
706 &config))
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
707 return (error);
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
708
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
709 if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
710 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size, &props))) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
711 nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
712 return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
713 }
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
714
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
715 buf = history_str_get(zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
716
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
717 error = spa_create(zc->zc_name, config, props, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
718
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
719 if (buf != NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
720 history_str_free(buf);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
721
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
722 nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
723
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
724 if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
725 nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
726
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
727 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
728 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
729
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
730 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
731 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
732 {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
733 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
734 zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
735 error = spa_destroy(zc->zc_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
736 return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
737 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
738
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
739 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
740 zfs_ioc_pool_import(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
741 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
742 int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
743 nvlist_t *config, *props = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
744 uint64_t guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
745
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
746 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
747 &config)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
748 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
749
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
750 if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
751 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size, &props))) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
752 nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
753 return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
754 }
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
755
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
756 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
757 guid != zc->zc_guid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
758 error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
759 else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
760 error = spa_import(zc->zc_name, config, props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
761
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
762 nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
763
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
764 if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
765 nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
766
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
767 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
768 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
769
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
770 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
771 zfs_ioc_pool_export(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
772 {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
773 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
774 zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
775 error = spa_export(zc->zc_name, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
776 return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
777 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
778
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
779 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
780 zfs_ioc_pool_configs(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
781 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
782 nvlist_t *configs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
783 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
785 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
786 return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
787
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
788 error = put_nvlist(zc, configs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
790 nvlist_free(configs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
791
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
792 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
793 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
794
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
795 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
796 zfs_ioc_pool_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
797 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
798 nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
799 int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
800 int ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
801
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
802 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
803 sizeof (zc->zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
805 if (config != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
806 ret = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
807 nvlist_free(config);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
808
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
809 /*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
810 * The config may be present even if 'error' is non-zero.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
811 * In this case we return success, and preserve the real errno
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
812 * in 'zc_cookie'.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
813 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
814 zc->zc_cookie = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
815 } else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
816 ret = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
817 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
818
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
819 return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
820 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
822 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
823 * Try to import the given pool, returning pool stats as appropriate so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
824 * user land knows which devices are available and overall pool health.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
825 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
826 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
827 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
828 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
829 nvlist_t *tryconfig, *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
830 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
831
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
832 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
833 &tryconfig)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
834 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
835
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
836 config = spa_tryimport(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
837
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
838 nvlist_free(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
840 if (config == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
841 return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
842
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
843 error = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
844 nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
845
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
846 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
847 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
848
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
849 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
850 zfs_ioc_pool_scrub(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
851 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
852 spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
853 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
854
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
855 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
856 return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
857
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
858 mutex_enter(&spa_namespace_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
859 error = spa_scrub(spa, zc->zc_cookie, B_FALSE);
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
860 mutex_exit(&spa_namespace_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
861
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
862 spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
863
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
864 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
865 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
866
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
867 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
868 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
869 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
870 spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
871 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
872
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
873 error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
874 if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
875 spa_freeze(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
876 spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
877 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
878 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
879 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
880
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
881 static int
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
882 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
883 {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
884 spa_t *spa;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
885 int error;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
886
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
887 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
888 return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
889
5118
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
890 if (zc->zc_cookie < spa_version(spa) || zc->zc_cookie > SPA_VERSION) {
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
891 spa_close(spa, FTAG);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
892 return (EINVAL);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
893 }
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
894
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
895 spa_upgrade(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
896 spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
897
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
898 return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
899 }
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
900
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
901 static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
902 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
903 {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
904 spa_t *spa;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
905 char *hist_buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
906 uint64_t size;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
907 int error;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
908
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
909 if ((size = zc->zc_history_len) == 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
910 return (EINVAL);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
911
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
912 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
913 return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
914
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
915 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
3863
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
916 spa_close(spa, FTAG);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
917 return (ENOTSUP);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
918 }
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
919
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
920 hist_buf = kmem_alloc(size, KM_SLEEP);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
921 if ((error = spa_history_get(spa, &zc->zc_history_offset,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
922 &zc->zc_history_len, hist_buf)) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
923 error = xcopyout(hist_buf,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
924 (char *)(uintptr_t)zc->zc_history,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
925 zc->zc_history_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
926 }
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
927
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
928 spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
929 kmem_free(hist_buf, size);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
930 return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
931 }
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
932
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
933 static int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
934 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
935 {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
936 int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
937
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
938 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
939 return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
940
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
941 return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
942 }
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
943
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
944 static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
945 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
946 {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
947 objset_t *osp;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
948 int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
949
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
950 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
951 DS_MODE_NONE | DS_MODE_READONLY, &osp)) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
952 return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
953
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
954 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
955 sizeof (zc->zc_value));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
956 dmu_objset_close(osp);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
957
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
958 return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
959 }
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
960
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
961 static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
962 zfs_ioc_vdev_add(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
963 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
964 spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
965 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
966 nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
967
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
968 error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
969 if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
970 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
971
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
972 /*
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
973 * A root pool with concatenated devices is not supported.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
974 * Thus, can not add a device to a root pool with one device.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
975 */
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
976 if (spa->spa_root_vdev->vdev_children == 1 && spa->spa_bootfs != 0) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
977 spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
978 return (EDOM);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
979 }
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
980
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
981 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
982 &config)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
983 error = spa_vdev_add(spa, config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
984 nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
985 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
986 spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
987 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
988 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
989
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
990 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
991 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
992 {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
993 spa_t *spa;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
994 int error;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
995
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
996 error = spa_open(zc->zc_name, &spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
997 if (error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
998 return (error);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
999 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
1000 spa_close(spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
1001 return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1002 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1003
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1004 static int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1005 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1006 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1007 spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1008 int error;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1009 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1010
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
1011 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1012 return (error);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1013 switch (zc->zc_cookie) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1014 case VDEV_STATE_ONLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1015 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1016 break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1017
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1018 case VDEV_STATE_OFFLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1019 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1020 break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1021
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1022 case VDEV_STATE_FAULTED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1023 error = vdev_fault(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1024 break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1025
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1026 case VDEV_STATE_DEGRADED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1027 error = vdev_degrade(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1028 break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1029
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1030 default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1031 error = EINVAL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1032 }
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
1033 zc->zc_cookie = newstate;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1034 spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1035 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1036 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1037
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1038 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1039 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1040 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1041 spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1042 int replacing = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1043 nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1044 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1045
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
1046 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1047 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1048
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1049 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1050 &config)) == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
1051 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1052 nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1053 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1054
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1055 spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1056 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1057 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1058
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1059 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1060 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1061 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1062 spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1063 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1064
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
1065 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1066 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1067
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
1068 error = spa_vdev_detach(spa, zc->zc_guid, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1069
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1070 spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1071 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1072 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1073
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1074 static int
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1075 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1076 {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1077 spa_t *spa;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1078 char *path = zc->zc_value;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
1079 uint64_t guid = zc->zc_guid;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1080 int error;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1081
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1082 error = spa_open(zc->zc_name, &spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1083 if (error != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1084 return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1085
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1086 error = spa_vdev_setpath(spa, guid, path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1087 spa_close(spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1088 return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1089 }
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1090
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1091 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1092 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1093 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1094 * zc_nvlist_dst_size size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1095 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1096 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1097 * zc_objset_stats stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1098 * zc_nvlist_dst property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1099 * zc_nvlist_dst_size size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1100 * zc_value alternate root
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1101 */
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
1102 static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1103 zfs_ioc_objset_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1104 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1105 objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1106 int error;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
1107 nvlist_t *nv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1108
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1109 retry:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1110 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1111 DS_MODE_STANDARD | DS_MODE_READONLY, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1112 if (error != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1113 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1114 * This is ugly: dmu_objset_open() can return EBUSY if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1115 * the objset is held exclusively. Fortunately this hold is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1116 * only for a short while, so we retry here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1117 * This avoids user code having to handle EBUSY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1118 * for example for a "zfs list".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1119 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1120 if (error == EBUSY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1121 delay(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1122 goto retry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1123 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1124 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1125 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1126
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
1127 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1128
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
1129 if (zc->zc_nvlist_dst != 0 &&
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
1130 (error = dsl_prop_get_all(os, &nv)) == 0) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
1131 dmu_objset_stats(os, nv);
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
1132 /*
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1133 * NB: zvol_get_stats() will read the objset contents,
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
1134 * which we aren't supposed to do with a
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
1135 * DS_MODE_STANDARD open, because it could be
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
1136 * inconsistent. So this is a bit of a workaround...
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
1137 */
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1138 if (!zc->zc_objset_stats.dds_inconsistent) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1139 if (dmu_objset_type(os) == DMU_OST_ZVOL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1140 VERIFY(zvol_get_stats(os, nv) == 0);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1141 }
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1142 error = put_nvlist(zc, nv);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
1143 nvlist_free(nv);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
1144 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1145
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1146 spa_altroot(dmu_objset_spa(os), zc->zc_value, sizeof (zc->zc_value));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
1147
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1148 dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1149 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1150 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1151
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1152 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1153 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1154 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1155 * zc_cookie zap cursor
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1156 * zc_nvlist_dst_size size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1157 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1158 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1159 * zc_name name of next filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1160 * zc_objset_stats stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1161 * zc_nvlist_dst property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1162 * zc_nvlist_dst_size size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1163 * zc_value alternate root
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1164 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1165 static int
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1166 zfs_ioc_objset_version(zfs_cmd_t *zc)
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1167 {
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1168 objset_t *os = NULL;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1169 int error;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1170
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1171 retry:
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1172 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1173 DS_MODE_STANDARD | DS_MODE_READONLY, &os);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1174 if (error != 0) {
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1175 /*
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1176 * This is ugly: dmu_objset_open() can return EBUSY if
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1177 * the objset is held exclusively. Fortunately this hold is
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1178 * only for a short while, so we retry here.
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1179 * This avoids user code having to handle EBUSY,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1180 * for example for a "zfs list".
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1181 */
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1182 if (error == EBUSY) {
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1183 delay(1);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1184 goto retry;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1185 }
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1186 return (error);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1187 }
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1188
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1189 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1190
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1191 /*
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1192 * NB: zfs_get_version() will read the objset contents,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1193 * which we aren't supposed to do with a
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1194 * DS_MODE_STANDARD open, because it could be
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1195 * inconsistent. So this is a bit of a workaround...
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1196 */
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1197 zc->zc_cookie = 0;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1198 if (!zc->zc_objset_stats.dds_inconsistent)
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1199 if (dmu_objset_type(os) == DMU_OST_ZFS)
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1200 (void) zfs_get_version(os, &zc->zc_cookie);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1201
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1202 dmu_objset_close(os);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1203 return (0);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1204 }
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1205
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
1206 static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1207 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1208 {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1209 objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1210 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1211 char *p;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1212
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1213 retry:
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1214 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
1215 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
1216 if (error != 0) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1217 /*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1218 * 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
1219 * 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
1220 * 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
1221 * 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
1222 * for example for a "zfs list".
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1223 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1224 if (error == EBUSY) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1225 delay(1);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1226 goto retry;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1227 }
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1228 if (error == ENOENT)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1229 error = ESRCH;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1230 return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1231 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1233 p = strrchr(zc->zc_name, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1234 if (p == NULL || p[1] != '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1235 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1236 p = zc->zc_name + strlen(zc->zc_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1238 do {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1239 error = dmu_dir_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1240 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
1241 NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1242 if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1243 error = ESRCH;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1244 } while (error == 0 && !INGLOBALZONE(curproc) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1245 !zone_dataset_visible(zc->zc_name, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1246
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1247 /*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1248 * 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
1249 * 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
1250 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1251 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
1252 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1253
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1254 dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1255 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1256 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1257
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1258 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1259 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1260 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1261 * zc_cookie zap cursor
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1262 * zc_nvlist_dst_size size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1263 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1264 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1265 * zc_name name of next snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1266 * zc_objset_stats stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1267 * zc_nvlist_dst property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1268 * zc_nvlist_dst_size size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1269 * zc_value alternate root
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1270 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1271 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1272 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1273 {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1274 objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1275 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1276
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1277 retry:
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1278 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
1279 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
1280 if (error != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1281 /*
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1282 * This is ugly: dmu_objset_open() can return EBUSY if
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1283 * the objset is held exclusively. Fortunately this hold is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1284 * only for a short while, so we retry here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1285 * 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
1286 * for example for a "zfs list".
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1287 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1288 if (error == EBUSY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1289 delay(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1290 goto retry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1291 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1292 if (error == ENOENT)
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1293 error = ESRCH;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1294 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1295 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1296
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
1297 /*
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
1298 * A dataset name of maximum length cannot have any snapshots,
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
1299 * so exit immediately.
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
1300 */
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
1301 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
1302 dmu_objset_close(os);
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
1303 return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1304 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1305
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1306 error = dmu_snapshot_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1307 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
1308 zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1309 if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1310 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1311
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1312 if (error == 0)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1313 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1314
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1315 /* if we failed, undo the @ that we tacked on to zc_name */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1316 if (error != 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1317 *strchr(zc->zc_name, '@') = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1318
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
1319 dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1320 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1321 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1322
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1323 static int
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1324 zfs_set_prop_nvlist(const char *name, nvlist_t *nvl)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1325 {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1326 nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1327 int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1328 uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1329 char *strval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1330
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1331 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1332 * First validate permission to set all of the properties
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1333 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1334 elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1335 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1336 const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1337 zfs_prop_t prop = zfs_name_to_prop(propname);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1338
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1339 if (prop == ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1340 /*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1341 * If this is a user-defined property, it must be a
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1342 * string, and there is no further validation to do.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1343 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1344 if (!zfs_prop_user(propname) ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1345 nvpair_type(elem) != DATA_TYPE_STRING)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1346 return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1347
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1348 if (error = zfs_secpolicy_write_perms(name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1349 ZFS_DELEG_PERM_USERPROP, CRED()))
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1350 return (error);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1351 continue;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1352 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1353
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1354 if ((error = zfs_secpolicy_setprop(name, prop, CRED())) != 0)
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1355 return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1356
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1357 /*
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1358 * Check that this value is valid for this pool version
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1359 */
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1360 switch (prop) {
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1361 case ZFS_PROP_COMPRESSION:
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1362 /*
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1363 * 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
1364 * 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
1365 * we'll catch them later.
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1366 */
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1367 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
1368 nvpair_value_uint64(elem, &intval) == 0 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1369 intval >= ZIO_COMPRESS_GZIP_1 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1370 intval <= ZIO_COMPRESS_GZIP_9) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1371 if (zfs_check_version(name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1372 SPA_VERSION_GZIP_COMPRESSION))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1373 return (ENOTSUP);
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1374 }
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
1375 break;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
1376
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
1377 case ZFS_PROP_COPIES:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1378 if (zfs_check_version(name, SPA_VERSION_DITTO_BLOCKS))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1379 return (ENOTSUP);
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
1380 break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1381 case ZFS_PROP_NORMALIZE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1382 case ZFS_PROP_UTF8ONLY:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1383 case ZFS_PROP_CASE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1384 if (zfs_check_version(name, SPA_VERSION_NORMALIZATION))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1385 return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1386
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
1387 }
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1388 if ((error = zfs_secpolicy_setprop(name, prop, CRED())) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1389 return (error);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1390 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1391
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1392 elem = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1393 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1394 const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
1395 zfs_prop_t prop = zfs_name_to_prop(propname);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1396
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1397 if (prop == ZPROP_INVAL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1398 VERIFY(nvpair_value_string(elem, &strval) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1399 error = dsl_prop_set(name, propname, 1,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1400 strlen(strval) + 1, strval);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1401 if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1402 continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1403 else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1404 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1405 }
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1406
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1407 switch (prop) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1408 case ZFS_PROP_QUOTA:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1409 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1410 (error = dsl_dir_set_quota(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1411 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1412 break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1413
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1414 case ZFS_PROP_REFQUOTA:
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1415 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1416 (error = dsl_dataset_set_quota(name, intval)) != 0)
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1417 return (error);
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1418 break;
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1419
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1420 case ZFS_PROP_RESERVATION:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1421 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1422 (error = dsl_dir_set_reservation(name,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1423 intval)) != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1424 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1425 break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1426
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1427 case ZFS_PROP_REFRESERVATION:
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1428 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1429 (error = dsl_dataset_set_reservation(name,
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1430 intval)) != 0)
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1431 return (error);
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1432 break;
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
1433
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1434 case ZFS_PROP_VOLSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1435 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1436 (error = zvol_set_volsize(name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1437 ddi_driver_major(zfs_dip), intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1438 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1439 break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1440
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1441 case ZFS_PROP_VOLBLOCKSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1442 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1443 (error = zvol_set_volblocksize(name, intval)) != 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1444 return (error);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1445 break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1446
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1447 case ZFS_PROP_VERSION:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1448 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1449 (error = zfs_set_version(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1450 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1451 break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1452
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1453 default:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1454 if (nvpair_type(elem) == DATA_TYPE_STRING) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1455 if (zfs_prop_get_type(prop) !=
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1456 PROP_TYPE_STRING)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1457 return (EINVAL);
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1458 VERIFY(nvpair_value_string(elem, &strval) == 0);
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1459 if ((error = dsl_prop_set(name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1460 nvpair_name(elem), 1, strlen(strval) + 1,
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1461 strval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1462 return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1463 } else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
1464 const char *unused;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
1465
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1466 VERIFY(nvpair_value_uint64(elem, &intval) == 0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1467
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1468 switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1469 case PROP_TYPE_NUMBER:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1470 break;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1471 case PROP_TYPE_STRING:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1472 return (EINVAL);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1473 case PROP_TYPE_INDEX:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1474 if (zfs_prop_index_to_string(prop,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1475 intval, &unused) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1476 return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1477 break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1478 default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1479 cmn_err(CE_PANIC,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1480 "unknown property type");
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1481 break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1482 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1483
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1484 if ((error = dsl_prop_set(name, propname,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1485 8, 1, &intval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
1486 return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1487 } else {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1488 return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1489 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1490 break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1491 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1492 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1493
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1494 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1495 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1496
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1497 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1498 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1499 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1500 * zc_value name of property to inherit
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1501 * zc_nvlist_src{_size} nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1502 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1503 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1504 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1505 static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1506 zfs_ioc_set_prop(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1507 {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1508 nvlist_t *nvl;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1509 int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1510
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1511 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1512 &nvl)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1513 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1514
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1515 error = zfs_set_prop_nvlist(zc->zc_name, nvl);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1516
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1517 nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1518 return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1519 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1520
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1521 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1522 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1523 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1524 * zc_value name of property to inherit
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1525 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1526 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1527 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1528 static int
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1529 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1530 {
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1531 /* the property name has been validated by zfs_secpolicy_inherit() */
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1532 return (dsl_prop_set(zc->zc_name, zc->zc_value, 0, 0, NULL));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1533 }
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1534
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
1535 static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
1536 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1537 {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1538 nvlist_t *props;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1539 spa_t *spa;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1540 int error;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1541
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1542 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1543 &props)))
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1544 return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1545
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1546 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1547 nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1548 return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1549 }
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1550
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1551 error = spa_prop_set(spa, props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1552
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1553 nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1554 spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1555
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1556 return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1557 }
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1558
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1559 static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
1560 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1561 {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1562 spa_t *spa;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1563 int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1564 nvlist_t *nvp = NULL;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1565
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1566 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1567 return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1568
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1569 error = spa_prop_get(spa, &nvp);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1570
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1571 if (error == 0 && zc->zc_nvlist_dst != NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1572 error = put_nvlist(zc, nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1573 else
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1574 error = EFAULT;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1575
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1576 spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1577
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1578 if (nvp)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1579 nvlist_free(nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1580 return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1581 }
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1582
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
1583 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1584 zfs_ioc_iscsi_perm_check(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1585 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1586 nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1587 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1588 uint32_t uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1589 uint32_t gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1590 uint32_t *groups;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1591 uint_t group_cnt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1592 cred_t *usercred;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1593
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1594 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1595 &nvp)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1596 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1597 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1598
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1599 if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1600 ZFS_DELEG_PERM_UID, &uid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1601 nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1602 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1603 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1604
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1605 if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1606 ZFS_DELEG_PERM_GID, &gid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1607 nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1608 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1609 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1610
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1611 if ((error = nvlist_lookup_uint32_array(nvp, ZFS_DELEG_PERM_GROUPS,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1612 &groups, &group_cnt)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1613 nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1614 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1615 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1616 usercred = cralloc();
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1617 if ((crsetugid(usercred, uid, gid) != 0) ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1618 (crsetgroups(usercred, group_cnt, (gid_t *)groups) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1619 nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1620 crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1621 return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1622 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1623 nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1624 error = dsl_deleg_access(zc->zc_name,
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1625 zfs_prop_to_name(ZFS_PROP_SHAREISCSI), usercred);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1626 crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1627 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1628 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1629
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1630 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1631 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1632 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1633 * zc_nvlist_src{_size} nvlist of delegated permissions
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1634 * zc_perm_action allow/unallow flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1635 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1636 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1637 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1638 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1639 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1640 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1641 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1642 nvlist_t *fsaclnv = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1643
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1644 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1645 &fsaclnv)) != 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1646 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1647
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1648 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1649 * Verify nvlist is constructed correctly
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1650 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1651 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1652 nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1653 return (EINVAL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1654 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1655
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1656 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1657 * If we don't have PRIV_SYS_MOUNT, then validate
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1658 * that user is allowed to hand out each permission in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1659 * the nvlist(s)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1660 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1661
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1662 error = secpolicy_zfs(CRED());
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1663 if (error) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1664 if (zc->zc_perm_action == B_FALSE) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1665 error = dsl_deleg_can_allow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1666 fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1667 } else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1668 error = dsl_deleg_can_unallow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1669 fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1670 }
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1671 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1672
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1673 if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1674 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1675
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1676 nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1677 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1678 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1679
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1680 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1681 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1682 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1683 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1684 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1685 * zc_nvlist_src{_size} nvlist of delegated permissions
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1686 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1687 static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1688 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1689 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1690 nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1691 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1692
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1693 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1694 error = put_nvlist(zc, nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1695 nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1696 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1697
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1698 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1699 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1700
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1701 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1702 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1703 * zc_name name of volume
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1704 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1705 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1706 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1707 static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1708 zfs_ioc_create_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1709 {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
1710 return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1711 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1712
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1713 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1714 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1715 * zc_name name of volume
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1716 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1717 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1718 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1719 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1720 zfs_ioc_remove_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1721 {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1722 return (zvol_remove_minor(zc->zc_name));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1723 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1725 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1726 * Search the vfs list for a specified resource. Returns a pointer to it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1727 * or NULL if no suitable entry is found. The caller of this routine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1728 * is responsible for releasing the returned vfs pointer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1729 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1730 static vfs_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1731 zfs_get_vfs(const char *resource)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1732 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1733 struct vfs *vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1734 struct vfs *vfs_found = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1736 vfs_list_read_lock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1737 vfsp = rootvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1738 do {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1739 if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1740 VFS_HOLD(vfsp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1741 vfs_found = vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1742 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1743 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1744 vfsp = vfsp->vfs_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1745 } while (vfsp != rootvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1746 vfs_list_unlock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1747 return (vfs_found);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1748 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1749
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1750 /* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1751 static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1752 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1753 {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1754 zfs_creat_t *zct = arg;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1755 uint64_t version;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1756
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1757 if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1758 version = ZPL_VERSION;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1759 else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1760 version = ZPL_VERSION_FUID - 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1761
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1762 (void) nvlist_lookup_uint64(zct->zct_props,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1763 zfs_prop_to_name(ZFS_PROP_VERSION), &version);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
1764
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1765 zfs_create_fs(os, cr, version, zct->zct_norm, tx);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1766 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1767
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1768 /*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1769 * zfs_prop_lookup()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1770 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1771 * Look for the property first in the existing property nvlist. If
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1772 * it's already present, you're done. If it's not there, attempt to
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1773 * find the property value from a parent dataset. If that fails, fall
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1774 * back to the property's default value. In either of these two
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1775 * cases, if update is TRUE, add a value for the property to the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1776 * property nvlist.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1777 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1778 * If the rval pointer is non-NULL, copy the discovered value to rval.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1779 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1780 * If we get any unexpected errors, bail and return the error number
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1781 * to the caller.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1782 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1783 * If we succeed, return 0.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1784 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1785 static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1786 zfs_prop_lookup(const char *parentname, zfs_prop_t propnum,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1787 nvlist_t *proplist, uint64_t *rval, boolean_t update)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1788 {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1789 const char *propname;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1790 uint64_t value;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1791 int error = ENOENT;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1792
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1793 propname = zfs_prop_to_name(propnum);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1794 if (proplist != NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1795 error = nvlist_lookup_uint64(proplist, propname, &value);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1796 if (error == ENOENT) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1797 error = dsl_prop_get_integer(parentname, propname,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1798 &value, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1799 if (error == ENOENT)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1800 value = zfs_prop_default_numeric(propnum);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1801 else if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1802 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1803 if (update) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1804 ASSERT(proplist != NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1805 error = nvlist_add_uint64(proplist, propname, value);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1806 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1807 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1808 if (error == 0 && rval)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1809 *rval = value;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1810 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1811 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1812
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1813 /*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1814 * zfs_normalization_get
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1815 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1816 * Get the normalization flag value. If the properties have
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1817 * non-default values, make sure the pool version is recent enough to
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1818 * support these choices.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1819 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1820 static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1821 zfs_normalization_get(const char *dataset, nvlist_t *proplist, int *norm,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1822 boolean_t update)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1823 {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1824 char parentname[MAXNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1825 char poolname[MAXNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1826 char *cp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1827 uint64_t value;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1828 int check = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1829 int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1830
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1831 ASSERT(norm != NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1832 *norm = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1833
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1834 (void) strncpy(parentname, dataset, sizeof (parentname));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1835 cp = strrchr(parentname, '@');
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1836 if (cp != NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1837 cp[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1838 } else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1839 cp = strrchr(parentname, '/');
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1840 if (cp == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1841 return (ENOENT);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1842 cp[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1843 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1844
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1845 (void) strncpy(poolname, dataset, sizeof (poolname));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1846 cp = strchr(poolname, '/');
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1847 if (cp != NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1848 cp[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1849
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1850 /*
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1851 * Make sure pool is of new enough vintage to support normalization.
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1852 */
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1853 if (zfs_check_version(poolname, SPA_VERSION_NORMALIZATION))
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1854 return (0);
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1855
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1856 error = zfs_prop_lookup(parentname, ZFS_PROP_UTF8ONLY,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1857 proplist, &value, update);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1858 if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1859 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1860 if (value != zfs_prop_default_numeric(ZFS_PROP_UTF8ONLY))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1861 check = 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1862
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1863 error = zfs_prop_lookup(parentname, ZFS_PROP_NORMALIZE,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1864 proplist, &value, update);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1865 if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1866 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1867 if (value != zfs_prop_default_numeric(ZFS_PROP_NORMALIZE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1868 check = 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1869 switch ((int)value) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1870 case ZFS_NORMALIZE_NONE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1871 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1872 case ZFS_NORMALIZE_C:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1873 *norm |= U8_TEXTPREP_NFC;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1874 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1875 case ZFS_NORMALIZE_D:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1876 *norm |= U8_TEXTPREP_NFD;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1877 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1878 case ZFS_NORMALIZE_KC:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1879 *norm |= U8_TEXTPREP_NFKC;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1880 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1881 case ZFS_NORMALIZE_KD:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1882 *norm |= U8_TEXTPREP_NFKD;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1883 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1884 default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1885 ASSERT((int)value >= ZFS_NORMALIZE_NONE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1886 ASSERT((int)value <= ZFS_NORMALIZE_KD);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1887 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1888 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1889 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1890
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1891 error = zfs_prop_lookup(parentname, ZFS_PROP_CASE,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1892 proplist, &value, update);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1893 if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1894 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1895 if (value != zfs_prop_default_numeric(ZFS_PROP_CASE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1896 check = 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1897 switch ((int)value) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1898 case ZFS_CASE_SENSITIVE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1899 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1900 case ZFS_CASE_INSENSITIVE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1901 *norm |= U8_TEXTPREP_TOUPPER;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1902 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1903 case ZFS_CASE_MIXED:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1904 *norm |= U8_TEXTPREP_TOUPPER;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1905 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1906 default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1907 ASSERT((int)value >= ZFS_CASE_SENSITIVE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1908 ASSERT((int)value <= ZFS_CASE_MIXED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1909 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1910 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1911 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1912
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1913 /*
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1914 * At the moment we are disabling non-default values for these
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1915 * properties because they cannot be preserved properly with a
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1916 * zfs send.
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1917 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1918 if (check == 1)
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1919 return (ENOTSUP);
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
1920
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1921 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1922 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1923
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1924 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1925 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1926 * zc_objset_type type of objset to create (fs vs zvol)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1927 * zc_name name of new objset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1928 * zc_value name of snapshot to clone from (may be empty)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1929 * zc_nvlist_src{_size} nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1930 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1931 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
1932 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1933 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1934 zfs_ioc_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1935 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1936 objset_t *clone;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1937 int error = 0;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1938 zfs_creat_t zct;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1939 nvlist_t *nvprops = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1940 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1941 dmu_objset_type_t type = zc->zc_objset_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1942
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1943 switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1944
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1945 case DMU_OST_ZFS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1946 cbfunc = zfs_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1947 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1948
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1949 case DMU_OST_ZVOL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1950 cbfunc = zvol_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1951 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1952
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1953 default:
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
1954 cbfunc = NULL;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
1955 }
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
1956 if (strchr(zc->zc_name, '@') ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
1957 strchr(zc->zc_name, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1958 return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1959
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1960 if (zc->zc_nvlist_src != NULL &&
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1961 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
1962 &nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1963 return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1964
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1965 zct.zct_norm = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1966 zct.zct_props = nvprops;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1967
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1968 if (zc->zc_value[0] != '\0') {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1969 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1970 * We're creating a clone of an existing snapshot.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1971 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1972 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1973 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1974 nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1975 return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1976 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1977
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1978 error = dmu_objset_open(zc->zc_value, type,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1979 DS_MODE_STANDARD | DS_MODE_READONLY, &clone);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1980 if (error) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
1981 nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1982 return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
1983 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1984 error = dmu_objset_create(zc->zc_name, type, clone, NULL, NULL);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1985 if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1986 dmu_objset_close(clone);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1987 nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1988 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1989 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1990 /*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1991 * If caller did not provide any properties, allocate
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1992 * an nvlist for properties, as we will be adding our set-once
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1993 * properties to it. This carries the choices made on the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1994 * original file system into the clone.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1995 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1996 if (nvprops == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1997 VERIFY(nvlist_alloc(&nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1998 NV_UNIQUE_NAME, KM_SLEEP) == 0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
1999
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2000 /*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2001 * We have to have normalization and case-folding
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2002 * flags correct when we do the file system creation,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2003 * so go figure them out now. All we really care about
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2004 * here is getting these values into the property list.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2005 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2006 error = zfs_normalization_get(zc->zc_value, nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2007 &zct.zct_norm, B_TRUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2008 if (error != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2009 dmu_objset_close(clone);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2010 nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2011 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2012 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2013 dmu_objset_close(clone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2014 } else {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2015 if (cbfunc == NULL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2016 nvlist_free(nvprops);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2017 return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2018 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2019
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2020 if (type == DMU_OST_ZVOL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2021 uint64_t volsize, volblocksize;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2022
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2023 if (nvprops == NULL ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2024 nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2025 zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2026 &volsize) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2027 nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2028 return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2029 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2030
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2031 if ((error = nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2032 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2033 &volblocksize)) != 0 && error != ENOENT) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2034 nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2035 return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2036 }
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
2037
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2038 if (error != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2039 volblocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2040 ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2041
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2042 if ((error = zvol_check_volblocksize(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2043 volblocksize)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2044 (error = zvol_check_volsize(volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2045 volblocksize)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2046 nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2047 return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2048 }
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2049 } else if (type == DMU_OST_ZFS) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2050 uint64_t version;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2051 int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2052
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2053 error = nvlist_lookup_uint64(nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2054 zfs_prop_to_name(ZFS_PROP_VERSION), &version);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2055
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2056 if (error == 0 && (version < ZPL_VERSION_INITIAL ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2057 version > ZPL_VERSION)) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2058 nvlist_free(nvprops);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2059 return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2060 } else if (error == 0 && version >= ZPL_VERSION_FUID &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2061 zfs_check_version(zc->zc_name, SPA_VERSION_FUID)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2062 nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2063 return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2064 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2065
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2066 /*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2067 * We have to have normalization and
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2068 * case-folding flags correct when we do the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2069 * file system creation, so go figure them out
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2070 * now. The final argument to zfs_normalization_get()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2071 * tells that routine not to update the nvprops
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2072 * list.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2073 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2074 error = zfs_normalization_get(zc->zc_name, nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2075 &zct.zct_norm, B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2076 if (error != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2077 nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2078 return (error);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2079 }
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2080 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2081 error = dmu_objset_create(zc->zc_name, type, NULL, cbfunc,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2082 &zct);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2083 }
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2084
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2085 /*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2086 * It would be nice to do this atomically.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2087 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2088 if (error == 0) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
2089 if ((error = zfs_set_prop_nvlist(zc->zc_name, nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2090 (void) dmu_objset_destroy(zc->zc_name);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2091 }
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2092
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2093 nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2094 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2095 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2096
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2097 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2098 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2099 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2100 * zc_value short name of snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2101 * zc_cookie recursive flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2102 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2103 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2104 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2105 static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2106 zfs_ioc_snapshot(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2107 {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2108 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2109 return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2110 return (dmu_objset_snapshot(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2111 zc->zc_value, zc->zc_cookie));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2112 }
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2113
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2114 int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2115 zfs_unmount_snap(char *name, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2116 {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2117 char *snapname = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2118 char *cp;
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2119 vfs_t *vfsp = NULL;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2120
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2121 /*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2122 * Snapshots (which are under .zfs control) must be unmounted
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2123 * before they can be destroyed.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2124 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2125
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2126 if (snapname) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2127 (void) strcat(name, "@");
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2128 (void) strcat(name, snapname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2129 vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2130 cp = strchr(name, '@');
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2131 *cp = '\0';
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2132 } else if (strchr(name, '@')) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2133 vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2134 }
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2135
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2136 if (vfsp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2137 /*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2138 * Always force the unmount for snapshots.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2139 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2140 int flag = MS_FORCE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2141 int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2142
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2143 if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2144 VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2145 return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2146 }
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2147 VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2148 if ((err = dounmount(vfsp, flag, kcred)) != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2149 return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2150 }
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2151 return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2152 }
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2153
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2154 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2155 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2156 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2157 * zc_value short name of snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2158 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2159 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2160 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2161 static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2162 zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2163 {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2164 int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2165
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2166 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2167 return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2168 err = dmu_objset_find(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2169 zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2170 if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2171 return (err);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2172 return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2173 }
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2174
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2175 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2176 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2177 * zc_name name of dataset to destroy
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2178 * zc_objset_type type of objset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2179 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2180 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2181 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2182 static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2183 zfs_ioc_destroy(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2184 {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2185 if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2186 int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2187 if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2188 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2189 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2190
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2191 return (dmu_objset_destroy(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2192 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2193
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2194 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2195 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2196 * zc_name name of snapshot to roll back to
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2197 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2198 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2199 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2200 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2201 zfs_ioc_rollback(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2202 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2203 return (dmu_objset_rollback(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2204 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2205
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2206 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2207 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2208 * zc_name old name of dataset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2209 * zc_value new name of dataset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2210 * zc_cookie recursive flag (only valid for snapshots)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2211 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2212 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2213 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2214 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2215 zfs_ioc_rename(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2216 {
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
2217 boolean_t recursive = zc->zc_cookie & 1;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2218
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2219 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2220 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2221 strchr(zc->zc_value, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2222 return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2223
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2224 /*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2225 * Unmount snapshot unless we're doing a recursive rename,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2226 * in which case the dataset code figures out which snapshots
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2227 * to unmount.
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2228 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2229 if (!recursive && strchr(zc->zc_name, '@') != NULL &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2230 zc->zc_objset_type == DMU_OST_ZFS) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2231 int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2232 if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2233 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2234 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2235
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
2236 return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2237 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2238
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2239 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2240 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2241 * zc_name name of containing filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2242 * zc_nvlist_src{_size} nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2243 * zc_value name of snapshot to create
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2244 * zc_string name of clone origin (if DRR_FLAG_CLONE)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2245 * zc_cookie file descriptor to recv from
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2246 * zc_begin_record the BEGIN record of the stream (not byteswapped)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2247 * zc_guid force flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2248 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2249 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2250 * zc_cookie number of bytes read
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2251 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2252 static int
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2253 zfs_ioc_recv(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2254 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2255 file_t *fp;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2256 objset_t *os;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2257 dmu_recv_cookie_t drc;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2258 zfsvfs_t *zfsvfs = NULL;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2259 boolean_t force = (boolean_t)zc->zc_guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2260 int error, fd;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2261 offset_t off;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2262 nvlist_t *props = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2263 objset_t *origin = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2264 char *tosnap;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2265 char tofs[ZFS_MAXNAMELEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2266
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
2267 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2268 strchr(zc->zc_value, '@') == NULL ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2269 strchr(zc->zc_value, '%'))
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
2270 return (EINVAL);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
2271
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2272 (void) strcpy(tofs, zc->zc_value);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2273 tosnap = strchr(tofs, '@');
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2274 *tosnap = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2275 tosnap++;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2276
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2277 if (zc->zc_nvlist_src != NULL &&
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2278 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2279 &props)) != 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2280 return (error);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2281
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2282 fd = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2283 fp = getf(fd);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2284 if (fp == NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2285 nvlist_free(props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2286 return (EBADF);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2287 }
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2288
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2289 /*
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2290 * Get the zfsvfs for the receiving objset. There
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2291 * won't be one if we're operating on a zvol, if the
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2292 * objset doesn't exist yet, or is not mounted.
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2293 */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2294
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2295 error = dmu_objset_open(tofs, DMU_OST_ANY,
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2296 DS_MODE_STANDARD | DS_MODE_READONLY, &os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2297 if (!error) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2298 if (dmu_objset_type(os) == DMU_OST_ZFS) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2299 mutex_enter(&os->os->os_user_ptr_lock);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2300 zfsvfs = dmu_objset_get_user(os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2301 if (zfsvfs != NULL)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2302 VFS_HOLD(zfsvfs->z_vfs);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2303 mutex_exit(&os->os->os_user_ptr_lock);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2304 }
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2305 dmu_objset_close(os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2306 }
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2307
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2308 if (zc->zc_string[0]) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2309 error = dmu_objset_open(zc->zc_string, DMU_OST_ANY,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2310 DS_MODE_STANDARD | DS_MODE_READONLY, &origin);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2311 if (error) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2312 if (zfsvfs != NULL)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2313 VFS_RELE(zfsvfs->z_vfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2314 nvlist_free(props);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2315 releasef(fd);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2316 return (error);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2317 }
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2318 }
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2319
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2320 error = dmu_recv_begin(tofs, tosnap, &zc->zc_begin_record,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2321 force, origin, zfsvfs != NULL, &drc);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2322 if (origin)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2323 dmu_objset_close(origin);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2324 if (error) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2325 if (zfsvfs != NULL)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2326 VFS_RELE(zfsvfs->z_vfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2327 nvlist_free(props);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2328 releasef(fd);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2329 return (error);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2330 }
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2331
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2332 /*
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2333 * If properties are supplied, they are to completely replace
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2334 * the existing ones; "inherit" any existing properties.
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2335 */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2336 if (props) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2337 objset_t *os;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2338 nvlist_t *nv = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2339
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2340 error = dmu_objset_open(tofs, DMU_OST_ANY,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2341 DS_MODE_STANDARD | DS_MODE_READONLY | DS_MODE_INCONSISTENT,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2342 &os);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2343 if (error == 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2344 error = dsl_prop_get_all(os, &nv);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2345 dmu_objset_close(os);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2346 }
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2347 if (error == 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2348 nvpair_t *elem;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2349 zfs_cmd_t zc2 = { 0 };
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2350
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2351 (void) strcpy(zc2.zc_name, tofs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2352 for (elem = nvlist_next_nvpair(nv, NULL); elem;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2353 elem = nvlist_next_nvpair(nv, elem)) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2354 (void) strcpy(zc2.zc_value, nvpair_name(elem));
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2355 if (zfs_secpolicy_inherit(&zc2, CRED()) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2356 (void) zfs_ioc_inherit_prop(&zc2);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2357 }
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2358 }
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2359 if (nv)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2360 nvlist_free(nv);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2361 }
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2362
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2363 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2364 * Set properties. Note, we ignore errors. Would be better to
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2365 * do best-effort in zfs_set_prop_nvlist, too.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2366 */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2367 (void) zfs_set_prop_nvlist(tofs, props);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2368 nvlist_free(props);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2369
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2370 off = fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2371 error = dmu_recv_stream(&drc, fp->f_vnode, &off);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2372
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2373 if (error == 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2374 if (zfsvfs != NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2375 char osname[MAXNAMELEN];
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2376 int mode;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2377
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2378 (void) zfs_suspend_fs(zfsvfs, osname, &mode);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2379 error = dmu_recv_end(&drc);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2380 error |= zfs_resume_fs(zfsvfs, osname, mode);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2381 } else {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2382 error = dmu_recv_end(&drc);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2383 }
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2384 }
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2385 if (zfsvfs != NULL)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2386 VFS_RELE(zfsvfs->z_vfs);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2387
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2388 zc->zc_cookie = off - fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2389 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2390 fp->f_offset = off;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2391
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2392 releasef(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2393 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2394 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2395
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2396 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2397 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2398 * zc_name name of snapshot to send
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2399 * zc_value short name of incremental fromsnap (may be empty)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2400 * zc_cookie file descriptor to send stream to
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2401 * zc_obj fromorigin flag (mutually exclusive with zc_value)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2402 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2403 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2404 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2405 static int
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2406 zfs_ioc_send(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2407 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2408 objset_t *fromsnap = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2409 objset_t *tosnap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2410 file_t *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2411 int error;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2412 offset_t off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2414 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2415 DS_MODE_STANDARD | DS_MODE_READONLY, &tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2416 if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2417 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2418
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2419 if (zc->zc_value[0] != '\0') {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2420 char buf[MAXPATHLEN];
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2421 char *cp;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2422
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2423 (void) strncpy(buf, zc->zc_name, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2424 cp = strchr(buf, '@');
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2425 if (cp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2426 *(cp+1) = 0;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2427 (void) strncat(buf, zc->zc_value, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
2428 error = dmu_objset_open(buf, DMU_OST_ANY,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2429 DS_MODE_STANDARD | DS_MODE_READONLY, &fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2430 if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2431 dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2432 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2433 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2434 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2436 fp = getf(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2437 if (fp == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2438 dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2439 if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2440 dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2441 return (EBADF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2442 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2443
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2444 off = fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2445 error = dmu_sendbackup(tosnap, fromsnap, zc->zc_obj, fp->f_vnode, &off);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2446
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2447 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2448 fp->f_offset = off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2449 releasef(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2450 if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2451 dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2452 dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2453 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2454 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2455
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2456 static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2457 zfs_ioc_inject_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2458 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2459 int id, error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2460
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2461 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2462 &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2463
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2464 if (error == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2465 zc->zc_guid = (uint64_t)id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2466
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2467 return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2468 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2469
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2470 static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2471 zfs_ioc_clear_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2472 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2473 return (zio_clear_fault((int)zc->zc_guid));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2474 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2475
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2476 static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2477 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2478 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2479 int id = (int)zc->zc_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2480 int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2481
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2482 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2483 &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2484
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2485 zc->zc_guid = id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2486
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2487 return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2488 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2489
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2490 static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2491 zfs_ioc_error_log(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2492 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2493 spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2494 int error;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2495 size_t count = (size_t)zc->zc_nvlist_dst_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2496
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2497 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2498 return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2499
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2500 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2501 &count);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2502 if (error == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2503 zc->zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2504 else
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2505 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2506
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2507 spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2508
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2509 return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2510 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2511
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2512 static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2513 zfs_ioc_clear(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2514 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2515 spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2516 vdev_t *vd;
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
2517 uint64_t txg;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2518 int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2519
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2520 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2521 return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2522
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2523 /*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2524 * Try to resume any I/Os which may have been suspended
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2525 * as a result of a complete pool failure.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2526 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2527 if (!list_is_empty(&spa->spa_zio_list)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2528 if (zio_vdev_resume_io(spa) != 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2529 spa_close(spa, FTAG);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2530 return (EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2531 }
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2532 }
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2533
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
2534 txg = spa_vdev_enter(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2535
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2536 if (zc->zc_guid == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2537 vd = NULL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2538 } else if ((vd = spa_lookup_by_guid(spa, zc->zc_guid)) == NULL) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
2539 (void) spa_vdev_exit(spa, NULL, txg, ENODEV);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2540 spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2541 return (ENODEV);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2542 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2543
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
2544 vdev_clear(spa, vd, B_TRUE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2545
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
2546 (void) spa_vdev_exit(spa, NULL, txg, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2547
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2548 spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2549
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2550 return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2551 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2552
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2553 /*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2554 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2555 * zc_name name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2556 * zc_value name of origin snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2557 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2558 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2559 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2560 static int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
2561 zfs_ioc_promote(zfs_cmd_t *zc)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
2562 {
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2563 char *cp;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2564
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2565 /*
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2566 * We don't need to unmount *all* the origin fs's snapshots, but
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2567 * it's easier.
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2568 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2569 cp = strchr(zc->zc_value, '@');
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2570 if (cp)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2571 *cp = '\0';
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2572 (void) dmu_objset_find(zc->zc_value,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
2573 zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
2574 return (dsl_dataset_promote(zc->zc_name));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
2575 }
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
2576
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2577 /*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2578 * We don't want to have a hard dependency
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2579 * against some special symbols in sharefs
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2580 * nfs, and smbsrv. Determine them if needed when
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2581 * the first file system is shared.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2582 * Neither sharefs, nfs or smbsrv are unloadable modules.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2583 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2584 int (*znfsexport_fs)(void *arg);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2585 int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2586 int (*zsmbexport_fs)(void *arg, boolean_t add_share);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2587
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2588 int zfs_nfsshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2589 int zfs_smbshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2590
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2591 ddi_modhandle_t nfs_mod;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2592 ddi_modhandle_t sharefs_mod;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2593 ddi_modhandle_t smbsrv_mod;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2594 kmutex_t zfs_share_lock;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2595
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2596 static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2597 zfs_init_sharefs()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2598 {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2599 int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2600
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2601 ASSERT(MUTEX_HELD(&zfs_share_lock));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2602 /* Both NFS and SMB shares also require sharetab support. */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2603 if (sharefs_mod == NULL && ((sharefs_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2604 ddi_modopen("fs/sharefs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2605 KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2606 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2607 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2608 if (zshare_fs == NULL && ((zshare_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2609 (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2610 ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2611 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2612 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2613 return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2614 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2615
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2616 static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2617 zfs_ioc_share(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2618 {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2619 int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2620 int opcode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2621
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2622 switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2623 case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2624 case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2625 if (zfs_nfsshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2626 mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2627 if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2628 KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2629 mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2630 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2631 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2632 if (znfsexport_fs == NULL &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2633 ((znfsexport_fs = (int (*)(void *))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2634 ddi_modsym(nfs_mod,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2635 "nfs_export", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2636 mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2637 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2638 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2639 error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2640 if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2641 mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2642 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2643 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2644 zfs_nfsshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2645 mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2646 }
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2647 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2648 case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2649 case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2650 if (zfs_smbshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2651 mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2652 if (smbsrv_mod == NULL && ((smbsrv_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2653 ddi_modopen("drv/smbsrv",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2654 KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2655 mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2656 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2657 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2658 if (zsmbexport_fs == NULL && ((zsmbexport_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2659 (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2660 "lmshrd_share_upcall", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2661 mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2662 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2663 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2664 error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2665 if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2666 mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2667 return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2668 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2669 zfs_smbshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2670 mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2671 }
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2672 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2673 default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2674 return (EINVAL);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2675 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2676
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2677 switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2678 case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2679 case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2680 if (error =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2681 znfsexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2682 (uintptr_t)zc->zc_share.z_exportdata))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2683 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2684 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2685 case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2686 case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2687 if (error = zsmbexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2688 (uintptr_t)zc->zc_share.z_exportdata,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2689 zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2690 B_TRUE : B_FALSE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2691 return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2692 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2693 break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2694 }
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2695
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2696 opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2697 zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2698 SHAREFS_ADD : SHAREFS_REMOVE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2699
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2700 /*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2701 * Add or remove share from sharetab
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2702 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2703 error = zshare_fs(opcode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2704 (void *)(uintptr_t)zc->zc_share.z_sharedata,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2705 zc->zc_share.z_sharemax);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2706
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2707 return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2708
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2709 }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2710
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2711 /*
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
2712 * pool create, destroy, and export don't log the history as part of
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
2713 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
2714 * do the logging of those commands.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2715 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2716 static zfs_ioc_vec_t zfs_ioc_vec[] = {
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
2717 { zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE },
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2718 { zfs_ioc_pool_destroy, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2719 { zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2720 { zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2721 { zfs_ioc_pool_configs, zfs_secpolicy_none, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2722 { zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2723 { zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2724 { zfs_ioc_pool_scrub, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2725 { zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2726 { zfs_ioc_pool_upgrade, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2727 { zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2728 { zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2729 { zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2730 { zfs_ioc_vdev_set_state, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2731 { zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2732 { zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2733 { zfs_ioc_vdev_setpath, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2734 { zfs_ioc_objset_stats, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
2735 { zfs_ioc_objset_version, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2736 { zfs_ioc_dataset_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2737 DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2738 { zfs_ioc_snapshot_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2739 DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2740 { zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2741 { zfs_ioc_create_minor, zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2742 { zfs_ioc_remove_minor, zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2743 { zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2744 { zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2745 { zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2746 { zfs_ioc_rename, zfs_secpolicy_rename, DATASET_NAME, B_TRUE },
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2747 { zfs_ioc_recv, zfs_secpolicy_receive, DATASET_NAME, B_TRUE },
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
2748 { zfs_ioc_send, zfs_secpolicy_send, DATASET_NAME, B_TRUE },
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2749 { zfs_ioc_inject_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2750 { zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2751 { zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2752 { zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2753 { zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2754 { zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2755 { zfs_ioc_destroy_snaps, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2756 { zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2757 { zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2758 { zfs_ioc_obj_to_path, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2759 { zfs_ioc_pool_set_props, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2760 { zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2761 { zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2762 { zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2763 { zfs_ioc_iscsi_perm_check, zfs_secpolicy_iscsi,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2764 DATASET_NAME, B_FALSE },
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
2765 { zfs_ioc_share, zfs_secpolicy_share, DATASET_NAME, B_FALSE },
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
2766 { zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2767 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2768
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2769 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2770 zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2771 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2772 zfs_cmd_t *zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2773 uint_t vec;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2774 int error, rc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2775
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2776 if (getminor(dev) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2777 return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2778
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2779 vec = cmd - ZFS_IOC;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
2780 ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2781
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2782 if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2783 return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2785 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2786
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2787 error = xcopyin((void *)arg, zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2788
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
2789 if (error == 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2790 error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2791
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2792 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2793 * Ensure that all pool/dataset names are valid before we pass down to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2794 * the lower layers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2795 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2796 if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2797 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2798 switch (zfs_ioc_vec[vec].zvec_namecheck) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2799 case POOL_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2800 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2801 error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2802 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2803
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2804 case DATASET_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2805 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2806 error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2807 break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
2808
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2809 case NO_NAME:
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
2810 break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2811 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2812 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2813
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2814 if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2815 error = zfs_ioc_vec[vec].zvec_func(zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2816
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2817 rc = xcopyout(zc, (void *)arg, sizeof (zfs_cmd_t));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2818 if (error == 0) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
2819 error = rc;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2820 if (zfs_ioc_vec[vec].zvec_his_log == B_TRUE)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2821 zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2822 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2823
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2824 kmem_free(zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2825 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2826 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2827
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2828 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2829 zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2830 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2831 if (cmd != DDI_ATTACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2832 return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2833
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2834 if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2835 DDI_PSEUDO, 0) == DDI_FAILURE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2836 return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2837
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2838 zfs_dip = dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2840 ddi_report_dev(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2841
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2842 return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2843 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2844
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2845 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2846 zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2847 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2848 if (spa_busy() || zfs_busy() || zvol_busy())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2849 return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2850
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2851 if (cmd != DDI_DETACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2852 return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2853
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2854 zfs_dip = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2856 ddi_prop_remove_all(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2857 ddi_remove_minor_node(dip, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2858
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2859 return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2860 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2861
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2862 /*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2863 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2864 zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2865 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2866 switch (infocmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2867 case DDI_INFO_DEVT2DEVINFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2868 *result = zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2869 return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2870
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2871 case DDI_INFO_DEVT2INSTANCE:
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2872 *result = (void *)0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2873 return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2874 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2875
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2876 return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2877 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2878
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2879 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2880 * OK, so this is a little weird.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2881 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2882 * /dev/zfs is the control node, i.e. minor 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2883 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2884 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2885 * /dev/zfs has basically nothing to do except serve up ioctls,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2886 * so most of the standard driver entry points are in zvol.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2887 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2888 static struct cb_ops zfs_cb_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2889 zvol_open, /* open */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2890 zvol_close, /* close */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2891 zvol_strategy, /* strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2892 nodev, /* print */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2893 nodev, /* dump */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2894 zvol_read, /* read */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2895 zvol_write, /* write */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2896 zfsdev_ioctl, /* ioctl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2897 nodev, /* devmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2898 nodev, /* mmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2899 nodev, /* segmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2900 nochpoll, /* poll */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2901 ddi_prop_op, /* prop_op */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2902 NULL, /* streamtab */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2903 D_NEW | D_MP | D_64BIT, /* Driver compatibility flag */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2904 CB_REV, /* version */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
2905 nodev, /* async read */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
2906 nodev, /* async write */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2907 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2908
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2909 static struct dev_ops zfs_dev_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2910 DEVO_REV, /* version */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2911 0, /* refcnt */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2912 zfs_info, /* info */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2913 nulldev, /* identify */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2914 nulldev, /* probe */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2915 zfs_attach, /* attach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2916 zfs_detach, /* detach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2917 nodev, /* reset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2918 &zfs_cb_ops, /* driver operations */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2919 NULL /* no bus operations */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2920 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2921
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2922 static struct modldrv zfs_modldrv = {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
2923 &mod_driverops, "ZFS storage pool version " SPA_VERSION_STRING,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
2924 &zfs_dev_ops
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2925 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2927 static struct modlinkage modlinkage = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2928 MODREV_1,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2929 (void *)&zfs_modlfs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2930 (void *)&zfs_modldrv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2931 NULL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2932 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2933
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
2934
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
2935 uint_t zfs_fsyncer_key;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2936 extern uint_t rrw_tsd_key;
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
2937
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2938 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2939 _init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2940 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2941 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2942
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2943 spa_init(FREAD | FWRITE);
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2944 zfs_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2945 zvol_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2946
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2947 if ((error = mod_install(&modlinkage)) != 0) {
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2948 zvol_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2949 zfs_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2950 spa_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2951 return (error);
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
2952 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2953
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
2954 tsd_create(&zfs_fsyncer_key, NULL);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
2955 tsd_create(&rrw_tsd_key, NULL);
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
2956
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2957 error = ldi_ident_from_mod(&modlinkage, &zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2958 ASSERT(error == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2959 mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2960
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2961 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2962 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2963
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2964 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2965 _fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2966 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2967 int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2968
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
2969 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2970 return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2971
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2972 if ((error = mod_remove(&modlinkage)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2973 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2974
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2975 zvol_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2976 zfs_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2977 spa_fini();
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2978 if (zfs_nfsshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2979 (void) ddi_modclose(nfs_mod);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2980 if (zfs_smbshare_inited)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2981 (void) ddi_modclose(smbsrv_mod);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
2982 if (zfs_nfsshare_inited || zfs_smbshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2983 (void) ddi_modclose(sharefs_mod);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2984
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
2985 tsd_destroy(&zfs_fsyncer_key);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2986 ldi_ident_release(zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2987 zfs_li = NULL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
2988 mutex_destroy(&zfs_share_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2989
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2990 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2991 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2992
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2993 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2994 _info(struct modinfo *modinfop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2995 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2996 return (mod_info(&modlinkage, modinfop));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2997 }