author | gw25295 |
Fri, 11 Apr 2008 18:36:28 -0700 | |
changeset 6423 | 437422a29d3a |
parent 6168 | 51c045dcc498 |
child 6612 | bed68cb8aa8c |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 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 |
*/ |
|
3126 | 21 |
|
789 | 22 |
/* |
5977
33727f49aeaa
6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents:
5751
diff
changeset
|
23 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
27 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
28 |
||
29 |
#include <assert.h> |
|
30 |
#include <ctype.h> |
|
31 |
#include <errno.h> |
|
32 |
#include <libdevinfo.h> |
|
33 |
#include <libintl.h> |
|
34 |
#include <math.h> |
|
35 |
#include <stdio.h> |
|
36 |
#include <stdlib.h> |
|
37 |
#include <strings.h> |
|
38 |
#include <unistd.h> |
|
5367 | 39 |
#include <stddef.h> |
789 | 40 |
#include <zone.h> |
2082 | 41 |
#include <fcntl.h> |
789 | 42 |
#include <sys/mntent.h> |
43 |
#include <sys/mnttab.h> |
|
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
44 |
#include <sys/mount.h> |
4543 | 45 |
#include <sys/avl.h> |
46 |
#include <priv.h> |
|
47 |
#include <pwd.h> |
|
48 |
#include <grp.h> |
|
49 |
#include <stddef.h> |
|
50 |
#include <ucred.h> |
|
789 | 51 |
|
52 |
#include <sys/spa.h> |
|
2676 | 53 |
#include <sys/zap.h> |
789 | 54 |
#include <libzfs.h> |
55 |
||
56 |
#include "zfs_namecheck.h" |
|
57 |
#include "zfs_prop.h" |
|
58 |
#include "libzfs_impl.h" |
|
4543 | 59 |
#include "zfs_deleg.h" |
789 | 60 |
|
4007 | 61 |
static int zvol_create_link_common(libzfs_handle_t *, const char *, int); |
62 |
||
789 | 63 |
/* |
64 |
* Given a single type (not a mask of types), return the type in a human |
|
65 |
* readable form. |
|
66 |
*/ |
|
67 |
const char * |
|
68 |
zfs_type_to_name(zfs_type_t type) |
|
69 |
{ |
|
70 |
switch (type) { |
|
71 |
case ZFS_TYPE_FILESYSTEM: |
|
72 |
return (dgettext(TEXT_DOMAIN, "filesystem")); |
|
73 |
case ZFS_TYPE_SNAPSHOT: |
|
74 |
return (dgettext(TEXT_DOMAIN, "snapshot")); |
|
75 |
case ZFS_TYPE_VOLUME: |
|
76 |
return (dgettext(TEXT_DOMAIN, "volume")); |
|
77 |
} |
|
78 |
||
79 |
return (NULL); |
|
80 |
} |
|
81 |
||
82 |
/* |
|
83 |
* Given a path and mask of ZFS types, return a string describing this dataset. |
|
84 |
* This is used when we fail to open a dataset and we cannot get an exact type. |
|
85 |
* We guess what the type would have been based on the path and the mask of |
|
86 |
* acceptable types. |
|
87 |
*/ |
|
88 |
static const char * |
|
89 |
path_to_str(const char *path, int types) |
|
90 |
{ |
|
91 |
/* |
|
92 |
* When given a single type, always report the exact type. |
|
93 |
*/ |
|
94 |
if (types == ZFS_TYPE_SNAPSHOT) |
|
95 |
return (dgettext(TEXT_DOMAIN, "snapshot")); |
|
96 |
if (types == ZFS_TYPE_FILESYSTEM) |
|
97 |
return (dgettext(TEXT_DOMAIN, "filesystem")); |
|
98 |
if (types == ZFS_TYPE_VOLUME) |
|
99 |
return (dgettext(TEXT_DOMAIN, "volume")); |
|
100 |
||
101 |
/* |
|
102 |
* The user is requesting more than one type of dataset. If this is the |
|
103 |
* case, consult the path itself. If we're looking for a snapshot, and |
|
104 |
* a '@' is found, then report it as "snapshot". Otherwise, remove the |
|
105 |
* snapshot attribute and try again. |
|
106 |
*/ |
|
107 |
if (types & ZFS_TYPE_SNAPSHOT) { |
|
108 |
if (strchr(path, '@') != NULL) |
|
109 |
return (dgettext(TEXT_DOMAIN, "snapshot")); |
|
110 |
return (path_to_str(path, types & ~ZFS_TYPE_SNAPSHOT)); |
|
111 |
} |
|
112 |
||
113 |
||
114 |
/* |
|
115 |
* The user has requested either filesystems or volumes. |
|
116 |
* We have no way of knowing a priori what type this would be, so always |
|
117 |
* report it as "filesystem" or "volume", our two primitive types. |
|
118 |
*/ |
|
119 |
if (types & ZFS_TYPE_FILESYSTEM) |
|
120 |
return (dgettext(TEXT_DOMAIN, "filesystem")); |
|
121 |
||
122 |
assert(types & ZFS_TYPE_VOLUME); |
|
123 |
return (dgettext(TEXT_DOMAIN, "volume")); |
|
124 |
} |
|
125 |
||
126 |
/* |
|
127 |
* Validate a ZFS path. This is used even before trying to open the dataset, to |
|
128 |
* provide a more meaningful error message. We place a more useful message in |
|
129 |
* 'buf' detailing exactly why the name was not valid. |
|
130 |
*/ |
|
131 |
static int |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
132 |
zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
133 |
boolean_t modifying) |
789 | 134 |
{ |
135 |
namecheck_err_t why; |
|
136 |
char what; |
|
137 |
||
138 |
if (dataset_namecheck(path, &why, &what) != 0) { |
|
2082 | 139 |
if (hdl != NULL) { |
789 | 140 |
switch (why) { |
1003 | 141 |
case NAME_ERR_TOOLONG: |
2082 | 142 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
143 |
"name is too long")); |
|
1003 | 144 |
break; |
145 |
||
789 | 146 |
case NAME_ERR_LEADING_SLASH: |
2082 | 147 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
148 |
"leading slash in name")); |
|
789 | 149 |
break; |
150 |
||
151 |
case NAME_ERR_EMPTY_COMPONENT: |
|
2082 | 152 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
153 |
"empty component in name")); |
|
789 | 154 |
break; |
155 |
||
156 |
case NAME_ERR_TRAILING_SLASH: |
|
2082 | 157 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
158 |
"trailing slash in name")); |
|
789 | 159 |
break; |
160 |
||
161 |
case NAME_ERR_INVALCHAR: |
|
2082 | 162 |
zfs_error_aux(hdl, |
789 | 163 |
dgettext(TEXT_DOMAIN, "invalid character " |
2082 | 164 |
"'%c' in name"), what); |
789 | 165 |
break; |
166 |
||
167 |
case NAME_ERR_MULTIPLE_AT: |
|
2082 | 168 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
169 |
"multiple '@' delimiters in name")); |
|
789 | 170 |
break; |
2856 | 171 |
|
172 |
case NAME_ERR_NOLETTER: |
|
173 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
174 |
"pool doesn't begin with a letter")); |
|
175 |
break; |
|
176 |
||
177 |
case NAME_ERR_RESERVED: |
|
178 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
179 |
"name is reserved")); |
|
180 |
break; |
|
181 |
||
182 |
case NAME_ERR_DISKLIKE: |
|
183 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
184 |
"reserved disk name")); |
|
185 |
break; |
|
789 | 186 |
} |
187 |
} |
|
188 |
||
189 |
return (0); |
|
190 |
} |
|
191 |
||
192 |
if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) { |
|
2082 | 193 |
if (hdl != NULL) |
194 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
195 |
"snapshot delimiter '@' in filesystem name")); |
|
789 | 196 |
return (0); |
197 |
} |
|
198 |
||
2199 | 199 |
if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) { |
200 |
if (hdl != NULL) |
|
201 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3413
f4cbe0204ab7
6471255 Some ZFS error messages contain spelling errors
mmusante
parents:
3377
diff
changeset
|
202 |
"missing '@' delimiter in snapshot name")); |
2199 | 203 |
return (0); |
204 |
} |
|
205 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
206 |
if (modifying && strchr(path, '%') != NULL) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
207 |
if (hdl != NULL) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
208 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
209 |
"invalid character %c in name"), '%'); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
210 |
return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
211 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
212 |
|
2082 | 213 |
return (-1); |
789 | 214 |
} |
215 |
||
216 |
int |
|
217 |
zfs_name_valid(const char *name, zfs_type_t type) |
|
218 |
{ |
|
6423 | 219 |
if (type == ZFS_TYPE_POOL) |
220 |
return (zpool_name_valid(NULL, B_FALSE, name)); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
221 |
return (zfs_validate_name(NULL, name, type, B_FALSE)); |
789 | 222 |
} |
223 |
||
224 |
/* |
|
2676 | 225 |
* This function takes the raw DSL properties, and filters out the user-defined |
226 |
* properties into a separate nvlist. |
|
227 |
*/ |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
228 |
static nvlist_t * |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
229 |
process_user_props(zfs_handle_t *zhp, nvlist_t *props) |
2676 | 230 |
{ |
231 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
232 |
nvpair_t *elem; |
|
233 |
nvlist_t *propval; |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
234 |
nvlist_t *nvl; |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
235 |
|
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
236 |
if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) { |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
237 |
(void) no_memory(hdl); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
238 |
return (NULL); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
239 |
} |
2676 | 240 |
|
241 |
elem = NULL; |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
242 |
while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { |
2676 | 243 |
if (!zfs_prop_user(nvpair_name(elem))) |
244 |
continue; |
|
245 |
||
246 |
verify(nvpair_value_nvlist(elem, &propval) == 0); |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
247 |
if (nvlist_add_nvlist(nvl, nvpair_name(elem), propval) != 0) { |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
248 |
nvlist_free(nvl); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
249 |
(void) no_memory(hdl); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
250 |
return (NULL); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
251 |
} |
2676 | 252 |
} |
253 |
||
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
254 |
return (nvl); |
2676 | 255 |
} |
256 |
||
257 |
/* |
|
789 | 258 |
* Utility function to gather stats (objset and zpl) for the given object. |
259 |
*/ |
|
260 |
static int |
|
261 |
get_stats(zfs_handle_t *zhp) |
|
262 |
{ |
|
263 |
zfs_cmd_t zc = { 0 }; |
|
2676 | 264 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
265 |
nvlist_t *allprops, *userprops; |
789 | 266 |
|
267 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
268 |
||
2676 | 269 |
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0) |
2082 | 270 |
return (-1); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
271 |
|
2082 | 272 |
while (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) { |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
273 |
if (errno == ENOMEM) { |
2676 | 274 |
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) { |
275 |
zcmd_free_nvlists(&zc); |
|
2082 | 276 |
return (-1); |
2676 | 277 |
} |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
278 |
} else { |
2676 | 279 |
zcmd_free_nvlists(&zc); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
280 |
return (-1); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
281 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
282 |
} |
789 | 283 |
|
2885 | 284 |
zhp->zfs_dmustats = zc.zc_objset_stats; /* structure assignment */ |
789 | 285 |
|
2676 | 286 |
(void) strlcpy(zhp->zfs_root, zc.zc_value, sizeof (zhp->zfs_root)); |
1544 | 287 |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
288 |
if (zcmd_read_dst_nvlist(hdl, &zc, &allprops) != 0) { |
2676 | 289 |
zcmd_free_nvlists(&zc); |
2082 | 290 |
return (-1); |
291 |
} |
|
789 | 292 |
|
2676 | 293 |
zcmd_free_nvlists(&zc); |
294 |
||
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
295 |
if ((userprops = process_user_props(zhp, allprops)) == NULL) { |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
296 |
nvlist_free(allprops); |
2676 | 297 |
return (-1); |
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
298 |
} |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
299 |
|
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
300 |
nvlist_free(zhp->zfs_props); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
301 |
nvlist_free(zhp->zfs_user_props); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
302 |
|
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
303 |
zhp->zfs_props = allprops; |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
304 |
zhp->zfs_user_props = userprops; |
2082 | 305 |
|
789 | 306 |
return (0); |
307 |
} |
|
308 |
||
309 |
/* |
|
310 |
* Refresh the properties currently stored in the handle. |
|
311 |
*/ |
|
312 |
void |
|
313 |
zfs_refresh_properties(zfs_handle_t *zhp) |
|
314 |
{ |
|
315 |
(void) get_stats(zhp); |
|
316 |
} |
|
317 |
||
318 |
/* |
|
319 |
* Makes a handle from the given dataset name. Used by zfs_open() and |
|
320 |
* zfs_iter_* to create child handles on the fly. |
|
321 |
*/ |
|
322 |
zfs_handle_t * |
|
2082 | 323 |
make_dataset_handle(libzfs_handle_t *hdl, const char *path) |
789 | 324 |
{ |
2082 | 325 |
zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1); |
4543 | 326 |
char *logstr; |
2082 | 327 |
|
328 |
if (zhp == NULL) |
|
329 |
return (NULL); |
|
330 |
||
331 |
zhp->zfs_hdl = hdl; |
|
789 | 332 |
|
4543 | 333 |
/* |
334 |
* Preserve history log string. |
|
335 |
* any changes performed here will be |
|
336 |
* logged as an internal event. |
|
337 |
*/ |
|
338 |
logstr = zhp->zfs_hdl->libzfs_log_str; |
|
339 |
zhp->zfs_hdl->libzfs_log_str = NULL; |
|
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
340 |
top: |
789 | 341 |
(void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name)); |
342 |
||
343 |
if (get_stats(zhp) != 0) { |
|
4543 | 344 |
zhp->zfs_hdl->libzfs_log_str = logstr; |
789 | 345 |
free(zhp); |
346 |
return (NULL); |
|
347 |
} |
|
348 |
||
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
349 |
if (zhp->zfs_dmustats.dds_inconsistent) { |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
350 |
zfs_cmd_t zc = { 0 }; |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
351 |
|
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
352 |
/* |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
353 |
* If it is dds_inconsistent, then we've caught it in |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
354 |
* the middle of a 'zfs receive' or 'zfs destroy', and |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
355 |
* it is inconsistent from the ZPL's point of view, so |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
356 |
* can't be mounted. However, it could also be that we |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
357 |
* have crashed in the middle of one of those |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
358 |
* operations, in which case we need to get rid of the |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
359 |
* inconsistent state. We do that by either rolling |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
360 |
* back to the previous snapshot (which will fail if |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
361 |
* there is none), or destroying the filesystem. Note |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
362 |
* that if we are still in the middle of an active |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
363 |
* 'receive' or 'destroy', then the rollback and destroy |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
364 |
* will fail with EBUSY and we will drive on as usual. |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
365 |
*/ |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
366 |
|
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
367 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
368 |
|
2885 | 369 |
if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL) { |
2082 | 370 |
(void) zvol_remove_link(hdl, zhp->zfs_name); |
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
371 |
zc.zc_objset_type = DMU_OST_ZVOL; |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
372 |
} else { |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
373 |
zc.zc_objset_type = DMU_OST_ZFS; |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
374 |
} |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
375 |
|
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
376 |
/* |
5331 | 377 |
* If we can successfully destroy it, pretend that it |
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
378 |
* never existed. |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
379 |
*/ |
2082 | 380 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc) == 0) { |
4543 | 381 |
zhp->zfs_hdl->libzfs_log_str = logstr; |
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
382 |
free(zhp); |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
383 |
errno = ENOENT; |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
384 |
return (NULL); |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
385 |
} |
5367 | 386 |
/* If we can successfully roll it back, reget the stats */ |
387 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_ROLLBACK, &zc) == 0) |
|
388 |
goto top; |
|
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
389 |
} |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1749
diff
changeset
|
390 |
|
789 | 391 |
/* |
392 |
* We've managed to open the dataset and gather statistics. Determine |
|
393 |
* the high-level type. |
|
394 |
*/ |
|
2885 | 395 |
if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL) |
396 |
zhp->zfs_head_type = ZFS_TYPE_VOLUME; |
|
397 |
else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS) |
|
398 |
zhp->zfs_head_type = ZFS_TYPE_FILESYSTEM; |
|
399 |
else |
|
400 |
abort(); |
|
401 |
||
789 | 402 |
if (zhp->zfs_dmustats.dds_is_snapshot) |
403 |
zhp->zfs_type = ZFS_TYPE_SNAPSHOT; |
|
404 |
else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL) |
|
405 |
zhp->zfs_type = ZFS_TYPE_VOLUME; |
|
406 |
else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS) |
|
407 |
zhp->zfs_type = ZFS_TYPE_FILESYSTEM; |
|
408 |
else |
|
2082 | 409 |
abort(); /* we should never see any other types */ |
789 | 410 |
|
4543 | 411 |
zhp->zfs_hdl->libzfs_log_str = logstr; |
789 | 412 |
return (zhp); |
413 |
} |
|
414 |
||
415 |
/* |
|
416 |
* Opens the given snapshot, filesystem, or volume. The 'types' |
|
417 |
* argument is a mask of acceptable types. The function will print an |
|
418 |
* appropriate error message and return NULL if it can't be opened. |
|
419 |
*/ |
|
420 |
zfs_handle_t * |
|
2082 | 421 |
zfs_open(libzfs_handle_t *hdl, const char *path, int types) |
789 | 422 |
{ |
423 |
zfs_handle_t *zhp; |
|
2082 | 424 |
char errbuf[1024]; |
425 |
||
426 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
427 |
dgettext(TEXT_DOMAIN, "cannot open '%s'"), path); |
|
789 | 428 |
|
429 |
/* |
|
2082 | 430 |
* Validate the name before we even try to open it. |
789 | 431 |
*/ |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
432 |
if (!zfs_validate_name(hdl, path, ZFS_TYPE_DATASET, B_FALSE)) { |
2082 | 433 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
434 |
"invalid dataset name")); |
|
435 |
(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf); |
|
789 | 436 |
return (NULL); |
437 |
} |
|
438 |
||
439 |
/* |
|
440 |
* Try to get stats for the dataset, which will tell us if it exists. |
|
441 |
*/ |
|
442 |
errno = 0; |
|
2082 | 443 |
if ((zhp = make_dataset_handle(hdl, path)) == NULL) { |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
444 |
(void) zfs_standard_error(hdl, errno, errbuf); |
789 | 445 |
return (NULL); |
446 |
} |
|
447 |
||
448 |
if (!(types & zhp->zfs_type)) { |
|
2082 | 449 |
(void) zfs_error(hdl, EZFS_BADTYPE, errbuf); |
2142
f6e0487aa9a3
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents:
2082
diff
changeset
|
450 |
zfs_close(zhp); |
789 | 451 |
return (NULL); |
452 |
} |
|
453 |
||
454 |
return (zhp); |
|
455 |
} |
|
456 |
||
457 |
/* |
|
458 |
* Release a ZFS handle. Nothing to do but free the associated memory. |
|
459 |
*/ |
|
460 |
void |
|
461 |
zfs_close(zfs_handle_t *zhp) |
|
462 |
{ |
|
463 |
if (zhp->zfs_mntopts) |
|
464 |
free(zhp->zfs_mntopts); |
|
2676 | 465 |
nvlist_free(zhp->zfs_props); |
466 |
nvlist_free(zhp->zfs_user_props); |
|
789 | 467 |
free(zhp); |
468 |
} |
|
469 |
||
5713 | 470 |
int |
471 |
zfs_spa_version(zfs_handle_t *zhp, int *spa_version) |
|
472 |
{ |
|
473 |
char *pool_name; |
|
474 |
zpool_handle_t *zpool_handle; |
|
475 |
char *p; |
|
476 |
||
477 |
pool_name = zfs_alloc(zhp->zfs_hdl, MAXPATHLEN); |
|
478 |
if (zfs_prop_get(zhp, ZFS_PROP_NAME, pool_name, |
|
479 |
MAXPATHLEN, NULL, NULL, 0, B_FALSE) != 0) { |
|
480 |
free(pool_name); |
|
481 |
return (-1); |
|
482 |
} |
|
483 |
||
484 |
if (p = strchr(pool_name, '/')) |
|
485 |
*p = '\0'; |
|
486 |
zpool_handle = zpool_open(zhp->zfs_hdl, pool_name); |
|
487 |
free(pool_name); |
|
488 |
if (zpool_handle == NULL) |
|
489 |
return (-1); |
|
490 |
||
491 |
*spa_version = zpool_get_prop_int(zpool_handle, |
|
492 |
ZPOOL_PROP_VERSION, NULL); |
|
493 |
zpool_close(zpool_handle); |
|
494 |
return (0); |
|
495 |
} |
|
496 |
||
497 |
/* |
|
498 |
* The choice of reservation property depends on the SPA version. |
|
499 |
*/ |
|
500 |
static int |
|
501 |
zfs_which_resv_prop(zfs_handle_t *zhp, zfs_prop_t *resv_prop) |
|
502 |
{ |
|
503 |
int spa_version; |
|
504 |
||
505 |
if (zfs_spa_version(zhp, &spa_version) < 0) |
|
506 |
return (-1); |
|
507 |
||
508 |
if (spa_version >= SPA_VERSION_REFRESERVATION) |
|
509 |
*resv_prop = ZFS_PROP_REFRESERVATION; |
|
510 |
else |
|
511 |
*resv_prop = ZFS_PROP_RESERVATION; |
|
512 |
||
513 |
return (0); |
|
514 |
} |
|
515 |
||
3912 | 516 |
/* |
2676 | 517 |
* Given an nvlist of properties to set, validates that they are correct, and |
518 |
* parses any numeric properties (index, boolean, etc) if they are specified as |
|
519 |
* strings. |
|
789 | 520 |
*/ |
5094 | 521 |
static nvlist_t * |
522 |
zfs_validate_properties(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl, |
|
523 |
uint64_t zoned, zfs_handle_t *zhp, const char *errbuf) |
|
789 | 524 |
{ |
2676 | 525 |
nvpair_t *elem; |
526 |
uint64_t intval; |
|
527 |
char *strval; |
|
5094 | 528 |
zfs_prop_t prop; |
2676 | 529 |
nvlist_t *ret; |
5331 | 530 |
int chosen_normal = -1; |
531 |
int chosen_utf = -1; |
|
2676 | 532 |
|
533 |
if (type == ZFS_TYPE_SNAPSHOT) { |
|
534 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3413
f4cbe0204ab7
6471255 Some ZFS error messages contain spelling errors
mmusante
parents:
3377
diff
changeset
|
535 |
"snapshot properties cannot be modified")); |
2676 | 536 |
(void) zfs_error(hdl, EZFS_PROPTYPE, errbuf); |
5094 | 537 |
return (NULL); |
538 |
} |
|
539 |
||
540 |
if (nvlist_alloc(&ret, NV_UNIQUE_NAME, 0) != 0) { |
|
541 |
(void) no_memory(hdl); |
|
542 |
return (NULL); |
|
789 | 543 |
} |
544 |
||
2676 | 545 |
elem = NULL; |
546 |
while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { |
|
5094 | 547 |
const char *propname = nvpair_name(elem); |
2676 | 548 |
|
549 |
/* |
|
550 |
* Make sure this property is valid and applies to this type. |
|
551 |
*/ |
|
5094 | 552 |
if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) { |
553 |
if (!zfs_prop_user(propname)) { |
|
2676 | 554 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
5094 | 555 |
"invalid property '%s'"), propname); |
556 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
557 |
goto error; |
|
558 |
} |
|
559 |
||
560 |
/* |
|
561 |
* If this is a user property, make sure it's a |
|
562 |
* string, and that it's less than ZAP_MAXNAMELEN. |
|
563 |
*/ |
|
564 |
if (nvpair_type(elem) != DATA_TYPE_STRING) { |
|
565 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
566 |
"'%s' must be a string"), propname); |
|
567 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
568 |
goto error; |
|
569 |
} |
|
570 |
||
571 |
if (strlen(nvpair_name(elem)) >= ZAP_MAXNAMELEN) { |
|
572 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
573 |
"property name '%s' is too long"), |
|
2676 | 574 |
propname); |
575 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
576 |
goto error; |
|
577 |
} |
|
578 |
||
579 |
(void) nvpair_value_string(elem, &strval); |
|
580 |
if (nvlist_add_string(ret, propname, strval) != 0) { |
|
581 |
(void) no_memory(hdl); |
|
582 |
goto error; |
|
583 |
} |
|
584 |
continue; |
|
789 | 585 |
} |
2676 | 586 |
|
587 |
if (!zfs_prop_valid_for_type(prop, type)) { |
|
588 |
zfs_error_aux(hdl, |
|
589 |
dgettext(TEXT_DOMAIN, "'%s' does not " |
|
590 |
"apply to datasets of this type"), propname); |
|
591 |
(void) zfs_error(hdl, EZFS_PROPTYPE, errbuf); |
|
592 |
goto error; |
|
593 |
} |
|
594 |
||
595 |
if (zfs_prop_readonly(prop) && |
|
5331 | 596 |
(!zfs_prop_setonce(prop) || zhp != NULL)) { |
2676 | 597 |
zfs_error_aux(hdl, |
598 |
dgettext(TEXT_DOMAIN, "'%s' is readonly"), |
|
599 |
propname); |
|
600 |
(void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf); |
|
601 |
goto error; |
|
602 |
} |
|
603 |
||
5094 | 604 |
if (zprop_parse_value(hdl, elem, prop, type, ret, |
605 |
&strval, &intval, errbuf) != 0) |
|
2676 | 606 |
goto error; |
607 |
||
608 |
/* |
|
609 |
* Perform some additional checks for specific properties. |
|
610 |
*/ |
|
611 |
switch (prop) { |
|
4577 | 612 |
case ZFS_PROP_VERSION: |
613 |
{ |
|
614 |
int version; |
|
615 |
||
616 |
if (zhp == NULL) |
|
617 |
break; |
|
618 |
version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); |
|
619 |
if (intval < version) { |
|
620 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
621 |
"Can not downgrade; already at version %u"), |
|
622 |
version); |
|
623 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
624 |
goto error; |
|
625 |
} |
|
626 |
break; |
|
627 |
} |
|
628 |
||
2676 | 629 |
case ZFS_PROP_RECORDSIZE: |
630 |
case ZFS_PROP_VOLBLOCKSIZE: |
|
631 |
/* must be power of two within SPA_{MIN,MAX}BLOCKSIZE */ |
|
632 |
if (intval < SPA_MINBLOCKSIZE || |
|
633 |
intval > SPA_MAXBLOCKSIZE || !ISP2(intval)) { |
|
2082 | 634 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2676 | 635 |
"'%s' must be power of 2 from %u " |
636 |
"to %uk"), propname, |
|
637 |
(uint_t)SPA_MINBLOCKSIZE, |
|
638 |
(uint_t)SPA_MAXBLOCKSIZE >> 10); |
|
639 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
640 |
goto error; |
|
789 | 641 |
} |
642 |
break; |
|
643 |
||
3126 | 644 |
case ZFS_PROP_SHAREISCSI: |
645 |
if (strcmp(strval, "off") != 0 && |
|
646 |
strcmp(strval, "on") != 0 && |
|
647 |
strcmp(strval, "type=disk") != 0) { |
|
648 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
649 |
"'%s' must be 'on', 'off', or 'type=disk'"), |
|
650 |
propname); |
|
651 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
652 |
goto error; |
|
653 |
} |
|
654 |
||
655 |
break; |
|
656 |
||
2676 | 657 |
case ZFS_PROP_MOUNTPOINT: |
4778
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
658 |
{ |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
659 |
namecheck_err_t why; |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
660 |
|
2676 | 661 |
if (strcmp(strval, ZFS_MOUNTPOINT_NONE) == 0 || |
662 |
strcmp(strval, ZFS_MOUNTPOINT_LEGACY) == 0) |
|
663 |
break; |
|
664 |
||
4778
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
665 |
if (mountpoint_namecheck(strval, &why)) { |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
666 |
switch (why) { |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
667 |
case NAME_ERR_LEADING_SLASH: |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
668 |
zfs_error_aux(hdl, |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
669 |
dgettext(TEXT_DOMAIN, |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
670 |
"'%s' must be an absolute path, " |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
671 |
"'none', or 'legacy'"), propname); |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
672 |
break; |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
673 |
case NAME_ERR_TOOLONG: |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
674 |
zfs_error_aux(hdl, |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
675 |
dgettext(TEXT_DOMAIN, |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
676 |
"component of '%s' is too long"), |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
677 |
propname); |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
678 |
break; |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
679 |
} |
2676 | 680 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
681 |
goto error; |
|
789 | 682 |
} |
4778
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
683 |
} |
068cf1db91f1
6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents:
4603
diff
changeset
|
684 |
|
3126 | 685 |
/*FALLTHRU*/ |
686 |
||
5331 | 687 |
case ZFS_PROP_SHARESMB: |
3126 | 688 |
case ZFS_PROP_SHARENFS: |
689 |
/* |
|
5331 | 690 |
* For the mountpoint and sharenfs or sharesmb |
691 |
* properties, check if it can be set in a |
|
692 |
* global/non-global zone based on |
|
3126 | 693 |
* the zoned property value: |
694 |
* |
|
695 |
* global zone non-global zone |
|
696 |
* -------------------------------------------------- |
|
697 |
* zoned=on mountpoint (no) mountpoint (yes) |
|
698 |
* sharenfs (no) sharenfs (no) |
|
5331 | 699 |
* sharesmb (no) sharesmb (no) |
3126 | 700 |
* |
701 |
* zoned=off mountpoint (yes) N/A |
|
702 |
* sharenfs (yes) |
|
5331 | 703 |
* sharesmb (yes) |
3126 | 704 |
*/ |
2676 | 705 |
if (zoned) { |
706 |
if (getzoneid() == GLOBAL_ZONEID) { |
|
707 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
708 |
"'%s' cannot be set on " |
|
709 |
"dataset in a non-global zone"), |
|
710 |
propname); |
|
711 |
(void) zfs_error(hdl, EZFS_ZONED, |
|
712 |
errbuf); |
|
713 |
goto error; |
|
5331 | 714 |
} else if (prop == ZFS_PROP_SHARENFS || |
715 |
prop == ZFS_PROP_SHARESMB) { |
|
2676 | 716 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
717 |
"'%s' cannot be set in " |
|
718 |
"a non-global zone"), propname); |
|
719 |
(void) zfs_error(hdl, EZFS_ZONED, |
|
720 |
errbuf); |
|
721 |
goto error; |
|
722 |
} |
|
723 |
} else if (getzoneid() != GLOBAL_ZONEID) { |
|
724 |
/* |
|
725 |
* If zoned property is 'off', this must be in |
|
726 |
* a globle zone. If not, something is wrong. |
|
727 |
*/ |
|
728 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
729 |
"'%s' cannot be set while dataset " |
|
730 |
"'zoned' property is set"), propname); |
|
731 |
(void) zfs_error(hdl, EZFS_ZONED, errbuf); |
|
732 |
goto error; |
|
733 |
} |
|
3126 | 734 |
|
4180
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
735 |
/* |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
736 |
* At this point, it is legitimate to set the |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
737 |
* property. Now we want to make sure that the |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
738 |
* property value is valid if it is sharenfs. |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
739 |
*/ |
5331 | 740 |
if ((prop == ZFS_PROP_SHARENFS || |
741 |
prop == ZFS_PROP_SHARESMB) && |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
742 |
strcmp(strval, "on") != 0 && |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
743 |
strcmp(strval, "off") != 0) { |
5331 | 744 |
zfs_share_proto_t proto; |
745 |
||
746 |
if (prop == ZFS_PROP_SHARESMB) |
|
747 |
proto = PROTO_SMB; |
|
748 |
else |
|
749 |
proto = PROTO_NFS; |
|
4180
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
750 |
|
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
751 |
/* |
5331 | 752 |
* Must be an valid sharing protocol |
753 |
* option string so init the libshare |
|
754 |
* in order to enable the parser and |
|
755 |
* then parse the options. We use the |
|
756 |
* control API since we don't care about |
|
757 |
* the current configuration and don't |
|
4180
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
758 |
* want the overhead of loading it |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
759 |
* until we actually do something. |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
760 |
*/ |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
761 |
|
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
762 |
if (zfs_init_libshare(hdl, |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
763 |
SA_INIT_CONTROL_API) != SA_OK) { |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
764 |
/* |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
765 |
* An error occurred so we can't do |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
766 |
* anything |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
767 |
*/ |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
768 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
769 |
"'%s' cannot be set: problem " |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
770 |
"in share initialization"), |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
771 |
propname); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
772 |
(void) zfs_error(hdl, EZFS_BADPROP, |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
773 |
errbuf); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
774 |
goto error; |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
775 |
} |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
776 |
|
5331 | 777 |
if (zfs_parse_options(strval, proto) != SA_OK) { |
4217
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
778 |
/* |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
779 |
* There was an error in parsing so |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
780 |
* deal with it by issuing an error |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
781 |
* message and leaving after |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
782 |
* uninitializing the the libshare |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
783 |
* interface. |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
784 |
*/ |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
785 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
786 |
"'%s' cannot be set to invalid " |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
787 |
"options"), propname); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
788 |
(void) zfs_error(hdl, EZFS_BADPROP, |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
789 |
errbuf); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
790 |
zfs_uninit_libshare(hdl); |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
791 |
goto error; |
3411a82f178f
6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents:
4183
diff
changeset
|
792 |
} |
4180
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
793 |
zfs_uninit_libshare(hdl); |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
794 |
} |
30b15f0bd3c9
6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents:
4007
diff
changeset
|
795 |
|
3126 | 796 |
break; |
5331 | 797 |
case ZFS_PROP_UTF8ONLY: |
798 |
chosen_utf = (int)intval; |
|
799 |
break; |
|
800 |
case ZFS_PROP_NORMALIZE: |
|
801 |
chosen_normal = (int)intval; |
|
802 |
break; |
|
2676 | 803 |
} |
804 |
||
805 |
/* |
|
806 |
* For changes to existing volumes, we have some additional |
|
807 |
* checks to enforce. |
|
808 |
*/ |
|
809 |
if (type == ZFS_TYPE_VOLUME && zhp != NULL) { |
|
810 |
uint64_t volsize = zfs_prop_get_int(zhp, |
|
811 |
ZFS_PROP_VOLSIZE); |
|
812 |
uint64_t blocksize = zfs_prop_get_int(zhp, |
|
813 |
ZFS_PROP_VOLBLOCKSIZE); |
|
814 |
char buf[64]; |
|
815 |
||
816 |
switch (prop) { |
|
817 |
case ZFS_PROP_RESERVATION: |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
818 |
case ZFS_PROP_REFRESERVATION: |
2676 | 819 |
if (intval > volsize) { |
820 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
821 |
"'%s' is greater than current " |
|
822 |
"volume size"), propname); |
|
823 |
(void) zfs_error(hdl, EZFS_BADPROP, |
|
824 |
errbuf); |
|
825 |
goto error; |
|
826 |
} |
|
827 |
break; |
|
828 |
||
829 |
case ZFS_PROP_VOLSIZE: |
|
830 |
if (intval % blocksize != 0) { |
|
831 |
zfs_nicenum(blocksize, buf, |
|
832 |
sizeof (buf)); |
|
833 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
834 |
"'%s' must be a multiple of " |
|
835 |
"volume block size (%s)"), |
|
836 |
propname, buf); |
|
837 |
(void) zfs_error(hdl, EZFS_BADPROP, |
|
838 |
errbuf); |
|
839 |
goto error; |
|
840 |
} |
|
841 |
||
842 |
if (intval == 0) { |
|
843 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
844 |
"'%s' cannot be zero"), |
|
845 |
propname); |
|
846 |
(void) zfs_error(hdl, EZFS_BADPROP, |
|
847 |
errbuf); |
|
848 |
goto error; |
|
789 | 849 |
} |
3126 | 850 |
break; |
789 | 851 |
} |
852 |
} |
|
853 |
} |
|
854 |
||
2676 | 855 |
/* |
5331 | 856 |
* If normalization was chosen, but no UTF8 choice was made, |
857 |
* enforce rejection of non-UTF8 names. |
|
858 |
* |
|
859 |
* If normalization was chosen, but rejecting non-UTF8 names |
|
860 |
* was explicitly not chosen, it is an error. |
|
861 |
*/ |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
862 |
if (chosen_normal > 0 && chosen_utf < 0) { |
5331 | 863 |
if (nvlist_add_uint64(ret, |
864 |
zfs_prop_to_name(ZFS_PROP_UTF8ONLY), 1) != 0) { |
|
865 |
(void) no_memory(hdl); |
|
866 |
goto error; |
|
867 |
} |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
868 |
} else if (chosen_normal > 0 && chosen_utf == 0) { |
5331 | 869 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
870 |
"'%s' must be set 'on' if normalization chosen"), |
|
871 |
zfs_prop_to_name(ZFS_PROP_UTF8ONLY)); |
|
872 |
(void) zfs_error(hdl, EZFS_BADPROP, errbuf); |
|
873 |
goto error; |
|
874 |
} |
|
875 |
||
876 |
/* |
|
2676 | 877 |
* If this is an existing volume, and someone is setting the volsize, |
878 |
* make sure that it matches the reservation, or add it if necessary. |
|
879 |
*/ |
|
880 |
if (zhp != NULL && type == ZFS_TYPE_VOLUME && |
|
881 |
nvlist_lookup_uint64(ret, zfs_prop_to_name(ZFS_PROP_VOLSIZE), |
|
882 |
&intval) == 0) { |
|
883 |
uint64_t old_volsize = zfs_prop_get_int(zhp, |
|
884 |
ZFS_PROP_VOLSIZE); |
|
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5473
diff
changeset
|
885 |
uint64_t old_reservation; |
2676 | 886 |
uint64_t new_reservation; |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5473
diff
changeset
|
887 |
zfs_prop_t resv_prop; |
5713 | 888 |
|
889 |
if (zfs_which_resv_prop(zhp, &resv_prop) < 0) |
|
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5473
diff
changeset
|
890 |
goto error; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5473
diff
changeset
|
891 |
old_reservation = zfs_prop_get_int(zhp, resv_prop); |
2676 | 892 |
|
893 |
if (old_volsize == old_reservation && |
|
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5473
diff
changeset
|
894 |
nvlist_lookup_uint64(ret, zfs_prop_to_name(resv_prop), |
2676 | 895 |
&new_reservation) != 0) { |
896 |
if (nvlist_add_uint64(ret, |
|
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5473
diff
changeset
|
897 |
zfs_prop_to_name(resv_prop), intval) != 0) { |
2676 | 898 |
(void) no_memory(hdl); |
899 |
goto error; |
|
900 |
} |
|
901 |
} |
|
902 |
} |
|
903 |
return (ret); |
|
904 |
||
905 |
error: |
|
906 |
nvlist_free(ret); |
|
907 |
return (NULL); |
|
789 | 908 |
} |
909 |
||
4543 | 910 |
static int |
911 |
zfs_get_perm_who(const char *who, zfs_deleg_who_type_t *who_type, |
|
912 |
uint64_t *ret_who) |
|
913 |
{ |
|
914 |
struct passwd *pwd; |
|
915 |
struct group *grp; |
|
916 |
uid_t id; |
|
917 |
||
918 |
if (*who_type == ZFS_DELEG_EVERYONE || *who_type == ZFS_DELEG_CREATE || |
|
919 |
*who_type == ZFS_DELEG_NAMED_SET) { |
|
920 |
*ret_who = -1; |
|
921 |
return (0); |
|
922 |
} |
|
923 |
if (who == NULL && !(*who_type == ZFS_DELEG_EVERYONE)) |
|
924 |
return (EZFS_BADWHO); |
|
925 |
||
926 |
if (*who_type == ZFS_DELEG_WHO_UNKNOWN && |
|
927 |
strcmp(who, "everyone") == 0) { |
|
928 |
*ret_who = -1; |
|
929 |
*who_type = ZFS_DELEG_EVERYONE; |
|
930 |
return (0); |
|
931 |
} |
|
932 |
||
933 |
pwd = getpwnam(who); |
|
934 |
grp = getgrnam(who); |
|
935 |
||
936 |
if ((*who_type == ZFS_DELEG_USER) && pwd) { |
|
937 |
*ret_who = pwd->pw_uid; |
|
938 |
} else if ((*who_type == ZFS_DELEG_GROUP) && grp) { |
|
939 |
*ret_who = grp->gr_gid; |
|
940 |
} else if (pwd) { |
|
941 |
*ret_who = pwd->pw_uid; |
|
942 |
*who_type = ZFS_DELEG_USER; |
|
943 |
} else if (grp) { |
|
944 |
*ret_who = grp->gr_gid; |
|
945 |
*who_type = ZFS_DELEG_GROUP; |
|
946 |
} else { |
|
947 |
char *end; |
|
948 |
||
949 |
id = strtol(who, &end, 10); |
|
950 |
if (errno != 0 || *end != '\0') { |
|
951 |
return (EZFS_BADWHO); |
|
952 |
} else { |
|
953 |
*ret_who = id; |
|
954 |
if (*who_type == ZFS_DELEG_WHO_UNKNOWN) |
|
955 |
*who_type = ZFS_DELEG_USER; |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
return (0); |
|
960 |
} |
|
961 |
||
962 |
static void |
|
963 |
zfs_perms_add_to_nvlist(nvlist_t *who_nvp, char *name, nvlist_t *perms_nvp) |
|
964 |
{ |
|
965 |
if (perms_nvp != NULL) { |
|
966 |
verify(nvlist_add_nvlist(who_nvp, |
|
967 |
name, perms_nvp) == 0); |
|
968 |
} else { |
|
969 |
verify(nvlist_add_boolean(who_nvp, name) == 0); |
|
970 |
} |
|
971 |
} |
|
972 |
||
973 |
static void |
|
974 |
helper(zfs_deleg_who_type_t who_type, uint64_t whoid, char *whostr, |
|
975 |
zfs_deleg_inherit_t inherit, nvlist_t *who_nvp, nvlist_t *perms_nvp, |
|
976 |
nvlist_t *sets_nvp) |
|
977 |
{ |
|
978 |
boolean_t do_perms, do_sets; |
|
979 |
char name[ZFS_MAX_DELEG_NAME]; |
|
980 |
||
981 |
do_perms = (nvlist_next_nvpair(perms_nvp, NULL) != NULL); |
|
982 |
do_sets = (nvlist_next_nvpair(sets_nvp, NULL) != NULL); |
|
983 |
||
984 |
if (!do_perms && !do_sets) |
|
985 |
do_perms = do_sets = B_TRUE; |
|
986 |
||
987 |
if (do_perms) { |
|
988 |
zfs_deleg_whokey(name, who_type, inherit, |
|
989 |
(who_type == ZFS_DELEG_NAMED_SET) ? |
|
990 |
whostr : (void *)&whoid); |
|
991 |
zfs_perms_add_to_nvlist(who_nvp, name, perms_nvp); |
|
992 |
} |
|
993 |
if (do_sets) { |
|
994 |
zfs_deleg_whokey(name, toupper(who_type), inherit, |
|
995 |
(who_type == ZFS_DELEG_NAMED_SET) ? |
|
996 |
whostr : (void *)&whoid); |
|
997 |
zfs_perms_add_to_nvlist(who_nvp, name, sets_nvp); |
|
998 |
} |
|
999 |
} |
|
1000 |
||
1001 |
static void |
|
1002 |
zfs_perms_add_who_nvlist(nvlist_t *who_nvp, uint64_t whoid, void *whostr, |
|
1003 |
nvlist_t *perms_nvp, nvlist_t *sets_nvp, |
|
1004 |
zfs_deleg_who_type_t who_type, zfs_deleg_inherit_t inherit) |
|
1005 |
{ |
|
1006 |
if (who_type == ZFS_DELEG_NAMED_SET || who_type == ZFS_DELEG_CREATE) { |
|
1007 |
helper(who_type, whoid, whostr, 0, |
|
1008 |
who_nvp, perms_nvp, sets_nvp); |
|
1009 |
} else { |
|
1010 |
if (inherit & ZFS_DELEG_PERM_LOCAL) { |
|
1011 |
helper(who_type, whoid, whostr, ZFS_DELEG_LOCAL, |
|
1012 |
who_nvp, perms_nvp, sets_nvp); |
|
1013 |
} |
|
1014 |
if (inherit & ZFS_DELEG_PERM_DESCENDENT) { |
|
1015 |
helper(who_type, whoid, whostr, ZFS_DELEG_DESCENDENT, |
|
1016 |
who_nvp, perms_nvp, sets_nvp); |
|
1017 |
} |
|
1018 |
} |
|
1019 |
} |
|
1020 |
||
1021 |
/* |
|
1022 |
* Construct nvlist to pass down to kernel for setting/removing permissions. |
|
1023 |
* |
|
1024 |
* The nvlist is constructed as a series of nvpairs with an optional embedded |
|
1025 |
* nvlist of permissions to remove or set. The topmost nvpairs are the actual |
|
1026 |
* base attribute named stored in the dsl. |
|
1027 |
* Arguments: |
|
1028 |
* |
|
1029 |
* whostr: is a comma separated list of users, groups, or a single set name. |
|
1030 |
* whostr may be null for everyone or create perms. |
|
1031 |
* who_type: is the type of entry in whostr. Typically this will be |
|
1032 |
* ZFS_DELEG_WHO_UNKNOWN. |
|
5331 | 1033 |
* perms: common separated list of permissions. May be null if user |
4543 | 1034 |
* is requested to remove permissions by who. |
1035 |
* inherit: Specifies the inheritance of the permissions. Will be either |
|
1036 |
* ZFS_DELEG_PERM_LOCAL and/or ZFS_DELEG_PERM_DESCENDENT. |
|
1037 |
* nvp The constructed nvlist to pass to zfs_perm_set(). |
|
1038 |
* The output nvp will look something like this. |
|
1039 |
* ul$1234 -> {create ; destroy } |
|
1040 |
* Ul$1234 -> { @myset } |
|
1041 |
* s-$@myset - { snapshot; checksum; compression } |
|
1042 |
*/ |
|
1043 |
int |
|
1044 |
zfs_build_perms(zfs_handle_t *zhp, char *whostr, char *perms, |
|
1045 |
zfs_deleg_who_type_t who_type, zfs_deleg_inherit_t inherit, nvlist_t **nvp) |
|
1046 |
{ |
|
1047 |
nvlist_t *who_nvp; |
|
1048 |
nvlist_t *perms_nvp = NULL; |
|
1049 |
nvlist_t *sets_nvp = NULL; |
|
1050 |
char errbuf[1024]; |
|
4787 | 1051 |
char *who_tok, *perm; |
4543 | 1052 |
int error; |
1053 |
||
1054 |
*nvp = NULL; |
|
1055 |
||
1056 |
if (perms) { |
|
1057 |
if ((error = nvlist_alloc(&perms_nvp, |
|
1058 |
NV_UNIQUE_NAME, 0)) != 0) { |
|
1059 |
return (1); |
|
1060 |
} |
|
1061 |
if ((error = nvlist_alloc(&sets_nvp, |
|
1062 |
NV_UNIQUE_NAME, 0)) != 0) { |
|
1063 |
nvlist_free(perms_nvp); |
|
1064 |
return (1); |
|
1065 |
} |
|
1066 |
} |
|
1067 |
||
1068 |
if ((error = nvlist_alloc(&who_nvp, NV_UNIQUE_NAME, 0)) != 0) { |
|
1069 |
if (perms_nvp) |
|
1070 |
nvlist_free(perms_nvp); |
|
1071 |
if (sets_nvp) |
|
1072 |
nvlist_free(sets_nvp); |
|
1073 |
return (1); |
|
1074 |
} |
|
1075 |
||
1076 |
if (who_type == ZFS_DELEG_NAMED_SET) { |
|
1077 |
namecheck_err_t why; |
|
1078 |
char what; |
|
1079 |
||
1080 |
if ((error = permset_namecheck(whostr, &why, &what)) != 0) { |
|
4787 | 1081 |
nvlist_free(who_nvp); |
1082 |
if (perms_nvp) |
|
1083 |
nvlist_free(perms_nvp); |
|
1084 |
if (sets_nvp) |
|
1085 |
nvlist_free(sets_nvp); |
|
1086 |
||
4543 | 1087 |
switch (why) { |
1088 |
case NAME_ERR_NO_AT: |
|
1089 |
zfs_error_aux(zhp->zfs_hdl, |
|
1090 |
dgettext(TEXT_DOMAIN, |
|
1091 |
"set definition must begin with an '@' " |
|
1092 |
"character")); |
|
1093 |
} |
|
1094 |
return (zfs_error(zhp->zfs_hdl, |
|
1095 |
EZFS_BADPERMSET, whostr)); |
|
1096 |
} |
|
1097 |
} |
|
1098 |
||
1099 |
/* |
|
1100 |
* Build up nvlist(s) of permissions. Two nvlists are maintained. |
|
1101 |
* The first nvlist perms_nvp will have normal permissions and the |
|
1102 |
* other sets_nvp will have only permssion set names in it. |
|
1103 |
*/ |
|
4787 | 1104 |
for (perm = strtok(perms, ","); perm; perm = strtok(NULL, ",")) { |
1105 |
const char *perm_canonical = zfs_deleg_canonicalize_perm(perm); |
|
1106 |
||
1107 |
if (perm_canonical) { |
|
1108 |
verify(nvlist_add_boolean(perms_nvp, |
|
1109 |
perm_canonical) == 0); |
|
1110 |
} else if (perm[0] == '@') { |
|
1111 |
verify(nvlist_add_boolean(sets_nvp, perm) == 0); |
|
1112 |
} else { |
|
1113 |
nvlist_free(who_nvp); |
|
1114 |
nvlist_free(perms_nvp); |
|
1115 |
nvlist_free(sets_nvp); |
|
1116 |
return (zfs_error(zhp->zfs_hdl, EZFS_BADPERM, perm)); |
|
4543 | 1117 |
} |
1118 |
} |
|
1119 |
||
1120 |
if (whostr && who_type != ZFS_DELEG_CREATE) { |
|
1121 |
who_tok = strtok(whostr, ","); |
|
1122 |
if (who_tok == NULL) { |
|
1123 |
nvlist_free(who_nvp); |
|
4787 | 1124 |
if (perms_nvp) |
1125 |
nvlist_free(perms_nvp); |
|
4543 | 1126 |
if (sets_nvp) |
1127 |
nvlist_free(sets_nvp); |
|
1128 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
1129 |
dgettext(TEXT_DOMAIN, "Who string is NULL"), |
|
1130 |
whostr); |
|
1131 |
return (zfs_error(zhp->zfs_hdl, EZFS_BADWHO, errbuf)); |
|
1132 |
} |
|
1133 |
} |
|
1134 |
||
1135 |
/* |
|
1136 |
* Now create the nvlist(s) |
|
1137 |
*/ |
|
1138 |
do { |
|
1139 |
uint64_t who_id; |
|
1140 |
||
1141 |
error = zfs_get_perm_who(who_tok, &who_type, |
|
1142 |
&who_id); |
|
1143 |
if (error) { |
|
1144 |
nvlist_free(who_nvp); |
|
4787 | 1145 |
if (perms_nvp) |
1146 |
nvlist_free(perms_nvp); |
|
4543 | 1147 |
if (sets_nvp) |
1148 |
nvlist_free(sets_nvp); |
|
1149 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
1150 |
dgettext(TEXT_DOMAIN, |
|
1151 |
"Unable to determine uid/gid for " |
|
1152 |
"%s "), who_tok); |
|
1153 |
return (zfs_error(zhp->zfs_hdl, EZFS_BADWHO, errbuf)); |
|
1154 |
} |
|
1155 |
||
1156 |
/* |
|
1157 |
* add entries for both local and descendent when required |
|
1158 |
*/ |
|
1159 |
zfs_perms_add_who_nvlist(who_nvp, who_id, who_tok, |
|
1160 |
perms_nvp, sets_nvp, who_type, inherit); |
|
1161 |
||
1162 |
} while (who_tok = strtok(NULL, ",")); |
|
1163 |
*nvp = who_nvp; |
|
1164 |
return (0); |
|
1165 |
} |
|
1166 |
||
1167 |
static int |
|
1168 |
zfs_perm_set_common(zfs_handle_t *zhp, nvlist_t *nvp, boolean_t unset) |
|
1169 |
{ |
|
1170 |
zfs_cmd_t zc = { 0 }; |
|
1171 |
int error; |
|
1172 |
char errbuf[1024]; |
|
1173 |
||
1174 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
1175 |
dgettext(TEXT_DOMAIN, "Cannot update 'allows' for '%s'"), |
|
1176 |
zhp->zfs_name); |
|
1177 |
||
5094 | 1178 |
if (zcmd_write_src_nvlist(zhp->zfs_hdl, &zc, nvp)) |
4543 | 1179 |
return (-1); |
1180 |
||
1181 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
1182 |
zc.zc_perm_action = unset; |
|
1183 |
||
1184 |
error = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SET_FSACL, &zc); |
|
1185 |
if (error && errno == ENOTSUP) { |
|
1186 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
1187 |
gettext("Pool must be upgraded to use 'allow/unallow'")); |
|
1188 |
zcmd_free_nvlists(&zc); |
|
1189 |
return (zfs_error(zhp->zfs_hdl, EZFS_BADVERSION, errbuf)); |
|
1190 |
} else if (error) { |
|
1191 |
return (zfs_standard_error(zhp->zfs_hdl, errno, errbuf)); |
|
1192 |
} |
|
1193 |
zcmd_free_nvlists(&zc); |
|
1194 |
||
1195 |
return (error); |
|
1196 |
} |
|
1197 |
||
1198 |
int |
|
1199 |
zfs_perm_set(zfs_handle_t *zhp, nvlist_t *nvp) |
|
1200 |
{ |
|
1201 |
return (zfs_perm_set_common(zhp, nvp, B_FALSE)); |
|
1202 |
} |
|
1203 |
||
1204 |
int |
|
1205 |
zfs_perm_remove(zfs_handle_t *zhp, nvlist_t *perms) |
|
1206 |
{ |
|
1207 |
return (zfs_perm_set_common(zhp, perms, B_TRUE)); |
|
1208 |
} |
|
1209 |
||
1210 |
static int |
|
1211 |
perm_compare(const void *arg1, const void *arg2) |
|
1212 |
{ |
|
1213 |
const zfs_perm_node_t *node1 = arg1; |
|
1214 |
const zfs_perm_node_t *node2 = arg2; |
|
1215 |
int ret; |
|
1216 |
||
1217 |
ret = strcmp(node1->z_pname, node2->z_pname); |
|
1218 |
||
1219 |
if (ret > 0) |
|
1220 |
return (1); |
|
1221 |
if (ret < 0) |
|
1222 |
return (-1); |
|
1223 |
else |
|
1224 |
return (0); |
|
1225 |
} |
|
1226 |
||
1227 |
static void |
|
1228 |
zfs_destroy_perm_tree(avl_tree_t *tree) |
|
1229 |
{ |
|
1230 |
zfs_perm_node_t *permnode; |
|
5367 | 1231 |
void *cookie = NULL; |
1232 |
||
1233 |
while ((permnode = avl_destroy_nodes(tree, &cookie)) != NULL) |
|
4543 | 1234 |
free(permnode); |
5367 | 1235 |
avl_destroy(tree); |
4543 | 1236 |
} |
1237 |
||
1238 |
static void |
|
1239 |
zfs_destroy_tree(avl_tree_t *tree) |
|
1240 |
{ |
|
1241 |
zfs_allow_node_t *allownode; |
|
5367 | 1242 |
void *cookie = NULL; |
1243 |
||
4543 | 1244 |
while ((allownode = avl_destroy_nodes(tree, &cookie)) != NULL) { |
1245 |
zfs_destroy_perm_tree(&allownode->z_localdescend); |
|
1246 |
zfs_destroy_perm_tree(&allownode->z_local); |
|
1247 |
zfs_destroy_perm_tree(&allownode->z_descend); |
|
1248 |
free(allownode); |
|
1249 |
} |
|
5367 | 1250 |
avl_destroy(tree); |
4543 | 1251 |
} |
1252 |
||
1253 |
void |
|
1254 |
zfs_free_allows(zfs_allow_t *allow) |
|
1255 |
{ |
|
1256 |
zfs_allow_t *allownext; |
|
1257 |
zfs_allow_t *freeallow; |
|
1258 |
||
1259 |
allownext = allow; |
|
1260 |
while (allownext) { |
|
1261 |
zfs_destroy_tree(&allownext->z_sets); |
|
1262 |
zfs_destroy_tree(&allownext->z_crperms); |
|
1263 |
zfs_destroy_tree(&allownext->z_user); |
|
1264 |
zfs_destroy_tree(&allownext->z_group); |
|
1265 |
zfs_destroy_tree(&allownext->z_everyone); |
|
1266 |
freeallow = allownext; |
|
1267 |
allownext = allownext->z_next; |
|
1268 |
free(freeallow); |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
static zfs_allow_t * |
|
1273 |
zfs_alloc_perm_tree(zfs_handle_t *zhp, zfs_allow_t *prev, char *setpoint) |
|
1274 |
{ |
|
1275 |
zfs_allow_t *ptree; |
|
1276 |
||
1277 |
if ((ptree = zfs_alloc(zhp->zfs_hdl, |
|
1278 |
sizeof (zfs_allow_t))) == NULL) { |
|
1279 |
return (NULL); |
|
1280 |
} |
|
1281 |
||
1282 |
(void) strlcpy(ptree->z_setpoint, setpoint, sizeof (ptree->z_setpoint)); |
|
1283 |
avl_create(&ptree->z_sets, |
|
1284 |
perm_compare, sizeof (zfs_allow_node_t), |
|
1285 |
offsetof(zfs_allow_node_t, z_node)); |
|
1286 |
avl_create(&ptree->z_crperms, |
|
1287 |
perm_compare, sizeof (zfs_allow_node_t), |
|
1288 |
offsetof(zfs_allow_node_t, z_node)); |
|
1289 |
avl_create(&ptree->z_user, |
|
1290 |
perm_compare, sizeof (zfs_allow_node_t), |
|
1291 |
offsetof(zfs_allow_node_t, z_node)); |
|
1292 |
avl_create(&ptree->z_group, |
|
1293 |
perm_compare, sizeof (zfs_allow_node_t), |
|
1294 |
offsetof(zfs_allow_node_t, z_node)); |
|
1295 |
avl_create(&ptree->z_everyone, |
|
1296 |
perm_compare, sizeof (zfs_allow_node_t), |
|
1297 |
offsetof(zfs_allow_node_t, z_node)); |
|
1298 |
||
1299 |
if (prev) |
|
1300 |
prev->z_next = ptree; |
|
1301 |
ptree->z_next = NULL; |
|
1302 |
return (ptree); |
|
1303 |
} |
|
1304 |
||
1305 |
/* |
|
1306 |
* Add permissions to the appropriate AVL permission tree. |
|
1307 |
* The appropriate tree may not be the requested tree. |
|
1308 |
* For example if ld indicates a local permission, but |
|
1309 |
* same permission also exists as a descendent permission |
|
1310 |
* then the permission will be removed from the descendent |
|
1311 |
* tree and add the the local+descendent tree. |
|
1312 |
*/ |
|
1313 |
static int |
|
1314 |
zfs_coalesce_perm(zfs_handle_t *zhp, zfs_allow_node_t *allownode, |
|
1315 |
char *perm, char ld) |
|
1316 |
{ |
|
1317 |
zfs_perm_node_t pnode, *permnode, *permnode2; |
|
1318 |
zfs_perm_node_t *newnode; |
|
1319 |
avl_index_t where, where2; |
|
1320 |
avl_tree_t *tree, *altree; |
|
1321 |
||
1322 |
(void) strlcpy(pnode.z_pname, perm, sizeof (pnode.z_pname)); |
|
1323 |
||
1324 |
if (ld == ZFS_DELEG_NA) { |
|
1325 |
tree = &allownode->z_localdescend; |
|
1326 |
altree = &allownode->z_descend; |
|
1327 |
} else if (ld == ZFS_DELEG_LOCAL) { |
|
1328 |
tree = &allownode->z_local; |
|
1329 |
altree = &allownode->z_descend; |
|
1330 |
} else { |
|
1331 |
tree = &allownode->z_descend; |
|
1332 |
altree = &allownode->z_local; |
|
1333 |
} |
|
1334 |
permnode = avl_find(tree, &pnode, &where); |
|
1335 |
permnode2 = avl_find(altree, &pnode, &where2); |
|
1336 |
||
1337 |
if (permnode2) { |
|
1338 |
avl_remove(altree, permnode2); |
|
1339 |
free(permnode2); |
|
1340 |
if (permnode == NULL) { |
|
1341 |
tree = &allownode->z_localdescend; |
|
1342 |
} |
|
1343 |
} |
|
1344 |
||
1345 |
/* |
|
1346 |
* Now insert new permission in either requested location |
|
1347 |
* local/descendent or into ld when perm will exist in both. |
|
1348 |
*/ |
|
1349 |
if (permnode == NULL) { |
|
1350 |
if ((newnode = zfs_alloc(zhp->zfs_hdl, |
|
1351 |
sizeof (zfs_perm_node_t))) == NULL) { |
|
1352 |
return (-1); |
|
1353 |
} |
|
1354 |
*newnode = pnode; |
|
1355 |
avl_add(tree, newnode); |
|
1356 |
} |
|
1357 |
return (0); |
|
1358 |
} |
|
4577 | 1359 |
|
4543 | 1360 |
/* |
1361 |
* Uggh, this is going to be a bit complicated. |
|
1362 |
* we have an nvlist coming out of the kernel that |
|
1363 |
* will indicate where the permission is set and then |
|
1364 |
* it will contain allow of the various "who's", and what |
|
1365 |
* their permissions are. To further complicate this |
|
1366 |
* we will then have to coalesce the local,descendent |
|
1367 |
* and local+descendent permissions where appropriate. |
|
1368 |
* The kernel only knows about a permission as being local |
|
1369 |
* or descendent, but not both. |
|
1370 |
* |
|
1371 |
* In order to make this easier for zfs_main to deal with |
|
1372 |
* a series of AVL trees will be used to maintain |
|
1373 |
* all of this, primarily for sorting purposes as well |
|
1374 |
* as the ability to quickly locate a specific entry. |
|
1375 |
* |
|
1376 |
* What we end up with are tree's for sets, create perms, |
|
1377 |
* user, groups and everyone. With each of those trees |
|
1378 |
* we have subtrees for local, descendent and local+descendent |
|
1379 |
* permissions. |
|
1380 |
*/ |
|
1381 |
int |
|
1382 |
zfs_perm_get(zfs_handle_t *zhp, zfs_allow_t **zfs_perms) |
|
1383 |
{ |
|
1384 |
zfs_cmd_t zc = { 0 }; |
|
1385 |
int error; |
|
1386 |
nvlist_t *nvlist; |
|
1387 |
nvlist_t *permnv, *sourcenv; |
|
1388 |
nvpair_t *who_pair, *source_pair; |
|
1389 |
nvpair_t *perm_pair; |
|
1390 |
char errbuf[1024]; |
|
1391 |
zfs_allow_t *zallowp, *newallowp; |
|
1392 |
char ld; |
|
1393 |
char *nvpname; |
|
1394 |
uid_t uid; |
|
1395 |
gid_t gid; |
|
1396 |
avl_tree_t *tree; |
|
1397 |
avl_index_t where; |
|
1398 |
||
1399 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
1400 |
||
1401 |
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) |
|
1402 |
return (-1); |
|
1403 |
||
1404 |
while (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_GET_FSACL, &zc) != 0) { |
|
1405 |
if (errno == ENOMEM) { |
|
1406 |
if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, &zc) != 0) { |
|
1407 |
zcmd_free_nvlists(&zc); |
|
1408 |
return (-1); |
|
1409 |
} |
|
1410 |
} else if (errno == ENOTSUP) { |
|
1411 |
zcmd_free_nvlists(&zc); |
|
1412 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
1413 |
gettext("Pool must be upgraded to use 'allow'")); |
|
1414 |
return (zfs_error(zhp->zfs_hdl, |
|
1415 |
EZFS_BADVERSION, errbuf)); |
|
1416 |
} else { |
|
1417 |
zcmd_free_nvlists(&zc); |
|
1418 |
return (-1); |
|
1419 |
} |
|
1420 |
} |
|
1421 |
||
1422 |
if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &nvlist) != 0) { |
|
1423 |
zcmd_free_nvlists(&zc); |
|
1424 |
return (-1); |
|
1425 |
} |
|
1426 |
||
1427 |
zcmd_free_nvlists(&zc); |
|
1428 |
||
1429 |
source_pair = nvlist_next_nvpair(nvlist, NULL); |
|
1430 |
||
1431 |
if (source_pair == NULL) { |
|
1432 |
*zfs_perms = NULL; |
|
1433 |
return (0); |
|
1434 |
} |
|
1435 |
||
1436 |
*zfs_perms = zfs_alloc_perm_tree(zhp, NULL, nvpair_name(source_pair)); |
|
1437 |
if (*zfs_perms == NULL) { |
|
1438 |
return (0); |
|
1439 |
} |
|
1440 |
||
1441 |
zallowp = *zfs_perms; |
|
1442 |
||
1443 |
for (;;) { |
|
1444 |
struct passwd *pwd; |
|
1445 |
struct group *grp; |
|
1446 |
zfs_allow_node_t *allownode; |
|
1447 |
zfs_allow_node_t findallownode; |
|
1448 |
zfs_allow_node_t *newallownode; |
|
1449 |
||
1450 |
(void) strlcpy(zallowp->z_setpoint, |
|
1451 |
nvpair_name(source_pair), |
|
1452 |
sizeof (zallowp->z_setpoint)); |
|
1453 |
||
1454 |
if ((error = nvpair_value_nvlist(source_pair, &sourcenv)) != 0) |
|
1455 |
goto abort; |
|
1456 |
||
1457 |
/* |
|
1458 |
* Make sure nvlist is composed correctly |
|
1459 |
*/ |
|
1460 |
if (zfs_deleg_verify_nvlist(sourcenv)) { |
|
1461 |
goto abort; |
|
1462 |
} |
|
1463 |
||
1464 |
who_pair = nvlist_next_nvpair(sourcenv, NULL); |
|
1465 |
if (who_pair == NULL) { |
|
1466 |
goto abort; |
|
1467 |
} |
|
1468 |
||
1469 |
do { |
|
1470 |
error = nvpair_value_nvlist(who_pair, &permnv); |
|
1471 |
if (error) { |
|
1472 |
goto abort; |
|
1473 |
} |
|
1474 |
||
1475 |
/* |
|
1476 |
* First build up the key to use |
|
1477 |
* for looking up in the various |
|
1478 |
* who trees. |
|
1479 |
*/ |
|
1480 |
ld = nvpair_name(who_pair)[1]; |
|
1481 |
nvpname = nvpair_name(who_pair); |
|
1482 |
switch (nvpair_name(who_pair)[0]) { |
|
1483 |
case ZFS_DELEG_USER: |
|
1484 |
case ZFS_DELEG_USER_SETS: |
|
1485 |
tree = &zallowp->z_user; |
|
1486 |
uid = atol(&nvpname[3]); |
|
1487 |
pwd = getpwuid(uid); |
|
1488 |
(void) snprintf(findallownode.z_key, |
|
1489 |
sizeof (findallownode.z_key), "user %s", |
|
1490 |
(pwd) ? pwd->pw_name : |
|
1491 |
&nvpair_name(who_pair)[3]); |
|
1492 |
break; |
|
1493 |
case ZFS_DELEG_GROUP: |
|
1494 |
case ZFS_DELEG_GROUP_SETS: |
|
1495 |
tree = &zallowp->z_group; |
|
1496 |
gid = atol(&nvpname[3]); |
|
1497 |
grp = getgrgid(gid); |
|
1498 |
(void) snprintf(findallownode.z_key, |
|
1499 |
sizeof (findallownode.z_key), "group %s", |
|
1500 |
(grp) ? grp->gr_name : |
|
1501 |
&nvpair_name(who_pair)[3]); |
|
1502 |
break; |
|
1503 |
case ZFS_DELEG_CREATE: |
|
1504 |
case ZFS_DELEG_CREATE_SETS: |
|
1505 |
tree = &zallowp->z_crperms; |
|
1506 |
(void) strlcpy(findallownode.z_key, "", |
|
1507 |
sizeof (findallownode.z_key)); |
|
1508 |
break; |
|
1509 |
case ZFS_DELEG_EVERYONE: |
|
1510 |
case ZFS_DELEG_EVERYONE_SETS: |
|
1511 |
(void) snprintf(findallownode.z_key, |
|
1512 |
sizeof (findallownode.z_key), "everyone"); |
|
1513 |
tree = &zallowp->z_everyone; |
|
1514 |
break; |
|
1515 |
case ZFS_DELEG_NAMED_SET: |
|
1516 |
case ZFS_DELEG_NAMED_SET_SETS: |
|
1517 |
(void) snprintf(findallownode.z_key, |
|
1518 |
sizeof (findallownode.z_key), "%s", |
|
1519 |
&nvpair_name(who_pair)[3]); |
|
1520 |
tree = &zallowp->z_sets; |
|
1521 |
break; |
|
1522 |
} |
|
1523 |
||
1524 |
/* |
|
1525 |
* Place who in tree |
|
1526 |
*/ |
|
1527 |
allownode = avl_find(tree, &findallownode, &where); |
|
1528 |
if (allownode == NULL) { |
|
1529 |
if ((newallownode = zfs_alloc(zhp->zfs_hdl, |
|
1530 |
sizeof (zfs_allow_node_t))) == NULL) { |
|
1531 |
goto abort; |
|
1532 |
} |
|
1533 |
avl_create(&newallownode->z_localdescend, |
|
1534 |
perm_compare, |
|
1535 |
sizeof (zfs_perm_node_t), |
|
1536 |
offsetof(zfs_perm_node_t, z_node)); |
|
1537 |
avl_create(&newallownode->z_local, |
|
1538 |
perm_compare, |
|
1539 |
sizeof (zfs_perm_node_t), |
|
1540 |
offsetof(zfs_perm_node_t, z_node)); |
|
1541 |
avl_create(&newallownode->z_descend, |
|
1542 |
perm_compare, |
|
1543 |
sizeof (zfs_perm_node_t), |
|
1544 |
offsetof(zfs_perm_node_t, z_node)); |
|
1545 |
(void) strlcpy(newallownode->z_key, |
|
1546 |
findallownode.z_key, |
|
1547 |
sizeof (findallownode.z_key)); |
|
1548 |
avl_insert(tree, newallownode, where); |
|
1549 |
allownode = newallownode; |
|
1550 |
} |
|
1551 |
||
1552 |
/* |
|
1553 |
* Now iterate over the permissions and |
|
1554 |
* place them in the appropriate local, |
|
1555 |
* descendent or local+descendent tree. |
|
1556 |
* |
|
1557 |
* The permissions are added to the tree |
|
1558 |
* via zfs_coalesce_perm(). |
|
1559 |
*/ |
|
1560 |
perm_pair = nvlist_next_nvpair(permnv, NULL); |
|
1561 |
if (perm_pair == NULL) |
|
1562 |
goto abort; |
|
1563 |
do { |
|
1564 |
if (zfs_coalesce_perm(zhp, allownode, |
|
1565 |
nvpair_name(perm_pair), ld) != 0) |
|
1566 |
goto abort; |
|
1567 |
} while (perm_pair = nvlist_next_nvpair(permnv, |
|
1568 |
perm_pair)); |
|
1569 |
} while (who_pair = nvlist_next_nvpair(sourcenv, who_pair)); |
|
1570 |
||
1571 |
source_pair = nvlist_next_nvpair(nvlist, source_pair); |
|
1572 |
if (source_pair == NULL) |
|
1573 |
break; |
|
1574 |
||
1575 |
/* |
|
1576 |
* allocate another node from the link list of |
|
1577 |
* zfs_allow_t structures |
|
1578 |
*/ |
|
1579 |
newallowp = zfs_alloc_perm_tree(zhp, zallowp, |
|
1580 |
nvpair_name(source_pair)); |
|
1581 |
if (newallowp == NULL) { |
|
1582 |
goto abort; |
|
1583 |
} |
|
1584 |
zallowp = newallowp; |
|
1585 |
} |
|
1586 |
nvlist_free(nvlist); |
|
1587 |
return (0); |
|
1588 |
abort: |
|
1589 |
zfs_free_allows(*zfs_perms); |
|
1590 |
nvlist_free(nvlist); |
|
1591 |
return (-1); |
|
1592 |
} |
|
1593 |
||
5993 | 1594 |
static char * |
1595 |
zfs_deleg_perm_note(zfs_deleg_note_t note) |
|
1596 |
{ |
|
1597 |
/* |
|
1598 |
* Don't put newlines on end of lines |
|
1599 |
*/ |
|
1600 |
switch (note) { |
|
1601 |
case ZFS_DELEG_NOTE_CREATE: |
|
1602 |
return (dgettext(TEXT_DOMAIN, |
|
1603 |
"Must also have the 'mount' ability")); |
|
1604 |
case ZFS_DELEG_NOTE_DESTROY: |
|
1605 |
return (dgettext(TEXT_DOMAIN, |
|
1606 |
"Must also have the 'mount' ability")); |
|
1607 |
case ZFS_DELEG_NOTE_SNAPSHOT: |
|
1608 |
return (dgettext(TEXT_DOMAIN, |
|
1609 |
"Must also have the 'mount' ability")); |
|
1610 |
case ZFS_DELEG_NOTE_ROLLBACK: |
|
1611 |
return (dgettext(TEXT_DOMAIN, |
|
1612 |
"Must also have the 'mount' ability")); |
|
1613 |
case ZFS_DELEG_NOTE_CLONE: |
|
1614 |
return (dgettext(TEXT_DOMAIN, "Must also have the 'create' " |
|
1615 |
"ability and 'mount'\n" |
|
1616 |
"\t\t\t\tability in the origin file system")); |
|
1617 |
case ZFS_DELEG_NOTE_PROMOTE: |
|
1618 |
return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'\n" |
|
1619 |
"\t\t\t\tand 'promote' ability in the origin file system")); |
|
1620 |
case ZFS_DELEG_NOTE_RENAME: |
|
1621 |
return (dgettext(TEXT_DOMAIN, "Must also have the 'mount' " |
|
1622 |
"and 'create' \n\t\t\t\tability in the new parent")); |
|
1623 |
case ZFS_DELEG_NOTE_RECEIVE: |
|
1624 |
return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'" |
|
1625 |
" and 'create' ability")); |
|
1626 |
case ZFS_DELEG_NOTE_USERPROP: |
|
1627 |
return (dgettext(TEXT_DOMAIN, |
|
1628 |
"Allows changing any user property")); |
|
1629 |
case ZFS_DELEG_NOTE_ALLOW: |
|
1630 |
return (dgettext(TEXT_DOMAIN, |
|
1631 |
"Must also have the permission that is being\n" |
|
1632 |
"\t\t\t\tallowed")); |
|
1633 |
case ZFS_DELEG_NOTE_MOUNT: |
|
1634 |
return (dgettext(TEXT_DOMAIN, |
|
1635 |
"Allows mount/umount of ZFS datasets")); |
|
1636 |
case ZFS_DELEG_NOTE_SHARE: |
|
1637 |
return (dgettext(TEXT_DOMAIN, |
|
1638 |
"Allows sharing file systems over NFS or SMB\n" |
|
1639 |
"\t\t\t\tprotocols")); |
|
1640 |
case ZFS_DELEG_NOTE_NONE: |
|
1641 |
default: |
|
1642 |
return (dgettext(TEXT_DOMAIN, "")); |
|
1643 |
} |
|
1644 |
} |
|
1645 |
||
1646 |
typedef enum { |
|
1647 |
ZFS_DELEG_SUBCOMMAND, |
|
1648 |
ZFS_DELEG_PROP, |
|
1649 |
ZFS_DELEG_OTHER |
|
1650 |
} zfs_deleg_perm_type_t; |
|
1651 |
||
1652 |
/* |
|
1653 |
* is the permission a subcommand or other? |
|
1654 |
*/ |
|
1655 |
zfs_deleg_perm_type_t |
|
1656 |
zfs_deleg_perm_type(const char *perm) |
|
1657 |
{ |
|
1658 |
if (strcmp(perm, "userprop") == 0) |
|
1659 |
return (ZFS_DELEG_OTHER); |
|
1660 |
else |
|
1661 |
return (ZFS_DELEG_SUBCOMMAND); |
|
1662 |
} |
|
1663 |
||
1664 |
static char * |
|
1665 |
zfs_deleg_perm_type_str(zfs_deleg_perm_type_t type) |
|
1666 |
{ |
|
1667 |
switch (type) { |
|
1668 |
case ZFS_DELEG_SUBCOMMAND: |
|
1669 |
return (dgettext(TEXT_DOMAIN, "subcommand")); |
|
1670 |
case ZFS_DELEG_PROP: |
|
1671 |
return (dgettext(TEXT_DOMAIN, "property")); |
|
1672 |
case ZFS_DELEG_OTHER: |
|
1673 |
return (dgettext(TEXT_DOMAIN, "other")); |
|
1674 |
} |
|
1675 |
return (""); |
|
1676 |
} |
|
1677 |
||
1678 |
/*ARGSUSED*/ |
|
1679 |
static int |
|
1680 |
zfs_deleg_prop_cb(int prop, void *cb) |
|
1681 |
{ |
|
1682 |
if (zfs_prop_delegatable(prop)) |
|
1683 |
(void) fprintf(stderr, "%-15s %-15s\n", zfs_prop_to_name(prop), |
|
1684 |
zfs_deleg_perm_type_str(ZFS_DELEG_PROP)); |
|
1685 |
||
1686 |
return (ZPROP_CONT); |
|
1687 |
} |
|
1688 |
||
1689 |
void |
|
1690 |
zfs_deleg_permissions(void) |
|
1691 |
{ |
|
1692 |
int i; |
|
1693 |
||
1694 |
(void) fprintf(stderr, "\n%-15s %-15s\t%s\n\n", "NAME", |
|
1695 |
"TYPE", "NOTES"); |
|
1696 |
||
1697 |
/* |
|
1698 |
* First print out the subcommands |
|
1699 |
*/ |
|
1700 |
for (i = 0; zfs_deleg_perm_tab[i].z_perm != NULL; i++) { |
|
1701 |
(void) fprintf(stderr, "%-15s %-15s\t%s\n", |
|
1702 |
zfs_deleg_perm_tab[i].z_perm, |
|
1703 |
zfs_deleg_perm_type_str( |
|
1704 |
zfs_deleg_perm_type(zfs_deleg_perm_tab[i].z_perm)), |
|
1705 |
zfs_deleg_perm_note(zfs_deleg_perm_tab[i].z_note)); |
|
1706 |
} |
|
1707 |
||
1708 |
(void) zprop_iter(zfs_deleg_prop_cb, NULL, B_FALSE, B_TRUE, |
|
1709 |
ZFS_TYPE_DATASET|ZFS_TYPE_VOLUME); |
|
1710 |
} |
|
1711 |
||
789 | 1712 |
/* |
1713 |
* Given a property name and value, set the property for the given dataset. |
|
1714 |
*/ |
|
1715 |
int |
|
2676 | 1716 |
zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval) |
789 | 1717 |
{ |
1718 |
zfs_cmd_t zc = { 0 }; |
|
2676 | 1719 |
int ret = -1; |
1720 |
prop_changelist_t *cl = NULL; |
|
2082 | 1721 |
char errbuf[1024]; |
1722 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
2676 | 1723 |
nvlist_t *nvl = NULL, *realprops; |
1724 |
zfs_prop_t prop; |
|
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1725 |
int do_prefix = 1; |
2082 | 1726 |
|
1727 |
(void) snprintf(errbuf, sizeof (errbuf), |
|
2676 | 1728 |
dgettext(TEXT_DOMAIN, "cannot set property for '%s'"), |
2082 | 1729 |
zhp->zfs_name); |
1730 |
||
2676 | 1731 |
if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0 || |
1732 |
nvlist_add_string(nvl, propname, propval) != 0) { |
|
1733 |
(void) no_memory(hdl); |
|
1734 |
goto error; |
|
789 | 1735 |
} |
1736 |
||
5094 | 1737 |
if ((realprops = zfs_validate_properties(hdl, zhp->zfs_type, nvl, |
2676 | 1738 |
zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, errbuf)) == NULL) |
1739 |
goto error; |
|
5094 | 1740 |
|
2676 | 1741 |
nvlist_free(nvl); |
1742 |
nvl = realprops; |
|
1743 |
||
1744 |
prop = zfs_name_to_prop(propname); |
|
1745 |
||
789 | 1746 |
if ((cl = changelist_gather(zhp, prop, 0)) == NULL) |
2676 | 1747 |
goto error; |
789 | 1748 |
|
1749 |
if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) { |
|
2082 | 1750 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1751 |
"child dataset with inherited mountpoint is used " |
|
1752 |
"in a non-global zone")); |
|
1753 |
ret = zfs_error(hdl, EZFS_ZONED, errbuf); |
|
789 | 1754 |
goto error; |
1755 |
} |
|
1756 |
||
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1757 |
|
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1758 |
/* do not unmount dataset if canmount is being set to noauto */ |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1759 |
if (prop == ZFS_PROP_CANMOUNT && *propval == ZFS_CANMOUNT_NOAUTO) |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1760 |
do_prefix = 0; |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1761 |
|
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1762 |
if (do_prefix && (ret = changelist_prefix(cl)) != 0) |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1763 |
goto error; |
789 | 1764 |
|
1765 |
/* |
|
1766 |
* Execute the corresponding ioctl() to set this property. |
|
1767 |
*/ |
|
1768 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
1769 |
||
5094 | 1770 |
if (zcmd_write_src_nvlist(hdl, &zc, nvl) != 0) |
2676 | 1771 |
goto error; |
1772 |
||
4543 | 1773 |
ret = zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc); |
789 | 1774 |
if (ret != 0) { |
1775 |
switch (errno) { |
|
1776 |
||
1777 |
case ENOSPC: |
|
1778 |
/* |
|
1779 |
* For quotas and reservations, ENOSPC indicates |
|
1780 |
* something different; setting a quota or reservation |
|
1781 |
* doesn't use any disk space. |
|
1782 |
*/ |
|
1783 |
switch (prop) { |
|
1784 |
case ZFS_PROP_QUOTA: |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
1785 |
case ZFS_PROP_REFQUOTA: |
2082 | 1786 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1787 |
"size is less than current used or " |
|
1788 |
"reserved space")); |
|
1789 |
(void) zfs_error(hdl, EZFS_PROPSPACE, errbuf); |
|
789 | 1790 |
break; |
1791 |
||
1792 |
case ZFS_PROP_RESERVATION: |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
1793 |
case ZFS_PROP_REFRESERVATION: |
2082 | 1794 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1795 |
"size is greater than available space")); |
|
1796 |
(void) zfs_error(hdl, EZFS_PROPSPACE, errbuf); |
|
789 | 1797 |
break; |
1798 |
||
1799 |
default: |
|
2082 | 1800 |
(void) zfs_standard_error(hdl, errno, errbuf); |
789 | 1801 |
break; |
1802 |
} |
|
1803 |
break; |
|
1804 |
||
1805 |
case EBUSY: |
|
2082 | 1806 |
if (prop == ZFS_PROP_VOLBLOCKSIZE) |
1807 |
(void) zfs_error(hdl, EZFS_VOLHASDATA, errbuf); |
|
1808 |
else |
|
2676 | 1809 |
(void) zfs_standard_error(hdl, EBUSY, errbuf); |
789 | 1810 |
break; |
1811 |
||
1175
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
1133
diff
changeset
|
1812 |
case EROFS: |
2082 | 1813 |
(void) zfs_error(hdl, EZFS_DSREADONLY, errbuf); |
1175
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
1133
diff
changeset
|
1814 |
break; |
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
1133
diff
changeset
|
1815 |
|
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3835
diff
changeset
|
1816 |
case ENOTSUP: |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3835
diff
changeset
|
1817 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
5977
33727f49aeaa
6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents:
5751
diff
changeset
|
1818 |
"pool and or dataset must be upgraded to set this " |
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4597
diff
changeset
|
1819 |
"property or value")); |
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3835
diff
changeset
|
1820 |
(void) zfs_error(hdl, EZFS_BADVERSION, errbuf); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3835
diff
changeset
|
1821 |
break; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3835
diff
changeset
|
1822 |
|
789 | 1823 |
case EOVERFLOW: |
1824 |
/* |
|
1825 |
* This platform can't address a volume this big. |
|
1826 |
*/ |
|
1827 |
#ifdef _ILP32 |
|
1828 |
if (prop == ZFS_PROP_VOLSIZE) { |
|
2082 | 1829 |
(void) zfs_error(hdl, EZFS_VOLTOOBIG, errbuf); |
789 | 1830 |
break; |
1831 |
} |
|
1832 |
#endif |
|
2082 | 1833 |
/* FALLTHROUGH */ |
789 | 1834 |
default: |
2082 | 1835 |
(void) zfs_standard_error(hdl, errno, errbuf); |
789 | 1836 |
} |
1837 |
} else { |
|
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1838 |
if (do_prefix) |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1839 |
ret = changelist_postfix(cl); |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1840 |
|
789 | 1841 |
/* |
1842 |
* Refresh the statistics so the new property value |
|
1843 |
* is reflected. |
|
1844 |
*/ |
|
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
1845 |
if (ret == 0) |
2676 | 1846 |
(void) get_stats(zhp); |
789 | 1847 |
} |
1848 |
||
1849 |
error: |
|
2676 | 1850 |
nvlist_free(nvl); |
1851 |
zcmd_free_nvlists(&zc); |
|
1852 |
if (cl) |
|
1853 |
changelist_free(cl); |
|
789 | 1854 |
return (ret); |
1855 |
} |
|
1856 |
||
1857 |
/* |
|
1858 |
* Given a property, inherit the value from the parent dataset. |
|
1859 |
*/ |
|
1860 |
int |
|
2676 | 1861 |
zfs_prop_inherit(zfs_handle_t *zhp, const char *propname) |
789 | 1862 |
{ |
1863 |
zfs_cmd_t zc = { 0 }; |
|
1864 |
int ret; |
|
1865 |
prop_changelist_t *cl; |
|
2082 | 1866 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
1867 |
char errbuf[1024]; |
|
2676 | 1868 |
zfs_prop_t prop; |
2082 | 1869 |
|
1870 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
1871 |
"cannot inherit %s for '%s'"), propname, zhp->zfs_name); |
|
789 | 1872 |
|
5094 | 1873 |
if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) { |
2676 | 1874 |
/* |
1875 |
* For user properties, the amount of work we have to do is very |
|
1876 |
* small, so just do it here. |
|
1877 |
*/ |
|
1878 |
if (!zfs_prop_user(propname)) { |
|
1879 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
1880 |
"invalid property")); |
|
1881 |
return (zfs_error(hdl, EZFS_BADPROP, errbuf)); |
|
1882 |
} |
|
1883 |
||
1884 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
1885 |
(void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value)); |
|
1886 |
||
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4801
diff
changeset
|
1887 |
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc) != 0) |
2676 | 1888 |
return (zfs_standard_error(hdl, errno, errbuf)); |
1889 |
||
1890 |
return (0); |
|
1891 |
} |
|
1892 |
||
789 | 1893 |
/* |
1894 |
* Verify that this property is inheritable. |
|
1895 |
*/ |
|
2082 | 1896 |
if (zfs_prop_readonly(prop)) |
1897 |
return (zfs_error(hdl, EZFS_PROPREADONLY, errbuf)); |
|
1898 |
||
1899 |
if (!zfs_prop_inheritable(prop)) |
|
1900 |
return (zfs_error(hdl, EZFS_PROPNONINHERIT, errbuf)); |
|
789 | 1901 |
|
1902 |
/* |
|
1903 |
* Check to see if the value applies to this type |
|
1904 |
*/ |
|
2082 | 1905 |
if (!zfs_prop_valid_for_type(prop, zhp->zfs_type)) |
1906 |
return (zfs_error(hdl, EZFS_PROPTYPE, errbuf)); |
|
789 | 1907 |
|
3443
e0e00ef6cee8
6494654 zfs inherit can't handle property short names
rm160521
parents:
3417
diff
changeset
|
1908 |
/* |
e0e00ef6cee8
6494654 zfs inherit can't handle property short names
rm160521
parents:
3417
diff
changeset
|
1909 |
* Normalize the name, to get rid of shorthand abbrevations. |
e0e00ef6cee8
6494654 zfs inherit can't handle property short names
rm160521
parents:
3417
diff
changeset
|
1910 |
*/ |
e0e00ef6cee8
6494654 zfs inherit can't handle property short names
rm160521
parents:
3417
diff
changeset
|
1911 |
propname = zfs_prop_to_name(prop); |
789 | 1912 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
2676 | 1913 |
(void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value)); |
789 | 1914 |
|
1915 |
if (prop == ZFS_PROP_MOUNTPOINT && getzoneid() == GLOBAL_ZONEID && |
|
1916 |
zfs_prop_get_int(zhp, ZFS_PROP_ZONED)) { |
|
2082 | 1917 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1918 |
"dataset is used in a non-global zone")); |
|
1919 |
return (zfs_error(hdl, EZFS_ZONED, errbuf)); |
|
789 | 1920 |
} |
1921 |
||
1922 |
/* |
|
1923 |
* Determine datasets which will be affected by this change, if any. |
|
1924 |
*/ |
|
1925 |
if ((cl = changelist_gather(zhp, prop, 0)) == NULL) |
|
1926 |
return (-1); |
|
1927 |
||
1928 |
if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) { |
|
2082 | 1929 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1930 |
"child dataset with inherited mountpoint is used " |
|
1931 |
"in a non-global zone")); |
|
1932 |
ret = zfs_error(hdl, EZFS_ZONED, errbuf); |
|
789 | 1933 |
goto error; |
1934 |
} |
|
1935 |
||
1936 |
if ((ret = changelist_prefix(cl)) != 0) |
|
1937 |
goto error; |
|
1938 |
||
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4801
diff
changeset
|
1939 |
if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc)) != 0) { |
2082 | 1940 |
return (zfs_standard_error(hdl, errno, errbuf)); |
789 | 1941 |
} else { |
1942 |
||
2169
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2166
diff
changeset
|
1943 |
if ((ret = changelist_postfix(cl)) != 0) |
789 | 1944 |
goto error; |
1945 |
||
1946 |
/* |
|
1947 |
* Refresh the statistics so the new property is reflected. |
|
1948 |
*/ |
|
1949 |
(void) get_stats(zhp); |
|
1950 |
} |
|
1951 |
||
1952 |
error: |
|
1953 |
changelist_free(cl); |
|
1954 |
return (ret); |
|
1955 |
} |
|
1956 |
||
1957 |
/* |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1958 |
* True DSL properties are stored in an nvlist. The following two functions |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1959 |
* extract them appropriately. |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1960 |
*/ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1961 |
static uint64_t |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1962 |
getprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1963 |
{ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1964 |
nvlist_t *nv; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1965 |
uint64_t value; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1966 |
|
2885 | 1967 |
*source = NULL; |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1968 |
if (nvlist_lookup_nvlist(zhp->zfs_props, |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1969 |
zfs_prop_to_name(prop), &nv) == 0) { |
5094 | 1970 |
verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0); |
1971 |
(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source); |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1972 |
} else { |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1973 |
value = zfs_prop_default_numeric(prop); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1974 |
*source = ""; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1975 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1976 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1977 |
return (value); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1978 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1979 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1980 |
static char * |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1981 |
getprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1982 |
{ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1983 |
nvlist_t *nv; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1984 |
char *value; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1985 |
|
2885 | 1986 |
*source = NULL; |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1987 |
if (nvlist_lookup_nvlist(zhp->zfs_props, |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1988 |
zfs_prop_to_name(prop), &nv) == 0) { |
5094 | 1989 |
verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0); |
1990 |
(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source); |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1991 |
} else { |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1992 |
if ((value = (char *)zfs_prop_default_string(prop)) == NULL) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1993 |
value = ""; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1994 |
*source = ""; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1995 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1996 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1997 |
return (value); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1998 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
1999 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2000 |
/* |
789 | 2001 |
* Internal function for getting a numeric property. Both zfs_prop_get() and |
2002 |
* zfs_prop_get_int() are built using this interface. |
|
2003 |
* |
|
2004 |
* Certain properties can be overridden using 'mount -o'. In this case, scan |
|
2005 |
* the contents of the /etc/mnttab entry, searching for the appropriate options. |
|
2006 |
* If they differ from the on-disk values, report the current values and mark |
|
2007 |
* the source "temporary". |
|
2008 |
*/ |
|
2082 | 2009 |
static int |
5094 | 2010 |
get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src, |
2082 | 2011 |
char **source, uint64_t *val) |
789 | 2012 |
{ |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2013 |
zfs_cmd_t zc = { 0 }; |
5592 | 2014 |
nvlist_t *zplprops = NULL; |
789 | 2015 |
struct mnttab mnt; |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2016 |
char *mntopt_on = NULL; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2017 |
char *mntopt_off = NULL; |
789 | 2018 |
|
2019 |
*source = NULL; |
|
2020 |
||
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2021 |
switch (prop) { |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2022 |
case ZFS_PROP_ATIME: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2023 |
mntopt_on = MNTOPT_ATIME; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2024 |
mntopt_off = MNTOPT_NOATIME; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2025 |
break; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2026 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2027 |
case ZFS_PROP_DEVICES: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2028 |
mntopt_on = MNTOPT_DEVICES; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2029 |
mntopt_off = MNTOPT_NODEVICES; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2030 |
break; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2031 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2032 |
case ZFS_PROP_EXEC: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2033 |
mntopt_on = MNTOPT_EXEC; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2034 |
mntopt_off = MNTOPT_NOEXEC; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2035 |
break; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2036 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2037 |
case ZFS_PROP_READONLY: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2038 |
mntopt_on = MNTOPT_RO; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2039 |
mntopt_off = MNTOPT_RW; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2040 |
break; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2041 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2042 |
case ZFS_PROP_SETUID: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2043 |
mntopt_on = MNTOPT_SETUID; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2044 |
mntopt_off = MNTOPT_NOSETUID; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2045 |
break; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2046 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2047 |
case ZFS_PROP_XATTR: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2048 |
mntopt_on = MNTOPT_XATTR; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2049 |
mntopt_off = MNTOPT_NOXATTR; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2050 |
break; |
5331 | 2051 |
|
2052 |
case ZFS_PROP_NBMAND: |
|
2053 |
mntopt_on = MNTOPT_NBMAND; |
|
2054 |
mntopt_off = MNTOPT_NONBMAND; |
|
2055 |
break; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2056 |
} |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2057 |
|
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2058 |
/* |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2059 |
* Because looking up the mount options is potentially expensive |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2060 |
* (iterating over all of /etc/mnttab), we defer its calculation until |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2061 |
* we're looking up a property which requires its presence. |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2062 |
*/ |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2063 |
if (!zhp->zfs_mntcheck && |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2064 |
(mntopt_on != NULL || prop == ZFS_PROP_MOUNTED)) { |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2065 |
struct mnttab entry, search = { 0 }; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2066 |
FILE *mnttab = zhp->zfs_hdl->libzfs_mnttab; |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2067 |
|
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2068 |
search.mnt_special = (char *)zhp->zfs_name; |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2069 |
search.mnt_fstype = MNTTYPE_ZFS; |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2070 |
rewind(mnttab); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2071 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2072 |
if (getmntany(mnttab, &entry, &search) == 0) { |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2073 |
zhp->zfs_mntopts = zfs_strdup(zhp->zfs_hdl, |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2074 |
entry.mnt_mntopts); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2075 |
if (zhp->zfs_mntopts == NULL) |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2076 |
return (-1); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2077 |
} |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2078 |
|
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2079 |
zhp->zfs_mntcheck = B_TRUE; |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2080 |
} |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
2081 |
|
789 | 2082 |
if (zhp->zfs_mntopts == NULL) |
2083 |
mnt.mnt_mntopts = ""; |
|
2084 |
else |
|
2085 |
mnt.mnt_mntopts = zhp->zfs_mntopts; |
|
2086 |
||
2087 |
switch (prop) { |
|
2088 |
case ZFS_PROP_ATIME: |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2089 |
case ZFS_PROP_DEVICES: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2090 |
case ZFS_PROP_EXEC: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2091 |
case ZFS_PROP_READONLY: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2092 |
case ZFS_PROP_SETUID: |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2093 |
case ZFS_PROP_XATTR: |
5331 | 2094 |
case ZFS_PROP_NBMAND: |
2082 | 2095 |
*val = getprop_uint64(zhp, prop, source); |
2096 |
||
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2097 |
if (hasmntopt(&mnt, mntopt_on) && !*val) { |
2082 | 2098 |
*val = B_TRUE; |
789 | 2099 |
if (src) |
5094 | 2100 |
*src = ZPROP_SRC_TEMPORARY; |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2101 |
} else if (hasmntopt(&mnt, mntopt_off) && *val) { |
2082 | 2102 |
*val = B_FALSE; |
789 | 2103 |
if (src) |
5094 | 2104 |
*src = ZPROP_SRC_TEMPORARY; |
789 | 2105 |
} |
2082 | 2106 |
break; |
789 | 2107 |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
2108 |
case ZFS_PROP_CANMOUNT: |
2082 | 2109 |
*val = getprop_uint64(zhp, prop, source); |
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
2110 |
if (*val != ZFS_CANMOUNT_ON) |
3417
0630f537a7e5
6480849 source of canmount property needs improvement
rm160521
parents:
3413
diff
changeset
|
2111 |
*source = zhp->zfs_name; |
0630f537a7e5
6480849 source of canmount property needs improvement
rm160521
parents:
3413
diff
changeset
|
2112 |
else |
0630f537a7e5
6480849 source of canmount property needs improvement
rm160521
parents:
3413
diff
changeset
|
2113 |
*source = ""; /* default */ |
2082 | 2114 |
break; |
789 | 2115 |
|
2116 |
case ZFS_PROP_QUOTA: |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
2117 |
case ZFS_PROP_REFQUOTA: |
789 | 2118 |
case ZFS_PROP_RESERVATION: |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
2119 |
case ZFS_PROP_REFRESERVATION: |
2885 | 2120 |
*val = getprop_uint64(zhp, prop, source); |
2121 |
if (*val == 0) |
|
789 | 2122 |
*source = ""; /* default */ |
2123 |
else |
|
2124 |
*source = zhp->zfs_name; |
|
2082 | 2125 |
break; |
789 | 2126 |
|
2127 |
case ZFS_PROP_MOUNTED: |
|
2082 | 2128 |
*val = (zhp->zfs_mntopts != NULL); |
2129 |
break; |
|
789 | 2130 |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3363
diff
changeset
|
2131 |
case ZFS_PROP_NUMCLONES: |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3363
diff
changeset
|
2132 |
*val = zhp->zfs_dmustats.dds_num_clones; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3363
diff
changeset
|
2133 |
break; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3363
diff
changeset
|
2134 |
|
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2135 |
case ZFS_PROP_VERSION: |
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2136 |
case ZFS_PROP_NORMALIZE: |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2137 |
case ZFS_PROP_UTF8ONLY: |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2138 |
case ZFS_PROP_CASE: |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2139 |
if (!zfs_prop_valid_for_type(prop, zhp->zfs_head_type) || |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2140 |
zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) |
5473
fcdd1931b3aa
6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents:
5446
diff
changeset
|
2141 |
return (-1); |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2142 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2143 |
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_OBJSET_ZPLPROPS, &zc)) { |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2144 |
zcmd_free_nvlists(&zc); |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2145 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2146 |
"unable to get %s property"), |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2147 |
zfs_prop_to_name(prop)); |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2148 |
return (zfs_error(zhp->zfs_hdl, EZFS_BADVERSION, |
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2149 |
dgettext(TEXT_DOMAIN, "internal error"))); |
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2150 |
} |
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2151 |
if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &zplprops) != 0 || |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2152 |
nvlist_lookup_uint64(zplprops, zfs_prop_to_name(prop), |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2153 |
val) != 0) { |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2154 |
zcmd_free_nvlists(&zc); |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2155 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2156 |
"unable to get %s property"), |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2157 |
zfs_prop_to_name(prop)); |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2158 |
return (zfs_error(zhp->zfs_hdl, EZFS_NOMEM, |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2159 |
dgettext(TEXT_DOMAIN, "internal error"))); |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2160 |
} |
5592 | 2161 |
if (zplprops) |
2162 |
nvlist_free(zplprops); |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5481
diff
changeset
|
2163 |
zcmd_free_nvlists(&zc); |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2164 |
break; |
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
5094
diff
changeset
|
2165 |
|
789 | 2166 |
default: |
4577 | 2167 |
switch (zfs_prop_get_type(prop)) { |
4787 | 2168 |
case PROP_TYPE_NUMBER: |
2169 |
case PROP_TYPE_INDEX: |
|
4577 | 2170 |
*val = getprop_uint64(zhp, prop, source); |
2171 |
break; |
|
2172 |
||
4787 | 2173 |
case PROP_TYPE_STRING: |
4577 | 2174 |
default: |
2175 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
|
2176 |
"cannot get non-numeric property")); |
|
2177 |
return (zfs_error(zhp->zfs_hdl, EZFS_BADPROP, |
|
2178 |
dgettext(TEXT_DOMAIN, "internal error"))); |
|
2179 |
} |
|
789 | 2180 |
} |
2181 |
||
2182 |
return (0); |
|
2183 |
} |
|
2184 |
||
2185 |
/* |
|
2186 |
* Calculate the source type, given the raw source string. |
|
2187 |
*/ |
|
2188 |
static void |
|
5094 | 2189 |
get_source(zfs_handle_t *zhp, zprop_source_t *srctype, char *source, |
789 | 2190 |
char *statbuf, size_t statlen) |
2191 |
{ |
|
5094 | 2192 |
if (statbuf == NULL || *srctype == ZPROP_SRC_TEMPORARY) |
789 | 2193 |
return; |
2194 |
||
2195 |
if (source == NULL) { |
|
5094 | 2196 |
*srctype = ZPROP_SRC_NONE; |
789 | 2197 |
} else if (source[0] == '\0') { |
5094 | 2198 |
*srctype = ZPROP_SRC_DEFAULT; |
789 | 2199 |
} else { |
2200 |
if (strcmp(source, zhp->zfs_name) == 0) { |
|
5094 | 2201 |
*srctype = ZPROP_SRC_LOCAL; |
789 | 2202 |
} else { |
2203 |
(void) strlcpy(statbuf, source, statlen); |
|
5094 | 2204 |
*srctype = ZPROP_SRC_INHERITED; |
789 | 2205 |
} |
2206 |
} |
|
2207 |
||
2208 |
} |
|
2209 |
||
2210 |
/* |
|
2211 |
* Retrieve a property from the given object. If 'literal' is specified, then |
|
2212 |
* numbers are left as exact values. Otherwise, numbers are converted to a |
|
2213 |
* human-readable form. |
|
2214 |
* |
|
2215 |
* Returns 0 on success, or -1 on error. |
|
2216 |
*/ |
|
2217 |
int |
|
2218 |
zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen, |
|
5094 | 2219 |
zprop_source_t *src, char *statbuf, size_t statlen, boolean_t literal) |
789 | 2220 |
{ |
2221 |
char *source = NULL; |
|
2222 |
uint64_t val; |
|
2223 |
char *str; |
|
2224 |
const char *root; |
|
2676 | 2225 |
const char *strval; |
789 | 2226 |
|
2227 |
/* |
|
2228 |
* Check to see if this property applies to our object |
|
2229 |
*/ |
|
2230 |
if (!zfs_prop_valid_for_type(prop, zhp->zfs_type)) |
|
2231 |
return (-1); |
|
2232 |
||
2233 |
if (src) |
|
5094 | 2234 |
*src = ZPROP_SRC_NONE; |
789 | 2235 |
|
2236 |
switch (prop) { |
|
2237 |
case ZFS_PROP_CREATION: |
|
2238 |
/* |
|
2239 |
* 'creation' is a time_t stored in the statistics. We convert |
|
2240 |
* this into a string unless 'literal' is specified. |
|
2241 |
*/ |
|
2242 |
{ |
|
2885 | 2243 |
val = getprop_uint64(zhp, prop, &source); |
2244 |
time_t time = (time_t)val; |
|
789 | 2245 |
struct tm t; |
2246 |
||
2247 |
if (literal || |
|
2248 |
localtime_r(&time, &t) == NULL || |
|
2249 |
strftime(propbuf, proplen, "%a %b %e %k:%M %Y", |
|
2250 |
&t) == 0) |
|
2885 | 2251 |
(void) snprintf(propbuf, proplen, "%llu", val); |
789 | 2252 |
} |
2253 |
break; |
|
2254 |
||
2255 |
case ZFS_PROP_MOUNTPOINT: |
|
2256 |
/* |
|
2257 |
* Getting the precise mountpoint can be tricky. |
|
2258 |
* |
|
2259 |
* - for 'none' or 'legacy', return those values. |
|
2260 |
* - for default mountpoints, construct it as /zfs/<dataset> |
|
2261 |
* - for inherited mountpoints, we want to take everything |
|
2262 |
* after our ancestor and append it to the inherited value. |
|
2263 |
* |
|
2264 |
* If the pool has an alternate root, we want to prepend that |
|
2265 |
* root to any values we return. |
|
2266 |
*/ |
|
1544 | 2267 |
root = zhp->zfs_root; |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2268 |
str = getprop_string(zhp, prop, &source); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2269 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2270 |
if (str[0] == '\0') { |
789 | 2271 |
(void) snprintf(propbuf, proplen, "%s/zfs/%s", |
2272 |
root, zhp->zfs_name); |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2273 |
} else if (str[0] == '/') { |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2274 |
const char *relpath = zhp->zfs_name + strlen(source); |
789 | 2275 |
|
2276 |
if (relpath[0] == '/') |
|
2277 |
relpath++; |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2278 |
if (str[1] == '\0') |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2279 |
str++; |
789 | 2280 |
|
2281 |
if (relpath[0] == '\0') |
|
2282 |
(void) snprintf(propbuf, proplen, "%s%s", |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2283 |
root, str); |
789 | 2284 |
else |
2285 |
(void) snprintf(propbuf, proplen, "%s%s%s%s", |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2286 |
root, str, relpath[0] == '@' ? "" : "/", |
789 | 2287 |
relpath); |
2288 |
} else { |
|
2289 |
/* 'legacy' or 'none' */ |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2290 |
(void) strlcpy(propbuf, str, proplen); |
789 | 2291 |
} |
2292 |
||
2293 |
break; |
|
2294 |
||
2295 |
case ZFS_PROP_ORIGIN: |
|
2885 | 2296 |
(void) strlcpy(propbuf, getprop_string(zhp, prop, &source), |
789 | 2297 |
proplen); |
2298 |
/* |
|
2299 |
* If there is no parent at all, return failure to indicate that |
|
2300 |
* it doesn't apply to this dataset. |
|
2301 |
*/ |
|
2302 |
if (propbuf[0] == '\0') |
|
2303 |
return (-1); |
|
2304 |
break; |
|
2305 |
||
2306 |
case ZFS_PROP_QUOTA: |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
2307 |
case ZFS_PROP_REFQUOTA: |
789 | 2308 |
case ZFS_PROP_RESERVATION: |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
2309 |
case ZFS_PROP_REFRESERVATION: |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5375
diff
changeset
|
2310 |
|
2082 | 2311 |
if (get_numeric_property(zhp, prop, src, &source, &val) != 0) |
2312 |
return (-1); |
|
789 | 2313 |
|
2314 |
/* |
|
2315 |
* If quota or reservation is 0, we translate this into 'none' |
|
2316 |
* (unless literal is set), and indicate that it's the default |
|
2317 |
* value. Otherwise, we print the number nicely and indicate |
|
2318 |
* that its set locally. |
|
2319 |
*/ |
|
2320 |
if (val == 0) { |
|
2321 |
if (literal) |
|
2322 |
(void) strlcpy(propbuf, "0", proplen); |
|
2323 |
else |
|
2324 |
(void) strlcpy(propbuf, "none", proplen); |
|
2325 |
} else { |
|
2326 |
if (literal) |
|
2856 | 2327 |
(void) snprintf(propbuf, proplen, "%llu", |
3912 | 2328 |
(u_longlong_t)val); |
789 | 2329 |
else |
2330 |
zfs_nicenum(val, propbuf, proplen); |
|
2331 |
} |
|
2332 |
break; |
|
2333 |
||
2334 |
case ZFS_PROP_COMPRESSRATIO: |
|
2082 | 2335 |
if (get_numeric_property(zhp, prop, src, &source, &val) != 0) |
2336 |
return (-1); |
|
2856 | 2337 |
(void) snprintf(propbuf, proplen, "%lld.%02lldx", (longlong_t) |
2338 |
val / 100, (longlong_t)val % 100); |
|
789 | 2339 |
break; |
2340 |
||
2341 |
case ZFS_PROP_TYPE: |
|
2342 |
switch (zhp->zfs_type) { |
|
2343 |
case ZFS_TYPE_FILESYSTEM: |
|
2344 |
str = "filesystem"; |
|
2345 |
break; |
|
2346 |
case ZFS_TYPE_VOLUME: |
|
2347 |
str = "volume"; |
|
2348 |
break; |
|
2349 |
case ZFS_TYPE_SNAPSHOT: |
|
2350 |
str = "snapshot"; |
|
2351 |
break; |
|
2352 |
default: |
|
2082 | 2353 |
abort(); |
789 | 2354 |
} |
2355 |
(void) snprintf(propbuf, proplen, "%s", str); |
|
2356 |
break; |
|
2357 |
||
2358 |
case ZFS_PROP_MOUNTED: |
|
2359 |
/* |
|
2360 |
* The 'mounted' property is a pseudo-property that described |
|
2361 |
* whether the filesystem is currently mounted. Even though |
|
2362 |
* it's a boolean value, the typical values of "on" and "off" |
|
2363 |
* don't make sense, so we translate to "yes" and "no". |
|
2364 |
*/ |
|
2082 | 2365 |
if (get_numeric_property(zhp, ZFS_PROP_MOUNTED, |
2366 |
src, &source, &val) != 0) |
|
2367 |
return (-1); |
|
2368 |
if (val) |
|
789 | 2369 |
(void) strlcpy(propbuf, "yes", proplen); |
2370 |
else |
|
2371 |
(void) strlcpy(propbuf, "no", proplen); |
|
2372 |
break; |
|
2373 |
||
2374 |
case ZFS_PROP_NAME: |
|
2375 |
/* |
|
2376 |
* The 'name' property is a pseudo-property derived from the |
|
2377 |
* dataset name. It is presented as a real property to simplify |
|
2378 |
* consumers. |
|
2379 |
*/ |
|
2380 |
(void) strlcpy(propbuf, zhp->zfs_name, proplen); |
|
2381 |
break; |
|
2382 |
||
2383 |
default: |
|
4577 | 2384 |
switch (zfs_prop_get_type(prop)) { |
4787 | 2385 |
case PROP_TYPE_NUMBER: |
4577 | 2386 |
if (get_numeric_property(zhp, prop, src, |
2387 |
&source, &val) != 0) |
|
2388 |
return (-1); |
|
2389 |
if (literal) |
|
2390 |
(void) snprintf(propbuf, proplen, "%llu", |
|
2391 |
(u_longlong_t)val); |
|
2392 |
else |
|
2393 |
zfs_nicenum(val, propbuf, proplen); |
|
2394 |
break; |
|
2395 |
||
4787 | 2396 |
case PROP_TYPE_STRING: |
4577 | 2397 |
(void) strlcpy(propbuf, |
2398 |
getprop_string(zhp, prop, &source), proplen); |
|
2399 |
break; |
|
2400 |
||
4787 | 2401 |
case PROP_TYPE_INDEX: |
4861
fa5be10d6612
6592018 "zfs get" does not display temporary property
ahrens
parents:
4849
diff
changeset
|
2402 |
if (get_numeric_property(zhp, prop, src, |
fa5be10d6612
6592018 "zfs get" does not display temporary property
ahrens
parents:
4849
diff
changeset
|
2403 |
&source, &val) != 0) |
fa5be10d6612
6592018 "zfs get" does not display temporary property
ahrens
parents:
4849
diff
changeset
|
2404 |
return (-1); |
fa5be10d6612
6592018 "zfs get" does not display temporary property
ahrens
parents:
4849
diff
changeset
|
2405 |
if (zfs_prop_index_to_string(prop, val, &strval) != 0) |
4577 | 2406 |
return (-1); |
2407 |
(void) strlcpy(propbuf, strval, proplen); |
|
2408 |
break; |
|
2409 |
||
2410 |
default: |
|
2411 |
abort(); |
|
2412 |
} |
|
789 | 2413 |
} |
2414 |
||
2415 |
get_source(zhp, src, source, statbuf, statlen); |
|
2416 |
||
2417 |
return (0); |
|
2418 |
} |
|
2419 |
||
2420 |
/* |
|
2421 |
* Utility function to get the given numeric property. Does no validation that |
|
2422 |
* the given property is the appropriate type; should only be used with |
|
2423 |
* hard-coded property types. |
|
2424 |
*/ |
|
2425 |
uint64_t |
|
2426 |
zfs_prop_get_int(zfs_handle_t *zhp, zfs_prop_t prop) |
|
2427 |
{ |
|
2428 |
char *source; |
|
2082 | 2429 |
uint64_t val; |
2430 |
||
5367 | 2431 |
(void) get_numeric_property(zhp, prop, NULL, &source, &val); |
2082 | 2432 |
|
2433 |
return (val); |
|
789 | 2434 |
} |
2435 |
||
5713 | 2436 |
int |
2437 |
zfs_prop_set_int(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t val) |
|
2438 |
{ |
|
2439 |
char buf[64]; |
|
2440 |
||
2441 |
zfs_nicenum(val, buf, sizeof (buf)); |
|
2442 |
return (zfs_prop_set(zhp, zfs_prop_to_name(prop), buf)); |
|
2443 |
} |
|
2444 |
||
789 | 2445 |
/* |
2446 |
* Similar to zfs_prop_get(), but returns the value as an integer. |
|
2447 |
*/ |
|
2448 |
int |
|
2449 |
zfs_prop_get_numeric(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t *value, |
|
5094 | 2450 |
zprop_source_t *src, char *statbuf, size_t statlen) |
789 | 2451 |
{ |
2452 |
char *source; |
|
2453 |
||
2454 |
/* |
|
2455 |
* Check to see if this property applies to our object |
|
2456 |
*/ |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4801
diff
changeset
|
2457 |
if (!zfs_prop_valid_for_type(prop, zhp->zfs_type)) { |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
2458 |
return (zfs_error_fmt(zhp->zfs_hdl, EZFS_PROPTYPE, |
2082 | 2459 |
dgettext(TEXT_DOMAIN, "cannot get property '%s'"), |
2460 |
zfs_prop_to_name(prop))); |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4801
diff
changeset
|
2461 |
} |
789 | 2462 |
|
2463 |
if (src) |
|
5094 | 2464 |
*src = ZPROP_SRC_NONE; |
789 | 2465 |
|
2082 | 2466 |
if (get_numeric_property(zhp, prop, src, &source, value) != 0) |
2467 |
return (-1); |
|
789 | 2468 |
|
2469 |
get_source(zhp, src, source, statbuf, statlen); |
|
2470 |
||
2471 |
return (0); |
|
2472 |
} |
|
2473 |
||
2474 |
/* |
|
2475 |
* Returns the name of the given zfs handle. |
|
2476 |
*/ |
|
2477 |
const char * |
|
2478 |
zfs_get_name(const zfs_handle_t *zhp) |
|
2479 |
{ |
|
2480 |
return (zhp->zfs_name); |
|
2481 |
} |
|
2482 |
||
2483 |
/* |
|
2484 |
* Returns the type of the given zfs handle. |
|
2485 |
*/ |
|
2486 |
zfs_type_t |
|
2487 |
zfs_get_type(const zfs_handle_t *zhp) |
|
2488 |
{ |
|
2489 |
return (zhp->zfs_type); |
|
2490 |
} |
|
2491 |
||
2492 |
/* |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2493 |
* Iterate over all child filesystems |
789 | 2494 |
*/ |
2495 |
int |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2496 |
zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data) |
789 | 2497 |
{ |
2498 |
zfs_cmd_t zc = { 0 }; |
|
2499 |
zfs_handle_t *nzhp; |
|
2500 |
int ret; |
|
2501 |
||
5367 | 2502 |
if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM) |
2503 |
return (0); |
|
2504 |
||
789 | 2505 |
for ((void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
2082 | 2506 |
ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_DATASET_LIST_NEXT, &zc) == 0; |
789 | 2507 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name))) { |
2508 |
/* |
|
2509 |
* Ignore private dataset names. |
|
2510 |
*/ |
|
2511 |
if (dataset_name_hidden(zc.zc_name)) |
|
2512 |
continue; |
|
2513 |
||
2514 |
/* |
|
2515 |
* Silently ignore errors, as the only plausible explanation is |
|
2516 |
* that the pool has since been removed. |
|
2517 |
*/ |
|
2082 | 2518 |
if ((nzhp = make_dataset_handle(zhp->zfs_hdl, |
2519 |
zc.zc_name)) == NULL) |
|
789 | 2520 |
continue; |
2521 |
||
2522 |
if ((ret = func(nzhp, data)) != 0) |
|
2523 |
return (ret); |
|
2524 |
} |
|
2525 |
||
2526 |
/* |
|
2527 |
* An errno value of ESRCH indicates normal completion. If ENOENT is |
|
2528 |
* returned, then the underlying dataset has been removed since we |
|
2529 |
* obtained the handle. |
|
2530 |
*/ |
|
2531 |
if (errno != ESRCH && errno != ENOENT) |
|
2082 | 2532 |
return (zfs_standard_error(zhp->zfs_hdl, errno, |
2533 |
dgettext(TEXT_DOMAIN, "cannot iterate filesystems"))); |
|
789 | 2534 |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2535 |
return (0); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2536 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2537 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2538 |
/* |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2539 |
* Iterate over all snapshots |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2540 |
*/ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2541 |
int |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2542 |
zfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2543 |
{ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2544 |
zfs_cmd_t zc = { 0 }; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2545 |
zfs_handle_t *nzhp; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2546 |
int ret; |
789 | 2547 |
|
5367 | 2548 |
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) |
2549 |
return (0); |
|
2550 |
||
789 | 2551 |
for ((void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
2082 | 2552 |
ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SNAPSHOT_LIST_NEXT, |
2553 |
&zc) == 0; |
|
789 | 2554 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name))) { |
2555 |
||
2082 | 2556 |
if ((nzhp = make_dataset_handle(zhp->zfs_hdl, |
2557 |
zc.zc_name)) == NULL) |
|
789 | 2558 |
continue; |
2559 |
||
2560 |
if ((ret = func(nzhp, data)) != 0) |
|
2561 |
return (ret); |
|
2562 |
} |
|
2563 |
||
2564 |
/* |
|
2565 |
* An errno value of ESRCH indicates normal completion. If ENOENT is |
|
2566 |
* returned, then the underlying dataset has been removed since we |
|
2567 |
* obtained the handle. Silently ignore this case, and return success. |
|
2568 |
*/ |
|
2569 |
if (errno != ESRCH && errno != ENOENT) |
|
2082 | 2570 |
return (zfs_standard_error(zhp->zfs_hdl, errno, |
2571 |
dgettext(TEXT_DOMAIN, "cannot iterate filesystems"))); |
|
789 | 2572 |
|
2573 |
return (0); |
|
2574 |
} |
|
2575 |
||
2576 |
/* |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2577 |
* Iterate over all children, snapshots and filesystems |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2578 |
*/ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2579 |
int |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2580 |
zfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2581 |
{ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2582 |
int ret; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2583 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2584 |
if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2585 |
return (ret); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2586 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2587 |
return (zfs_iter_snapshots(zhp, func, data)); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2588 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2589 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2590 |
/* |
789 | 2591 |
* Given a complete name, return just the portion that refers to the parent. |
2592 |
* Can return NULL if this is a pool. |
|
2593 |
*/ |
|
2594 |
static int |
|
2595 |
parent_name(const char *path, char *buf, size_t buflen) |
|
2596 |
{ |
|
2597 |
char *loc; |
|
2598 |
||
2599 |
if ((loc = strrchr(path, '/')) == NULL) |
|
2600 |
return (-1); |
|
2601 |
||
2602 |
(void) strncpy(buf, path, MIN(buflen, loc - path)); |
|
2603 |
buf[loc - path] = '\0'; |
|
2604 |
||
2605 |
return (0); |
|
2606 |
} |
|
2607 |
||
2608 |
/* |
|
4490 | 2609 |
* If accept_ancestor is false, then check to make sure that the given path has |
2610 |
* a parent, and that it exists. If accept_ancestor is true, then find the |
|
2611 |
* closest existing ancestor for the given path. In prefixlen return the |
|
2612 |
* length of already existing prefix of the given path. We also fetch the |
|
2613 |
* 'zoned' property, which is used to validate property settings when creating |
|
2614 |
* new datasets. |
|
789 | 2615 |
*/ |
2616 |
static int |
|
4490 | 2617 |
check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned, |
2618 |
boolean_t accept_ancestor, int *prefixlen) |
|
789 | 2619 |
{ |
2620 |
zfs_cmd_t zc = { 0 }; |
|
2621 |
char parent[ZFS_MAXNAMELEN]; |
|
2622 |
char *slash; |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2623 |
zfs_handle_t *zhp; |
2082 | 2624 |
char errbuf[1024]; |
2625 |
||
2626 |
(void) snprintf(errbuf, sizeof (errbuf), "cannot create '%s'", |
|
2627 |
path); |
|
789 | 2628 |
|
2629 |
/* get parent, and check to see if this is just a pool */ |
|
2630 |
if (parent_name(path, parent, sizeof (parent)) != 0) { |
|
2082 | 2631 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2632 |
"missing dataset name")); |
|
2633 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
|
789 | 2634 |
} |
2635 |
||
2636 |
/* check to see if the pool exists */ |
|
2637 |
if ((slash = strchr(parent, '/')) == NULL) |
|
2638 |
slash = parent + strlen(parent); |
|
2639 |
(void) strncpy(zc.zc_name, parent, slash - parent); |
|
2640 |
zc.zc_name[slash - parent] = '\0'; |
|
2082 | 2641 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0 && |
789 | 2642 |
errno == ENOENT) { |
2082 | 2643 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2644 |
"no such pool '%s'"), zc.zc_name); |
|
2645 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
789 | 2646 |
} |
2647 |
||
2648 |
/* check to see if the parent dataset exists */ |
|
4490 | 2649 |
while ((zhp = make_dataset_handle(hdl, parent)) == NULL) { |
2650 |
if (errno == ENOENT && accept_ancestor) { |
|
2651 |
/* |
|
2652 |
* Go deeper to find an ancestor, give up on top level. |
|
2653 |
*/ |
|
2654 |
if (parent_name(parent, parent, sizeof (parent)) != 0) { |
|
2655 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2656 |
"no such pool '%s'"), zc.zc_name); |
|
2657 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2658 |
} |
|
2659 |
} else if (errno == ENOENT) { |
|
2082 | 2660 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2661 |
"parent does not exist")); |
|
2662 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
4490 | 2663 |
} else |
2082 | 2664 |
return (zfs_standard_error(hdl, errno, errbuf)); |
789 | 2665 |
} |
2666 |
||
2676 | 2667 |
*zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED); |
789 | 2668 |
/* we are in a non-global zone, but parent is in the global zone */ |
2676 | 2669 |
if (getzoneid() != GLOBAL_ZONEID && !(*zoned)) { |
2082 | 2670 |
(void) zfs_standard_error(hdl, EPERM, errbuf); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2671 |
zfs_close(zhp); |
789 | 2672 |
return (-1); |
2673 |
} |
|
2674 |
||
2675 |
/* make sure parent is a filesystem */ |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2676 |
if (zfs_get_type(zhp) != ZFS_TYPE_FILESYSTEM) { |
2082 | 2677 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2678 |
"parent is not a filesystem")); |
|
2679 |
(void) zfs_error(hdl, EZFS_BADTYPE, errbuf); |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2680 |
zfs_close(zhp); |
789 | 2681 |
return (-1); |
2682 |
} |
|
2683 |
||
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2684 |
zfs_close(zhp); |
4490 | 2685 |
if (prefixlen != NULL) |
2686 |
*prefixlen = strlen(parent); |
|
2687 |
return (0); |
|
2688 |
} |
|
2689 |
||
2690 |
/* |
|
2691 |
* Finds whether the dataset of the given type(s) exists. |
|
2692 |
*/ |
|
2693 |
boolean_t |
|
2694 |
zfs_dataset_exists(libzfs_handle_t *hdl, const char *path, zfs_type_t types) |
|
2695 |
{ |
|
2696 |
zfs_handle_t *zhp; |
|
2697 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
2698 |
if (!zfs_validate_name(hdl, path, types, B_FALSE)) |
4490 | 2699 |
return (B_FALSE); |
2700 |
||
2701 |
/* |
|
2702 |
* Try to get stats for the dataset, which will tell us if it exists. |
|
2703 |
*/ |
|
2704 |
if ((zhp = make_dataset_handle(hdl, path)) != NULL) { |
|
2705 |
int ds_type = zhp->zfs_type; |
|
2706 |
||
2707 |
zfs_close(zhp); |
|
2708 |
if (types & ds_type) |
|
2709 |
return (B_TRUE); |
|
2710 |
} |
|
2711 |
return (B_FALSE); |
|
2712 |
} |
|
2713 |
||
2714 |
/* |
|
5367 | 2715 |
* Given a path to 'target', create all the ancestors between |
2716 |
* the prefixlen portion of the path, and the target itself. |
|
2717 |
* Fail if the initial prefixlen-ancestor does not already exist. |
|
2718 |
*/ |
|
2719 |
int |
|
2720 |
create_parents(libzfs_handle_t *hdl, char *target, int prefixlen) |
|
2721 |
{ |
|
2722 |
zfs_handle_t *h; |
|
2723 |
char *cp; |
|
2724 |
const char *opname; |
|
2725 |
||
2726 |
/* make sure prefix exists */ |
|
2727 |
cp = target + prefixlen; |
|
2728 |
if (*cp != '/') { |
|
2729 |
assert(strchr(cp, '/') == NULL); |
|
2730 |
h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM); |
|
2731 |
} else { |
|
2732 |
*cp = '\0'; |
|
2733 |
h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM); |
|
2734 |
*cp = '/'; |
|
2735 |
} |
|
2736 |
if (h == NULL) |
|
2737 |
return (-1); |
|
2738 |
zfs_close(h); |
|
2739 |
||
2740 |
/* |
|
2741 |
* Attempt to create, mount, and share any ancestor filesystems, |
|
2742 |
* up to the prefixlen-long one. |
|
2743 |
*/ |
|
2744 |
for (cp = target + prefixlen + 1; |
|
2745 |
cp = strchr(cp, '/'); *cp = '/', cp++) { |
|
2746 |
char *logstr; |
|
2747 |
||
2748 |
*cp = '\0'; |
|
2749 |
||
2750 |
h = make_dataset_handle(hdl, target); |
|
2751 |
if (h) { |
|
2752 |
/* it already exists, nothing to do here */ |
|
2753 |
zfs_close(h); |
|
2754 |
continue; |
|
2755 |
} |
|
2756 |
||
2757 |
logstr = hdl->libzfs_log_str; |
|
2758 |
hdl->libzfs_log_str = NULL; |
|
2759 |
if (zfs_create(hdl, target, ZFS_TYPE_FILESYSTEM, |
|
2760 |
NULL) != 0) { |
|
2761 |
hdl->libzfs_log_str = logstr; |
|
2762 |
opname = dgettext(TEXT_DOMAIN, "create"); |
|
2763 |
goto ancestorerr; |
|
2764 |
} |
|
2765 |
||
2766 |
hdl->libzfs_log_str = logstr; |
|
2767 |
h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM); |
|
2768 |
if (h == NULL) { |
|
2769 |
opname = dgettext(TEXT_DOMAIN, "open"); |
|
2770 |
goto ancestorerr; |
|
2771 |
} |
|
2772 |
||
2773 |
if (zfs_mount(h, NULL, 0) != 0) { |
|
2774 |
opname = dgettext(TEXT_DOMAIN, "mount"); |
|
2775 |
goto ancestorerr; |
|
2776 |
} |
|
2777 |
||
2778 |
if (zfs_share(h) != 0) { |
|
2779 |
opname = dgettext(TEXT_DOMAIN, "share"); |
|
2780 |
goto ancestorerr; |
|
2781 |
} |
|
2782 |
||
2783 |
zfs_close(h); |
|
2784 |
} |
|
2785 |
||
2786 |
return (0); |
|
2787 |
||
2788 |
ancestorerr: |
|
2789 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2790 |
"failed to %s ancestor '%s'"), opname, target); |
|
2791 |
return (-1); |
|
2792 |
} |
|
2793 |
||
2794 |
/* |
|
4490 | 2795 |
* Creates non-existing ancestors of the given path. |
2796 |
*/ |
|
2797 |
int |
|
2798 |
zfs_create_ancestors(libzfs_handle_t *hdl, const char *path) |
|
2799 |
{ |
|
2800 |
int prefix; |
|
2801 |
uint64_t zoned; |
|
2802 |
char *path_copy; |
|
2803 |
int rc; |
|
2804 |
||
2805 |
if (check_parents(hdl, path, &zoned, B_TRUE, &prefix) != 0) |
|
2806 |
return (-1); |
|
2807 |
||
2808 |
if ((path_copy = strdup(path)) != NULL) { |
|
2809 |
rc = create_parents(hdl, path_copy, prefix); |
|
2810 |
free(path_copy); |
|
2811 |
} |
|
2812 |
if (path_copy == NULL || rc != 0) |
|
2813 |
return (-1); |
|
2814 |
||
789 | 2815 |
return (0); |
2816 |
} |
|
2817 |
||
2818 |
/* |
|
2676 | 2819 |
* Create a new filesystem or volume. |
789 | 2820 |
*/ |
2821 |
int |
|
2082 | 2822 |
zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type, |
2676 | 2823 |
nvlist_t *props) |
789 | 2824 |
{ |
2825 |
zfs_cmd_t zc = { 0 }; |
|
2826 |
int ret; |
|
2827 |
uint64_t size = 0; |
|
2828 |
uint64_t blocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE); |
|
2082 | 2829 |
char errbuf[1024]; |
2676 | 2830 |
uint64_t zoned; |
2082 | 2831 |
|
2832 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2833 |
"cannot create '%s'"), path); |
|
789 | 2834 |
|
2835 |
/* validate the path, taking care to note the extended error message */ |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
2836 |
if (!zfs_validate_name(hdl, path, type, B_TRUE)) |
2082 | 2837 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
789 | 2838 |
|
2839 |
/* validate parents exist */ |
|
4490 | 2840 |
if (check_parents(hdl, path, &zoned, B_FALSE, NULL) != 0) |
789 | 2841 |
return (-1); |
2842 |
||
2843 |
/* |
|
2844 |
* The failure modes when creating a dataset of a different type over |
|
2845 |
* one that already exists is a little strange. In particular, if you |
|
2846 |
* try to create a dataset on top of an existing dataset, the ioctl() |
|
2847 |
* will return ENOENT, not EEXIST. To prevent this from happening, we |
|
2848 |
* first try to see if the dataset exists. |
|
2849 |
*/ |
|
2850 |
(void) strlcpy(zc.zc_name, path, sizeof (zc.zc_name)); |
|
5094 | 2851 |
if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
2082 | 2852 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2853 |
"dataset already exists")); |
|
2854 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
789 | 2855 |
} |
2856 |
||
2857 |
if (type == ZFS_TYPE_VOLUME) |
|
2858 |
zc.zc_objset_type = DMU_OST_ZVOL; |
|
2859 |
else |
|
2860 |
zc.zc_objset_type = DMU_OST_ZFS; |
|
2861 |
||
5094 | 2862 |
if (props && (props = zfs_validate_properties(hdl, type, props, |
3912 | 2863 |
zoned, NULL, errbuf)) == 0) |
2676 | 2864 |
return (-1); |
2865 |
||
789 | 2866 |
if (type == ZFS_TYPE_VOLUME) { |
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2867 |
/* |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2868 |
* If we are creating a volume, the size and block size must |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2869 |
* satisfy a few restraints. First, the blocksize must be a |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2870 |
* valid block size between SPA_{MIN,MAX}BLOCKSIZE. Second, the |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2871 |
* volsize must be a multiple of the block size, and cannot be |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2872 |
* zero. |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2873 |
*/ |
2676 | 2874 |
if (props == NULL || nvlist_lookup_uint64(props, |
2875 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE), &size) != 0) { |
|
2876 |
nvlist_free(props); |
|
2082 | 2877 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2676 | 2878 |
"missing volume size")); |
2879 |
return (zfs_error(hdl, EZFS_BADPROP, errbuf)); |
|
789 | 2880 |
} |
2881 |
||
2676 | 2882 |
if ((ret = nvlist_lookup_uint64(props, |
2883 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), |
|
2884 |
&blocksize)) != 0) { |
|
2885 |
if (ret == ENOENT) { |
|
2886 |
blocksize = zfs_prop_default_numeric( |
|
2887 |
ZFS_PROP_VOLBLOCKSIZE); |
|
2888 |
} else { |
|
2889 |
nvlist_free(props); |
|
2890 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2891 |
"missing volume block size")); |
|
2892 |
return (zfs_error(hdl, EZFS_BADPROP, errbuf)); |
|
2893 |
} |
|
2894 |
} |
|
2895 |
||
2896 |
if (size == 0) { |
|
2897 |
nvlist_free(props); |
|
2082 | 2898 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2676 | 2899 |
"volume size cannot be zero")); |
2900 |
return (zfs_error(hdl, EZFS_BADPROP, errbuf)); |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2901 |
} |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2902 |
|
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2903 |
if (size % blocksize != 0) { |
2676 | 2904 |
nvlist_free(props); |
2082 | 2905 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2676 | 2906 |
"volume size must be a multiple of volume block " |
2907 |
"size")); |
|
2908 |
return (zfs_error(hdl, EZFS_BADPROP, errbuf)); |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
1003
diff
changeset
|
2909 |
} |
789 | 2910 |
} |
2911 |
||
5094 | 2912 |
if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0) |
2676 | 2913 |
return (-1); |
2914 |
nvlist_free(props); |
|
2915 |
||
789 | 2916 |
/* create the dataset */ |
4543 | 2917 |
ret = zfs_ioctl(hdl, ZFS_IOC_CREATE, &zc); |
789 | 2918 |
|
3912 | 2919 |
if (ret == 0 && type == ZFS_TYPE_VOLUME) { |
2082 | 2920 |
ret = zvol_create_link(hdl, path); |
3912 | 2921 |
if (ret) { |
2922 |
(void) zfs_standard_error(hdl, errno, |
|
2923 |
dgettext(TEXT_DOMAIN, |
|
2924 |
"Volume successfully created, but device links " |
|
2925 |
"were not created")); |
|
2926 |
zcmd_free_nvlists(&zc); |
|
2927 |
return (-1); |
|
2928 |
} |
|
2929 |
} |
|
789 | 2930 |
|
2676 | 2931 |
zcmd_free_nvlists(&zc); |
2932 |
||
789 | 2933 |
/* check for failure */ |
2934 |
if (ret != 0) { |
|
2935 |
char parent[ZFS_MAXNAMELEN]; |
|
2936 |
(void) parent_name(path, parent, sizeof (parent)); |
|
2937 |
||
2938 |
switch (errno) { |
|
2939 |
case ENOENT: |
|
2082 | 2940 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2941 |
"no such parent '%s'"), parent); |
|
2942 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
789 | 2943 |
|
2944 |
case EINVAL: |
|
2082 | 2945 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
3413
f4cbe0204ab7
6471255 Some ZFS error messages contain spelling errors
mmusante
parents:
3377
diff
changeset
|
2946 |
"parent '%s' is not a filesystem"), parent); |
2082 | 2947 |
return (zfs_error(hdl, EZFS_BADTYPE, errbuf)); |
789 | 2948 |
|
2949 |
case EDOM: |
|
2082 | 2950 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2676 | 2951 |
"volume block size must be power of 2 from " |
2952 |
"%u to %uk"), |
|
789 | 2953 |
(uint_t)SPA_MINBLOCKSIZE, |
2954 |
(uint_t)SPA_MAXBLOCKSIZE >> 10); |
|
2082 | 2955 |
|
2676 | 2956 |
return (zfs_error(hdl, EZFS_BADPROP, errbuf)); |
2082 | 2957 |
|
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4597
diff
changeset
|
2958 |
case ENOTSUP: |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4597
diff
changeset
|
2959 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4597
diff
changeset
|
2960 |
"pool must be upgraded to set this " |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4597
diff
changeset
|
2961 |
"property or value")); |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4597
diff
changeset
|
2962 |
return (zfs_error(hdl, EZFS_BADVERSION, errbuf)); |
789 | 2963 |
#ifdef _ILP32 |
2964 |
case EOVERFLOW: |
|
2965 |
/* |
|
2966 |
* This platform can't address a volume this big. |
|
2967 |
*/ |
|
2082 | 2968 |
if (type == ZFS_TYPE_VOLUME) |
2969 |
return (zfs_error(hdl, EZFS_VOLTOOBIG, |
|
2970 |
errbuf)); |
|
789 | 2971 |
#endif |
2082 | 2972 |
/* FALLTHROUGH */ |
789 | 2973 |
default: |
2082 | 2974 |
return (zfs_standard_error(hdl, errno, errbuf)); |
789 | 2975 |
} |
2976 |
} |
|
2977 |
||
2978 |
return (0); |
|
2979 |
} |
|
2980 |
||
2981 |
/* |
|
2982 |
* Destroys the given dataset. The caller must make sure that the filesystem |
|
2983 |
* isn't mounted, and that there are no active dependents. |
|
2984 |
*/ |
|
2985 |
int |
|
2986 |
zfs_destroy(zfs_handle_t *zhp) |
|
2987 |
{ |
|
2988 |
zfs_cmd_t zc = { 0 }; |
|
2989 |
||
2990 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
2991 |
||
2676 | 2992 |
if (ZFS_IS_VOLUME(zhp)) { |
3126 | 2993 |
/* |
4543 | 2994 |
* If user doesn't have permissions to unshare volume, then |
2995 |
* abort the request. This would only happen for a |
|
2996 |
* non-privileged user. |
|
3126 | 2997 |
*/ |
4543 | 2998 |
if (zfs_unshare_iscsi(zhp) != 0) { |
2999 |
return (-1); |
|
3000 |
} |
|
3126 | 3001 |
|
2082 | 3002 |
if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0) |
789 | 3003 |
return (-1); |
3004 |
||
3005 |
zc.zc_objset_type = DMU_OST_ZVOL; |
|
3006 |
} else { |
|
3007 |
zc.zc_objset_type = DMU_OST_ZFS; |
|
3008 |
} |
|
3009 |
||
4543 | 3010 |
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY, &zc) != 0) { |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
3011 |
return (zfs_standard_error_fmt(zhp->zfs_hdl, errno, |
2082 | 3012 |
dgettext(TEXT_DOMAIN, "cannot destroy '%s'"), |
3013 |
zhp->zfs_name)); |
|
2199 | 3014 |
} |
789 | 3015 |
|
3016 |
remove_mountpoint(zhp); |
|
3017 |
||
3018 |
return (0); |
|
3019 |
} |
|
3020 |
||
2199 | 3021 |
struct destroydata { |
3022 |
char *snapname; |
|
3023 |
boolean_t gotone; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3024 |
boolean_t closezhp; |
2199 | 3025 |
}; |
3026 |
||
3027 |
static int |
|
3028 |
zfs_remove_link_cb(zfs_handle_t *zhp, void *arg) |
|
3029 |
{ |
|
3030 |
struct destroydata *dd = arg; |
|
3031 |
zfs_handle_t *szhp; |
|
3032 |
char name[ZFS_MAXNAMELEN]; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3033 |
boolean_t closezhp = dd->closezhp; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3034 |
int rv; |
2199 | 3035 |
|
2676 | 3036 |
(void) strlcpy(name, zhp->zfs_name, sizeof (name)); |
3037 |
(void) strlcat(name, "@", sizeof (name)); |
|
3038 |
(void) strlcat(name, dd->snapname, sizeof (name)); |
|
2199 | 3039 |
|
3040 |
szhp = make_dataset_handle(zhp->zfs_hdl, name); |
|
3041 |
if (szhp) { |
|
3042 |
dd->gotone = B_TRUE; |
|
3043 |
zfs_close(szhp); |
|
3044 |
} |
|
3045 |
||
3046 |
if (zhp->zfs_type == ZFS_TYPE_VOLUME) { |
|
3047 |
(void) zvol_remove_link(zhp->zfs_hdl, name); |
|
3048 |
/* |
|
3049 |
* NB: this is simply a best-effort. We don't want to |
|
3050 |
* return an error, because then we wouldn't visit all |
|
3051 |
* the volumes. |
|
3052 |
*/ |
|
3053 |
} |
|
3054 |
||
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3055 |
dd->closezhp = B_TRUE; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3056 |
rv = zfs_iter_filesystems(zhp, zfs_remove_link_cb, arg); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3057 |
if (closezhp) |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3058 |
zfs_close(zhp); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3059 |
return (rv); |
2199 | 3060 |
} |
3061 |
||
3062 |
/* |
|
3063 |
* Destroys all snapshots with the given name in zhp & descendants. |
|
3064 |
*/ |
|
3065 |
int |
|
3066 |
zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname) |
|
3067 |
{ |
|
3068 |
zfs_cmd_t zc = { 0 }; |
|
3069 |
int ret; |
|
3070 |
struct destroydata dd = { 0 }; |
|
3071 |
||
3072 |
dd.snapname = snapname; |
|
3073 |
(void) zfs_remove_link_cb(zhp, &dd); |
|
3074 |
||
3075 |
if (!dd.gotone) { |
|
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
3076 |
return (zfs_standard_error_fmt(zhp->zfs_hdl, ENOENT, |
2199 | 3077 |
dgettext(TEXT_DOMAIN, "cannot destroy '%s@%s'"), |
3078 |
zhp->zfs_name, snapname)); |
|
3079 |
} |
|
3080 |
||
3081 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
2676 | 3082 |
(void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value)); |
2199 | 3083 |
|
4543 | 3084 |
ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS, &zc); |
2199 | 3085 |
if (ret != 0) { |
3086 |
char errbuf[1024]; |
|
3087 |
||
3088 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
3089 |
"cannot destroy '%s@%s'"), zc.zc_name, snapname); |
|
3090 |
||
3091 |
switch (errno) { |
|
3092 |
case EEXIST: |
|
3093 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
|
3094 |
"snapshot is cloned")); |
|
3095 |
return (zfs_error(zhp->zfs_hdl, EZFS_EXISTS, errbuf)); |
|
3096 |
||
3097 |
default: |
|
3098 |
return (zfs_standard_error(zhp->zfs_hdl, errno, |
|
3099 |
errbuf)); |
|
3100 |
} |
|
3101 |
} |
|
3102 |
||
3103 |
return (0); |
|
3104 |
} |
|
3105 |
||
789 | 3106 |
/* |
3107 |
* Clones the given dataset. The target must be of the same type as the source. |
|
3108 |
*/ |
|
3109 |
int |
|
2676 | 3110 |
zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props) |
789 | 3111 |
{ |
3112 |
zfs_cmd_t zc = { 0 }; |
|
3113 |
char parent[ZFS_MAXNAMELEN]; |
|
3114 |
int ret; |
|
2082 | 3115 |
char errbuf[1024]; |
3116 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
2676 | 3117 |
zfs_type_t type; |
3118 |
uint64_t zoned; |
|
789 | 3119 |
|
3120 |
assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); |
|
3121 |
||
2082 | 3122 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
3123 |
"cannot create '%s'"), target); |
|
3124 |
||
789 | 3125 |
/* validate the target name */ |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
3126 |
if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM, B_TRUE)) |
2082 | 3127 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
789 | 3128 |
|
3129 |
/* validate parents exist */ |
|
4490 | 3130 |
if (check_parents(hdl, target, &zoned, B_FALSE, NULL) != 0) |
789 | 3131 |
return (-1); |
3132 |
||
3133 |
(void) parent_name(target, parent, sizeof (parent)); |
|
3134 |
||
3135 |
/* do the clone */ |
|
2676 | 3136 |
if (ZFS_IS_VOLUME(zhp)) { |
789 | 3137 |
zc.zc_objset_type = DMU_OST_ZVOL; |
2744
0a6f00b6a209
6468554 zone install with a zfs zonepath could not create a dataset
nn35248
parents:
2676
diff
changeset
|
3138 |
type = ZFS_TYPE_VOLUME; |
2676 | 3139 |
} else { |
789 | 3140 |
zc.zc_objset_type = DMU_OST_ZFS; |
2744
0a6f00b6a209
6468554 zone install with a zfs zonepath could not create a dataset
nn35248
parents:
2676
diff
changeset
|
3141 |
type = ZFS_TYPE_FILESYSTEM; |
2676 | 3142 |
} |
3143 |
||
3144 |
if (props) { |
|
5094 | 3145 |
if ((props = zfs_validate_properties(hdl, type, props, |
3912 | 3146 |
zoned, zhp, errbuf)) == NULL) |
2676 | 3147 |
return (-1); |
3148 |
||
5094 | 3149 |
if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) { |
2676 | 3150 |
nvlist_free(props); |
3151 |
return (-1); |
|
3152 |
} |
|
3153 |
||
3154 |
nvlist_free(props); |
|
3155 |
} |
|
789 | 3156 |
|
3157 |
(void) strlcpy(zc.zc_name, target, sizeof (zc.zc_name)); |
|
2676 | 3158 |
(void) strlcpy(zc.zc_value, zhp->zfs_name, sizeof (zc.zc_value)); |
4543 | 3159 |
ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_CREATE, &zc); |
789 | 3160 |
|
2676 | 3161 |
zcmd_free_nvlists(&zc); |
3162 |
||
789 | 3163 |
if (ret != 0) { |
3164 |
switch (errno) { |
|
3165 |
||
3166 |
case ENOENT: |
|
3167 |
/* |
|
3168 |
* The parent doesn't exist. We should have caught this |
|
3169 |
* above, but there may a race condition that has since |
|
3170 |
* destroyed the parent. |
|
3171 |
* |
|
3172 |
* At this point, we don't know whether it's the source |
|
3173 |
* that doesn't exist anymore, or whether the target |
|
3174 |
* dataset doesn't exist. |
|
3175 |
*/ |
|
2082 | 3176 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
3177 |
"no such parent '%s'"), parent); |
|
3178 |
return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf)); |
|
3179 |
||
3180 |
case EXDEV: |
|
3181 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
|
3182 |
"source and target pools differ")); |
|
3183 |
return (zfs_error(zhp->zfs_hdl, EZFS_CROSSTARGET, |
|
3184 |
errbuf)); |
|
3185 |
||
3186 |
default: |
|
3187 |
return (zfs_standard_error(zhp->zfs_hdl, errno, |
|
3188 |
errbuf)); |
|
3189 |
} |
|
2676 | 3190 |
} else if (ZFS_IS_VOLUME(zhp)) { |
2082 | 3191 |
ret = zvol_create_link(zhp->zfs_hdl, target); |
3192 |
} |
|
3193 |
||
3194 |
return (ret); |
|
3195 |
} |
|
3196 |
||
3197 |
typedef struct promote_data { |
|
3198 |
char cb_mountpoint[MAXPATHLEN]; |
|
3199 |
const char *cb_target; |
|
3200 |
const char *cb_errbuf; |
|
3201 |
uint64_t cb_pivot_txg; |
|
3202 |
} promote_data_t; |
|
3203 |
||
3204 |
static int |
|
3205 |
promote_snap_cb(zfs_handle_t *zhp, void *data) |
|
3206 |
{ |
|
3207 |
promote_data_t *pd = data; |
|
3208 |
zfs_handle_t *szhp; |
|
3209 |
char snapname[MAXPATHLEN]; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3210 |
int rv = 0; |
2082 | 3211 |
|
3212 |
/* We don't care about snapshots after the pivot point */ |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3213 |
if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > pd->cb_pivot_txg) { |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3214 |
zfs_close(zhp); |
2082 | 3215 |
return (0); |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3216 |
} |
2082 | 3217 |
|
2417 | 3218 |
/* Remove the device link if it's a zvol. */ |
2676 | 3219 |
if (ZFS_IS_VOLUME(zhp)) |
2417 | 3220 |
(void) zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name); |
2082 | 3221 |
|
3222 |
/* Check for conflicting names */ |
|
2676 | 3223 |
(void) strlcpy(snapname, pd->cb_target, sizeof (snapname)); |
3224 |
(void) strlcat(snapname, strchr(zhp->zfs_name, '@'), sizeof (snapname)); |
|
2082 | 3225 |
szhp = make_dataset_handle(zhp->zfs_hdl, snapname); |
3226 |
if (szhp != NULL) { |
|
3227 |
zfs_close(szhp); |
|
3228 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
|
3229 |
"snapshot name '%s' from origin \n" |
|
3230 |
"conflicts with '%s' from target"), |
|
3231 |
zhp->zfs_name, snapname); |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3232 |
rv = zfs_error(zhp->zfs_hdl, EZFS_EXISTS, pd->cb_errbuf); |
2082 | 3233 |
} |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3234 |
zfs_close(zhp); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3235 |
return (rv); |
2082 | 3236 |
} |
3237 |
||
2417 | 3238 |
static int |
3239 |
promote_snap_done_cb(zfs_handle_t *zhp, void *data) |
|
3240 |
{ |
|
3241 |
promote_data_t *pd = data; |
|
3242 |
||
3243 |
/* We don't care about snapshots after the pivot point */ |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3244 |
if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) <= pd->cb_pivot_txg) { |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3245 |
/* Create the device link if it's a zvol. */ |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3246 |
if (ZFS_IS_VOLUME(zhp)) |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3247 |
(void) zvol_create_link(zhp->zfs_hdl, zhp->zfs_name); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3248 |
} |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3249 |
|
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3237
diff
changeset
|
3250 |
zfs_close(zhp); |
2417 | 3251 |
return (0); |
3252 |
} |
|
3253 |
||
2082 | 3254 |
/* |
3255 |
* Promotes the given clone fs to be the clone parent. |
|
3256 |
*/ |
|
3257 |
int |
|
3258 |
zfs_promote(zfs_handle_t *zhp) |
|
3259 |
{ |
|
3260 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
3261 |
zfs_cmd_t zc = { 0 }; |
|
3262 |
char parent[MAXPATHLEN]; |
|
3263 |
char *cp; |
|
3264 |
int ret; |
|
3265 |
zfs_handle_t *pzhp; |
|
3266 |
promote_data_t pd; |
|
3267 |
char errbuf[1024]; |
|
3268 |
||
3269 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
3270 |
"cannot promote '%s'"), zhp->zfs_name); |
|
3271 |
||
3272 |
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) { |
|
3273 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3274 |
"snapshots can not be promoted")); |
|
3275 |
return (zfs_error(hdl, EZFS_BADTYPE, errbuf)); |
|
3276 |
} |
|
3277 |
||
5367 | 3278 |
(void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent)); |
2082 | 3279 |
if (parent[0] == '\0') { |
3280 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3281 |
"not a cloned filesystem")); |
|
3282 |
return (zfs_error(hdl, EZFS_BADTYPE, errbuf)); |
|
3283 |
} |
|
3284 |
cp = strchr(parent, '@'); |
|
3285 |
*cp = '\0'; |
|
3286 |
||
3287 |
/* Walk the snapshots we will be moving */ |
|
5367 | 3288 |
pzhp = zfs_open(hdl, zhp->zfs_dmustats.dds_origin, ZFS_TYPE_SNAPSHOT); |
2082 | 3289 |
if (pzhp == NULL) |
3290 |
return (-1); |
|
3291 |
pd.cb_pivot_txg = zfs_prop_get_int(pzhp, ZFS_PROP_CREATETXG); |
|
3292 |
zfs_close(pzhp); |
|
3293 |
pd.cb_target = zhp->zfs_name; |
|
3294 |
pd.cb_errbuf = errbuf; |
|
5094 | 3295 |
pzhp = zfs_open(hdl, parent, ZFS_TYPE_DATASET); |
2082 | 3296 |
if (pzhp == NULL) |
3297 |
return (-1); |
|
3298 |
(void) zfs_prop_get(pzhp, ZFS_PROP_MOUNTPOINT, pd.cb_mountpoint, |
|
3299 |
sizeof (pd.cb_mountpoint), NULL, NULL, 0, FALSE); |
|
3300 |
ret = zfs_iter_snapshots(pzhp, promote_snap_cb, &pd); |
|
2417 | 3301 |
if (ret != 0) { |
3302 |
zfs_close(pzhp); |
|
2082 | 3303 |
return (-1); |
2417 | 3304 |
} |
2082 | 3305 |
|
3306 |
/* issue the ioctl */ |
|
5367 | 3307 |
(void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin, |
2676 | 3308 |
sizeof (zc.zc_value)); |
2082 | 3309 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
4543 | 3310 |
ret = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc); |
2082 | 3311 |
|
3312 |
if (ret != 0) { |
|
2417 | 3313 |
int save_errno = errno; |
3314 |
||
3315 |
(void) zfs_iter_snapshots(pzhp, promote_snap_done_cb, &pd); |
|
3316 |
zfs_close(pzhp); |
|
3317 |
||
3318 |
switch (save_errno) { |
|
789 | 3319 |
case EEXIST: |
3320 |
/* |
|
2082 | 3321 |
* There is a conflicting snapshot name. We |
3322 |
* should have caught this above, but they could |
|
3323 |
* have renamed something in the mean time. |
|
789 | 3324 |
*/ |
2082 | 3325 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
3326 |
"conflicting snapshot name from parent '%s'"), |
|
3327 |
parent); |
|
3328 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
789 | 3329 |
|
3330 |
default: |
|
2417 | 3331 |
return (zfs_standard_error(hdl, save_errno, errbuf)); |
789 | 3332 |
} |
2417 | 3333 |
} else { |
3334 |
(void) zfs_iter_snapshots(zhp, promote_snap_done_cb, &pd); |
|
789 | 3335 |
} |
3336 |
||
2417 | 3337 |
zfs_close(pzhp); |
789 | 3338 |
return (ret); |
3339 |
} |
|
3340 |
||
4007 | 3341 |
struct createdata { |
3342 |
const char *cd_snapname; |
|
3343 |
int cd_ifexists; |
|
3344 |
}; |
|
3345 |
||
2199 | 3346 |
static int |
3347 |
zfs_create_link_cb(zfs_handle_t *zhp, void *arg) |
|
3348 |
{ |
|
4007 | 3349 |
struct createdata *cd = arg; |
2676 | 3350 |
int ret; |
2199 | 3351 |
|
3352 |
if (zhp->zfs_type == ZFS_TYPE_VOLUME) { |
|
3353 |
char name[MAXPATHLEN]; |
|
3354 |
||
2676 | 3355 |
(void) strlcpy(name, zhp->zfs_name, sizeof (name)); |
3356 |
(void) strlcat(name, "@", sizeof (name)); |
|
4007 | 3357 |
(void) strlcat(name, cd->cd_snapname, sizeof (name)); |
3358 |
(void) zvol_create_link_common(zhp->zfs_hdl, name, |
|
3359 |
cd->cd_ifexists); |
|
2199 | 3360 |
/* |
3361 |
* NB: this is simply a best-effort. We don't want to |
|
3362 |
* return an error, because then we wouldn't visit all |
|
3363 |
* the volumes. |
|
3364 |
*/ |
|
3365 |
} |
|
2676 | 3366 |
|
4007 | 3367 |
ret = zfs_iter_filesystems(zhp, zfs_create_link_cb, cd); |
2676 | 3368 |
|
3369 |
zfs_close(zhp); |
|
3370 |
||
3371 |
return (ret); |
|
2199 | 3372 |
} |
3373 |
||
789 | 3374 |
/* |
3504
6eb2466ff1c9
6516175 zfs_send()/zfs_receive() should take file descriptor arguments
ahl
parents:
3443
diff
changeset
|
3375 |
* Takes a snapshot of the given dataset. |
789 | 3376 |
*/ |
3377 |
int |
|
2199 | 3378 |
zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive) |
789 | 3379 |
{ |
3380 |
const char *delim; |
|
3381 |
char *parent; |
|
3382 |
zfs_handle_t *zhp; |
|
3383 |
zfs_cmd_t zc = { 0 }; |
|
3384 |
int ret; |
|
2082 | 3385 |
char errbuf[1024]; |
3386 |
||
3387 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
3388 |
"cannot snapshot '%s'"), path); |
|
3389 |
||
3390 |
/* validate the target name */ |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
3391 |
if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT, B_TRUE)) |
2082 | 3392 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
789 | 3393 |
|
3394 |
/* make sure the parent exists and is of the appropriate type */ |
|
2199 | 3395 |
delim = strchr(path, '@'); |
2082 | 3396 |
if ((parent = zfs_alloc(hdl, delim - path + 1)) == NULL) |
3397 |
return (-1); |
|
789 | 3398 |
(void) strncpy(parent, path, delim - path); |
3399 |
parent[delim - path] = '\0'; |
|
3400 |
||
2082 | 3401 |
if ((zhp = zfs_open(hdl, parent, ZFS_TYPE_FILESYSTEM | |
789 | 3402 |
ZFS_TYPE_VOLUME)) == NULL) { |
3403 |
free(parent); |
|
3404 |
return (-1); |
|
3405 |
} |
|
3406 |
||
2199 | 3407 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
2676 | 3408 |
(void) strlcpy(zc.zc_value, delim+1, sizeof (zc.zc_value)); |
4543 | 3409 |
if (ZFS_IS_VOLUME(zhp)) |
3410 |
zc.zc_objset_type = DMU_OST_ZVOL; |
|
3411 |
else |
|
3412 |
zc.zc_objset_type = DMU_OST_ZFS; |
|
2199 | 3413 |
zc.zc_cookie = recursive; |
4543 | 3414 |
ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SNAPSHOT, &zc); |
2199 | 3415 |
|
3416 |
/* |
|
3417 |
* if it was recursive, the one that actually failed will be in |
|
3418 |
* zc.zc_name. |
|
3419 |
*/ |
|
4543 | 3420 |
if (ret != 0) |
3421 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
3422 |
"cannot create snapshot '%s@%s'"), zc.zc_name, zc.zc_value); |
|
3423 |
||
2199 | 3424 |
if (ret == 0 && recursive) { |
4007 | 3425 |
struct createdata cd; |
3426 |
||
3427 |
cd.cd_snapname = delim + 1; |
|
3428 |
cd.cd_ifexists = B_FALSE; |
|
3429 |
(void) zfs_iter_filesystems(zhp, zfs_create_link_cb, &cd); |
|
2199 | 3430 |
} |
789 | 3431 |
if (ret == 0 && zhp->zfs_type == ZFS_TYPE_VOLUME) { |
2082 | 3432 |
ret = zvol_create_link(zhp->zfs_hdl, path); |
2199 | 3433 |
if (ret != 0) { |
4543 | 3434 |
(void) zfs_standard_error(hdl, errno, |
3435 |
dgettext(TEXT_DOMAIN, |
|
3436 |
"Volume successfully snapshotted, but device links " |
|
3437 |
"were not created")); |
|
3438 |
free(parent); |
|
3439 |
zfs_close(zhp); |
|
3440 |
return (-1); |
|
2199 | 3441 |
} |
789 | 3442 |
} |
3443 |
||
2082 | 3444 |
if (ret != 0) |
3445 |
(void) zfs_standard_error(hdl, errno, errbuf); |
|
789 | 3446 |
|
3447 |
free(parent); |
|
3448 |
zfs_close(zhp); |
|
3449 |
||
3450 |
return (ret); |
|
3451 |
} |
|
3452 |
||
3453 |
/* |
|
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3454 |
* Destroy any more recent snapshots. We invoke this callback on any dependents |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3455 |
* of the snapshot first. If the 'cb_dependent' member is non-zero, then this |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3456 |
* is a dependent and we should just destroy it without checking the transaction |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3457 |
* group. |
789 | 3458 |
*/ |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3459 |
typedef struct rollback_data { |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3460 |
const char *cb_target; /* the snapshot */ |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3461 |
uint64_t cb_create; /* creation time reference */ |
5749 | 3462 |
boolean_t cb_error; |
2082 | 3463 |
boolean_t cb_dependent; |
5749 | 3464 |
boolean_t cb_force; |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3465 |
} rollback_data_t; |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3466 |
|
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3467 |
static int |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3468 |
rollback_destroy(zfs_handle_t *zhp, void *data) |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3469 |
{ |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3470 |
rollback_data_t *cbp = data; |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3471 |
|
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3472 |
if (!cbp->cb_dependent) { |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3473 |
if (strcmp(zhp->zfs_name, cbp->cb_target) != 0 && |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3474 |
zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT && |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3475 |
zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3476 |
cbp->cb_create) { |
4543 | 3477 |
char *logstr; |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3478 |
|
2082 | 3479 |
cbp->cb_dependent = B_TRUE; |
5446 | 3480 |
cbp->cb_error |= zfs_iter_dependents(zhp, B_FALSE, |
3481 |
rollback_destroy, cbp); |
|
2082 | 3482 |
cbp->cb_dependent = B_FALSE; |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3483 |
|
4543 | 3484 |
logstr = zhp->zfs_hdl->libzfs_log_str; |
3485 |
zhp->zfs_hdl->libzfs_log_str = NULL; |
|
5446 | 3486 |
cbp->cb_error |= zfs_destroy(zhp); |
4543 | 3487 |
zhp->zfs_hdl->libzfs_log_str = logstr; |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3488 |
} |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3489 |
} else { |
5749 | 3490 |
/* We must destroy this clone; first unmount it */ |
3491 |
prop_changelist_t *clp; |
|
3492 |
||
3493 |
clp = changelist_gather(zhp, ZFS_PROP_NAME, |
|
3494 |
cbp->cb_force ? MS_FORCE: 0); |
|
3495 |
if (clp == NULL || changelist_prefix(clp) != 0) { |
|
3496 |
cbp->cb_error = B_TRUE; |
|
3497 |
zfs_close(zhp); |
|
3498 |
return (0); |
|
3499 |
} |
|
3500 |
if (zfs_destroy(zhp) != 0) |
|
3501 |
cbp->cb_error = B_TRUE; |
|
3502 |
else |
|
3503 |
changelist_remove(clp, zhp->zfs_name); |
|
5751
86c712b1b536
6641210 zfs rollback -R fails with EBUSY if there is a clone (fix lint)
ahrens
parents:
5749
diff
changeset
|
3504 |
(void) changelist_postfix(clp); |
5749 | 3505 |
changelist_free(clp); |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3506 |
} |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3507 |
|
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3508 |
zfs_close(zhp); |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3509 |
return (0); |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3510 |
} |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3511 |
|
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3512 |
/* |
5446 | 3513 |
* Given a dataset, rollback to a specific snapshot, discarding any |
3514 |
* data changes since then and making it the active dataset. |
|
3515 |
* |
|
3516 |
* Any snapshots more recent than the target are destroyed, along with |
|
3517 |
* their dependents. |
|
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3518 |
*/ |
5446 | 3519 |
int |
5749 | 3520 |
zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) |
789 | 3521 |
{ |
5446 | 3522 |
rollback_data_t cb = { 0 }; |
3523 |
int err; |
|
789 | 3524 |
zfs_cmd_t zc = { 0 }; |
5713 | 3525 |
boolean_t restore_resv = 0; |
3526 |
uint64_t old_volsize, new_volsize; |
|
3527 |
zfs_prop_t resv_prop; |
|
789 | 3528 |
|
3529 |
assert(zhp->zfs_type == ZFS_TYPE_FILESYSTEM || |
|
3530 |
zhp->zfs_type == ZFS_TYPE_VOLUME); |
|
3531 |
||
5446 | 3532 |
/* |
3533 |
* Destroy all recent snapshots and its dependends. |
|
3534 |
*/ |
|
5749 | 3535 |
cb.cb_force = force; |
5446 | 3536 |
cb.cb_target = snap->zfs_name; |
3537 |
cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG); |
|
3538 |
(void) zfs_iter_children(zhp, rollback_destroy, &cb); |
|
3539 |
||
5749 | 3540 |
if (cb.cb_error) |
3541 |
return (-1); |
|
5446 | 3542 |
|
3543 |
/* |
|
3544 |
* Now that we have verified that the snapshot is the latest, |
|
3545 |
* rollback to the given snapshot. |
|
3546 |
*/ |
|
3547 |
||
5713 | 3548 |
if (zhp->zfs_type == ZFS_TYPE_VOLUME) { |
3549 |
if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0) |
|
3550 |
return (-1); |
|
3551 |
if (zfs_which_resv_prop(zhp, &resv_prop) < 0) |
|
3552 |
return (-1); |
|
3553 |
old_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE); |
|
3554 |
restore_resv = |
|
3555 |
(old_volsize == zfs_prop_get_int(zhp, resv_prop)); |
|
3556 |
} |
|
789 | 3557 |
|
3558 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
3559 |
||
2676 | 3560 |
if (ZFS_IS_VOLUME(zhp)) |
789 | 3561 |
zc.zc_objset_type = DMU_OST_ZVOL; |
3562 |
else |
|
3563 |
zc.zc_objset_type = DMU_OST_ZFS; |
|
3564 |
||
3565 |
/* |
|
5446 | 3566 |
* We rely on zfs_iter_children() to verify that there are no |
3567 |
* newer snapshots for the given dataset. Therefore, we can |
|
3568 |
* simply pass the name on to the ioctl() call. There is still |
|
3569 |
* an unlikely race condition where the user has taken a |
|
3570 |
* snapshot since we verified that this was the most recent. |
|
5713 | 3571 |
* |
789 | 3572 |
*/ |
5446 | 3573 |
if ((err = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_ROLLBACK, &zc)) != 0) { |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
3574 |
(void) zfs_standard_error_fmt(zhp->zfs_hdl, errno, |
2082 | 3575 |
dgettext(TEXT_DOMAIN, "cannot rollback '%s'"), |
3576 |
zhp->zfs_name); |
|
5717
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3577 |
return (err); |
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3578 |
} |
5713 | 3579 |
|
3580 |
/* |
|
3581 |
* For volumes, if the pre-rollback volsize matched the pre- |
|
3582 |
* rollback reservation and the volsize has changed then set |
|
3583 |
* the reservation property to the post-rollback volsize. |
|
3584 |
* Make a new handle since the rollback closed the dataset. |
|
3585 |
*/ |
|
5717
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3586 |
if ((zhp->zfs_type == ZFS_TYPE_VOLUME) && |
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3587 |
(zhp = make_dataset_handle(zhp->zfs_hdl, zhp->zfs_name))) { |
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3588 |
if (err = zvol_create_link(zhp->zfs_hdl, zhp->zfs_name)) { |
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3589 |
zfs_close(zhp); |
5713 | 3590 |
return (err); |
5717
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3591 |
} |
5713 | 3592 |
if (restore_resv) { |
3593 |
new_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE); |
|
3594 |
if (old_volsize != new_volsize) |
|
5717
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3595 |
err = zfs_prop_set_int(zhp, resv_prop, |
b163be0bb014
6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents:
5713
diff
changeset
|
3596 |
new_volsize); |
5713 | 3597 |
} |
3598 |
zfs_close(zhp); |
|
789 | 3599 |
} |
5446 | 3600 |
return (err); |
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3601 |
} |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3602 |
|
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1175
diff
changeset
|
3603 |
/* |
789 | 3604 |
* Iterate over all dependents for a given dataset. This includes both |
3605 |
* hierarchical dependents (children) and data dependents (snapshots and |
|
3606 |
* clones). The bulk of the processing occurs in get_dependents() in |
|
3607 |
* libzfs_graph.c. |
|
3608 |
*/ |
|
3609 |
int |
|
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
3610 |
zfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion, |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
3611 |
zfs_iter_f func, void *data) |
789 | 3612 |
{ |
3613 |
char **dependents; |
|
3614 |
size_t count; |
|
3615 |
int i; |
|
3616 |
zfs_handle_t *child; |
|
3617 |
int ret = 0; |
|
3618 |
||
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
3619 |
if (get_dependents(zhp->zfs_hdl, allowrecursion, zhp->zfs_name, |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
3620 |
&dependents, &count) != 0) |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
3621 |
return (-1); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2440
diff
changeset
|
3622 |
|
789 | 3623 |
for (i = 0; i < count; i++) { |
2082 | 3624 |
if ((child = make_dataset_handle(zhp->zfs_hdl, |
3625 |
dependents[i])) == NULL) |
|
789 | 3626 |
continue; |
3627 |
||
3628 |
if ((ret = func(child, data)) != 0) |
|
3629 |
break; |
|
3630 |
} |
|
3631 |
||
3632 |
for (i = 0; i < count; i++) |
|
3633 |
free(dependents[i]); |
|
3634 |
free(dependents); |
|
3635 |
||
3636 |
return (ret); |
|
3637 |
} |
|
3638 |
||
3639 |
/* |
|
3640 |
* Renames the given dataset. |
|
3641 |
*/ |
|
3642 |
int |
|
4490 | 3643 |
zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive) |
789 | 3644 |
{ |
3645 |
int ret; |
|
3646 |
zfs_cmd_t zc = { 0 }; |
|
3647 |
char *delim; |
|
4007 | 3648 |
prop_changelist_t *cl = NULL; |
3649 |
zfs_handle_t *zhrp = NULL; |
|
3650 |
char *parentname = NULL; |
|
789 | 3651 |
char parent[ZFS_MAXNAMELEN]; |
2082 | 3652 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
3653 |
char errbuf[1024]; |
|
789 | 3654 |
|
3655 |
/* if we have the same exact name, just return success */ |
|
3656 |
if (strcmp(zhp->zfs_name, target) == 0) |
|
3657 |
return (0); |
|
3658 |
||
2082 | 3659 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
3660 |
"cannot rename to '%s'"), target); |
|
3661 |
||
789 | 3662 |
/* |
3663 |
* Make sure the target name is valid |
|
3664 |
*/ |
|
3665 |
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) { |
|
2665 | 3666 |
if ((strchr(target, '@') == NULL) || |
3667 |
*target == '@') { |
|
3668 |
/* |
|
3669 |
* Snapshot target name is abbreviated, |
|
3670 |
* reconstruct full dataset name |
|
3671 |
*/ |
|
3672 |
(void) strlcpy(parent, zhp->zfs_name, |
|
3673 |
sizeof (parent)); |
|
3674 |
delim = strchr(parent, '@'); |
|
3675 |
if (strchr(target, '@') == NULL) |
|
3676 |
*(++delim) = '\0'; |
|
3677 |
else |
|
3678 |
*delim = '\0'; |
|
3679 |
(void) strlcat(parent, target, sizeof (parent)); |
|
3680 |
target = parent; |
|
3681 |
} else { |
|
3682 |
/* |
|
3683 |
* Make sure we're renaming within the same dataset. |
|
3684 |
*/ |
|
3685 |
delim = strchr(target, '@'); |
|
3686 |
if (strncmp(zhp->zfs_name, target, delim - target) |
|
3687 |
!= 0 || zhp->zfs_name[delim - target] != '@') { |
|
3688 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3689 |
"snapshots must be part of same " |
|
3690 |
"dataset")); |
|
3691 |
return (zfs_error(hdl, EZFS_CROSSTARGET, |
|
3912 | 3692 |
errbuf)); |
2665 | 3693 |
} |
789 | 3694 |
} |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
3695 |
if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE)) |
2665 | 3696 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
789 | 3697 |
} else { |
4007 | 3698 |
if (recursive) { |
3699 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3700 |
"recursive rename must be a snapshot")); |
|
3701 |
return (zfs_error(hdl, EZFS_BADTYPE, errbuf)); |
|
3702 |
} |
|
3703 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
3704 |
if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE)) |
2665 | 3705 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
2676 | 3706 |
uint64_t unused; |
3707 |
||
789 | 3708 |
/* validate parents */ |
4490 | 3709 |
if (check_parents(hdl, target, &unused, B_FALSE, NULL) != 0) |
789 | 3710 |
return (-1); |
3711 |
||
3712 |
(void) parent_name(target, parent, sizeof (parent)); |
|
3713 |
||
3714 |
/* make sure we're in the same pool */ |
|
3715 |
verify((delim = strchr(target, '/')) != NULL); |
|
3716 |
if (strncmp(zhp->zfs_name, target, delim - target) != 0 || |
|
3717 |
zhp->zfs_name[delim - target] != '/') { |
|
2082 | 3718 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
3719 |
"datasets must be within same pool")); |
|
3720 |
return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); |
|
789 | 3721 |
} |
2440
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3722 |
|
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3723 |
/* new name cannot be a child of the current dataset name */ |
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3724 |
if (strncmp(parent, zhp->zfs_name, |
3912 | 3725 |
strlen(zhp->zfs_name)) == 0) { |
2440
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3726 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3727 |
"New dataset name cannot be a descendent of " |
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3728 |
"current dataset name")); |
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3729 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
9281a87e8a9e
6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents:
2417
diff
changeset
|
3730 |
} |
789 | 3731 |
} |
3732 |
||
2082 | 3733 |
(void) snprintf(errbuf, sizeof (errbuf), |
3734 |
dgettext(TEXT_DOMAIN, "cannot rename '%s'"), zhp->zfs_name); |
|
3735 |
||
789 | 3736 |
if (getzoneid() == GLOBAL_ZONEID && |
3737 |
zfs_prop_get_int(zhp, ZFS_PROP_ZONED)) { |
|
2082 | 3738 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
3739 |
"dataset is used in a non-global zone")); |
|
3740 |
return (zfs_error(hdl, EZFS_ZONED, errbuf)); |
|
789 | 3741 |
} |
3742 |
||
4007 | 3743 |
if (recursive) { |
3744 |
struct destroydata dd; |
|
3745 |
||
4183
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3746 |
parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name); |
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3747 |
if (parentname == NULL) { |
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3748 |
ret = -1; |
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3749 |
goto error; |
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3750 |
} |
4007 | 3751 |
delim = strchr(parentname, '@'); |
3752 |
*delim = '\0'; |
|
5094 | 3753 |
zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET); |
4007 | 3754 |
if (zhrp == NULL) { |
4183
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3755 |
ret = -1; |
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3756 |
goto error; |
4007 | 3757 |
} |
3758 |
||
3759 |
dd.snapname = delim + 1; |
|
3760 |
dd.gotone = B_FALSE; |
|
4183
8dbff10731ef
6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents:
4180
diff
changeset
|
3761 |
dd.closezhp = B_TRUE; |
4007 | 3762 |
|
3763 |
/* We remove any zvol links prior to renaming them */ |
|
3764 |
ret = zfs_iter_filesystems(zhrp, zfs_remove_link_cb, &dd); |
|
3765 |
if (ret) { |
|
3766 |
goto error; |
|
3767 |
} |
|
3768 |
} else { |
|
3769 |
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0)) == NULL) |
|
3770 |
return (-1); |
|
3771 |
||
3772 |
if (changelist_haszonedchild(cl)) { |
|
3773 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3774 |
"child dataset with inherited mountpoint is used " |
|
3775 |
"in a non-global zone")); |
|
3776 |
(void) zfs_error(hdl, EZFS_ZONED, errbuf); |
|
3777 |
goto error; |
|
3778 |
} |
|
3779 |
||
3780 |
if ((ret = changelist_prefix(cl)) != 0) |
|
3781 |
goto error; |
|
789 | 3782 |
} |
3783 |
||
2676 | 3784 |
if (ZFS_IS_VOLUME(zhp)) |
789 | 3785 |
zc.zc_objset_type = DMU_OST_ZVOL; |
3786 |
else |
|
3787 |
zc.zc_objset_type = DMU_OST_ZFS; |
|
3788 |
||
2665 | 3789 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
2676 | 3790 |
(void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value)); |
2665 | 3791 |
|
4007 | 3792 |
zc.zc_cookie = recursive; |
3793 |
||
4543 | 3794 |
if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_RENAME, &zc)) != 0) { |
4007 | 3795 |
/* |
3796 |
* if it was recursive, the one that actually failed will |
|
3797 |
* be in zc.zc_name |
|
3798 |
*/ |
|
3799 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
5367 | 3800 |
"cannot rename '%s'"), zc.zc_name); |
4007 | 3801 |
|
3802 |
if (recursive && errno == EEXIST) { |
|
3803 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
3804 |
"a child dataset already has a snapshot " |
|
3805 |
"with the new name")); |
|
4801
5cd7916484a5
4687827 dumpadm should be more tolerant of a read-only /etc/dumpadm.conf
eschrock
parents:
4787
diff
changeset
|
3806 |
(void) zfs_error(hdl, EZFS_EXISTS, errbuf); |
4007 | 3807 |
} else { |
3808 |
(void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf); |
|
3809 |
} |
|
789 | 3810 |
|
3811 |
/* |
|
3812 |
* On failure, we still want to remount any filesystems that |
|
3813 |
* were previously mounted, so we don't alter the system state. |
|
3814 |
*/ |
|
4007 | 3815 |
if (recursive) { |
3816 |
struct createdata cd; |
|
3817 |
||
3818 |
/* only create links for datasets that had existed */ |
|
3819 |
cd.cd_snapname = delim + 1; |
|
3820 |
cd.cd_ifexists = B_TRUE; |
|
3821 |
(void) zfs_iter_filesystems(zhrp, zfs_create_link_cb, |
|
3822 |
&cd); |
|
3823 |
} else { |
|
3824 |
(void) changelist_postfix(cl); |
|
3825 |
} |
|
789 | 3826 |
} else { |
4007 | 3827 |
if (recursive) { |
3828 |
struct createdata cd; |
|
3829 |
||
3830 |
/* only create links for datasets that had existed */ |
|
3831 |
cd.cd_snapname = strchr(target, '@') + 1; |
|
3832 |
cd.cd_ifexists = B_TRUE; |
|
3833 |
ret = zfs_iter_filesystems(zhrp, zfs_create_link_cb, |
|
3834 |
&cd); |
|
3835 |
} else { |
|
3836 |
changelist_rename(cl, zfs_get_name(zhp), target); |
|
3837 |
ret = changelist_postfix(cl); |
|
3838 |
} |
|
789 | 3839 |
} |
3840 |
||
3841 |
error: |
|
4007 | 3842 |
if (parentname) { |
3843 |
free(parentname); |
|
3844 |
} |
|
3845 |
if (zhrp) { |
|
3846 |
zfs_close(zhrp); |
|
3847 |
} |
|
3848 |
if (cl) { |
|
3849 |
changelist_free(cl); |
|
3850 |
} |
|
789 | 3851 |
return (ret); |
3852 |
} |
|
3853 |
||
3854 |
/* |
|
3855 |
* Given a zvol dataset, issue the ioctl to create the appropriate minor node, |
|
3856 |
* poke devfsadm to create the /dev link, and then wait for the link to appear. |
|
3857 |
*/ |
|
3858 |
int |
|
2082 | 3859 |
zvol_create_link(libzfs_handle_t *hdl, const char *dataset) |
789 | 3860 |
{ |
4007 | 3861 |
return (zvol_create_link_common(hdl, dataset, B_FALSE)); |
3862 |
} |
|
3863 |
||
3864 |
static int |
|
3865 |
zvol_create_link_common(libzfs_handle_t *hdl, const char *dataset, int ifexists) |
|
3866 |
{ |
|
789 | 3867 |
zfs_cmd_t zc = { 0 }; |
2082 | 3868 |
di_devlink_handle_t dhdl; |
4543 | 3869 |
priv_set_t *priv_effective; |
3870 |
int privileged; |
|
789 | 3871 |
|
3872 |
(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); |
|
3873 |
||
3874 |
/* |
|
3875 |
* Issue the appropriate ioctl. |
|
3876 |
*/ |
|
2082 | 3877 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_CREATE_MINOR, &zc) != 0) { |
789 | 3878 |
switch (errno) { |
3879 |
case EEXIST: |
|
3880 |
/* |
|
3881 |
* Silently ignore the case where the link already |
|
3882 |
* exists. This allows 'zfs volinit' to be run multiple |
|
3883 |
* times without errors. |
|
3884 |
*/ |
|
3885 |
return (0); |
|
3886 |
||
4007 | 3887 |
case ENOENT: |
3888 |
/* |
|
3889 |
* Dataset does not exist in the kernel. If we |
|
3890 |
* don't care (see zfs_rename), then ignore the |
|
3891 |
* error quietly. |
|
3892 |
*/ |
|
3893 |
if (ifexists) { |
|
3894 |
return (0); |
|
3895 |
} |
|
3896 |
||
3897 |
/* FALLTHROUGH */ |
|
3898 |
||
789 | 3899 |
default: |
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
3900 |
return (zfs_standard_error_fmt(hdl, errno, |
2082 | 3901 |
dgettext(TEXT_DOMAIN, "cannot create device links " |
3902 |
"for '%s'"), dataset)); |
|
789 | 3903 |
} |
3904 |
} |
|
3905 |
||
3906 |
/* |
|
4543 | 3907 |
* If privileged call devfsadm and wait for the links to |
3908 |
* magically appear. |
|
3909 |
* Otherwise, print out an informational message. |
|
789 | 3910 |
*/ |
4543 | 3911 |
|
3912 |
priv_effective = priv_allocset(); |
|
3913 |
(void) getppriv(PRIV_EFFECTIVE, priv_effective); |
|
3914 |
privileged = (priv_isfullset(priv_effective) == B_TRUE); |
|
3915 |
priv_freeset(priv_effective); |
|
3916 |
||
3917 |
if (privileged) { |
|
3918 |
if ((dhdl = di_devlink_init(ZFS_DRIVER, |
|
3919 |
DI_MAKE_LINK)) == NULL) { |
|
3920 |
zfs_error_aux(hdl, strerror(errno)); |
|
3921 |
(void) zfs_standard_error_fmt(hdl, EZFS_DEVLINKS, |
|
3922 |
dgettext(TEXT_DOMAIN, "cannot create device links " |
|
3923 |
"for '%s'"), dataset); |
|
3924 |
(void) ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc); |
|
3925 |
return (-1); |
|
3926 |
} else { |
|
3927 |
(void) di_devlink_fini(&dhdl); |
|
3928 |
} |
|
789 | 3929 |
} else { |
4543 | 3930 |
char pathname[MAXPATHLEN]; |
3931 |
struct stat64 statbuf; |
|
3932 |
int i; |
|
3933 |
||
3934 |
#define MAX_WAIT 10 |
|
3935 |
||
3936 |
/* |
|
3937 |
* This is the poor mans way of waiting for the link |
|
3938 |
* to show up. If after 10 seconds we still don't |
|
3939 |
* have it, then print out a message. |
|
3940 |
*/ |
|
3941 |
(void) snprintf(pathname, sizeof (pathname), "/dev/zvol/dsk/%s", |
|
3942 |
dataset); |
|
3943 |
||
3944 |
for (i = 0; i != MAX_WAIT; i++) { |
|
3945 |
if (stat64(pathname, &statbuf) == 0) |
|
3946 |
break; |
|
3947 |
(void) sleep(1); |
|
3948 |
} |
|
3949 |
if (i == MAX_WAIT) |
|
3950 |
(void) printf(gettext("%s may not be immediately " |
|
3951 |
"available\n"), pathname); |
|
789 | 3952 |
} |
3953 |
||
3954 |
return (0); |
|
3955 |
} |
|
3956 |
||
3957 |
/* |
|
3958 |
* Remove a minor node for the given zvol and the associated /dev links. |
|
3959 |
*/ |
|
3960 |
int |
|
2082 | 3961 |
zvol_remove_link(libzfs_handle_t *hdl, const char *dataset) |
789 | 3962 |
{ |
3963 |
zfs_cmd_t zc = { 0 }; |
|
3964 |
||
3965 |
(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); |
|
3966 |
||
2082 | 3967 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc) != 0) { |
789 | 3968 |
switch (errno) { |
3969 |
case ENXIO: |
|
3970 |
/* |
|
3971 |
* Silently ignore the case where the link no longer |
|
3972 |
* exists, so that 'zfs volfini' can be run multiple |
|
3973 |
* times without errors. |
|
3974 |
*/ |
|
3975 |
return (0); |
|
3976 |
||
3977 |
default: |
|
3237
98d0c28f2f5e
6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents:
3234
diff
changeset
|
3978 |
return (zfs_standard_error_fmt(hdl, errno, |
2082 | 3979 |
dgettext(TEXT_DOMAIN, "cannot remove device " |
3980 |
"links for '%s'"), dataset)); |
|
789 | 3981 |
} |
3982 |
} |
|
3983 |
||
3984 |
return (0); |
|
3985 |
} |
|
2676 | 3986 |
|
3987 |
nvlist_t * |
|
3988 |
zfs_get_user_props(zfs_handle_t *zhp) |
|
3989 |
{ |
|
3990 |
return (zhp->zfs_user_props); |
|
3991 |
} |
|
3992 |
||
3993 |
/* |
|
3912 | 3994 |
* This function is used by 'zfs list' to determine the exact set of columns to |
3995 |
* display, and their maximum widths. This does two main things: |
|
3996 |
* |
|
3997 |
* - If this is a list of all properties, then expand the list to include |
|
3998 |
* all native properties, and set a flag so that for each dataset we look |
|
3999 |
* for new unique user properties and add them to the list. |
|
4000 |
* |
|
4001 |
* - For non fixed-width properties, keep track of the maximum width seen |
|
4002 |
* so that we can size the column appropriately. |
|
4003 |
*/ |
|
4004 |
int |
|
5094 | 4005 |
zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp) |
3912 | 4006 |
{ |
4007 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
5094 | 4008 |
zprop_list_t *entry; |
4009 |
zprop_list_t **last, **start; |
|
3912 | 4010 |
nvlist_t *userprops, *propval; |
4011 |
nvpair_t *elem; |
|
4012 |
char *strval; |
|
4013 |
char buf[ZFS_MAXPROPLEN]; |
|
4014 |
||
5094 | 4015 |
if (zprop_expand_list(hdl, plp, ZFS_TYPE_DATASET) != 0) |
3912 | 4016 |
return (-1); |
2676 | 4017 |
|
4018 |
userprops = zfs_get_user_props(zhp); |
|
4019 |
||
4020 |
entry = *plp; |
|
4021 |
if (entry->pl_all && nvlist_next_nvpair(userprops, NULL) != NULL) { |
|
4022 |
/* |
|
4023 |
* Go through and add any user properties as necessary. We |
|
4024 |
* start by incrementing our list pointer to the first |
|
4025 |
* non-native property. |
|
4026 |
*/ |
|
4027 |
start = plp; |
|
4028 |
while (*start != NULL) { |
|
5094 | 4029 |
if ((*start)->pl_prop == ZPROP_INVAL) |
2676 | 4030 |
break; |
4031 |
start = &(*start)->pl_next; |
|
4032 |
} |
|
4033 |
||
4034 |
elem = NULL; |
|
4035 |
while ((elem = nvlist_next_nvpair(userprops, elem)) != NULL) { |
|
4036 |
/* |
|
4037 |
* See if we've already found this property in our list. |
|
4038 |
*/ |
|
4039 |
for (last = start; *last != NULL; |
|
4040 |
last = &(*last)->pl_next) { |
|
4041 |
if (strcmp((*last)->pl_user_prop, |
|
4042 |
nvpair_name(elem)) == 0) |
|
4043 |
break; |
|
4044 |
} |
|
4045 |
||
4046 |
if (*last == NULL) { |
|
4047 |
if ((entry = zfs_alloc(hdl, |
|
5094 | 4048 |
sizeof (zprop_list_t))) == NULL || |
2676 | 4049 |
((entry->pl_user_prop = zfs_strdup(hdl, |
4050 |
nvpair_name(elem)))) == NULL) { |
|
4051 |
free(entry); |
|
4052 |
return (-1); |
|
4053 |
} |
|
4054 |
||
5094 | 4055 |
entry->pl_prop = ZPROP_INVAL; |
2676 | 4056 |
entry->pl_width = strlen(nvpair_name(elem)); |
4057 |
entry->pl_all = B_TRUE; |
|
4058 |
*last = entry; |
|
4059 |
} |
|
4060 |
} |
|
4061 |
} |
|
4062 |
||
4063 |
/* |
|
4064 |
* Now go through and check the width of any non-fixed columns |
|
4065 |
*/ |
|
4066 |
for (entry = *plp; entry != NULL; entry = entry->pl_next) { |
|
4067 |
if (entry->pl_fixed) |
|
4068 |
continue; |
|
4069 |
||
5094 | 4070 |
if (entry->pl_prop != ZPROP_INVAL) { |
2676 | 4071 |
if (zfs_prop_get(zhp, entry->pl_prop, |
4072 |
buf, sizeof (buf), NULL, NULL, 0, B_FALSE) == 0) { |
|
4073 |
if (strlen(buf) > entry->pl_width) |
|
4074 |
entry->pl_width = strlen(buf); |
|
4075 |
} |
|
4076 |
} else if (nvlist_lookup_nvlist(userprops, |
|
4077 |
entry->pl_user_prop, &propval) == 0) { |
|
4078 |
verify(nvlist_lookup_string(propval, |
|
5094 | 4079 |
ZPROP_VALUE, &strval) == 0); |
2676 | 4080 |
if (strlen(strval) > entry->pl_width) |
4081 |
entry->pl_width = strlen(strval); |
|
4082 |
} |
|
4083 |
} |
|
4084 |
||
4085 |
return (0); |
|
4086 |
} |
|
4543 | 4087 |
|
4088 |
int |
|
4089 |
zfs_iscsi_perm_check(libzfs_handle_t *hdl, char *dataset, ucred_t *cred) |
|
4090 |
{ |
|
4091 |
zfs_cmd_t zc = { 0 }; |
|
4092 |
nvlist_t *nvp; |
|
4093 |
gid_t gid; |
|
4094 |
uid_t uid; |
|
4095 |
const gid_t *groups; |
|
4096 |
int group_cnt; |
|
4097 |
int error; |
|
4098 |
||
4099 |
if (nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0) != 0) |
|
4100 |
return (no_memory(hdl)); |
|
4101 |
||
4102 |
uid = ucred_geteuid(cred); |
|
4103 |
gid = ucred_getegid(cred); |
|
4104 |
group_cnt = ucred_getgroups(cred, &groups); |
|
4105 |
||
4106 |
if (uid == (uid_t)-1 || gid == (uid_t)-1 || group_cnt == (uid_t)-1) |
|
4107 |
return (1); |
|
4108 |
||
4109 |
if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_UID, uid) != 0) { |
|
4110 |
nvlist_free(nvp); |
|
4111 |
return (1); |
|
4112 |
} |
|
4113 |
||
4114 |
if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_GID, gid) != 0) { |
|
4115 |
nvlist_free(nvp); |
|
4116 |
return (1); |
|
4117 |
} |
|
4118 |
||
4119 |
if (nvlist_add_uint32_array(nvp, |
|
4120 |
ZFS_DELEG_PERM_GROUPS, (uint32_t *)groups, group_cnt) != 0) { |
|
4121 |
nvlist_free(nvp); |
|
4122 |
return (1); |
|
4123 |
} |
|
4124 |
(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); |
|
4125 |
||
5094 | 4126 |
if (zcmd_write_src_nvlist(hdl, &zc, nvp)) |
4543 | 4127 |
return (-1); |
4128 |
||
4129 |
error = ioctl(hdl->libzfs_fd, ZFS_IOC_ISCSI_PERM_CHECK, &zc); |
|
4130 |
nvlist_free(nvp); |
|
4131 |
return (error); |
|
4132 |
} |
|
4133 |
||
4134 |
int |
|
4135 |
zfs_deleg_share_nfs(libzfs_handle_t *hdl, char *dataset, char *path, |
|
5331 | 4136 |
void *export, void *sharetab, int sharemax, zfs_share_op_t operation) |
4543 | 4137 |
{ |
4138 |
zfs_cmd_t zc = { 0 }; |
|
4139 |
int error; |
|
4140 |
||
4141 |
(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); |
|
4142 |
(void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value)); |
|
4143 |
zc.zc_share.z_sharedata = (uint64_t)(uintptr_t)sharetab; |
|
4144 |
zc.zc_share.z_exportdata = (uint64_t)(uintptr_t)export; |
|
5331 | 4145 |
zc.zc_share.z_sharetype = operation; |
4543 | 4146 |
zc.zc_share.z_sharemax = sharemax; |
4147 |
||
4148 |
error = ioctl(hdl->libzfs_fd, ZFS_IOC_SHARE, &zc); |
|
4149 |
return (error); |
|
4150 |
} |