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