4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Portions Copyright 2011 Martin Matuska
25 * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
26 * Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
27 * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
28 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
29 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
30 * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
31 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
32 * Copyright (c) 2013 Steven Hartland. All rights reserved.
33 * Copyright (c) 2014 Integros [integros.com]
34 * Copyright 2016 Toomas Soome <tsoome@me.com>
35 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
36 * Copyright (c) 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
37 * Copyright (c) 2017 Datto Inc. All rights reserved.
38 * Copyright 2017 RackTop Systems.
39 * Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
45 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
46 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
48 * There are two ways that we handle ioctls: the legacy way where almost
49 * all of the logic is in the ioctl callback, and the new way where most
50 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
52 * Non-legacy ioctls should be registered by calling
53 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
54 * from userland by lzc_ioctl().
56 * The registration arguments are as follows:
59 * The name of the ioctl. This is used for history logging. If the
60 * ioctl returns successfully (the callback returns 0), and allow_log
61 * is true, then a history log entry will be recorded with the input &
62 * output nvlists. The log entry can be printed with "zpool history -i".
65 * The ioctl request number, which userland will pass to ioctl(2).
66 * We want newer versions of libzfs and libzfs_core to run against
67 * existing zfs kernel modules (i.e. a deferred reboot after an update).
68 * Therefore the ioctl numbers cannot change from release to release.
70 * zfs_secpolicy_func_t *secpolicy
71 * This function will be called before the zfs_ioc_func_t, to
72 * determine if this operation is permitted. It should return EPERM
73 * on failure, and 0 on success. Checks include determining if the
74 * dataset is visible in this zone, and if the user has either all
75 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
76 * to do this operation on this dataset with "zfs allow".
78 * zfs_ioc_namecheck_t namecheck
79 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
80 * name, a dataset name, or nothing. If the name is not well-formed,
81 * the ioctl will fail and the callback will not be called.
82 * Therefore, the callback can assume that the name is well-formed
83 * (e.g. is null-terminated, doesn't have more than one '@' character,
84 * doesn't have invalid characters).
86 * zfs_ioc_poolcheck_t pool_check
87 * This specifies requirements on the pool state. If the pool does
88 * not meet them (is suspended or is readonly), the ioctl will fail
89 * and the callback will not be called. If any checks are specified
90 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
91 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
92 * POOL_CHECK_READONLY).
94 * zfs_ioc_key_t *nvl_keys
95 * The list of expected/allowable innvl input keys. This list is used
96 * to validate the nvlist input to the ioctl.
98 * boolean_t smush_outnvlist
99 * If smush_outnvlist is true, then the output is presumed to be a
100 * list of errors, and it will be "smushed" down to fit into the
101 * caller's buffer, by removing some entries and replacing them with a
102 * single "N_MORE_ERRORS" entry indicating how many were removed. See
103 * nvlist_smush() for details. If smush_outnvlist is false, and the
104 * outnvlist does not fit into the userland-provided buffer, then the
105 * ioctl will fail with ENOMEM.
107 * zfs_ioc_func_t *func
108 * The callback function that will perform the operation.
110 * The callback should return 0 on success, or an error number on
111 * failure. If the function fails, the userland ioctl will return -1,
112 * and errno will be set to the callback's return value. The callback
113 * will be called with the following arguments:
116 * The name of the pool or dataset to operate on, from
117 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
118 * expected type (pool, dataset, or none).
121 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
122 * NULL if no input nvlist was provided. Changes to this nvlist are
123 * ignored. If the input nvlist could not be deserialized, the
124 * ioctl will fail and the callback will not be called.
127 * The output nvlist, initially empty. The callback can fill it in,
128 * and it will be returned to userland by serializing it into
129 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
130 * fails (e.g. because the caller didn't supply a large enough
131 * buffer), then the overall ioctl will fail. See the
132 * 'smush_nvlist' argument above for additional behaviors.
134 * There are two typical uses of the output nvlist:
135 * - To return state, e.g. property values. In this case,
136 * smush_outnvlist should be false. If the buffer was not large
137 * enough, the caller will reallocate a larger buffer and try
140 * - To return multiple errors from an ioctl which makes on-disk
141 * changes. In this case, smush_outnvlist should be true.
142 * Ioctls which make on-disk modifications should generally not
143 * use the outnvl if they succeed, because the caller can not
144 * distinguish between the operation failing, and
145 * deserialization failing.
147 * IOCTL Interface Errors
149 * The following ioctl input errors can be returned:
150 * ZFS_ERR_IOC_CMD_UNAVAIL the ioctl number is not supported by kernel
151 * ZFS_ERR_IOC_ARG_UNAVAIL an input argument is not supported by kernel
152 * ZFS_ERR_IOC_ARG_REQUIRED a required input argument is missing
153 * ZFS_ERR_IOC_ARG_BADTYPE an input argument has an invalid type
156 #include <sys/types.h>
157 #include <sys/param.h>
158 #include <sys/errno.h>
160 #include <sys/file.h>
161 #include <sys/kmem.h>
162 #include <sys/cmn_err.h>
163 #include <sys/stat.h>
164 #include <sys/zfs_ioctl.h>
165 #include <sys/zfs_vfsops.h>
166 #include <sys/zfs_znode.h>
169 #include <sys/spa_impl.h>
170 #include <sys/vdev.h>
171 #include <sys/vdev_impl.h>
173 #include <sys/dsl_dir.h>
174 #include <sys/dsl_dataset.h>
175 #include <sys/dsl_prop.h>
176 #include <sys/dsl_deleg.h>
177 #include <sys/dmu_objset.h>
178 #include <sys/dmu_impl.h>
179 #include <sys/dmu_tx.h>
180 #include <sys/sunddi.h>
181 #include <sys/policy.h>
182 #include <sys/zone.h>
183 #include <sys/nvpair.h>
184 #include <sys/pathname.h>
186 #include <sys/fs/zfs.h>
187 #include <sys/zfs_ctldir.h>
188 #include <sys/zfs_dir.h>
189 #include <sys/zfs_onexit.h>
190 #include <sys/zvol.h>
191 #include <sys/dsl_scan.h>
192 #include <sys/fm/util.h>
193 #include <sys/dsl_crypt.h>
195 #include <sys/dmu_recv.h>
196 #include <sys/dmu_send.h>
197 #include <sys/dsl_destroy.h>
198 #include <sys/dsl_bookmark.h>
199 #include <sys/dsl_userhold.h>
200 #include <sys/zfeature.h>
202 #include <sys/zio_checksum.h>
203 #include <sys/vdev_removal.h>
204 #include <sys/zfs_sysfs.h>
205 #include <sys/vdev_impl.h>
206 #include <sys/vdev_initialize.h>
208 #include <linux/miscdevice.h>
209 #include <linux/slab.h>
211 #include "zfs_namecheck.h"
212 #include "zfs_prop.h"
213 #include "zfs_deleg.h"
214 #include "zfs_comutil.h"
216 #include <sys/lua/lua.h>
217 #include <sys/lua/lauxlib.h>
220 * Limit maximum nvlist size. We don't want users passing in insane values
221 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
223 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
225 kmutex_t zfsdev_state_lock
;
226 zfsdev_state_t
*zfsdev_state_list
;
228 extern void zfs_init(void);
229 extern void zfs_fini(void);
231 uint_t zfs_fsyncer_key
;
232 extern uint_t rrw_tsd_key
;
233 static uint_t zfs_allow_log_key
;
235 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
236 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
237 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
240 * IOC Keys are used to document and validate user->kernel interface inputs.
241 * See zfs_keys_recv_new for an example declaration. Any key name that is not
242 * listed will be rejected as input.
244 * The keyname 'optional' is always allowed, and must be an nvlist if present.
245 * Arguments which older kernels can safely ignore can be placed under the
248 * When adding new keys to an existing ioc for new functionality, consider:
249 * - adding an entry into zfs_sysfs.c zfs_features[] list
250 * - updating the libzfs_input_check.c test utility
252 * Note: in the ZK_WILDCARDLIST case, the name serves as documentation
253 * for the expected name (bookmark, snapshot, property, etc) but there
254 * is no validation in the preflight zfs_check_input_nvpairs() check.
257 ZK_OPTIONAL
= 1 << 0, /* pair is optional */
258 ZK_WILDCARDLIST
= 1 << 1, /* one or more unspecified key names */
261 /* DATA_TYPE_ANY is used when zkey_type can vary. */
262 #define DATA_TYPE_ANY DATA_TYPE_UNKNOWN
264 typedef struct zfs_ioc_key
{
265 const char *zkey_name
;
266 data_type_t zkey_type
;
267 ioc_key_flag_t zkey_flags
;
274 } zfs_ioc_namecheck_t
;
277 POOL_CHECK_NONE
= 1 << 0,
278 POOL_CHECK_SUSPENDED
= 1 << 1,
279 POOL_CHECK_READONLY
= 1 << 2,
280 } zfs_ioc_poolcheck_t
;
282 typedef struct zfs_ioc_vec
{
283 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
284 zfs_ioc_func_t
*zvec_func
;
285 zfs_secpolicy_func_t
*zvec_secpolicy
;
286 zfs_ioc_namecheck_t zvec_namecheck
;
287 boolean_t zvec_allow_log
;
288 zfs_ioc_poolcheck_t zvec_pool_check
;
289 boolean_t zvec_smush_outnvlist
;
290 const char *zvec_name
;
291 const zfs_ioc_key_t
*zvec_nvl_keys
;
292 size_t zvec_nvl_key_count
;
295 /* This array is indexed by zfs_userquota_prop_t */
296 static const char *userquota_perms
[] = {
297 ZFS_DELEG_PERM_USERUSED
,
298 ZFS_DELEG_PERM_USERQUOTA
,
299 ZFS_DELEG_PERM_GROUPUSED
,
300 ZFS_DELEG_PERM_GROUPQUOTA
,
301 ZFS_DELEG_PERM_USEROBJUSED
,
302 ZFS_DELEG_PERM_USEROBJQUOTA
,
303 ZFS_DELEG_PERM_GROUPOBJUSED
,
304 ZFS_DELEG_PERM_GROUPOBJQUOTA
,
305 ZFS_DELEG_PERM_PROJECTUSED
,
306 ZFS_DELEG_PERM_PROJECTQUOTA
,
307 ZFS_DELEG_PERM_PROJECTOBJUSED
,
308 ZFS_DELEG_PERM_PROJECTOBJQUOTA
,
311 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
312 static int zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
);
313 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
315 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
317 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
319 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
320 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
323 history_str_free(char *buf
)
325 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
329 history_str_get(zfs_cmd_t
*zc
)
333 if (zc
->zc_history
== 0)
336 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
337 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
338 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
339 history_str_free(buf
);
343 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
349 * Check to see if the named dataset is currently defined as bootable
352 zfs_is_bootfs(const char *name
)
356 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
358 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
359 dmu_objset_rele(os
, FTAG
);
366 * Return non-zero if the spa version is less than requested version.
369 zfs_earlier_version(const char *name
, int version
)
373 if (spa_open(name
, &spa
, FTAG
) == 0) {
374 if (spa_version(spa
) < version
) {
375 spa_close(spa
, FTAG
);
378 spa_close(spa
, FTAG
);
384 * Return TRUE if the ZPL version is less than requested version.
387 zpl_earlier_version(const char *name
, int version
)
390 boolean_t rc
= B_TRUE
;
392 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
395 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
396 dmu_objset_rele(os
, FTAG
);
399 /* XXX reading from non-owned objset */
400 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
401 rc
= zplversion
< version
;
402 dmu_objset_rele(os
, FTAG
);
408 zfs_log_history(zfs_cmd_t
*zc
)
413 if ((buf
= history_str_get(zc
)) == NULL
)
416 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
417 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
418 (void) spa_history_log(spa
, buf
);
419 spa_close(spa
, FTAG
);
421 history_str_free(buf
);
425 * Policy for top-level read operations (list pools). Requires no privileges,
426 * and can be used in the local zone, as there is no associated dataset.
430 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
436 * Policy for dataset read operations (list children, get statistics). Requires
437 * no privileges, but must be visible in the local zone.
441 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
443 if (INGLOBALZONE(curproc
) ||
444 zone_dataset_visible(zc
->zc_name
, NULL
))
447 return (SET_ERROR(ENOENT
));
451 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
456 * The dataset must be visible by this zone -- check this first
457 * so they don't see EPERM on something they shouldn't know about.
459 if (!INGLOBALZONE(curproc
) &&
460 !zone_dataset_visible(dataset
, &writable
))
461 return (SET_ERROR(ENOENT
));
463 if (INGLOBALZONE(curproc
)) {
465 * If the fs is zoned, only root can access it from the
468 if (secpolicy_zfs(cr
) && zoned
)
469 return (SET_ERROR(EPERM
));
472 * If we are in a local zone, the 'zoned' property must be set.
475 return (SET_ERROR(EPERM
));
477 /* must be writable by this zone */
479 return (SET_ERROR(EPERM
));
485 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
489 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
490 return (SET_ERROR(ENOENT
));
492 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
496 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
500 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
501 return (SET_ERROR(ENOENT
));
503 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
507 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
508 const char *perm
, cred_t
*cr
)
512 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
514 error
= secpolicy_zfs(cr
);
516 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
522 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
529 * First do a quick check for root in the global zone, which
530 * is allowed to do all write_perms. This ensures that zfs_ioc_*
531 * will get to handle nonexistent datasets.
533 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
536 error
= dsl_pool_hold(name
, FTAG
, &dp
);
540 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
542 dsl_pool_rele(dp
, FTAG
);
546 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
548 dsl_dataset_rele(ds
, FTAG
);
549 dsl_pool_rele(dp
, FTAG
);
554 * Policy for setting the security label property.
556 * Returns 0 for success, non-zero for access and other errors.
559 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
562 char ds_hexsl
[MAXNAMELEN
];
563 bslabel_t ds_sl
, new_sl
;
564 boolean_t new_default
= FALSE
;
566 int needed_priv
= -1;
569 /* First get the existing dataset label. */
570 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
571 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
573 return (SET_ERROR(EPERM
));
575 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
578 /* The label must be translatable */
579 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
580 return (SET_ERROR(EINVAL
));
583 * In a non-global zone, disallow attempts to set a label that
584 * doesn't match that of the zone; otherwise no other checks
587 if (!INGLOBALZONE(curproc
)) {
588 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
589 return (SET_ERROR(EPERM
));
594 * For global-zone datasets (i.e., those whose zoned property is
595 * "off", verify that the specified new label is valid for the
598 if (dsl_prop_get_integer(name
,
599 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
600 return (SET_ERROR(EPERM
));
602 if (zfs_check_global_label(name
, strval
) != 0)
603 return (SET_ERROR(EPERM
));
607 * If the existing dataset label is nondefault, check if the
608 * dataset is mounted (label cannot be changed while mounted).
609 * Get the zfsvfs_t; if there isn't one, then the dataset isn't
610 * mounted (or isn't a dataset, doesn't exist, ...).
612 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
614 static char *setsl_tag
= "setsl_tag";
617 * Try to own the dataset; abort if there is any error,
618 * (e.g., already mounted, in use, or other error).
620 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
, B_TRUE
,
623 return (SET_ERROR(EPERM
));
625 dmu_objset_disown(os
, B_TRUE
, setsl_tag
);
628 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
632 if (hexstr_to_label(strval
, &new_sl
) != 0)
633 return (SET_ERROR(EPERM
));
635 if (blstrictdom(&ds_sl
, &new_sl
))
636 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
637 else if (blstrictdom(&new_sl
, &ds_sl
))
638 needed_priv
= PRIV_FILE_UPGRADE_SL
;
640 /* dataset currently has a default label */
642 needed_priv
= PRIV_FILE_UPGRADE_SL
;
646 if (needed_priv
!= -1)
647 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
650 return (SET_ERROR(ENOTSUP
));
651 #endif /* HAVE_MLSLABEL */
655 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
661 * Check permissions for special properties.
668 * Disallow setting of 'zoned' from within a local zone.
670 if (!INGLOBALZONE(curproc
))
671 return (SET_ERROR(EPERM
));
675 case ZFS_PROP_FILESYSTEM_LIMIT
:
676 case ZFS_PROP_SNAPSHOT_LIMIT
:
677 if (!INGLOBALZONE(curproc
)) {
679 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
681 * Unprivileged users are allowed to modify the
682 * limit on things *under* (ie. contained by)
683 * the thing they own.
685 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
687 return (SET_ERROR(EPERM
));
688 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
689 return (SET_ERROR(EPERM
));
693 case ZFS_PROP_MLSLABEL
:
694 if (!is_system_labeled())
695 return (SET_ERROR(EPERM
));
697 if (nvpair_value_string(propval
, &strval
) == 0) {
700 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
707 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
712 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
716 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
721 * permission to set permissions will be evaluated later in
722 * dsl_deleg_can_allow()
729 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
731 return (zfs_secpolicy_write_perms(zc
->zc_name
,
732 ZFS_DELEG_PERM_ROLLBACK
, cr
));
737 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
745 * Generate the current snapshot name from the given objsetid, then
746 * use that name for the secpolicy/zone checks.
748 cp
= strchr(zc
->zc_name
, '@');
750 return (SET_ERROR(EINVAL
));
751 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
755 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
757 dsl_pool_rele(dp
, FTAG
);
761 dsl_dataset_name(ds
, zc
->zc_name
);
763 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
764 ZFS_DELEG_PERM_SEND
, cr
);
765 dsl_dataset_rele(ds
, FTAG
);
766 dsl_pool_rele(dp
, FTAG
);
773 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
775 return (zfs_secpolicy_write_perms(zc
->zc_name
,
776 ZFS_DELEG_PERM_SEND
, cr
));
780 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
782 return (SET_ERROR(ENOTSUP
));
786 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
788 return (SET_ERROR(ENOTSUP
));
792 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
797 * Remove the @bla or /bla from the end of the name to get the parent.
799 (void) strncpy(parent
, datasetname
, parentsize
);
800 cp
= strrchr(parent
, '@');
804 cp
= strrchr(parent
, '/');
806 return (SET_ERROR(ENOENT
));
814 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
818 if ((error
= zfs_secpolicy_write_perms(name
,
819 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
822 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
827 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
829 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
833 * Destroying snapshots with delegated permissions requires
834 * descendant mount and destroy permissions.
838 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
841 nvpair_t
*pair
, *nextpair
;
844 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
846 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
848 nextpair
= nvlist_next_nvpair(snaps
, pair
);
849 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
850 if (error
== ENOENT
) {
852 * Ignore any snapshots that don't exist (we consider
853 * them "already destroyed"). Remove the name from the
854 * nvl here in case the snapshot is created between
855 * now and when we try to destroy it (in which case
856 * we don't want to destroy it since we haven't
857 * checked for permission).
859 fnvlist_remove_nvpair(snaps
, pair
);
870 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
872 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
875 if ((error
= zfs_secpolicy_write_perms(from
,
876 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
879 if ((error
= zfs_secpolicy_write_perms(from
,
880 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
883 if ((error
= zfs_get_parent(to
, parentname
,
884 sizeof (parentname
))) != 0)
887 if ((error
= zfs_secpolicy_write_perms(parentname
,
888 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
891 if ((error
= zfs_secpolicy_write_perms(parentname
,
892 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
900 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
902 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
907 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
910 dsl_dataset_t
*clone
;
913 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
914 ZFS_DELEG_PERM_PROMOTE
, cr
);
918 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
922 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
925 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
926 dsl_dataset_t
*origin
= NULL
;
930 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
931 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
933 dsl_dataset_rele(clone
, FTAG
);
934 dsl_pool_rele(dp
, FTAG
);
938 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
939 ZFS_DELEG_PERM_MOUNT
, cr
);
941 dsl_dataset_name(origin
, parentname
);
943 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
944 ZFS_DELEG_PERM_PROMOTE
, cr
);
946 dsl_dataset_rele(clone
, FTAG
);
947 dsl_dataset_rele(origin
, FTAG
);
949 dsl_pool_rele(dp
, FTAG
);
955 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
959 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
960 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
963 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
964 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
967 return (zfs_secpolicy_write_perms(zc
->zc_name
,
968 ZFS_DELEG_PERM_CREATE
, cr
));
973 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
975 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
979 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
981 return (zfs_secpolicy_write_perms(name
,
982 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
986 * Check for permission to create each snapshot in the nvlist.
990 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
996 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
998 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
999 pair
= nvlist_next_nvpair(snaps
, pair
)) {
1000 char *name
= nvpair_name(pair
);
1001 char *atp
= strchr(name
, '@');
1004 error
= SET_ERROR(EINVAL
);
1008 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
1017 * Check for permission to create each bookmark in the nvlist.
1021 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1025 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
1026 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1027 char *name
= nvpair_name(pair
);
1028 char *hashp
= strchr(name
, '#');
1030 if (hashp
== NULL
) {
1031 error
= SET_ERROR(EINVAL
);
1035 error
= zfs_secpolicy_write_perms(name
,
1036 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1046 zfs_secpolicy_remap(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1048 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1049 ZFS_DELEG_PERM_REMAP
, cr
));
1054 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1056 nvpair_t
*pair
, *nextpair
;
1059 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1061 char *name
= nvpair_name(pair
);
1062 char *hashp
= strchr(name
, '#');
1063 nextpair
= nvlist_next_nvpair(innvl
, pair
);
1065 if (hashp
== NULL
) {
1066 error
= SET_ERROR(EINVAL
);
1071 error
= zfs_secpolicy_write_perms(name
,
1072 ZFS_DELEG_PERM_DESTROY
, cr
);
1074 if (error
== ENOENT
) {
1076 * Ignore any filesystems that don't exist (we consider
1077 * their bookmarks "already destroyed"). Remove
1078 * the name from the nvl here in case the filesystem
1079 * is created between now and when we try to destroy
1080 * the bookmark (in which case we don't want to
1081 * destroy it since we haven't checked for permission).
1083 fnvlist_remove_nvpair(innvl
, pair
);
1095 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1098 * Even root must have a proper TSD so that we know what pool
1101 if (tsd_get(zfs_allow_log_key
) == NULL
)
1102 return (SET_ERROR(EPERM
));
1107 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1109 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1113 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1114 sizeof (parentname
))) != 0)
1117 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1118 (error
= zfs_secpolicy_write_perms(origin
,
1119 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1122 if ((error
= zfs_secpolicy_write_perms(parentname
,
1123 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1126 return (zfs_secpolicy_write_perms(parentname
,
1127 ZFS_DELEG_PERM_MOUNT
, cr
));
1131 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1132 * SYS_CONFIG privilege, which is not available in a local zone.
1136 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1138 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1139 return (SET_ERROR(EPERM
));
1145 * Policy for object to name lookups.
1149 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1153 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1156 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1161 * Policy for fault injection. Requires all privileges.
1165 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1167 return (secpolicy_zinject(cr
));
1172 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1174 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1176 if (prop
== ZPROP_INVAL
) {
1177 if (!zfs_prop_user(zc
->zc_value
))
1178 return (SET_ERROR(EINVAL
));
1179 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1180 ZFS_DELEG_PERM_USERPROP
, cr
));
1182 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1188 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1190 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1194 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1195 return (SET_ERROR(EINVAL
));
1197 if (zc
->zc_value
[0] == 0) {
1199 * They are asking about a posix uid/gid. If it's
1200 * themself, allow it.
1202 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1203 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
||
1204 zc
->zc_objset_type
== ZFS_PROP_USEROBJUSED
||
1205 zc
->zc_objset_type
== ZFS_PROP_USEROBJQUOTA
) {
1206 if (zc
->zc_guid
== crgetuid(cr
))
1208 } else if (zc
->zc_objset_type
== ZFS_PROP_GROUPUSED
||
1209 zc
->zc_objset_type
== ZFS_PROP_GROUPQUOTA
||
1210 zc
->zc_objset_type
== ZFS_PROP_GROUPOBJUSED
||
1211 zc
->zc_objset_type
== ZFS_PROP_GROUPOBJQUOTA
) {
1212 if (groupmember(zc
->zc_guid
, cr
))
1215 /* else is for project quota/used */
1218 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1219 userquota_perms
[zc
->zc_objset_type
], cr
));
1223 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1225 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1229 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1230 return (SET_ERROR(EINVAL
));
1232 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1233 userquota_perms
[zc
->zc_objset_type
], cr
));
1238 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1240 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1246 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1252 holds
= fnvlist_lookup_nvlist(innvl
, "holds");
1254 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1255 pair
= nvlist_next_nvpair(holds
, pair
)) {
1256 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1257 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1260 error
= zfs_secpolicy_write_perms(fsname
,
1261 ZFS_DELEG_PERM_HOLD
, cr
);
1270 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1275 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1276 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1277 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1278 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1281 error
= zfs_secpolicy_write_perms(fsname
,
1282 ZFS_DELEG_PERM_RELEASE
, cr
);
1290 * Policy for allowing temporary snapshots to be taken or released
1293 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1296 * A temporary snapshot is the same as a snapshot,
1297 * hold, destroy and release all rolled into one.
1298 * Delegated diff alone is sufficient that we allow this.
1302 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1303 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1306 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1308 if (innvl
!= NULL
) {
1310 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1312 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1314 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1320 zfs_secpolicy_load_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1322 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1323 ZFS_DELEG_PERM_LOAD_KEY
, cr
));
1327 zfs_secpolicy_change_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1329 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1330 ZFS_DELEG_PERM_CHANGE_KEY
, cr
));
1334 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1337 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1341 nvlist_t
*list
= NULL
;
1344 * Read in and unpack the user-supplied nvlist.
1347 return (SET_ERROR(EINVAL
));
1349 packed
= vmem_alloc(size
, KM_SLEEP
);
1351 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1353 vmem_free(packed
, size
);
1354 return (SET_ERROR(EFAULT
));
1357 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1358 vmem_free(packed
, size
);
1362 vmem_free(packed
, size
);
1369 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1370 * Entries will be removed from the end of the nvlist, and one int32 entry
1371 * named "N_MORE_ERRORS" will be added indicating how many entries were
1375 nvlist_smush(nvlist_t
*errors
, size_t max
)
1379 size
= fnvlist_size(errors
);
1382 nvpair_t
*more_errors
;
1386 return (SET_ERROR(ENOMEM
));
1388 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1389 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1392 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1394 fnvlist_remove_nvpair(errors
, pair
);
1396 size
= fnvlist_size(errors
);
1397 } while (size
> max
);
1399 fnvlist_remove_nvpair(errors
, more_errors
);
1400 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1401 ASSERT3U(fnvlist_size(errors
), <=, max
);
1408 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1410 char *packed
= NULL
;
1414 size
= fnvlist_size(nvl
);
1416 if (size
> zc
->zc_nvlist_dst_size
) {
1417 error
= SET_ERROR(ENOMEM
);
1419 packed
= fnvlist_pack(nvl
, &size
);
1420 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1421 size
, zc
->zc_iflags
) != 0)
1422 error
= SET_ERROR(EFAULT
);
1423 fnvlist_pack_free(packed
, size
);
1426 zc
->zc_nvlist_dst_size
= size
;
1427 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1432 getzfsvfs_impl(objset_t
*os
, zfsvfs_t
**zfvp
)
1435 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1436 return (SET_ERROR(EINVAL
));
1439 mutex_enter(&os
->os_user_ptr_lock
);
1440 *zfvp
= dmu_objset_get_user(os
);
1441 /* bump s_active only when non-zero to prevent umount race */
1442 if (*zfvp
== NULL
|| (*zfvp
)->z_sb
== NULL
||
1443 !atomic_inc_not_zero(&((*zfvp
)->z_sb
->s_active
))) {
1444 error
= SET_ERROR(ESRCH
);
1446 mutex_exit(&os
->os_user_ptr_lock
);
1451 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1456 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1460 error
= getzfsvfs_impl(os
, zfvp
);
1461 dmu_objset_rele(os
, FTAG
);
1466 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1467 * case its z_sb will be NULL, and it will be opened as the owner.
1468 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1469 * which prevents all inode ops from running.
1472 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1476 if (getzfsvfs(name
, zfvp
) != 0)
1477 error
= zfsvfs_create(name
, B_FALSE
, zfvp
);
1479 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1481 if ((*zfvp
)->z_unmounted
) {
1483 * XXX we could probably try again, since the unmounting
1484 * thread should be just about to disassociate the
1485 * objset from the zfsvfs.
1487 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1488 return (SET_ERROR(EBUSY
));
1495 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1497 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1500 deactivate_super(zfsvfs
->z_sb
);
1502 dmu_objset_disown(zfsvfs
->z_os
, B_TRUE
, zfsvfs
);
1503 zfsvfs_free(zfsvfs
);
1508 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1511 nvlist_t
*config
, *props
= NULL
;
1512 nvlist_t
*rootprops
= NULL
;
1513 nvlist_t
*zplprops
= NULL
;
1514 dsl_crypto_params_t
*dcp
= NULL
;
1515 char *spa_name
= zc
->zc_name
;
1517 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1518 zc
->zc_iflags
, &config
)))
1521 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1522 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1523 zc
->zc_iflags
, &props
))) {
1524 nvlist_free(config
);
1529 nvlist_t
*nvl
= NULL
;
1530 nvlist_t
*hidden_args
= NULL
;
1531 uint64_t version
= SPA_VERSION
;
1534 (void) nvlist_lookup_uint64(props
,
1535 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1536 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1537 error
= SET_ERROR(EINVAL
);
1538 goto pool_props_bad
;
1540 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1542 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1544 nvlist_free(config
);
1548 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1551 (void) nvlist_lookup_nvlist(props
, ZPOOL_HIDDEN_ARGS
,
1553 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
,
1554 rootprops
, hidden_args
, &dcp
);
1556 nvlist_free(config
);
1560 (void) nvlist_remove_all(props
, ZPOOL_HIDDEN_ARGS
);
1562 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1563 error
= zfs_fill_zplprops_root(version
, rootprops
,
1566 goto pool_props_bad
;
1568 if (nvlist_lookup_string(props
,
1569 zpool_prop_to_name(ZPOOL_PROP_TNAME
), &tname
) == 0)
1573 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
, dcp
);
1576 * Set the remaining root properties
1578 if (!error
&& (error
= zfs_set_prop_nvlist(spa_name
,
1579 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1580 (void) spa_destroy(spa_name
);
1583 nvlist_free(rootprops
);
1584 nvlist_free(zplprops
);
1585 nvlist_free(config
);
1587 dsl_crypto_params_free(dcp
, !!error
);
1593 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1596 zfs_log_history(zc
);
1597 error
= spa_destroy(zc
->zc_name
);
1603 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1605 nvlist_t
*config
, *props
= NULL
;
1609 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1610 zc
->zc_iflags
, &config
)) != 0)
1613 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1614 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1615 zc
->zc_iflags
, &props
))) {
1616 nvlist_free(config
);
1620 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1621 guid
!= zc
->zc_guid
)
1622 error
= SET_ERROR(EINVAL
);
1624 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1626 if (zc
->zc_nvlist_dst
!= 0) {
1629 if ((err
= put_nvlist(zc
, config
)) != 0)
1633 nvlist_free(config
);
1640 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1643 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1644 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1646 zfs_log_history(zc
);
1647 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1653 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1658 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1659 return (SET_ERROR(EEXIST
));
1661 error
= put_nvlist(zc
, configs
);
1663 nvlist_free(configs
);
1670 * zc_name name of the pool
1673 * zc_cookie real errno
1674 * zc_nvlist_dst config nvlist
1675 * zc_nvlist_dst_size size of config nvlist
1678 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1684 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1685 sizeof (zc
->zc_value
));
1687 if (config
!= NULL
) {
1688 ret
= put_nvlist(zc
, config
);
1689 nvlist_free(config
);
1692 * The config may be present even if 'error' is non-zero.
1693 * In this case we return success, and preserve the real errno
1696 zc
->zc_cookie
= error
;
1705 * Try to import the given pool, returning pool stats as appropriate so that
1706 * user land knows which devices are available and overall pool health.
1709 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1711 nvlist_t
*tryconfig
, *config
= NULL
;
1714 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1715 zc
->zc_iflags
, &tryconfig
)) != 0)
1718 config
= spa_tryimport(tryconfig
);
1720 nvlist_free(tryconfig
);
1723 return (SET_ERROR(EINVAL
));
1725 error
= put_nvlist(zc
, config
);
1726 nvlist_free(config
);
1733 * zc_name name of the pool
1734 * zc_cookie scan func (pool_scan_func_t)
1735 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1738 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1743 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1744 return (SET_ERROR(EINVAL
));
1746 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1749 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1750 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1751 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1752 error
= spa_scan_stop(spa
);
1754 error
= spa_scan(spa
, zc
->zc_cookie
);
1756 spa_close(spa
, FTAG
);
1762 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1767 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1770 spa_close(spa
, FTAG
);
1776 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1781 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1784 if (zc
->zc_cookie
< spa_version(spa
) ||
1785 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1786 spa_close(spa
, FTAG
);
1787 return (SET_ERROR(EINVAL
));
1790 spa_upgrade(spa
, zc
->zc_cookie
);
1791 spa_close(spa
, FTAG
);
1797 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1804 if ((size
= zc
->zc_history_len
) == 0)
1805 return (SET_ERROR(EINVAL
));
1807 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1810 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1811 spa_close(spa
, FTAG
);
1812 return (SET_ERROR(ENOTSUP
));
1815 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1816 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1817 &zc
->zc_history_len
, hist_buf
)) == 0) {
1818 error
= ddi_copyout(hist_buf
,
1819 (void *)(uintptr_t)zc
->zc_history
,
1820 zc
->zc_history_len
, zc
->zc_iflags
);
1823 spa_close(spa
, FTAG
);
1824 vmem_free(hist_buf
, size
);
1829 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1834 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1836 error
= spa_change_guid(spa
);
1837 spa_close(spa
, FTAG
);
1843 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1845 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1850 * zc_name name of filesystem
1851 * zc_obj object to find
1854 * zc_value name of object
1857 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1862 /* XXX reading from objset not owned */
1863 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1866 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1867 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1868 return (SET_ERROR(EINVAL
));
1870 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1871 sizeof (zc
->zc_value
));
1872 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1879 * zc_name name of filesystem
1880 * zc_obj object to find
1883 * zc_stat stats on object
1884 * zc_value path to object
1887 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1892 /* XXX reading from objset not owned */
1893 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1896 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1897 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1898 return (SET_ERROR(EINVAL
));
1900 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1901 sizeof (zc
->zc_value
));
1902 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1908 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1914 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1918 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1919 zc
->zc_iflags
, &config
);
1921 error
= spa_vdev_add(spa
, config
);
1922 nvlist_free(config
);
1924 spa_close(spa
, FTAG
);
1930 * zc_name name of the pool
1931 * zc_guid guid of vdev to remove
1932 * zc_cookie cancel removal
1935 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1940 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1943 if (zc
->zc_cookie
!= 0) {
1944 error
= spa_vdev_remove_cancel(spa
);
1946 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1948 spa_close(spa
, FTAG
);
1953 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1957 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1959 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1961 switch (zc
->zc_cookie
) {
1962 case VDEV_STATE_ONLINE
:
1963 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1966 case VDEV_STATE_OFFLINE
:
1967 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1970 case VDEV_STATE_FAULTED
:
1971 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1972 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
&&
1973 zc
->zc_obj
!= VDEV_AUX_EXTERNAL_PERSIST
)
1974 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1976 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1979 case VDEV_STATE_DEGRADED
:
1980 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1981 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1982 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1984 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1988 error
= SET_ERROR(EINVAL
);
1990 zc
->zc_cookie
= newstate
;
1991 spa_close(spa
, FTAG
);
1996 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1999 int replacing
= zc
->zc_cookie
;
2003 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2006 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2007 zc
->zc_iflags
, &config
)) == 0) {
2008 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
2009 nvlist_free(config
);
2012 spa_close(spa
, FTAG
);
2017 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
2022 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2025 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
2027 spa_close(spa
, FTAG
);
2032 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
2035 nvlist_t
*config
, *props
= NULL
;
2037 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
2039 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2042 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2043 zc
->zc_iflags
, &config
))) {
2044 spa_close(spa
, FTAG
);
2048 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
2049 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2050 zc
->zc_iflags
, &props
))) {
2051 spa_close(spa
, FTAG
);
2052 nvlist_free(config
);
2056 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
2058 spa_close(spa
, FTAG
);
2060 nvlist_free(config
);
2067 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
2070 char *path
= zc
->zc_value
;
2071 uint64_t guid
= zc
->zc_guid
;
2074 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2078 error
= spa_vdev_setpath(spa
, guid
, path
);
2079 spa_close(spa
, FTAG
);
2084 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
2087 char *fru
= zc
->zc_value
;
2088 uint64_t guid
= zc
->zc_guid
;
2091 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2095 error
= spa_vdev_setfru(spa
, guid
, fru
);
2096 spa_close(spa
, FTAG
);
2101 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2106 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2108 if (zc
->zc_nvlist_dst
!= 0 &&
2109 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2110 dmu_objset_stats(os
, nv
);
2112 * NB: zvol_get_stats() will read the objset contents,
2113 * which we aren't supposed to do with a
2114 * DS_MODE_USER hold, because it could be
2115 * inconsistent. So this is a bit of a workaround...
2116 * XXX reading with out owning
2118 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2119 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2120 error
= zvol_get_stats(os
, nv
);
2128 error
= put_nvlist(zc
, nv
);
2137 * zc_name name of filesystem
2138 * zc_nvlist_dst_size size of buffer for property nvlist
2141 * zc_objset_stats stats
2142 * zc_nvlist_dst property nvlist
2143 * zc_nvlist_dst_size size of property nvlist
2146 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2151 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2153 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2154 dmu_objset_rele(os
, FTAG
);
2162 * zc_name name of filesystem
2163 * zc_nvlist_dst_size size of buffer for property nvlist
2166 * zc_nvlist_dst received property nvlist
2167 * zc_nvlist_dst_size size of received property nvlist
2169 * Gets received properties (distinct from local properties on or after
2170 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2171 * local property values.
2174 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2180 * Without this check, we would return local property values if the
2181 * caller has not already received properties on or after
2182 * SPA_VERSION_RECVD_PROPS.
2184 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2185 return (SET_ERROR(ENOTSUP
));
2187 if (zc
->zc_nvlist_dst
!= 0 &&
2188 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2189 error
= put_nvlist(zc
, nv
);
2197 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2203 * zfs_get_zplprop() will either find a value or give us
2204 * the default value (if there is one).
2206 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2208 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2214 * zc_name name of filesystem
2215 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2218 * zc_nvlist_dst zpl property nvlist
2219 * zc_nvlist_dst_size size of zpl property nvlist
2222 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2227 /* XXX reading without owning */
2228 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2231 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2234 * NB: nvl_add_zplprop() will read the objset contents,
2235 * which we aren't supposed to do with a DS_MODE_USER
2236 * hold, because it could be inconsistent.
2238 if (zc
->zc_nvlist_dst
!= 0 &&
2239 !zc
->zc_objset_stats
.dds_inconsistent
&&
2240 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2243 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2244 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2245 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2246 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2247 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2248 err
= put_nvlist(zc
, nv
);
2251 err
= SET_ERROR(ENOENT
);
2253 dmu_objset_rele(os
, FTAG
);
2259 * zc_name name of filesystem
2260 * zc_cookie zap cursor
2261 * zc_nvlist_dst_size size of buffer for property nvlist
2264 * zc_name name of next filesystem
2265 * zc_cookie zap cursor
2266 * zc_objset_stats stats
2267 * zc_nvlist_dst property nvlist
2268 * zc_nvlist_dst_size size of property nvlist
2271 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2276 size_t orig_len
= strlen(zc
->zc_name
);
2279 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2280 if (error
== ENOENT
)
2281 error
= SET_ERROR(ESRCH
);
2285 p
= strrchr(zc
->zc_name
, '/');
2286 if (p
== NULL
|| p
[1] != '\0')
2287 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2288 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2291 error
= dmu_dir_list_next(os
,
2292 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2293 NULL
, &zc
->zc_cookie
);
2294 if (error
== ENOENT
)
2295 error
= SET_ERROR(ESRCH
);
2296 } while (error
== 0 && zfs_dataset_name_hidden(zc
->zc_name
));
2297 dmu_objset_rele(os
, FTAG
);
2300 * If it's an internal dataset (ie. with a '$' in its name),
2301 * don't try to get stats for it, otherwise we'll return ENOENT.
2303 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2304 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2305 if (error
== ENOENT
) {
2306 /* We lost a race with destroy, get the next one. */
2307 zc
->zc_name
[orig_len
] = '\0';
2316 * zc_name name of filesystem
2317 * zc_cookie zap cursor
2318 * zc_nvlist_dst_size size of buffer for property nvlist
2321 * zc_name name of next snapshot
2322 * zc_objset_stats stats
2323 * zc_nvlist_dst property nvlist
2324 * zc_nvlist_dst_size size of property nvlist
2327 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2332 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2334 return (error
== ENOENT
? ESRCH
: error
);
2338 * A dataset name of maximum length cannot have any snapshots,
2339 * so exit immediately.
2341 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2342 ZFS_MAX_DATASET_NAME_LEN
) {
2343 dmu_objset_rele(os
, FTAG
);
2344 return (SET_ERROR(ESRCH
));
2347 error
= dmu_snapshot_list_next(os
,
2348 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2349 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2352 if (error
== 0 && !zc
->zc_simple
) {
2354 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2356 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2360 error
= dmu_objset_from_ds(ds
, &ossnap
);
2362 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2363 dsl_dataset_rele(ds
, FTAG
);
2365 } else if (error
== ENOENT
) {
2366 error
= SET_ERROR(ESRCH
);
2369 dmu_objset_rele(os
, FTAG
);
2370 /* if we failed, undo the @ that we tacked on to zc_name */
2372 *strchr(zc
->zc_name
, '@') = '\0';
2377 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2379 const char *propname
= nvpair_name(pair
);
2381 unsigned int vallen
;
2384 zfs_userquota_prop_t type
;
2390 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2392 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2393 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2395 return (SET_ERROR(EINVAL
));
2399 * A correctly constructed propname is encoded as
2400 * userquota@<rid>-<domain>.
2402 if ((dash
= strchr(propname
, '-')) == NULL
||
2403 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2405 return (SET_ERROR(EINVAL
));
2412 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2414 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2415 zfsvfs_rele(zfsvfs
, FTAG
);
2422 * If the named property is one that has a special function to set its value,
2423 * return 0 on success and a positive error code on failure; otherwise if it is
2424 * not one of the special properties handled by this function, return -1.
2426 * XXX: It would be better for callers of the property interface if we handled
2427 * these special cases in dsl_prop.c (in the dsl layer).
2430 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2433 const char *propname
= nvpair_name(pair
);
2434 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2435 uint64_t intval
= 0;
2436 char *strval
= NULL
;
2439 if (prop
== ZPROP_INVAL
) {
2440 if (zfs_prop_userquota(propname
))
2441 return (zfs_prop_set_userquota(dsname
, pair
));
2445 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2447 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2448 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2452 /* all special properties are numeric except for keylocation */
2453 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
) {
2454 strval
= fnvpair_value_string(pair
);
2456 intval
= fnvpair_value_uint64(pair
);
2460 case ZFS_PROP_QUOTA
:
2461 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2463 case ZFS_PROP_REFQUOTA
:
2464 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2466 case ZFS_PROP_FILESYSTEM_LIMIT
:
2467 case ZFS_PROP_SNAPSHOT_LIMIT
:
2468 if (intval
== UINT64_MAX
) {
2469 /* clearing the limit, just do it */
2472 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2475 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2476 * default path to set the value in the nvlist.
2481 case ZFS_PROP_KEYLOCATION
:
2482 err
= dsl_crypto_can_set_keylocation(dsname
, strval
);
2485 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2486 * default path to set the value in the nvlist.
2491 case ZFS_PROP_RESERVATION
:
2492 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2494 case ZFS_PROP_REFRESERVATION
:
2495 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2497 case ZFS_PROP_VOLSIZE
:
2498 err
= zvol_set_volsize(dsname
, intval
);
2500 case ZFS_PROP_SNAPDEV
:
2501 err
= zvol_set_snapdev(dsname
, source
, intval
);
2503 case ZFS_PROP_VOLMODE
:
2504 err
= zvol_set_volmode(dsname
, source
, intval
);
2506 case ZFS_PROP_VERSION
:
2510 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2513 err
= zfs_set_version(zfsvfs
, intval
);
2514 zfsvfs_rele(zfsvfs
, FTAG
);
2516 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2519 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2520 (void) strcpy(zc
->zc_name
, dsname
);
2521 (void) zfs_ioc_userspace_upgrade(zc
);
2522 (void) zfs_ioc_id_quota_upgrade(zc
);
2523 kmem_free(zc
, sizeof (zfs_cmd_t
));
2535 * This function is best effort. If it fails to set any of the given properties,
2536 * it continues to set as many as it can and returns the last error
2537 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2538 * with the list of names of all the properties that failed along with the
2539 * corresponding error numbers.
2541 * If every property is set successfully, zero is returned and errlist is not
2545 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2554 nvlist_t
*genericnvl
= fnvlist_alloc();
2555 nvlist_t
*retrynvl
= fnvlist_alloc();
2558 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2559 const char *propname
= nvpair_name(pair
);
2560 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2563 /* decode the property value */
2565 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2567 attrs
= fnvpair_value_nvlist(pair
);
2568 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2570 err
= SET_ERROR(EINVAL
);
2573 /* Validate value type */
2574 if (err
== 0 && source
== ZPROP_SRC_INHERITED
) {
2575 /* inherited properties are expected to be booleans */
2576 if (nvpair_type(propval
) != DATA_TYPE_BOOLEAN
)
2577 err
= SET_ERROR(EINVAL
);
2578 } else if (err
== 0 && prop
== ZPROP_INVAL
) {
2579 if (zfs_prop_user(propname
)) {
2580 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2581 err
= SET_ERROR(EINVAL
);
2582 } else if (zfs_prop_userquota(propname
)) {
2583 if (nvpair_type(propval
) !=
2584 DATA_TYPE_UINT64_ARRAY
)
2585 err
= SET_ERROR(EINVAL
);
2587 err
= SET_ERROR(EINVAL
);
2589 } else if (err
== 0) {
2590 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2591 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2592 err
= SET_ERROR(EINVAL
);
2593 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2596 intval
= fnvpair_value_uint64(propval
);
2598 switch (zfs_prop_get_type(prop
)) {
2599 case PROP_TYPE_NUMBER
:
2601 case PROP_TYPE_STRING
:
2602 err
= SET_ERROR(EINVAL
);
2604 case PROP_TYPE_INDEX
:
2605 if (zfs_prop_index_to_string(prop
,
2606 intval
, &unused
) != 0)
2607 err
= SET_ERROR(EINVAL
);
2611 "unknown property type");
2614 err
= SET_ERROR(EINVAL
);
2618 /* Validate permissions */
2620 err
= zfs_check_settable(dsname
, pair
, CRED());
2623 if (source
== ZPROP_SRC_INHERITED
)
2624 err
= -1; /* does not need special handling */
2626 err
= zfs_prop_set_special(dsname
, source
,
2630 * For better performance we build up a list of
2631 * properties to set in a single transaction.
2633 err
= nvlist_add_nvpair(genericnvl
, pair
);
2634 } else if (err
!= 0 && nvl
!= retrynvl
) {
2636 * This may be a spurious error caused by
2637 * receiving quota and reservation out of order.
2638 * Try again in a second pass.
2640 err
= nvlist_add_nvpair(retrynvl
, pair
);
2645 if (errlist
!= NULL
)
2646 fnvlist_add_int32(errlist
, propname
, err
);
2651 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2656 if (!nvlist_empty(genericnvl
) &&
2657 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2659 * If this fails, we still want to set as many properties as we
2660 * can, so try setting them individually.
2663 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2664 const char *propname
= nvpair_name(pair
);
2668 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2670 attrs
= fnvpair_value_nvlist(pair
);
2671 propval
= fnvlist_lookup_nvpair(attrs
,
2675 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2676 strval
= fnvpair_value_string(propval
);
2677 err
= dsl_prop_set_string(dsname
, propname
,
2679 } else if (nvpair_type(propval
) == DATA_TYPE_BOOLEAN
) {
2680 err
= dsl_prop_inherit(dsname
, propname
,
2683 intval
= fnvpair_value_uint64(propval
);
2684 err
= dsl_prop_set_int(dsname
, propname
, source
,
2689 if (errlist
!= NULL
) {
2690 fnvlist_add_int32(errlist
, propname
,
2697 nvlist_free(genericnvl
);
2698 nvlist_free(retrynvl
);
2704 * Check that all the properties are valid user properties.
2707 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2709 nvpair_t
*pair
= NULL
;
2712 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2713 const char *propname
= nvpair_name(pair
);
2715 if (!zfs_prop_user(propname
) ||
2716 nvpair_type(pair
) != DATA_TYPE_STRING
)
2717 return (SET_ERROR(EINVAL
));
2719 if ((error
= zfs_secpolicy_write_perms(fsname
,
2720 ZFS_DELEG_PERM_USERPROP
, CRED())))
2723 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2724 return (SET_ERROR(ENAMETOOLONG
));
2726 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2727 return (SET_ERROR(E2BIG
));
2733 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2737 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2740 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2741 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2744 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2749 clear_received_props(const char *dsname
, nvlist_t
*props
,
2753 nvlist_t
*cleared_props
= NULL
;
2754 props_skip(props
, skipped
, &cleared_props
);
2755 if (!nvlist_empty(cleared_props
)) {
2757 * Acts on local properties until the dataset has received
2758 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2760 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2761 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2762 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2764 nvlist_free(cleared_props
);
2770 * zc_name name of filesystem
2771 * zc_value name of property to set
2772 * zc_nvlist_src{_size} nvlist of properties to apply
2773 * zc_cookie received properties flag
2776 * zc_nvlist_dst{_size} error for each unapplied received property
2779 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2782 boolean_t received
= zc
->zc_cookie
;
2783 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2788 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2789 zc
->zc_iflags
, &nvl
)) != 0)
2793 nvlist_t
*origprops
;
2795 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2796 (void) clear_received_props(zc
->zc_name
,
2798 nvlist_free(origprops
);
2801 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2804 errors
= fnvlist_alloc();
2806 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2808 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2809 (void) put_nvlist(zc
, errors
);
2812 nvlist_free(errors
);
2819 * zc_name name of filesystem
2820 * zc_value name of property to inherit
2821 * zc_cookie revert to received value if TRUE
2826 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2828 const char *propname
= zc
->zc_value
;
2829 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2830 boolean_t received
= zc
->zc_cookie
;
2831 zprop_source_t source
= (received
2832 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2833 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2841 * Only check this in the non-received case. We want to allow
2842 * 'inherit -S' to revert non-inheritable properties like quota
2843 * and reservation to the received or default values even though
2844 * they are not considered inheritable.
2846 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2847 return (SET_ERROR(EINVAL
));
2850 if (prop
== ZPROP_INVAL
) {
2851 if (!zfs_prop_user(propname
))
2852 return (SET_ERROR(EINVAL
));
2854 type
= PROP_TYPE_STRING
;
2855 } else if (prop
== ZFS_PROP_VOLSIZE
|| prop
== ZFS_PROP_VERSION
) {
2856 return (SET_ERROR(EINVAL
));
2858 type
= zfs_prop_get_type(prop
);
2862 * zfs_prop_set_special() expects properties in the form of an
2863 * nvpair with type info.
2865 dummy
= fnvlist_alloc();
2868 case PROP_TYPE_STRING
:
2869 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2871 case PROP_TYPE_NUMBER
:
2872 case PROP_TYPE_INDEX
:
2873 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2876 err
= SET_ERROR(EINVAL
);
2880 pair
= nvlist_next_nvpair(dummy
, NULL
);
2882 err
= SET_ERROR(EINVAL
);
2884 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2885 if (err
== -1) /* property is not "special", needs handling */
2886 err
= dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
,
2896 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2903 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2904 zc
->zc_iflags
, &props
)))
2908 * If the only property is the configfile, then just do a spa_lookup()
2909 * to handle the faulted case.
2911 pair
= nvlist_next_nvpair(props
, NULL
);
2912 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2913 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2914 nvlist_next_nvpair(props
, pair
) == NULL
) {
2915 mutex_enter(&spa_namespace_lock
);
2916 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2917 spa_configfile_set(spa
, props
, B_FALSE
);
2918 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
);
2920 mutex_exit(&spa_namespace_lock
);
2927 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2932 error
= spa_prop_set(spa
, props
);
2935 spa_close(spa
, FTAG
);
2941 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2945 nvlist_t
*nvp
= NULL
;
2947 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2949 * If the pool is faulted, there may be properties we can still
2950 * get (such as altroot and cachefile), so attempt to get them
2953 mutex_enter(&spa_namespace_lock
);
2954 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2955 error
= spa_prop_get(spa
, &nvp
);
2956 mutex_exit(&spa_namespace_lock
);
2958 error
= spa_prop_get(spa
, &nvp
);
2959 spa_close(spa
, FTAG
);
2962 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2963 error
= put_nvlist(zc
, nvp
);
2965 error
= SET_ERROR(EFAULT
);
2973 * zc_name name of filesystem
2974 * zc_nvlist_src{_size} nvlist of delegated permissions
2975 * zc_perm_action allow/unallow flag
2980 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2983 nvlist_t
*fsaclnv
= NULL
;
2985 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2986 zc
->zc_iflags
, &fsaclnv
)) != 0)
2990 * Verify nvlist is constructed correctly
2992 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2993 nvlist_free(fsaclnv
);
2994 return (SET_ERROR(EINVAL
));
2998 * If we don't have PRIV_SYS_MOUNT, then validate
2999 * that user is allowed to hand out each permission in
3003 error
= secpolicy_zfs(CRED());
3005 if (zc
->zc_perm_action
== B_FALSE
) {
3006 error
= dsl_deleg_can_allow(zc
->zc_name
,
3009 error
= dsl_deleg_can_unallow(zc
->zc_name
,
3015 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
3017 nvlist_free(fsaclnv
);
3023 * zc_name name of filesystem
3026 * zc_nvlist_src{_size} nvlist of delegated permissions
3029 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
3034 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
3035 error
= put_nvlist(zc
, nvp
);
3044 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
3046 zfs_creat_t
*zct
= arg
;
3048 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
3051 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
3055 * os parent objset pointer (NULL if root fs)
3056 * fuids_ok fuids allowed in this version of the spa?
3057 * sa_ok SAs allowed in this version of the spa?
3058 * createprops list of properties requested by creator
3061 * zplprops values for the zplprops we attach to the master node object
3062 * is_ci true if requested file system will be purely case-insensitive
3064 * Determine the settings for utf8only, normalization and
3065 * casesensitivity. Specific values may have been requested by the
3066 * creator and/or we can inherit values from the parent dataset. If
3067 * the file system is of too early a vintage, a creator can not
3068 * request settings for these properties, even if the requested
3069 * setting is the default value. We don't actually want to create dsl
3070 * properties for these, so remove them from the source nvlist after
3074 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
3075 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
3076 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3078 uint64_t sense
= ZFS_PROP_UNDEFINED
;
3079 uint64_t norm
= ZFS_PROP_UNDEFINED
;
3080 uint64_t u8
= ZFS_PROP_UNDEFINED
;
3083 ASSERT(zplprops
!= NULL
);
3085 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
3086 return (SET_ERROR(EINVAL
));
3089 * Pull out creator prop choices, if any.
3092 (void) nvlist_lookup_uint64(createprops
,
3093 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
3094 (void) nvlist_lookup_uint64(createprops
,
3095 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
3096 (void) nvlist_remove_all(createprops
,
3097 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3098 (void) nvlist_lookup_uint64(createprops
,
3099 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3100 (void) nvlist_remove_all(createprops
,
3101 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3102 (void) nvlist_lookup_uint64(createprops
,
3103 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3104 (void) nvlist_remove_all(createprops
,
3105 zfs_prop_to_name(ZFS_PROP_CASE
));
3109 * If the zpl version requested is whacky or the file system
3110 * or pool is version is too "young" to support normalization
3111 * and the creator tried to set a value for one of the props,
3114 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3115 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3116 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3117 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3118 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3119 sense
!= ZFS_PROP_UNDEFINED
)))
3120 return (SET_ERROR(ENOTSUP
));
3123 * Put the version in the zplprops
3125 VERIFY(nvlist_add_uint64(zplprops
,
3126 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3128 if (norm
== ZFS_PROP_UNDEFINED
&&
3129 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3131 VERIFY(nvlist_add_uint64(zplprops
,
3132 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3135 * If we're normalizing, names must always be valid UTF-8 strings.
3139 if (u8
== ZFS_PROP_UNDEFINED
&&
3140 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3142 VERIFY(nvlist_add_uint64(zplprops
,
3143 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3145 if (sense
== ZFS_PROP_UNDEFINED
&&
3146 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3148 VERIFY(nvlist_add_uint64(zplprops
,
3149 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3152 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3158 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3159 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3161 boolean_t fuids_ok
, sa_ok
;
3162 uint64_t zplver
= ZPL_VERSION
;
3163 objset_t
*os
= NULL
;
3164 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3170 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3171 cp
= strrchr(parentname
, '/');
3175 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3178 spa_vers
= spa_version(spa
);
3179 spa_close(spa
, FTAG
);
3181 zplver
= zfs_zpl_version_map(spa_vers
);
3182 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3183 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3186 * Open parent object set so we can inherit zplprop values.
3188 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3191 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3193 dmu_objset_rele(os
, FTAG
);
3198 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3199 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3203 uint64_t zplver
= ZPL_VERSION
;
3206 zplver
= zfs_zpl_version_map(spa_vers
);
3207 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3208 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3210 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3211 createprops
, zplprops
, is_ci
);
3217 * "type" -> dmu_objset_type_t (int32)
3218 * (optional) "props" -> { prop -> value }
3219 * (optional) "hidden_args" -> { "wkeydata" -> value }
3220 * raw uint8_t array of encryption wrapping key data (32 bytes)
3223 * outnvl: propname -> error code (int32)
3226 static const zfs_ioc_key_t zfs_keys_create
[] = {
3227 {"type", DATA_TYPE_INT32
, 0},
3228 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3229 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3233 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3236 zfs_creat_t zct
= { 0 };
3237 nvlist_t
*nvprops
= NULL
;
3238 nvlist_t
*hidden_args
= NULL
;
3239 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3240 dmu_objset_type_t type
;
3241 boolean_t is_insensitive
= B_FALSE
;
3242 dsl_crypto_params_t
*dcp
= NULL
;
3244 type
= (dmu_objset_type_t
)fnvlist_lookup_int32(innvl
, "type");
3245 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3246 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
3250 cbfunc
= zfs_create_cb
;
3254 cbfunc
= zvol_create_cb
;
3261 if (strchr(fsname
, '@') ||
3262 strchr(fsname
, '%'))
3263 return (SET_ERROR(EINVAL
));
3265 zct
.zct_props
= nvprops
;
3268 return (SET_ERROR(EINVAL
));
3270 if (type
== DMU_OST_ZVOL
) {
3271 uint64_t volsize
, volblocksize
;
3273 if (nvprops
== NULL
)
3274 return (SET_ERROR(EINVAL
));
3275 if (nvlist_lookup_uint64(nvprops
,
3276 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3277 return (SET_ERROR(EINVAL
));
3279 if ((error
= nvlist_lookup_uint64(nvprops
,
3280 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3281 &volblocksize
)) != 0 && error
!= ENOENT
)
3282 return (SET_ERROR(EINVAL
));
3285 volblocksize
= zfs_prop_default_numeric(
3286 ZFS_PROP_VOLBLOCKSIZE
);
3288 if ((error
= zvol_check_volblocksize(fsname
,
3289 volblocksize
)) != 0 ||
3290 (error
= zvol_check_volsize(volsize
,
3291 volblocksize
)) != 0)
3293 } else if (type
== DMU_OST_ZFS
) {
3297 * We have to have normalization and
3298 * case-folding flags correct when we do the
3299 * file system creation, so go figure them out
3302 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3303 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3304 error
= zfs_fill_zplprops(fsname
, nvprops
,
3305 zct
.zct_zplprops
, &is_insensitive
);
3307 nvlist_free(zct
.zct_zplprops
);
3312 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, nvprops
,
3315 nvlist_free(zct
.zct_zplprops
);
3319 error
= dmu_objset_create(fsname
, type
,
3320 is_insensitive
? DS_FLAG_CI_DATASET
: 0, dcp
, cbfunc
, &zct
);
3322 nvlist_free(zct
.zct_zplprops
);
3323 dsl_crypto_params_free(dcp
, !!error
);
3326 * It would be nice to do this atomically.
3329 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3336 * Volumes will return EBUSY and cannot be destroyed
3337 * until all asynchronous minor handling has completed.
3338 * Wait for the spa_zvol_taskq to drain then retry.
3340 error2
= dsl_destroy_head(fsname
);
3341 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3342 error2
= spa_open(fsname
, &spa
, FTAG
);
3344 taskq_wait(spa
->spa_zvol_taskq
);
3345 spa_close(spa
, FTAG
);
3347 error2
= dsl_destroy_head(fsname
);
3356 * "origin" -> name of origin snapshot
3357 * (optional) "props" -> { prop -> value }
3358 * (optional) "hidden_args" -> { "wkeydata" -> value }
3359 * raw uint8_t array of encryption wrapping key data (32 bytes)
3363 * outnvl: propname -> error code (int32)
3365 static const zfs_ioc_key_t zfs_keys_clone
[] = {
3366 {"origin", DATA_TYPE_STRING
, 0},
3367 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3368 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3372 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3375 nvlist_t
*nvprops
= NULL
;
3378 origin_name
= fnvlist_lookup_string(innvl
, "origin");
3379 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3381 if (strchr(fsname
, '@') ||
3382 strchr(fsname
, '%'))
3383 return (SET_ERROR(EINVAL
));
3385 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3386 return (SET_ERROR(EINVAL
));
3388 error
= dmu_objset_clone(fsname
, origin_name
);
3391 * It would be nice to do this atomically.
3394 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3397 (void) dsl_destroy_head(fsname
);
3402 static const zfs_ioc_key_t zfs_keys_remap
[] = {
3408 zfs_ioc_remap(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3410 if (strchr(fsname
, '@') ||
3411 strchr(fsname
, '%'))
3412 return (SET_ERROR(EINVAL
));
3414 return (dmu_objset_remap_indirects(fsname
));
3419 * "snaps" -> { snapshot1, snapshot2 }
3420 * (optional) "props" -> { prop -> value (string) }
3423 * outnvl: snapshot -> error code (int32)
3425 static const zfs_ioc_key_t zfs_keys_snapshot
[] = {
3426 {"snaps", DATA_TYPE_NVLIST
, 0},
3427 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3431 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3434 nvlist_t
*props
= NULL
;
3438 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3439 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3442 if (!nvlist_empty(props
) &&
3443 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3444 return (SET_ERROR(ENOTSUP
));
3446 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
3447 poollen
= strlen(poolname
);
3448 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3449 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3450 const char *name
= nvpair_name(pair
);
3451 const char *cp
= strchr(name
, '@');
3454 * The snap name must contain an @, and the part after it must
3455 * contain only valid characters.
3458 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3459 return (SET_ERROR(EINVAL
));
3462 * The snap must be in the specified pool.
3464 if (strncmp(name
, poolname
, poollen
) != 0 ||
3465 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3466 return (SET_ERROR(EXDEV
));
3468 /* This must be the only snap of this fs. */
3469 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3470 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3471 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3473 return (SET_ERROR(EXDEV
));
3478 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3484 * innvl: "message" -> string
3486 static const zfs_ioc_key_t zfs_keys_log_history
[] = {
3487 {"message", DATA_TYPE_STRING
, 0},
3492 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3500 * The poolname in the ioctl is not set, we get it from the TSD,
3501 * which was set at the end of the last successful ioctl that allows
3502 * logging. The secpolicy func already checked that it is set.
3503 * Only one log ioctl is allowed after each successful ioctl, so
3504 * we clear the TSD here.
3506 poolname
= tsd_get(zfs_allow_log_key
);
3507 if (poolname
== NULL
)
3508 return (SET_ERROR(EINVAL
));
3509 (void) tsd_set(zfs_allow_log_key
, NULL
);
3510 error
= spa_open(poolname
, &spa
, FTAG
);
3515 message
= fnvlist_lookup_string(innvl
, "message");
3517 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3518 spa_close(spa
, FTAG
);
3519 return (SET_ERROR(ENOTSUP
));
3522 error
= spa_history_log(spa
, message
);
3523 spa_close(spa
, FTAG
);
3528 * The dp_config_rwlock must not be held when calling this, because the
3529 * unmount may need to write out data.
3531 * This function is best-effort. Callers must deal gracefully if it
3532 * remains mounted (or is remounted after this call).
3534 * Returns 0 if the argument is not a snapshot, or it is not currently a
3535 * filesystem, or we were able to unmount it. Returns error code otherwise.
3538 zfs_unmount_snap(const char *snapname
)
3540 if (strchr(snapname
, '@') == NULL
)
3543 (void) zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3548 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3550 zfs_unmount_snap(snapname
);
3555 * When a clone is destroyed, its origin may also need to be destroyed,
3556 * in which case it must be unmounted. This routine will do that unmount
3560 zfs_destroy_unmount_origin(const char *fsname
)
3566 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3569 ds
= dmu_objset_ds(os
);
3570 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3571 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3572 dsl_dataset_name(ds
->ds_prev
, originname
);
3573 dmu_objset_rele(os
, FTAG
);
3574 zfs_unmount_snap(originname
);
3576 dmu_objset_rele(os
, FTAG
);
3582 * "snaps" -> { snapshot1, snapshot2 }
3583 * (optional boolean) "defer"
3586 * outnvl: snapshot -> error code (int32)
3588 static const zfs_ioc_key_t zfs_keys_destroy_snaps
[] = {
3589 {"snaps", DATA_TYPE_NVLIST
, 0},
3590 {"defer", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
3595 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3601 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
3602 defer
= nvlist_exists(innvl
, "defer");
3604 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3605 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3606 zfs_unmount_snap(nvpair_name(pair
));
3609 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3613 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3614 * All bookmarks must be in the same pool.
3617 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3620 * outnvl: bookmark -> error code (int32)
3623 static const zfs_ioc_key_t zfs_keys_bookmark
[] = {
3624 {"<bookmark>...", DATA_TYPE_STRING
, ZK_WILDCARDLIST
},
3629 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3631 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3632 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3636 * Verify the snapshot argument.
3638 if (nvpair_value_string(pair
, &snap_name
) != 0)
3639 return (SET_ERROR(EINVAL
));
3642 /* Verify that the keys (bookmarks) are unique */
3643 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3644 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3645 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3646 return (SET_ERROR(EINVAL
));
3650 return (dsl_bookmark_create(innvl
, outnvl
));
3655 * property 1, property 2, ...
3659 * bookmark name 1 -> { property 1, property 2, ... },
3660 * bookmark name 2 -> { property 1, property 2, ... }
3664 static const zfs_ioc_key_t zfs_keys_get_bookmarks
[] = {
3665 {"<property>...", DATA_TYPE_BOOLEAN
, ZK_WILDCARDLIST
| ZK_OPTIONAL
},
3669 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3671 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3676 * bookmark name 1, bookmark name 2
3679 * outnvl: bookmark -> error code (int32)
3682 static const zfs_ioc_key_t zfs_keys_destroy_bookmarks
[] = {
3683 {"<bookmark>...", DATA_TYPE_BOOLEAN
, ZK_WILDCARDLIST
},
3687 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3692 poollen
= strlen(poolname
);
3693 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3694 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3695 const char *name
= nvpair_name(pair
);
3696 const char *cp
= strchr(name
, '#');
3699 * The bookmark name must contain an #, and the part after it
3700 * must contain only valid characters.
3703 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3704 return (SET_ERROR(EINVAL
));
3707 * The bookmark must be in the specified pool.
3709 if (strncmp(name
, poolname
, poollen
) != 0 ||
3710 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3711 return (SET_ERROR(EXDEV
));
3714 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3718 static const zfs_ioc_key_t zfs_keys_channel_program
[] = {
3719 {"program", DATA_TYPE_STRING
, 0},
3720 {"arg", DATA_TYPE_ANY
, 0},
3721 {"sync", DATA_TYPE_BOOLEAN_VALUE
, ZK_OPTIONAL
},
3722 {"instrlimit", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
3723 {"memlimit", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
3727 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3731 uint64_t instrlimit
, memlimit
;
3732 boolean_t sync_flag
;
3733 nvpair_t
*nvarg
= NULL
;
3735 program
= fnvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
);
3736 if (0 != nvlist_lookup_boolean_value(innvl
, ZCP_ARG_SYNC
, &sync_flag
)) {
3739 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3740 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3742 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3743 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3745 nvarg
= fnvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
);
3747 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3749 if (memlimit
== 0 || memlimit
> zfs_lua_max_memlimit
)
3752 return (zcp_eval(poolname
, program
, sync_flag
, instrlimit
, memlimit
,
3760 static const zfs_ioc_key_t zfs_keys_pool_checkpoint
[] = {
3766 zfs_ioc_pool_checkpoint(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3768 return (spa_checkpoint(poolname
));
3775 static const zfs_ioc_key_t zfs_keys_pool_discard_checkpoint
[] = {
3781 zfs_ioc_pool_discard_checkpoint(const char *poolname
, nvlist_t
*innvl
,
3784 return (spa_checkpoint_discard(poolname
));
3789 * zc_name name of dataset to destroy
3790 * zc_defer_destroy mark for deferred destroy
3795 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3798 dmu_objset_type_t ost
;
3801 err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
3804 ost
= dmu_objset_type(os
);
3805 dmu_objset_rele(os
, FTAG
);
3807 if (ost
== DMU_OST_ZFS
)
3808 zfs_unmount_snap(zc
->zc_name
);
3810 if (strchr(zc
->zc_name
, '@')) {
3811 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3813 err
= dsl_destroy_head(zc
->zc_name
);
3814 if (err
== EEXIST
) {
3816 * It is possible that the given DS may have
3817 * hidden child (%recv) datasets - "leftovers"
3818 * resulting from the previously interrupted
3821 * 6 extra bytes for /%recv
3823 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3825 if (snprintf(namebuf
, sizeof (namebuf
), "%s/%s",
3826 zc
->zc_name
, recv_clone_name
) >=
3828 return (SET_ERROR(EINVAL
));
3831 * Try to remove the hidden child (%recv) and after
3832 * that try to remove the target dataset.
3833 * If the hidden child (%recv) does not exist
3834 * the original error (EEXIST) will be returned
3836 err
= dsl_destroy_head(namebuf
);
3838 err
= dsl_destroy_head(zc
->zc_name
);
3839 else if (err
== ENOENT
)
3840 err
= SET_ERROR(EEXIST
);
3849 * "initialize_command" -> POOL_INITIALIZE_{CANCEL|DO|SUSPEND} (uint64)
3850 * "initialize_vdevs": { -> guids to initialize (nvlist)
3851 * "vdev_path_1": vdev_guid_1, (uint64),
3852 * "vdev_path_2": vdev_guid_2, (uint64),
3858 * "initialize_vdevs": { -> initialization errors (nvlist)
3859 * "vdev_path_1": errno, see function body for possible errnos (uint64)
3860 * "vdev_path_2": errno, ... (uint64)
3865 * EINVAL is returned for an unknown commands or if any of the provided vdev
3866 * guids have be specified with a type other than uint64.
3868 static const zfs_ioc_key_t zfs_keys_pool_initialize
[] = {
3869 {ZPOOL_INITIALIZE_COMMAND
, DATA_TYPE_UINT64
, 0},
3870 {ZPOOL_INITIALIZE_VDEVS
, DATA_TYPE_NVLIST
, 0}
3874 zfs_ioc_pool_initialize(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3877 if (nvlist_lookup_uint64(innvl
, ZPOOL_INITIALIZE_COMMAND
,
3879 return (SET_ERROR(EINVAL
));
3882 if (!(cmd_type
== POOL_INITIALIZE_CANCEL
||
3883 cmd_type
== POOL_INITIALIZE_DO
||
3884 cmd_type
== POOL_INITIALIZE_SUSPEND
)) {
3885 return (SET_ERROR(EINVAL
));
3888 nvlist_t
*vdev_guids
;
3889 if (nvlist_lookup_nvlist(innvl
, ZPOOL_INITIALIZE_VDEVS
,
3890 &vdev_guids
) != 0) {
3891 return (SET_ERROR(EINVAL
));
3894 for (nvpair_t
*pair
= nvlist_next_nvpair(vdev_guids
, NULL
);
3895 pair
!= NULL
; pair
= nvlist_next_nvpair(vdev_guids
, pair
)) {
3897 if (nvpair_value_uint64(pair
, &vdev_guid
) != 0) {
3898 return (SET_ERROR(EINVAL
));
3903 int error
= spa_open(poolname
, &spa
, FTAG
);
3907 nvlist_t
*vdev_errlist
= fnvlist_alloc();
3908 int total_errors
= spa_vdev_initialize(spa
, vdev_guids
, cmd_type
,
3911 if (fnvlist_size(vdev_errlist
) > 0) {
3912 fnvlist_add_nvlist(outnvl
, ZPOOL_INITIALIZE_VDEVS
,
3915 fnvlist_free(vdev_errlist
);
3917 spa_close(spa
, FTAG
);
3918 return (total_errors
> 0 ? EINVAL
: 0);
3922 * fsname is name of dataset to rollback (to most recent snapshot)
3924 * innvl may contain name of expected target snapshot
3926 * outnvl: "target" -> name of most recent snapshot
3929 static const zfs_ioc_key_t zfs_keys_rollback
[] = {
3930 {"target", DATA_TYPE_STRING
, ZK_OPTIONAL
},
3935 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3939 char *target
= NULL
;
3942 (void) nvlist_lookup_string(innvl
, "target", &target
);
3943 if (target
!= NULL
) {
3944 const char *cp
= strchr(target
, '@');
3947 * The snap name must contain an @, and the part after it must
3948 * contain only valid characters.
3951 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3952 return (SET_ERROR(EINVAL
));
3955 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3958 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3959 error
= zfs_suspend_fs(zfsvfs
);
3963 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3965 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3966 error
= error
? error
: resume_err
;
3968 deactivate_super(zfsvfs
->z_sb
);
3969 } else if ((zv
= zvol_suspend(fsname
)) != NULL
) {
3970 error
= dsl_dataset_rollback(fsname
, target
, zvol_tag(zv
),
3974 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3980 recursive_unmount(const char *fsname
, void *arg
)
3982 const char *snapname
= arg
;
3985 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3986 zfs_unmount_snap(fullname
);
3994 * zc_name old name of dataset
3995 * zc_value new name of dataset
3996 * zc_cookie recursive flag (only valid for snapshots)
4001 zfs_ioc_rename(zfs_cmd_t
*zc
)
4004 dmu_objset_type_t ost
;
4005 boolean_t recursive
= zc
->zc_cookie
& 1;
4009 /* "zfs rename" from and to ...%recv datasets should both fail */
4010 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
4011 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
4012 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
4013 dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4014 strchr(zc
->zc_name
, '%') || strchr(zc
->zc_value
, '%'))
4015 return (SET_ERROR(EINVAL
));
4017 err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4020 ost
= dmu_objset_type(os
);
4021 dmu_objset_rele(os
, FTAG
);
4023 at
= strchr(zc
->zc_name
, '@');
4025 /* snaps must be in same fs */
4028 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
4029 return (SET_ERROR(EXDEV
));
4031 if (ost
== DMU_OST_ZFS
) {
4032 error
= dmu_objset_find(zc
->zc_name
,
4033 recursive_unmount
, at
+ 1,
4034 recursive
? DS_FIND_CHILDREN
: 0);
4040 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
4041 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
4046 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
4051 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
4053 const char *propname
= nvpair_name(pair
);
4054 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
4055 zfs_prop_t prop
= zfs_name_to_prop(propname
);
4059 if (prop
== ZPROP_INVAL
) {
4060 if (zfs_prop_user(propname
)) {
4061 if ((err
= zfs_secpolicy_write_perms(dsname
,
4062 ZFS_DELEG_PERM_USERPROP
, cr
)))
4067 if (!issnap
&& zfs_prop_userquota(propname
)) {
4068 const char *perm
= NULL
;
4069 const char *uq_prefix
=
4070 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
4071 const char *gq_prefix
=
4072 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
4073 const char *uiq_prefix
=
4074 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
];
4075 const char *giq_prefix
=
4076 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
];
4077 const char *pq_prefix
=
4078 zfs_userquota_prop_prefixes
[ZFS_PROP_PROJECTQUOTA
];
4079 const char *piq_prefix
= zfs_userquota_prop_prefixes
[\
4080 ZFS_PROP_PROJECTOBJQUOTA
];
4082 if (strncmp(propname
, uq_prefix
,
4083 strlen(uq_prefix
)) == 0) {
4084 perm
= ZFS_DELEG_PERM_USERQUOTA
;
4085 } else if (strncmp(propname
, uiq_prefix
,
4086 strlen(uiq_prefix
)) == 0) {
4087 perm
= ZFS_DELEG_PERM_USEROBJQUOTA
;
4088 } else if (strncmp(propname
, gq_prefix
,
4089 strlen(gq_prefix
)) == 0) {
4090 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
4091 } else if (strncmp(propname
, giq_prefix
,
4092 strlen(giq_prefix
)) == 0) {
4093 perm
= ZFS_DELEG_PERM_GROUPOBJQUOTA
;
4094 } else if (strncmp(propname
, pq_prefix
,
4095 strlen(pq_prefix
)) == 0) {
4096 perm
= ZFS_DELEG_PERM_PROJECTQUOTA
;
4097 } else if (strncmp(propname
, piq_prefix
,
4098 strlen(piq_prefix
)) == 0) {
4099 perm
= ZFS_DELEG_PERM_PROJECTOBJQUOTA
;
4101 /* {USER|GROUP|PROJECT}USED are read-only */
4102 return (SET_ERROR(EINVAL
));
4105 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
4110 return (SET_ERROR(EINVAL
));
4114 return (SET_ERROR(EINVAL
));
4116 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
4118 * dsl_prop_get_all_impl() returns properties in this
4122 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
4123 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4128 * Check that this value is valid for this pool version
4131 case ZFS_PROP_COMPRESSION
:
4133 * If the user specified gzip compression, make sure
4134 * the SPA supports it. We ignore any errors here since
4135 * we'll catch them later.
4137 if (nvpair_value_uint64(pair
, &intval
) == 0) {
4138 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
4139 intval
<= ZIO_COMPRESS_GZIP_9
&&
4140 zfs_earlier_version(dsname
,
4141 SPA_VERSION_GZIP_COMPRESSION
)) {
4142 return (SET_ERROR(ENOTSUP
));
4145 if (intval
== ZIO_COMPRESS_ZLE
&&
4146 zfs_earlier_version(dsname
,
4147 SPA_VERSION_ZLE_COMPRESSION
))
4148 return (SET_ERROR(ENOTSUP
));
4150 if (intval
== ZIO_COMPRESS_LZ4
) {
4153 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4156 if (!spa_feature_is_enabled(spa
,
4157 SPA_FEATURE_LZ4_COMPRESS
)) {
4158 spa_close(spa
, FTAG
);
4159 return (SET_ERROR(ENOTSUP
));
4161 spa_close(spa
, FTAG
);
4165 * If this is a bootable dataset then
4166 * verify that the compression algorithm
4167 * is supported for booting. We must return
4168 * something other than ENOTSUP since it
4169 * implies a downrev pool version.
4171 if (zfs_is_bootfs(dsname
) &&
4172 !BOOTFS_COMPRESS_VALID(intval
)) {
4173 return (SET_ERROR(ERANGE
));
4178 case ZFS_PROP_COPIES
:
4179 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
4180 return (SET_ERROR(ENOTSUP
));
4183 case ZFS_PROP_VOLBLOCKSIZE
:
4184 case ZFS_PROP_RECORDSIZE
:
4185 /* Record sizes above 128k need the feature to be enabled */
4186 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4187 intval
> SPA_OLD_MAXBLOCKSIZE
) {
4191 * We don't allow setting the property above 1MB,
4192 * unless the tunable has been changed.
4194 if (intval
> zfs_max_recordsize
||
4195 intval
> SPA_MAXBLOCKSIZE
)
4196 return (SET_ERROR(ERANGE
));
4198 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4201 if (!spa_feature_is_enabled(spa
,
4202 SPA_FEATURE_LARGE_BLOCKS
)) {
4203 spa_close(spa
, FTAG
);
4204 return (SET_ERROR(ENOTSUP
));
4206 spa_close(spa
, FTAG
);
4210 case ZFS_PROP_DNODESIZE
:
4211 /* Dnode sizes above 512 need the feature to be enabled */
4212 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4213 intval
!= ZFS_DNSIZE_LEGACY
) {
4217 * If this is a bootable dataset then
4218 * we don't allow large (>512B) dnodes,
4219 * because GRUB doesn't support them.
4221 if (zfs_is_bootfs(dsname
) &&
4222 intval
!= ZFS_DNSIZE_LEGACY
) {
4223 return (SET_ERROR(EDOM
));
4226 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4229 if (!spa_feature_is_enabled(spa
,
4230 SPA_FEATURE_LARGE_DNODE
)) {
4231 spa_close(spa
, FTAG
);
4232 return (SET_ERROR(ENOTSUP
));
4234 spa_close(spa
, FTAG
);
4238 case ZFS_PROP_SPECIAL_SMALL_BLOCKS
:
4240 * This property could require the allocation classes
4241 * feature to be active for setting, however we allow
4242 * it so that tests of settable properties succeed.
4243 * The CLI will issue a warning in this case.
4247 case ZFS_PROP_SHARESMB
:
4248 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
4249 return (SET_ERROR(ENOTSUP
));
4252 case ZFS_PROP_ACLINHERIT
:
4253 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4254 nvpair_value_uint64(pair
, &intval
) == 0) {
4255 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
4256 zfs_earlier_version(dsname
,
4257 SPA_VERSION_PASSTHROUGH_X
))
4258 return (SET_ERROR(ENOTSUP
));
4261 case ZFS_PROP_CHECKSUM
:
4262 case ZFS_PROP_DEDUP
:
4264 spa_feature_t feature
;
4268 /* dedup feature version checks */
4269 if (prop
== ZFS_PROP_DEDUP
&&
4270 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
4271 return (SET_ERROR(ENOTSUP
));
4273 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4274 nvpair_value_uint64(pair
, &intval
) == 0) {
4275 /* check prop value is enabled in features */
4276 feature
= zio_checksum_to_feature(
4277 intval
& ZIO_CHECKSUM_MASK
);
4278 if (feature
== SPA_FEATURE_NONE
)
4281 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4284 if (!spa_feature_is_enabled(spa
, feature
)) {
4285 spa_close(spa
, FTAG
);
4286 return (SET_ERROR(ENOTSUP
));
4288 spa_close(spa
, FTAG
);
4297 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
4301 * Removes properties from the given props list that fail permission checks
4302 * needed to clear them and to restore them in case of a receive error. For each
4303 * property, make sure we have both set and inherit permissions.
4305 * Returns the first error encountered if any permission checks fail. If the
4306 * caller provides a non-NULL errlist, it also gives the complete list of names
4307 * of all the properties that failed a permission check along with the
4308 * corresponding error numbers. The caller is responsible for freeing the
4311 * If every property checks out successfully, zero is returned and the list
4312 * pointed at by errlist is NULL.
4315 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
4318 nvpair_t
*pair
, *next_pair
;
4325 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4327 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
4328 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
4329 pair
= nvlist_next_nvpair(props
, NULL
);
4330 while (pair
!= NULL
) {
4331 next_pair
= nvlist_next_nvpair(props
, pair
);
4333 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
4334 sizeof (zc
->zc_value
));
4335 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
4336 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
4337 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
4338 VERIFY(nvlist_add_int32(errors
,
4339 zc
->zc_value
, err
) == 0);
4343 kmem_free(zc
, sizeof (zfs_cmd_t
));
4345 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
4346 nvlist_free(errors
);
4349 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
4352 if (errlist
== NULL
)
4353 nvlist_free(errors
);
4361 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4363 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4364 /* dsl_prop_get_all_impl() format */
4366 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4367 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4371 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4373 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4374 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4378 if (nvpair_type(p1
) != nvpair_type(p2
))
4381 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4382 char *valstr1
, *valstr2
;
4384 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4385 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4386 return (strcmp(valstr1
, valstr2
) == 0);
4388 uint64_t intval1
, intval2
;
4390 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4391 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4392 return (intval1
== intval2
);
4397 * Remove properties from props if they are not going to change (as determined
4398 * by comparison with origprops). Remove them from origprops as well, since we
4399 * do not need to clear or restore properties that won't change.
4402 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4404 nvpair_t
*pair
, *next_pair
;
4406 if (origprops
== NULL
)
4407 return; /* all props need to be received */
4409 pair
= nvlist_next_nvpair(props
, NULL
);
4410 while (pair
!= NULL
) {
4411 const char *propname
= nvpair_name(pair
);
4414 next_pair
= nvlist_next_nvpair(props
, pair
);
4416 if ((nvlist_lookup_nvpair(origprops
, propname
,
4417 &match
) != 0) || !propval_equals(pair
, match
))
4418 goto next
; /* need to set received value */
4420 /* don't clear the existing received value */
4421 (void) nvlist_remove_nvpair(origprops
, match
);
4422 /* don't bother receiving the property */
4423 (void) nvlist_remove_nvpair(props
, pair
);
4430 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4431 * For example, refquota cannot be set until after the receipt of a dataset,
4432 * because in replication streams, an older/earlier snapshot may exceed the
4433 * refquota. We want to receive the older/earlier snapshot, but setting
4434 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4435 * the older/earlier snapshot from being received (with EDQUOT).
4437 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4439 * libzfs will need to be judicious handling errors encountered by props
4440 * extracted by this function.
4443 extract_delay_props(nvlist_t
*props
)
4445 nvlist_t
*delayprops
;
4446 nvpair_t
*nvp
, *tmp
;
4447 static const zfs_prop_t delayable
[] = {
4449 ZFS_PROP_KEYLOCATION
,
4454 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4456 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4457 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4459 * strcmp() is safe because zfs_prop_to_name() always returns
4462 for (i
= 0; delayable
[i
] != 0; i
++) {
4463 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4464 nvpair_name(nvp
)) == 0) {
4468 if (delayable
[i
] != 0) {
4469 tmp
= nvlist_prev_nvpair(props
, nvp
);
4470 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4471 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4476 if (nvlist_empty(delayprops
)) {
4477 nvlist_free(delayprops
);
4480 return (delayprops
);
4484 static boolean_t zfs_ioc_recv_inject_err
;
4488 * nvlist 'errors' is always allocated. It will contain descriptions of
4489 * encountered errors, if any. It's the callers responsibility to free.
4492 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
, nvlist_t
*recvprops
,
4493 nvlist_t
*localprops
, nvlist_t
*hidden_args
, boolean_t force
,
4494 boolean_t resumable
, int input_fd
, dmu_replay_record_t
*begin_record
,
4495 int cleanup_fd
, uint64_t *read_bytes
, uint64_t *errflags
,
4496 uint64_t *action_handle
, nvlist_t
**errors
)
4498 dmu_recv_cookie_t drc
;
4500 int props_error
= 0;
4502 nvlist_t
*local_delayprops
= NULL
;
4503 nvlist_t
*recv_delayprops
= NULL
;
4504 nvlist_t
*origprops
= NULL
; /* existing properties */
4505 nvlist_t
*origrecvd
= NULL
; /* existing received properties */
4506 boolean_t first_recvd_props
= B_FALSE
;
4511 *errors
= fnvlist_alloc();
4513 input_fp
= getf(input_fd
);
4514 if (input_fp
== NULL
)
4515 return (SET_ERROR(EBADF
));
4517 error
= dmu_recv_begin(tofs
, tosnap
, begin_record
, force
,
4518 resumable
, localprops
, hidden_args
, origin
, &drc
);
4523 * Set properties before we receive the stream so that they are applied
4524 * to the new data. Note that we must call dmu_recv_stream() if
4525 * dmu_recv_begin() succeeds.
4527 if (recvprops
!= NULL
&& !drc
.drc_newfs
) {
4528 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4529 SPA_VERSION_RECVD_PROPS
&&
4530 !dsl_prop_get_hasrecvd(tofs
))
4531 first_recvd_props
= B_TRUE
;
4534 * If new received properties are supplied, they are to
4535 * completely replace the existing received properties,
4536 * so stash away the existing ones.
4538 if (dsl_prop_get_received(tofs
, &origrecvd
) == 0) {
4539 nvlist_t
*errlist
= NULL
;
4541 * Don't bother writing a property if its value won't
4542 * change (and avoid the unnecessary security checks).
4544 * The first receive after SPA_VERSION_RECVD_PROPS is a
4545 * special case where we blow away all local properties
4548 if (!first_recvd_props
)
4549 props_reduce(recvprops
, origrecvd
);
4550 if (zfs_check_clearable(tofs
, origrecvd
, &errlist
) != 0)
4551 (void) nvlist_merge(*errors
, errlist
, 0);
4552 nvlist_free(errlist
);
4554 if (clear_received_props(tofs
, origrecvd
,
4555 first_recvd_props
? NULL
: recvprops
) != 0)
4556 *errflags
|= ZPROP_ERR_NOCLEAR
;
4558 *errflags
|= ZPROP_ERR_NOCLEAR
;
4563 * Stash away existing properties so we can restore them on error unless
4564 * we're doing the first receive after SPA_VERSION_RECVD_PROPS, in which
4565 * case "origrecvd" will take care of that.
4567 if (localprops
!= NULL
&& !drc
.drc_newfs
&& !first_recvd_props
) {
4569 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
4570 if (dsl_prop_get_all(os
, &origprops
) != 0) {
4571 *errflags
|= ZPROP_ERR_NOCLEAR
;
4573 dmu_objset_rele(os
, FTAG
);
4575 *errflags
|= ZPROP_ERR_NOCLEAR
;
4579 if (recvprops
!= NULL
) {
4580 props_error
= dsl_prop_set_hasrecvd(tofs
);
4582 if (props_error
== 0) {
4583 recv_delayprops
= extract_delay_props(recvprops
);
4584 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4585 recvprops
, *errors
);
4589 if (localprops
!= NULL
) {
4590 nvlist_t
*oprops
= fnvlist_alloc();
4591 nvlist_t
*xprops
= fnvlist_alloc();
4592 nvpair_t
*nvp
= NULL
;
4594 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4595 if (nvpair_type(nvp
) == DATA_TYPE_BOOLEAN
) {
4597 const char *name
= nvpair_name(nvp
);
4598 zfs_prop_t prop
= zfs_name_to_prop(name
);
4599 if (prop
!= ZPROP_INVAL
) {
4600 if (!zfs_prop_inheritable(prop
))
4602 } else if (!zfs_prop_user(name
))
4604 fnvlist_add_boolean(xprops
, name
);
4606 /* -o property=value */
4607 fnvlist_add_nvpair(oprops
, nvp
);
4611 local_delayprops
= extract_delay_props(oprops
);
4612 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4614 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
,
4617 nvlist_free(oprops
);
4618 nvlist_free(xprops
);
4621 off
= input_fp
->f_offset
;
4622 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4626 zfsvfs_t
*zfsvfs
= NULL
;
4627 zvol_state_t
*zv
= NULL
;
4629 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4634 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4635 error
= zfs_suspend_fs(zfsvfs
);
4637 * If the suspend fails, then the recv_end will
4638 * likely also fail, and clean up after itself.
4640 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4642 error
= zfs_resume_fs(zfsvfs
, ds
);
4643 error
= error
? error
: end_err
;
4644 deactivate_super(zfsvfs
->z_sb
);
4645 } else if ((zv
= zvol_suspend(tofs
)) != NULL
) {
4646 error
= dmu_recv_end(&drc
, zvol_tag(zv
));
4649 error
= dmu_recv_end(&drc
, NULL
);
4652 /* Set delayed properties now, after we're done receiving. */
4653 if (recv_delayprops
!= NULL
&& error
== 0) {
4654 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4655 recv_delayprops
, *errors
);
4657 if (local_delayprops
!= NULL
&& error
== 0) {
4658 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4659 local_delayprops
, *errors
);
4664 * Merge delayed props back in with initial props, in case
4665 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4666 * we have to make sure clear_received_props() includes
4667 * the delayed properties).
4669 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4670 * using ASSERT() will be just like a VERIFY.
4672 if (recv_delayprops
!= NULL
) {
4673 ASSERT(nvlist_merge(recvprops
, recv_delayprops
, 0) == 0);
4674 nvlist_free(recv_delayprops
);
4676 if (local_delayprops
!= NULL
) {
4677 ASSERT(nvlist_merge(localprops
, local_delayprops
, 0) == 0);
4678 nvlist_free(local_delayprops
);
4681 *read_bytes
= off
- input_fp
->f_offset
;
4682 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4683 input_fp
->f_offset
= off
;
4686 if (zfs_ioc_recv_inject_err
) {
4687 zfs_ioc_recv_inject_err
= B_FALSE
;
4693 * On error, restore the original props.
4695 if (error
!= 0 && recvprops
!= NULL
&& !drc
.drc_newfs
) {
4696 if (clear_received_props(tofs
, recvprops
, NULL
) != 0) {
4698 * We failed to clear the received properties.
4699 * Since we may have left a $recvd value on the
4700 * system, we can't clear the $hasrecvd flag.
4702 *errflags
|= ZPROP_ERR_NORESTORE
;
4703 } else if (first_recvd_props
) {
4704 dsl_prop_unset_hasrecvd(tofs
);
4707 if (origrecvd
== NULL
&& !drc
.drc_newfs
) {
4708 /* We failed to stash the original properties. */
4709 *errflags
|= ZPROP_ERR_NORESTORE
;
4713 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4714 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4715 * explicitly if we're restoring local properties cleared in the
4716 * first new-style receive.
4718 if (origrecvd
!= NULL
&&
4719 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4720 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4721 origrecvd
, NULL
) != 0) {
4723 * We stashed the original properties but failed to
4726 *errflags
|= ZPROP_ERR_NORESTORE
;
4729 if (error
!= 0 && localprops
!= NULL
&& !drc
.drc_newfs
&&
4730 !first_recvd_props
) {
4732 nvlist_t
*inheritprops
;
4735 if (origprops
== NULL
) {
4736 /* We failed to stash the original properties. */
4737 *errflags
|= ZPROP_ERR_NORESTORE
;
4741 /* Restore original props */
4742 setprops
= fnvlist_alloc();
4743 inheritprops
= fnvlist_alloc();
4745 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4746 const char *name
= nvpair_name(nvp
);
4750 if (!nvlist_exists(origprops
, name
)) {
4752 * Property was not present or was explicitly
4753 * inherited before the receive, restore this.
4755 fnvlist_add_boolean(inheritprops
, name
);
4758 attrs
= fnvlist_lookup_nvlist(origprops
, name
);
4759 source
= fnvlist_lookup_string(attrs
, ZPROP_SOURCE
);
4761 /* Skip received properties */
4762 if (strcmp(source
, ZPROP_SOURCE_VAL_RECVD
) == 0)
4765 if (strcmp(source
, tofs
) == 0) {
4766 /* Property was locally set */
4767 fnvlist_add_nvlist(setprops
, name
, attrs
);
4769 /* Property was implicitly inherited */
4770 fnvlist_add_boolean(inheritprops
, name
);
4774 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
, setprops
,
4776 *errflags
|= ZPROP_ERR_NORESTORE
;
4777 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
, inheritprops
,
4779 *errflags
|= ZPROP_ERR_NORESTORE
;
4781 nvlist_free(setprops
);
4782 nvlist_free(inheritprops
);
4786 nvlist_free(origrecvd
);
4787 nvlist_free(origprops
);
4790 error
= props_error
;
4797 * zc_name name of containing filesystem (unused)
4798 * zc_nvlist_src{_size} nvlist of properties to apply
4799 * zc_nvlist_conf{_size} nvlist of properties to exclude
4800 * (DATA_TYPE_BOOLEAN) and override (everything else)
4801 * zc_value name of snapshot to create
4802 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4803 * zc_cookie file descriptor to recv from
4804 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4805 * zc_guid force flag
4806 * zc_cleanup_fd cleanup-on-exit file descriptor
4807 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4810 * zc_cookie number of bytes read
4811 * zc_obj zprop_errflags_t
4812 * zc_action_handle handle for this guid/ds mapping
4813 * zc_nvlist_dst{_size} error for each unapplied received property
4816 zfs_ioc_recv(zfs_cmd_t
*zc
)
4818 dmu_replay_record_t begin_record
;
4819 nvlist_t
*errors
= NULL
;
4820 nvlist_t
*recvdprops
= NULL
;
4821 nvlist_t
*localprops
= NULL
;
4822 char *origin
= NULL
;
4824 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4827 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4828 strchr(zc
->zc_value
, '@') == NULL
||
4829 strchr(zc
->zc_value
, '%'))
4830 return (SET_ERROR(EINVAL
));
4832 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4833 tosnap
= strchr(tofs
, '@');
4836 if (zc
->zc_nvlist_src
!= 0 &&
4837 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4838 zc
->zc_iflags
, &recvdprops
)) != 0)
4841 if (zc
->zc_nvlist_conf
!= 0 &&
4842 (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
4843 zc
->zc_iflags
, &localprops
)) != 0)
4846 if (zc
->zc_string
[0])
4847 origin
= zc
->zc_string
;
4849 begin_record
.drr_type
= DRR_BEGIN
;
4850 begin_record
.drr_payloadlen
= 0;
4851 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4853 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvdprops
, localprops
,
4854 NULL
, zc
->zc_guid
, B_FALSE
, zc
->zc_cookie
, &begin_record
,
4855 zc
->zc_cleanup_fd
, &zc
->zc_cookie
, &zc
->zc_obj
,
4856 &zc
->zc_action_handle
, &errors
);
4857 nvlist_free(recvdprops
);
4858 nvlist_free(localprops
);
4861 * Now that all props, initial and delayed, are set, report the prop
4862 * errors to the caller.
4864 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4865 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4866 put_nvlist(zc
, errors
) != 0)) {
4868 * Caller made zc->zc_nvlist_dst less than the minimum expected
4869 * size or supplied an invalid address.
4871 error
= SET_ERROR(EINVAL
);
4874 nvlist_free(errors
);
4881 * "snapname" -> full name of the snapshot to create
4882 * (optional) "props" -> received properties to set (nvlist)
4883 * (optional) "localprops" -> override and exclude properties (nvlist)
4884 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
4885 * "begin_record" -> non-byteswapped dmu_replay_record_t
4886 * "input_fd" -> file descriptor to read stream from (int32)
4887 * (optional) "force" -> force flag (value ignored)
4888 * (optional) "resumable" -> resumable flag (value ignored)
4889 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
4890 * (optional) "action_handle" -> handle for this guid/ds mapping
4891 * (optional) "hidden_args" -> { "wkeydata" -> value }
4895 * "read_bytes" -> number of bytes read
4896 * "error_flags" -> zprop_errflags_t
4897 * "action_handle" -> handle for this guid/ds mapping
4898 * "errors" -> error for each unapplied received property (nvlist)
4901 static const zfs_ioc_key_t zfs_keys_recv_new
[] = {
4902 {"snapname", DATA_TYPE_STRING
, 0},
4903 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
4904 {"localprops", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
4905 {"origin", DATA_TYPE_STRING
, ZK_OPTIONAL
},
4906 {"begin_record", DATA_TYPE_BYTE_ARRAY
, 0},
4907 {"input_fd", DATA_TYPE_INT32
, 0},
4908 {"force", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
4909 {"resumable", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
4910 {"cleanup_fd", DATA_TYPE_INT32
, ZK_OPTIONAL
},
4911 {"action_handle", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
4912 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
4916 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4918 dmu_replay_record_t
*begin_record
;
4919 uint_t begin_record_size
;
4920 nvlist_t
*errors
= NULL
;
4921 nvlist_t
*recvprops
= NULL
;
4922 nvlist_t
*localprops
= NULL
;
4923 nvlist_t
*hidden_args
= NULL
;
4925 char *origin
= NULL
;
4927 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4929 boolean_t resumable
;
4930 uint64_t action_handle
= 0;
4931 uint64_t read_bytes
= 0;
4932 uint64_t errflags
= 0;
4934 int cleanup_fd
= -1;
4937 snapname
= fnvlist_lookup_string(innvl
, "snapname");
4939 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
4940 strchr(snapname
, '@') == NULL
||
4941 strchr(snapname
, '%'))
4942 return (SET_ERROR(EINVAL
));
4944 (void) strcpy(tofs
, snapname
);
4945 tosnap
= strchr(tofs
, '@');
4948 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
4949 if (error
&& error
!= ENOENT
)
4952 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
4953 (uchar_t
**)&begin_record
, &begin_record_size
);
4954 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
4955 return (SET_ERROR(EINVAL
));
4957 input_fd
= fnvlist_lookup_int32(innvl
, "input_fd");
4959 force
= nvlist_exists(innvl
, "force");
4960 resumable
= nvlist_exists(innvl
, "resumable");
4962 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
4963 if (error
&& error
!= ENOENT
)
4966 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
4967 if (error
&& error
!= ENOENT
)
4970 /* we still use "props" here for backwards compatibility */
4971 error
= nvlist_lookup_nvlist(innvl
, "props", &recvprops
);
4972 if (error
&& error
!= ENOENT
)
4975 error
= nvlist_lookup_nvlist(innvl
, "localprops", &localprops
);
4976 if (error
&& error
!= ENOENT
)
4979 error
= nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
4980 if (error
&& error
!= ENOENT
)
4983 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvprops
, localprops
,
4984 hidden_args
, force
, resumable
, input_fd
, begin_record
, cleanup_fd
,
4985 &read_bytes
, &errflags
, &action_handle
, &errors
);
4987 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
4988 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
4989 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
4990 fnvlist_add_nvlist(outnvl
, "errors", errors
);
4992 nvlist_free(errors
);
4993 nvlist_free(recvprops
);
4994 nvlist_free(localprops
);
5001 * zc_name name of snapshot to send
5002 * zc_cookie file descriptor to send stream to
5003 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
5004 * zc_sendobj objsetid of snapshot to send
5005 * zc_fromobj objsetid of incremental fromsnap (may be zero)
5006 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
5007 * output size in zc_objset_type.
5008 * zc_flags lzc_send_flags
5011 * zc_objset_type estimated size, if zc_guid is set
5013 * NOTE: This is no longer the preferred interface, any new functionality
5014 * should be added to zfs_ioc_send_new() instead.
5017 zfs_ioc_send(zfs_cmd_t
*zc
)
5021 boolean_t estimate
= (zc
->zc_guid
!= 0);
5022 boolean_t embedok
= (zc
->zc_flags
& 0x1);
5023 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
5024 boolean_t compressok
= (zc
->zc_flags
& 0x4);
5025 boolean_t rawok
= (zc
->zc_flags
& 0x8);
5027 if (zc
->zc_obj
!= 0) {
5029 dsl_dataset_t
*tosnap
;
5031 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5035 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
5037 dsl_pool_rele(dp
, FTAG
);
5041 if (dsl_dir_is_clone(tosnap
->ds_dir
))
5043 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
5044 dsl_dataset_rele(tosnap
, FTAG
);
5045 dsl_pool_rele(dp
, FTAG
);
5050 dsl_dataset_t
*tosnap
;
5051 dsl_dataset_t
*fromsnap
= NULL
;
5053 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5057 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
,
5060 dsl_pool_rele(dp
, FTAG
);
5064 if (zc
->zc_fromobj
!= 0) {
5065 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
5068 dsl_dataset_rele(tosnap
, FTAG
);
5069 dsl_pool_rele(dp
, FTAG
);
5074 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
|| rawok
,
5075 &zc
->zc_objset_type
);
5077 if (fromsnap
!= NULL
)
5078 dsl_dataset_rele(fromsnap
, FTAG
);
5079 dsl_dataset_rele(tosnap
, FTAG
);
5080 dsl_pool_rele(dp
, FTAG
);
5082 file_t
*fp
= getf(zc
->zc_cookie
);
5084 return (SET_ERROR(EBADF
));
5087 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
5088 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
, rawok
,
5089 zc
->zc_cookie
, fp
->f_vnode
, &off
);
5091 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5093 releasef(zc
->zc_cookie
);
5100 * zc_name name of snapshot on which to report progress
5101 * zc_cookie file descriptor of send stream
5104 * zc_cookie number of bytes written in send stream thus far
5107 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
5111 dmu_sendarg_t
*dsp
= NULL
;
5114 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5118 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5120 dsl_pool_rele(dp
, FTAG
);
5124 mutex_enter(&ds
->ds_sendstream_lock
);
5127 * Iterate over all the send streams currently active on this dataset.
5128 * If there's one which matches the specified file descriptor _and_ the
5129 * stream was started by the current process, return the progress of
5133 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
5134 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
5135 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
5136 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
5141 zc
->zc_cookie
= *(dsp
->dsa_off
);
5143 error
= SET_ERROR(ENOENT
);
5145 mutex_exit(&ds
->ds_sendstream_lock
);
5146 dsl_dataset_rele(ds
, FTAG
);
5147 dsl_pool_rele(dp
, FTAG
);
5152 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
5156 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
5157 &zc
->zc_inject_record
);
5160 zc
->zc_guid
= (uint64_t)id
;
5166 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
5168 return (zio_clear_fault((int)zc
->zc_guid
));
5172 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
5174 int id
= (int)zc
->zc_guid
;
5177 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
5178 &zc
->zc_inject_record
);
5186 zfs_ioc_error_log(zfs_cmd_t
*zc
)
5190 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
5192 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
5195 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5198 zc
->zc_nvlist_dst_size
= count
;
5200 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
5202 spa_close(spa
, FTAG
);
5208 zfs_ioc_clear(zfs_cmd_t
*zc
)
5215 * On zpool clear we also fix up missing slogs
5217 mutex_enter(&spa_namespace_lock
);
5218 spa
= spa_lookup(zc
->zc_name
);
5220 mutex_exit(&spa_namespace_lock
);
5221 return (SET_ERROR(EIO
));
5223 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
5224 /* we need to let spa_open/spa_load clear the chains */
5225 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
5227 spa
->spa_last_open_failed
= 0;
5228 mutex_exit(&spa_namespace_lock
);
5230 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
5231 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
5234 nvlist_t
*config
= NULL
;
5236 if (zc
->zc_nvlist_src
== 0)
5237 return (SET_ERROR(EINVAL
));
5239 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5240 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
5241 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
5243 if (config
!= NULL
) {
5246 if ((err
= put_nvlist(zc
, config
)) != 0)
5248 nvlist_free(config
);
5250 nvlist_free(policy
);
5257 spa_vdev_state_enter(spa
, SCL_NONE
);
5259 if (zc
->zc_guid
== 0) {
5262 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
5264 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
5265 spa_close(spa
, FTAG
);
5266 return (SET_ERROR(ENODEV
));
5270 vdev_clear(spa
, vd
);
5272 (void) spa_vdev_state_exit(spa
, spa_suspended(spa
) ?
5273 NULL
: spa
->spa_root_vdev
, 0);
5276 * Resume any suspended I/Os.
5278 if (zio_resume(spa
) != 0)
5279 error
= SET_ERROR(EIO
);
5281 spa_close(spa
, FTAG
);
5287 * Reopen all the vdevs associated with the pool.
5290 * "scrub_restart" -> when true and scrub is running, allow to restart
5291 * scrub as the side effect of the reopen (boolean).
5296 static const zfs_ioc_key_t zfs_keys_pool_reopen
[] = {
5297 {"scrub_restart", DATA_TYPE_BOOLEAN_VALUE
, 0},
5302 zfs_ioc_pool_reopen(const char *pool
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5306 boolean_t scrub_restart
= B_TRUE
;
5309 scrub_restart
= fnvlist_lookup_boolean_value(innvl
,
5313 error
= spa_open(pool
, &spa
, FTAG
);
5317 spa_vdev_state_enter(spa
, SCL_NONE
);
5320 * If the scrub_restart flag is B_FALSE and a scrub is already
5321 * in progress then set spa_scrub_reopen flag to B_TRUE so that
5322 * we don't restart the scrub as a side effect of the reopen.
5323 * Otherwise, let vdev_open() decided if a resilver is required.
5326 spa
->spa_scrub_reopen
= (!scrub_restart
&&
5327 dsl_scan_scrubbing(spa
->spa_dsl_pool
));
5328 vdev_reopen(spa
->spa_root_vdev
);
5329 spa
->spa_scrub_reopen
= B_FALSE
;
5331 (void) spa_vdev_state_exit(spa
, NULL
, 0);
5332 spa_close(spa
, FTAG
);
5338 * zc_name name of filesystem
5341 * zc_string name of conflicting snapshot, if there is one
5344 zfs_ioc_promote(zfs_cmd_t
*zc
)
5347 dsl_dataset_t
*ds
, *ods
;
5348 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
5352 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5353 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
5354 strchr(zc
->zc_name
, '%'))
5355 return (SET_ERROR(EINVAL
));
5357 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5361 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5363 dsl_pool_rele(dp
, FTAG
);
5367 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
5368 dsl_dataset_rele(ds
, FTAG
);
5369 dsl_pool_rele(dp
, FTAG
);
5370 return (SET_ERROR(EINVAL
));
5373 error
= dsl_dataset_hold_obj(dp
,
5374 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
5376 dsl_dataset_rele(ds
, FTAG
);
5377 dsl_pool_rele(dp
, FTAG
);
5381 dsl_dataset_name(ods
, origin
);
5382 dsl_dataset_rele(ods
, FTAG
);
5383 dsl_dataset_rele(ds
, FTAG
);
5384 dsl_pool_rele(dp
, FTAG
);
5387 * We don't need to unmount *all* the origin fs's snapshots, but
5390 cp
= strchr(origin
, '@');
5393 (void) dmu_objset_find(origin
,
5394 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
5395 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
5399 * Retrieve a single {user|group|project}{used|quota}@... property.
5402 * zc_name name of filesystem
5403 * zc_objset_type zfs_userquota_prop_t
5404 * zc_value domain name (eg. "S-1-234-567-89")
5405 * zc_guid RID/UID/GID
5408 * zc_cookie property value
5411 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
5416 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
5417 return (SET_ERROR(EINVAL
));
5419 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5423 error
= zfs_userspace_one(zfsvfs
,
5424 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
5425 zfsvfs_rele(zfsvfs
, FTAG
);
5432 * zc_name name of filesystem
5433 * zc_cookie zap cursor
5434 * zc_objset_type zfs_userquota_prop_t
5435 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
5438 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
5439 * zc_cookie zap cursor
5442 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
5445 int bufsize
= zc
->zc_nvlist_dst_size
;
5448 return (SET_ERROR(ENOMEM
));
5450 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5454 void *buf
= vmem_alloc(bufsize
, KM_SLEEP
);
5456 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
5457 buf
, &zc
->zc_nvlist_dst_size
);
5460 error
= xcopyout(buf
,
5461 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5462 zc
->zc_nvlist_dst_size
);
5464 vmem_free(buf
, bufsize
);
5465 zfsvfs_rele(zfsvfs
, FTAG
);
5472 * zc_name name of filesystem
5478 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
5484 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
5485 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
5487 * If userused is not enabled, it may be because the
5488 * objset needs to be closed & reopened (to grow the
5489 * objset_phys_t). Suspend/resume the fs will do that.
5491 dsl_dataset_t
*ds
, *newds
;
5493 ds
= dmu_objset_ds(zfsvfs
->z_os
);
5494 error
= zfs_suspend_fs(zfsvfs
);
5496 dmu_objset_refresh_ownership(ds
, &newds
,
5498 error
= zfs_resume_fs(zfsvfs
, newds
);
5502 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
5503 deactivate_super(zfsvfs
->z_sb
);
5505 /* XXX kind of reading contents without owning */
5506 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5510 error
= dmu_objset_userspace_upgrade(os
);
5511 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
5519 * zc_name name of filesystem
5525 zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
)
5530 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5534 if (dmu_objset_userobjspace_upgradable(os
) ||
5535 dmu_objset_projectquota_upgradable(os
)) {
5536 mutex_enter(&os
->os_upgrade_lock
);
5537 if (os
->os_upgrade_id
== 0) {
5538 /* clear potential error code and retry */
5539 os
->os_upgrade_status
= 0;
5540 mutex_exit(&os
->os_upgrade_lock
);
5542 dmu_objset_id_quota_upgrade(os
);
5544 mutex_exit(&os
->os_upgrade_lock
);
5547 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5549 taskq_wait_id(os
->os_spa
->spa_upgrade_taskq
, os
->os_upgrade_id
);
5550 error
= os
->os_upgrade_status
;
5552 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5555 dsl_dataset_rele_flags(dmu_objset_ds(os
), DS_HOLD_FLAG_DECRYPT
, FTAG
);
5561 zfs_ioc_share(zfs_cmd_t
*zc
)
5563 return (SET_ERROR(ENOSYS
));
5566 ace_t full_access
[] = {
5567 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
5572 * zc_name name of containing filesystem
5573 * zc_obj object # beyond which we want next in-use object #
5576 * zc_obj next in-use object #
5579 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
5581 objset_t
*os
= NULL
;
5584 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
5588 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
5590 dmu_objset_rele(os
, FTAG
);
5596 * zc_name name of filesystem
5597 * zc_value prefix name for snapshot
5598 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5601 * zc_value short name of new snapshot
5604 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5611 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5615 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5616 (u_longlong_t
)ddi_get_lbolt64());
5617 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5619 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5622 (void) strlcpy(zc
->zc_value
, snap_name
,
5623 sizeof (zc
->zc_value
));
5626 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5632 * zc_name name of "to" snapshot
5633 * zc_value name of "from" snapshot
5634 * zc_cookie file descriptor to write diff data on
5637 * dmu_diff_record_t's to the file descriptor
5640 zfs_ioc_diff(zfs_cmd_t
*zc
)
5646 fp
= getf(zc
->zc_cookie
);
5648 return (SET_ERROR(EBADF
));
5652 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5654 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5656 releasef(zc
->zc_cookie
);
5662 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5664 return (SET_ERROR(ENOTSUP
));
5669 * "holds" -> { snapname -> holdname (string), ... }
5670 * (optional) "cleanup_fd" -> fd (int32)
5674 * snapname -> error value (int32)
5678 static const zfs_ioc_key_t zfs_keys_hold
[] = {
5679 {"holds", DATA_TYPE_NVLIST
, 0},
5680 {"cleanup_fd", DATA_TYPE_INT32
, ZK_OPTIONAL
},
5685 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5689 int cleanup_fd
= -1;
5693 holds
= fnvlist_lookup_nvlist(args
, "holds");
5695 /* make sure the user didn't pass us any invalid (empty) tags */
5696 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5697 pair
= nvlist_next_nvpair(holds
, pair
)) {
5700 error
= nvpair_value_string(pair
, &htag
);
5702 return (SET_ERROR(error
));
5704 if (strlen(htag
) == 0)
5705 return (SET_ERROR(EINVAL
));
5708 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5709 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5714 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5716 zfs_onexit_fd_rele(cleanup_fd
);
5721 * innvl is not used.
5724 * holdname -> time added (uint64 seconds since epoch)
5728 static const zfs_ioc_key_t zfs_keys_get_holds
[] = {
5734 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5736 return (dsl_dataset_get_holds(snapname
, outnvl
));
5741 * snapname -> { holdname, ... }
5746 * snapname -> error value (int32)
5750 static const zfs_ioc_key_t zfs_keys_release
[] = {
5751 {"<snapname>...", DATA_TYPE_NVLIST
, ZK_WILDCARDLIST
},
5756 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5758 return (dsl_dataset_user_release(holds
, errlist
));
5763 * zc_guid flags (ZEVENT_NONBLOCK)
5764 * zc_cleanup_fd zevent file descriptor
5767 * zc_nvlist_dst next nvlist event
5768 * zc_cookie dropped events since last get
5771 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5774 nvlist_t
*event
= NULL
;
5776 uint64_t dropped
= 0;
5779 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5784 error
= zfs_zevent_next(ze
, &event
,
5785 &zc
->zc_nvlist_dst_size
, &dropped
);
5786 if (event
!= NULL
) {
5787 zc
->zc_cookie
= dropped
;
5788 error
= put_nvlist(zc
, event
);
5792 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5795 if ((error
== 0) || (error
!= ENOENT
))
5798 error
= zfs_zevent_wait(ze
);
5803 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5810 * zc_cookie cleared events count
5813 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5817 zfs_zevent_drain_all(&count
);
5818 zc
->zc_cookie
= count
;
5825 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5826 * zc_cleanup zevent file descriptor
5829 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5835 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5839 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5840 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5847 * zc_name name of new filesystem or snapshot
5848 * zc_value full name of old snapshot
5851 * zc_cookie space in bytes
5852 * zc_objset_type compressed space in bytes
5853 * zc_perm_action uncompressed space in bytes
5856 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5860 dsl_dataset_t
*new, *old
;
5862 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5865 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5867 dsl_pool_rele(dp
, FTAG
);
5870 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5872 dsl_dataset_rele(new, FTAG
);
5873 dsl_pool_rele(dp
, FTAG
);
5877 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5878 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5879 dsl_dataset_rele(old
, FTAG
);
5880 dsl_dataset_rele(new, FTAG
);
5881 dsl_pool_rele(dp
, FTAG
);
5887 * "firstsnap" -> snapshot name
5891 * "used" -> space in bytes
5892 * "compressed" -> compressed space in bytes
5893 * "uncompressed" -> uncompressed space in bytes
5896 static const zfs_ioc_key_t zfs_keys_space_snaps
[] = {
5897 {"firstsnap", DATA_TYPE_STRING
, 0},
5901 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5905 dsl_dataset_t
*new, *old
;
5907 uint64_t used
, comp
, uncomp
;
5909 firstsnap
= fnvlist_lookup_string(innvl
, "firstsnap");
5911 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5915 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5916 if (error
== 0 && !new->ds_is_snapshot
) {
5917 dsl_dataset_rele(new, FTAG
);
5918 error
= SET_ERROR(EINVAL
);
5921 dsl_pool_rele(dp
, FTAG
);
5924 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5925 if (error
== 0 && !old
->ds_is_snapshot
) {
5926 dsl_dataset_rele(old
, FTAG
);
5927 error
= SET_ERROR(EINVAL
);
5930 dsl_dataset_rele(new, FTAG
);
5931 dsl_pool_rele(dp
, FTAG
);
5935 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5936 dsl_dataset_rele(old
, FTAG
);
5937 dsl_dataset_rele(new, FTAG
);
5938 dsl_pool_rele(dp
, FTAG
);
5939 fnvlist_add_uint64(outnvl
, "used", used
);
5940 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5941 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5947 * "fd" -> file descriptor to write stream to (int32)
5948 * (optional) "fromsnap" -> full snap name to send an incremental from
5949 * (optional) "largeblockok" -> (value ignored)
5950 * indicates that blocks > 128KB are permitted
5951 * (optional) "embedok" -> (value ignored)
5952 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5953 * (optional) "compressok" -> (value ignored)
5954 * presence indicates compressed DRR_WRITE records are permitted
5955 * (optional) "rawok" -> (value ignored)
5956 * presence indicates raw encrypted records should be used.
5957 * (optional) "resume_object" and "resume_offset" -> (uint64)
5958 * if present, resume send stream from specified object and offset.
5963 static const zfs_ioc_key_t zfs_keys_send_new
[] = {
5964 {"fd", DATA_TYPE_INT32
, 0},
5965 {"fromsnap", DATA_TYPE_STRING
, ZK_OPTIONAL
},
5966 {"largeblockok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
5967 {"embedok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
5968 {"compressok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
5969 {"rawok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
5970 {"resume_object", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
5971 {"resume_offset", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
5976 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5980 char *fromname
= NULL
;
5983 boolean_t largeblockok
;
5985 boolean_t compressok
;
5987 uint64_t resumeobj
= 0;
5988 uint64_t resumeoff
= 0;
5990 fd
= fnvlist_lookup_int32(innvl
, "fd");
5992 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5994 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5995 embedok
= nvlist_exists(innvl
, "embedok");
5996 compressok
= nvlist_exists(innvl
, "compressok");
5997 rawok
= nvlist_exists(innvl
, "rawok");
5999 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
6000 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
6002 if ((fp
= getf(fd
)) == NULL
)
6003 return (SET_ERROR(EBADF
));
6006 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
6007 rawok
, fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
6009 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
6017 * Determine approximately how large a zfs send stream will be -- the number
6018 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
6021 * (optional) "from" -> full snap or bookmark name to send an incremental
6023 * (optional) "largeblockok" -> (value ignored)
6024 * indicates that blocks > 128KB are permitted
6025 * (optional) "embedok" -> (value ignored)
6026 * presence indicates DRR_WRITE_EMBEDDED records are permitted
6027 * (optional) "compressok" -> (value ignored)
6028 * presence indicates compressed DRR_WRITE records are permitted
6029 * (optional) "rawok" -> (value ignored)
6030 * presence indicates raw encrypted records should be used.
6034 * "space" -> bytes of space (uint64)
6037 static const zfs_ioc_key_t zfs_keys_send_space
[] = {
6038 {"from", DATA_TYPE_STRING
, ZK_OPTIONAL
},
6039 {"fromsnap", DATA_TYPE_STRING
, ZK_OPTIONAL
},
6040 {"largeblockok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6041 {"embedok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6042 {"compressok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6043 {"rawok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6047 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6050 dsl_dataset_t
*tosnap
;
6053 boolean_t compressok
;
6057 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
6061 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
6063 dsl_pool_rele(dp
, FTAG
);
6067 compressok
= nvlist_exists(innvl
, "compressok");
6068 rawok
= nvlist_exists(innvl
, "rawok");
6070 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
6072 if (strchr(fromname
, '@') != NULL
) {
6074 * If from is a snapshot, hold it and use the more
6075 * efficient dmu_send_estimate to estimate send space
6076 * size using deadlists.
6078 dsl_dataset_t
*fromsnap
;
6079 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
6082 error
= dmu_send_estimate(tosnap
, fromsnap
,
6083 compressok
|| rawok
, &space
);
6084 dsl_dataset_rele(fromsnap
, FTAG
);
6085 } else if (strchr(fromname
, '#') != NULL
) {
6087 * If from is a bookmark, fetch the creation TXG of the
6088 * snapshot it was created from and use that to find
6089 * blocks that were born after it.
6091 zfs_bookmark_phys_t frombm
;
6093 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
6097 error
= dmu_send_estimate_from_txg(tosnap
,
6098 frombm
.zbm_creation_txg
, compressok
|| rawok
,
6102 * from is not properly formatted as a snapshot or
6105 error
= SET_ERROR(EINVAL
);
6110 * If estimating the size of a full send, use dmu_send_estimate.
6112 error
= dmu_send_estimate(tosnap
, NULL
, compressok
|| rawok
,
6116 fnvlist_add_uint64(outnvl
, "space", space
);
6119 dsl_dataset_rele(tosnap
, FTAG
);
6120 dsl_pool_rele(dp
, FTAG
);
6125 * Sync the currently open TXG to disk for the specified pool.
6126 * This is somewhat similar to 'zfs_sync()'.
6127 * For cases that do not result in error this ioctl will wait for
6128 * the currently open TXG to commit before returning back to the caller.
6131 * "force" -> when true, force uberblock update even if there is no dirty data.
6132 * In addition this will cause the vdev configuration to be written
6133 * out including updating the zpool cache file. (boolean_t)
6138 static const zfs_ioc_key_t zfs_keys_pool_sync
[] = {
6139 {"force", DATA_TYPE_BOOLEAN_VALUE
, 0},
6144 zfs_ioc_pool_sync(const char *pool
, nvlist_t
*innvl
, nvlist_t
*onvl
)
6147 boolean_t force
= B_FALSE
;
6150 if ((err
= spa_open(pool
, &spa
, FTAG
)) != 0)
6154 force
= fnvlist_lookup_boolean_value(innvl
, "force");
6157 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_WRITER
);
6158 vdev_config_dirty(spa
->spa_root_vdev
);
6159 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6161 txg_wait_synced(spa_get_dsl(spa
), 0);
6163 spa_close(spa
, FTAG
);
6169 * Load a user's wrapping key into the kernel.
6171 * "hidden_args" -> { "wkeydata" -> value }
6172 * raw uint8_t array of encryption wrapping key data (32 bytes)
6173 * (optional) "noop" -> (value ignored)
6174 * presence indicated key should only be verified, not loaded
6177 static const zfs_ioc_key_t zfs_keys_load_key
[] = {
6178 {"hidden_args", DATA_TYPE_NVLIST
, 0},
6179 {"noop", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6184 zfs_ioc_load_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6187 dsl_crypto_params_t
*dcp
= NULL
;
6188 nvlist_t
*hidden_args
;
6189 boolean_t noop
= nvlist_exists(innvl
, "noop");
6191 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6192 ret
= SET_ERROR(EINVAL
);
6196 hidden_args
= fnvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
);
6198 ret
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, NULL
,
6203 ret
= spa_keystore_load_wkey(dsname
, dcp
, noop
);
6207 dsl_crypto_params_free(dcp
, noop
);
6212 dsl_crypto_params_free(dcp
, B_TRUE
);
6217 * Unload a user's wrapping key from the kernel.
6218 * Both innvl and outnvl are unused.
6220 static const zfs_ioc_key_t zfs_keys_unload_key
[] = {
6226 zfs_ioc_unload_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6230 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6231 ret
= (SET_ERROR(EINVAL
));
6235 ret
= spa_keystore_unload_wkey(dsname
);
6244 * Changes a user's wrapping key used to decrypt a dataset. The keyformat,
6245 * keylocation, pbkdf2salt, and pbkdf2iters properties can also be specified
6246 * here to change how the key is derived in userspace.
6249 * "hidden_args" (optional) -> { "wkeydata" -> value }
6250 * raw uint8_t array of new encryption wrapping key data (32 bytes)
6251 * "props" (optional) -> { prop -> value }
6256 static const zfs_ioc_key_t zfs_keys_change_key
[] = {
6257 {"crypt_cmd", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
6258 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
6259 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
6264 zfs_ioc_change_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6267 uint64_t cmd
= DCP_CMD_NONE
;
6268 dsl_crypto_params_t
*dcp
= NULL
;
6269 nvlist_t
*args
= NULL
, *hidden_args
= NULL
;
6271 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6272 ret
= (SET_ERROR(EINVAL
));
6276 (void) nvlist_lookup_uint64(innvl
, "crypt_cmd", &cmd
);
6277 (void) nvlist_lookup_nvlist(innvl
, "props", &args
);
6278 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6280 ret
= dsl_crypto_params_create_nvlist(cmd
, args
, hidden_args
, &dcp
);
6284 ret
= spa_keystore_change_key(dsname
, dcp
);
6288 dsl_crypto_params_free(dcp
, B_FALSE
);
6293 dsl_crypto_params_free(dcp
, B_TRUE
);
6297 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
6300 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6301 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6302 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
6304 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6306 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6307 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6308 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6309 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6311 vec
->zvec_legacy_func
= func
;
6312 vec
->zvec_secpolicy
= secpolicy
;
6313 vec
->zvec_namecheck
= namecheck
;
6314 vec
->zvec_allow_log
= log_history
;
6315 vec
->zvec_pool_check
= pool_check
;
6319 * See the block comment at the beginning of this file for details on
6320 * each argument to this function.
6323 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
6324 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6325 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
6326 boolean_t allow_log
, const zfs_ioc_key_t
*nvl_keys
, size_t num_keys
)
6328 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6330 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6331 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6332 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6333 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6335 /* if we are logging, the name must be valid */
6336 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
6338 vec
->zvec_name
= name
;
6339 vec
->zvec_func
= func
;
6340 vec
->zvec_secpolicy
= secpolicy
;
6341 vec
->zvec_namecheck
= namecheck
;
6342 vec
->zvec_pool_check
= pool_check
;
6343 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
6344 vec
->zvec_allow_log
= allow_log
;
6345 vec
->zvec_nvl_keys
= nvl_keys
;
6346 vec
->zvec_nvl_key_count
= num_keys
;
6350 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6351 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
6352 zfs_ioc_poolcheck_t pool_check
)
6354 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6355 POOL_NAME
, log_history
, pool_check
);
6359 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6360 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
6362 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6363 DATASET_NAME
, B_FALSE
, pool_check
);
6367 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6369 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
6370 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6374 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6375 zfs_secpolicy_func_t
*secpolicy
)
6377 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6378 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6382 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
6383 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
6385 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6386 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6390 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6392 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
6393 zfs_secpolicy_read
);
6397 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6398 zfs_secpolicy_func_t
*secpolicy
)
6400 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6401 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6405 zfs_ioctl_init(void)
6407 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
6408 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
6409 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6410 zfs_keys_snapshot
, ARRAY_SIZE(zfs_keys_snapshot
));
6412 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
6413 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
6414 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
,
6415 zfs_keys_log_history
, ARRAY_SIZE(zfs_keys_log_history
));
6417 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
6418 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
6419 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6420 zfs_keys_space_snaps
, ARRAY_SIZE(zfs_keys_space_snaps
));
6422 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
6423 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
6424 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6425 zfs_keys_send_new
, ARRAY_SIZE(zfs_keys_send_new
));
6427 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
6428 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
6429 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6430 zfs_keys_send_space
, ARRAY_SIZE(zfs_keys_send_space
));
6432 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
6433 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6434 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6435 zfs_keys_create
, ARRAY_SIZE(zfs_keys_create
));
6437 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
6438 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6439 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6440 zfs_keys_clone
, ARRAY_SIZE(zfs_keys_clone
));
6442 zfs_ioctl_register("remap", ZFS_IOC_REMAP
,
6443 zfs_ioc_remap
, zfs_secpolicy_remap
, DATASET_NAME
,
6444 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
,
6445 zfs_keys_remap
, ARRAY_SIZE(zfs_keys_remap
));
6447 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
6448 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
6449 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6450 zfs_keys_destroy_snaps
, ARRAY_SIZE(zfs_keys_destroy_snaps
));
6452 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
6453 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
6454 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6455 zfs_keys_hold
, ARRAY_SIZE(zfs_keys_hold
));
6456 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
6457 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
6458 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6459 zfs_keys_release
, ARRAY_SIZE(zfs_keys_release
));
6461 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
6462 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
6463 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6464 zfs_keys_get_holds
, ARRAY_SIZE(zfs_keys_get_holds
));
6466 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
6467 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
6468 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
,
6469 zfs_keys_rollback
, ARRAY_SIZE(zfs_keys_rollback
));
6471 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
6472 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
6473 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6474 zfs_keys_bookmark
, ARRAY_SIZE(zfs_keys_bookmark
));
6476 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
6477 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
6478 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6479 zfs_keys_get_bookmarks
, ARRAY_SIZE(zfs_keys_get_bookmarks
));
6481 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
6482 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
6484 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6485 zfs_keys_destroy_bookmarks
,
6486 ARRAY_SIZE(zfs_keys_destroy_bookmarks
));
6488 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
6489 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
6490 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6491 zfs_keys_recv_new
, ARRAY_SIZE(zfs_keys_recv_new
));
6492 zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY
,
6493 zfs_ioc_load_key
, zfs_secpolicy_load_key
,
6494 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
,
6495 zfs_keys_load_key
, ARRAY_SIZE(zfs_keys_load_key
));
6496 zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY
,
6497 zfs_ioc_unload_key
, zfs_secpolicy_load_key
,
6498 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
,
6499 zfs_keys_unload_key
, ARRAY_SIZE(zfs_keys_unload_key
));
6500 zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY
,
6501 zfs_ioc_change_key
, zfs_secpolicy_change_key
,
6502 DATASET_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
,
6503 B_TRUE
, B_TRUE
, zfs_keys_change_key
,
6504 ARRAY_SIZE(zfs_keys_change_key
));
6506 zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC
,
6507 zfs_ioc_pool_sync
, zfs_secpolicy_none
, POOL_NAME
,
6508 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
,
6509 zfs_keys_pool_sync
, ARRAY_SIZE(zfs_keys_pool_sync
));
6510 zfs_ioctl_register("reopen", ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
6511 zfs_secpolicy_config
, POOL_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
,
6512 B_TRUE
, zfs_keys_pool_reopen
, ARRAY_SIZE(zfs_keys_pool_reopen
));
6514 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
6515 zfs_ioc_channel_program
, zfs_secpolicy_config
,
6516 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
6517 B_TRUE
, zfs_keys_channel_program
,
6518 ARRAY_SIZE(zfs_keys_channel_program
));
6520 zfs_ioctl_register("zpool_checkpoint", ZFS_IOC_POOL_CHECKPOINT
,
6521 zfs_ioc_pool_checkpoint
, zfs_secpolicy_config
, POOL_NAME
,
6522 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6523 zfs_keys_pool_checkpoint
, ARRAY_SIZE(zfs_keys_pool_checkpoint
));
6525 zfs_ioctl_register("zpool_discard_checkpoint",
6526 ZFS_IOC_POOL_DISCARD_CHECKPOINT
, zfs_ioc_pool_discard_checkpoint
,
6527 zfs_secpolicy_config
, POOL_NAME
,
6528 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6529 zfs_keys_pool_discard_checkpoint
,
6530 ARRAY_SIZE(zfs_keys_pool_discard_checkpoint
));
6532 zfs_ioctl_register("initialize", ZFS_IOC_POOL_INITIALIZE
,
6533 zfs_ioc_pool_initialize
, zfs_secpolicy_config
, POOL_NAME
,
6534 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6535 zfs_keys_pool_initialize
, ARRAY_SIZE(zfs_keys_pool_initialize
));
6537 /* IOCTLS that use the legacy function signature */
6539 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
6540 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
6542 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
6543 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6544 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
6546 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
6547 zfs_ioc_pool_upgrade
);
6548 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
6550 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
6551 zfs_ioc_vdev_remove
);
6552 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
6553 zfs_ioc_vdev_set_state
);
6554 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
6555 zfs_ioc_vdev_attach
);
6556 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
6557 zfs_ioc_vdev_detach
);
6558 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
6559 zfs_ioc_vdev_setpath
);
6560 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
6561 zfs_ioc_vdev_setfru
);
6562 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
6563 zfs_ioc_pool_set_props
);
6564 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
6565 zfs_ioc_vdev_split
);
6566 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
6567 zfs_ioc_pool_reguid
);
6569 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
6570 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
6571 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
6572 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
6573 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
6574 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
6575 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
6576 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
6577 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
6578 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
6581 * pool destroy, and export don't log the history as part of
6582 * zfsdev_ioctl, but rather zfs_ioc_pool_export
6583 * does the logging of those commands.
6585 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
6586 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6587 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
6588 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6590 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
6591 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6592 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
6593 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6595 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
6596 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6597 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
6598 zfs_ioc_dsobj_to_dsname
,
6599 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6600 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
6601 zfs_ioc_pool_get_history
,
6602 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6604 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
6605 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6607 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
6608 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_READONLY
);
6610 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
6611 zfs_ioc_space_written
);
6612 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
6613 zfs_ioc_objset_recvd_props
);
6614 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
6616 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
6618 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
6619 zfs_ioc_objset_stats
);
6620 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
6621 zfs_ioc_objset_zplprops
);
6622 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
6623 zfs_ioc_dataset_list_next
);
6624 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
6625 zfs_ioc_snapshot_list_next
);
6626 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
6627 zfs_ioc_send_progress
);
6629 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
6630 zfs_ioc_diff
, zfs_secpolicy_diff
);
6631 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
6632 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
6633 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
6634 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
6635 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
6636 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
6637 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
6638 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
6639 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
6640 zfs_ioc_send
, zfs_secpolicy_send
);
6642 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
6643 zfs_secpolicy_none
);
6644 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
6645 zfs_secpolicy_destroy
);
6646 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
6647 zfs_secpolicy_rename
);
6648 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
6649 zfs_secpolicy_recv
);
6650 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
6651 zfs_secpolicy_promote
);
6652 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
6653 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
6654 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
6655 zfs_secpolicy_set_fsacl
);
6657 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
6658 zfs_secpolicy_share
, POOL_CHECK_NONE
);
6659 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
6660 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
6661 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
6662 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
6663 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6664 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
6665 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
6666 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6671 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
6672 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6673 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
6674 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6675 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
6676 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6680 * Verify that for non-legacy ioctls the input nvlist
6681 * pairs match against the expected input.
6683 * Possible errors are:
6684 * ZFS_ERR_IOC_ARG_UNAVAIL An unrecognized nvpair was encountered
6685 * ZFS_ERR_IOC_ARG_REQUIRED A required nvpair is missing
6686 * ZFS_ERR_IOC_ARG_BADTYPE Invalid type for nvpair
6689 zfs_check_input_nvpairs(nvlist_t
*innvl
, const zfs_ioc_vec_t
*vec
)
6691 const zfs_ioc_key_t
*nvl_keys
= vec
->zvec_nvl_keys
;
6692 boolean_t required_keys_found
= B_FALSE
;
6695 * examine each input pair
6697 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
6698 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
6699 char *name
= nvpair_name(pair
);
6700 data_type_t type
= nvpair_type(pair
);
6701 boolean_t identified
= B_FALSE
;
6704 * check pair against the documented names and type
6706 for (int k
= 0; k
< vec
->zvec_nvl_key_count
; k
++) {
6707 /* if not a wild card name, check for an exact match */
6708 if ((nvl_keys
[k
].zkey_flags
& ZK_WILDCARDLIST
) == 0 &&
6709 strcmp(nvl_keys
[k
].zkey_name
, name
) != 0)
6712 identified
= B_TRUE
;
6714 if (nvl_keys
[k
].zkey_type
!= DATA_TYPE_ANY
&&
6715 nvl_keys
[k
].zkey_type
!= type
) {
6716 return (SET_ERROR(ZFS_ERR_IOC_ARG_BADTYPE
));
6719 if (nvl_keys
[k
].zkey_flags
& ZK_OPTIONAL
)
6722 required_keys_found
= B_TRUE
;
6726 /* allow an 'optional' key, everything else is invalid */
6728 (strcmp(name
, "optional") != 0 ||
6729 type
!= DATA_TYPE_NVLIST
)) {
6730 return (SET_ERROR(ZFS_ERR_IOC_ARG_UNAVAIL
));
6734 /* verify that all required keys were found */
6735 for (int k
= 0; k
< vec
->zvec_nvl_key_count
; k
++) {
6736 if (nvl_keys
[k
].zkey_flags
& ZK_OPTIONAL
)
6739 if (nvl_keys
[k
].zkey_flags
& ZK_WILDCARDLIST
) {
6740 /* at least one non-optionial key is expected here */
6741 if (!required_keys_found
)
6742 return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED
));
6746 if (!nvlist_exists(innvl
, nvl_keys
[k
].zkey_name
))
6747 return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED
));
6754 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
6755 zfs_ioc_poolcheck_t check
)
6760 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
6762 if (check
& POOL_CHECK_NONE
)
6765 error
= spa_open(name
, &spa
, FTAG
);
6767 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
6768 error
= SET_ERROR(EAGAIN
);
6769 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
6770 error
= SET_ERROR(EROFS
);
6771 spa_close(spa
, FTAG
);
6777 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
6781 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6782 if (zs
->zs_minor
== minor
) {
6786 return (zs
->zs_onexit
);
6788 return (zs
->zs_zevent
);
6799 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
6803 ptr
= zfsdev_get_state_impl(minor
, which
);
6809 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
6811 zfsdev_state_t
*zs
, *fpd
;
6813 ASSERT(filp
!= NULL
);
6814 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
6816 fpd
= filp
->private_data
;
6818 return (SET_ERROR(EBADF
));
6820 mutex_enter(&zfsdev_state_lock
);
6822 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6824 if (zs
->zs_minor
== -1)
6828 *minorp
= fpd
->zs_minor
;
6829 mutex_exit(&zfsdev_state_lock
);
6834 mutex_exit(&zfsdev_state_lock
);
6836 return (SET_ERROR(EBADF
));
6840 * Find a free minor number. The zfsdev_state_list is expected to
6841 * be short since it is only a list of currently open file handles.
6844 zfsdev_minor_alloc(void)
6846 static minor_t last_minor
= 0;
6849 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6851 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6852 if (m
> ZFSDEV_MAX_MINOR
)
6854 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
6864 zfsdev_state_init(struct file
*filp
)
6866 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6868 boolean_t newzs
= B_FALSE
;
6870 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6872 minor
= zfsdev_minor_alloc();
6874 return (SET_ERROR(ENXIO
));
6876 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6877 if (zs
->zs_minor
== -1)
6883 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6888 filp
->private_data
= zs
;
6890 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
6891 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
6895 * In order to provide for lock-free concurrent read access
6896 * to the minor list in zfsdev_get_state_impl(), new entries
6897 * must be completely written before linking them into the
6898 * list whereas existing entries are already linked; the last
6899 * operation must be updating zs_minor (from -1 to the new
6903 zs
->zs_minor
= minor
;
6905 zsprev
->zs_next
= zs
;
6908 zs
->zs_minor
= minor
;
6915 zfsdev_state_destroy(struct file
*filp
)
6919 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6920 ASSERT(filp
->private_data
!= NULL
);
6922 zs
= filp
->private_data
;
6924 zfs_onexit_destroy(zs
->zs_onexit
);
6925 zfs_zevent_destroy(zs
->zs_zevent
);
6931 zfsdev_open(struct inode
*ino
, struct file
*filp
)
6935 mutex_enter(&zfsdev_state_lock
);
6936 error
= zfsdev_state_init(filp
);
6937 mutex_exit(&zfsdev_state_lock
);
6943 zfsdev_release(struct inode
*ino
, struct file
*filp
)
6947 mutex_enter(&zfsdev_state_lock
);
6948 error
= zfsdev_state_destroy(filp
);
6949 mutex_exit(&zfsdev_state_lock
);
6955 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6959 int error
, rc
, flag
= 0;
6960 const zfs_ioc_vec_t
*vec
;
6961 char *saved_poolname
= NULL
;
6962 nvlist_t
*innvl
= NULL
;
6963 fstrans_cookie_t cookie
;
6965 vecnum
= cmd
- ZFS_IOC_FIRST
;
6966 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6967 return (-SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL
));
6968 vec
= &zfs_ioc_vec
[vecnum
];
6971 * The registered ioctl list may be sparse, verify that either
6972 * a normal or legacy handler are registered.
6974 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
6975 return (-SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL
));
6977 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6979 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6981 error
= SET_ERROR(EFAULT
);
6985 zc
->zc_iflags
= flag
& FKIOCTL
;
6986 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
6988 * Make sure the user doesn't pass in an insane value for
6989 * zc_nvlist_src_size. We have to check, since we will end
6990 * up allocating that much memory inside of get_nvlist(). This
6991 * prevents a nefarious user from allocating tons of kernel
6994 * Also, we return EINVAL instead of ENOMEM here. The reason
6995 * being that returning ENOMEM from an ioctl() has a special
6996 * connotation; that the user's size value is too small and
6997 * needs to be expanded to hold the nvlist. See
6998 * zcmd_expand_dst_nvlist() for details.
7000 error
= SET_ERROR(EINVAL
); /* User's size too big */
7002 } else if (zc
->zc_nvlist_src_size
!= 0) {
7003 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
7004 zc
->zc_iflags
, &innvl
);
7010 * Ensure that all pool/dataset names are valid before we pass down to
7013 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
7014 switch (vec
->zvec_namecheck
) {
7016 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
7017 error
= SET_ERROR(EINVAL
);
7019 error
= pool_status_check(zc
->zc_name
,
7020 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
7024 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
7025 error
= SET_ERROR(EINVAL
);
7027 error
= pool_status_check(zc
->zc_name
,
7028 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
7036 * Ensure that all input pairs are valid before we pass them down
7037 * to the lower layers.
7039 * The vectored functions can use fnvlist_lookup_{type} for any
7040 * required pairs since zfs_check_input_nvpairs() confirmed that
7041 * they exist and are of the correct type.
7043 if (error
== 0 && vec
->zvec_func
!= NULL
) {
7044 error
= zfs_check_input_nvpairs(innvl
, vec
);
7050 cookie
= spl_fstrans_mark();
7051 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
7052 spl_fstrans_unmark(cookie
);
7058 /* legacy ioctls can modify zc_name */
7059 saved_poolname
= strdup(zc
->zc_name
);
7060 if (saved_poolname
== NULL
) {
7061 error
= SET_ERROR(ENOMEM
);
7064 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
7067 if (vec
->zvec_func
!= NULL
) {
7071 nvlist_t
*lognv
= NULL
;
7073 ASSERT(vec
->zvec_legacy_func
== NULL
);
7076 * Add the innvl to the lognv before calling the func,
7077 * in case the func changes the innvl.
7079 if (vec
->zvec_allow_log
) {
7080 lognv
= fnvlist_alloc();
7081 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
7083 if (!nvlist_empty(innvl
)) {
7084 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
7089 outnvl
= fnvlist_alloc();
7090 cookie
= spl_fstrans_mark();
7091 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
7092 spl_fstrans_unmark(cookie
);
7095 * Some commands can partially execute, modify state, and still
7096 * return an error. In these cases, attempt to record what
7100 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
7101 vec
->zvec_allow_log
&&
7102 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
7103 if (!nvlist_empty(outnvl
)) {
7104 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
7108 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
7111 (void) spa_history_log_nvl(spa
, lognv
);
7112 spa_close(spa
, FTAG
);
7114 fnvlist_free(lognv
);
7116 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
7118 if (vec
->zvec_smush_outnvlist
) {
7119 smusherror
= nvlist_smush(outnvl
,
7120 zc
->zc_nvlist_dst_size
);
7122 if (smusherror
== 0)
7123 puterror
= put_nvlist(zc
, outnvl
);
7129 nvlist_free(outnvl
);
7131 cookie
= spl_fstrans_mark();
7132 error
= vec
->zvec_legacy_func(zc
);
7133 spl_fstrans_unmark(cookie
);
7138 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
7139 if (error
== 0 && rc
!= 0)
7140 error
= SET_ERROR(EFAULT
);
7141 if (error
== 0 && vec
->zvec_allow_log
) {
7142 char *s
= tsd_get(zfs_allow_log_key
);
7145 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
7147 if (saved_poolname
!= NULL
)
7148 strfree(saved_poolname
);
7151 kmem_free(zc
, sizeof (zfs_cmd_t
));
7155 #ifdef CONFIG_COMPAT
7157 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
7159 return (zfsdev_ioctl(filp
, cmd
, arg
));
7162 #define zfsdev_compat_ioctl NULL
7165 static const struct file_operations zfsdev_fops
= {
7166 .open
= zfsdev_open
,
7167 .release
= zfsdev_release
,
7168 .unlocked_ioctl
= zfsdev_ioctl
,
7169 .compat_ioctl
= zfsdev_compat_ioctl
,
7170 .owner
= THIS_MODULE
,
7173 static struct miscdevice zfs_misc
= {
7174 .minor
= ZFS_DEVICE_MINOR
,
7176 .fops
= &zfsdev_fops
,
7179 MODULE_ALIAS_MISCDEV(ZFS_DEVICE_MINOR
);
7180 MODULE_ALIAS("devname:zfs");
7187 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
7188 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
7189 zfsdev_state_list
->zs_minor
= -1;
7191 error
= misc_register(&zfs_misc
);
7192 if (error
== -EBUSY
) {
7194 * Fallback to dynamic minor allocation in the event of a
7195 * collision with a reserved minor in linux/miscdevice.h.
7196 * In this case the kernel modules must be manually loaded.
7198 printk(KERN_INFO
"ZFS: misc_register() with static minor %d "
7199 "failed %d, retrying with MISC_DYNAMIC_MINOR\n",
7200 ZFS_DEVICE_MINOR
, error
);
7202 zfs_misc
.minor
= MISC_DYNAMIC_MINOR
;
7203 error
= misc_register(&zfs_misc
);
7207 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
7215 zfsdev_state_t
*zs
, *zsprev
= NULL
;
7217 misc_deregister(&zfs_misc
);
7218 mutex_destroy(&zfsdev_state_lock
);
7220 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
7222 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7226 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7230 zfs_allow_log_destroy(void *arg
)
7232 char *poolname
= arg
;
7234 if (poolname
!= NULL
)
7239 #define ZFS_DEBUG_STR " (DEBUG mode)"
7241 #define ZFS_DEBUG_STR ""
7249 error
= -vn_set_pwd("/");
7252 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
7256 if ((error
= -zvol_init()) != 0)
7259 spa_init(FREAD
| FWRITE
);
7265 if ((error
= zfs_attach()) != 0)
7268 tsd_create(&zfs_fsyncer_key
, NULL
);
7269 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
7270 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
7272 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
7273 "ZFS pool version %s, ZFS filesystem version %s\n",
7274 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
7275 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
7276 #ifndef CONFIG_FS_POSIX_ACL
7277 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
7278 #endif /* CONFIG_FS_POSIX_ACL */
7287 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
7288 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
7289 ZFS_DEBUG_STR
, error
);
7303 tsd_destroy(&zfs_fsyncer_key
);
7304 tsd_destroy(&rrw_tsd_key
);
7305 tsd_destroy(&zfs_allow_log_key
);
7307 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
7308 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
7311 #if defined(_KERNEL)
7315 MODULE_DESCRIPTION("ZFS");
7316 MODULE_AUTHOR(ZFS_META_AUTHOR
);
7317 MODULE_LICENSE(ZFS_META_LICENSE
);
7318 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);