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 * Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
26 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
29 * Copyright (c) 201i3 by Delphix. All rights reserved.
30 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
31 * Copyright (c) 2013 Steven Hartland. All rights reserved.
32 * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved.
38 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
39 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
41 * There are two ways that we handle ioctls: the legacy way where almost
42 * all of the logic is in the ioctl callback, and the new way where most
43 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
45 * Non-legacy ioctls should be registered by calling
46 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
47 * from userland by lzc_ioctl().
49 * The registration arguments are as follows:
52 * The name of the ioctl. This is used for history logging. If the
53 * ioctl returns successfully (the callback returns 0), and allow_log
54 * is true, then a history log entry will be recorded with the input &
55 * output nvlists. The log entry can be printed with "zpool history -i".
58 * The ioctl request number, which userland will pass to ioctl(2).
59 * The ioctl numbers can change from release to release, because
60 * the caller (libzfs) must be matched to the kernel.
62 * zfs_secpolicy_func_t *secpolicy
63 * This function will be called before the zfs_ioc_func_t, to
64 * determine if this operation is permitted. It should return EPERM
65 * on failure, and 0 on success. Checks include determining if the
66 * dataset is visible in this zone, and if the user has either all
67 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
68 * to do this operation on this dataset with "zfs allow".
70 * zfs_ioc_namecheck_t namecheck
71 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
72 * name, a dataset name, or nothing. If the name is not well-formed,
73 * the ioctl will fail and the callback will not be called.
74 * Therefore, the callback can assume that the name is well-formed
75 * (e.g. is null-terminated, doesn't have more than one '@' character,
76 * doesn't have invalid characters).
78 * zfs_ioc_poolcheck_t pool_check
79 * This specifies requirements on the pool state. If the pool does
80 * not meet them (is suspended or is readonly), the ioctl will fail
81 * and the callback will not be called. If any checks are specified
82 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
83 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
84 * POOL_CHECK_READONLY).
86 * boolean_t smush_outnvlist
87 * If smush_outnvlist is true, then the output is presumed to be a
88 * list of errors, and it will be "smushed" down to fit into the
89 * caller's buffer, by removing some entries and replacing them with a
90 * single "N_MORE_ERRORS" entry indicating how many were removed. See
91 * nvlist_smush() for details. If smush_outnvlist is false, and the
92 * outnvlist does not fit into the userland-provided buffer, then the
93 * ioctl will fail with ENOMEM.
95 * zfs_ioc_func_t *func
96 * The callback function that will perform the operation.
98 * The callback should return 0 on success, or an error number on
99 * failure. If the function fails, the userland ioctl will return -1,
100 * and errno will be set to the callback's return value. The callback
101 * will be called with the following arguments:
104 * The name of the pool or dataset to operate on, from
105 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
106 * expected type (pool, dataset, or none).
109 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
110 * NULL if no input nvlist was provided. Changes to this nvlist are
111 * ignored. If the input nvlist could not be deserialized, the
112 * ioctl will fail and the callback will not be called.
115 * The output nvlist, initially empty. The callback can fill it in,
116 * and it will be returned to userland by serializing it into
117 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
118 * fails (e.g. because the caller didn't supply a large enough
119 * buffer), then the overall ioctl will fail. See the
120 * 'smush_nvlist' argument above for additional behaviors.
122 * There are two typical uses of the output nvlist:
123 * - To return state, e.g. property values. In this case,
124 * smush_outnvlist should be false. If the buffer was not large
125 * enough, the caller will reallocate a larger buffer and try
128 * - To return multiple errors from an ioctl which makes on-disk
129 * changes. In this case, smush_outnvlist should be true.
130 * Ioctls which make on-disk modifications should generally not
131 * use the outnvl if they succeed, because the caller can not
132 * distinguish between the operation failing, and
133 * deserialization failing.
136 #include <sys/types.h>
137 #include <sys/param.h>
138 #include <sys/errno.h>
141 #include <sys/modctl.h>
142 #include <sys/open.h>
143 #include <sys/file.h>
144 #include <sys/kmem.h>
145 #include <sys/conf.h>
146 #include <sys/cmn_err.h>
147 #include <sys/stat.h>
148 #include <sys/zfs_ioctl.h>
149 #include <sys/zfs_vfsops.h>
150 #include <sys/zfs_znode.h>
153 #include <sys/spa_impl.h>
154 #include <sys/vdev.h>
155 #include <sys/priv_impl.h>
157 #include <sys/dsl_dir.h>
158 #include <sys/dsl_dataset.h>
159 #include <sys/dsl_prop.h>
160 #include <sys/dsl_deleg.h>
161 #include <sys/dmu_objset.h>
162 #include <sys/dmu_impl.h>
163 #include <sys/dmu_tx.h>
165 #include <sys/sunddi.h>
166 #include <sys/sunldi.h>
167 #include <sys/policy.h>
168 #include <sys/zone.h>
169 #include <sys/nvpair.h>
170 #include <sys/pathname.h>
171 #include <sys/mount.h>
173 #include <sys/fs/zfs.h>
174 #include <sys/zfs_ctldir.h>
175 #include <sys/zfs_dir.h>
176 #include <sys/zfs_onexit.h>
177 #include <sys/zvol.h>
178 #include <sys/dsl_scan.h>
179 #include <sharefs/share.h>
180 #include <sys/fm/util.h>
182 #include <sys/dmu_send.h>
183 #include <sys/dsl_destroy.h>
184 #include <sys/dsl_bookmark.h>
185 #include <sys/dsl_userhold.h>
186 #include <sys/zfeature.h>
188 #include <linux/miscdevice.h>
189 #include <linux/module_compat.h>
191 #include "zfs_namecheck.h"
192 #include "zfs_prop.h"
193 #include "zfs_deleg.h"
194 #include "zfs_comutil.h"
196 kmutex_t zfsdev_state_lock;
197 zfsdev_state_t *zfsdev_state_list;
199 extern void zfs_init(void);
200 extern void zfs_fini(void);
202 uint_t zfs_fsyncer_key;
203 extern uint_t rrw_tsd_key;
204 static uint_t zfs_allow_log_key;
206 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t *);
207 typedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
208 typedef int zfs_secpolicy_func_t(zfs_cmd_t *, nvlist_t *, cred_t *);
214 } zfs_ioc_namecheck_t;
217 POOL_CHECK_NONE = 1 << 0,
218 POOL_CHECK_SUSPENDED = 1 << 1,
219 POOL_CHECK_READONLY = 1 << 2,
220 } zfs_ioc_poolcheck_t;
222 typedef struct zfs_ioc_vec {
223 zfs_ioc_legacy_func_t *zvec_legacy_func;
224 zfs_ioc_func_t *zvec_func;
225 zfs_secpolicy_func_t *zvec_secpolicy;
226 zfs_ioc_namecheck_t zvec_namecheck;
227 boolean_t zvec_allow_log;
228 zfs_ioc_poolcheck_t zvec_pool_check;
229 boolean_t zvec_smush_outnvlist;
230 const char *zvec_name;
233 /* This array is indexed by zfs_userquota_prop_t */
234 static const char *userquota_perms[] = {
235 ZFS_DELEG_PERM_USERUSED,
236 ZFS_DELEG_PERM_USERQUOTA,
237 ZFS_DELEG_PERM_GROUPUSED,
238 ZFS_DELEG_PERM_GROUPQUOTA,
241 static int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
242 static int zfs_check_settable(const char *name, nvpair_t *property,
244 static int zfs_check_clearable(char *dataset, nvlist_t *props,
246 static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
248 int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t *);
249 static int get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp);
251 #if defined(HAVE_DECLARE_EVENT_CLASS)
253 __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
257 char *buf = kmem_alloc(size, KM_SLEEP);
262 * Get rid of annoying prefix to filename.
264 newfile = strrchr(file, '/');
265 if (newfile != NULL) {
266 newfile = newfile + 1; /* Get rid of leading / */
272 (void) vsnprintf(buf, size, fmt, adx);
276 * Get rid of trailing newline.
278 nl = strrchr(buf, '\n');
283 * To get this data enable the zfs__dprintf trace point as shown:
285 * # Enable zfs__dprintf tracepoint, clear the tracepoint ring buffer
286 * $ echo 1 > /sys/module/zfs/parameters/zfs_flags
287 * $ echo 1 > /sys/kernel/debug/tracing/events/zfs/enable
288 * $ echo 0 > /sys/kernel/debug/tracing/trace
290 * # Dump the ring buffer.
291 * $ cat /sys/kernel/debug/tracing/trace
293 DTRACE_PROBE4(zfs__dprintf,
294 char *, newfile, char *, func, int, line, char *, buf);
296 kmem_free(buf, size);
298 #endif /* HAVE_DECLARE_EVENT_CLASS */
301 history_str_free(char *buf)
303 kmem_free(buf, HIS_MAX_RECORD_LEN);
307 history_str_get(zfs_cmd_t *zc)
311 if (zc->zc_history == 0)
314 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
315 if (copyinstr((void *)(uintptr_t)zc->zc_history,
316 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
317 history_str_free(buf);
321 buf[HIS_MAX_RECORD_LEN -1] = '\0';
327 * Check to see if the named dataset is currently defined as bootable
330 zfs_is_bootfs(const char *name)
334 if (dmu_objset_hold(name, FTAG, &os) == 0) {
336 ret = (dmu_objset_id(os) == spa_bootfs(dmu_objset_spa(os)));
337 dmu_objset_rele(os, FTAG);
344 * Return non-zero if the spa version is less than requested version.
347 zfs_earlier_version(const char *name, int version)
351 if (spa_open(name, &spa, FTAG) == 0) {
352 if (spa_version(spa) < version) {
353 spa_close(spa, FTAG);
356 spa_close(spa, FTAG);
362 * Return TRUE if the ZPL version is less than requested version.
365 zpl_earlier_version(const char *name, int version)
368 boolean_t rc = B_TRUE;
370 if (dmu_objset_hold(name, FTAG, &os) == 0) {
373 if (dmu_objset_type(os) != DMU_OST_ZFS) {
374 dmu_objset_rele(os, FTAG);
377 /* XXX reading from non-owned objset */
378 if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
379 rc = zplversion < version;
380 dmu_objset_rele(os, FTAG);
386 zfs_log_history(zfs_cmd_t *zc)
391 if ((buf = history_str_get(zc)) == NULL)
394 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
395 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
396 (void) spa_history_log(spa, buf);
397 spa_close(spa, FTAG);
399 history_str_free(buf);
403 * Policy for top-level read operations (list pools). Requires no privileges,
404 * and can be used in the local zone, as there is no associated dataset.
408 zfs_secpolicy_none(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
414 * Policy for dataset read operations (list children, get statistics). Requires
415 * no privileges, but must be visible in the local zone.
419 zfs_secpolicy_read(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
421 if (INGLOBALZONE(curproc) ||
422 zone_dataset_visible(zc->zc_name, NULL))
425 return (SET_ERROR(ENOENT));
429 zfs_dozonecheck_impl(const char *dataset, uint64_t zoned, cred_t *cr)
434 * The dataset must be visible by this zone -- check this first
435 * so they don't see EPERM on something they shouldn't know about.
437 if (!INGLOBALZONE(curproc) &&
438 !zone_dataset_visible(dataset, &writable))
439 return (SET_ERROR(ENOENT));
441 if (INGLOBALZONE(curproc)) {
443 * If the fs is zoned, only root can access it from the
446 if (secpolicy_zfs(cr) && zoned)
447 return (SET_ERROR(EPERM));
450 * If we are in a local zone, the 'zoned' property must be set.
453 return (SET_ERROR(EPERM));
455 /* must be writable by this zone */
457 return (SET_ERROR(EPERM));
463 zfs_dozonecheck(const char *dataset, cred_t *cr)
467 if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
468 return (SET_ERROR(ENOENT));
470 return (zfs_dozonecheck_impl(dataset, zoned, cr));
474 zfs_dozonecheck_ds(const char *dataset, dsl_dataset_t *ds, cred_t *cr)
478 if (dsl_prop_get_int_ds(ds, "zoned", &zoned))
479 return (SET_ERROR(ENOENT));
481 return (zfs_dozonecheck_impl(dataset, zoned, cr));
485 zfs_secpolicy_write_perms_ds(const char *name, dsl_dataset_t *ds,
486 const char *perm, cred_t *cr)
490 error = zfs_dozonecheck_ds(name, ds, cr);
492 error = secpolicy_zfs(cr);
494 error = dsl_deleg_access_impl(ds, perm, cr);
500 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
506 error = dsl_pool_hold(name, FTAG, &dp);
510 error = dsl_dataset_hold(dp, name, FTAG, &ds);
512 dsl_pool_rele(dp, FTAG);
516 error = zfs_secpolicy_write_perms_ds(name, ds, perm, cr);
518 dsl_dataset_rele(ds, FTAG);
519 dsl_pool_rele(dp, FTAG);
524 * Policy for setting the security label property.
526 * Returns 0 for success, non-zero for access and other errors.
529 zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
532 char ds_hexsl[MAXNAMELEN];
533 bslabel_t ds_sl, new_sl;
534 boolean_t new_default = FALSE;
536 int needed_priv = -1;
539 /* First get the existing dataset label. */
540 error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
541 1, sizeof (ds_hexsl), &ds_hexsl, NULL);
543 return (SET_ERROR(EPERM));
545 if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
548 /* The label must be translatable */
549 if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
550 return (SET_ERROR(EINVAL));
553 * In a non-global zone, disallow attempts to set a label that
554 * doesn't match that of the zone; otherwise no other checks
557 if (!INGLOBALZONE(curproc)) {
558 if (new_default || !blequal(&new_sl, CR_SL(CRED())))
559 return (SET_ERROR(EPERM));
564 * For global-zone datasets (i.e., those whose zoned property is
565 * "off", verify that the specified new label is valid for the
568 if (dsl_prop_get_integer(name,
569 zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
570 return (SET_ERROR(EPERM));
572 if (zfs_check_global_label(name, strval) != 0)
573 return (SET_ERROR(EPERM));
577 * If the existing dataset label is nondefault, check if the
578 * dataset is mounted (label cannot be changed while mounted).
579 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
580 * mounted (or isn't a dataset, doesn't exist, ...).
582 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
584 static char *setsl_tag = "setsl_tag";
587 * Try to own the dataset; abort if there is any error,
588 * (e.g., already mounted, in use, or other error).
590 error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
593 return (SET_ERROR(EPERM));
595 dmu_objset_disown(os, setsl_tag);
598 needed_priv = PRIV_FILE_DOWNGRADE_SL;
602 if (hexstr_to_label(strval, &new_sl) != 0)
603 return (SET_ERROR(EPERM));
605 if (blstrictdom(&ds_sl, &new_sl))
606 needed_priv = PRIV_FILE_DOWNGRADE_SL;
607 else if (blstrictdom(&new_sl, &ds_sl))
608 needed_priv = PRIV_FILE_UPGRADE_SL;
610 /* dataset currently has a default label */
612 needed_priv = PRIV_FILE_UPGRADE_SL;
616 if (needed_priv != -1)
617 return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
621 #endif /* HAVE_MLSLABEL */
625 zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
631 * Check permissions for special properties.
638 * Disallow setting of 'zoned' from within a local zone.
640 if (!INGLOBALZONE(curproc))
641 return (SET_ERROR(EPERM));
645 if (!INGLOBALZONE(curproc)) {
647 char setpoint[MAXNAMELEN];
649 * Unprivileged users are allowed to modify the
650 * quota on things *under* (ie. contained by)
651 * the thing they own.
653 if (dsl_prop_get_integer(dsname, "zoned", &zoned,
655 return (SET_ERROR(EPERM));
656 if (!zoned || strlen(dsname) <= strlen(setpoint))
657 return (SET_ERROR(EPERM));
661 case ZFS_PROP_MLSLABEL:
662 if (!is_system_labeled())
663 return (SET_ERROR(EPERM));
665 if (nvpair_value_string(propval, &strval) == 0) {
668 err = zfs_set_slabel_policy(dsname, strval, CRED());
675 return (zfs_secpolicy_write_perms(dsname, zfs_prop_to_name(prop), cr));
680 zfs_secpolicy_set_fsacl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
684 error = zfs_dozonecheck(zc->zc_name, cr);
689 * permission to set permissions will be evaluated later in
690 * dsl_deleg_can_allow()
697 zfs_secpolicy_rollback(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
699 return (zfs_secpolicy_write_perms(zc->zc_name,
700 ZFS_DELEG_PERM_ROLLBACK, cr));
705 zfs_secpolicy_send(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
713 * Generate the current snapshot name from the given objsetid, then
714 * use that name for the secpolicy/zone checks.
716 cp = strchr(zc->zc_name, '@');
718 return (SET_ERROR(EINVAL));
719 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
723 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &ds);
725 dsl_pool_rele(dp, FTAG);
729 dsl_dataset_name(ds, zc->zc_name);
731 error = zfs_secpolicy_write_perms_ds(zc->zc_name, ds,
732 ZFS_DELEG_PERM_SEND, cr);
733 dsl_dataset_rele(ds, FTAG);
734 dsl_pool_rele(dp, FTAG);
741 zfs_secpolicy_send_new(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
743 return (zfs_secpolicy_write_perms(zc->zc_name,
744 ZFS_DELEG_PERM_SEND, cr));
747 #ifdef HAVE_SMB_SHARE
750 zfs_secpolicy_deleg_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
755 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
756 NO_FOLLOW, NULL, &vp)) != 0)
759 /* Now make sure mntpnt and dataset are ZFS */
761 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
762 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
763 zc->zc_name) != 0)) {
765 return (SET_ERROR(EPERM));
769 return (dsl_deleg_access(zc->zc_name,
770 ZFS_DELEG_PERM_SHARE, cr));
772 #endif /* HAVE_SMB_SHARE */
775 zfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
777 #ifdef HAVE_SMB_SHARE
778 if (!INGLOBALZONE(curproc))
779 return (SET_ERROR(EPERM));
781 if (secpolicy_nfs(cr) == 0) {
784 return (zfs_secpolicy_deleg_share(zc, innvl, cr));
787 return (SET_ERROR(ENOTSUP));
788 #endif /* HAVE_SMB_SHARE */
792 zfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
794 #ifdef HAVE_SMB_SHARE
795 if (!INGLOBALZONE(curproc))
796 return (SET_ERROR(EPERM));
798 if (secpolicy_smb(cr) == 0) {
801 return (zfs_secpolicy_deleg_share(zc, innvl, cr));
804 return (SET_ERROR(ENOTSUP));
805 #endif /* HAVE_SMB_SHARE */
809 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
814 * Remove the @bla or /bla from the end of the name to get the parent.
816 (void) strncpy(parent, datasetname, parentsize);
817 cp = strrchr(parent, '@');
821 cp = strrchr(parent, '/');
823 return (SET_ERROR(ENOENT));
831 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
835 if ((error = zfs_secpolicy_write_perms(name,
836 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
839 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
844 zfs_secpolicy_destroy(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
846 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
850 * Destroying snapshots with delegated permissions requires
851 * descendant mount and destroy permissions.
855 zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
858 nvpair_t *pair, *nextpair;
861 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
862 return (SET_ERROR(EINVAL));
863 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
865 nextpair = nvlist_next_nvpair(snaps, pair);
866 error = zfs_secpolicy_destroy_perms(nvpair_name(pair), cr);
867 if (error == ENOENT) {
869 * Ignore any snapshots that don't exist (we consider
870 * them "already destroyed"). Remove the name from the
871 * nvl here in case the snapshot is created between
872 * now and when we try to destroy it (in which case
873 * we don't want to destroy it since we haven't
874 * checked for permission).
876 fnvlist_remove_nvpair(snaps, pair);
887 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
889 char parentname[MAXNAMELEN];
892 if ((error = zfs_secpolicy_write_perms(from,
893 ZFS_DELEG_PERM_RENAME, cr)) != 0)
896 if ((error = zfs_secpolicy_write_perms(from,
897 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
900 if ((error = zfs_get_parent(to, parentname,
901 sizeof (parentname))) != 0)
904 if ((error = zfs_secpolicy_write_perms(parentname,
905 ZFS_DELEG_PERM_CREATE, cr)) != 0)
908 if ((error = zfs_secpolicy_write_perms(parentname,
909 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
917 zfs_secpolicy_rename(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
919 return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
924 zfs_secpolicy_promote(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
927 dsl_dataset_t *clone;
930 error = zfs_secpolicy_write_perms(zc->zc_name,
931 ZFS_DELEG_PERM_PROMOTE, cr);
935 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
939 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &clone);
942 char parentname[MAXNAMELEN];
943 dsl_dataset_t *origin = NULL;
947 error = dsl_dataset_hold_obj(dd->dd_pool,
948 dd->dd_phys->dd_origin_obj, FTAG, &origin);
950 dsl_dataset_rele(clone, FTAG);
951 dsl_pool_rele(dp, FTAG);
955 error = zfs_secpolicy_write_perms_ds(zc->zc_name, clone,
956 ZFS_DELEG_PERM_MOUNT, cr);
958 dsl_dataset_name(origin, parentname);
960 error = zfs_secpolicy_write_perms_ds(parentname, origin,
961 ZFS_DELEG_PERM_PROMOTE, cr);
963 dsl_dataset_rele(clone, FTAG);
964 dsl_dataset_rele(origin, FTAG);
966 dsl_pool_rele(dp, FTAG);
972 zfs_secpolicy_recv(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
976 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
977 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
980 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
981 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
984 return (zfs_secpolicy_write_perms(zc->zc_name,
985 ZFS_DELEG_PERM_CREATE, cr));
989 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
991 return (zfs_secpolicy_write_perms(name,
992 ZFS_DELEG_PERM_SNAPSHOT, cr));
996 * Check for permission to create each snapshot in the nvlist.
1000 zfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1006 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
1007 return (SET_ERROR(EINVAL));
1008 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
1009 pair = nvlist_next_nvpair(snaps, pair)) {
1010 char *name = nvpair_name(pair);
1011 char *atp = strchr(name, '@');
1014 error = SET_ERROR(EINVAL);
1018 error = zfs_secpolicy_snapshot_perms(name, cr);
1027 * Check for permission to create each snapshot in the nvlist.
1031 zfs_secpolicy_bookmark(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1036 for (pair = nvlist_next_nvpair(innvl, NULL);
1037 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
1038 char *name = nvpair_name(pair);
1039 char *hashp = strchr(name, '#');
1041 if (hashp == NULL) {
1042 error = SET_ERROR(EINVAL);
1046 error = zfs_secpolicy_write_perms(name,
1047 ZFS_DELEG_PERM_BOOKMARK, cr);
1057 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1059 nvpair_t *pair, *nextpair;
1062 for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
1064 char *name = nvpair_name(pair);
1065 char *hashp = strchr(name, '#');
1066 nextpair = nvlist_next_nvpair(innvl, pair);
1068 if (hashp == NULL) {
1069 error = SET_ERROR(EINVAL);
1074 error = zfs_secpolicy_write_perms(name,
1075 ZFS_DELEG_PERM_DESTROY, cr);
1077 if (error == ENOENT) {
1079 * Ignore any filesystems that don't exist (we consider
1080 * their bookmarks "already destroyed"). Remove
1081 * the name from the nvl here in case the filesystem
1082 * is created between now and when we try to destroy
1083 * the bookmark (in which case we don't want to
1084 * destroy it since we haven't checked for permission).
1086 fnvlist_remove_nvpair(innvl, pair);
1098 zfs_secpolicy_log_history(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1101 * Even root must have a proper TSD so that we know what pool
1104 if (tsd_get(zfs_allow_log_key) == NULL)
1105 return (SET_ERROR(EPERM));
1110 zfs_secpolicy_create_clone(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1112 char parentname[MAXNAMELEN];
1116 if ((error = zfs_get_parent(zc->zc_name, parentname,
1117 sizeof (parentname))) != 0)
1120 if (nvlist_lookup_string(innvl, "origin", &origin) == 0 &&
1121 (error = zfs_secpolicy_write_perms(origin,
1122 ZFS_DELEG_PERM_CLONE, cr)) != 0)
1125 if ((error = zfs_secpolicy_write_perms(parentname,
1126 ZFS_DELEG_PERM_CREATE, cr)) != 0)
1129 return (zfs_secpolicy_write_perms(parentname,
1130 ZFS_DELEG_PERM_MOUNT, cr));
1134 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1135 * SYS_CONFIG privilege, which is not available in a local zone.
1139 zfs_secpolicy_config(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1141 if (secpolicy_sys_config(cr, B_FALSE) != 0)
1142 return (SET_ERROR(EPERM));
1148 * Policy for object to name lookups.
1152 zfs_secpolicy_diff(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1156 if ((error = secpolicy_sys_config(cr, B_FALSE)) == 0)
1159 error = zfs_secpolicy_write_perms(zc->zc_name, ZFS_DELEG_PERM_DIFF, cr);
1164 * Policy for fault injection. Requires all privileges.
1168 zfs_secpolicy_inject(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1170 return (secpolicy_zinject(cr));
1175 zfs_secpolicy_inherit_prop(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1177 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
1179 if (prop == ZPROP_INVAL) {
1180 if (!zfs_prop_user(zc->zc_value))
1181 return (SET_ERROR(EINVAL));
1182 return (zfs_secpolicy_write_perms(zc->zc_name,
1183 ZFS_DELEG_PERM_USERPROP, cr));
1185 return (zfs_secpolicy_setprop(zc->zc_name, prop,
1191 zfs_secpolicy_userspace_one(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1193 int err = zfs_secpolicy_read(zc, innvl, cr);
1197 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1198 return (SET_ERROR(EINVAL));
1200 if (zc->zc_value[0] == 0) {
1202 * They are asking about a posix uid/gid. If it's
1203 * themself, allow it.
1205 if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
1206 zc->zc_objset_type == ZFS_PROP_USERQUOTA) {
1207 if (zc->zc_guid == crgetuid(cr))
1210 if (groupmember(zc->zc_guid, cr))
1215 return (zfs_secpolicy_write_perms(zc->zc_name,
1216 userquota_perms[zc->zc_objset_type], cr));
1220 zfs_secpolicy_userspace_many(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1222 int err = zfs_secpolicy_read(zc, innvl, cr);
1226 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1227 return (SET_ERROR(EINVAL));
1229 return (zfs_secpolicy_write_perms(zc->zc_name,
1230 userquota_perms[zc->zc_objset_type], cr));
1235 zfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1237 return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION,
1243 zfs_secpolicy_hold(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1249 error = nvlist_lookup_nvlist(innvl, "holds", &holds);
1251 return (SET_ERROR(EINVAL));
1253 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
1254 pair = nvlist_next_nvpair(holds, pair)) {
1255 char fsname[MAXNAMELEN];
1256 error = dmu_fsname(nvpair_name(pair), fsname);
1259 error = zfs_secpolicy_write_perms(fsname,
1260 ZFS_DELEG_PERM_HOLD, cr);
1269 zfs_secpolicy_release(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1274 for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
1275 pair = nvlist_next_nvpair(innvl, pair)) {
1276 char fsname[MAXNAMELEN];
1277 error = dmu_fsname(nvpair_name(pair), fsname);
1280 error = zfs_secpolicy_write_perms(fsname,
1281 ZFS_DELEG_PERM_RELEASE, cr);
1289 * Policy for allowing temporary snapshots to be taken or released
1292 zfs_secpolicy_tmp_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1295 * A temporary snapshot is the same as a snapshot,
1296 * hold, destroy and release all rolled into one.
1297 * Delegated diff alone is sufficient that we allow this.
1301 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
1302 ZFS_DELEG_PERM_DIFF, cr)) == 0)
1305 error = zfs_secpolicy_snapshot_perms(zc->zc_name, cr);
1307 error = zfs_secpolicy_hold(zc, innvl, cr);
1309 error = zfs_secpolicy_release(zc, innvl, cr);
1311 error = zfs_secpolicy_destroy(zc, innvl, cr);
1316 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1319 get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
1323 nvlist_t *list = NULL;
1326 * Read in and unpack the user-supplied nvlist.
1329 return (SET_ERROR(EINVAL));
1331 packed = kmem_alloc(size, KM_SLEEP);
1333 if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
1335 kmem_free(packed, size);
1339 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
1340 kmem_free(packed, size);
1344 kmem_free(packed, size);
1351 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1352 * Entries will be removed from the end of the nvlist, and one int32 entry
1353 * named "N_MORE_ERRORS" will be added indicating how many entries were
1357 nvlist_smush(nvlist_t *errors, size_t max)
1361 size = fnvlist_size(errors);
1364 nvpair_t *more_errors;
1368 return (SET_ERROR(ENOMEM));
1370 fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, 0);
1371 more_errors = nvlist_prev_nvpair(errors, NULL);
1374 nvpair_t *pair = nvlist_prev_nvpair(errors,
1376 fnvlist_remove_nvpair(errors, pair);
1378 size = fnvlist_size(errors);
1379 } while (size > max);
1381 fnvlist_remove_nvpair(errors, more_errors);
1382 fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, n);
1383 ASSERT3U(fnvlist_size(errors), <=, max);
1390 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
1392 char *packed = NULL;
1396 size = fnvlist_size(nvl);
1398 if (size > zc->zc_nvlist_dst_size) {
1399 error = SET_ERROR(ENOMEM);
1401 packed = fnvlist_pack(nvl, &size);
1402 if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
1403 size, zc->zc_iflags) != 0)
1404 error = SET_ERROR(EFAULT);
1405 fnvlist_pack_free(packed, size);
1408 zc->zc_nvlist_dst_size = size;
1409 zc->zc_nvlist_dst_filled = B_TRUE;
1414 get_zfs_sb(const char *dsname, zfs_sb_t **zsbp)
1419 error = dmu_objset_hold(dsname, FTAG, &os);
1422 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1423 dmu_objset_rele(os, FTAG);
1424 return (SET_ERROR(EINVAL));
1427 mutex_enter(&os->os_user_ptr_lock);
1428 *zsbp = dmu_objset_get_user(os);
1429 if (*zsbp && (*zsbp)->z_sb) {
1430 atomic_inc(&((*zsbp)->z_sb->s_active));
1432 error = SET_ERROR(ESRCH);
1434 mutex_exit(&os->os_user_ptr_lock);
1435 dmu_objset_rele(os, FTAG);
1440 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1441 * case its z_sb will be NULL, and it will be opened as the owner.
1442 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1443 * which prevents all inode ops from running.
1446 zfs_sb_hold(const char *name, void *tag, zfs_sb_t **zsbp, boolean_t writer)
1450 if (get_zfs_sb(name, zsbp) != 0)
1451 error = zfs_sb_create(name, zsbp);
1453 rrw_enter(&(*zsbp)->z_teardown_lock, (writer) ? RW_WRITER :
1455 if ((*zsbp)->z_unmounted) {
1457 * XXX we could probably try again, since the unmounting
1458 * thread should be just about to disassociate the
1459 * objset from the zsb.
1461 rrw_exit(&(*zsbp)->z_teardown_lock, tag);
1462 return (SET_ERROR(EBUSY));
1469 zfs_sb_rele(zfs_sb_t *zsb, void *tag)
1471 rrw_exit(&zsb->z_teardown_lock, tag);
1474 deactivate_super(zsb->z_sb);
1476 dmu_objset_disown(zsb->z_os, zsb);
1482 zfs_ioc_pool_create(zfs_cmd_t *zc)
1485 nvlist_t *config, *props = NULL;
1486 nvlist_t *rootprops = NULL;
1487 nvlist_t *zplprops = NULL;
1489 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1490 zc->zc_iflags, &config)))
1493 if (zc->zc_nvlist_src_size != 0 && (error =
1494 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1495 zc->zc_iflags, &props))) {
1496 nvlist_free(config);
1501 nvlist_t *nvl = NULL;
1502 uint64_t version = SPA_VERSION;
1504 (void) nvlist_lookup_uint64(props,
1505 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
1506 if (!SPA_VERSION_IS_SUPPORTED(version)) {
1507 error = SET_ERROR(EINVAL);
1508 goto pool_props_bad;
1510 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
1512 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
1514 nvlist_free(config);
1518 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
1520 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1521 error = zfs_fill_zplprops_root(version, rootprops,
1524 goto pool_props_bad;
1527 error = spa_create(zc->zc_name, config, props, zplprops);
1530 * Set the remaining root properties
1532 if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
1533 ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
1534 (void) spa_destroy(zc->zc_name);
1537 nvlist_free(rootprops);
1538 nvlist_free(zplprops);
1539 nvlist_free(config);
1546 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
1549 zfs_log_history(zc);
1550 error = spa_destroy(zc->zc_name);
1552 zvol_remove_minors(zc->zc_name);
1557 zfs_ioc_pool_import(zfs_cmd_t *zc)
1559 nvlist_t *config, *props = NULL;
1563 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1564 zc->zc_iflags, &config)) != 0)
1567 if (zc->zc_nvlist_src_size != 0 && (error =
1568 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1569 zc->zc_iflags, &props))) {
1570 nvlist_free(config);
1574 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1575 guid != zc->zc_guid)
1576 error = SET_ERROR(EINVAL);
1578 error = spa_import(zc->zc_name, config, props, zc->zc_cookie);
1580 if (zc->zc_nvlist_dst != 0) {
1583 if ((err = put_nvlist(zc, config)) != 0)
1587 nvlist_free(config);
1596 zfs_ioc_pool_export(zfs_cmd_t *zc)
1599 boolean_t force = (boolean_t)zc->zc_cookie;
1600 boolean_t hardforce = (boolean_t)zc->zc_guid;
1602 zfs_log_history(zc);
1603 error = spa_export(zc->zc_name, NULL, force, hardforce);
1605 zvol_remove_minors(zc->zc_name);
1610 zfs_ioc_pool_configs(zfs_cmd_t *zc)
1615 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
1616 return (SET_ERROR(EEXIST));
1618 error = put_nvlist(zc, configs);
1620 nvlist_free(configs);
1627 * zc_name name of the pool
1630 * zc_cookie real errno
1631 * zc_nvlist_dst config nvlist
1632 * zc_nvlist_dst_size size of config nvlist
1635 zfs_ioc_pool_stats(zfs_cmd_t *zc)
1641 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
1642 sizeof (zc->zc_value));
1644 if (config != NULL) {
1645 ret = put_nvlist(zc, config);
1646 nvlist_free(config);
1649 * The config may be present even if 'error' is non-zero.
1650 * In this case we return success, and preserve the real errno
1653 zc->zc_cookie = error;
1662 * Try to import the given pool, returning pool stats as appropriate so that
1663 * user land knows which devices are available and overall pool health.
1666 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
1668 nvlist_t *tryconfig, *config;
1671 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1672 zc->zc_iflags, &tryconfig)) != 0)
1675 config = spa_tryimport(tryconfig);
1677 nvlist_free(tryconfig);
1680 return (SET_ERROR(EINVAL));
1682 error = put_nvlist(zc, config);
1683 nvlist_free(config);
1690 * zc_name name of the pool
1691 * zc_cookie scan func (pool_scan_func_t)
1694 zfs_ioc_pool_scan(zfs_cmd_t *zc)
1699 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1702 if (zc->zc_cookie == POOL_SCAN_NONE)
1703 error = spa_scan_stop(spa);
1705 error = spa_scan(spa, zc->zc_cookie);
1707 spa_close(spa, FTAG);
1713 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
1718 error = spa_open(zc->zc_name, &spa, FTAG);
1721 spa_close(spa, FTAG);
1727 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
1732 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1735 if (zc->zc_cookie < spa_version(spa) ||
1736 !SPA_VERSION_IS_SUPPORTED(zc->zc_cookie)) {
1737 spa_close(spa, FTAG);
1738 return (SET_ERROR(EINVAL));
1741 spa_upgrade(spa, zc->zc_cookie);
1742 spa_close(spa, FTAG);
1748 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
1755 if ((size = zc->zc_history_len) == 0)
1756 return (SET_ERROR(EINVAL));
1758 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1761 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
1762 spa_close(spa, FTAG);
1763 return (SET_ERROR(ENOTSUP));
1766 hist_buf = vmem_alloc(size, KM_SLEEP);
1767 if ((error = spa_history_get(spa, &zc->zc_history_offset,
1768 &zc->zc_history_len, hist_buf)) == 0) {
1769 error = ddi_copyout(hist_buf,
1770 (void *)(uintptr_t)zc->zc_history,
1771 zc->zc_history_len, zc->zc_iflags);
1774 spa_close(spa, FTAG);
1775 vmem_free(hist_buf, size);
1780 zfs_ioc_pool_reguid(zfs_cmd_t *zc)
1785 error = spa_open(zc->zc_name, &spa, FTAG);
1787 error = spa_change_guid(spa);
1788 spa_close(spa, FTAG);
1794 zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
1796 return (dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value));
1801 * zc_name name of filesystem
1802 * zc_obj object to find
1805 * zc_value name of object
1808 zfs_ioc_obj_to_path(zfs_cmd_t *zc)
1813 /* XXX reading from objset not owned */
1814 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1816 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1817 dmu_objset_rele(os, FTAG);
1818 return (SET_ERROR(EINVAL));
1820 error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
1821 sizeof (zc->zc_value));
1822 dmu_objset_rele(os, FTAG);
1829 * zc_name name of filesystem
1830 * zc_obj object to find
1833 * zc_stat stats on object
1834 * zc_value path to object
1837 zfs_ioc_obj_to_stats(zfs_cmd_t *zc)
1842 /* XXX reading from objset not owned */
1843 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1845 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1846 dmu_objset_rele(os, FTAG);
1847 return (SET_ERROR(EINVAL));
1849 error = zfs_obj_to_stats(os, zc->zc_obj, &zc->zc_stat, zc->zc_value,
1850 sizeof (zc->zc_value));
1851 dmu_objset_rele(os, FTAG);
1857 zfs_ioc_vdev_add(zfs_cmd_t *zc)
1863 error = spa_open(zc->zc_name, &spa, FTAG);
1867 error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1868 zc->zc_iflags, &config);
1870 error = spa_vdev_add(spa, config);
1871 nvlist_free(config);
1873 spa_close(spa, FTAG);
1879 * zc_name name of the pool
1880 * zc_nvlist_conf nvlist of devices to remove
1881 * zc_cookie to stop the remove?
1884 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
1889 error = spa_open(zc->zc_name, &spa, FTAG);
1892 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
1893 spa_close(spa, FTAG);
1898 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
1902 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1904 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1906 switch (zc->zc_cookie) {
1907 case VDEV_STATE_ONLINE:
1908 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
1911 case VDEV_STATE_OFFLINE:
1912 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
1915 case VDEV_STATE_FAULTED:
1916 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1917 zc->zc_obj != VDEV_AUX_EXTERNAL)
1918 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1920 error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
1923 case VDEV_STATE_DEGRADED:
1924 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1925 zc->zc_obj != VDEV_AUX_EXTERNAL)
1926 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1928 error = vdev_degrade(spa, zc->zc_guid, zc->zc_obj);
1932 error = SET_ERROR(EINVAL);
1934 zc->zc_cookie = newstate;
1935 spa_close(spa, FTAG);
1940 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
1943 int replacing = zc->zc_cookie;
1947 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1950 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1951 zc->zc_iflags, &config)) == 0) {
1952 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
1953 nvlist_free(config);
1956 spa_close(spa, FTAG);
1961 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
1966 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1969 error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
1971 spa_close(spa, FTAG);
1976 zfs_ioc_vdev_split(zfs_cmd_t *zc)
1979 nvlist_t *config, *props = NULL;
1981 boolean_t exp = !!(zc->zc_cookie & ZPOOL_EXPORT_AFTER_SPLIT);
1983 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1986 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1987 zc->zc_iflags, &config))) {
1988 spa_close(spa, FTAG);
1992 if (zc->zc_nvlist_src_size != 0 && (error =
1993 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1994 zc->zc_iflags, &props))) {
1995 spa_close(spa, FTAG);
1996 nvlist_free(config);
2000 error = spa_vdev_split_mirror(spa, zc->zc_string, config, props, exp);
2002 spa_close(spa, FTAG);
2004 nvlist_free(config);
2011 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
2014 char *path = zc->zc_value;
2015 uint64_t guid = zc->zc_guid;
2018 error = spa_open(zc->zc_name, &spa, FTAG);
2022 error = spa_vdev_setpath(spa, guid, path);
2023 spa_close(spa, FTAG);
2028 zfs_ioc_vdev_setfru(zfs_cmd_t *zc)
2031 char *fru = zc->zc_value;
2032 uint64_t guid = zc->zc_guid;
2035 error = spa_open(zc->zc_name, &spa, FTAG);
2039 error = spa_vdev_setfru(spa, guid, fru);
2040 spa_close(spa, FTAG);
2045 zfs_ioc_objset_stats_impl(zfs_cmd_t *zc, objset_t *os)
2050 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
2052 if (zc->zc_nvlist_dst != 0 &&
2053 (error = dsl_prop_get_all(os, &nv)) == 0) {
2054 dmu_objset_stats(os, nv);
2056 * NB: zvol_get_stats() will read the objset contents,
2057 * which we aren't supposed to do with a
2058 * DS_MODE_USER hold, because it could be
2059 * inconsistent. So this is a bit of a workaround...
2060 * XXX reading with out owning
2062 if (!zc->zc_objset_stats.dds_inconsistent &&
2063 dmu_objset_type(os) == DMU_OST_ZVOL) {
2064 error = zvol_get_stats(os, nv);
2070 error = put_nvlist(zc, nv);
2079 * zc_name name of filesystem
2080 * zc_nvlist_dst_size size of buffer for property nvlist
2083 * zc_objset_stats stats
2084 * zc_nvlist_dst property nvlist
2085 * zc_nvlist_dst_size size of property nvlist
2088 zfs_ioc_objset_stats(zfs_cmd_t *zc)
2093 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
2095 error = zfs_ioc_objset_stats_impl(zc, os);
2096 dmu_objset_rele(os, FTAG);
2104 * zc_name name of filesystem
2105 * zc_nvlist_dst_size size of buffer for property nvlist
2108 * zc_nvlist_dst received property nvlist
2109 * zc_nvlist_dst_size size of received property nvlist
2111 * Gets received properties (distinct from local properties on or after
2112 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2113 * local property values.
2116 zfs_ioc_objset_recvd_props(zfs_cmd_t *zc)
2122 * Without this check, we would return local property values if the
2123 * caller has not already received properties on or after
2124 * SPA_VERSION_RECVD_PROPS.
2126 if (!dsl_prop_get_hasrecvd(zc->zc_name))
2127 return (SET_ERROR(ENOTSUP));
2129 if (zc->zc_nvlist_dst != 0 &&
2130 (error = dsl_prop_get_received(zc->zc_name, &nv)) == 0) {
2131 error = put_nvlist(zc, nv);
2139 nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
2145 * zfs_get_zplprop() will either find a value or give us
2146 * the default value (if there is one).
2148 if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
2150 VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
2156 * zc_name name of filesystem
2157 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2160 * zc_nvlist_dst zpl property nvlist
2161 * zc_nvlist_dst_size size of zpl property nvlist
2164 zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
2169 /* XXX reading without owning */
2170 if ((err = dmu_objset_hold(zc->zc_name, FTAG, &os)))
2173 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
2176 * NB: nvl_add_zplprop() will read the objset contents,
2177 * which we aren't supposed to do with a DS_MODE_USER
2178 * hold, because it could be inconsistent.
2180 if (zc->zc_nvlist_dst != 0 &&
2181 !zc->zc_objset_stats.dds_inconsistent &&
2182 dmu_objset_type(os) == DMU_OST_ZFS) {
2185 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2186 if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
2187 (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
2188 (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
2189 (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
2190 err = put_nvlist(zc, nv);
2193 err = SET_ERROR(ENOENT);
2195 dmu_objset_rele(os, FTAG);
2200 dataset_name_hidden(const char *name)
2203 * Skip over datasets that are not visible in this zone,
2204 * internal datasets (which have a $ in their name), and
2205 * temporary datasets (which have a % in their name).
2207 if (strchr(name, '$') != NULL)
2209 if (strchr(name, '%') != NULL)
2211 if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
2218 * zc_name name of filesystem
2219 * zc_cookie zap cursor
2220 * zc_nvlist_dst_size size of buffer for property nvlist
2223 * zc_name name of next filesystem
2224 * zc_cookie zap cursor
2225 * zc_objset_stats stats
2226 * zc_nvlist_dst property nvlist
2227 * zc_nvlist_dst_size size of property nvlist
2230 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
2235 size_t orig_len = strlen(zc->zc_name);
2238 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os))) {
2239 if (error == ENOENT)
2240 error = SET_ERROR(ESRCH);
2244 p = strrchr(zc->zc_name, '/');
2245 if (p == NULL || p[1] != '\0')
2246 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
2247 p = zc->zc_name + strlen(zc->zc_name);
2250 error = dmu_dir_list_next(os,
2251 sizeof (zc->zc_name) - (p - zc->zc_name), p,
2252 NULL, &zc->zc_cookie);
2253 if (error == ENOENT)
2254 error = SET_ERROR(ESRCH);
2255 } while (error == 0 && dataset_name_hidden(zc->zc_name));
2256 dmu_objset_rele(os, FTAG);
2259 * If it's an internal dataset (ie. with a '$' in its name),
2260 * don't try to get stats for it, otherwise we'll return ENOENT.
2262 if (error == 0 && strchr(zc->zc_name, '$') == NULL) {
2263 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
2264 if (error == ENOENT) {
2265 /* We lost a race with destroy, get the next one. */
2266 zc->zc_name[orig_len] = '\0';
2275 * zc_name name of filesystem
2276 * zc_cookie zap cursor
2277 * zc_nvlist_dst_size size of buffer for property nvlist
2280 * zc_name name of next snapshot
2281 * zc_objset_stats stats
2282 * zc_nvlist_dst property nvlist
2283 * zc_nvlist_dst_size size of property nvlist
2286 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
2291 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
2293 return (error == ENOENT ? ESRCH : error);
2297 * A dataset name of maximum length cannot have any snapshots,
2298 * so exit immediately.
2300 if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
2301 dmu_objset_rele(os, FTAG);
2302 return (SET_ERROR(ESRCH));
2305 error = dmu_snapshot_list_next(os,
2306 sizeof (zc->zc_name) - strlen(zc->zc_name),
2307 zc->zc_name + strlen(zc->zc_name), &zc->zc_obj, &zc->zc_cookie,
2310 if (error == 0 && !zc->zc_simple) {
2312 dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
2314 error = dsl_dataset_hold_obj(dp, zc->zc_obj, FTAG, &ds);
2318 error = dmu_objset_from_ds(ds, &ossnap);
2320 error = zfs_ioc_objset_stats_impl(zc, ossnap);
2321 dsl_dataset_rele(ds, FTAG);
2323 } else if (error == ENOENT) {
2324 error = SET_ERROR(ESRCH);
2327 dmu_objset_rele(os, FTAG);
2328 /* if we failed, undo the @ that we tacked on to zc_name */
2330 *strchr(zc->zc_name, '@') = '\0';
2335 zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
2337 const char *propname = nvpair_name(pair);
2339 unsigned int vallen;
2342 zfs_userquota_prop_t type;
2348 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2350 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2351 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2353 return (SET_ERROR(EINVAL));
2357 * A correctly constructed propname is encoded as
2358 * userquota@<rid>-<domain>.
2360 if ((dash = strchr(propname, '-')) == NULL ||
2361 nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
2363 return (SET_ERROR(EINVAL));
2370 err = zfs_sb_hold(dsname, FTAG, &zsb, B_FALSE);
2372 err = zfs_set_userquota(zsb, type, domain, rid, quota);
2373 zfs_sb_rele(zsb, FTAG);
2380 * If the named property is one that has a special function to set its value,
2381 * return 0 on success and a positive error code on failure; otherwise if it is
2382 * not one of the special properties handled by this function, return -1.
2384 * XXX: It would be better for callers of the property interface if we handled
2385 * these special cases in dsl_prop.c (in the dsl layer).
2388 zfs_prop_set_special(const char *dsname, zprop_source_t source,
2391 const char *propname = nvpair_name(pair);
2392 zfs_prop_t prop = zfs_name_to_prop(propname);
2396 if (prop == ZPROP_INVAL) {
2397 if (zfs_prop_userquota(propname))
2398 return (zfs_prop_set_userquota(dsname, pair));
2402 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2404 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2405 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2409 if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
2412 VERIFY(0 == nvpair_value_uint64(pair, &intval));
2415 case ZFS_PROP_QUOTA:
2416 err = dsl_dir_set_quota(dsname, source, intval);
2418 case ZFS_PROP_REFQUOTA:
2419 err = dsl_dataset_set_refquota(dsname, source, intval);
2421 case ZFS_PROP_RESERVATION:
2422 err = dsl_dir_set_reservation(dsname, source, intval);
2424 case ZFS_PROP_REFRESERVATION:
2425 err = dsl_dataset_set_refreservation(dsname, source, intval);
2427 case ZFS_PROP_VOLSIZE:
2428 err = zvol_set_volsize(dsname, intval);
2430 case ZFS_PROP_SNAPDEV:
2431 err = zvol_set_snapdev(dsname, intval);
2433 case ZFS_PROP_VERSION:
2437 if ((err = zfs_sb_hold(dsname, FTAG, &zsb, B_TRUE)) != 0)
2440 err = zfs_set_version(zsb, intval);
2441 zfs_sb_rele(zsb, FTAG);
2443 if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
2446 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
2447 (void) strcpy(zc->zc_name, dsname);
2448 (void) zfs_ioc_userspace_upgrade(zc);
2449 kmem_free(zc, sizeof (zfs_cmd_t));
2461 * This function is best effort. If it fails to set any of the given properties,
2462 * it continues to set as many as it can and returns the last error
2463 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2464 * with the list of names of all the properties that failed along with the
2465 * corresponding error numbers.
2467 * If every property is set successfully, zero is returned and errlist is not
2471 zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
2480 nvlist_t *genericnvl = fnvlist_alloc();
2481 nvlist_t *retrynvl = fnvlist_alloc();
2484 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2485 const char *propname = nvpair_name(pair);
2486 zfs_prop_t prop = zfs_name_to_prop(propname);
2489 /* decode the property value */
2491 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2493 attrs = fnvpair_value_nvlist(pair);
2494 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2496 err = SET_ERROR(EINVAL);
2499 /* Validate value type */
2500 if (err == 0 && prop == ZPROP_INVAL) {
2501 if (zfs_prop_user(propname)) {
2502 if (nvpair_type(propval) != DATA_TYPE_STRING)
2503 err = SET_ERROR(EINVAL);
2504 } else if (zfs_prop_userquota(propname)) {
2505 if (nvpair_type(propval) !=
2506 DATA_TYPE_UINT64_ARRAY)
2507 err = SET_ERROR(EINVAL);
2509 err = SET_ERROR(EINVAL);
2511 } else if (err == 0) {
2512 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2513 if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
2514 err = SET_ERROR(EINVAL);
2515 } else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
2518 intval = fnvpair_value_uint64(propval);
2520 switch (zfs_prop_get_type(prop)) {
2521 case PROP_TYPE_NUMBER:
2523 case PROP_TYPE_STRING:
2524 err = SET_ERROR(EINVAL);
2526 case PROP_TYPE_INDEX:
2527 if (zfs_prop_index_to_string(prop,
2528 intval, &unused) != 0)
2529 err = SET_ERROR(EINVAL);
2533 "unknown property type");
2536 err = SET_ERROR(EINVAL);
2540 /* Validate permissions */
2542 err = zfs_check_settable(dsname, pair, CRED());
2545 err = zfs_prop_set_special(dsname, source, pair);
2548 * For better performance we build up a list of
2549 * properties to set in a single transaction.
2551 err = nvlist_add_nvpair(genericnvl, pair);
2552 } else if (err != 0 && nvl != retrynvl) {
2554 * This may be a spurious error caused by
2555 * receiving quota and reservation out of order.
2556 * Try again in a second pass.
2558 err = nvlist_add_nvpair(retrynvl, pair);
2563 if (errlist != NULL)
2564 fnvlist_add_int32(errlist, propname, err);
2569 if (nvl != retrynvl && !nvlist_empty(retrynvl)) {
2574 if (!nvlist_empty(genericnvl) &&
2575 dsl_props_set(dsname, source, genericnvl) != 0) {
2577 * If this fails, we still want to set as many properties as we
2578 * can, so try setting them individually.
2581 while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) {
2582 const char *propname = nvpair_name(pair);
2586 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2588 attrs = fnvpair_value_nvlist(pair);
2589 propval = fnvlist_lookup_nvpair(attrs,
2593 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2594 strval = fnvpair_value_string(propval);
2595 err = dsl_prop_set_string(dsname, propname,
2598 intval = fnvpair_value_uint64(propval);
2599 err = dsl_prop_set_int(dsname, propname, source,
2604 if (errlist != NULL) {
2605 fnvlist_add_int32(errlist, propname,
2612 nvlist_free(genericnvl);
2613 nvlist_free(retrynvl);
2619 * Check that all the properties are valid user properties.
2622 zfs_check_userprops(const char *fsname, nvlist_t *nvl)
2624 nvpair_t *pair = NULL;
2627 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2628 const char *propname = nvpair_name(pair);
2630 if (!zfs_prop_user(propname) ||
2631 nvpair_type(pair) != DATA_TYPE_STRING)
2632 return (SET_ERROR(EINVAL));
2634 if ((error = zfs_secpolicy_write_perms(fsname,
2635 ZFS_DELEG_PERM_USERPROP, CRED())))
2638 if (strlen(propname) >= ZAP_MAXNAMELEN)
2639 return (SET_ERROR(ENAMETOOLONG));
2641 if (strlen(fnvpair_value_string(pair)) >= ZAP_MAXVALUELEN)
2642 return (SET_ERROR(E2BIG));
2648 props_skip(nvlist_t *props, nvlist_t *skipped, nvlist_t **newprops)
2652 VERIFY(nvlist_alloc(newprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2655 while ((pair = nvlist_next_nvpair(props, pair)) != NULL) {
2656 if (nvlist_exists(skipped, nvpair_name(pair)))
2659 VERIFY(nvlist_add_nvpair(*newprops, pair) == 0);
2664 clear_received_props(const char *dsname, nvlist_t *props,
2668 nvlist_t *cleared_props = NULL;
2669 props_skip(props, skipped, &cleared_props);
2670 if (!nvlist_empty(cleared_props)) {
2672 * Acts on local properties until the dataset has received
2673 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2675 zprop_source_t flags = (ZPROP_SRC_NONE |
2676 (dsl_prop_get_hasrecvd(dsname) ? ZPROP_SRC_RECEIVED : 0));
2677 err = zfs_set_prop_nvlist(dsname, flags, cleared_props, NULL);
2679 nvlist_free(cleared_props);
2685 * zc_name name of filesystem
2686 * zc_value name of property to set
2687 * zc_nvlist_src{_size} nvlist of properties to apply
2688 * zc_cookie received properties flag
2691 * zc_nvlist_dst{_size} error for each unapplied received property
2694 zfs_ioc_set_prop(zfs_cmd_t *zc)
2697 boolean_t received = zc->zc_cookie;
2698 zprop_source_t source = (received ? ZPROP_SRC_RECEIVED :
2703 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2704 zc->zc_iflags, &nvl)) != 0)
2708 nvlist_t *origprops;
2710 if (dsl_prop_get_received(zc->zc_name, &origprops) == 0) {
2711 (void) clear_received_props(zc->zc_name,
2713 nvlist_free(origprops);
2716 error = dsl_prop_set_hasrecvd(zc->zc_name);
2719 errors = fnvlist_alloc();
2721 error = zfs_set_prop_nvlist(zc->zc_name, source, nvl, errors);
2723 if (zc->zc_nvlist_dst != 0 && errors != NULL) {
2724 (void) put_nvlist(zc, errors);
2727 nvlist_free(errors);
2734 * zc_name name of filesystem
2735 * zc_value name of property to inherit
2736 * zc_cookie revert to received value if TRUE
2741 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
2743 const char *propname = zc->zc_value;
2744 zfs_prop_t prop = zfs_name_to_prop(propname);
2745 boolean_t received = zc->zc_cookie;
2746 zprop_source_t source = (received
2747 ? ZPROP_SRC_NONE /* revert to received value, if any */
2748 : ZPROP_SRC_INHERITED); /* explicitly inherit */
2757 * zfs_prop_set_special() expects properties in the form of an
2758 * nvpair with type info.
2760 if (prop == ZPROP_INVAL) {
2761 if (!zfs_prop_user(propname))
2762 return (SET_ERROR(EINVAL));
2764 type = PROP_TYPE_STRING;
2765 } else if (prop == ZFS_PROP_VOLSIZE ||
2766 prop == ZFS_PROP_VERSION) {
2767 return (SET_ERROR(EINVAL));
2769 type = zfs_prop_get_type(prop);
2772 VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2775 case PROP_TYPE_STRING:
2776 VERIFY(0 == nvlist_add_string(dummy, propname, ""));
2778 case PROP_TYPE_NUMBER:
2779 case PROP_TYPE_INDEX:
2780 VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
2784 return (SET_ERROR(EINVAL));
2787 pair = nvlist_next_nvpair(dummy, NULL);
2788 err = zfs_prop_set_special(zc->zc_name, source, pair);
2791 return (err); /* special property already handled */
2794 * Only check this in the non-received case. We want to allow
2795 * 'inherit -S' to revert non-inheritable properties like quota
2796 * and reservation to the received or default values even though
2797 * they are not considered inheritable.
2799 if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
2800 return (SET_ERROR(EINVAL));
2803 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2804 return (dsl_prop_inherit(zc->zc_name, zc->zc_value, source));
2808 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
2815 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2816 zc->zc_iflags, &props)))
2820 * If the only property is the configfile, then just do a spa_lookup()
2821 * to handle the faulted case.
2823 pair = nvlist_next_nvpair(props, NULL);
2824 if (pair != NULL && strcmp(nvpair_name(pair),
2825 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
2826 nvlist_next_nvpair(props, pair) == NULL) {
2827 mutex_enter(&spa_namespace_lock);
2828 if ((spa = spa_lookup(zc->zc_name)) != NULL) {
2829 spa_configfile_set(spa, props, B_FALSE);
2830 spa_config_sync(spa, B_FALSE, B_TRUE);
2832 mutex_exit(&spa_namespace_lock);
2839 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2844 error = spa_prop_set(spa, props);
2847 spa_close(spa, FTAG);
2853 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
2857 nvlist_t *nvp = NULL;
2859 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2861 * If the pool is faulted, there may be properties we can still
2862 * get (such as altroot and cachefile), so attempt to get them
2865 mutex_enter(&spa_namespace_lock);
2866 if ((spa = spa_lookup(zc->zc_name)) != NULL)
2867 error = spa_prop_get(spa, &nvp);
2868 mutex_exit(&spa_namespace_lock);
2870 error = spa_prop_get(spa, &nvp);
2871 spa_close(spa, FTAG);
2874 if (error == 0 && zc->zc_nvlist_dst != 0)
2875 error = put_nvlist(zc, nvp);
2877 error = SET_ERROR(EFAULT);
2885 * zc_name name of filesystem
2886 * zc_nvlist_src{_size} nvlist of delegated permissions
2887 * zc_perm_action allow/unallow flag
2892 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
2895 nvlist_t *fsaclnv = NULL;
2897 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2898 zc->zc_iflags, &fsaclnv)) != 0)
2902 * Verify nvlist is constructed correctly
2904 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
2905 nvlist_free(fsaclnv);
2906 return (SET_ERROR(EINVAL));
2910 * If we don't have PRIV_SYS_MOUNT, then validate
2911 * that user is allowed to hand out each permission in
2915 error = secpolicy_zfs(CRED());
2917 if (zc->zc_perm_action == B_FALSE) {
2918 error = dsl_deleg_can_allow(zc->zc_name,
2921 error = dsl_deleg_can_unallow(zc->zc_name,
2927 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
2929 nvlist_free(fsaclnv);
2935 * zc_name name of filesystem
2938 * zc_nvlist_src{_size} nvlist of delegated permissions
2941 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
2946 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
2947 error = put_nvlist(zc, nvp);
2956 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
2958 zfs_creat_t *zct = arg;
2960 zfs_create_fs(os, cr, zct->zct_zplprops, tx);
2963 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2967 * os parent objset pointer (NULL if root fs)
2968 * fuids_ok fuids allowed in this version of the spa?
2969 * sa_ok SAs allowed in this version of the spa?
2970 * createprops list of properties requested by creator
2973 * zplprops values for the zplprops we attach to the master node object
2974 * is_ci true if requested file system will be purely case-insensitive
2976 * Determine the settings for utf8only, normalization and
2977 * casesensitivity. Specific values may have been requested by the
2978 * creator and/or we can inherit values from the parent dataset. If
2979 * the file system is of too early a vintage, a creator can not
2980 * request settings for these properties, even if the requested
2981 * setting is the default value. We don't actually want to create dsl
2982 * properties for these, so remove them from the source nvlist after
2986 zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
2987 boolean_t fuids_ok, boolean_t sa_ok, nvlist_t *createprops,
2988 nvlist_t *zplprops, boolean_t *is_ci)
2990 uint64_t sense = ZFS_PROP_UNDEFINED;
2991 uint64_t norm = ZFS_PROP_UNDEFINED;
2992 uint64_t u8 = ZFS_PROP_UNDEFINED;
2995 ASSERT(zplprops != NULL);
2998 * Pull out creator prop choices, if any.
3001 (void) nvlist_lookup_uint64(createprops,
3002 zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
3003 (void) nvlist_lookup_uint64(createprops,
3004 zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
3005 (void) nvlist_remove_all(createprops,
3006 zfs_prop_to_name(ZFS_PROP_NORMALIZE));
3007 (void) nvlist_lookup_uint64(createprops,
3008 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
3009 (void) nvlist_remove_all(createprops,
3010 zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
3011 (void) nvlist_lookup_uint64(createprops,
3012 zfs_prop_to_name(ZFS_PROP_CASE), &sense);
3013 (void) nvlist_remove_all(createprops,
3014 zfs_prop_to_name(ZFS_PROP_CASE));
3018 * If the zpl version requested is whacky or the file system
3019 * or pool is version is too "young" to support normalization
3020 * and the creator tried to set a value for one of the props,
3023 if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
3024 (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
3025 (zplver >= ZPL_VERSION_SA && !sa_ok) ||
3026 (zplver < ZPL_VERSION_NORMALIZATION &&
3027 (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
3028 sense != ZFS_PROP_UNDEFINED)))
3029 return (SET_ERROR(ENOTSUP));
3032 * Put the version in the zplprops
3034 VERIFY(nvlist_add_uint64(zplprops,
3035 zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
3037 if (norm == ZFS_PROP_UNDEFINED &&
3038 (error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm)) != 0)
3040 VERIFY(nvlist_add_uint64(zplprops,
3041 zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
3044 * If we're normalizing, names must always be valid UTF-8 strings.
3048 if (u8 == ZFS_PROP_UNDEFINED &&
3049 (error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8)) != 0)
3051 VERIFY(nvlist_add_uint64(zplprops,
3052 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
3054 if (sense == ZFS_PROP_UNDEFINED &&
3055 (error = zfs_get_zplprop(os, ZFS_PROP_CASE, &sense)) != 0)
3057 VERIFY(nvlist_add_uint64(zplprops,
3058 zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
3061 *is_ci = (sense == ZFS_CASE_INSENSITIVE);
3067 zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
3068 nvlist_t *zplprops, boolean_t *is_ci)
3070 boolean_t fuids_ok, sa_ok;
3071 uint64_t zplver = ZPL_VERSION;
3072 objset_t *os = NULL;
3073 char parentname[MAXNAMELEN];
3079 (void) strlcpy(parentname, dataset, sizeof (parentname));
3080 cp = strrchr(parentname, '/');
3084 if ((error = spa_open(dataset, &spa, FTAG)) != 0)
3087 spa_vers = spa_version(spa);
3088 spa_close(spa, FTAG);
3090 zplver = zfs_zpl_version_map(spa_vers);
3091 fuids_ok = (zplver >= ZPL_VERSION_FUID);
3092 sa_ok = (zplver >= ZPL_VERSION_SA);
3095 * Open parent object set so we can inherit zplprop values.
3097 if ((error = dmu_objset_hold(parentname, FTAG, &os)) != 0)
3100 error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, sa_ok, createprops,
3102 dmu_objset_rele(os, FTAG);
3107 zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
3108 nvlist_t *zplprops, boolean_t *is_ci)
3112 uint64_t zplver = ZPL_VERSION;
3115 zplver = zfs_zpl_version_map(spa_vers);
3116 fuids_ok = (zplver >= ZPL_VERSION_FUID);
3117 sa_ok = (zplver >= ZPL_VERSION_SA);
3119 error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, sa_ok,
3120 createprops, zplprops, is_ci);
3126 * "type" -> dmu_objset_type_t (int32)
3127 * (optional) "props" -> { prop -> value }
3130 * outnvl: propname -> error code (int32)
3133 zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3136 zfs_creat_t zct = { 0 };
3137 nvlist_t *nvprops = NULL;
3138 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
3140 dmu_objset_type_t type;
3141 boolean_t is_insensitive = B_FALSE;
3143 if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
3144 return (SET_ERROR(EINVAL));
3146 (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
3150 cbfunc = zfs_create_cb;
3154 cbfunc = zvol_create_cb;
3161 if (strchr(fsname, '@') ||
3162 strchr(fsname, '%'))
3163 return (SET_ERROR(EINVAL));
3165 zct.zct_props = nvprops;
3168 return (SET_ERROR(EINVAL));
3170 if (type == DMU_OST_ZVOL) {
3171 uint64_t volsize, volblocksize;
3173 if (nvprops == NULL)
3174 return (SET_ERROR(EINVAL));
3175 if (nvlist_lookup_uint64(nvprops,
3176 zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) != 0)
3177 return (SET_ERROR(EINVAL));
3179 if ((error = nvlist_lookup_uint64(nvprops,
3180 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
3181 &volblocksize)) != 0 && error != ENOENT)
3182 return (SET_ERROR(EINVAL));
3185 volblocksize = zfs_prop_default_numeric(
3186 ZFS_PROP_VOLBLOCKSIZE);
3188 if ((error = zvol_check_volblocksize(
3189 volblocksize)) != 0 ||
3190 (error = zvol_check_volsize(volsize,
3191 volblocksize)) != 0)
3193 } else if (type == DMU_OST_ZFS) {
3197 * We have to have normalization and
3198 * case-folding flags correct when we do the
3199 * file system creation, so go figure them out
3202 VERIFY(nvlist_alloc(&zct.zct_zplprops,
3203 NV_UNIQUE_NAME, KM_SLEEP) == 0);
3204 error = zfs_fill_zplprops(fsname, nvprops,
3205 zct.zct_zplprops, &is_insensitive);
3207 nvlist_free(zct.zct_zplprops);
3212 error = dmu_objset_create(fsname, type,
3213 is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
3214 nvlist_free(zct.zct_zplprops);
3217 * It would be nice to do this atomically.
3220 error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
3223 (void) dsl_destroy_head(fsname);
3227 if (error == 0 && type == DMU_OST_ZVOL)
3228 zvol_create_minors(fsname);
3236 * "origin" -> name of origin snapshot
3237 * (optional) "props" -> { prop -> value }
3241 * outnvl: propname -> error code (int32)
3244 zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3247 nvlist_t *nvprops = NULL;
3250 if (nvlist_lookup_string(innvl, "origin", &origin_name) != 0)
3251 return (SET_ERROR(EINVAL));
3252 (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
3254 if (strchr(fsname, '@') ||
3255 strchr(fsname, '%'))
3256 return (SET_ERROR(EINVAL));
3258 if (dataset_namecheck(origin_name, NULL, NULL) != 0)
3259 return (SET_ERROR(EINVAL));
3260 error = dmu_objset_clone(fsname, origin_name);
3265 * It would be nice to do this atomically.
3268 error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
3271 (void) dsl_destroy_head(fsname);
3276 zvol_create_minors(fsname);
3284 * "snaps" -> { snapshot1, snapshot2 }
3285 * (optional) "props" -> { prop -> value (string) }
3288 * outnvl: snapshot -> error code (int32)
3291 zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3294 nvlist_t *props = NULL;
3296 nvpair_t *pair, *pair2;
3298 (void) nvlist_lookup_nvlist(innvl, "props", &props);
3299 if ((error = zfs_check_userprops(poolname, props)) != 0)
3302 if (!nvlist_empty(props) &&
3303 zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
3304 return (SET_ERROR(ENOTSUP));
3306 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
3307 return (SET_ERROR(EINVAL));
3308 poollen = strlen(poolname);
3309 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
3310 pair = nvlist_next_nvpair(snaps, pair)) {
3311 const char *name = nvpair_name(pair);
3312 const char *cp = strchr(name, '@');
3315 * The snap name must contain an @, and the part after it must
3316 * contain only valid characters.
3319 zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
3320 return (SET_ERROR(EINVAL));
3323 * The snap must be in the specified pool.
3325 if (strncmp(name, poolname, poollen) != 0 ||
3326 (name[poollen] != '/' && name[poollen] != '@'))
3327 return (SET_ERROR(EXDEV));
3329 /* This must be the only snap of this fs. */
3330 for (pair2 = nvlist_next_nvpair(snaps, pair);
3331 pair2 != NULL; pair2 = nvlist_next_nvpair(snaps, pair2)) {
3332 if (strncmp(name, nvpair_name(pair2), cp - name + 1)
3334 return (SET_ERROR(EXDEV));
3339 error = dsl_dataset_snapshot(snaps, props, outnvl);
3343 zvol_create_minors(poolname);
3350 * innvl: "message" -> string
3354 zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
3362 * The poolname in the ioctl is not set, we get it from the TSD,
3363 * which was set at the end of the last successful ioctl that allows
3364 * logging. The secpolicy func already checked that it is set.
3365 * Only one log ioctl is allowed after each successful ioctl, so
3366 * we clear the TSD here.
3368 poolname = tsd_get(zfs_allow_log_key);
3369 (void) tsd_set(zfs_allow_log_key, NULL);
3370 error = spa_open(poolname, &spa, FTAG);
3375 if (nvlist_lookup_string(innvl, "message", &message) != 0) {
3376 spa_close(spa, FTAG);
3377 return (SET_ERROR(EINVAL));
3380 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
3381 spa_close(spa, FTAG);
3382 return (SET_ERROR(ENOTSUP));
3385 error = spa_history_log(spa, message);
3386 spa_close(spa, FTAG);
3391 * The dp_config_rwlock must not be held when calling this, because the
3392 * unmount may need to write out data.
3394 * This function is best-effort. Callers must deal gracefully if it
3395 * remains mounted (or is remounted after this call).
3397 * XXX: This function should detect a failure to unmount a snapdir of a dataset
3398 * and return the appropriate error code when it is mounted. Its Illumos and
3399 * FreeBSD counterparts do this. We do not do this on Linux because there is no
3400 * clear way to access the mount information that FreeBSD and Illumos use to
3401 * distinguish between things with mounted snapshot directories, and things
3402 * without mounted snapshot directories, which include zvols. Returning a
3403 * failure for the latter causes `zfs destroy` to fail on zvol snapshots.
3406 zfs_unmount_snap(const char *snapname)
3408 zfs_sb_t *zsb = NULL;
3413 if ((ptr = strchr(snapname, '@')) == NULL)
3416 dsname = kmem_alloc(ptr - snapname + 1, KM_SLEEP);
3417 strlcpy(dsname, snapname, ptr - snapname + 1);
3418 fullname = strdup(snapname);
3420 if (zfs_sb_hold(dsname, FTAG, &zsb, B_FALSE) == 0) {
3421 ASSERT(!dsl_pool_config_held(dmu_objset_pool(zsb->z_os)));
3422 (void) zfsctl_unmount_snapshot(zsb, fullname, MNT_FORCE);
3423 zfs_sb_rele(zsb, FTAG);
3426 kmem_free(dsname, ptr - snapname + 1);
3434 zfs_unmount_snap_cb(const char *snapname, void *arg)
3436 return (zfs_unmount_snap(snapname));
3440 * When a clone is destroyed, its origin may also need to be destroyed,
3441 * in which case it must be unmounted. This routine will do that unmount
3445 zfs_destroy_unmount_origin(const char *fsname)
3451 error = dmu_objset_hold(fsname, FTAG, &os);
3454 ds = dmu_objset_ds(os);
3455 if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev)) {
3456 char originname[MAXNAMELEN];
3457 dsl_dataset_name(ds->ds_prev, originname);
3458 dmu_objset_rele(os, FTAG);
3459 (void) zfs_unmount_snap(originname);
3461 dmu_objset_rele(os, FTAG);
3467 * "snaps" -> { snapshot1, snapshot2 }
3468 * (optional boolean) "defer"
3471 * outnvl: snapshot -> error code (int32)
3475 zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3481 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
3482 return (SET_ERROR(EINVAL));
3483 defer = nvlist_exists(innvl, "defer");
3485 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
3486 pair = nvlist_next_nvpair(snaps, pair)) {
3487 (void) zfs_unmount_snap(nvpair_name(pair));
3488 (void) zvol_remove_minor(nvpair_name(pair));
3491 return (dsl_destroy_snapshots_nvl(snaps, defer, outnvl));
3495 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3496 * All bookmarks must be in the same pool.
3499 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3502 * outnvl: bookmark -> error code (int32)
3507 zfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3509 nvpair_t *pair, *pair2;
3511 for (pair = nvlist_next_nvpair(innvl, NULL);
3512 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
3516 * Verify the snapshot argument.
3518 if (nvpair_value_string(pair, &snap_name) != 0)
3519 return (SET_ERROR(EINVAL));
3522 /* Verify that the keys (bookmarks) are unique */
3523 for (pair2 = nvlist_next_nvpair(innvl, pair);
3524 pair2 != NULL; pair2 = nvlist_next_nvpair(innvl, pair2)) {
3525 if (strcmp(nvpair_name(pair), nvpair_name(pair2)) == 0)
3526 return (SET_ERROR(EINVAL));
3530 return (dsl_bookmark_create(innvl, outnvl));
3535 * property 1, property 2, ...
3539 * bookmark name 1 -> { property 1, property 2, ... },
3540 * bookmark name 2 -> { property 1, property 2, ... }
3545 zfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3547 return (dsl_get_bookmarks(fsname, innvl, outnvl));
3552 * bookmark name 1, bookmark name 2
3555 * outnvl: bookmark -> error code (int32)
3559 zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
3565 poollen = strlen(poolname);
3566 for (pair = nvlist_next_nvpair(innvl, NULL);
3567 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
3568 const char *name = nvpair_name(pair);
3569 const char *cp = strchr(name, '#');
3572 * The bookmark name must contain an #, and the part after it
3573 * must contain only valid characters.
3576 zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
3577 return (SET_ERROR(EINVAL));
3580 * The bookmark must be in the specified pool.
3582 if (strncmp(name, poolname, poollen) != 0 ||
3583 (name[poollen] != '/' && name[poollen] != '#'))
3584 return (SET_ERROR(EXDEV));
3587 error = dsl_bookmark_destroy(innvl, outnvl);
3593 * zc_name name of dataset to destroy
3594 * zc_objset_type type of objset
3595 * zc_defer_destroy mark for deferred destroy
3600 zfs_ioc_destroy(zfs_cmd_t *zc)
3604 if (zc->zc_objset_type == DMU_OST_ZFS) {
3605 err = zfs_unmount_snap(zc->zc_name);
3610 if (strchr(zc->zc_name, '@'))
3611 err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
3613 err = dsl_destroy_head(zc->zc_name);
3614 if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
3615 (void) zvol_remove_minor(zc->zc_name);
3620 * fsname is name of dataset to rollback (to most recent snapshot)
3622 * innvl is not used.
3624 * outnvl: "target" -> name of most recent snapshot
3629 zfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
3634 if (get_zfs_sb(fsname, &zsb) == 0) {
3635 error = zfs_suspend_fs(zsb);
3639 error = dsl_dataset_rollback(fsname, zsb, outnvl);
3640 resume_err = zfs_resume_fs(zsb, fsname);
3641 error = error ? error : resume_err;
3643 deactivate_super(zsb->z_sb);
3645 error = dsl_dataset_rollback(fsname, NULL, outnvl);
3651 recursive_unmount(const char *fsname, void *arg)
3653 const char *snapname = arg;
3657 fullname = kmem_asprintf("%s@%s", fsname, snapname);
3658 error = zfs_unmount_snap(fullname);
3666 * zc_name old name of dataset
3667 * zc_value new name of dataset
3668 * zc_cookie recursive flag (only valid for snapshots)
3673 zfs_ioc_rename(zfs_cmd_t *zc)
3675 boolean_t recursive = zc->zc_cookie & 1;
3678 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
3679 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
3680 strchr(zc->zc_value, '%'))
3681 return (SET_ERROR(EINVAL));
3683 at = strchr(zc->zc_name, '@');
3685 /* snaps must be in same fs */
3688 if (strncmp(zc->zc_name, zc->zc_value, at - zc->zc_name + 1))
3689 return (SET_ERROR(EXDEV));
3691 if (zc->zc_objset_type == DMU_OST_ZFS) {
3692 error = dmu_objset_find(zc->zc_name,
3693 recursive_unmount, at + 1,
3694 recursive ? DS_FIND_CHILDREN : 0);
3700 error = dsl_dataset_rename_snapshot(zc->zc_name,
3701 at + 1, strchr(zc->zc_value, '@') + 1, recursive);
3706 return (dsl_dir_rename(zc->zc_name, zc->zc_value));
3711 zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
3713 const char *propname = nvpair_name(pair);
3714 boolean_t issnap = (strchr(dsname, '@') != NULL);
3715 zfs_prop_t prop = zfs_name_to_prop(propname);
3719 if (prop == ZPROP_INVAL) {
3720 if (zfs_prop_user(propname)) {
3721 if ((err = zfs_secpolicy_write_perms(dsname,
3722 ZFS_DELEG_PERM_USERPROP, cr)))
3727 if (!issnap && zfs_prop_userquota(propname)) {
3728 const char *perm = NULL;
3729 const char *uq_prefix =
3730 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA];
3731 const char *gq_prefix =
3732 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA];
3734 if (strncmp(propname, uq_prefix,
3735 strlen(uq_prefix)) == 0) {
3736 perm = ZFS_DELEG_PERM_USERQUOTA;
3737 } else if (strncmp(propname, gq_prefix,
3738 strlen(gq_prefix)) == 0) {
3739 perm = ZFS_DELEG_PERM_GROUPQUOTA;
3741 /* USERUSED and GROUPUSED are read-only */
3742 return (SET_ERROR(EINVAL));
3745 if ((err = zfs_secpolicy_write_perms(dsname, perm, cr)))
3750 return (SET_ERROR(EINVAL));
3754 return (SET_ERROR(EINVAL));
3756 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
3758 * dsl_prop_get_all_impl() returns properties in this
3762 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
3763 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3768 * Check that this value is valid for this pool version
3771 case ZFS_PROP_COMPRESSION:
3773 * If the user specified gzip compression, make sure
3774 * the SPA supports it. We ignore any errors here since
3775 * we'll catch them later.
3777 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3778 nvpair_value_uint64(pair, &intval) == 0) {
3779 if (intval >= ZIO_COMPRESS_GZIP_1 &&
3780 intval <= ZIO_COMPRESS_GZIP_9 &&
3781 zfs_earlier_version(dsname,
3782 SPA_VERSION_GZIP_COMPRESSION)) {
3783 return (SET_ERROR(ENOTSUP));
3786 if (intval == ZIO_COMPRESS_ZLE &&
3787 zfs_earlier_version(dsname,
3788 SPA_VERSION_ZLE_COMPRESSION))
3789 return (SET_ERROR(ENOTSUP));
3791 if (intval == ZIO_COMPRESS_LZ4) {
3794 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
3797 if (!spa_feature_is_enabled(spa,
3798 SPA_FEATURE_LZ4_COMPRESS)) {
3799 spa_close(spa, FTAG);
3800 return (SET_ERROR(ENOTSUP));
3802 spa_close(spa, FTAG);
3806 * If this is a bootable dataset then
3807 * verify that the compression algorithm
3808 * is supported for booting. We must return
3809 * something other than ENOTSUP since it
3810 * implies a downrev pool version.
3812 if (zfs_is_bootfs(dsname) &&
3813 !BOOTFS_COMPRESS_VALID(intval)) {
3814 return (SET_ERROR(ERANGE));
3819 case ZFS_PROP_COPIES:
3820 if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
3821 return (SET_ERROR(ENOTSUP));
3824 case ZFS_PROP_DEDUP:
3825 if (zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
3826 return (SET_ERROR(ENOTSUP));
3829 case ZFS_PROP_SHARESMB:
3830 if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
3831 return (SET_ERROR(ENOTSUP));
3834 case ZFS_PROP_ACLINHERIT:
3835 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3836 nvpair_value_uint64(pair, &intval) == 0) {
3837 if (intval == ZFS_ACL_PASSTHROUGH_X &&
3838 zfs_earlier_version(dsname,
3839 SPA_VERSION_PASSTHROUGH_X))
3840 return (SET_ERROR(ENOTSUP));
3847 return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
3851 * Removes properties from the given props list that fail permission checks
3852 * needed to clear them and to restore them in case of a receive error. For each
3853 * property, make sure we have both set and inherit permissions.
3855 * Returns the first error encountered if any permission checks fail. If the
3856 * caller provides a non-NULL errlist, it also gives the complete list of names
3857 * of all the properties that failed a permission check along with the
3858 * corresponding error numbers. The caller is responsible for freeing the
3861 * If every property checks out successfully, zero is returned and the list
3862 * pointed at by errlist is NULL.
3865 zfs_check_clearable(char *dataset, nvlist_t *props, nvlist_t **errlist)
3868 nvpair_t *pair, *next_pair;
3875 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
3877 zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
3878 (void) strcpy(zc->zc_name, dataset);
3879 pair = nvlist_next_nvpair(props, NULL);
3880 while (pair != NULL) {
3881 next_pair = nvlist_next_nvpair(props, pair);
3883 (void) strcpy(zc->zc_value, nvpair_name(pair));
3884 if ((err = zfs_check_settable(dataset, pair, CRED())) != 0 ||
3885 (err = zfs_secpolicy_inherit_prop(zc, NULL, CRED())) != 0) {
3886 VERIFY(nvlist_remove_nvpair(props, pair) == 0);
3887 VERIFY(nvlist_add_int32(errors,
3888 zc->zc_value, err) == 0);
3892 kmem_free(zc, sizeof (zfs_cmd_t));
3894 if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
3895 nvlist_free(errors);
3898 VERIFY(nvpair_value_int32(pair, &rv) == 0);
3901 if (errlist == NULL)
3902 nvlist_free(errors);
3910 propval_equals(nvpair_t *p1, nvpair_t *p2)
3912 if (nvpair_type(p1) == DATA_TYPE_NVLIST) {
3913 /* dsl_prop_get_all_impl() format */
3915 VERIFY(nvpair_value_nvlist(p1, &attrs) == 0);
3916 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3920 if (nvpair_type(p2) == DATA_TYPE_NVLIST) {
3922 VERIFY(nvpair_value_nvlist(p2, &attrs) == 0);
3923 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3927 if (nvpair_type(p1) != nvpair_type(p2))
3930 if (nvpair_type(p1) == DATA_TYPE_STRING) {
3931 char *valstr1, *valstr2;
3933 VERIFY(nvpair_value_string(p1, (char **)&valstr1) == 0);
3934 VERIFY(nvpair_value_string(p2, (char **)&valstr2) == 0);
3935 return (strcmp(valstr1, valstr2) == 0);
3937 uint64_t intval1, intval2;
3939 VERIFY(nvpair_value_uint64(p1, &intval1) == 0);
3940 VERIFY(nvpair_value_uint64(p2, &intval2) == 0);
3941 return (intval1 == intval2);
3946 * Remove properties from props if they are not going to change (as determined
3947 * by comparison with origprops). Remove them from origprops as well, since we
3948 * do not need to clear or restore properties that won't change.
3951 props_reduce(nvlist_t *props, nvlist_t *origprops)
3953 nvpair_t *pair, *next_pair;
3955 if (origprops == NULL)
3956 return; /* all props need to be received */
3958 pair = nvlist_next_nvpair(props, NULL);
3959 while (pair != NULL) {
3960 const char *propname = nvpair_name(pair);
3963 next_pair = nvlist_next_nvpair(props, pair);
3965 if ((nvlist_lookup_nvpair(origprops, propname,
3966 &match) != 0) || !propval_equals(pair, match))
3967 goto next; /* need to set received value */
3969 /* don't clear the existing received value */
3970 (void) nvlist_remove_nvpair(origprops, match);
3971 /* don't bother receiving the property */
3972 (void) nvlist_remove_nvpair(props, pair);
3979 static boolean_t zfs_ioc_recv_inject_err;
3984 * zc_name name of containing filesystem
3985 * zc_nvlist_src{_size} nvlist of properties to apply
3986 * zc_value name of snapshot to create
3987 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3988 * zc_cookie file descriptor to recv from
3989 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3990 * zc_guid force flag
3991 * zc_cleanup_fd cleanup-on-exit file descriptor
3992 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
3995 * zc_cookie number of bytes read
3996 * zc_nvlist_dst{_size} error for each unapplied received property
3997 * zc_obj zprop_errflags_t
3998 * zc_action_handle handle for this guid/ds mapping
4001 zfs_ioc_recv(zfs_cmd_t *zc)
4004 dmu_recv_cookie_t drc;
4005 boolean_t force = (boolean_t)zc->zc_guid;
4008 int props_error = 0;
4011 nvlist_t *props = NULL; /* sent properties */
4012 nvlist_t *origprops = NULL; /* existing properties */
4013 char *origin = NULL;
4015 char tofs[ZFS_MAXNAMELEN];
4016 boolean_t first_recvd_props = B_FALSE;
4018 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
4019 strchr(zc->zc_value, '@') == NULL ||
4020 strchr(zc->zc_value, '%'))
4021 return (SET_ERROR(EINVAL));
4023 (void) strcpy(tofs, zc->zc_value);
4024 tosnap = strchr(tofs, '@');
4027 if (zc->zc_nvlist_src != 0 &&
4028 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
4029 zc->zc_iflags, &props)) != 0)
4036 return (SET_ERROR(EBADF));
4039 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
4041 if (zc->zc_string[0])
4042 origin = zc->zc_string;
4044 error = dmu_recv_begin(tofs, tosnap,
4045 &zc->zc_begin_record, force, origin, &drc);
4050 * Set properties before we receive the stream so that they are applied
4051 * to the new data. Note that we must call dmu_recv_stream() if
4052 * dmu_recv_begin() succeeds.
4054 if (props != NULL && !drc.drc_newfs) {
4055 if (spa_version(dsl_dataset_get_spa(drc.drc_ds)) >=
4056 SPA_VERSION_RECVD_PROPS &&
4057 !dsl_prop_get_hasrecvd(tofs))
4058 first_recvd_props = B_TRUE;
4061 * If new received properties are supplied, they are to
4062 * completely replace the existing received properties, so stash
4063 * away the existing ones.
4065 if (dsl_prop_get_received(tofs, &origprops) == 0) {
4066 nvlist_t *errlist = NULL;
4068 * Don't bother writing a property if its value won't
4069 * change (and avoid the unnecessary security checks).
4071 * The first receive after SPA_VERSION_RECVD_PROPS is a
4072 * special case where we blow away all local properties
4075 if (!first_recvd_props)
4076 props_reduce(props, origprops);
4077 if (zfs_check_clearable(tofs, origprops, &errlist) != 0)
4078 (void) nvlist_merge(errors, errlist, 0);
4079 nvlist_free(errlist);
4081 if (clear_received_props(tofs, origprops,
4082 first_recvd_props ? NULL : props) != 0)
4083 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
4085 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
4089 if (props != NULL) {
4090 props_error = dsl_prop_set_hasrecvd(tofs);
4092 if (props_error == 0) {
4093 (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
4098 if (zc->zc_nvlist_dst_size != 0 &&
4099 (nvlist_smush(errors, zc->zc_nvlist_dst_size) != 0 ||
4100 put_nvlist(zc, errors) != 0)) {
4102 * Caller made zc->zc_nvlist_dst less than the minimum expected
4103 * size or supplied an invalid address.
4105 props_error = SET_ERROR(EINVAL);
4109 error = dmu_recv_stream(&drc, fp->f_vnode, &off, zc->zc_cleanup_fd,
4110 &zc->zc_action_handle);
4113 zfs_sb_t *zsb = NULL;
4115 if (get_zfs_sb(tofs, &zsb) == 0) {
4119 error = zfs_suspend_fs(zsb);
4121 * If the suspend fails, then the recv_end will
4122 * likely also fail, and clean up after itself.
4124 end_err = dmu_recv_end(&drc, zsb);
4126 error = zfs_resume_fs(zsb, tofs);
4127 error = error ? error : end_err;
4128 deactivate_super(zsb->z_sb);
4130 error = dmu_recv_end(&drc, NULL);
4134 zc->zc_cookie = off - fp->f_offset;
4135 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4139 if (zfs_ioc_recv_inject_err) {
4140 zfs_ioc_recv_inject_err = B_FALSE;
4147 zvol_create_minors(tofs);
4151 * On error, restore the original props.
4153 if (error != 0 && props != NULL && !drc.drc_newfs) {
4154 if (clear_received_props(tofs, props, NULL) != 0) {
4156 * We failed to clear the received properties.
4157 * Since we may have left a $recvd value on the
4158 * system, we can't clear the $hasrecvd flag.
4160 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4161 } else if (first_recvd_props) {
4162 dsl_prop_unset_hasrecvd(tofs);
4165 if (origprops == NULL && !drc.drc_newfs) {
4166 /* We failed to stash the original properties. */
4167 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4171 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4172 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4173 * explictly if we're restoring local properties cleared in the
4174 * first new-style receive.
4176 if (origprops != NULL &&
4177 zfs_set_prop_nvlist(tofs, (first_recvd_props ?
4178 ZPROP_SRC_LOCAL : ZPROP_SRC_RECEIVED),
4179 origprops, NULL) != 0) {
4181 * We stashed the original properties but failed to
4184 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4189 nvlist_free(origprops);
4190 nvlist_free(errors);
4194 error = props_error;
4201 * zc_name name of snapshot to send
4202 * zc_cookie file descriptor to send stream to
4203 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4204 * zc_sendobj objsetid of snapshot to send
4205 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4206 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4207 * output size in zc_objset_type.
4208 * zc_flags if =1, WRITE_EMBEDDED records are permitted
4211 * zc_objset_type estimated size, if zc_guid is set
4214 zfs_ioc_send(zfs_cmd_t *zc)
4218 boolean_t estimate = (zc->zc_guid != 0);
4219 boolean_t embedok = (zc->zc_flags & 0x1);
4221 if (zc->zc_obj != 0) {
4223 dsl_dataset_t *tosnap;
4225 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4229 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
4231 dsl_pool_rele(dp, FTAG);
4235 if (dsl_dir_is_clone(tosnap->ds_dir))
4236 zc->zc_fromobj = tosnap->ds_dir->dd_phys->dd_origin_obj;
4237 dsl_dataset_rele(tosnap, FTAG);
4238 dsl_pool_rele(dp, FTAG);
4243 dsl_dataset_t *tosnap;
4244 dsl_dataset_t *fromsnap = NULL;
4246 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4250 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
4252 dsl_pool_rele(dp, FTAG);
4256 if (zc->zc_fromobj != 0) {
4257 error = dsl_dataset_hold_obj(dp, zc->zc_fromobj,
4260 dsl_dataset_rele(tosnap, FTAG);
4261 dsl_pool_rele(dp, FTAG);
4266 error = dmu_send_estimate(tosnap, fromsnap,
4267 &zc->zc_objset_type);
4269 if (fromsnap != NULL)
4270 dsl_dataset_rele(fromsnap, FTAG);
4271 dsl_dataset_rele(tosnap, FTAG);
4272 dsl_pool_rele(dp, FTAG);
4274 file_t *fp = getf(zc->zc_cookie);
4276 return (SET_ERROR(EBADF));
4279 error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
4280 zc->zc_fromobj, embedok, zc->zc_cookie, fp->f_vnode, &off);
4282 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4284 releasef(zc->zc_cookie);
4291 * zc_name name of snapshot on which to report progress
4292 * zc_cookie file descriptor of send stream
4295 * zc_cookie number of bytes written in send stream thus far
4298 zfs_ioc_send_progress(zfs_cmd_t *zc)
4302 dmu_sendarg_t *dsp = NULL;
4305 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4309 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &ds);
4311 dsl_pool_rele(dp, FTAG);
4315 mutex_enter(&ds->ds_sendstream_lock);
4318 * Iterate over all the send streams currently active on this dataset.
4319 * If there's one which matches the specified file descriptor _and_ the
4320 * stream was started by the current process, return the progress of
4324 for (dsp = list_head(&ds->ds_sendstreams); dsp != NULL;
4325 dsp = list_next(&ds->ds_sendstreams, dsp)) {
4326 if (dsp->dsa_outfd == zc->zc_cookie &&
4327 dsp->dsa_proc->group_leader == curproc->group_leader)
4332 zc->zc_cookie = *(dsp->dsa_off);
4334 error = SET_ERROR(ENOENT);
4336 mutex_exit(&ds->ds_sendstream_lock);
4337 dsl_dataset_rele(ds, FTAG);
4338 dsl_pool_rele(dp, FTAG);
4343 zfs_ioc_inject_fault(zfs_cmd_t *zc)
4347 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
4348 &zc->zc_inject_record);
4351 zc->zc_guid = (uint64_t)id;
4357 zfs_ioc_clear_fault(zfs_cmd_t *zc)
4359 return (zio_clear_fault((int)zc->zc_guid));
4363 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
4365 int id = (int)zc->zc_guid;
4368 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
4369 &zc->zc_inject_record);
4377 zfs_ioc_error_log(zfs_cmd_t *zc)
4381 size_t count = (size_t)zc->zc_nvlist_dst_size;
4383 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
4386 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
4389 zc->zc_nvlist_dst_size = count;
4391 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
4393 spa_close(spa, FTAG);
4399 zfs_ioc_clear(zfs_cmd_t *zc)
4406 * On zpool clear we also fix up missing slogs
4408 mutex_enter(&spa_namespace_lock);
4409 spa = spa_lookup(zc->zc_name);
4411 mutex_exit(&spa_namespace_lock);
4412 return (SET_ERROR(EIO));
4414 if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
4415 /* we need to let spa_open/spa_load clear the chains */
4416 spa_set_log_state(spa, SPA_LOG_CLEAR);
4418 spa->spa_last_open_failed = 0;
4419 mutex_exit(&spa_namespace_lock);
4421 if (zc->zc_cookie & ZPOOL_NO_REWIND) {
4422 error = spa_open(zc->zc_name, &spa, FTAG);
4425 nvlist_t *config = NULL;
4427 if (zc->zc_nvlist_src == 0)
4428 return (SET_ERROR(EINVAL));
4430 if ((error = get_nvlist(zc->zc_nvlist_src,
4431 zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
4432 error = spa_open_rewind(zc->zc_name, &spa, FTAG,
4434 if (config != NULL) {
4437 if ((err = put_nvlist(zc, config)) != 0)
4439 nvlist_free(config);
4441 nvlist_free(policy);
4448 spa_vdev_state_enter(spa, SCL_NONE);
4450 if (zc->zc_guid == 0) {
4453 vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
4455 (void) spa_vdev_state_exit(spa, NULL, ENODEV);
4456 spa_close(spa, FTAG);
4457 return (SET_ERROR(ENODEV));
4461 vdev_clear(spa, vd);
4463 (void) spa_vdev_state_exit(spa, NULL, 0);
4466 * Resume any suspended I/Os.
4468 if (zio_resume(spa) != 0)
4469 error = SET_ERROR(EIO);
4471 spa_close(spa, FTAG);
4477 zfs_ioc_pool_reopen(zfs_cmd_t *zc)
4482 error = spa_open(zc->zc_name, &spa, FTAG);
4486 spa_vdev_state_enter(spa, SCL_NONE);
4489 * If a resilver is already in progress then set the
4490 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4491 * the scan as a side effect of the reopen. Otherwise, let
4492 * vdev_open() decided if a resilver is required.
4494 spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
4495 vdev_reopen(spa->spa_root_vdev);
4496 spa->spa_scrub_reopen = B_FALSE;
4498 (void) spa_vdev_state_exit(spa, NULL, 0);
4499 spa_close(spa, FTAG);
4504 * zc_name name of filesystem
4505 * zc_value name of origin snapshot
4508 * zc_string name of conflicting snapshot, if there is one
4511 zfs_ioc_promote(zfs_cmd_t *zc)
4516 * We don't need to unmount *all* the origin fs's snapshots, but
4519 cp = strchr(zc->zc_value, '@');
4522 (void) dmu_objset_find(zc->zc_value,
4523 zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
4524 return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
4528 * Retrieve a single {user|group}{used|quota}@... property.
4531 * zc_name name of filesystem
4532 * zc_objset_type zfs_userquota_prop_t
4533 * zc_value domain name (eg. "S-1-234-567-89")
4534 * zc_guid RID/UID/GID
4537 * zc_cookie property value
4540 zfs_ioc_userspace_one(zfs_cmd_t *zc)
4545 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
4546 return (SET_ERROR(EINVAL));
4548 error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
4552 error = zfs_userspace_one(zsb,
4553 zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
4554 zfs_sb_rele(zsb, FTAG);
4561 * zc_name name of filesystem
4562 * zc_cookie zap cursor
4563 * zc_objset_type zfs_userquota_prop_t
4564 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4567 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4568 * zc_cookie zap cursor
4571 zfs_ioc_userspace_many(zfs_cmd_t *zc)
4574 int bufsize = zc->zc_nvlist_dst_size;
4579 return (SET_ERROR(ENOMEM));
4581 error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
4585 buf = vmem_alloc(bufsize, KM_SLEEP);
4587 error = zfs_userspace_many(zsb, zc->zc_objset_type, &zc->zc_cookie,
4588 buf, &zc->zc_nvlist_dst_size);
4591 error = xcopyout(buf,
4592 (void *)(uintptr_t)zc->zc_nvlist_dst,
4593 zc->zc_nvlist_dst_size);
4595 vmem_free(buf, bufsize);
4596 zfs_sb_rele(zsb, FTAG);
4603 * zc_name name of filesystem
4609 zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
4615 if (get_zfs_sb(zc->zc_name, &zsb) == 0) {
4616 if (!dmu_objset_userused_enabled(zsb->z_os)) {
4618 * If userused is not enabled, it may be because the
4619 * objset needs to be closed & reopened (to grow the
4620 * objset_phys_t). Suspend/resume the fs will do that.
4622 error = zfs_suspend_fs(zsb);
4624 dmu_objset_refresh_ownership(zsb->z_os,
4626 error = zfs_resume_fs(zsb, zc->zc_name);
4630 error = dmu_objset_userspace_upgrade(zsb->z_os);
4631 deactivate_super(zsb->z_sb);
4633 /* XXX kind of reading contents without owning */
4634 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
4638 error = dmu_objset_userspace_upgrade(os);
4639 dmu_objset_rele(os, FTAG);
4646 zfs_ioc_share(zfs_cmd_t *zc)
4648 return (SET_ERROR(ENOSYS));
4651 ace_t full_access[] = {
4652 {(uid_t)-1, ACE_ALL_PERMS, ACE_EVERYONE, 0}
4657 * zc_name name of containing filesystem
4658 * zc_obj object # beyond which we want next in-use object #
4661 * zc_obj next in-use object #
4664 zfs_ioc_next_obj(zfs_cmd_t *zc)
4666 objset_t *os = NULL;
4669 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
4673 error = dmu_object_next(os, &zc->zc_obj, B_FALSE,
4674 os->os_dsl_dataset->ds_phys->ds_prev_snap_txg);
4676 dmu_objset_rele(os, FTAG);
4682 * zc_name name of filesystem
4683 * zc_value prefix name for snapshot
4684 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4687 * zc_value short name of new snapshot
4690 zfs_ioc_tmp_snapshot(zfs_cmd_t *zc)
4697 error = zfs_onexit_fd_hold(zc->zc_cleanup_fd, &minor);
4701 snap_name = kmem_asprintf("%s-%016llx", zc->zc_value,
4702 (u_longlong_t)ddi_get_lbolt64());
4703 hold_name = kmem_asprintf("%%%s", zc->zc_value);
4705 error = dsl_dataset_snapshot_tmp(zc->zc_name, snap_name, minor,
4708 (void) strcpy(zc->zc_value, snap_name);
4711 zfs_onexit_fd_rele(zc->zc_cleanup_fd);
4717 * zc_name name of "to" snapshot
4718 * zc_value name of "from" snapshot
4719 * zc_cookie file descriptor to write diff data on
4722 * dmu_diff_record_t's to the file descriptor
4725 zfs_ioc_diff(zfs_cmd_t *zc)
4731 fp = getf(zc->zc_cookie);
4733 return (SET_ERROR(EBADF));
4737 error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off);
4739 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4741 releasef(zc->zc_cookie);
4747 * Remove all ACL files in shares dir
4749 #ifdef HAVE_SMB_SHARE
4751 zfs_smb_acl_purge(znode_t *dzp)
4754 zap_attribute_t zap;
4755 zfs_sb_t *zsb = ZTOZSB(dzp);
4758 for (zap_cursor_init(&zc, zsb->z_os, dzp->z_id);
4759 (error = zap_cursor_retrieve(&zc, &zap)) == 0;
4760 zap_cursor_advance(&zc)) {
4761 if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
4765 zap_cursor_fini(&zc);
4768 #endif /* HAVE_SMB_SHARE */
4771 zfs_ioc_smb_acl(zfs_cmd_t *zc)
4773 #ifdef HAVE_SMB_SHARE
4776 vnode_t *resourcevp = NULL;
4785 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
4786 NO_FOLLOW, NULL, &vp)) != 0)
4789 /* Now make sure mntpnt and dataset are ZFS */
4791 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
4792 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
4793 zc->zc_name) != 0)) {
4795 return (SET_ERROR(EINVAL));
4803 * Create share dir if its missing.
4805 mutex_enter(&zsb->z_lock);
4806 if (zsb->z_shares_dir == 0) {
4809 tx = dmu_tx_create(zsb->z_os);
4810 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
4812 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
4813 error = dmu_tx_assign(tx, TXG_WAIT);
4817 error = zfs_create_share_dir(zsb, tx);
4821 mutex_exit(&zsb->z_lock);
4827 mutex_exit(&zsb->z_lock);
4829 ASSERT(zsb->z_shares_dir);
4830 if ((error = zfs_zget(zsb, zsb->z_shares_dir, &sharedir)) != 0) {
4836 switch (zc->zc_cookie) {
4837 case ZFS_SMB_ACL_ADD:
4838 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
4839 vattr.va_mode = S_IFREG|0777;
4843 vsec.vsa_mask = VSA_ACE;
4844 vsec.vsa_aclentp = &full_access;
4845 vsec.vsa_aclentsz = sizeof (full_access);
4846 vsec.vsa_aclcnt = 1;
4848 error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
4849 &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
4851 VN_RELE(resourcevp);
4854 case ZFS_SMB_ACL_REMOVE:
4855 error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
4859 case ZFS_SMB_ACL_RENAME:
4860 if ((error = get_nvlist(zc->zc_nvlist_src,
4861 zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
4866 if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
4867 nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
4870 VN_RELE(ZTOV(sharedir));
4872 nvlist_free(nvlist);
4875 error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
4877 nvlist_free(nvlist);
4880 case ZFS_SMB_ACL_PURGE:
4881 error = zfs_smb_acl_purge(sharedir);
4885 error = SET_ERROR(EINVAL);
4890 VN_RELE(ZTOV(sharedir));
4896 return (SET_ERROR(ENOTSUP));
4897 #endif /* HAVE_SMB_SHARE */
4902 * "holds" -> { snapname -> holdname (string), ... }
4903 * (optional) "cleanup_fd" -> fd (int32)
4907 * snapname -> error value (int32)
4913 zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
4916 int cleanup_fd = -1;
4920 error = nvlist_lookup_nvlist(args, "holds", &holds);
4922 return (SET_ERROR(EINVAL));
4924 if (nvlist_lookup_int32(args, "cleanup_fd", &cleanup_fd) == 0) {
4925 error = zfs_onexit_fd_hold(cleanup_fd, &minor);
4930 error = dsl_dataset_user_hold(holds, minor, errlist);
4932 zfs_onexit_fd_rele(cleanup_fd);
4937 * innvl is not used.
4940 * holdname -> time added (uint64 seconds since epoch)
4946 zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
4948 return (dsl_dataset_get_holds(snapname, outnvl));
4953 * snapname -> { holdname, ... }
4958 * snapname -> error value (int32)
4964 zfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
4966 return (dsl_dataset_user_release(holds, errlist));
4971 * zc_guid flags (ZEVENT_NONBLOCK)
4972 * zc_cleanup_fd zevent file descriptor
4975 * zc_nvlist_dst next nvlist event
4976 * zc_cookie dropped events since last get
4979 zfs_ioc_events_next(zfs_cmd_t *zc)
4982 nvlist_t *event = NULL;
4984 uint64_t dropped = 0;
4987 error = zfs_zevent_fd_hold(zc->zc_cleanup_fd, &minor, &ze);
4992 error = zfs_zevent_next(ze, &event,
4993 &zc->zc_nvlist_dst_size, &dropped);
4994 if (event != NULL) {
4995 zc->zc_cookie = dropped;
4996 error = put_nvlist(zc, event);
5000 if (zc->zc_guid & ZEVENT_NONBLOCK)
5003 if ((error == 0) || (error != ENOENT))
5006 error = zfs_zevent_wait(ze);
5011 zfs_zevent_fd_rele(zc->zc_cleanup_fd);
5018 * zc_cookie cleared events count
5021 zfs_ioc_events_clear(zfs_cmd_t *zc)
5025 zfs_zevent_drain_all(&count);
5026 zc->zc_cookie = count;
5033 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5034 * zc_cleanup zevent file descriptor
5037 zfs_ioc_events_seek(zfs_cmd_t *zc)
5043 error = zfs_zevent_fd_hold(zc->zc_cleanup_fd, &minor, &ze);
5047 error = zfs_zevent_seek(ze, zc->zc_guid);
5048 zfs_zevent_fd_rele(zc->zc_cleanup_fd);
5055 * zc_name name of new filesystem or snapshot
5056 * zc_value full name of old snapshot
5059 * zc_cookie space in bytes
5060 * zc_objset_type compressed space in bytes
5061 * zc_perm_action uncompressed space in bytes
5064 zfs_ioc_space_written(zfs_cmd_t *zc)
5068 dsl_dataset_t *new, *old;
5070 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
5073 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &new);
5075 dsl_pool_rele(dp, FTAG);
5078 error = dsl_dataset_hold(dp, zc->zc_value, FTAG, &old);
5080 dsl_dataset_rele(new, FTAG);
5081 dsl_pool_rele(dp, FTAG);
5085 error = dsl_dataset_space_written(old, new, &zc->zc_cookie,
5086 &zc->zc_objset_type, &zc->zc_perm_action);
5087 dsl_dataset_rele(old, FTAG);
5088 dsl_dataset_rele(new, FTAG);
5089 dsl_pool_rele(dp, FTAG);
5095 * "firstsnap" -> snapshot name
5099 * "used" -> space in bytes
5100 * "compressed" -> compressed space in bytes
5101 * "uncompressed" -> uncompressed space in bytes
5105 zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
5109 dsl_dataset_t *new, *old;
5111 uint64_t used, comp, uncomp;
5113 if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
5114 return (SET_ERROR(EINVAL));
5116 error = dsl_pool_hold(lastsnap, FTAG, &dp);
5120 error = dsl_dataset_hold(dp, lastsnap, FTAG, &new);
5122 dsl_pool_rele(dp, FTAG);
5125 error = dsl_dataset_hold(dp, firstsnap, FTAG, &old);
5127 dsl_dataset_rele(new, FTAG);
5128 dsl_pool_rele(dp, FTAG);
5132 error = dsl_dataset_space_wouldfree(old, new, &used, &comp, &uncomp);
5133 dsl_dataset_rele(old, FTAG);
5134 dsl_dataset_rele(new, FTAG);
5135 dsl_pool_rele(dp, FTAG);
5136 fnvlist_add_uint64(outnvl, "used", used);
5137 fnvlist_add_uint64(outnvl, "compressed", comp);
5138 fnvlist_add_uint64(outnvl, "uncompressed", uncomp);
5144 * "fd" -> file descriptor to write stream to (int32)
5145 * (optional) "fromsnap" -> full snap name to send an incremental from
5146 * (optional) "embedok" -> (value ignored)
5147 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5154 zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5158 char *fromname = NULL;
5163 error = nvlist_lookup_int32(innvl, "fd", &fd);
5165 return (SET_ERROR(EINVAL));
5167 (void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
5169 embedok = nvlist_exists(innvl, "embedok");
5171 if ((fp = getf(fd)) == NULL)
5172 return (SET_ERROR(EBADF));
5175 error = dmu_send(snapname, fromname, embedok, fd, fp->f_vnode, &off);
5177 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
5185 * Determine approximately how large a zfs send stream will be -- the number
5186 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5189 * (optional) "fromsnap" -> full snap name to send an incremental from
5193 * "space" -> bytes of space (uint64)
5197 zfs_ioc_send_space(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5200 dsl_dataset_t *fromsnap = NULL;
5201 dsl_dataset_t *tosnap;
5206 error = dsl_pool_hold(snapname, FTAG, &dp);
5210 error = dsl_dataset_hold(dp, snapname, FTAG, &tosnap);
5212 dsl_pool_rele(dp, FTAG);
5216 error = nvlist_lookup_string(innvl, "fromsnap", &fromname);
5218 error = dsl_dataset_hold(dp, fromname, FTAG, &fromsnap);
5220 dsl_dataset_rele(tosnap, FTAG);
5221 dsl_pool_rele(dp, FTAG);
5226 error = dmu_send_estimate(tosnap, fromsnap, &space);
5227 fnvlist_add_uint64(outnvl, "space", space);
5229 if (fromsnap != NULL)
5230 dsl_dataset_rele(fromsnap, FTAG);
5231 dsl_dataset_rele(tosnap, FTAG);
5232 dsl_pool_rele(dp, FTAG);
5237 static zfs_ioc_vec_t zfs_ioc_vec[ZFS_IOC_LAST - ZFS_IOC_FIRST];
5240 zfs_ioctl_register_legacy(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5241 zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
5242 boolean_t log_history, zfs_ioc_poolcheck_t pool_check)
5244 zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
5246 ASSERT3U(ioc, >=, ZFS_IOC_FIRST);
5247 ASSERT3U(ioc, <, ZFS_IOC_LAST);
5248 ASSERT3P(vec->zvec_legacy_func, ==, NULL);
5249 ASSERT3P(vec->zvec_func, ==, NULL);
5251 vec->zvec_legacy_func = func;
5252 vec->zvec_secpolicy = secpolicy;
5253 vec->zvec_namecheck = namecheck;
5254 vec->zvec_allow_log = log_history;
5255 vec->zvec_pool_check = pool_check;
5259 * See the block comment at the beginning of this file for details on
5260 * each argument to this function.
5263 zfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
5264 zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
5265 zfs_ioc_poolcheck_t pool_check, boolean_t smush_outnvlist,
5266 boolean_t allow_log)
5268 zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
5270 ASSERT3U(ioc, >=, ZFS_IOC_FIRST);
5271 ASSERT3U(ioc, <, ZFS_IOC_LAST);
5272 ASSERT3P(vec->zvec_legacy_func, ==, NULL);
5273 ASSERT3P(vec->zvec_func, ==, NULL);
5275 /* if we are logging, the name must be valid */
5276 ASSERT(!allow_log || namecheck != NO_NAME);
5278 vec->zvec_name = name;
5279 vec->zvec_func = func;
5280 vec->zvec_secpolicy = secpolicy;
5281 vec->zvec_namecheck = namecheck;
5282 vec->zvec_pool_check = pool_check;
5283 vec->zvec_smush_outnvlist = smush_outnvlist;
5284 vec->zvec_allow_log = allow_log;
5288 zfs_ioctl_register_pool(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5289 zfs_secpolicy_func_t *secpolicy, boolean_t log_history,
5290 zfs_ioc_poolcheck_t pool_check)
5292 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5293 POOL_NAME, log_history, pool_check);
5297 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5298 zfs_secpolicy_func_t *secpolicy, zfs_ioc_poolcheck_t pool_check)
5300 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5301 DATASET_NAME, B_FALSE, pool_check);
5305 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
5307 zfs_ioctl_register_legacy(ioc, func, zfs_secpolicy_config,
5308 POOL_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5312 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5313 zfs_secpolicy_func_t *secpolicy)
5315 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5316 NO_NAME, B_FALSE, POOL_CHECK_NONE);
5320 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc,
5321 zfs_ioc_legacy_func_t *func, zfs_secpolicy_func_t *secpolicy)
5323 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5324 DATASET_NAME, B_FALSE, POOL_CHECK_SUSPENDED);
5328 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
5330 zfs_ioctl_register_dataset_read_secpolicy(ioc, func,
5331 zfs_secpolicy_read);
5335 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5336 zfs_secpolicy_func_t *secpolicy)
5338 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5339 DATASET_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5343 zfs_ioctl_init(void)
5345 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT,
5346 zfs_ioc_snapshot, zfs_secpolicy_snapshot, POOL_NAME,
5347 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5349 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY,
5350 zfs_ioc_log_history, zfs_secpolicy_log_history, NO_NAME,
5351 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
5353 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS,
5354 zfs_ioc_space_snaps, zfs_secpolicy_read, DATASET_NAME,
5355 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5357 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW,
5358 zfs_ioc_send_new, zfs_secpolicy_send_new, DATASET_NAME,
5359 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5361 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE,
5362 zfs_ioc_send_space, zfs_secpolicy_read, DATASET_NAME,
5363 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5365 zfs_ioctl_register("create", ZFS_IOC_CREATE,
5366 zfs_ioc_create, zfs_secpolicy_create_clone, DATASET_NAME,
5367 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5369 zfs_ioctl_register("clone", ZFS_IOC_CLONE,
5370 zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
5371 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5373 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
5374 zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
5375 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5377 zfs_ioctl_register("hold", ZFS_IOC_HOLD,
5378 zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
5379 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5380 zfs_ioctl_register("release", ZFS_IOC_RELEASE,
5381 zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
5382 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5384 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
5385 zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
5386 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5388 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
5389 zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
5390 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
5392 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK,
5393 zfs_ioc_bookmark, zfs_secpolicy_bookmark, POOL_NAME,
5394 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5396 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS,
5397 zfs_ioc_get_bookmarks, zfs_secpolicy_read, DATASET_NAME,
5398 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5400 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS,
5401 zfs_ioc_destroy_bookmarks, zfs_secpolicy_destroy_bookmarks,
5403 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5405 /* IOCTLS that use the legacy function signature */
5407 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
5408 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_READONLY);
5410 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE, zfs_ioc_pool_create,
5411 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5412 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN,
5414 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE,
5415 zfs_ioc_pool_upgrade);
5416 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD,
5418 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE,
5419 zfs_ioc_vdev_remove);
5420 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE,
5421 zfs_ioc_vdev_set_state);
5422 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH,
5423 zfs_ioc_vdev_attach);
5424 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH,
5425 zfs_ioc_vdev_detach);
5426 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH,
5427 zfs_ioc_vdev_setpath);
5428 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU,
5429 zfs_ioc_vdev_setfru);
5430 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS,
5431 zfs_ioc_pool_set_props);
5432 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT,
5433 zfs_ioc_vdev_split);
5434 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID,
5435 zfs_ioc_pool_reguid);
5437 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS,
5438 zfs_ioc_pool_configs, zfs_secpolicy_none);
5439 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT,
5440 zfs_ioc_pool_tryimport, zfs_secpolicy_config);
5441 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT,
5442 zfs_ioc_inject_fault, zfs_secpolicy_inject);
5443 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT,
5444 zfs_ioc_clear_fault, zfs_secpolicy_inject);
5445 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT,
5446 zfs_ioc_inject_list_next, zfs_secpolicy_inject);
5449 * pool destroy, and export don't log the history as part of
5450 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5451 * does the logging of those commands.
5453 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY, zfs_ioc_pool_destroy,
5454 zfs_secpolicy_config, B_FALSE, POOL_CHECK_NONE);
5455 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT, zfs_ioc_pool_export,
5456 zfs_secpolicy_config, B_FALSE, POOL_CHECK_NONE);
5458 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS, zfs_ioc_pool_stats,
5459 zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
5460 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS, zfs_ioc_pool_get_props,
5461 zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
5463 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG, zfs_ioc_error_log,
5464 zfs_secpolicy_inject, B_FALSE, POOL_CHECK_SUSPENDED);
5465 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME,
5466 zfs_ioc_dsobj_to_dsname,
5467 zfs_secpolicy_diff, B_FALSE, POOL_CHECK_SUSPENDED);
5468 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY,
5469 zfs_ioc_pool_get_history,
5470 zfs_secpolicy_config, B_FALSE, POOL_CHECK_SUSPENDED);
5472 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT, zfs_ioc_pool_import,
5473 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5475 zfs_ioctl_register_pool(ZFS_IOC_CLEAR, zfs_ioc_clear,
5476 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5477 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
5478 zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
5480 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN,
5481 zfs_ioc_space_written);
5482 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS,
5483 zfs_ioc_objset_recvd_props);
5484 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ,
5486 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL,
5488 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS,
5489 zfs_ioc_objset_stats);
5490 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS,
5491 zfs_ioc_objset_zplprops);
5492 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT,
5493 zfs_ioc_dataset_list_next);
5494 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT,
5495 zfs_ioc_snapshot_list_next);
5496 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS,
5497 zfs_ioc_send_progress);
5499 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF,
5500 zfs_ioc_diff, zfs_secpolicy_diff);
5501 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS,
5502 zfs_ioc_obj_to_stats, zfs_secpolicy_diff);
5503 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH,
5504 zfs_ioc_obj_to_path, zfs_secpolicy_diff);
5505 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE,
5506 zfs_ioc_userspace_one, zfs_secpolicy_userspace_one);
5507 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY,
5508 zfs_ioc_userspace_many, zfs_secpolicy_userspace_many);
5509 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND,
5510 zfs_ioc_send, zfs_secpolicy_send);
5512 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP, zfs_ioc_set_prop,
5513 zfs_secpolicy_none);
5514 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
5515 zfs_secpolicy_destroy);
5516 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
5517 zfs_secpolicy_rename);
5518 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
5519 zfs_secpolicy_recv);
5520 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE, zfs_ioc_promote,
5521 zfs_secpolicy_promote);
5522 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP,
5523 zfs_ioc_inherit_prop, zfs_secpolicy_inherit_prop);
5524 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL, zfs_ioc_set_fsacl,
5525 zfs_secpolicy_set_fsacl);
5527 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE, zfs_ioc_share,
5528 zfs_secpolicy_share, POOL_CHECK_NONE);
5529 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL, zfs_ioc_smb_acl,
5530 zfs_secpolicy_smb_acl, POOL_CHECK_NONE);
5531 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE,
5532 zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
5533 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5534 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT,
5535 zfs_ioc_tmp_snapshot, zfs_secpolicy_tmp_snapshot,
5536 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5541 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT, zfs_ioc_events_next,
5542 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
5543 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR, zfs_ioc_events_clear,
5544 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
5545 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK, zfs_ioc_events_seek,
5546 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
5550 pool_status_check(const char *name, zfs_ioc_namecheck_t type,
5551 zfs_ioc_poolcheck_t check)
5556 ASSERT(type == POOL_NAME || type == DATASET_NAME);
5558 if (check & POOL_CHECK_NONE)
5561 error = spa_open(name, &spa, FTAG);
5563 if ((check & POOL_CHECK_SUSPENDED) && spa_suspended(spa))
5564 error = SET_ERROR(EAGAIN);
5565 else if ((check & POOL_CHECK_READONLY) && !spa_writeable(spa))
5566 error = SET_ERROR(EROFS);
5567 spa_close(spa, FTAG);
5573 zfsdev_get_state_impl(minor_t minor, enum zfsdev_state_type which)
5577 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
5578 if (zs->zs_minor == minor) {
5582 return (zs->zs_onexit);
5584 return (zs->zs_zevent);
5595 zfsdev_get_state(minor_t minor, enum zfsdev_state_type which)
5599 ptr = zfsdev_get_state_impl(minor, which);
5605 zfsdev_getminor(struct file *filp)
5607 ASSERT(filp != NULL);
5608 ASSERT(filp->private_data != NULL);
5610 return (((zfsdev_state_t *)filp->private_data)->zs_minor);
5614 * Find a free minor number. The zfsdev_state_list is expected to
5615 * be short since it is only a list of currently open file handles.
5618 zfsdev_minor_alloc(void)
5620 static minor_t last_minor = 0;
5623 ASSERT(MUTEX_HELD(&zfsdev_state_lock));
5625 for (m = last_minor + 1; m != last_minor; m++) {
5626 if (m > ZFSDEV_MAX_MINOR)
5628 if (zfsdev_get_state_impl(m, ZST_ALL) == NULL) {
5638 zfsdev_state_init(struct file *filp)
5640 zfsdev_state_t *zs, *zsprev = NULL;
5642 boolean_t newzs = B_FALSE;
5644 ASSERT(MUTEX_HELD(&zfsdev_state_lock));
5646 minor = zfsdev_minor_alloc();
5648 return (SET_ERROR(ENXIO));
5650 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
5651 if (zs->zs_minor == -1)
5657 zs = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
5662 filp->private_data = zs;
5664 zfs_onexit_init((zfs_onexit_t **)&zs->zs_onexit);
5665 zfs_zevent_init((zfs_zevent_t **)&zs->zs_zevent);
5669 * In order to provide for lock-free concurrent read access
5670 * to the minor list in zfsdev_get_state_impl(), new entries
5671 * must be completely written before linking them into the
5672 * list whereas existing entries are already linked; the last
5673 * operation must be updating zs_minor (from -1 to the new
5677 zs->zs_minor = minor;
5679 zsprev->zs_next = zs;
5682 zs->zs_minor = minor;
5689 zfsdev_state_destroy(struct file *filp)
5693 ASSERT(MUTEX_HELD(&zfsdev_state_lock));
5694 ASSERT(filp->private_data != NULL);
5696 zs = filp->private_data;
5698 zfs_onexit_destroy(zs->zs_onexit);
5699 zfs_zevent_destroy(zs->zs_zevent);
5705 zfsdev_open(struct inode *ino, struct file *filp)
5709 mutex_enter(&zfsdev_state_lock);
5710 error = zfsdev_state_init(filp);
5711 mutex_exit(&zfsdev_state_lock);
5717 zfsdev_release(struct inode *ino, struct file *filp)
5721 mutex_enter(&zfsdev_state_lock);
5722 error = zfsdev_state_destroy(filp);
5723 mutex_exit(&zfsdev_state_lock);
5729 zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
5733 int error, rc, flag = 0;
5734 const zfs_ioc_vec_t *vec;
5735 char *saved_poolname = NULL;
5736 nvlist_t *innvl = NULL;
5738 vecnum = cmd - ZFS_IOC_FIRST;
5739 if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
5740 return (-SET_ERROR(EINVAL));
5741 vec = &zfs_ioc_vec[vecnum];
5744 * The registered ioctl list may be sparse, verify that either
5745 * a normal or legacy handler are registered.
5747 if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL)
5748 return (-SET_ERROR(EINVAL));
5750 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
5752 error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
5754 error = SET_ERROR(EFAULT);
5758 zc->zc_iflags = flag & FKIOCTL;
5759 if (zc->zc_nvlist_src_size != 0) {
5760 error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
5761 zc->zc_iflags, &innvl);
5767 * Ensure that all pool/dataset names are valid before we pass down to
5770 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
5771 switch (vec->zvec_namecheck) {
5773 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
5774 error = SET_ERROR(EINVAL);
5776 error = pool_status_check(zc->zc_name,
5777 vec->zvec_namecheck, vec->zvec_pool_check);
5781 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
5782 error = SET_ERROR(EINVAL);
5784 error = pool_status_check(zc->zc_name,
5785 vec->zvec_namecheck, vec->zvec_pool_check);
5793 if (error == 0 && !(flag & FKIOCTL))
5794 error = vec->zvec_secpolicy(zc, innvl, CRED());
5799 /* legacy ioctls can modify zc_name */
5800 saved_poolname = strdup(zc->zc_name);
5801 if (saved_poolname == NULL) {
5802 error = SET_ERROR(ENOMEM);
5805 saved_poolname[strcspn(saved_poolname, "/@#")] = '\0';
5808 if (vec->zvec_func != NULL) {
5812 nvlist_t *lognv = NULL;
5814 ASSERT(vec->zvec_legacy_func == NULL);
5817 * Add the innvl to the lognv before calling the func,
5818 * in case the func changes the innvl.
5820 if (vec->zvec_allow_log) {
5821 lognv = fnvlist_alloc();
5822 fnvlist_add_string(lognv, ZPOOL_HIST_IOCTL,
5824 if (!nvlist_empty(innvl)) {
5825 fnvlist_add_nvlist(lognv, ZPOOL_HIST_INPUT_NVL,
5830 outnvl = fnvlist_alloc();
5831 error = vec->zvec_func(zc->zc_name, innvl, outnvl);
5833 if (error == 0 && vec->zvec_allow_log &&
5834 spa_open(zc->zc_name, &spa, FTAG) == 0) {
5835 if (!nvlist_empty(outnvl)) {
5836 fnvlist_add_nvlist(lognv, ZPOOL_HIST_OUTPUT_NVL,
5839 (void) spa_history_log_nvl(spa, lognv);
5840 spa_close(spa, FTAG);
5842 fnvlist_free(lognv);
5844 if (!nvlist_empty(outnvl) || zc->zc_nvlist_dst_size != 0) {
5846 if (vec->zvec_smush_outnvlist) {
5847 smusherror = nvlist_smush(outnvl,
5848 zc->zc_nvlist_dst_size);
5850 if (smusherror == 0)
5851 puterror = put_nvlist(zc, outnvl);
5857 nvlist_free(outnvl);
5859 error = vec->zvec_legacy_func(zc);
5864 rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
5865 if (error == 0 && rc != 0)
5866 error = SET_ERROR(EFAULT);
5867 if (error == 0 && vec->zvec_allow_log) {
5868 char *s = tsd_get(zfs_allow_log_key);
5871 (void) tsd_set(zfs_allow_log_key, saved_poolname);
5873 if (saved_poolname != NULL)
5874 strfree(saved_poolname);
5877 kmem_free(zc, sizeof (zfs_cmd_t));
5881 #ifdef CONFIG_COMPAT
5883 zfsdev_compat_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
5885 return (zfsdev_ioctl(filp, cmd, arg));
5888 #define zfsdev_compat_ioctl NULL
5891 static const struct file_operations zfsdev_fops = {
5892 .open = zfsdev_open,
5893 .release = zfsdev_release,
5894 .unlocked_ioctl = zfsdev_ioctl,
5895 .compat_ioctl = zfsdev_compat_ioctl,
5896 .owner = THIS_MODULE,
5899 static struct miscdevice zfs_misc = {
5900 .minor = MISC_DYNAMIC_MINOR,
5902 .fops = &zfsdev_fops,
5910 mutex_init(&zfsdev_state_lock, NULL, MUTEX_DEFAULT, NULL);
5911 zfsdev_state_list = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
5912 zfsdev_state_list->zs_minor = -1;
5914 error = misc_register(&zfs_misc);
5916 printk(KERN_INFO "ZFS: misc_register() failed %d\n", error);
5927 zfsdev_state_t *zs, *zsprev = NULL;
5929 error = misc_deregister(&zfs_misc);
5931 printk(KERN_INFO "ZFS: misc_deregister() failed %d\n", error);
5933 mutex_destroy(&zfsdev_state_lock);
5935 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
5937 kmem_free(zsprev, sizeof (zfsdev_state_t));
5941 kmem_free(zsprev, sizeof (zfsdev_state_t));
5945 zfs_allow_log_destroy(void *arg)
5947 char *poolname = arg;
5952 #define ZFS_DEBUG_STR " (DEBUG mode)"
5954 #define ZFS_DEBUG_STR ""
5962 spa_init(FREAD | FWRITE);
5965 if ((error = zvol_init()) != 0)
5970 if ((error = zfs_attach()) != 0)
5973 tsd_create(&zfs_fsyncer_key, NULL);
5974 tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
5975 tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy);
5977 printk(KERN_NOTICE "ZFS: Loaded module v%s-%s%s, "
5978 "ZFS pool version %s, ZFS filesystem version %s\n",
5979 ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR,
5980 SPA_VERSION_STRING, ZPL_VERSION_STRING);
5981 #ifndef CONFIG_FS_POSIX_ACL
5982 printk(KERN_NOTICE "ZFS: Posix ACLs disabled by kernel\n");
5983 #endif /* CONFIG_FS_POSIX_ACL */
5992 printk(KERN_NOTICE "ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
5993 ", rc = %d\n", ZFS_META_VERSION, ZFS_META_RELEASE,
5994 ZFS_DEBUG_STR, error);
6007 tsd_destroy(&zfs_fsyncer_key);
6008 tsd_destroy(&rrw_tsd_key);
6009 tsd_destroy(&zfs_allow_log_key);
6011 printk(KERN_NOTICE "ZFS: Unloaded module v%s-%s%s\n",
6012 ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR);
6018 spl_module_init(_init);
6019 spl_module_exit(_fini);
6021 MODULE_DESCRIPTION("ZFS");
6022 MODULE_AUTHOR(ZFS_META_AUTHOR);
6023 MODULE_LICENSE(ZFS_META_LICENSE);
6024 MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
6025 #endif /* HAVE_SPL */