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