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 2015 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
29 * Copyright (c) 2011, 2015 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) 2016 Actifio, 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/slab.h>
191 #include "zfs_namecheck.h"
192 #include "zfs_prop.h"
193 #include "zfs_deleg.h"
194 #include "zfs_comutil.h"
197 * Limit maximum nvlist size. We don't want users passing in insane values
198 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
200 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
202 kmutex_t zfsdev_state_lock;
203 zfsdev_state_t *zfsdev_state_list;
205 extern void zfs_init(void);
206 extern void zfs_fini(void);
208 uint_t zfs_fsyncer_key;
209 extern uint_t rrw_tsd_key;
210 static uint_t zfs_allow_log_key;
212 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t *);
213 typedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
214 typedef int zfs_secpolicy_func_t(zfs_cmd_t *, nvlist_t *, cred_t *);
220 } zfs_ioc_namecheck_t;
223 POOL_CHECK_NONE = 1 << 0,
224 POOL_CHECK_SUSPENDED = 1 << 1,
225 POOL_CHECK_READONLY = 1 << 2,
226 } zfs_ioc_poolcheck_t;
228 typedef struct zfs_ioc_vec {
229 zfs_ioc_legacy_func_t *zvec_legacy_func;
230 zfs_ioc_func_t *zvec_func;
231 zfs_secpolicy_func_t *zvec_secpolicy;
232 zfs_ioc_namecheck_t zvec_namecheck;
233 boolean_t zvec_allow_log;
234 zfs_ioc_poolcheck_t zvec_pool_check;
235 boolean_t zvec_smush_outnvlist;
236 const char *zvec_name;
239 /* This array is indexed by zfs_userquota_prop_t */
240 static const char *userquota_perms[] = {
241 ZFS_DELEG_PERM_USERUSED,
242 ZFS_DELEG_PERM_USERQUOTA,
243 ZFS_DELEG_PERM_GROUPUSED,
244 ZFS_DELEG_PERM_GROUPQUOTA,
247 static int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
248 static int zfs_check_settable(const char *name, nvpair_t *property,
250 static int zfs_check_clearable(char *dataset, nvlist_t *props,
252 static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
254 int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t *);
255 static int get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp);
258 history_str_free(char *buf)
260 kmem_free(buf, HIS_MAX_RECORD_LEN);
264 history_str_get(zfs_cmd_t *zc)
268 if (zc->zc_history == 0)
271 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
272 if (copyinstr((void *)(uintptr_t)zc->zc_history,
273 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
274 history_str_free(buf);
278 buf[HIS_MAX_RECORD_LEN -1] = '\0';
284 * Check to see if the named dataset is currently defined as bootable
287 zfs_is_bootfs(const char *name)
291 if (dmu_objset_hold(name, FTAG, &os) == 0) {
293 ret = (dmu_objset_id(os) == spa_bootfs(dmu_objset_spa(os)));
294 dmu_objset_rele(os, FTAG);
301 * Return non-zero if the spa version is less than requested version.
304 zfs_earlier_version(const char *name, int version)
308 if (spa_open(name, &spa, FTAG) == 0) {
309 if (spa_version(spa) < version) {
310 spa_close(spa, FTAG);
313 spa_close(spa, FTAG);
319 * Return TRUE if the ZPL version is less than requested version.
322 zpl_earlier_version(const char *name, int version)
325 boolean_t rc = B_TRUE;
327 if (dmu_objset_hold(name, FTAG, &os) == 0) {
330 if (dmu_objset_type(os) != DMU_OST_ZFS) {
331 dmu_objset_rele(os, FTAG);
334 /* XXX reading from non-owned objset */
335 if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
336 rc = zplversion < version;
337 dmu_objset_rele(os, FTAG);
343 zfs_log_history(zfs_cmd_t *zc)
348 if ((buf = history_str_get(zc)) == NULL)
351 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
352 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
353 (void) spa_history_log(spa, buf);
354 spa_close(spa, FTAG);
356 history_str_free(buf);
360 * Policy for top-level read operations (list pools). Requires no privileges,
361 * and can be used in the local zone, as there is no associated dataset.
365 zfs_secpolicy_none(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
371 * Policy for dataset read operations (list children, get statistics). Requires
372 * no privileges, but must be visible in the local zone.
376 zfs_secpolicy_read(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
378 if (INGLOBALZONE(curproc) ||
379 zone_dataset_visible(zc->zc_name, NULL))
382 return (SET_ERROR(ENOENT));
386 zfs_dozonecheck_impl(const char *dataset, uint64_t zoned, cred_t *cr)
391 * The dataset must be visible by this zone -- check this first
392 * so they don't see EPERM on something they shouldn't know about.
394 if (!INGLOBALZONE(curproc) &&
395 !zone_dataset_visible(dataset, &writable))
396 return (SET_ERROR(ENOENT));
398 if (INGLOBALZONE(curproc)) {
400 * If the fs is zoned, only root can access it from the
403 if (secpolicy_zfs(cr) && zoned)
404 return (SET_ERROR(EPERM));
407 * If we are in a local zone, the 'zoned' property must be set.
410 return (SET_ERROR(EPERM));
412 /* must be writable by this zone */
414 return (SET_ERROR(EPERM));
420 zfs_dozonecheck(const char *dataset, cred_t *cr)
424 if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
425 return (SET_ERROR(ENOENT));
427 return (zfs_dozonecheck_impl(dataset, zoned, cr));
431 zfs_dozonecheck_ds(const char *dataset, dsl_dataset_t *ds, cred_t *cr)
435 if (dsl_prop_get_int_ds(ds, "zoned", &zoned))
436 return (SET_ERROR(ENOENT));
438 return (zfs_dozonecheck_impl(dataset, zoned, cr));
442 zfs_secpolicy_write_perms_ds(const char *name, dsl_dataset_t *ds,
443 const char *perm, cred_t *cr)
447 error = zfs_dozonecheck_ds(name, ds, cr);
449 error = secpolicy_zfs(cr);
451 error = dsl_deleg_access_impl(ds, perm, cr);
457 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
463 error = dsl_pool_hold(name, FTAG, &dp);
467 error = dsl_dataset_hold(dp, name, FTAG, &ds);
469 dsl_pool_rele(dp, FTAG);
473 error = zfs_secpolicy_write_perms_ds(name, ds, perm, cr);
475 dsl_dataset_rele(ds, FTAG);
476 dsl_pool_rele(dp, FTAG);
481 * Policy for setting the security label property.
483 * Returns 0 for success, non-zero for access and other errors.
486 zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
489 char ds_hexsl[MAXNAMELEN];
490 bslabel_t ds_sl, new_sl;
491 boolean_t new_default = FALSE;
493 int needed_priv = -1;
496 /* First get the existing dataset label. */
497 error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
498 1, sizeof (ds_hexsl), &ds_hexsl, NULL);
500 return (SET_ERROR(EPERM));
502 if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
505 /* The label must be translatable */
506 if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
507 return (SET_ERROR(EINVAL));
510 * In a non-global zone, disallow attempts to set a label that
511 * doesn't match that of the zone; otherwise no other checks
514 if (!INGLOBALZONE(curproc)) {
515 if (new_default || !blequal(&new_sl, CR_SL(CRED())))
516 return (SET_ERROR(EPERM));
521 * For global-zone datasets (i.e., those whose zoned property is
522 * "off", verify that the specified new label is valid for the
525 if (dsl_prop_get_integer(name,
526 zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
527 return (SET_ERROR(EPERM));
529 if (zfs_check_global_label(name, strval) != 0)
530 return (SET_ERROR(EPERM));
534 * If the existing dataset label is nondefault, check if the
535 * dataset is mounted (label cannot be changed while mounted).
536 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
537 * mounted (or isn't a dataset, doesn't exist, ...).
539 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
541 static char *setsl_tag = "setsl_tag";
544 * Try to own the dataset; abort if there is any error,
545 * (e.g., already mounted, in use, or other error).
547 error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
550 return (SET_ERROR(EPERM));
552 dmu_objset_disown(os, setsl_tag);
555 needed_priv = PRIV_FILE_DOWNGRADE_SL;
559 if (hexstr_to_label(strval, &new_sl) != 0)
560 return (SET_ERROR(EPERM));
562 if (blstrictdom(&ds_sl, &new_sl))
563 needed_priv = PRIV_FILE_DOWNGRADE_SL;
564 else if (blstrictdom(&new_sl, &ds_sl))
565 needed_priv = PRIV_FILE_UPGRADE_SL;
567 /* dataset currently has a default label */
569 needed_priv = PRIV_FILE_UPGRADE_SL;
573 if (needed_priv != -1)
574 return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
578 #endif /* HAVE_MLSLABEL */
582 zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
588 * Check permissions for special properties.
595 * Disallow setting of 'zoned' from within a local zone.
597 if (!INGLOBALZONE(curproc))
598 return (SET_ERROR(EPERM));
602 case ZFS_PROP_FILESYSTEM_LIMIT:
603 case ZFS_PROP_SNAPSHOT_LIMIT:
604 if (!INGLOBALZONE(curproc)) {
606 char setpoint[MAXNAMELEN];
608 * Unprivileged users are allowed to modify the
609 * limit on things *under* (ie. contained by)
610 * the thing they own.
612 if (dsl_prop_get_integer(dsname, "zoned", &zoned,
614 return (SET_ERROR(EPERM));
615 if (!zoned || strlen(dsname) <= strlen(setpoint))
616 return (SET_ERROR(EPERM));
620 case ZFS_PROP_MLSLABEL:
621 if (!is_system_labeled())
622 return (SET_ERROR(EPERM));
624 if (nvpair_value_string(propval, &strval) == 0) {
627 err = zfs_set_slabel_policy(dsname, strval, CRED());
634 return (zfs_secpolicy_write_perms(dsname, zfs_prop_to_name(prop), cr));
639 zfs_secpolicy_set_fsacl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
643 error = zfs_dozonecheck(zc->zc_name, cr);
648 * permission to set permissions will be evaluated later in
649 * dsl_deleg_can_allow()
656 zfs_secpolicy_rollback(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
658 return (zfs_secpolicy_write_perms(zc->zc_name,
659 ZFS_DELEG_PERM_ROLLBACK, cr));
664 zfs_secpolicy_send(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
672 * Generate the current snapshot name from the given objsetid, then
673 * use that name for the secpolicy/zone checks.
675 cp = strchr(zc->zc_name, '@');
677 return (SET_ERROR(EINVAL));
678 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
682 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &ds);
684 dsl_pool_rele(dp, FTAG);
688 dsl_dataset_name(ds, zc->zc_name);
690 error = zfs_secpolicy_write_perms_ds(zc->zc_name, ds,
691 ZFS_DELEG_PERM_SEND, cr);
692 dsl_dataset_rele(ds, FTAG);
693 dsl_pool_rele(dp, FTAG);
700 zfs_secpolicy_send_new(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
702 return (zfs_secpolicy_write_perms(zc->zc_name,
703 ZFS_DELEG_PERM_SEND, cr));
706 #ifdef HAVE_SMB_SHARE
709 zfs_secpolicy_deleg_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
714 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
715 NO_FOLLOW, NULL, &vp)) != 0)
718 /* Now make sure mntpnt and dataset are ZFS */
720 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
721 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
722 zc->zc_name) != 0)) {
724 return (SET_ERROR(EPERM));
728 return (dsl_deleg_access(zc->zc_name,
729 ZFS_DELEG_PERM_SHARE, cr));
731 #endif /* HAVE_SMB_SHARE */
734 zfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
736 #ifdef HAVE_SMB_SHARE
737 if (!INGLOBALZONE(curproc))
738 return (SET_ERROR(EPERM));
740 if (secpolicy_nfs(cr) == 0) {
743 return (zfs_secpolicy_deleg_share(zc, innvl, cr));
746 return (SET_ERROR(ENOTSUP));
747 #endif /* HAVE_SMB_SHARE */
751 zfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
753 #ifdef HAVE_SMB_SHARE
754 if (!INGLOBALZONE(curproc))
755 return (SET_ERROR(EPERM));
757 if (secpolicy_smb(cr) == 0) {
760 return (zfs_secpolicy_deleg_share(zc, innvl, cr));
763 return (SET_ERROR(ENOTSUP));
764 #endif /* HAVE_SMB_SHARE */
768 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
773 * Remove the @bla or /bla from the end of the name to get the parent.
775 (void) strncpy(parent, datasetname, parentsize);
776 cp = strrchr(parent, '@');
780 cp = strrchr(parent, '/');
782 return (SET_ERROR(ENOENT));
790 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
794 if ((error = zfs_secpolicy_write_perms(name,
795 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
798 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
803 zfs_secpolicy_destroy(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
805 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
809 * Destroying snapshots with delegated permissions requires
810 * descendant mount and destroy permissions.
814 zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
817 nvpair_t *pair, *nextpair;
820 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
821 return (SET_ERROR(EINVAL));
822 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
824 nextpair = nvlist_next_nvpair(snaps, pair);
825 error = zfs_secpolicy_destroy_perms(nvpair_name(pair), cr);
826 if (error == ENOENT) {
828 * Ignore any snapshots that don't exist (we consider
829 * them "already destroyed"). Remove the name from the
830 * nvl here in case the snapshot is created between
831 * now and when we try to destroy it (in which case
832 * we don't want to destroy it since we haven't
833 * checked for permission).
835 fnvlist_remove_nvpair(snaps, pair);
846 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
848 char parentname[MAXNAMELEN];
851 if ((error = zfs_secpolicy_write_perms(from,
852 ZFS_DELEG_PERM_RENAME, cr)) != 0)
855 if ((error = zfs_secpolicy_write_perms(from,
856 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
859 if ((error = zfs_get_parent(to, parentname,
860 sizeof (parentname))) != 0)
863 if ((error = zfs_secpolicy_write_perms(parentname,
864 ZFS_DELEG_PERM_CREATE, cr)) != 0)
867 if ((error = zfs_secpolicy_write_perms(parentname,
868 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
876 zfs_secpolicy_rename(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
878 return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
883 zfs_secpolicy_promote(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
886 dsl_dataset_t *clone;
889 error = zfs_secpolicy_write_perms(zc->zc_name,
890 ZFS_DELEG_PERM_PROMOTE, cr);
894 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
898 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &clone);
901 char parentname[MAXNAMELEN];
902 dsl_dataset_t *origin = NULL;
906 error = dsl_dataset_hold_obj(dd->dd_pool,
907 dsl_dir_phys(dd)->dd_origin_obj, FTAG, &origin);
909 dsl_dataset_rele(clone, FTAG);
910 dsl_pool_rele(dp, FTAG);
914 error = zfs_secpolicy_write_perms_ds(zc->zc_name, clone,
915 ZFS_DELEG_PERM_MOUNT, cr);
917 dsl_dataset_name(origin, parentname);
919 error = zfs_secpolicy_write_perms_ds(parentname, origin,
920 ZFS_DELEG_PERM_PROMOTE, cr);
922 dsl_dataset_rele(clone, FTAG);
923 dsl_dataset_rele(origin, FTAG);
925 dsl_pool_rele(dp, FTAG);
931 zfs_secpolicy_recv(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
935 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
936 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
939 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
940 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
943 return (zfs_secpolicy_write_perms(zc->zc_name,
944 ZFS_DELEG_PERM_CREATE, cr));
948 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
950 return (zfs_secpolicy_write_perms(name,
951 ZFS_DELEG_PERM_SNAPSHOT, cr));
955 * Check for permission to create each snapshot in the nvlist.
959 zfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
965 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
966 return (SET_ERROR(EINVAL));
967 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
968 pair = nvlist_next_nvpair(snaps, pair)) {
969 char *name = nvpair_name(pair);
970 char *atp = strchr(name, '@');
973 error = SET_ERROR(EINVAL);
977 error = zfs_secpolicy_snapshot_perms(name, cr);
986 * Check for permission to create each snapshot in the nvlist.
990 zfs_secpolicy_bookmark(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
995 for (pair = nvlist_next_nvpair(innvl, NULL);
996 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
997 char *name = nvpair_name(pair);
998 char *hashp = strchr(name, '#');
1000 if (hashp == NULL) {
1001 error = SET_ERROR(EINVAL);
1005 error = zfs_secpolicy_write_perms(name,
1006 ZFS_DELEG_PERM_BOOKMARK, cr);
1016 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1018 nvpair_t *pair, *nextpair;
1021 for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
1023 char *name = nvpair_name(pair);
1024 char *hashp = strchr(name, '#');
1025 nextpair = nvlist_next_nvpair(innvl, pair);
1027 if (hashp == NULL) {
1028 error = SET_ERROR(EINVAL);
1033 error = zfs_secpolicy_write_perms(name,
1034 ZFS_DELEG_PERM_DESTROY, cr);
1036 if (error == ENOENT) {
1038 * Ignore any filesystems that don't exist (we consider
1039 * their bookmarks "already destroyed"). Remove
1040 * the name from the nvl here in case the filesystem
1041 * is created between now and when we try to destroy
1042 * the bookmark (in which case we don't want to
1043 * destroy it since we haven't checked for permission).
1045 fnvlist_remove_nvpair(innvl, pair);
1057 zfs_secpolicy_log_history(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1060 * Even root must have a proper TSD so that we know what pool
1063 if (tsd_get(zfs_allow_log_key) == NULL)
1064 return (SET_ERROR(EPERM));
1069 zfs_secpolicy_create_clone(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1071 char parentname[MAXNAMELEN];
1075 if ((error = zfs_get_parent(zc->zc_name, parentname,
1076 sizeof (parentname))) != 0)
1079 if (nvlist_lookup_string(innvl, "origin", &origin) == 0 &&
1080 (error = zfs_secpolicy_write_perms(origin,
1081 ZFS_DELEG_PERM_CLONE, cr)) != 0)
1084 if ((error = zfs_secpolicy_write_perms(parentname,
1085 ZFS_DELEG_PERM_CREATE, cr)) != 0)
1088 return (zfs_secpolicy_write_perms(parentname,
1089 ZFS_DELEG_PERM_MOUNT, cr));
1093 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1094 * SYS_CONFIG privilege, which is not available in a local zone.
1098 zfs_secpolicy_config(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1100 if (secpolicy_sys_config(cr, B_FALSE) != 0)
1101 return (SET_ERROR(EPERM));
1107 * Policy for object to name lookups.
1111 zfs_secpolicy_diff(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1115 if ((error = secpolicy_sys_config(cr, B_FALSE)) == 0)
1118 error = zfs_secpolicy_write_perms(zc->zc_name, ZFS_DELEG_PERM_DIFF, cr);
1123 * Policy for fault injection. Requires all privileges.
1127 zfs_secpolicy_inject(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1129 return (secpolicy_zinject(cr));
1134 zfs_secpolicy_inherit_prop(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1136 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
1138 if (prop == ZPROP_INVAL) {
1139 if (!zfs_prop_user(zc->zc_value))
1140 return (SET_ERROR(EINVAL));
1141 return (zfs_secpolicy_write_perms(zc->zc_name,
1142 ZFS_DELEG_PERM_USERPROP, cr));
1144 return (zfs_secpolicy_setprop(zc->zc_name, prop,
1150 zfs_secpolicy_userspace_one(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1152 int err = zfs_secpolicy_read(zc, innvl, cr);
1156 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1157 return (SET_ERROR(EINVAL));
1159 if (zc->zc_value[0] == 0) {
1161 * They are asking about a posix uid/gid. If it's
1162 * themself, allow it.
1164 if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
1165 zc->zc_objset_type == ZFS_PROP_USERQUOTA) {
1166 if (zc->zc_guid == crgetuid(cr))
1169 if (groupmember(zc->zc_guid, cr))
1174 return (zfs_secpolicy_write_perms(zc->zc_name,
1175 userquota_perms[zc->zc_objset_type], cr));
1179 zfs_secpolicy_userspace_many(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1181 int err = zfs_secpolicy_read(zc, innvl, cr);
1185 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1186 return (SET_ERROR(EINVAL));
1188 return (zfs_secpolicy_write_perms(zc->zc_name,
1189 userquota_perms[zc->zc_objset_type], cr));
1194 zfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1196 return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION,
1202 zfs_secpolicy_hold(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1208 error = nvlist_lookup_nvlist(innvl, "holds", &holds);
1210 return (SET_ERROR(EINVAL));
1212 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
1213 pair = nvlist_next_nvpair(holds, pair)) {
1214 char fsname[MAXNAMELEN];
1215 error = dmu_fsname(nvpair_name(pair), fsname);
1218 error = zfs_secpolicy_write_perms(fsname,
1219 ZFS_DELEG_PERM_HOLD, cr);
1228 zfs_secpolicy_release(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1233 for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
1234 pair = nvlist_next_nvpair(innvl, pair)) {
1235 char fsname[MAXNAMELEN];
1236 error = dmu_fsname(nvpair_name(pair), fsname);
1239 error = zfs_secpolicy_write_perms(fsname,
1240 ZFS_DELEG_PERM_RELEASE, cr);
1248 * Policy for allowing temporary snapshots to be taken or released
1251 zfs_secpolicy_tmp_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1254 * A temporary snapshot is the same as a snapshot,
1255 * hold, destroy and release all rolled into one.
1256 * Delegated diff alone is sufficient that we allow this.
1260 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
1261 ZFS_DELEG_PERM_DIFF, cr)) == 0)
1264 error = zfs_secpolicy_snapshot_perms(zc->zc_name, cr);
1266 error = zfs_secpolicy_hold(zc, innvl, cr);
1268 error = zfs_secpolicy_release(zc, innvl, cr);
1270 error = zfs_secpolicy_destroy(zc, innvl, cr);
1275 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1278 get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
1282 nvlist_t *list = NULL;
1285 * Read in and unpack the user-supplied nvlist.
1288 return (SET_ERROR(EINVAL));
1290 packed = vmem_alloc(size, KM_SLEEP);
1292 if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
1294 vmem_free(packed, size);
1295 return (SET_ERROR(EFAULT));
1298 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
1299 vmem_free(packed, size);
1303 vmem_free(packed, size);
1310 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1311 * Entries will be removed from the end of the nvlist, and one int32 entry
1312 * named "N_MORE_ERRORS" will be added indicating how many entries were
1316 nvlist_smush(nvlist_t *errors, size_t max)
1320 size = fnvlist_size(errors);
1323 nvpair_t *more_errors;
1327 return (SET_ERROR(ENOMEM));
1329 fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, 0);
1330 more_errors = nvlist_prev_nvpair(errors, NULL);
1333 nvpair_t *pair = nvlist_prev_nvpair(errors,
1335 fnvlist_remove_nvpair(errors, pair);
1337 size = fnvlist_size(errors);
1338 } while (size > max);
1340 fnvlist_remove_nvpair(errors, more_errors);
1341 fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, n);
1342 ASSERT3U(fnvlist_size(errors), <=, max);
1349 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
1351 char *packed = NULL;
1355 size = fnvlist_size(nvl);
1357 if (size > zc->zc_nvlist_dst_size) {
1358 error = SET_ERROR(ENOMEM);
1360 packed = fnvlist_pack(nvl, &size);
1361 if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
1362 size, zc->zc_iflags) != 0)
1363 error = SET_ERROR(EFAULT);
1364 fnvlist_pack_free(packed, size);
1367 zc->zc_nvlist_dst_size = size;
1368 zc->zc_nvlist_dst_filled = B_TRUE;
1373 get_zfs_sb(const char *dsname, zfs_sb_t **zsbp)
1378 error = dmu_objset_hold(dsname, FTAG, &os);
1381 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1382 dmu_objset_rele(os, FTAG);
1383 return (SET_ERROR(EINVAL));
1386 mutex_enter(&os->os_user_ptr_lock);
1387 *zsbp = dmu_objset_get_user(os);
1388 if (*zsbp && (*zsbp)->z_sb) {
1389 atomic_inc(&((*zsbp)->z_sb->s_active));
1391 error = SET_ERROR(ESRCH);
1393 mutex_exit(&os->os_user_ptr_lock);
1394 dmu_objset_rele(os, FTAG);
1399 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1400 * case its z_sb will be NULL, and it will be opened as the owner.
1401 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1402 * which prevents all inode ops from running.
1405 zfs_sb_hold(const char *name, void *tag, zfs_sb_t **zsbp, boolean_t writer)
1409 if (get_zfs_sb(name, zsbp) != 0)
1410 error = zfs_sb_create(name, NULL, zsbp);
1412 rrm_enter(&(*zsbp)->z_teardown_lock, (writer) ? RW_WRITER :
1414 if ((*zsbp)->z_unmounted) {
1416 * XXX we could probably try again, since the unmounting
1417 * thread should be just about to disassociate the
1418 * objset from the zsb.
1420 rrm_exit(&(*zsbp)->z_teardown_lock, tag);
1421 return (SET_ERROR(EBUSY));
1428 zfs_sb_rele(zfs_sb_t *zsb, void *tag)
1430 rrm_exit(&zsb->z_teardown_lock, tag);
1433 deactivate_super(zsb->z_sb);
1435 dmu_objset_disown(zsb->z_os, zsb);
1441 zfs_ioc_pool_create(zfs_cmd_t *zc)
1444 nvlist_t *config, *props = NULL;
1445 nvlist_t *rootprops = NULL;
1446 nvlist_t *zplprops = NULL;
1448 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1449 zc->zc_iflags, &config)))
1452 if (zc->zc_nvlist_src_size != 0 && (error =
1453 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1454 zc->zc_iflags, &props))) {
1455 nvlist_free(config);
1460 nvlist_t *nvl = NULL;
1461 uint64_t version = SPA_VERSION;
1463 (void) nvlist_lookup_uint64(props,
1464 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
1465 if (!SPA_VERSION_IS_SUPPORTED(version)) {
1466 error = SET_ERROR(EINVAL);
1467 goto pool_props_bad;
1469 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
1471 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
1473 nvlist_free(config);
1477 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
1479 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1480 error = zfs_fill_zplprops_root(version, rootprops,
1483 goto pool_props_bad;
1486 error = spa_create(zc->zc_name, config, props, zplprops);
1489 * Set the remaining root properties
1491 if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
1492 ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
1493 (void) spa_destroy(zc->zc_name);
1496 nvlist_free(rootprops);
1497 nvlist_free(zplprops);
1498 nvlist_free(config);
1505 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
1508 zfs_log_history(zc);
1509 error = spa_destroy(zc->zc_name);
1515 zfs_ioc_pool_import(zfs_cmd_t *zc)
1517 nvlist_t *config, *props = NULL;
1521 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1522 zc->zc_iflags, &config)) != 0)
1525 if (zc->zc_nvlist_src_size != 0 && (error =
1526 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1527 zc->zc_iflags, &props))) {
1528 nvlist_free(config);
1532 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1533 guid != zc->zc_guid)
1534 error = SET_ERROR(EINVAL);
1536 error = spa_import(zc->zc_name, config, props, zc->zc_cookie);
1538 if (zc->zc_nvlist_dst != 0) {
1541 if ((err = put_nvlist(zc, config)) != 0)
1545 nvlist_free(config);
1552 zfs_ioc_pool_export(zfs_cmd_t *zc)
1555 boolean_t force = (boolean_t)zc->zc_cookie;
1556 boolean_t hardforce = (boolean_t)zc->zc_guid;
1558 zfs_log_history(zc);
1559 error = spa_export(zc->zc_name, NULL, force, hardforce);
1565 zfs_ioc_pool_configs(zfs_cmd_t *zc)
1570 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
1571 return (SET_ERROR(EEXIST));
1573 error = put_nvlist(zc, configs);
1575 nvlist_free(configs);
1582 * zc_name name of the pool
1585 * zc_cookie real errno
1586 * zc_nvlist_dst config nvlist
1587 * zc_nvlist_dst_size size of config nvlist
1590 zfs_ioc_pool_stats(zfs_cmd_t *zc)
1596 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
1597 sizeof (zc->zc_value));
1599 if (config != NULL) {
1600 ret = put_nvlist(zc, config);
1601 nvlist_free(config);
1604 * The config may be present even if 'error' is non-zero.
1605 * In this case we return success, and preserve the real errno
1608 zc->zc_cookie = error;
1617 * Try to import the given pool, returning pool stats as appropriate so that
1618 * user land knows which devices are available and overall pool health.
1621 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
1623 nvlist_t *tryconfig, *config;
1626 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1627 zc->zc_iflags, &tryconfig)) != 0)
1630 config = spa_tryimport(tryconfig);
1632 nvlist_free(tryconfig);
1635 return (SET_ERROR(EINVAL));
1637 error = put_nvlist(zc, config);
1638 nvlist_free(config);
1645 * zc_name name of the pool
1646 * zc_cookie scan func (pool_scan_func_t)
1649 zfs_ioc_pool_scan(zfs_cmd_t *zc)
1654 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1657 if (zc->zc_cookie == POOL_SCAN_NONE)
1658 error = spa_scan_stop(spa);
1660 error = spa_scan(spa, zc->zc_cookie);
1662 spa_close(spa, FTAG);
1668 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
1673 error = spa_open(zc->zc_name, &spa, FTAG);
1676 spa_close(spa, FTAG);
1682 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
1687 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1690 if (zc->zc_cookie < spa_version(spa) ||
1691 !SPA_VERSION_IS_SUPPORTED(zc->zc_cookie)) {
1692 spa_close(spa, FTAG);
1693 return (SET_ERROR(EINVAL));
1696 spa_upgrade(spa, zc->zc_cookie);
1697 spa_close(spa, FTAG);
1703 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
1710 if ((size = zc->zc_history_len) == 0)
1711 return (SET_ERROR(EINVAL));
1713 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1716 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
1717 spa_close(spa, FTAG);
1718 return (SET_ERROR(ENOTSUP));
1721 hist_buf = vmem_alloc(size, KM_SLEEP);
1722 if ((error = spa_history_get(spa, &zc->zc_history_offset,
1723 &zc->zc_history_len, hist_buf)) == 0) {
1724 error = ddi_copyout(hist_buf,
1725 (void *)(uintptr_t)zc->zc_history,
1726 zc->zc_history_len, zc->zc_iflags);
1729 spa_close(spa, FTAG);
1730 vmem_free(hist_buf, size);
1735 zfs_ioc_pool_reguid(zfs_cmd_t *zc)
1740 error = spa_open(zc->zc_name, &spa, FTAG);
1742 error = spa_change_guid(spa);
1743 spa_close(spa, FTAG);
1749 zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
1751 return (dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value));
1756 * zc_name name of filesystem
1757 * zc_obj object to find
1760 * zc_value name of object
1763 zfs_ioc_obj_to_path(zfs_cmd_t *zc)
1768 /* XXX reading from objset not owned */
1769 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1771 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1772 dmu_objset_rele(os, FTAG);
1773 return (SET_ERROR(EINVAL));
1775 error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
1776 sizeof (zc->zc_value));
1777 dmu_objset_rele(os, FTAG);
1784 * zc_name name of filesystem
1785 * zc_obj object to find
1788 * zc_stat stats on object
1789 * zc_value path to object
1792 zfs_ioc_obj_to_stats(zfs_cmd_t *zc)
1797 /* XXX reading from objset not owned */
1798 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1800 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1801 dmu_objset_rele(os, FTAG);
1802 return (SET_ERROR(EINVAL));
1804 error = zfs_obj_to_stats(os, zc->zc_obj, &zc->zc_stat, zc->zc_value,
1805 sizeof (zc->zc_value));
1806 dmu_objset_rele(os, FTAG);
1812 zfs_ioc_vdev_add(zfs_cmd_t *zc)
1818 error = spa_open(zc->zc_name, &spa, FTAG);
1822 error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1823 zc->zc_iflags, &config);
1825 error = spa_vdev_add(spa, config);
1826 nvlist_free(config);
1828 spa_close(spa, FTAG);
1834 * zc_name name of the pool
1835 * zc_nvlist_conf nvlist of devices to remove
1836 * zc_cookie to stop the remove?
1839 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
1844 error = spa_open(zc->zc_name, &spa, FTAG);
1847 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
1848 spa_close(spa, FTAG);
1853 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
1857 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1859 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1861 switch (zc->zc_cookie) {
1862 case VDEV_STATE_ONLINE:
1863 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
1866 case VDEV_STATE_OFFLINE:
1867 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
1870 case VDEV_STATE_FAULTED:
1871 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1872 zc->zc_obj != VDEV_AUX_EXTERNAL)
1873 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1875 error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
1878 case VDEV_STATE_DEGRADED:
1879 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1880 zc->zc_obj != VDEV_AUX_EXTERNAL)
1881 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1883 error = vdev_degrade(spa, zc->zc_guid, zc->zc_obj);
1887 error = SET_ERROR(EINVAL);
1889 zc->zc_cookie = newstate;
1890 spa_close(spa, FTAG);
1895 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
1898 int replacing = zc->zc_cookie;
1902 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1905 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1906 zc->zc_iflags, &config)) == 0) {
1907 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
1908 nvlist_free(config);
1911 spa_close(spa, FTAG);
1916 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
1921 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1924 error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
1926 spa_close(spa, FTAG);
1931 zfs_ioc_vdev_split(zfs_cmd_t *zc)
1934 nvlist_t *config, *props = NULL;
1936 boolean_t exp = !!(zc->zc_cookie & ZPOOL_EXPORT_AFTER_SPLIT);
1938 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1941 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1942 zc->zc_iflags, &config))) {
1943 spa_close(spa, FTAG);
1947 if (zc->zc_nvlist_src_size != 0 && (error =
1948 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1949 zc->zc_iflags, &props))) {
1950 spa_close(spa, FTAG);
1951 nvlist_free(config);
1955 error = spa_vdev_split_mirror(spa, zc->zc_string, config, props, exp);
1957 spa_close(spa, FTAG);
1959 nvlist_free(config);
1966 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
1969 char *path = zc->zc_value;
1970 uint64_t guid = zc->zc_guid;
1973 error = spa_open(zc->zc_name, &spa, FTAG);
1977 error = spa_vdev_setpath(spa, guid, path);
1978 spa_close(spa, FTAG);
1983 zfs_ioc_vdev_setfru(zfs_cmd_t *zc)
1986 char *fru = zc->zc_value;
1987 uint64_t guid = zc->zc_guid;
1990 error = spa_open(zc->zc_name, &spa, FTAG);
1994 error = spa_vdev_setfru(spa, guid, fru);
1995 spa_close(spa, FTAG);
2000 zfs_ioc_objset_stats_impl(zfs_cmd_t *zc, objset_t *os)
2005 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
2007 if (zc->zc_nvlist_dst != 0 &&
2008 (error = dsl_prop_get_all(os, &nv)) == 0) {
2009 dmu_objset_stats(os, nv);
2011 * NB: zvol_get_stats() will read the objset contents,
2012 * which we aren't supposed to do with a
2013 * DS_MODE_USER hold, because it could be
2014 * inconsistent. So this is a bit of a workaround...
2015 * XXX reading with out owning
2017 if (!zc->zc_objset_stats.dds_inconsistent &&
2018 dmu_objset_type(os) == DMU_OST_ZVOL) {
2019 error = zvol_get_stats(os, nv);
2025 error = put_nvlist(zc, nv);
2034 * zc_name name of filesystem
2035 * zc_nvlist_dst_size size of buffer for property nvlist
2038 * zc_objset_stats stats
2039 * zc_nvlist_dst property nvlist
2040 * zc_nvlist_dst_size size of property nvlist
2043 zfs_ioc_objset_stats(zfs_cmd_t *zc)
2048 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
2050 error = zfs_ioc_objset_stats_impl(zc, os);
2051 dmu_objset_rele(os, FTAG);
2059 * zc_name name of filesystem
2060 * zc_nvlist_dst_size size of buffer for property nvlist
2063 * zc_nvlist_dst received property nvlist
2064 * zc_nvlist_dst_size size of received property nvlist
2066 * Gets received properties (distinct from local properties on or after
2067 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2068 * local property values.
2071 zfs_ioc_objset_recvd_props(zfs_cmd_t *zc)
2077 * Without this check, we would return local property values if the
2078 * caller has not already received properties on or after
2079 * SPA_VERSION_RECVD_PROPS.
2081 if (!dsl_prop_get_hasrecvd(zc->zc_name))
2082 return (SET_ERROR(ENOTSUP));
2084 if (zc->zc_nvlist_dst != 0 &&
2085 (error = dsl_prop_get_received(zc->zc_name, &nv)) == 0) {
2086 error = put_nvlist(zc, nv);
2094 nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
2100 * zfs_get_zplprop() will either find a value or give us
2101 * the default value (if there is one).
2103 if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
2105 VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
2111 * zc_name name of filesystem
2112 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2115 * zc_nvlist_dst zpl property nvlist
2116 * zc_nvlist_dst_size size of zpl property nvlist
2119 zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
2124 /* XXX reading without owning */
2125 if ((err = dmu_objset_hold(zc->zc_name, FTAG, &os)))
2128 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
2131 * NB: nvl_add_zplprop() will read the objset contents,
2132 * which we aren't supposed to do with a DS_MODE_USER
2133 * hold, because it could be inconsistent.
2135 if (zc->zc_nvlist_dst != 0 &&
2136 !zc->zc_objset_stats.dds_inconsistent &&
2137 dmu_objset_type(os) == DMU_OST_ZFS) {
2140 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2141 if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
2142 (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
2143 (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
2144 (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
2145 err = put_nvlist(zc, nv);
2148 err = SET_ERROR(ENOENT);
2150 dmu_objset_rele(os, FTAG);
2155 dataset_name_hidden(const char *name)
2158 * Skip over datasets that are not visible in this zone,
2159 * internal datasets (which have a $ in their name), and
2160 * temporary datasets (which have a % in their name).
2162 if (strchr(name, '$') != NULL)
2164 if (strchr(name, '%') != NULL)
2166 if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
2173 * zc_name name of filesystem
2174 * zc_cookie zap cursor
2175 * zc_nvlist_dst_size size of buffer for property nvlist
2178 * zc_name name of next filesystem
2179 * zc_cookie zap cursor
2180 * zc_objset_stats stats
2181 * zc_nvlist_dst property nvlist
2182 * zc_nvlist_dst_size size of property nvlist
2185 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
2190 size_t orig_len = strlen(zc->zc_name);
2193 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os))) {
2194 if (error == ENOENT)
2195 error = SET_ERROR(ESRCH);
2199 p = strrchr(zc->zc_name, '/');
2200 if (p == NULL || p[1] != '\0')
2201 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
2202 p = zc->zc_name + strlen(zc->zc_name);
2205 error = dmu_dir_list_next(os,
2206 sizeof (zc->zc_name) - (p - zc->zc_name), p,
2207 NULL, &zc->zc_cookie);
2208 if (error == ENOENT)
2209 error = SET_ERROR(ESRCH);
2210 } while (error == 0 && dataset_name_hidden(zc->zc_name));
2211 dmu_objset_rele(os, FTAG);
2214 * If it's an internal dataset (ie. with a '$' in its name),
2215 * don't try to get stats for it, otherwise we'll return ENOENT.
2217 if (error == 0 && strchr(zc->zc_name, '$') == NULL) {
2218 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
2219 if (error == ENOENT) {
2220 /* We lost a race with destroy, get the next one. */
2221 zc->zc_name[orig_len] = '\0';
2230 * zc_name name of filesystem
2231 * zc_cookie zap cursor
2232 * zc_nvlist_dst_size size of buffer for property nvlist
2235 * zc_name name of next snapshot
2236 * zc_objset_stats stats
2237 * zc_nvlist_dst property nvlist
2238 * zc_nvlist_dst_size size of property nvlist
2241 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
2246 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
2248 return (error == ENOENT ? ESRCH : error);
2252 * A dataset name of maximum length cannot have any snapshots,
2253 * so exit immediately.
2255 if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
2256 dmu_objset_rele(os, FTAG);
2257 return (SET_ERROR(ESRCH));
2260 error = dmu_snapshot_list_next(os,
2261 sizeof (zc->zc_name) - strlen(zc->zc_name),
2262 zc->zc_name + strlen(zc->zc_name), &zc->zc_obj, &zc->zc_cookie,
2265 if (error == 0 && !zc->zc_simple) {
2267 dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
2269 error = dsl_dataset_hold_obj(dp, zc->zc_obj, FTAG, &ds);
2273 error = dmu_objset_from_ds(ds, &ossnap);
2275 error = zfs_ioc_objset_stats_impl(zc, ossnap);
2276 dsl_dataset_rele(ds, FTAG);
2278 } else if (error == ENOENT) {
2279 error = SET_ERROR(ESRCH);
2282 dmu_objset_rele(os, FTAG);
2283 /* if we failed, undo the @ that we tacked on to zc_name */
2285 *strchr(zc->zc_name, '@') = '\0';
2290 zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
2292 const char *propname = nvpair_name(pair);
2294 unsigned int vallen;
2297 zfs_userquota_prop_t type;
2303 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2305 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2306 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2308 return (SET_ERROR(EINVAL));
2312 * A correctly constructed propname is encoded as
2313 * userquota@<rid>-<domain>.
2315 if ((dash = strchr(propname, '-')) == NULL ||
2316 nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
2318 return (SET_ERROR(EINVAL));
2325 err = zfs_sb_hold(dsname, FTAG, &zsb, B_FALSE);
2327 err = zfs_set_userquota(zsb, type, domain, rid, quota);
2328 zfs_sb_rele(zsb, FTAG);
2335 * If the named property is one that has a special function to set its value,
2336 * return 0 on success and a positive error code on failure; otherwise if it is
2337 * not one of the special properties handled by this function, return -1.
2339 * XXX: It would be better for callers of the property interface if we handled
2340 * these special cases in dsl_prop.c (in the dsl layer).
2343 zfs_prop_set_special(const char *dsname, zprop_source_t source,
2346 const char *propname = nvpair_name(pair);
2347 zfs_prop_t prop = zfs_name_to_prop(propname);
2351 if (prop == ZPROP_INVAL) {
2352 if (zfs_prop_userquota(propname))
2353 return (zfs_prop_set_userquota(dsname, pair));
2357 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2359 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2360 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2364 if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
2367 VERIFY(0 == nvpair_value_uint64(pair, &intval));
2370 case ZFS_PROP_QUOTA:
2371 err = dsl_dir_set_quota(dsname, source, intval);
2373 case ZFS_PROP_REFQUOTA:
2374 err = dsl_dataset_set_refquota(dsname, source, intval);
2376 case ZFS_PROP_FILESYSTEM_LIMIT:
2377 case ZFS_PROP_SNAPSHOT_LIMIT:
2378 if (intval == UINT64_MAX) {
2379 /* clearing the limit, just do it */
2382 err = dsl_dir_activate_fs_ss_limit(dsname);
2385 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2386 * default path to set the value in the nvlist.
2391 case ZFS_PROP_RESERVATION:
2392 err = dsl_dir_set_reservation(dsname, source, intval);
2394 case ZFS_PROP_REFRESERVATION:
2395 err = dsl_dataset_set_refreservation(dsname, source, intval);
2397 case ZFS_PROP_VOLSIZE:
2398 err = zvol_set_volsize(dsname, intval);
2400 case ZFS_PROP_SNAPDEV:
2401 err = zvol_set_snapdev(dsname, source, intval);
2403 case ZFS_PROP_VERSION:
2407 if ((err = zfs_sb_hold(dsname, FTAG, &zsb, B_TRUE)) != 0)
2410 err = zfs_set_version(zsb, intval);
2411 zfs_sb_rele(zsb, FTAG);
2413 if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
2416 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
2417 (void) strcpy(zc->zc_name, dsname);
2418 (void) zfs_ioc_userspace_upgrade(zc);
2419 kmem_free(zc, sizeof (zfs_cmd_t));
2431 * This function is best effort. If it fails to set any of the given properties,
2432 * it continues to set as many as it can and returns the last error
2433 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2434 * with the list of names of all the properties that failed along with the
2435 * corresponding error numbers.
2437 * If every property is set successfully, zero is returned and errlist is not
2441 zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
2450 nvlist_t *genericnvl = fnvlist_alloc();
2451 nvlist_t *retrynvl = fnvlist_alloc();
2454 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2455 const char *propname = nvpair_name(pair);
2456 zfs_prop_t prop = zfs_name_to_prop(propname);
2459 /* decode the property value */
2461 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2463 attrs = fnvpair_value_nvlist(pair);
2464 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2466 err = SET_ERROR(EINVAL);
2469 /* Validate value type */
2470 if (err == 0 && prop == ZPROP_INVAL) {
2471 if (zfs_prop_user(propname)) {
2472 if (nvpair_type(propval) != DATA_TYPE_STRING)
2473 err = SET_ERROR(EINVAL);
2474 } else if (zfs_prop_userquota(propname)) {
2475 if (nvpair_type(propval) !=
2476 DATA_TYPE_UINT64_ARRAY)
2477 err = SET_ERROR(EINVAL);
2479 err = SET_ERROR(EINVAL);
2481 } else if (err == 0) {
2482 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2483 if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
2484 err = SET_ERROR(EINVAL);
2485 } else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
2488 intval = fnvpair_value_uint64(propval);
2490 switch (zfs_prop_get_type(prop)) {
2491 case PROP_TYPE_NUMBER:
2493 case PROP_TYPE_STRING:
2494 err = SET_ERROR(EINVAL);
2496 case PROP_TYPE_INDEX:
2497 if (zfs_prop_index_to_string(prop,
2498 intval, &unused) != 0)
2499 err = SET_ERROR(EINVAL);
2503 "unknown property type");
2506 err = SET_ERROR(EINVAL);
2510 /* Validate permissions */
2512 err = zfs_check_settable(dsname, pair, CRED());
2515 err = zfs_prop_set_special(dsname, source, pair);
2518 * For better performance we build up a list of
2519 * properties to set in a single transaction.
2521 err = nvlist_add_nvpair(genericnvl, pair);
2522 } else if (err != 0 && nvl != retrynvl) {
2524 * This may be a spurious error caused by
2525 * receiving quota and reservation out of order.
2526 * Try again in a second pass.
2528 err = nvlist_add_nvpair(retrynvl, pair);
2533 if (errlist != NULL)
2534 fnvlist_add_int32(errlist, propname, err);
2539 if (nvl != retrynvl && !nvlist_empty(retrynvl)) {
2544 if (!nvlist_empty(genericnvl) &&
2545 dsl_props_set(dsname, source, genericnvl) != 0) {
2547 * If this fails, we still want to set as many properties as we
2548 * can, so try setting them individually.
2551 while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) {
2552 const char *propname = nvpair_name(pair);
2556 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2558 attrs = fnvpair_value_nvlist(pair);
2559 propval = fnvlist_lookup_nvpair(attrs,
2563 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2564 strval = fnvpair_value_string(propval);
2565 err = dsl_prop_set_string(dsname, propname,
2568 intval = fnvpair_value_uint64(propval);
2569 err = dsl_prop_set_int(dsname, propname, source,
2574 if (errlist != NULL) {
2575 fnvlist_add_int32(errlist, propname,
2582 nvlist_free(genericnvl);
2583 nvlist_free(retrynvl);
2589 * Check that all the properties are valid user properties.
2592 zfs_check_userprops(const char *fsname, nvlist_t *nvl)
2594 nvpair_t *pair = NULL;
2597 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2598 const char *propname = nvpair_name(pair);
2600 if (!zfs_prop_user(propname) ||
2601 nvpair_type(pair) != DATA_TYPE_STRING)
2602 return (SET_ERROR(EINVAL));
2604 if ((error = zfs_secpolicy_write_perms(fsname,
2605 ZFS_DELEG_PERM_USERPROP, CRED())))
2608 if (strlen(propname) >= ZAP_MAXNAMELEN)
2609 return (SET_ERROR(ENAMETOOLONG));
2611 if (strlen(fnvpair_value_string(pair)) >= ZAP_MAXVALUELEN)
2612 return (SET_ERROR(E2BIG));
2618 props_skip(nvlist_t *props, nvlist_t *skipped, nvlist_t **newprops)
2622 VERIFY(nvlist_alloc(newprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2625 while ((pair = nvlist_next_nvpair(props, pair)) != NULL) {
2626 if (nvlist_exists(skipped, nvpair_name(pair)))
2629 VERIFY(nvlist_add_nvpair(*newprops, pair) == 0);
2634 clear_received_props(const char *dsname, nvlist_t *props,
2638 nvlist_t *cleared_props = NULL;
2639 props_skip(props, skipped, &cleared_props);
2640 if (!nvlist_empty(cleared_props)) {
2642 * Acts on local properties until the dataset has received
2643 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2645 zprop_source_t flags = (ZPROP_SRC_NONE |
2646 (dsl_prop_get_hasrecvd(dsname) ? ZPROP_SRC_RECEIVED : 0));
2647 err = zfs_set_prop_nvlist(dsname, flags, cleared_props, NULL);
2649 nvlist_free(cleared_props);
2655 * zc_name name of filesystem
2656 * zc_value name of property to set
2657 * zc_nvlist_src{_size} nvlist of properties to apply
2658 * zc_cookie received properties flag
2661 * zc_nvlist_dst{_size} error for each unapplied received property
2664 zfs_ioc_set_prop(zfs_cmd_t *zc)
2667 boolean_t received = zc->zc_cookie;
2668 zprop_source_t source = (received ? ZPROP_SRC_RECEIVED :
2673 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2674 zc->zc_iflags, &nvl)) != 0)
2678 nvlist_t *origprops;
2680 if (dsl_prop_get_received(zc->zc_name, &origprops) == 0) {
2681 (void) clear_received_props(zc->zc_name,
2683 nvlist_free(origprops);
2686 error = dsl_prop_set_hasrecvd(zc->zc_name);
2689 errors = fnvlist_alloc();
2691 error = zfs_set_prop_nvlist(zc->zc_name, source, nvl, errors);
2693 if (zc->zc_nvlist_dst != 0 && errors != NULL) {
2694 (void) put_nvlist(zc, errors);
2697 nvlist_free(errors);
2704 * zc_name name of filesystem
2705 * zc_value name of property to inherit
2706 * zc_cookie revert to received value if TRUE
2711 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
2713 const char *propname = zc->zc_value;
2714 zfs_prop_t prop = zfs_name_to_prop(propname);
2715 boolean_t received = zc->zc_cookie;
2716 zprop_source_t source = (received
2717 ? ZPROP_SRC_NONE /* revert to received value, if any */
2718 : ZPROP_SRC_INHERITED); /* explicitly inherit */
2727 * zfs_prop_set_special() expects properties in the form of an
2728 * nvpair with type info.
2730 if (prop == ZPROP_INVAL) {
2731 if (!zfs_prop_user(propname))
2732 return (SET_ERROR(EINVAL));
2734 type = PROP_TYPE_STRING;
2735 } else if (prop == ZFS_PROP_VOLSIZE ||
2736 prop == ZFS_PROP_VERSION) {
2737 return (SET_ERROR(EINVAL));
2739 type = zfs_prop_get_type(prop);
2742 VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2745 case PROP_TYPE_STRING:
2746 VERIFY(0 == nvlist_add_string(dummy, propname, ""));
2748 case PROP_TYPE_NUMBER:
2749 case PROP_TYPE_INDEX:
2750 VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
2754 return (SET_ERROR(EINVAL));
2757 pair = nvlist_next_nvpair(dummy, NULL);
2758 err = zfs_prop_set_special(zc->zc_name, source, pair);
2761 return (err); /* special property already handled */
2764 * Only check this in the non-received case. We want to allow
2765 * 'inherit -S' to revert non-inheritable properties like quota
2766 * and reservation to the received or default values even though
2767 * they are not considered inheritable.
2769 if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
2770 return (SET_ERROR(EINVAL));
2773 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2774 return (dsl_prop_inherit(zc->zc_name, zc->zc_value, source));
2778 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
2785 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2786 zc->zc_iflags, &props)))
2790 * If the only property is the configfile, then just do a spa_lookup()
2791 * to handle the faulted case.
2793 pair = nvlist_next_nvpair(props, NULL);
2794 if (pair != NULL && strcmp(nvpair_name(pair),
2795 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
2796 nvlist_next_nvpair(props, pair) == NULL) {
2797 mutex_enter(&spa_namespace_lock);
2798 if ((spa = spa_lookup(zc->zc_name)) != NULL) {
2799 spa_configfile_set(spa, props, B_FALSE);
2800 spa_config_sync(spa, B_FALSE, B_TRUE);
2802 mutex_exit(&spa_namespace_lock);
2809 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2814 error = spa_prop_set(spa, props);
2817 spa_close(spa, FTAG);
2823 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
2827 nvlist_t *nvp = NULL;
2829 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2831 * If the pool is faulted, there may be properties we can still
2832 * get (such as altroot and cachefile), so attempt to get them
2835 mutex_enter(&spa_namespace_lock);
2836 if ((spa = spa_lookup(zc->zc_name)) != NULL)
2837 error = spa_prop_get(spa, &nvp);
2838 mutex_exit(&spa_namespace_lock);
2840 error = spa_prop_get(spa, &nvp);
2841 spa_close(spa, FTAG);
2844 if (error == 0 && zc->zc_nvlist_dst != 0)
2845 error = put_nvlist(zc, nvp);
2847 error = SET_ERROR(EFAULT);
2855 * zc_name name of filesystem
2856 * zc_nvlist_src{_size} nvlist of delegated permissions
2857 * zc_perm_action allow/unallow flag
2862 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
2865 nvlist_t *fsaclnv = NULL;
2867 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2868 zc->zc_iflags, &fsaclnv)) != 0)
2872 * Verify nvlist is constructed correctly
2874 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
2875 nvlist_free(fsaclnv);
2876 return (SET_ERROR(EINVAL));
2880 * If we don't have PRIV_SYS_MOUNT, then validate
2881 * that user is allowed to hand out each permission in
2885 error = secpolicy_zfs(CRED());
2887 if (zc->zc_perm_action == B_FALSE) {
2888 error = dsl_deleg_can_allow(zc->zc_name,
2891 error = dsl_deleg_can_unallow(zc->zc_name,
2897 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
2899 nvlist_free(fsaclnv);
2905 * zc_name name of filesystem
2908 * zc_nvlist_src{_size} nvlist of delegated permissions
2911 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
2916 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
2917 error = put_nvlist(zc, nvp);
2926 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
2928 zfs_creat_t *zct = arg;
2930 zfs_create_fs(os, cr, zct->zct_zplprops, tx);
2933 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2937 * os parent objset pointer (NULL if root fs)
2938 * fuids_ok fuids allowed in this version of the spa?
2939 * sa_ok SAs allowed in this version of the spa?
2940 * createprops list of properties requested by creator
2943 * zplprops values for the zplprops we attach to the master node object
2944 * is_ci true if requested file system will be purely case-insensitive
2946 * Determine the settings for utf8only, normalization and
2947 * casesensitivity. Specific values may have been requested by the
2948 * creator and/or we can inherit values from the parent dataset. If
2949 * the file system is of too early a vintage, a creator can not
2950 * request settings for these properties, even if the requested
2951 * setting is the default value. We don't actually want to create dsl
2952 * properties for these, so remove them from the source nvlist after
2956 zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
2957 boolean_t fuids_ok, boolean_t sa_ok, nvlist_t *createprops,
2958 nvlist_t *zplprops, boolean_t *is_ci)
2960 uint64_t sense = ZFS_PROP_UNDEFINED;
2961 uint64_t norm = ZFS_PROP_UNDEFINED;
2962 uint64_t u8 = ZFS_PROP_UNDEFINED;
2965 ASSERT(zplprops != NULL);
2968 * Pull out creator prop choices, if any.
2971 (void) nvlist_lookup_uint64(createprops,
2972 zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
2973 (void) nvlist_lookup_uint64(createprops,
2974 zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
2975 (void) nvlist_remove_all(createprops,
2976 zfs_prop_to_name(ZFS_PROP_NORMALIZE));
2977 (void) nvlist_lookup_uint64(createprops,
2978 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
2979 (void) nvlist_remove_all(createprops,
2980 zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
2981 (void) nvlist_lookup_uint64(createprops,
2982 zfs_prop_to_name(ZFS_PROP_CASE), &sense);
2983 (void) nvlist_remove_all(createprops,
2984 zfs_prop_to_name(ZFS_PROP_CASE));
2988 * If the zpl version requested is whacky or the file system
2989 * or pool is version is too "young" to support normalization
2990 * and the creator tried to set a value for one of the props,
2993 if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
2994 (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
2995 (zplver >= ZPL_VERSION_SA && !sa_ok) ||
2996 (zplver < ZPL_VERSION_NORMALIZATION &&
2997 (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
2998 sense != ZFS_PROP_UNDEFINED)))
2999 return (SET_ERROR(ENOTSUP));
3002 * Put the version in the zplprops
3004 VERIFY(nvlist_add_uint64(zplprops,
3005 zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
3007 if (norm == ZFS_PROP_UNDEFINED &&
3008 (error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm)) != 0)
3010 VERIFY(nvlist_add_uint64(zplprops,
3011 zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
3014 * If we're normalizing, names must always be valid UTF-8 strings.
3018 if (u8 == ZFS_PROP_UNDEFINED &&
3019 (error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8)) != 0)
3021 VERIFY(nvlist_add_uint64(zplprops,
3022 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
3024 if (sense == ZFS_PROP_UNDEFINED &&
3025 (error = zfs_get_zplprop(os, ZFS_PROP_CASE, &sense)) != 0)
3027 VERIFY(nvlist_add_uint64(zplprops,
3028 zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
3031 *is_ci = (sense == ZFS_CASE_INSENSITIVE);
3037 zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
3038 nvlist_t *zplprops, boolean_t *is_ci)
3040 boolean_t fuids_ok, sa_ok;
3041 uint64_t zplver = ZPL_VERSION;
3042 objset_t *os = NULL;
3043 char parentname[MAXNAMELEN];
3049 (void) strlcpy(parentname, dataset, sizeof (parentname));
3050 cp = strrchr(parentname, '/');
3054 if ((error = spa_open(dataset, &spa, FTAG)) != 0)
3057 spa_vers = spa_version(spa);
3058 spa_close(spa, FTAG);
3060 zplver = zfs_zpl_version_map(spa_vers);
3061 fuids_ok = (zplver >= ZPL_VERSION_FUID);
3062 sa_ok = (zplver >= ZPL_VERSION_SA);
3065 * Open parent object set so we can inherit zplprop values.
3067 if ((error = dmu_objset_hold(parentname, FTAG, &os)) != 0)
3070 error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, sa_ok, createprops,
3072 dmu_objset_rele(os, FTAG);
3077 zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
3078 nvlist_t *zplprops, boolean_t *is_ci)
3082 uint64_t zplver = ZPL_VERSION;
3085 zplver = zfs_zpl_version_map(spa_vers);
3086 fuids_ok = (zplver >= ZPL_VERSION_FUID);
3087 sa_ok = (zplver >= ZPL_VERSION_SA);
3089 error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, sa_ok,
3090 createprops, zplprops, is_ci);
3096 * "type" -> dmu_objset_type_t (int32)
3097 * (optional) "props" -> { prop -> value }
3100 * outnvl: propname -> error code (int32)
3103 zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3106 zfs_creat_t zct = { 0 };
3107 nvlist_t *nvprops = NULL;
3108 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
3110 dmu_objset_type_t type;
3111 boolean_t is_insensitive = B_FALSE;
3113 if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
3114 return (SET_ERROR(EINVAL));
3116 (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
3120 cbfunc = zfs_create_cb;
3124 cbfunc = zvol_create_cb;
3131 if (strchr(fsname, '@') ||
3132 strchr(fsname, '%'))
3133 return (SET_ERROR(EINVAL));
3135 zct.zct_props = nvprops;
3138 return (SET_ERROR(EINVAL));
3140 if (type == DMU_OST_ZVOL) {
3141 uint64_t volsize, volblocksize;
3143 if (nvprops == NULL)
3144 return (SET_ERROR(EINVAL));
3145 if (nvlist_lookup_uint64(nvprops,
3146 zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) != 0)
3147 return (SET_ERROR(EINVAL));
3149 if ((error = nvlist_lookup_uint64(nvprops,
3150 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
3151 &volblocksize)) != 0 && error != ENOENT)
3152 return (SET_ERROR(EINVAL));
3155 volblocksize = zfs_prop_default_numeric(
3156 ZFS_PROP_VOLBLOCKSIZE);
3158 if ((error = zvol_check_volblocksize(fsname,
3159 volblocksize)) != 0 ||
3160 (error = zvol_check_volsize(volsize,
3161 volblocksize)) != 0)
3163 } else if (type == DMU_OST_ZFS) {
3167 * We have to have normalization and
3168 * case-folding flags correct when we do the
3169 * file system creation, so go figure them out
3172 VERIFY(nvlist_alloc(&zct.zct_zplprops,
3173 NV_UNIQUE_NAME, KM_SLEEP) == 0);
3174 error = zfs_fill_zplprops(fsname, nvprops,
3175 zct.zct_zplprops, &is_insensitive);
3177 nvlist_free(zct.zct_zplprops);
3182 error = dmu_objset_create(fsname, type,
3183 is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
3184 nvlist_free(zct.zct_zplprops);
3187 * It would be nice to do this atomically.
3190 error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
3197 * Volumes will return EBUSY and cannot be destroyed
3198 * until all asynchronous minor handling has completed.
3199 * Wait for the spa_zvol_taskq to drain then retry.
3201 error2 = dsl_destroy_head(fsname);
3202 while ((error2 == EBUSY) && (type == DMU_OST_ZVOL)) {
3203 error2 = spa_open(fsname, &spa, FTAG);
3205 taskq_wait(spa->spa_zvol_taskq);
3206 spa_close(spa, FTAG);
3208 error2 = dsl_destroy_head(fsname);
3217 * "origin" -> name of origin snapshot
3218 * (optional) "props" -> { prop -> value }
3222 * outnvl: propname -> error code (int32)
3225 zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3228 nvlist_t *nvprops = NULL;
3231 if (nvlist_lookup_string(innvl, "origin", &origin_name) != 0)
3232 return (SET_ERROR(EINVAL));
3233 (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
3235 if (strchr(fsname, '@') ||
3236 strchr(fsname, '%'))
3237 return (SET_ERROR(EINVAL));
3239 if (dataset_namecheck(origin_name, NULL, NULL) != 0)
3240 return (SET_ERROR(EINVAL));
3241 error = dmu_objset_clone(fsname, origin_name);
3246 * It would be nice to do this atomically.
3249 error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
3252 (void) dsl_destroy_head(fsname);
3259 * "snaps" -> { snapshot1, snapshot2 }
3260 * (optional) "props" -> { prop -> value (string) }
3263 * outnvl: snapshot -> error code (int32)
3266 zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3269 nvlist_t *props = NULL;
3271 nvpair_t *pair, *pair2;
3273 (void) nvlist_lookup_nvlist(innvl, "props", &props);
3274 if ((error = zfs_check_userprops(poolname, props)) != 0)
3277 if (!nvlist_empty(props) &&
3278 zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
3279 return (SET_ERROR(ENOTSUP));
3281 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
3282 return (SET_ERROR(EINVAL));
3283 poollen = strlen(poolname);
3284 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
3285 pair = nvlist_next_nvpair(snaps, pair)) {
3286 const char *name = nvpair_name(pair);
3287 const char *cp = strchr(name, '@');
3290 * The snap name must contain an @, and the part after it must
3291 * contain only valid characters.
3294 zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
3295 return (SET_ERROR(EINVAL));
3298 * The snap must be in the specified pool.
3300 if (strncmp(name, poolname, poollen) != 0 ||
3301 (name[poollen] != '/' && name[poollen] != '@'))
3302 return (SET_ERROR(EXDEV));
3304 /* This must be the only snap of this fs. */
3305 for (pair2 = nvlist_next_nvpair(snaps, pair);
3306 pair2 != NULL; pair2 = nvlist_next_nvpair(snaps, pair2)) {
3307 if (strncmp(name, nvpair_name(pair2), cp - name + 1)
3309 return (SET_ERROR(EXDEV));
3314 error = dsl_dataset_snapshot(snaps, props, outnvl);
3320 * innvl: "message" -> string
3324 zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
3332 * The poolname in the ioctl is not set, we get it from the TSD,
3333 * which was set at the end of the last successful ioctl that allows
3334 * logging. The secpolicy func already checked that it is set.
3335 * Only one log ioctl is allowed after each successful ioctl, so
3336 * we clear the TSD here.
3338 poolname = tsd_get(zfs_allow_log_key);
3339 (void) tsd_set(zfs_allow_log_key, NULL);
3340 error = spa_open(poolname, &spa, FTAG);
3345 if (nvlist_lookup_string(innvl, "message", &message) != 0) {
3346 spa_close(spa, FTAG);
3347 return (SET_ERROR(EINVAL));
3350 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
3351 spa_close(spa, FTAG);
3352 return (SET_ERROR(ENOTSUP));
3355 error = spa_history_log(spa, message);
3356 spa_close(spa, FTAG);
3361 * The dp_config_rwlock must not be held when calling this, because the
3362 * unmount may need to write out data.
3364 * This function is best-effort. Callers must deal gracefully if it
3365 * remains mounted (or is remounted after this call).
3367 * Returns 0 if the argument is not a snapshot, or it is not currently a
3368 * filesystem, or we were able to unmount it. Returns error code otherwise.
3371 zfs_unmount_snap(const char *snapname)
3375 if (strchr(snapname, '@') == NULL)
3378 err = zfsctl_snapshot_unmount((char *)snapname, MNT_FORCE);
3379 if (err != 0 && err != ENOENT)
3380 return (SET_ERROR(err));
3387 zfs_unmount_snap_cb(const char *snapname, void *arg)
3389 return (zfs_unmount_snap(snapname));
3393 * When a clone is destroyed, its origin may also need to be destroyed,
3394 * in which case it must be unmounted. This routine will do that unmount
3398 zfs_destroy_unmount_origin(const char *fsname)
3404 error = dmu_objset_hold(fsname, FTAG, &os);
3407 ds = dmu_objset_ds(os);
3408 if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev)) {
3409 char originname[MAXNAMELEN];
3410 dsl_dataset_name(ds->ds_prev, originname);
3411 dmu_objset_rele(os, FTAG);
3412 (void) zfs_unmount_snap(originname);
3414 dmu_objset_rele(os, FTAG);
3420 * "snaps" -> { snapshot1, snapshot2 }
3421 * (optional boolean) "defer"
3424 * outnvl: snapshot -> error code (int32)
3428 zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3434 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
3435 return (SET_ERROR(EINVAL));
3436 defer = nvlist_exists(innvl, "defer");
3438 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
3439 pair = nvlist_next_nvpair(snaps, pair)) {
3440 (void) zfs_unmount_snap(nvpair_name(pair));
3443 return (dsl_destroy_snapshots_nvl(snaps, defer, outnvl));
3447 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3448 * All bookmarks must be in the same pool.
3451 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3454 * outnvl: bookmark -> error code (int32)
3459 zfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3461 nvpair_t *pair, *pair2;
3463 for (pair = nvlist_next_nvpair(innvl, NULL);
3464 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
3468 * Verify the snapshot argument.
3470 if (nvpair_value_string(pair, &snap_name) != 0)
3471 return (SET_ERROR(EINVAL));
3474 /* Verify that the keys (bookmarks) are unique */
3475 for (pair2 = nvlist_next_nvpair(innvl, pair);
3476 pair2 != NULL; pair2 = nvlist_next_nvpair(innvl, pair2)) {
3477 if (strcmp(nvpair_name(pair), nvpair_name(pair2)) == 0)
3478 return (SET_ERROR(EINVAL));
3482 return (dsl_bookmark_create(innvl, outnvl));
3487 * property 1, property 2, ...
3491 * bookmark name 1 -> { property 1, property 2, ... },
3492 * bookmark name 2 -> { property 1, property 2, ... }
3497 zfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3499 return (dsl_get_bookmarks(fsname, innvl, outnvl));
3504 * bookmark name 1, bookmark name 2
3507 * outnvl: bookmark -> error code (int32)
3511 zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
3517 poollen = strlen(poolname);
3518 for (pair = nvlist_next_nvpair(innvl, NULL);
3519 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
3520 const char *name = nvpair_name(pair);
3521 const char *cp = strchr(name, '#');
3524 * The bookmark name must contain an #, and the part after it
3525 * must contain only valid characters.
3528 zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
3529 return (SET_ERROR(EINVAL));
3532 * The bookmark must be in the specified pool.
3534 if (strncmp(name, poolname, poollen) != 0 ||
3535 (name[poollen] != '/' && name[poollen] != '#'))
3536 return (SET_ERROR(EXDEV));
3539 error = dsl_bookmark_destroy(innvl, outnvl);
3545 * zc_name name of dataset to destroy
3546 * zc_objset_type type of objset
3547 * zc_defer_destroy mark for deferred destroy
3552 zfs_ioc_destroy(zfs_cmd_t *zc)
3556 if (zc->zc_objset_type == DMU_OST_ZFS) {
3557 err = zfs_unmount_snap(zc->zc_name);
3562 if (strchr(zc->zc_name, '@'))
3563 err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
3565 err = dsl_destroy_head(zc->zc_name);
3571 * fsname is name of dataset to rollback (to most recent snapshot)
3573 * innvl is not used.
3575 * outnvl: "target" -> name of most recent snapshot
3580 zfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
3585 if (get_zfs_sb(fsname, &zsb) == 0) {
3586 error = zfs_suspend_fs(zsb);
3590 error = dsl_dataset_rollback(fsname, zsb, outnvl);
3591 resume_err = zfs_resume_fs(zsb, fsname);
3592 error = error ? error : resume_err;
3594 deactivate_super(zsb->z_sb);
3596 error = dsl_dataset_rollback(fsname, NULL, outnvl);
3602 recursive_unmount(const char *fsname, void *arg)
3604 const char *snapname = arg;
3608 fullname = kmem_asprintf("%s@%s", fsname, snapname);
3609 error = zfs_unmount_snap(fullname);
3617 * zc_name old name of dataset
3618 * zc_value new name of dataset
3619 * zc_cookie recursive flag (only valid for snapshots)
3624 zfs_ioc_rename(zfs_cmd_t *zc)
3626 boolean_t recursive = zc->zc_cookie & 1;
3629 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
3630 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
3631 strchr(zc->zc_value, '%'))
3632 return (SET_ERROR(EINVAL));
3634 at = strchr(zc->zc_name, '@');
3636 /* snaps must be in same fs */
3639 if (strncmp(zc->zc_name, zc->zc_value, at - zc->zc_name + 1))
3640 return (SET_ERROR(EXDEV));
3642 if (zc->zc_objset_type == DMU_OST_ZFS) {
3643 error = dmu_objset_find(zc->zc_name,
3644 recursive_unmount, at + 1,
3645 recursive ? DS_FIND_CHILDREN : 0);
3651 error = dsl_dataset_rename_snapshot(zc->zc_name,
3652 at + 1, strchr(zc->zc_value, '@') + 1, recursive);
3657 return (dsl_dir_rename(zc->zc_name, zc->zc_value));
3662 zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
3664 const char *propname = nvpair_name(pair);
3665 boolean_t issnap = (strchr(dsname, '@') != NULL);
3666 zfs_prop_t prop = zfs_name_to_prop(propname);
3670 if (prop == ZPROP_INVAL) {
3671 if (zfs_prop_user(propname)) {
3672 if ((err = zfs_secpolicy_write_perms(dsname,
3673 ZFS_DELEG_PERM_USERPROP, cr)))
3678 if (!issnap && zfs_prop_userquota(propname)) {
3679 const char *perm = NULL;
3680 const char *uq_prefix =
3681 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA];
3682 const char *gq_prefix =
3683 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA];
3685 if (strncmp(propname, uq_prefix,
3686 strlen(uq_prefix)) == 0) {
3687 perm = ZFS_DELEG_PERM_USERQUOTA;
3688 } else if (strncmp(propname, gq_prefix,
3689 strlen(gq_prefix)) == 0) {
3690 perm = ZFS_DELEG_PERM_GROUPQUOTA;
3692 /* USERUSED and GROUPUSED are read-only */
3693 return (SET_ERROR(EINVAL));
3696 if ((err = zfs_secpolicy_write_perms(dsname, perm, cr)))
3701 return (SET_ERROR(EINVAL));
3705 return (SET_ERROR(EINVAL));
3707 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
3709 * dsl_prop_get_all_impl() returns properties in this
3713 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
3714 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3719 * Check that this value is valid for this pool version
3722 case ZFS_PROP_COMPRESSION:
3724 * If the user specified gzip compression, make sure
3725 * the SPA supports it. We ignore any errors here since
3726 * we'll catch them later.
3728 if (nvpair_value_uint64(pair, &intval) == 0) {
3729 if (intval >= ZIO_COMPRESS_GZIP_1 &&
3730 intval <= ZIO_COMPRESS_GZIP_9 &&
3731 zfs_earlier_version(dsname,
3732 SPA_VERSION_GZIP_COMPRESSION)) {
3733 return (SET_ERROR(ENOTSUP));
3736 if (intval == ZIO_COMPRESS_ZLE &&
3737 zfs_earlier_version(dsname,
3738 SPA_VERSION_ZLE_COMPRESSION))
3739 return (SET_ERROR(ENOTSUP));
3741 if (intval == ZIO_COMPRESS_LZ4) {
3744 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
3747 if (!spa_feature_is_enabled(spa,
3748 SPA_FEATURE_LZ4_COMPRESS)) {
3749 spa_close(spa, FTAG);
3750 return (SET_ERROR(ENOTSUP));
3752 spa_close(spa, FTAG);
3756 * If this is a bootable dataset then
3757 * verify that the compression algorithm
3758 * is supported for booting. We must return
3759 * something other than ENOTSUP since it
3760 * implies a downrev pool version.
3762 if (zfs_is_bootfs(dsname) &&
3763 !BOOTFS_COMPRESS_VALID(intval)) {
3764 return (SET_ERROR(ERANGE));
3769 case ZFS_PROP_COPIES:
3770 if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
3771 return (SET_ERROR(ENOTSUP));
3774 case ZFS_PROP_DEDUP:
3775 if (zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
3776 return (SET_ERROR(ENOTSUP));
3779 case ZFS_PROP_VOLBLOCKSIZE:
3780 case ZFS_PROP_RECORDSIZE:
3781 /* Record sizes above 128k need the feature to be enabled */
3782 if (nvpair_value_uint64(pair, &intval) == 0 &&
3783 intval > SPA_OLD_MAXBLOCKSIZE) {
3787 * If this is a bootable dataset then
3788 * the we don't allow large (>128K) blocks,
3789 * because GRUB doesn't support them.
3791 if (zfs_is_bootfs(dsname) &&
3792 intval > SPA_OLD_MAXBLOCKSIZE) {
3793 return (SET_ERROR(ERANGE));
3797 * We don't allow setting the property above 1MB,
3798 * unless the tunable has been changed.
3800 if (intval > zfs_max_recordsize ||
3801 intval > SPA_MAXBLOCKSIZE)
3802 return (SET_ERROR(ERANGE));
3804 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
3807 if (!spa_feature_is_enabled(spa,
3808 SPA_FEATURE_LARGE_BLOCKS)) {
3809 spa_close(spa, FTAG);
3810 return (SET_ERROR(ENOTSUP));
3812 spa_close(spa, FTAG);
3816 case ZFS_PROP_SHARESMB:
3817 if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
3818 return (SET_ERROR(ENOTSUP));
3821 case ZFS_PROP_ACLINHERIT:
3822 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3823 nvpair_value_uint64(pair, &intval) == 0) {
3824 if (intval == ZFS_ACL_PASSTHROUGH_X &&
3825 zfs_earlier_version(dsname,
3826 SPA_VERSION_PASSTHROUGH_X))
3827 return (SET_ERROR(ENOTSUP));
3834 return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
3838 * Removes properties from the given props list that fail permission checks
3839 * needed to clear them and to restore them in case of a receive error. For each
3840 * property, make sure we have both set and inherit permissions.
3842 * Returns the first error encountered if any permission checks fail. If the
3843 * caller provides a non-NULL errlist, it also gives the complete list of names
3844 * of all the properties that failed a permission check along with the
3845 * corresponding error numbers. The caller is responsible for freeing the
3848 * If every property checks out successfully, zero is returned and the list
3849 * pointed at by errlist is NULL.
3852 zfs_check_clearable(char *dataset, nvlist_t *props, nvlist_t **errlist)
3855 nvpair_t *pair, *next_pair;
3862 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
3864 zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
3865 (void) strcpy(zc->zc_name, dataset);
3866 pair = nvlist_next_nvpair(props, NULL);
3867 while (pair != NULL) {
3868 next_pair = nvlist_next_nvpair(props, pair);
3870 (void) strcpy(zc->zc_value, nvpair_name(pair));
3871 if ((err = zfs_check_settable(dataset, pair, CRED())) != 0 ||
3872 (err = zfs_secpolicy_inherit_prop(zc, NULL, CRED())) != 0) {
3873 VERIFY(nvlist_remove_nvpair(props, pair) == 0);
3874 VERIFY(nvlist_add_int32(errors,
3875 zc->zc_value, err) == 0);
3879 kmem_free(zc, sizeof (zfs_cmd_t));
3881 if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
3882 nvlist_free(errors);
3885 VERIFY(nvpair_value_int32(pair, &rv) == 0);
3888 if (errlist == NULL)
3889 nvlist_free(errors);
3897 propval_equals(nvpair_t *p1, nvpair_t *p2)
3899 if (nvpair_type(p1) == DATA_TYPE_NVLIST) {
3900 /* dsl_prop_get_all_impl() format */
3902 VERIFY(nvpair_value_nvlist(p1, &attrs) == 0);
3903 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3907 if (nvpair_type(p2) == DATA_TYPE_NVLIST) {
3909 VERIFY(nvpair_value_nvlist(p2, &attrs) == 0);
3910 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3914 if (nvpair_type(p1) != nvpair_type(p2))
3917 if (nvpair_type(p1) == DATA_TYPE_STRING) {
3918 char *valstr1, *valstr2;
3920 VERIFY(nvpair_value_string(p1, (char **)&valstr1) == 0);
3921 VERIFY(nvpair_value_string(p2, (char **)&valstr2) == 0);
3922 return (strcmp(valstr1, valstr2) == 0);
3924 uint64_t intval1, intval2;
3926 VERIFY(nvpair_value_uint64(p1, &intval1) == 0);
3927 VERIFY(nvpair_value_uint64(p2, &intval2) == 0);
3928 return (intval1 == intval2);
3933 * Remove properties from props if they are not going to change (as determined
3934 * by comparison with origprops). Remove them from origprops as well, since we
3935 * do not need to clear or restore properties that won't change.
3938 props_reduce(nvlist_t *props, nvlist_t *origprops)
3940 nvpair_t *pair, *next_pair;
3942 if (origprops == NULL)
3943 return; /* all props need to be received */
3945 pair = nvlist_next_nvpair(props, NULL);
3946 while (pair != NULL) {
3947 const char *propname = nvpair_name(pair);
3950 next_pair = nvlist_next_nvpair(props, pair);
3952 if ((nvlist_lookup_nvpair(origprops, propname,
3953 &match) != 0) || !propval_equals(pair, match))
3954 goto next; /* need to set received value */
3956 /* don't clear the existing received value */
3957 (void) nvlist_remove_nvpair(origprops, match);
3958 /* don't bother receiving the property */
3959 (void) nvlist_remove_nvpair(props, pair);
3966 static boolean_t zfs_ioc_recv_inject_err;
3971 * zc_name name of containing filesystem
3972 * zc_nvlist_src{_size} nvlist of properties to apply
3973 * zc_value name of snapshot to create
3974 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3975 * zc_cookie file descriptor to recv from
3976 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3977 * zc_guid force flag
3978 * zc_cleanup_fd cleanup-on-exit file descriptor
3979 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
3982 * zc_cookie number of bytes read
3983 * zc_nvlist_dst{_size} error for each unapplied received property
3984 * zc_obj zprop_errflags_t
3985 * zc_action_handle handle for this guid/ds mapping
3988 zfs_ioc_recv(zfs_cmd_t *zc)
3991 dmu_recv_cookie_t drc;
3992 boolean_t force = (boolean_t)zc->zc_guid;
3995 int props_error = 0;
3998 nvlist_t *props = NULL; /* sent properties */
3999 nvlist_t *origprops = NULL; /* existing properties */
4000 char *origin = NULL;
4002 char tofs[ZFS_MAXNAMELEN];
4003 boolean_t first_recvd_props = B_FALSE;
4005 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
4006 strchr(zc->zc_value, '@') == NULL ||
4007 strchr(zc->zc_value, '%'))
4008 return (SET_ERROR(EINVAL));
4010 (void) strcpy(tofs, zc->zc_value);
4011 tosnap = strchr(tofs, '@');
4014 if (zc->zc_nvlist_src != 0 &&
4015 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
4016 zc->zc_iflags, &props)) != 0)
4023 return (SET_ERROR(EBADF));
4026 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
4028 if (zc->zc_string[0])
4029 origin = zc->zc_string;
4031 error = dmu_recv_begin(tofs, tosnap,
4032 &zc->zc_begin_record, force, origin, &drc);
4037 * Set properties before we receive the stream so that they are applied
4038 * to the new data. Note that we must call dmu_recv_stream() if
4039 * dmu_recv_begin() succeeds.
4041 if (props != NULL && !drc.drc_newfs) {
4042 if (spa_version(dsl_dataset_get_spa(drc.drc_ds)) >=
4043 SPA_VERSION_RECVD_PROPS &&
4044 !dsl_prop_get_hasrecvd(tofs))
4045 first_recvd_props = B_TRUE;
4048 * If new received properties are supplied, they are to
4049 * completely replace the existing received properties, so stash
4050 * away the existing ones.
4052 if (dsl_prop_get_received(tofs, &origprops) == 0) {
4053 nvlist_t *errlist = NULL;
4055 * Don't bother writing a property if its value won't
4056 * change (and avoid the unnecessary security checks).
4058 * The first receive after SPA_VERSION_RECVD_PROPS is a
4059 * special case where we blow away all local properties
4062 if (!first_recvd_props)
4063 props_reduce(props, origprops);
4064 if (zfs_check_clearable(tofs, origprops, &errlist) != 0)
4065 (void) nvlist_merge(errors, errlist, 0);
4066 nvlist_free(errlist);
4068 if (clear_received_props(tofs, origprops,
4069 first_recvd_props ? NULL : props) != 0)
4070 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
4072 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
4076 if (props != NULL) {
4077 props_error = dsl_prop_set_hasrecvd(tofs);
4079 if (props_error == 0) {
4080 (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
4085 if (zc->zc_nvlist_dst_size != 0 &&
4086 (nvlist_smush(errors, zc->zc_nvlist_dst_size) != 0 ||
4087 put_nvlist(zc, errors) != 0)) {
4089 * Caller made zc->zc_nvlist_dst less than the minimum expected
4090 * size or supplied an invalid address.
4092 props_error = SET_ERROR(EINVAL);
4096 error = dmu_recv_stream(&drc, fp->f_vnode, &off, zc->zc_cleanup_fd,
4097 &zc->zc_action_handle);
4100 zfs_sb_t *zsb = NULL;
4102 if (get_zfs_sb(tofs, &zsb) == 0) {
4106 error = zfs_suspend_fs(zsb);
4108 * If the suspend fails, then the recv_end will
4109 * likely also fail, and clean up after itself.
4111 end_err = dmu_recv_end(&drc, zsb);
4113 error = zfs_resume_fs(zsb, tofs);
4114 error = error ? error : end_err;
4115 deactivate_super(zsb->z_sb);
4117 error = dmu_recv_end(&drc, NULL);
4121 zc->zc_cookie = off - fp->f_offset;
4122 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4126 if (zfs_ioc_recv_inject_err) {
4127 zfs_ioc_recv_inject_err = B_FALSE;
4133 * On error, restore the original props.
4135 if (error != 0 && props != NULL && !drc.drc_newfs) {
4136 if (clear_received_props(tofs, props, NULL) != 0) {
4138 * We failed to clear the received properties.
4139 * Since we may have left a $recvd value on the
4140 * system, we can't clear the $hasrecvd flag.
4142 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4143 } else if (first_recvd_props) {
4144 dsl_prop_unset_hasrecvd(tofs);
4147 if (origprops == NULL && !drc.drc_newfs) {
4148 /* We failed to stash the original properties. */
4149 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4153 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4154 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4155 * explictly if we're restoring local properties cleared in the
4156 * first new-style receive.
4158 if (origprops != NULL &&
4159 zfs_set_prop_nvlist(tofs, (first_recvd_props ?
4160 ZPROP_SRC_LOCAL : ZPROP_SRC_RECEIVED),
4161 origprops, NULL) != 0) {
4163 * We stashed the original properties but failed to
4166 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4171 nvlist_free(origprops);
4172 nvlist_free(errors);
4176 error = props_error;
4183 * zc_name name of snapshot to send
4184 * zc_cookie file descriptor to send stream to
4185 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4186 * zc_sendobj objsetid of snapshot to send
4187 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4188 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4189 * output size in zc_objset_type.
4190 * zc_flags lzc_send_flags
4193 * zc_objset_type estimated size, if zc_guid is set
4196 zfs_ioc_send(zfs_cmd_t *zc)
4200 boolean_t estimate = (zc->zc_guid != 0);
4201 boolean_t embedok = (zc->zc_flags & 0x1);
4202 boolean_t large_block_ok = (zc->zc_flags & 0x2);
4204 if (zc->zc_obj != 0) {
4206 dsl_dataset_t *tosnap;
4208 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4212 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
4214 dsl_pool_rele(dp, FTAG);
4218 if (dsl_dir_is_clone(tosnap->ds_dir))
4220 dsl_dir_phys(tosnap->ds_dir)->dd_origin_obj;
4221 dsl_dataset_rele(tosnap, FTAG);
4222 dsl_pool_rele(dp, FTAG);
4227 dsl_dataset_t *tosnap;
4228 dsl_dataset_t *fromsnap = NULL;
4230 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4234 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
4236 dsl_pool_rele(dp, FTAG);
4240 if (zc->zc_fromobj != 0) {
4241 error = dsl_dataset_hold_obj(dp, zc->zc_fromobj,
4244 dsl_dataset_rele(tosnap, FTAG);
4245 dsl_pool_rele(dp, FTAG);
4250 error = dmu_send_estimate(tosnap, fromsnap,
4251 &zc->zc_objset_type);
4253 if (fromsnap != NULL)
4254 dsl_dataset_rele(fromsnap, FTAG);
4255 dsl_dataset_rele(tosnap, FTAG);
4256 dsl_pool_rele(dp, FTAG);
4258 file_t *fp = getf(zc->zc_cookie);
4260 return (SET_ERROR(EBADF));
4263 error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
4264 zc->zc_fromobj, embedok, large_block_ok,
4265 zc->zc_cookie, fp->f_vnode, &off);
4267 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4269 releasef(zc->zc_cookie);
4276 * zc_name name of snapshot on which to report progress
4277 * zc_cookie file descriptor of send stream
4280 * zc_cookie number of bytes written in send stream thus far
4283 zfs_ioc_send_progress(zfs_cmd_t *zc)
4287 dmu_sendarg_t *dsp = NULL;
4290 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4294 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &ds);
4296 dsl_pool_rele(dp, FTAG);
4300 mutex_enter(&ds->ds_sendstream_lock);
4303 * Iterate over all the send streams currently active on this dataset.
4304 * If there's one which matches the specified file descriptor _and_ the
4305 * stream was started by the current process, return the progress of
4309 for (dsp = list_head(&ds->ds_sendstreams); dsp != NULL;
4310 dsp = list_next(&ds->ds_sendstreams, dsp)) {
4311 if (dsp->dsa_outfd == zc->zc_cookie &&
4312 dsp->dsa_proc->group_leader == curproc->group_leader)
4317 zc->zc_cookie = *(dsp->dsa_off);
4319 error = SET_ERROR(ENOENT);
4321 mutex_exit(&ds->ds_sendstream_lock);
4322 dsl_dataset_rele(ds, FTAG);
4323 dsl_pool_rele(dp, FTAG);
4328 zfs_ioc_inject_fault(zfs_cmd_t *zc)
4332 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
4333 &zc->zc_inject_record);
4336 zc->zc_guid = (uint64_t)id;
4342 zfs_ioc_clear_fault(zfs_cmd_t *zc)
4344 return (zio_clear_fault((int)zc->zc_guid));
4348 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
4350 int id = (int)zc->zc_guid;
4353 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
4354 &zc->zc_inject_record);
4362 zfs_ioc_error_log(zfs_cmd_t *zc)
4366 size_t count = (size_t)zc->zc_nvlist_dst_size;
4368 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
4371 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
4374 zc->zc_nvlist_dst_size = count;
4376 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
4378 spa_close(spa, FTAG);
4384 zfs_ioc_clear(zfs_cmd_t *zc)
4391 * On zpool clear we also fix up missing slogs
4393 mutex_enter(&spa_namespace_lock);
4394 spa = spa_lookup(zc->zc_name);
4396 mutex_exit(&spa_namespace_lock);
4397 return (SET_ERROR(EIO));
4399 if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
4400 /* we need to let spa_open/spa_load clear the chains */
4401 spa_set_log_state(spa, SPA_LOG_CLEAR);
4403 spa->spa_last_open_failed = 0;
4404 mutex_exit(&spa_namespace_lock);
4406 if (zc->zc_cookie & ZPOOL_NO_REWIND) {
4407 error = spa_open(zc->zc_name, &spa, FTAG);
4410 nvlist_t *config = NULL;
4412 if (zc->zc_nvlist_src == 0)
4413 return (SET_ERROR(EINVAL));
4415 if ((error = get_nvlist(zc->zc_nvlist_src,
4416 zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
4417 error = spa_open_rewind(zc->zc_name, &spa, FTAG,
4419 if (config != NULL) {
4422 if ((err = put_nvlist(zc, config)) != 0)
4424 nvlist_free(config);
4426 nvlist_free(policy);
4433 spa_vdev_state_enter(spa, SCL_NONE);
4435 if (zc->zc_guid == 0) {
4438 vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
4440 (void) spa_vdev_state_exit(spa, NULL, ENODEV);
4441 spa_close(spa, FTAG);
4442 return (SET_ERROR(ENODEV));
4446 vdev_clear(spa, vd);
4448 (void) spa_vdev_state_exit(spa, NULL, 0);
4451 * Resume any suspended I/Os.
4453 if (zio_resume(spa) != 0)
4454 error = SET_ERROR(EIO);
4456 spa_close(spa, FTAG);
4462 zfs_ioc_pool_reopen(zfs_cmd_t *zc)
4467 error = spa_open(zc->zc_name, &spa, FTAG);
4471 spa_vdev_state_enter(spa, SCL_NONE);
4474 * If a resilver is already in progress then set the
4475 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4476 * the scan as a side effect of the reopen. Otherwise, let
4477 * vdev_open() decided if a resilver is required.
4479 spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
4480 vdev_reopen(spa->spa_root_vdev);
4481 spa->spa_scrub_reopen = B_FALSE;
4483 (void) spa_vdev_state_exit(spa, NULL, 0);
4484 spa_close(spa, FTAG);
4489 * zc_name name of filesystem
4490 * zc_value name of origin snapshot
4493 * zc_string name of conflicting snapshot, if there is one
4496 zfs_ioc_promote(zfs_cmd_t *zc)
4501 * We don't need to unmount *all* the origin fs's snapshots, but
4504 cp = strchr(zc->zc_value, '@');
4507 (void) dmu_objset_find(zc->zc_value,
4508 zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
4509 return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
4513 * Retrieve a single {user|group}{used|quota}@... property.
4516 * zc_name name of filesystem
4517 * zc_objset_type zfs_userquota_prop_t
4518 * zc_value domain name (eg. "S-1-234-567-89")
4519 * zc_guid RID/UID/GID
4522 * zc_cookie property value
4525 zfs_ioc_userspace_one(zfs_cmd_t *zc)
4530 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
4531 return (SET_ERROR(EINVAL));
4533 error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
4537 error = zfs_userspace_one(zsb,
4538 zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
4539 zfs_sb_rele(zsb, FTAG);
4546 * zc_name name of filesystem
4547 * zc_cookie zap cursor
4548 * zc_objset_type zfs_userquota_prop_t
4549 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4552 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4553 * zc_cookie zap cursor
4556 zfs_ioc_userspace_many(zfs_cmd_t *zc)
4559 int bufsize = zc->zc_nvlist_dst_size;
4564 return (SET_ERROR(ENOMEM));
4566 error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
4570 buf = vmem_alloc(bufsize, KM_SLEEP);
4572 error = zfs_userspace_many(zsb, zc->zc_objset_type, &zc->zc_cookie,
4573 buf, &zc->zc_nvlist_dst_size);
4576 error = xcopyout(buf,
4577 (void *)(uintptr_t)zc->zc_nvlist_dst,
4578 zc->zc_nvlist_dst_size);
4580 vmem_free(buf, bufsize);
4581 zfs_sb_rele(zsb, FTAG);
4588 * zc_name name of filesystem
4594 zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
4600 if (get_zfs_sb(zc->zc_name, &zsb) == 0) {
4601 if (!dmu_objset_userused_enabled(zsb->z_os)) {
4603 * If userused is not enabled, it may be because the
4604 * objset needs to be closed & reopened (to grow the
4605 * objset_phys_t). Suspend/resume the fs will do that.
4607 error = zfs_suspend_fs(zsb);
4609 dmu_objset_refresh_ownership(zsb->z_os,
4611 error = zfs_resume_fs(zsb, zc->zc_name);
4615 error = dmu_objset_userspace_upgrade(zsb->z_os);
4616 deactivate_super(zsb->z_sb);
4618 /* XXX kind of reading contents without owning */
4619 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
4623 error = dmu_objset_userspace_upgrade(os);
4624 dmu_objset_rele(os, FTAG);
4631 zfs_ioc_share(zfs_cmd_t *zc)
4633 return (SET_ERROR(ENOSYS));
4636 ace_t full_access[] = {
4637 {(uid_t)-1, ACE_ALL_PERMS, ACE_EVERYONE, 0}
4642 * zc_name name of containing filesystem
4643 * zc_obj object # beyond which we want next in-use object #
4646 * zc_obj next in-use object #
4649 zfs_ioc_next_obj(zfs_cmd_t *zc)
4651 objset_t *os = NULL;
4654 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
4658 error = dmu_object_next(os, &zc->zc_obj, B_FALSE, 0);
4660 dmu_objset_rele(os, FTAG);
4666 * zc_name name of filesystem
4667 * zc_value prefix name for snapshot
4668 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4671 * zc_value short name of new snapshot
4674 zfs_ioc_tmp_snapshot(zfs_cmd_t *zc)
4681 error = zfs_onexit_fd_hold(zc->zc_cleanup_fd, &minor);
4685 snap_name = kmem_asprintf("%s-%016llx", zc->zc_value,
4686 (u_longlong_t)ddi_get_lbolt64());
4687 hold_name = kmem_asprintf("%%%s", zc->zc_value);
4689 error = dsl_dataset_snapshot_tmp(zc->zc_name, snap_name, minor,
4692 (void) strcpy(zc->zc_value, snap_name);
4695 zfs_onexit_fd_rele(zc->zc_cleanup_fd);
4701 * zc_name name of "to" snapshot
4702 * zc_value name of "from" snapshot
4703 * zc_cookie file descriptor to write diff data on
4706 * dmu_diff_record_t's to the file descriptor
4709 zfs_ioc_diff(zfs_cmd_t *zc)
4715 fp = getf(zc->zc_cookie);
4717 return (SET_ERROR(EBADF));
4721 error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off);
4723 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4725 releasef(zc->zc_cookie);
4731 * Remove all ACL files in shares dir
4733 #ifdef HAVE_SMB_SHARE
4735 zfs_smb_acl_purge(znode_t *dzp)
4738 zap_attribute_t zap;
4739 zfs_sb_t *zsb = ZTOZSB(dzp);
4742 for (zap_cursor_init(&zc, zsb->z_os, dzp->z_id);
4743 (error = zap_cursor_retrieve(&zc, &zap)) == 0;
4744 zap_cursor_advance(&zc)) {
4745 if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
4749 zap_cursor_fini(&zc);
4752 #endif /* HAVE_SMB_SHARE */
4755 zfs_ioc_smb_acl(zfs_cmd_t *zc)
4757 #ifdef HAVE_SMB_SHARE
4760 vnode_t *resourcevp = NULL;
4769 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
4770 NO_FOLLOW, NULL, &vp)) != 0)
4773 /* Now make sure mntpnt and dataset are ZFS */
4775 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
4776 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
4777 zc->zc_name) != 0)) {
4779 return (SET_ERROR(EINVAL));
4787 * Create share dir if its missing.
4789 mutex_enter(&zsb->z_lock);
4790 if (zsb->z_shares_dir == 0) {
4793 tx = dmu_tx_create(zsb->z_os);
4794 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
4796 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
4797 error = dmu_tx_assign(tx, TXG_WAIT);
4801 error = zfs_create_share_dir(zsb, tx);
4805 mutex_exit(&zsb->z_lock);
4811 mutex_exit(&zsb->z_lock);
4813 ASSERT(zsb->z_shares_dir);
4814 if ((error = zfs_zget(zsb, zsb->z_shares_dir, &sharedir)) != 0) {
4820 switch (zc->zc_cookie) {
4821 case ZFS_SMB_ACL_ADD:
4822 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
4823 vattr.va_mode = S_IFREG|0777;
4827 vsec.vsa_mask = VSA_ACE;
4828 vsec.vsa_aclentp = &full_access;
4829 vsec.vsa_aclentsz = sizeof (full_access);
4830 vsec.vsa_aclcnt = 1;
4832 error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
4833 &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
4835 VN_RELE(resourcevp);
4838 case ZFS_SMB_ACL_REMOVE:
4839 error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
4843 case ZFS_SMB_ACL_RENAME:
4844 if ((error = get_nvlist(zc->zc_nvlist_src,
4845 zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
4847 VN_RELE(ZTOV(sharedir));
4851 if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
4852 nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
4855 VN_RELE(ZTOV(sharedir));
4857 nvlist_free(nvlist);
4860 error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
4862 nvlist_free(nvlist);
4865 case ZFS_SMB_ACL_PURGE:
4866 error = zfs_smb_acl_purge(sharedir);
4870 error = SET_ERROR(EINVAL);
4875 VN_RELE(ZTOV(sharedir));
4881 return (SET_ERROR(ENOTSUP));
4882 #endif /* HAVE_SMB_SHARE */
4887 * "holds" -> { snapname -> holdname (string), ... }
4888 * (optional) "cleanup_fd" -> fd (int32)
4892 * snapname -> error value (int32)
4898 zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
4902 int cleanup_fd = -1;
4906 error = nvlist_lookup_nvlist(args, "holds", &holds);
4908 return (SET_ERROR(EINVAL));
4910 /* make sure the user didn't pass us any invalid (empty) tags */
4911 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
4912 pair = nvlist_next_nvpair(holds, pair)) {
4915 error = nvpair_value_string(pair, &htag);
4917 return (SET_ERROR(error));
4919 if (strlen(htag) == 0)
4920 return (SET_ERROR(EINVAL));
4923 if (nvlist_lookup_int32(args, "cleanup_fd", &cleanup_fd) == 0) {
4924 error = zfs_onexit_fd_hold(cleanup_fd, &minor);
4929 error = dsl_dataset_user_hold(holds, minor, errlist);
4931 zfs_onexit_fd_rele(cleanup_fd);
4936 * innvl is not used.
4939 * holdname -> time added (uint64 seconds since epoch)
4945 zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
4947 return (dsl_dataset_get_holds(snapname, outnvl));
4952 * snapname -> { holdname, ... }
4957 * snapname -> error value (int32)
4963 zfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
4965 return (dsl_dataset_user_release(holds, errlist));
4970 * zc_guid flags (ZEVENT_NONBLOCK)
4971 * zc_cleanup_fd zevent file descriptor
4974 * zc_nvlist_dst next nvlist event
4975 * zc_cookie dropped events since last get
4978 zfs_ioc_events_next(zfs_cmd_t *zc)
4981 nvlist_t *event = NULL;
4983 uint64_t dropped = 0;
4986 error = zfs_zevent_fd_hold(zc->zc_cleanup_fd, &minor, &ze);
4991 error = zfs_zevent_next(ze, &event,
4992 &zc->zc_nvlist_dst_size, &dropped);
4993 if (event != NULL) {
4994 zc->zc_cookie = dropped;
4995 error = put_nvlist(zc, event);
4999 if (zc->zc_guid & ZEVENT_NONBLOCK)
5002 if ((error == 0) || (error != ENOENT))
5005 error = zfs_zevent_wait(ze);
5010 zfs_zevent_fd_rele(zc->zc_cleanup_fd);
5017 * zc_cookie cleared events count
5020 zfs_ioc_events_clear(zfs_cmd_t *zc)
5024 zfs_zevent_drain_all(&count);
5025 zc->zc_cookie = count;
5032 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5033 * zc_cleanup zevent file descriptor
5036 zfs_ioc_events_seek(zfs_cmd_t *zc)
5042 error = zfs_zevent_fd_hold(zc->zc_cleanup_fd, &minor, &ze);
5046 error = zfs_zevent_seek(ze, zc->zc_guid);
5047 zfs_zevent_fd_rele(zc->zc_cleanup_fd);
5054 * zc_name name of new filesystem or snapshot
5055 * zc_value full name of old snapshot
5058 * zc_cookie space in bytes
5059 * zc_objset_type compressed space in bytes
5060 * zc_perm_action uncompressed space in bytes
5063 zfs_ioc_space_written(zfs_cmd_t *zc)
5067 dsl_dataset_t *new, *old;
5069 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
5072 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &new);
5074 dsl_pool_rele(dp, FTAG);
5077 error = dsl_dataset_hold(dp, zc->zc_value, FTAG, &old);
5079 dsl_dataset_rele(new, FTAG);
5080 dsl_pool_rele(dp, FTAG);
5084 error = dsl_dataset_space_written(old, new, &zc->zc_cookie,
5085 &zc->zc_objset_type, &zc->zc_perm_action);
5086 dsl_dataset_rele(old, FTAG);
5087 dsl_dataset_rele(new, FTAG);
5088 dsl_pool_rele(dp, FTAG);
5094 * "firstsnap" -> snapshot name
5098 * "used" -> space in bytes
5099 * "compressed" -> compressed space in bytes
5100 * "uncompressed" -> uncompressed space in bytes
5104 zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
5108 dsl_dataset_t *new, *old;
5110 uint64_t used, comp, uncomp;
5112 if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
5113 return (SET_ERROR(EINVAL));
5115 error = dsl_pool_hold(lastsnap, FTAG, &dp);
5119 error = dsl_dataset_hold(dp, lastsnap, FTAG, &new);
5120 if (error == 0 && !new->ds_is_snapshot) {
5121 dsl_dataset_rele(new, FTAG);
5122 error = SET_ERROR(EINVAL);
5125 dsl_pool_rele(dp, FTAG);
5128 error = dsl_dataset_hold(dp, firstsnap, FTAG, &old);
5129 if (error == 0 && !old->ds_is_snapshot) {
5130 dsl_dataset_rele(old, FTAG);
5131 error = SET_ERROR(EINVAL);
5134 dsl_dataset_rele(new, FTAG);
5135 dsl_pool_rele(dp, FTAG);
5139 error = dsl_dataset_space_wouldfree(old, new, &used, &comp, &uncomp);
5140 dsl_dataset_rele(old, FTAG);
5141 dsl_dataset_rele(new, FTAG);
5142 dsl_pool_rele(dp, FTAG);
5143 fnvlist_add_uint64(outnvl, "used", used);
5144 fnvlist_add_uint64(outnvl, "compressed", comp);
5145 fnvlist_add_uint64(outnvl, "uncompressed", uncomp);
5151 * "fd" -> file descriptor to write stream to (int32)
5152 * (optional) "fromsnap" -> full snap name to send an incremental from
5153 * (optional) "largeblockok" -> (value ignored)
5154 * indicates that blocks > 128KB are permitted
5155 * (optional) "embedok" -> (value ignored)
5156 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5163 zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5167 char *fromname = NULL;
5170 boolean_t largeblockok;
5173 error = nvlist_lookup_int32(innvl, "fd", &fd);
5175 return (SET_ERROR(EINVAL));
5177 (void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
5179 largeblockok = nvlist_exists(innvl, "largeblockok");
5180 embedok = nvlist_exists(innvl, "embedok");
5182 if ((fp = getf(fd)) == NULL)
5183 return (SET_ERROR(EBADF));
5186 error = dmu_send(snapname, fromname, embedok, largeblockok,
5187 fd, fp->f_vnode, &off);
5189 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
5197 * Determine approximately how large a zfs send stream will be -- the number
5198 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5201 * (optional) "from" -> full snap or bookmark name to send an incremental
5206 * "space" -> bytes of space (uint64)
5210 zfs_ioc_send_space(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5213 dsl_dataset_t *tosnap;
5218 error = dsl_pool_hold(snapname, FTAG, &dp);
5222 error = dsl_dataset_hold(dp, snapname, FTAG, &tosnap);
5224 dsl_pool_rele(dp, FTAG);
5228 error = nvlist_lookup_string(innvl, "from", &fromname);
5230 if (strchr(fromname, '@') != NULL) {
5232 * If from is a snapshot, hold it and use the more
5233 * efficient dmu_send_estimate to estimate send space
5234 * size using deadlists.
5236 dsl_dataset_t *fromsnap;
5237 error = dsl_dataset_hold(dp, fromname, FTAG, &fromsnap);
5240 error = dmu_send_estimate(tosnap, fromsnap, &space);
5241 dsl_dataset_rele(fromsnap, FTAG);
5242 } else if (strchr(fromname, '#') != NULL) {
5244 * If from is a bookmark, fetch the creation TXG of the
5245 * snapshot it was created from and use that to find
5246 * blocks that were born after it.
5248 zfs_bookmark_phys_t frombm;
5250 error = dsl_bookmark_lookup(dp, fromname, tosnap,
5254 error = dmu_send_estimate_from_txg(tosnap,
5255 frombm.zbm_creation_txg, &space);
5258 * from is not properly formatted as a snapshot or
5261 error = SET_ERROR(EINVAL);
5265 // If estimating the size of a full send, use dmu_send_estimate
5266 error = dmu_send_estimate(tosnap, NULL, &space);
5269 fnvlist_add_uint64(outnvl, "space", space);
5272 dsl_dataset_rele(tosnap, FTAG);
5273 dsl_pool_rele(dp, FTAG);
5277 static zfs_ioc_vec_t zfs_ioc_vec[ZFS_IOC_LAST - ZFS_IOC_FIRST];
5280 zfs_ioctl_register_legacy(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5281 zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
5282 boolean_t log_history, zfs_ioc_poolcheck_t pool_check)
5284 zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
5286 ASSERT3U(ioc, >=, ZFS_IOC_FIRST);
5287 ASSERT3U(ioc, <, ZFS_IOC_LAST);
5288 ASSERT3P(vec->zvec_legacy_func, ==, NULL);
5289 ASSERT3P(vec->zvec_func, ==, NULL);
5291 vec->zvec_legacy_func = func;
5292 vec->zvec_secpolicy = secpolicy;
5293 vec->zvec_namecheck = namecheck;
5294 vec->zvec_allow_log = log_history;
5295 vec->zvec_pool_check = pool_check;
5299 * See the block comment at the beginning of this file for details on
5300 * each argument to this function.
5303 zfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
5304 zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
5305 zfs_ioc_poolcheck_t pool_check, boolean_t smush_outnvlist,
5306 boolean_t allow_log)
5308 zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
5310 ASSERT3U(ioc, >=, ZFS_IOC_FIRST);
5311 ASSERT3U(ioc, <, ZFS_IOC_LAST);
5312 ASSERT3P(vec->zvec_legacy_func, ==, NULL);
5313 ASSERT3P(vec->zvec_func, ==, NULL);
5315 /* if we are logging, the name must be valid */
5316 ASSERT(!allow_log || namecheck != NO_NAME);
5318 vec->zvec_name = name;
5319 vec->zvec_func = func;
5320 vec->zvec_secpolicy = secpolicy;
5321 vec->zvec_namecheck = namecheck;
5322 vec->zvec_pool_check = pool_check;
5323 vec->zvec_smush_outnvlist = smush_outnvlist;
5324 vec->zvec_allow_log = allow_log;
5328 zfs_ioctl_register_pool(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5329 zfs_secpolicy_func_t *secpolicy, boolean_t log_history,
5330 zfs_ioc_poolcheck_t pool_check)
5332 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5333 POOL_NAME, log_history, pool_check);
5337 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5338 zfs_secpolicy_func_t *secpolicy, zfs_ioc_poolcheck_t pool_check)
5340 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5341 DATASET_NAME, B_FALSE, pool_check);
5345 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
5347 zfs_ioctl_register_legacy(ioc, func, zfs_secpolicy_config,
5348 POOL_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5352 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5353 zfs_secpolicy_func_t *secpolicy)
5355 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5356 NO_NAME, B_FALSE, POOL_CHECK_NONE);
5360 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc,
5361 zfs_ioc_legacy_func_t *func, zfs_secpolicy_func_t *secpolicy)
5363 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5364 DATASET_NAME, B_FALSE, POOL_CHECK_SUSPENDED);
5368 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
5370 zfs_ioctl_register_dataset_read_secpolicy(ioc, func,
5371 zfs_secpolicy_read);
5375 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5376 zfs_secpolicy_func_t *secpolicy)
5378 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5379 DATASET_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5383 zfs_ioctl_init(void)
5385 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT,
5386 zfs_ioc_snapshot, zfs_secpolicy_snapshot, POOL_NAME,
5387 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5389 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY,
5390 zfs_ioc_log_history, zfs_secpolicy_log_history, NO_NAME,
5391 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
5393 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS,
5394 zfs_ioc_space_snaps, zfs_secpolicy_read, DATASET_NAME,
5395 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5397 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW,
5398 zfs_ioc_send_new, zfs_secpolicy_send_new, DATASET_NAME,
5399 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5401 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE,
5402 zfs_ioc_send_space, zfs_secpolicy_read, DATASET_NAME,
5403 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5405 zfs_ioctl_register("create", ZFS_IOC_CREATE,
5406 zfs_ioc_create, zfs_secpolicy_create_clone, DATASET_NAME,
5407 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5409 zfs_ioctl_register("clone", ZFS_IOC_CLONE,
5410 zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
5411 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5413 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
5414 zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
5415 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5417 zfs_ioctl_register("hold", ZFS_IOC_HOLD,
5418 zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
5419 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5420 zfs_ioctl_register("release", ZFS_IOC_RELEASE,
5421 zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
5422 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5424 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
5425 zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
5426 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5428 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
5429 zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
5430 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
5432 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK,
5433 zfs_ioc_bookmark, zfs_secpolicy_bookmark, POOL_NAME,
5434 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5436 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS,
5437 zfs_ioc_get_bookmarks, zfs_secpolicy_read, DATASET_NAME,
5438 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5440 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS,
5441 zfs_ioc_destroy_bookmarks, zfs_secpolicy_destroy_bookmarks,
5443 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5445 /* IOCTLS that use the legacy function signature */
5447 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
5448 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_READONLY);
5450 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE, zfs_ioc_pool_create,
5451 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5452 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN,
5454 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE,
5455 zfs_ioc_pool_upgrade);
5456 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD,
5458 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE,
5459 zfs_ioc_vdev_remove);
5460 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE,
5461 zfs_ioc_vdev_set_state);
5462 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH,
5463 zfs_ioc_vdev_attach);
5464 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH,
5465 zfs_ioc_vdev_detach);
5466 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH,
5467 zfs_ioc_vdev_setpath);
5468 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU,
5469 zfs_ioc_vdev_setfru);
5470 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS,
5471 zfs_ioc_pool_set_props);
5472 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT,
5473 zfs_ioc_vdev_split);
5474 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID,
5475 zfs_ioc_pool_reguid);
5477 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS,
5478 zfs_ioc_pool_configs, zfs_secpolicy_none);
5479 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT,
5480 zfs_ioc_pool_tryimport, zfs_secpolicy_config);
5481 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT,
5482 zfs_ioc_inject_fault, zfs_secpolicy_inject);
5483 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT,
5484 zfs_ioc_clear_fault, zfs_secpolicy_inject);
5485 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT,
5486 zfs_ioc_inject_list_next, zfs_secpolicy_inject);
5489 * pool destroy, and export don't log the history as part of
5490 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5491 * does the logging of those commands.
5493 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY, zfs_ioc_pool_destroy,
5494 zfs_secpolicy_config, B_FALSE, POOL_CHECK_SUSPENDED);
5495 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT, zfs_ioc_pool_export,
5496 zfs_secpolicy_config, B_FALSE, POOL_CHECK_SUSPENDED);
5498 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS, zfs_ioc_pool_stats,
5499 zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
5500 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS, zfs_ioc_pool_get_props,
5501 zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
5503 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG, zfs_ioc_error_log,
5504 zfs_secpolicy_inject, B_FALSE, POOL_CHECK_SUSPENDED);
5505 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME,
5506 zfs_ioc_dsobj_to_dsname,
5507 zfs_secpolicy_diff, B_FALSE, POOL_CHECK_SUSPENDED);
5508 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY,
5509 zfs_ioc_pool_get_history,
5510 zfs_secpolicy_config, B_FALSE, POOL_CHECK_SUSPENDED);
5512 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT, zfs_ioc_pool_import,
5513 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5515 zfs_ioctl_register_pool(ZFS_IOC_CLEAR, zfs_ioc_clear,
5516 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5517 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
5518 zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
5520 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN,
5521 zfs_ioc_space_written);
5522 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS,
5523 zfs_ioc_objset_recvd_props);
5524 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ,
5526 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL,
5528 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS,
5529 zfs_ioc_objset_stats);
5530 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS,
5531 zfs_ioc_objset_zplprops);
5532 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT,
5533 zfs_ioc_dataset_list_next);
5534 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT,
5535 zfs_ioc_snapshot_list_next);
5536 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS,
5537 zfs_ioc_send_progress);
5539 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF,
5540 zfs_ioc_diff, zfs_secpolicy_diff);
5541 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS,
5542 zfs_ioc_obj_to_stats, zfs_secpolicy_diff);
5543 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH,
5544 zfs_ioc_obj_to_path, zfs_secpolicy_diff);
5545 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE,
5546 zfs_ioc_userspace_one, zfs_secpolicy_userspace_one);
5547 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY,
5548 zfs_ioc_userspace_many, zfs_secpolicy_userspace_many);
5549 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND,
5550 zfs_ioc_send, zfs_secpolicy_send);
5552 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP, zfs_ioc_set_prop,
5553 zfs_secpolicy_none);
5554 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
5555 zfs_secpolicy_destroy);
5556 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
5557 zfs_secpolicy_rename);
5558 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
5559 zfs_secpolicy_recv);
5560 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE, zfs_ioc_promote,
5561 zfs_secpolicy_promote);
5562 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP,
5563 zfs_ioc_inherit_prop, zfs_secpolicy_inherit_prop);
5564 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL, zfs_ioc_set_fsacl,
5565 zfs_secpolicy_set_fsacl);
5567 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE, zfs_ioc_share,
5568 zfs_secpolicy_share, POOL_CHECK_NONE);
5569 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL, zfs_ioc_smb_acl,
5570 zfs_secpolicy_smb_acl, POOL_CHECK_NONE);
5571 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE,
5572 zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
5573 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5574 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT,
5575 zfs_ioc_tmp_snapshot, zfs_secpolicy_tmp_snapshot,
5576 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5581 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT, zfs_ioc_events_next,
5582 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
5583 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR, zfs_ioc_events_clear,
5584 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
5585 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK, zfs_ioc_events_seek,
5586 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
5590 pool_status_check(const char *name, zfs_ioc_namecheck_t type,
5591 zfs_ioc_poolcheck_t check)
5596 ASSERT(type == POOL_NAME || type == DATASET_NAME);
5598 if (check & POOL_CHECK_NONE)
5601 error = spa_open(name, &spa, FTAG);
5603 if ((check & POOL_CHECK_SUSPENDED) && spa_suspended(spa))
5604 error = SET_ERROR(EAGAIN);
5605 else if ((check & POOL_CHECK_READONLY) && !spa_writeable(spa))
5606 error = SET_ERROR(EROFS);
5607 spa_close(spa, FTAG);
5613 zfsdev_get_state_impl(minor_t minor, enum zfsdev_state_type which)
5617 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
5618 if (zs->zs_minor == minor) {
5622 return (zs->zs_onexit);
5624 return (zs->zs_zevent);
5635 zfsdev_get_state(minor_t minor, enum zfsdev_state_type which)
5639 ptr = zfsdev_get_state_impl(minor, which);
5645 zfsdev_getminor(struct file *filp, minor_t *minorp)
5647 zfsdev_state_t *zs, *fpd;
5649 ASSERT(filp != NULL);
5650 ASSERT(!MUTEX_HELD(&zfsdev_state_lock));
5652 fpd = filp->private_data;
5656 mutex_enter(&zfsdev_state_lock);
5658 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
5660 if (zs->zs_minor == -1)
5664 *minorp = fpd->zs_minor;
5665 mutex_exit(&zfsdev_state_lock);
5670 mutex_exit(&zfsdev_state_lock);
5676 * Find a free minor number. The zfsdev_state_list is expected to
5677 * be short since it is only a list of currently open file handles.
5680 zfsdev_minor_alloc(void)
5682 static minor_t last_minor = 0;
5685 ASSERT(MUTEX_HELD(&zfsdev_state_lock));
5687 for (m = last_minor + 1; m != last_minor; m++) {
5688 if (m > ZFSDEV_MAX_MINOR)
5690 if (zfsdev_get_state_impl(m, ZST_ALL) == NULL) {
5700 zfsdev_state_init(struct file *filp)
5702 zfsdev_state_t *zs, *zsprev = NULL;
5704 boolean_t newzs = B_FALSE;
5706 ASSERT(MUTEX_HELD(&zfsdev_state_lock));
5708 minor = zfsdev_minor_alloc();
5710 return (SET_ERROR(ENXIO));
5712 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
5713 if (zs->zs_minor == -1)
5719 zs = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
5724 filp->private_data = zs;
5726 zfs_onexit_init((zfs_onexit_t **)&zs->zs_onexit);
5727 zfs_zevent_init((zfs_zevent_t **)&zs->zs_zevent);
5731 * In order to provide for lock-free concurrent read access
5732 * to the minor list in zfsdev_get_state_impl(), new entries
5733 * must be completely written before linking them into the
5734 * list whereas existing entries are already linked; the last
5735 * operation must be updating zs_minor (from -1 to the new
5739 zs->zs_minor = minor;
5741 zsprev->zs_next = zs;
5744 zs->zs_minor = minor;
5751 zfsdev_state_destroy(struct file *filp)
5755 ASSERT(MUTEX_HELD(&zfsdev_state_lock));
5756 ASSERT(filp->private_data != NULL);
5758 zs = filp->private_data;
5760 zfs_onexit_destroy(zs->zs_onexit);
5761 zfs_zevent_destroy(zs->zs_zevent);
5767 zfsdev_open(struct inode *ino, struct file *filp)
5771 mutex_enter(&zfsdev_state_lock);
5772 error = zfsdev_state_init(filp);
5773 mutex_exit(&zfsdev_state_lock);
5779 zfsdev_release(struct inode *ino, struct file *filp)
5783 mutex_enter(&zfsdev_state_lock);
5784 error = zfsdev_state_destroy(filp);
5785 mutex_exit(&zfsdev_state_lock);
5791 zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
5795 int error, rc, flag = 0;
5796 const zfs_ioc_vec_t *vec;
5797 char *saved_poolname = NULL;
5798 nvlist_t *innvl = NULL;
5799 fstrans_cookie_t cookie;
5801 vecnum = cmd - ZFS_IOC_FIRST;
5802 if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
5803 return (-SET_ERROR(EINVAL));
5804 vec = &zfs_ioc_vec[vecnum];
5807 * The registered ioctl list may be sparse, verify that either
5808 * a normal or legacy handler are registered.
5810 if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL)
5811 return (-SET_ERROR(EINVAL));
5813 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
5815 error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
5817 error = SET_ERROR(EFAULT);
5821 zc->zc_iflags = flag & FKIOCTL;
5822 if (zc->zc_nvlist_src_size > MAX_NVLIST_SRC_SIZE) {
5824 * Make sure the user doesn't pass in an insane value for
5825 * zc_nvlist_src_size. We have to check, since we will end
5826 * up allocating that much memory inside of get_nvlist(). This
5827 * prevents a nefarious user from allocating tons of kernel
5830 * Also, we return EINVAL instead of ENOMEM here. The reason
5831 * being that returning ENOMEM from an ioctl() has a special
5832 * connotation; that the user's size value is too small and
5833 * needs to be expanded to hold the nvlist. See
5834 * zcmd_expand_dst_nvlist() for details.
5836 error = SET_ERROR(EINVAL); /* User's size too big */
5838 } else if (zc->zc_nvlist_src_size != 0) {
5839 error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
5840 zc->zc_iflags, &innvl);
5846 * Ensure that all pool/dataset names are valid before we pass down to
5849 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
5850 switch (vec->zvec_namecheck) {
5852 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
5853 error = SET_ERROR(EINVAL);
5855 error = pool_status_check(zc->zc_name,
5856 vec->zvec_namecheck, vec->zvec_pool_check);
5860 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
5861 error = SET_ERROR(EINVAL);
5863 error = pool_status_check(zc->zc_name,
5864 vec->zvec_namecheck, vec->zvec_pool_check);
5872 if (error == 0 && !(flag & FKIOCTL)) {
5873 cookie = spl_fstrans_mark();
5874 error = vec->zvec_secpolicy(zc, innvl, CRED());
5875 spl_fstrans_unmark(cookie);
5881 /* legacy ioctls can modify zc_name */
5882 saved_poolname = strdup(zc->zc_name);
5883 if (saved_poolname == NULL) {
5884 error = SET_ERROR(ENOMEM);
5887 saved_poolname[strcspn(saved_poolname, "/@#")] = '\0';
5890 if (vec->zvec_func != NULL) {
5894 nvlist_t *lognv = NULL;
5896 ASSERT(vec->zvec_legacy_func == NULL);
5899 * Add the innvl to the lognv before calling the func,
5900 * in case the func changes the innvl.
5902 if (vec->zvec_allow_log) {
5903 lognv = fnvlist_alloc();
5904 fnvlist_add_string(lognv, ZPOOL_HIST_IOCTL,
5906 if (!nvlist_empty(innvl)) {
5907 fnvlist_add_nvlist(lognv, ZPOOL_HIST_INPUT_NVL,
5912 outnvl = fnvlist_alloc();
5913 cookie = spl_fstrans_mark();
5914 error = vec->zvec_func(zc->zc_name, innvl, outnvl);
5915 spl_fstrans_unmark(cookie);
5917 if (error == 0 && vec->zvec_allow_log &&
5918 spa_open(zc->zc_name, &spa, FTAG) == 0) {
5919 if (!nvlist_empty(outnvl)) {
5920 fnvlist_add_nvlist(lognv, ZPOOL_HIST_OUTPUT_NVL,
5923 (void) spa_history_log_nvl(spa, lognv);
5924 spa_close(spa, FTAG);
5926 fnvlist_free(lognv);
5928 if (!nvlist_empty(outnvl) || zc->zc_nvlist_dst_size != 0) {
5930 if (vec->zvec_smush_outnvlist) {
5931 smusherror = nvlist_smush(outnvl,
5932 zc->zc_nvlist_dst_size);
5934 if (smusherror == 0)
5935 puterror = put_nvlist(zc, outnvl);
5941 nvlist_free(outnvl);
5943 cookie = spl_fstrans_mark();
5944 error = vec->zvec_legacy_func(zc);
5945 spl_fstrans_unmark(cookie);
5950 rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
5951 if (error == 0 && rc != 0)
5952 error = SET_ERROR(EFAULT);
5953 if (error == 0 && vec->zvec_allow_log) {
5954 char *s = tsd_get(zfs_allow_log_key);
5957 (void) tsd_set(zfs_allow_log_key, saved_poolname);
5959 if (saved_poolname != NULL)
5960 strfree(saved_poolname);
5963 kmem_free(zc, sizeof (zfs_cmd_t));
5967 #ifdef CONFIG_COMPAT
5969 zfsdev_compat_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
5971 return (zfsdev_ioctl(filp, cmd, arg));
5974 #define zfsdev_compat_ioctl NULL
5977 static const struct file_operations zfsdev_fops = {
5978 .open = zfsdev_open,
5979 .release = zfsdev_release,
5980 .unlocked_ioctl = zfsdev_ioctl,
5981 .compat_ioctl = zfsdev_compat_ioctl,
5982 .owner = THIS_MODULE,
5985 static struct miscdevice zfs_misc = {
5986 .minor = MISC_DYNAMIC_MINOR,
5988 .fops = &zfsdev_fops,
5996 mutex_init(&zfsdev_state_lock, NULL, MUTEX_DEFAULT, NULL);
5997 zfsdev_state_list = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
5998 zfsdev_state_list->zs_minor = -1;
6000 error = misc_register(&zfs_misc);
6002 printk(KERN_INFO "ZFS: misc_register() failed %d\n", error);
6012 zfsdev_state_t *zs, *zsprev = NULL;
6014 misc_deregister(&zfs_misc);
6015 mutex_destroy(&zfsdev_state_lock);
6017 for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
6019 kmem_free(zsprev, sizeof (zfsdev_state_t));
6023 kmem_free(zsprev, sizeof (zfsdev_state_t));
6027 zfs_allow_log_destroy(void *arg)
6029 char *poolname = arg;
6034 #define ZFS_DEBUG_STR " (DEBUG mode)"
6036 #define ZFS_DEBUG_STR ""
6044 error = -vn_set_pwd("/");
6047 "ZFS: Warning unable to set pwd to '/': %d\n", error);
6051 if ((error = -zvol_init()) != 0)
6054 spa_init(FREAD | FWRITE);
6059 if ((error = zfs_attach()) != 0)
6062 tsd_create(&zfs_fsyncer_key, NULL);
6063 tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
6064 tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy);
6066 printk(KERN_NOTICE "ZFS: Loaded module v%s-%s%s, "
6067 "ZFS pool version %s, ZFS filesystem version %s\n",
6068 ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR,
6069 SPA_VERSION_STRING, ZPL_VERSION_STRING);
6070 #ifndef CONFIG_FS_POSIX_ACL
6071 printk(KERN_NOTICE "ZFS: Posix ACLs disabled by kernel\n");
6072 #endif /* CONFIG_FS_POSIX_ACL */
6080 printk(KERN_NOTICE "ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
6081 ", rc = %d\n", ZFS_META_VERSION, ZFS_META_RELEASE,
6082 ZFS_DEBUG_STR, error);
6095 tsd_destroy(&zfs_fsyncer_key);
6096 tsd_destroy(&rrw_tsd_key);
6097 tsd_destroy(&zfs_allow_log_key);
6099 printk(KERN_NOTICE "ZFS: Unloaded module v%s-%s%s\n",
6100 ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR);
6107 MODULE_DESCRIPTION("ZFS");
6108 MODULE_AUTHOR(ZFS_META_AUTHOR);
6109 MODULE_LICENSE(ZFS_META_LICENSE);
6110 MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
6111 #endif /* HAVE_SPL */