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