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 * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
25 * Copyright 2013 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
26 * Copyright 2014 Xin Li <delphij@FreeBSD.org>. All rights reserved.
27 * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
28 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
29 * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
30 * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
31 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
32 * Copyright (c) 2013 Steven Hartland. All rights reserved.
33 * Copyright (c) 2014 Integros [integros.com]
39 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
40 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
42 * There are two ways that we handle ioctls: the legacy way where almost
43 * all of the logic is in the ioctl callback, and the new way where most
44 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
46 * Non-legacy ioctls should be registered by calling
47 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
48 * from userland by lzc_ioctl().
50 * The registration arguments are as follows:
53 * The name of the ioctl. This is used for history logging. If the
54 * ioctl returns successfully (the callback returns 0), and allow_log
55 * is true, then a history log entry will be recorded with the input &
56 * output nvlists. The log entry can be printed with "zpool history -i".
59 * The ioctl request number, which userland will pass to ioctl(2).
60 * The ioctl numbers can change from release to release, because
61 * the caller (libzfs) must be matched to the kernel.
63 * zfs_secpolicy_func_t *secpolicy
64 * This function will be called before the zfs_ioc_func_t, to
65 * determine if this operation is permitted. It should return EPERM
66 * on failure, and 0 on success. Checks include determining if the
67 * dataset is visible in this zone, and if the user has either all
68 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
69 * to do this operation on this dataset with "zfs allow".
71 * zfs_ioc_namecheck_t namecheck
72 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
73 * name, a dataset name, or nothing. If the name is not well-formed,
74 * the ioctl will fail and the callback will not be called.
75 * Therefore, the callback can assume that the name is well-formed
76 * (e.g. is null-terminated, doesn't have more than one '@' character,
77 * doesn't have invalid characters).
79 * zfs_ioc_poolcheck_t pool_check
80 * This specifies requirements on the pool state. If the pool does
81 * not meet them (is suspended or is readonly), the ioctl will fail
82 * and the callback will not be called. If any checks are specified
83 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
84 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
85 * POOL_CHECK_READONLY).
87 * boolean_t smush_outnvlist
88 * If smush_outnvlist is true, then the output is presumed to be a
89 * list of errors, and it will be "smushed" down to fit into the
90 * caller's buffer, by removing some entries and replacing them with a
91 * single "N_MORE_ERRORS" entry indicating how many were removed. See
92 * nvlist_smush() for details. If smush_outnvlist is false, and the
93 * outnvlist does not fit into the userland-provided buffer, then the
94 * ioctl will fail with ENOMEM.
96 * zfs_ioc_func_t *func
97 * The callback function that will perform the operation.
99 * The callback should return 0 on success, or an error number on
100 * failure. If the function fails, the userland ioctl will return -1,
101 * and errno will be set to the callback's return value. The callback
102 * will be called with the following arguments:
105 * The name of the pool or dataset to operate on, from
106 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
107 * expected type (pool, dataset, or none).
110 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
111 * NULL if no input nvlist was provided. Changes to this nvlist are
112 * ignored. If the input nvlist could not be deserialized, the
113 * ioctl will fail and the callback will not be called.
116 * The output nvlist, initially empty. The callback can fill it in,
117 * and it will be returned to userland by serializing it into
118 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
119 * fails (e.g. because the caller didn't supply a large enough
120 * buffer), then the overall ioctl will fail. See the
121 * 'smush_nvlist' argument above for additional behaviors.
123 * There are two typical uses of the output nvlist:
124 * - To return state, e.g. property values. In this case,
125 * smush_outnvlist should be false. If the buffer was not large
126 * enough, the caller will reallocate a larger buffer and try
129 * - To return multiple errors from an ioctl which makes on-disk
130 * changes. In this case, smush_outnvlist should be true.
131 * Ioctls which make on-disk modifications should generally not
132 * use the outnvl if they succeed, because the caller can not
133 * distinguish between the operation failing, and
134 * deserialization failing.
137 #include "opt_kstack_pages.h"
140 #include <sys/types.h>
141 #include <sys/param.h>
142 #include <sys/systm.h>
143 #include <sys/conf.h>
144 #include <sys/kernel.h>
145 #include <sys/lock.h>
146 #include <sys/malloc.h>
147 #include <sys/mutex.h>
148 #include <sys/proc.h>
149 #include <sys/errno.h>
152 #include <sys/file.h>
153 #include <sys/kmem.h>
154 #include <sys/conf.h>
155 #include <sys/cmn_err.h>
156 #include <sys/stat.h>
157 #include <sys/zfs_ioctl.h>
158 #include <sys/zfs_vfsops.h>
159 #include <sys/zfs_znode.h>
162 #include <sys/spa_impl.h>
163 #include <sys/vdev.h>
165 #include <sys/dsl_dir.h>
166 #include <sys/dsl_dataset.h>
167 #include <sys/dsl_prop.h>
168 #include <sys/dsl_deleg.h>
169 #include <sys/dmu_objset.h>
170 #include <sys/dmu_impl.h>
171 #include <sys/dmu_tx.h>
172 #include <sys/sunddi.h>
173 #include <sys/policy.h>
174 #include <sys/zone.h>
175 #include <sys/nvpair.h>
176 #include <sys/mount.h>
177 #include <sys/taskqueue.h>
179 #include <sys/varargs.h>
180 #include <sys/fs/zfs.h>
181 #include <sys/zfs_ctldir.h>
182 #include <sys/zfs_dir.h>
183 #include <sys/zfs_onexit.h>
184 #include <sys/zvol.h>
185 #include <sys/dsl_scan.h>
186 #include <sys/dmu_objset.h>
187 #include <sys/dmu_send.h>
188 #include <sys/dsl_destroy.h>
189 #include <sys/dsl_bookmark.h>
190 #include <sys/dsl_userhold.h>
191 #include <sys/zfeature.h>
192 #include <sys/zio_checksum.h>
194 #include "zfs_namecheck.h"
195 #include "zfs_prop.h"
196 #include "zfs_deleg.h"
197 #include "zfs_comutil.h"
198 #include "zfs_ioctl_compat.h"
200 CTASSERT(sizeof(zfs_cmd_t) < IOCPARM_MAX);
202 static struct cdev *zfsdev;
204 extern void zfs_init(void);
205 extern void zfs_fini(void);
207 uint_t zfs_fsyncer_key;
208 extern uint_t rrw_tsd_key;
209 static uint_t zfs_allow_log_key;
210 extern uint_t zfs_geom_probe_vdev_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);
257 static void zfsdev_close(void *data);
259 static int zfs_prop_activate_feature(spa_t *spa, spa_feature_t feature);
261 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
263 __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
270 * Get rid of annoying "../common/" prefix to filename.
272 newfile = strrchr(file, '/');
273 if (newfile != NULL) {
274 newfile = newfile + 1; /* Get rid of leading / */
280 (void) vsnprintf(buf, sizeof (buf), fmt, adx);
284 * To get this data, use the zfs-dprintf probe as so:
285 * dtrace -q -n 'zfs-dprintf \
286 * /stringof(arg0) == "dbuf.c"/ \
287 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
289 * arg1 = function name
293 DTRACE_PROBE4(zfs__dprintf,
294 char *, newfile, char *, func, int, line, char *, buf);
298 history_str_free(char *buf)
300 kmem_free(buf, HIS_MAX_RECORD_LEN);
304 history_str_get(zfs_cmd_t *zc)
308 if (zc->zc_history == 0)
311 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
312 if (copyinstr((void *)(uintptr_t)zc->zc_history,
313 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
314 history_str_free(buf);
318 buf[HIS_MAX_RECORD_LEN -1] = '\0';
324 * Check to see if the named dataset is currently defined as bootable
327 zfs_is_bootfs(const char *name)
331 if (dmu_objset_hold(name, FTAG, &os) == 0) {
333 ret = (dmu_objset_id(os) == spa_bootfs(dmu_objset_spa(os)));
334 dmu_objset_rele(os, FTAG);
341 * Return non-zero if the spa version is less than requested version.
344 zfs_earlier_version(const char *name, int version)
348 if (spa_open(name, &spa, FTAG) == 0) {
349 if (spa_version(spa) < version) {
350 spa_close(spa, FTAG);
353 spa_close(spa, FTAG);
359 * Return TRUE if the ZPL version is less than requested version.
362 zpl_earlier_version(const char *name, int version)
365 boolean_t rc = B_TRUE;
367 if (dmu_objset_hold(name, FTAG, &os) == 0) {
370 if (dmu_objset_type(os) != DMU_OST_ZFS) {
371 dmu_objset_rele(os, FTAG);
374 /* XXX reading from non-owned objset */
375 if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
376 rc = zplversion < version;
377 dmu_objset_rele(os, FTAG);
383 zfs_log_history(zfs_cmd_t *zc)
388 if ((buf = history_str_get(zc)) == NULL)
391 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
392 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
393 (void) spa_history_log(spa, buf);
394 spa_close(spa, FTAG);
396 history_str_free(buf);
400 * Policy for top-level read operations (list pools). Requires no privileges,
401 * and can be used in the local zone, as there is no associated dataset.
405 zfs_secpolicy_none(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
411 * Policy for dataset read operations (list children, get statistics). Requires
412 * no privileges, but must be visible in the local zone.
416 zfs_secpolicy_read(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
418 if (INGLOBALZONE(curthread) ||
419 zone_dataset_visible(zc->zc_name, NULL))
422 return (SET_ERROR(ENOENT));
426 zfs_dozonecheck_impl(const char *dataset, uint64_t zoned, cred_t *cr)
431 * The dataset must be visible by this zone -- check this first
432 * so they don't see EPERM on something they shouldn't know about.
434 if (!INGLOBALZONE(curthread) &&
435 !zone_dataset_visible(dataset, &writable))
436 return (SET_ERROR(ENOENT));
438 if (INGLOBALZONE(curthread)) {
440 * If the fs is zoned, only root can access it from the
443 if (secpolicy_zfs(cr) && zoned)
444 return (SET_ERROR(EPERM));
447 * If we are in a local zone, the 'zoned' property must be set.
450 return (SET_ERROR(EPERM));
452 /* must be writable by this zone */
454 return (SET_ERROR(EPERM));
460 zfs_dozonecheck(const char *dataset, cred_t *cr)
464 if (dsl_prop_get_integer(dataset, "jailed", &zoned, NULL))
465 return (SET_ERROR(ENOENT));
467 return (zfs_dozonecheck_impl(dataset, zoned, cr));
471 zfs_dozonecheck_ds(const char *dataset, dsl_dataset_t *ds, cred_t *cr)
475 if (dsl_prop_get_int_ds(ds, "jailed", &zoned))
476 return (SET_ERROR(ENOENT));
478 return (zfs_dozonecheck_impl(dataset, zoned, cr));
482 zfs_secpolicy_write_perms_ds(const char *name, dsl_dataset_t *ds,
483 const char *perm, cred_t *cr)
487 error = zfs_dozonecheck_ds(name, ds, cr);
489 error = secpolicy_zfs(cr);
491 error = dsl_deleg_access_impl(ds, perm, cr);
497 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
504 * First do a quick check for root in the global zone, which
505 * is allowed to do all write_perms. This ensures that zfs_ioc_*
506 * will get to handle nonexistent datasets.
508 if (INGLOBALZONE(curthread) && secpolicy_zfs(cr) == 0)
511 error = dsl_pool_hold(name, FTAG, &dp);
515 error = dsl_dataset_hold(dp, name, FTAG, &ds);
517 dsl_pool_rele(dp, FTAG);
521 error = zfs_secpolicy_write_perms_ds(name, ds, perm, cr);
523 dsl_dataset_rele(ds, FTAG);
524 dsl_pool_rele(dp, FTAG);
530 * Policy for setting the security label property.
532 * Returns 0 for success, non-zero for access and other errors.
535 zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
537 char ds_hexsl[MAXNAMELEN];
538 bslabel_t ds_sl, new_sl;
539 boolean_t new_default = FALSE;
541 int needed_priv = -1;
544 /* First get the existing dataset label. */
545 error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
546 1, sizeof (ds_hexsl), &ds_hexsl, NULL);
548 return (SET_ERROR(EPERM));
550 if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
553 /* The label must be translatable */
554 if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
555 return (SET_ERROR(EINVAL));
558 * In a non-global zone, disallow attempts to set a label that
559 * doesn't match that of the zone; otherwise no other checks
562 if (!INGLOBALZONE(curproc)) {
563 if (new_default || !blequal(&new_sl, CR_SL(CRED())))
564 return (SET_ERROR(EPERM));
569 * For global-zone datasets (i.e., those whose zoned property is
570 * "off", verify that the specified new label is valid for the
573 if (dsl_prop_get_integer(name,
574 zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
575 return (SET_ERROR(EPERM));
577 if (zfs_check_global_label(name, strval) != 0)
578 return (SET_ERROR(EPERM));
582 * If the existing dataset label is nondefault, check if the
583 * dataset is mounted (label cannot be changed while mounted).
584 * Get the zfsvfs; if there isn't one, then the dataset isn't
585 * mounted (or isn't a dataset, doesn't exist, ...).
587 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
589 static char *setsl_tag = "setsl_tag";
592 * Try to own the dataset; abort if there is any error,
593 * (e.g., already mounted, in use, or other error).
595 error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
598 return (SET_ERROR(EPERM));
600 dmu_objset_disown(os, setsl_tag);
603 needed_priv = PRIV_FILE_DOWNGRADE_SL;
607 if (hexstr_to_label(strval, &new_sl) != 0)
608 return (SET_ERROR(EPERM));
610 if (blstrictdom(&ds_sl, &new_sl))
611 needed_priv = PRIV_FILE_DOWNGRADE_SL;
612 else if (blstrictdom(&new_sl, &ds_sl))
613 needed_priv = PRIV_FILE_UPGRADE_SL;
615 /* dataset currently has a default label */
617 needed_priv = PRIV_FILE_UPGRADE_SL;
621 if (needed_priv != -1)
622 return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
625 #endif /* SECLABEL */
628 zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
634 * Check permissions for special properties.
639 * Disallow setting of 'zoned' from within a local zone.
641 if (!INGLOBALZONE(curthread))
642 return (SET_ERROR(EPERM));
646 case ZFS_PROP_FILESYSTEM_LIMIT:
647 case ZFS_PROP_SNAPSHOT_LIMIT:
648 if (!INGLOBALZONE(curthread)) {
650 char setpoint[ZFS_MAX_DATASET_NAME_LEN];
652 * Unprivileged users are allowed to modify the
653 * limit on things *under* (ie. contained by)
654 * the thing they own.
656 if (dsl_prop_get_integer(dsname, "jailed", &zoned,
658 return (SET_ERROR(EPERM));
659 if (!zoned || strlen(dsname) <= strlen(setpoint))
660 return (SET_ERROR(EPERM));
664 case ZFS_PROP_MLSLABEL:
666 if (!is_system_labeled())
667 return (SET_ERROR(EPERM));
669 if (nvpair_value_string(propval, &strval) == 0) {
672 err = zfs_set_slabel_policy(dsname, strval, CRED());
682 return (zfs_secpolicy_write_perms(dsname, zfs_prop_to_name(prop), cr));
687 zfs_secpolicy_set_fsacl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
691 error = zfs_dozonecheck(zc->zc_name, cr);
696 * permission to set permissions will be evaluated later in
697 * dsl_deleg_can_allow()
704 zfs_secpolicy_rollback(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
706 return (zfs_secpolicy_write_perms(zc->zc_name,
707 ZFS_DELEG_PERM_ROLLBACK, cr));
712 zfs_secpolicy_send(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
720 * Generate the current snapshot name from the given objsetid, then
721 * use that name for the secpolicy/zone checks.
723 cp = strchr(zc->zc_name, '@');
725 return (SET_ERROR(EINVAL));
726 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
730 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &ds);
732 dsl_pool_rele(dp, FTAG);
736 dsl_dataset_name(ds, zc->zc_name);
738 error = zfs_secpolicy_write_perms_ds(zc->zc_name, ds,
739 ZFS_DELEG_PERM_SEND, cr);
740 dsl_dataset_rele(ds, FTAG);
741 dsl_pool_rele(dp, FTAG);
748 zfs_secpolicy_send_new(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
750 return (zfs_secpolicy_write_perms(zc->zc_name,
751 ZFS_DELEG_PERM_SEND, cr));
756 zfs_secpolicy_deleg_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
761 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
762 NO_FOLLOW, NULL, &vp)) != 0)
765 /* Now make sure mntpnt and dataset are ZFS */
767 if (strcmp(vp->v_vfsp->mnt_stat.f_fstypename, "zfs") != 0 ||
768 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
769 zc->zc_name) != 0)) {
771 return (SET_ERROR(EPERM));
775 return (dsl_deleg_access(zc->zc_name,
776 ZFS_DELEG_PERM_SHARE, cr));
780 zfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
782 if (!INGLOBALZONE(curthread))
783 return (SET_ERROR(EPERM));
785 if (secpolicy_nfs(cr) == 0) {
788 return (zfs_secpolicy_deleg_share(zc, innvl, cr));
793 zfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
795 if (!INGLOBALZONE(curthread))
796 return (SET_ERROR(EPERM));
798 if (secpolicy_smb(cr) == 0) {
801 return (zfs_secpolicy_deleg_share(zc, innvl, cr));
806 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
811 * Remove the @bla or /bla from the end of the name to get the parent.
813 (void) strncpy(parent, datasetname, parentsize);
814 cp = strrchr(parent, '@');
818 cp = strrchr(parent, '/');
820 return (SET_ERROR(ENOENT));
828 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
832 if ((error = zfs_secpolicy_write_perms(name,
833 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
836 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
841 zfs_secpolicy_destroy(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
843 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
847 * Destroying snapshots with delegated permissions requires
848 * descendant mount and destroy permissions.
852 zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
855 nvpair_t *pair, *nextpair;
858 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
859 return (SET_ERROR(EINVAL));
860 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
862 nextpair = nvlist_next_nvpair(snaps, pair);
863 error = zfs_secpolicy_destroy_perms(nvpair_name(pair), cr);
864 if (error == ENOENT) {
866 * Ignore any snapshots that don't exist (we consider
867 * them "already destroyed"). Remove the name from the
868 * nvl here in case the snapshot is created between
869 * now and when we try to destroy it (in which case
870 * we don't want to destroy it since we haven't
871 * checked for permission).
873 fnvlist_remove_nvpair(snaps, pair);
884 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
886 char parentname[ZFS_MAX_DATASET_NAME_LEN];
889 if ((error = zfs_secpolicy_write_perms(from,
890 ZFS_DELEG_PERM_RENAME, cr)) != 0)
893 if ((error = zfs_secpolicy_write_perms(from,
894 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
897 if ((error = zfs_get_parent(to, parentname,
898 sizeof (parentname))) != 0)
901 if ((error = zfs_secpolicy_write_perms(parentname,
902 ZFS_DELEG_PERM_CREATE, cr)) != 0)
905 if ((error = zfs_secpolicy_write_perms(parentname,
906 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
914 zfs_secpolicy_rename(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
919 if ((zc->zc_cookie & 1) != 0) {
921 * This is recursive rename, so the starting snapshot might
922 * not exist. Check file system or volume permission instead.
924 at = strchr(zc->zc_name, '@');
930 error = zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr);
940 zfs_secpolicy_promote(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
943 dsl_dataset_t *clone;
946 error = zfs_secpolicy_write_perms(zc->zc_name,
947 ZFS_DELEG_PERM_PROMOTE, cr);
951 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
955 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &clone);
958 char parentname[ZFS_MAX_DATASET_NAME_LEN];
959 dsl_dataset_t *origin = NULL;
963 error = dsl_dataset_hold_obj(dd->dd_pool,
964 dsl_dir_phys(dd)->dd_origin_obj, FTAG, &origin);
966 dsl_dataset_rele(clone, FTAG);
967 dsl_pool_rele(dp, FTAG);
971 error = zfs_secpolicy_write_perms_ds(zc->zc_name, clone,
972 ZFS_DELEG_PERM_MOUNT, cr);
974 dsl_dataset_name(origin, parentname);
976 error = zfs_secpolicy_write_perms_ds(parentname, origin,
977 ZFS_DELEG_PERM_PROMOTE, cr);
979 dsl_dataset_rele(clone, FTAG);
980 dsl_dataset_rele(origin, FTAG);
982 dsl_pool_rele(dp, FTAG);
988 zfs_secpolicy_recv(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
992 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
993 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
996 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
997 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
1000 return (zfs_secpolicy_write_perms(zc->zc_name,
1001 ZFS_DELEG_PERM_CREATE, cr));
1005 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
1007 return (zfs_secpolicy_write_perms(name,
1008 ZFS_DELEG_PERM_SNAPSHOT, cr));
1012 * Check for permission to create each snapshot in the nvlist.
1016 zfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1022 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
1023 return (SET_ERROR(EINVAL));
1024 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
1025 pair = nvlist_next_nvpair(snaps, pair)) {
1026 char *name = nvpair_name(pair);
1027 char *atp = strchr(name, '@');
1030 error = SET_ERROR(EINVAL);
1034 error = zfs_secpolicy_snapshot_perms(name, cr);
1043 * Check for permission to create each snapshot in the nvlist.
1047 zfs_secpolicy_bookmark(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1051 for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
1052 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
1053 char *name = nvpair_name(pair);
1054 char *hashp = strchr(name, '#');
1056 if (hashp == NULL) {
1057 error = SET_ERROR(EINVAL);
1061 error = zfs_secpolicy_write_perms(name,
1062 ZFS_DELEG_PERM_BOOKMARK, cr);
1072 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1074 nvpair_t *pair, *nextpair;
1077 for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
1079 char *name = nvpair_name(pair);
1080 char *hashp = strchr(name, '#');
1081 nextpair = nvlist_next_nvpair(innvl, pair);
1083 if (hashp == NULL) {
1084 error = SET_ERROR(EINVAL);
1089 error = zfs_secpolicy_write_perms(name,
1090 ZFS_DELEG_PERM_DESTROY, cr);
1092 if (error == ENOENT) {
1094 * Ignore any filesystems that don't exist (we consider
1095 * their bookmarks "already destroyed"). Remove
1096 * the name from the nvl here in case the filesystem
1097 * is created between now and when we try to destroy
1098 * the bookmark (in which case we don't want to
1099 * destroy it since we haven't checked for permission).
1101 fnvlist_remove_nvpair(innvl, pair);
1113 zfs_secpolicy_log_history(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1116 * Even root must have a proper TSD so that we know what pool
1119 if (tsd_get(zfs_allow_log_key) == NULL)
1120 return (SET_ERROR(EPERM));
1125 zfs_secpolicy_create_clone(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1127 char parentname[ZFS_MAX_DATASET_NAME_LEN];
1131 if ((error = zfs_get_parent(zc->zc_name, parentname,
1132 sizeof (parentname))) != 0)
1135 if (nvlist_lookup_string(innvl, "origin", &origin) == 0 &&
1136 (error = zfs_secpolicy_write_perms(origin,
1137 ZFS_DELEG_PERM_CLONE, cr)) != 0)
1140 if ((error = zfs_secpolicy_write_perms(parentname,
1141 ZFS_DELEG_PERM_CREATE, cr)) != 0)
1144 return (zfs_secpolicy_write_perms(parentname,
1145 ZFS_DELEG_PERM_MOUNT, cr));
1149 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1150 * SYS_CONFIG privilege, which is not available in a local zone.
1154 zfs_secpolicy_config(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1156 if (secpolicy_sys_config(cr, B_FALSE) != 0)
1157 return (SET_ERROR(EPERM));
1163 * Policy for object to name lookups.
1167 zfs_secpolicy_diff(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1171 if ((error = secpolicy_sys_config(cr, B_FALSE)) == 0)
1174 error = zfs_secpolicy_write_perms(zc->zc_name, ZFS_DELEG_PERM_DIFF, cr);
1179 * Policy for fault injection. Requires all privileges.
1183 zfs_secpolicy_inject(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1185 return (secpolicy_zinject(cr));
1190 zfs_secpolicy_inherit_prop(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1192 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
1194 if (prop == ZPROP_INVAL) {
1195 if (!zfs_prop_user(zc->zc_value))
1196 return (SET_ERROR(EINVAL));
1197 return (zfs_secpolicy_write_perms(zc->zc_name,
1198 ZFS_DELEG_PERM_USERPROP, cr));
1200 return (zfs_secpolicy_setprop(zc->zc_name, prop,
1206 zfs_secpolicy_userspace_one(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1208 int err = zfs_secpolicy_read(zc, innvl, cr);
1212 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1213 return (SET_ERROR(EINVAL));
1215 if (zc->zc_value[0] == 0) {
1217 * They are asking about a posix uid/gid. If it's
1218 * themself, allow it.
1220 if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
1221 zc->zc_objset_type == ZFS_PROP_USERQUOTA) {
1222 if (zc->zc_guid == crgetuid(cr))
1225 if (groupmember(zc->zc_guid, cr))
1230 return (zfs_secpolicy_write_perms(zc->zc_name,
1231 userquota_perms[zc->zc_objset_type], cr));
1235 zfs_secpolicy_userspace_many(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1237 int err = zfs_secpolicy_read(zc, innvl, cr);
1241 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1242 return (SET_ERROR(EINVAL));
1244 return (zfs_secpolicy_write_perms(zc->zc_name,
1245 userquota_perms[zc->zc_objset_type], cr));
1250 zfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1252 return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION,
1258 zfs_secpolicy_hold(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1264 error = nvlist_lookup_nvlist(innvl, "holds", &holds);
1266 return (SET_ERROR(EINVAL));
1268 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
1269 pair = nvlist_next_nvpair(holds, pair)) {
1270 char fsname[ZFS_MAX_DATASET_NAME_LEN];
1271 error = dmu_fsname(nvpair_name(pair), fsname);
1274 error = zfs_secpolicy_write_perms(fsname,
1275 ZFS_DELEG_PERM_HOLD, cr);
1284 zfs_secpolicy_release(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1289 for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
1290 pair = nvlist_next_nvpair(innvl, pair)) {
1291 char fsname[ZFS_MAX_DATASET_NAME_LEN];
1292 error = dmu_fsname(nvpair_name(pair), fsname);
1295 error = zfs_secpolicy_write_perms(fsname,
1296 ZFS_DELEG_PERM_RELEASE, cr);
1304 * Policy for allowing temporary snapshots to be taken or released
1307 zfs_secpolicy_tmp_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
1310 * A temporary snapshot is the same as a snapshot,
1311 * hold, destroy and release all rolled into one.
1312 * Delegated diff alone is sufficient that we allow this.
1316 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
1317 ZFS_DELEG_PERM_DIFF, cr)) == 0)
1320 error = zfs_secpolicy_snapshot_perms(zc->zc_name, cr);
1322 error = zfs_secpolicy_hold(zc, innvl, cr);
1324 error = zfs_secpolicy_release(zc, innvl, cr);
1326 error = zfs_secpolicy_destroy(zc, innvl, cr);
1331 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1334 get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
1338 nvlist_t *list = NULL;
1341 * Read in and unpack the user-supplied nvlist.
1344 return (SET_ERROR(EINVAL));
1346 packed = kmem_alloc(size, KM_SLEEP);
1348 if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
1350 kmem_free(packed, size);
1351 return (SET_ERROR(EFAULT));
1354 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
1355 kmem_free(packed, size);
1359 kmem_free(packed, size);
1366 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1367 * Entries will be removed from the end of the nvlist, and one int32 entry
1368 * named "N_MORE_ERRORS" will be added indicating how many entries were
1372 nvlist_smush(nvlist_t *errors, size_t max)
1376 size = fnvlist_size(errors);
1379 nvpair_t *more_errors;
1383 return (SET_ERROR(ENOMEM));
1385 fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, 0);
1386 more_errors = nvlist_prev_nvpair(errors, NULL);
1389 nvpair_t *pair = nvlist_prev_nvpair(errors,
1391 fnvlist_remove_nvpair(errors, pair);
1393 size = fnvlist_size(errors);
1394 } while (size > max);
1396 fnvlist_remove_nvpair(errors, more_errors);
1397 fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, n);
1398 ASSERT3U(fnvlist_size(errors), <=, max);
1405 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
1407 char *packed = NULL;
1411 size = fnvlist_size(nvl);
1413 if (size > zc->zc_nvlist_dst_size) {
1415 * Solaris returns ENOMEM here, because even if an error is
1416 * returned from an ioctl(2), new zc_nvlist_dst_size will be
1417 * passed to the userland. This is not the case for FreeBSD.
1418 * We need to return 0, so the kernel will copy the
1419 * zc_nvlist_dst_size back and the userland can discover that a
1420 * bigger buffer is needed.
1424 packed = fnvlist_pack(nvl, &size);
1425 if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
1426 size, zc->zc_iflags) != 0)
1427 error = SET_ERROR(EFAULT);
1428 fnvlist_pack_free(packed, size);
1431 zc->zc_nvlist_dst_size = size;
1432 zc->zc_nvlist_dst_filled = B_TRUE;
1437 getzfsvfs(const char *dsname, zfsvfs_t **zfvp)
1443 error = dmu_objset_hold(dsname, FTAG, &os);
1446 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1447 dmu_objset_rele(os, FTAG);
1448 return (SET_ERROR(EINVAL));
1451 mutex_enter(&os->os_user_ptr_lock);
1452 *zfvp = dmu_objset_get_user(os);
1454 vfsp = (*zfvp)->z_vfs;
1457 error = SET_ERROR(ESRCH);
1459 mutex_exit(&os->os_user_ptr_lock);
1460 dmu_objset_rele(os, FTAG);
1462 error = vfs_busy(vfsp, 0);
1466 error = SET_ERROR(ESRCH);
1473 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1474 * case its z_vfs will be NULL, and it will be opened as the owner.
1475 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1476 * which prevents all vnode ops from running.
1479 zfsvfs_hold(const char *name, void *tag, zfsvfs_t **zfvp, boolean_t writer)
1483 if (getzfsvfs(name, zfvp) != 0)
1484 error = zfsvfs_create(name, zfvp);
1486 rrm_enter(&(*zfvp)->z_teardown_lock, (writer) ? RW_WRITER :
1488 if ((*zfvp)->z_unmounted) {
1490 * XXX we could probably try again, since the unmounting
1491 * thread should be just about to disassociate the
1492 * objset from the zfsvfs.
1494 rrm_exit(&(*zfvp)->z_teardown_lock, tag);
1495 return (SET_ERROR(EBUSY));
1502 zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
1504 rrm_exit(&zfsvfs->z_teardown_lock, tag);
1506 if (zfsvfs->z_vfs) {
1508 VFS_RELE(zfsvfs->z_vfs);
1510 vfs_unbusy(zfsvfs->z_vfs);
1513 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1514 zfsvfs_free(zfsvfs);
1519 zfs_ioc_pool_create(zfs_cmd_t *zc)
1522 nvlist_t *config, *props = NULL;
1523 nvlist_t *rootprops = NULL;
1524 nvlist_t *zplprops = NULL;
1526 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1527 zc->zc_iflags, &config))
1530 if (zc->zc_nvlist_src_size != 0 && (error =
1531 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1532 zc->zc_iflags, &props))) {
1533 nvlist_free(config);
1538 nvlist_t *nvl = NULL;
1539 uint64_t version = SPA_VERSION;
1541 (void) nvlist_lookup_uint64(props,
1542 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
1543 if (!SPA_VERSION_IS_SUPPORTED(version)) {
1544 error = SET_ERROR(EINVAL);
1545 goto pool_props_bad;
1547 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
1549 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
1551 nvlist_free(config);
1555 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
1557 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1558 error = zfs_fill_zplprops_root(version, rootprops,
1561 goto pool_props_bad;
1564 error = spa_create(zc->zc_name, config, props, zplprops);
1567 * Set the remaining root properties
1569 if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
1570 ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
1571 (void) spa_destroy(zc->zc_name);
1574 nvlist_free(rootprops);
1575 nvlist_free(zplprops);
1576 nvlist_free(config);
1583 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
1586 zfs_log_history(zc);
1587 error = spa_destroy(zc->zc_name);
1589 zvol_remove_minors(zc->zc_name);
1594 zfs_ioc_pool_import(zfs_cmd_t *zc)
1596 nvlist_t *config, *props = NULL;
1600 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1601 zc->zc_iflags, &config)) != 0)
1604 if (zc->zc_nvlist_src_size != 0 && (error =
1605 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1606 zc->zc_iflags, &props))) {
1607 nvlist_free(config);
1611 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1612 guid != zc->zc_guid)
1613 error = SET_ERROR(EINVAL);
1615 error = spa_import(zc->zc_name, config, props, zc->zc_cookie);
1617 if (zc->zc_nvlist_dst != 0) {
1620 if ((err = put_nvlist(zc, config)) != 0)
1624 nvlist_free(config);
1632 zfs_ioc_pool_export(zfs_cmd_t *zc)
1635 boolean_t force = (boolean_t)zc->zc_cookie;
1636 boolean_t hardforce = (boolean_t)zc->zc_guid;
1638 zfs_log_history(zc);
1639 error = spa_export(zc->zc_name, NULL, force, hardforce);
1641 zvol_remove_minors(zc->zc_name);
1646 zfs_ioc_pool_configs(zfs_cmd_t *zc)
1651 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
1652 return (SET_ERROR(EEXIST));
1654 error = put_nvlist(zc, configs);
1656 nvlist_free(configs);
1663 * zc_name name of the pool
1666 * zc_cookie real errno
1667 * zc_nvlist_dst config nvlist
1668 * zc_nvlist_dst_size size of config nvlist
1671 zfs_ioc_pool_stats(zfs_cmd_t *zc)
1677 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
1678 sizeof (zc->zc_value));
1680 if (config != NULL) {
1681 ret = put_nvlist(zc, config);
1682 nvlist_free(config);
1685 * The config may be present even if 'error' is non-zero.
1686 * In this case we return success, and preserve the real errno
1689 zc->zc_cookie = error;
1698 * Try to import the given pool, returning pool stats as appropriate so that
1699 * user land knows which devices are available and overall pool health.
1702 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
1704 nvlist_t *tryconfig, *config;
1707 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1708 zc->zc_iflags, &tryconfig)) != 0)
1711 config = spa_tryimport(tryconfig);
1713 nvlist_free(tryconfig);
1716 return (SET_ERROR(EINVAL));
1718 error = put_nvlist(zc, config);
1719 nvlist_free(config);
1726 * zc_name name of the pool
1727 * zc_cookie scan func (pool_scan_func_t)
1730 zfs_ioc_pool_scan(zfs_cmd_t *zc)
1735 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1738 if (zc->zc_cookie == POOL_SCAN_NONE)
1739 error = spa_scan_stop(spa);
1741 error = spa_scan(spa, zc->zc_cookie);
1743 spa_close(spa, FTAG);
1749 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
1754 error = spa_open(zc->zc_name, &spa, FTAG);
1757 spa_close(spa, FTAG);
1763 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
1768 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1771 if (zc->zc_cookie < spa_version(spa) ||
1772 !SPA_VERSION_IS_SUPPORTED(zc->zc_cookie)) {
1773 spa_close(spa, FTAG);
1774 return (SET_ERROR(EINVAL));
1777 spa_upgrade(spa, zc->zc_cookie);
1778 spa_close(spa, FTAG);
1784 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
1791 if ((size = zc->zc_history_len) == 0)
1792 return (SET_ERROR(EINVAL));
1794 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1797 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
1798 spa_close(spa, FTAG);
1799 return (SET_ERROR(ENOTSUP));
1802 hist_buf = kmem_alloc(size, KM_SLEEP);
1803 if ((error = spa_history_get(spa, &zc->zc_history_offset,
1804 &zc->zc_history_len, hist_buf)) == 0) {
1805 error = ddi_copyout(hist_buf,
1806 (void *)(uintptr_t)zc->zc_history,
1807 zc->zc_history_len, zc->zc_iflags);
1810 spa_close(spa, FTAG);
1811 kmem_free(hist_buf, size);
1816 zfs_ioc_pool_reguid(zfs_cmd_t *zc)
1821 error = spa_open(zc->zc_name, &spa, FTAG);
1823 error = spa_change_guid(spa);
1824 spa_close(spa, FTAG);
1830 zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
1832 return (dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value));
1837 * zc_name name of filesystem
1838 * zc_obj object to find
1841 * zc_value name of object
1844 zfs_ioc_obj_to_path(zfs_cmd_t *zc)
1849 /* XXX reading from objset not owned */
1850 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1852 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1853 dmu_objset_rele(os, FTAG);
1854 return (SET_ERROR(EINVAL));
1856 error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
1857 sizeof (zc->zc_value));
1858 dmu_objset_rele(os, FTAG);
1865 * zc_name name of filesystem
1866 * zc_obj object to find
1869 * zc_stat stats on object
1870 * zc_value path to object
1873 zfs_ioc_obj_to_stats(zfs_cmd_t *zc)
1878 /* XXX reading from objset not owned */
1879 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1881 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1882 dmu_objset_rele(os, FTAG);
1883 return (SET_ERROR(EINVAL));
1885 error = zfs_obj_to_stats(os, zc->zc_obj, &zc->zc_stat, zc->zc_value,
1886 sizeof (zc->zc_value));
1887 dmu_objset_rele(os, FTAG);
1893 zfs_ioc_vdev_add(zfs_cmd_t *zc)
1897 nvlist_t *config, **l2cache, **spares;
1898 uint_t nl2cache = 0, nspares = 0;
1900 error = spa_open(zc->zc_name, &spa, FTAG);
1904 error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1905 zc->zc_iflags, &config);
1906 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
1907 &l2cache, &nl2cache);
1909 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
1914 * A root pool with concatenated devices is not supported.
1915 * Thus, can not add a device to a root pool.
1917 * Intent log device can not be added to a rootpool because
1918 * during mountroot, zil is replayed, a seperated log device
1919 * can not be accessed during the mountroot time.
1921 * l2cache and spare devices are ok to be added to a rootpool.
1923 if (spa_bootfs(spa) != 0 && nl2cache == 0 && nspares == 0) {
1924 nvlist_free(config);
1925 spa_close(spa, FTAG);
1926 return (SET_ERROR(EDOM));
1928 #endif /* illumos */
1931 error = spa_vdev_add(spa, config);
1932 nvlist_free(config);
1934 spa_close(spa, FTAG);
1940 * zc_name name of the pool
1941 * zc_nvlist_conf nvlist of devices to remove
1942 * zc_cookie to stop the remove?
1945 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
1950 error = spa_open(zc->zc_name, &spa, FTAG);
1953 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
1954 spa_close(spa, FTAG);
1959 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
1963 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1965 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1967 switch (zc->zc_cookie) {
1968 case VDEV_STATE_ONLINE:
1969 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
1972 case VDEV_STATE_OFFLINE:
1973 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
1976 case VDEV_STATE_FAULTED:
1977 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1978 zc->zc_obj != VDEV_AUX_EXTERNAL)
1979 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1981 error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
1984 case VDEV_STATE_DEGRADED:
1985 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1986 zc->zc_obj != VDEV_AUX_EXTERNAL)
1987 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1989 error = vdev_degrade(spa, zc->zc_guid, zc->zc_obj);
1993 error = SET_ERROR(EINVAL);
1995 zc->zc_cookie = newstate;
1996 spa_close(spa, FTAG);
2001 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
2004 int replacing = zc->zc_cookie;
2008 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2011 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
2012 zc->zc_iflags, &config)) == 0) {
2013 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
2014 nvlist_free(config);
2017 spa_close(spa, FTAG);
2022 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
2027 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2030 error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
2032 spa_close(spa, FTAG);
2037 zfs_ioc_vdev_split(zfs_cmd_t *zc)
2040 nvlist_t *config, *props = NULL;
2042 boolean_t exp = !!(zc->zc_cookie & ZPOOL_EXPORT_AFTER_SPLIT);
2044 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2047 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
2048 zc->zc_iflags, &config)) {
2049 spa_close(spa, FTAG);
2053 if (zc->zc_nvlist_src_size != 0 && (error =
2054 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2055 zc->zc_iflags, &props))) {
2056 spa_close(spa, FTAG);
2057 nvlist_free(config);
2061 error = spa_vdev_split_mirror(spa, zc->zc_string, config, props, exp);
2063 spa_close(spa, FTAG);
2065 nvlist_free(config);
2072 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
2075 char *path = zc->zc_value;
2076 uint64_t guid = zc->zc_guid;
2079 error = spa_open(zc->zc_name, &spa, FTAG);
2083 error = spa_vdev_setpath(spa, guid, path);
2084 spa_close(spa, FTAG);
2089 zfs_ioc_vdev_setfru(zfs_cmd_t *zc)
2092 char *fru = zc->zc_value;
2093 uint64_t guid = zc->zc_guid;
2096 error = spa_open(zc->zc_name, &spa, FTAG);
2100 error = spa_vdev_setfru(spa, guid, fru);
2101 spa_close(spa, FTAG);
2106 zfs_ioc_objset_stats_impl(zfs_cmd_t *zc, objset_t *os)
2111 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
2113 if (zc->zc_nvlist_dst != 0 &&
2114 (error = dsl_prop_get_all(os, &nv)) == 0) {
2115 dmu_objset_stats(os, nv);
2117 * NB: zvol_get_stats() will read the objset contents,
2118 * which we aren't supposed to do with a
2119 * DS_MODE_USER hold, because it could be
2120 * inconsistent. So this is a bit of a workaround...
2121 * XXX reading with out owning
2123 if (!zc->zc_objset_stats.dds_inconsistent &&
2124 dmu_objset_type(os) == DMU_OST_ZVOL) {
2125 error = zvol_get_stats(os, nv);
2130 error = put_nvlist(zc, nv);
2139 * zc_name name of filesystem
2140 * zc_nvlist_dst_size size of buffer for property nvlist
2143 * zc_objset_stats stats
2144 * zc_nvlist_dst property nvlist
2145 * zc_nvlist_dst_size size of property nvlist
2148 zfs_ioc_objset_stats(zfs_cmd_t *zc)
2153 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
2155 error = zfs_ioc_objset_stats_impl(zc, os);
2156 dmu_objset_rele(os, FTAG);
2159 if (error == ENOMEM)
2166 * zc_name name of filesystem
2167 * zc_nvlist_dst_size size of buffer for property nvlist
2170 * zc_nvlist_dst received property nvlist
2171 * zc_nvlist_dst_size size of received property nvlist
2173 * Gets received properties (distinct from local properties on or after
2174 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2175 * local property values.
2178 zfs_ioc_objset_recvd_props(zfs_cmd_t *zc)
2184 * Without this check, we would return local property values if the
2185 * caller has not already received properties on or after
2186 * SPA_VERSION_RECVD_PROPS.
2188 if (!dsl_prop_get_hasrecvd(zc->zc_name))
2189 return (SET_ERROR(ENOTSUP));
2191 if (zc->zc_nvlist_dst != 0 &&
2192 (error = dsl_prop_get_received(zc->zc_name, &nv)) == 0) {
2193 error = put_nvlist(zc, nv);
2201 nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
2207 * zfs_get_zplprop() will either find a value or give us
2208 * the default value (if there is one).
2210 if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
2212 VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
2218 * zc_name name of filesystem
2219 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2222 * zc_nvlist_dst zpl property nvlist
2223 * zc_nvlist_dst_size size of zpl property nvlist
2226 zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
2231 /* XXX reading without owning */
2232 if (err = dmu_objset_hold(zc->zc_name, FTAG, &os))
2235 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
2238 * NB: nvl_add_zplprop() will read the objset contents,
2239 * which we aren't supposed to do with a DS_MODE_USER
2240 * hold, because it could be inconsistent.
2242 if (zc->zc_nvlist_dst != 0 &&
2243 !zc->zc_objset_stats.dds_inconsistent &&
2244 dmu_objset_type(os) == DMU_OST_ZFS) {
2247 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2248 if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
2249 (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
2250 (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
2251 (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
2252 err = put_nvlist(zc, nv);
2255 err = SET_ERROR(ENOENT);
2257 dmu_objset_rele(os, FTAG);
2262 dataset_name_hidden(const char *name)
2265 * Skip over datasets that are not visible in this zone,
2266 * internal datasets (which have a $ in their name), and
2267 * temporary datasets (which have a % in their name).
2269 if (strchr(name, '$') != NULL)
2271 if (strchr(name, '%') != NULL)
2273 if (!INGLOBALZONE(curthread) && !zone_dataset_visible(name, NULL))
2280 * zc_name name of filesystem
2281 * zc_cookie zap cursor
2282 * zc_nvlist_dst_size size of buffer for property nvlist
2285 * zc_name name of next filesystem
2286 * zc_cookie zap cursor
2287 * zc_objset_stats stats
2288 * zc_nvlist_dst property nvlist
2289 * zc_nvlist_dst_size size of property nvlist
2292 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
2297 size_t orig_len = strlen(zc->zc_name);
2300 if (error = dmu_objset_hold(zc->zc_name, FTAG, &os)) {
2301 if (error == ENOENT)
2302 error = SET_ERROR(ESRCH);
2306 p = strrchr(zc->zc_name, '/');
2307 if (p == NULL || p[1] != '\0')
2308 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
2309 p = zc->zc_name + strlen(zc->zc_name);
2312 error = dmu_dir_list_next(os,
2313 sizeof (zc->zc_name) - (p - zc->zc_name), p,
2314 NULL, &zc->zc_cookie);
2315 if (error == ENOENT)
2316 error = SET_ERROR(ESRCH);
2317 } while (error == 0 && dataset_name_hidden(zc->zc_name));
2318 dmu_objset_rele(os, FTAG);
2321 * If it's an internal dataset (ie. with a '$' in its name),
2322 * don't try to get stats for it, otherwise we'll return ENOENT.
2324 if (error == 0 && strchr(zc->zc_name, '$') == NULL) {
2325 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
2326 if (error == ENOENT) {
2327 /* We lost a race with destroy, get the next one. */
2328 zc->zc_name[orig_len] = '\0';
2337 * zc_name name of filesystem
2338 * zc_cookie zap cursor
2339 * zc_nvlist_dst_size size of buffer for property nvlist
2340 * zc_simple when set, only name is requested
2343 * zc_name name of next snapshot
2344 * zc_objset_stats stats
2345 * zc_nvlist_dst property nvlist
2346 * zc_nvlist_dst_size size of property nvlist
2349 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
2354 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
2356 return (error == ENOENT ? ESRCH : error);
2360 * A dataset name of maximum length cannot have any snapshots,
2361 * so exit immediately.
2363 if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >=
2364 ZFS_MAX_DATASET_NAME_LEN) {
2365 dmu_objset_rele(os, FTAG);
2366 return (SET_ERROR(ESRCH));
2369 error = dmu_snapshot_list_next(os,
2370 sizeof (zc->zc_name) - strlen(zc->zc_name),
2371 zc->zc_name + strlen(zc->zc_name), &zc->zc_obj, &zc->zc_cookie,
2374 if (error == 0 && !zc->zc_simple) {
2376 dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
2378 error = dsl_dataset_hold_obj(dp, zc->zc_obj, FTAG, &ds);
2382 error = dmu_objset_from_ds(ds, &ossnap);
2384 error = zfs_ioc_objset_stats_impl(zc, ossnap);
2385 dsl_dataset_rele(ds, FTAG);
2387 } else if (error == ENOENT) {
2388 error = SET_ERROR(ESRCH);
2391 dmu_objset_rele(os, FTAG);
2392 /* if we failed, undo the @ that we tacked on to zc_name */
2394 *strchr(zc->zc_name, '@') = '\0';
2399 zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
2401 const char *propname = nvpair_name(pair);
2403 unsigned int vallen;
2406 zfs_userquota_prop_t type;
2412 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2414 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2415 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2417 return (SET_ERROR(EINVAL));
2421 * A correctly constructed propname is encoded as
2422 * userquota@<rid>-<domain>.
2424 if ((dash = strchr(propname, '-')) == NULL ||
2425 nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
2427 return (SET_ERROR(EINVAL));
2434 err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_FALSE);
2436 err = zfs_set_userquota(zfsvfs, type, domain, rid, quota);
2437 zfsvfs_rele(zfsvfs, FTAG);
2444 * If the named property is one that has a special function to set its value,
2445 * return 0 on success and a positive error code on failure; otherwise if it is
2446 * not one of the special properties handled by this function, return -1.
2448 * XXX: It would be better for callers of the property interface if we handled
2449 * these special cases in dsl_prop.c (in the dsl layer).
2452 zfs_prop_set_special(const char *dsname, zprop_source_t source,
2455 const char *propname = nvpair_name(pair);
2456 zfs_prop_t prop = zfs_name_to_prop(propname);
2460 if (prop == ZPROP_INVAL) {
2461 if (zfs_prop_userquota(propname))
2462 return (zfs_prop_set_userquota(dsname, pair));
2466 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2468 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2469 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2473 if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
2476 VERIFY(0 == nvpair_value_uint64(pair, &intval));
2479 case ZFS_PROP_QUOTA:
2480 err = dsl_dir_set_quota(dsname, source, intval);
2482 case ZFS_PROP_REFQUOTA:
2483 err = dsl_dataset_set_refquota(dsname, source, intval);
2485 case ZFS_PROP_FILESYSTEM_LIMIT:
2486 case ZFS_PROP_SNAPSHOT_LIMIT:
2487 if (intval == UINT64_MAX) {
2488 /* clearing the limit, just do it */
2491 err = dsl_dir_activate_fs_ss_limit(dsname);
2494 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2495 * default path to set the value in the nvlist.
2500 case ZFS_PROP_RESERVATION:
2501 err = dsl_dir_set_reservation(dsname, source, intval);
2503 case ZFS_PROP_REFRESERVATION:
2504 err = dsl_dataset_set_refreservation(dsname, source, intval);
2506 case ZFS_PROP_VOLSIZE:
2507 err = zvol_set_volsize(dsname, intval);
2509 case ZFS_PROP_VERSION:
2513 if ((err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_TRUE)) != 0)
2516 err = zfs_set_version(zfsvfs, intval);
2517 zfsvfs_rele(zfsvfs, FTAG);
2519 if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
2522 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
2523 (void) strcpy(zc->zc_name, dsname);
2524 (void) zfs_ioc_userspace_upgrade(zc);
2525 kmem_free(zc, sizeof (zfs_cmd_t));
2537 * This function is best effort. If it fails to set any of the given properties,
2538 * it continues to set as many as it can and returns the last error
2539 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2540 * with the list of names of all the properties that failed along with the
2541 * corresponding error numbers.
2543 * If every property is set successfully, zero is returned and errlist is not
2547 zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
2555 nvlist_t *genericnvl = fnvlist_alloc();
2556 nvlist_t *retrynvl = fnvlist_alloc();
2560 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2561 const char *propname = nvpair_name(pair);
2562 zfs_prop_t prop = zfs_name_to_prop(propname);
2565 /* decode the property value */
2567 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2569 attrs = fnvpair_value_nvlist(pair);
2570 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2572 err = SET_ERROR(EINVAL);
2575 /* Validate value type */
2576 if (err == 0 && prop == ZPROP_INVAL) {
2577 if (zfs_prop_user(propname)) {
2578 if (nvpair_type(propval) != DATA_TYPE_STRING)
2579 err = SET_ERROR(EINVAL);
2580 } else if (zfs_prop_userquota(propname)) {
2581 if (nvpair_type(propval) !=
2582 DATA_TYPE_UINT64_ARRAY)
2583 err = SET_ERROR(EINVAL);
2585 err = SET_ERROR(EINVAL);
2587 } else if (err == 0) {
2588 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2589 if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
2590 err = SET_ERROR(EINVAL);
2591 } else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
2594 intval = fnvpair_value_uint64(propval);
2596 switch (zfs_prop_get_type(prop)) {
2597 case PROP_TYPE_NUMBER:
2599 case PROP_TYPE_STRING:
2600 err = SET_ERROR(EINVAL);
2602 case PROP_TYPE_INDEX:
2603 if (zfs_prop_index_to_string(prop,
2604 intval, &unused) != 0)
2605 err = SET_ERROR(EINVAL);
2609 "unknown property type");
2612 err = SET_ERROR(EINVAL);
2616 /* Validate permissions */
2618 err = zfs_check_settable(dsname, pair, CRED());
2621 err = zfs_prop_set_special(dsname, source, pair);
2624 * For better performance we build up a list of
2625 * properties to set in a single transaction.
2627 err = nvlist_add_nvpair(genericnvl, pair);
2628 } else if (err != 0 && nvl != retrynvl) {
2630 * This may be a spurious error caused by
2631 * receiving quota and reservation out of order.
2632 * Try again in a second pass.
2634 err = nvlist_add_nvpair(retrynvl, pair);
2639 if (errlist != NULL)
2640 fnvlist_add_int32(errlist, propname, err);
2645 if (nvl != retrynvl && !nvlist_empty(retrynvl)) {
2650 if (!nvlist_empty(genericnvl) &&
2651 dsl_props_set(dsname, source, genericnvl) != 0) {
2653 * If this fails, we still want to set as many properties as we
2654 * can, so try setting them individually.
2657 while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) {
2658 const char *propname = nvpair_name(pair);
2662 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2664 attrs = fnvpair_value_nvlist(pair);
2665 propval = fnvlist_lookup_nvpair(attrs,
2669 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2670 strval = fnvpair_value_string(propval);
2671 err = dsl_prop_set_string(dsname, propname,
2674 intval = fnvpair_value_uint64(propval);
2675 err = dsl_prop_set_int(dsname, propname, source,
2680 if (errlist != NULL) {
2681 fnvlist_add_int32(errlist, propname,
2688 nvlist_free(genericnvl);
2689 nvlist_free(retrynvl);
2695 * Check that all the properties are valid user properties.
2698 zfs_check_userprops(const char *fsname, nvlist_t *nvl)
2700 nvpair_t *pair = NULL;
2703 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2704 const char *propname = nvpair_name(pair);
2706 if (!zfs_prop_user(propname) ||
2707 nvpair_type(pair) != DATA_TYPE_STRING)
2708 return (SET_ERROR(EINVAL));
2710 if (error = zfs_secpolicy_write_perms(fsname,
2711 ZFS_DELEG_PERM_USERPROP, CRED()))
2714 if (strlen(propname) >= ZAP_MAXNAMELEN)
2715 return (SET_ERROR(ENAMETOOLONG));
2717 if (strlen(fnvpair_value_string(pair)) >= ZAP_MAXVALUELEN)
2724 props_skip(nvlist_t *props, nvlist_t *skipped, nvlist_t **newprops)
2728 VERIFY(nvlist_alloc(newprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2731 while ((pair = nvlist_next_nvpair(props, pair)) != NULL) {
2732 if (nvlist_exists(skipped, nvpair_name(pair)))
2735 VERIFY(nvlist_add_nvpair(*newprops, pair) == 0);
2740 clear_received_props(const char *dsname, nvlist_t *props,
2744 nvlist_t *cleared_props = NULL;
2745 props_skip(props, skipped, &cleared_props);
2746 if (!nvlist_empty(cleared_props)) {
2748 * Acts on local properties until the dataset has received
2749 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2751 zprop_source_t flags = (ZPROP_SRC_NONE |
2752 (dsl_prop_get_hasrecvd(dsname) ? ZPROP_SRC_RECEIVED : 0));
2753 err = zfs_set_prop_nvlist(dsname, flags, cleared_props, NULL);
2755 nvlist_free(cleared_props);
2761 * zc_name name of filesystem
2762 * zc_value name of property to set
2763 * zc_nvlist_src{_size} nvlist of properties to apply
2764 * zc_cookie received properties flag
2767 * zc_nvlist_dst{_size} error for each unapplied received property
2770 zfs_ioc_set_prop(zfs_cmd_t *zc)
2773 boolean_t received = zc->zc_cookie;
2774 zprop_source_t source = (received ? ZPROP_SRC_RECEIVED :
2779 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2780 zc->zc_iflags, &nvl)) != 0)
2784 nvlist_t *origprops;
2786 if (dsl_prop_get_received(zc->zc_name, &origprops) == 0) {
2787 (void) clear_received_props(zc->zc_name,
2789 nvlist_free(origprops);
2792 error = dsl_prop_set_hasrecvd(zc->zc_name);
2795 errors = fnvlist_alloc();
2797 error = zfs_set_prop_nvlist(zc->zc_name, source, nvl, errors);
2799 if (zc->zc_nvlist_dst != 0 && errors != NULL) {
2800 (void) put_nvlist(zc, errors);
2803 nvlist_free(errors);
2810 * zc_name name of filesystem
2811 * zc_value name of property to inherit
2812 * zc_cookie revert to received value if TRUE
2817 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
2819 const char *propname = zc->zc_value;
2820 zfs_prop_t prop = zfs_name_to_prop(propname);
2821 boolean_t received = zc->zc_cookie;
2822 zprop_source_t source = (received
2823 ? ZPROP_SRC_NONE /* revert to received value, if any */
2824 : ZPROP_SRC_INHERITED); /* explicitly inherit */
2833 * zfs_prop_set_special() expects properties in the form of an
2834 * nvpair with type info.
2836 if (prop == ZPROP_INVAL) {
2837 if (!zfs_prop_user(propname))
2838 return (SET_ERROR(EINVAL));
2840 type = PROP_TYPE_STRING;
2841 } else if (prop == ZFS_PROP_VOLSIZE ||
2842 prop == ZFS_PROP_VERSION) {
2843 return (SET_ERROR(EINVAL));
2845 type = zfs_prop_get_type(prop);
2848 VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2851 case PROP_TYPE_STRING:
2852 VERIFY(0 == nvlist_add_string(dummy, propname, ""));
2854 case PROP_TYPE_NUMBER:
2855 case PROP_TYPE_INDEX:
2856 VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
2860 return (SET_ERROR(EINVAL));
2863 pair = nvlist_next_nvpair(dummy, NULL);
2864 err = zfs_prop_set_special(zc->zc_name, source, pair);
2867 return (err); /* special property already handled */
2870 * Only check this in the non-received case. We want to allow
2871 * 'inherit -S' to revert non-inheritable properties like quota
2872 * and reservation to the received or default values even though
2873 * they are not considered inheritable.
2875 if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
2876 return (SET_ERROR(EINVAL));
2879 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2880 return (dsl_prop_inherit(zc->zc_name, zc->zc_value, source));
2884 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
2891 if (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2892 zc->zc_iflags, &props))
2896 * If the only property is the configfile, then just do a spa_lookup()
2897 * to handle the faulted case.
2899 pair = nvlist_next_nvpair(props, NULL);
2900 if (pair != NULL && strcmp(nvpair_name(pair),
2901 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
2902 nvlist_next_nvpair(props, pair) == NULL) {
2903 mutex_enter(&spa_namespace_lock);
2904 if ((spa = spa_lookup(zc->zc_name)) != NULL) {
2905 spa_configfile_set(spa, props, B_FALSE);
2906 spa_config_sync(spa, B_FALSE, B_TRUE);
2908 mutex_exit(&spa_namespace_lock);
2915 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2920 error = spa_prop_set(spa, props);
2923 spa_close(spa, FTAG);
2929 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
2933 nvlist_t *nvp = NULL;
2935 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2937 * If the pool is faulted, there may be properties we can still
2938 * get (such as altroot and cachefile), so attempt to get them
2941 mutex_enter(&spa_namespace_lock);
2942 if ((spa = spa_lookup(zc->zc_name)) != NULL)
2943 error = spa_prop_get(spa, &nvp);
2944 mutex_exit(&spa_namespace_lock);
2946 error = spa_prop_get(spa, &nvp);
2947 spa_close(spa, FTAG);
2950 if (error == 0 && zc->zc_nvlist_dst != 0)
2951 error = put_nvlist(zc, nvp);
2953 error = SET_ERROR(EFAULT);
2961 * zc_name name of filesystem
2962 * zc_nvlist_src{_size} nvlist of delegated permissions
2963 * zc_perm_action allow/unallow flag
2968 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
2971 nvlist_t *fsaclnv = NULL;
2973 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2974 zc->zc_iflags, &fsaclnv)) != 0)
2978 * Verify nvlist is constructed correctly
2980 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
2981 nvlist_free(fsaclnv);
2982 return (SET_ERROR(EINVAL));
2986 * If we don't have PRIV_SYS_MOUNT, then validate
2987 * that user is allowed to hand out each permission in
2991 error = secpolicy_zfs(CRED());
2993 if (zc->zc_perm_action == B_FALSE) {
2994 error = dsl_deleg_can_allow(zc->zc_name,
2997 error = dsl_deleg_can_unallow(zc->zc_name,
3003 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
3005 nvlist_free(fsaclnv);
3011 * zc_name name of filesystem
3014 * zc_nvlist_src{_size} nvlist of delegated permissions
3017 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
3022 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
3023 error = put_nvlist(zc, nvp);
3031 * Search the vfs list for a specified resource. Returns a pointer to it
3032 * or NULL if no suitable entry is found. The caller of this routine
3033 * is responsible for releasing the returned vfs pointer.
3036 zfs_get_vfs(const char *resource)
3040 mtx_lock(&mountlist_mtx);
3041 TAILQ_FOREACH(vfsp, &mountlist, mnt_list) {
3042 if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
3043 if (vfs_busy(vfsp, MBF_MNTLSTLOCK) != 0)
3049 mtx_unlock(&mountlist_mtx);
3055 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
3057 zfs_creat_t *zct = arg;
3059 zfs_create_fs(os, cr, zct->zct_zplprops, tx);
3062 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
3066 * os parent objset pointer (NULL if root fs)
3067 * fuids_ok fuids allowed in this version of the spa?
3068 * sa_ok SAs allowed in this version of the spa?
3069 * createprops list of properties requested by creator
3072 * zplprops values for the zplprops we attach to the master node object
3073 * is_ci true if requested file system will be purely case-insensitive
3075 * Determine the settings for utf8only, normalization and
3076 * casesensitivity. Specific values may have been requested by the
3077 * creator and/or we can inherit values from the parent dataset. If
3078 * the file system is of too early a vintage, a creator can not
3079 * request settings for these properties, even if the requested
3080 * setting is the default value. We don't actually want to create dsl
3081 * properties for these, so remove them from the source nvlist after
3085 zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
3086 boolean_t fuids_ok, boolean_t sa_ok, nvlist_t *createprops,
3087 nvlist_t *zplprops, boolean_t *is_ci)
3089 uint64_t sense = ZFS_PROP_UNDEFINED;
3090 uint64_t norm = ZFS_PROP_UNDEFINED;
3091 uint64_t u8 = ZFS_PROP_UNDEFINED;
3093 ASSERT(zplprops != NULL);
3096 * Pull out creator prop choices, if any.
3099 (void) nvlist_lookup_uint64(createprops,
3100 zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
3101 (void) nvlist_lookup_uint64(createprops,
3102 zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
3103 (void) nvlist_remove_all(createprops,
3104 zfs_prop_to_name(ZFS_PROP_NORMALIZE));
3105 (void) nvlist_lookup_uint64(createprops,
3106 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
3107 (void) nvlist_remove_all(createprops,
3108 zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
3109 (void) nvlist_lookup_uint64(createprops,
3110 zfs_prop_to_name(ZFS_PROP_CASE), &sense);
3111 (void) nvlist_remove_all(createprops,
3112 zfs_prop_to_name(ZFS_PROP_CASE));
3116 * If the zpl version requested is whacky or the file system
3117 * or pool is version is too "young" to support normalization
3118 * and the creator tried to set a value for one of the props,
3121 if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
3122 (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
3123 (zplver >= ZPL_VERSION_SA && !sa_ok) ||
3124 (zplver < ZPL_VERSION_NORMALIZATION &&
3125 (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
3126 sense != ZFS_PROP_UNDEFINED)))
3127 return (SET_ERROR(ENOTSUP));
3130 * Put the version in the zplprops
3132 VERIFY(nvlist_add_uint64(zplprops,
3133 zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
3135 if (norm == ZFS_PROP_UNDEFINED)
3136 VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
3137 VERIFY(nvlist_add_uint64(zplprops,
3138 zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
3141 * If we're normalizing, names must always be valid UTF-8 strings.
3145 if (u8 == ZFS_PROP_UNDEFINED)
3146 VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
3147 VERIFY(nvlist_add_uint64(zplprops,
3148 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
3150 if (sense == ZFS_PROP_UNDEFINED)
3151 VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
3152 VERIFY(nvlist_add_uint64(zplprops,
3153 zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
3156 *is_ci = (sense == ZFS_CASE_INSENSITIVE);
3162 zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
3163 nvlist_t *zplprops, boolean_t *is_ci)
3165 boolean_t fuids_ok, sa_ok;
3166 uint64_t zplver = ZPL_VERSION;
3167 objset_t *os = NULL;
3168 char parentname[ZFS_MAX_DATASET_NAME_LEN];
3174 (void) strlcpy(parentname, dataset, sizeof (parentname));
3175 cp = strrchr(parentname, '/');
3179 if ((error = spa_open(dataset, &spa, FTAG)) != 0)
3182 spa_vers = spa_version(spa);
3183 spa_close(spa, FTAG);
3185 zplver = zfs_zpl_version_map(spa_vers);
3186 fuids_ok = (zplver >= ZPL_VERSION_FUID);
3187 sa_ok = (zplver >= ZPL_VERSION_SA);
3190 * Open parent object set so we can inherit zplprop values.
3192 if ((error = dmu_objset_hold(parentname, FTAG, &os)) != 0)
3195 error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, sa_ok, createprops,
3197 dmu_objset_rele(os, FTAG);
3202 zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
3203 nvlist_t *zplprops, boolean_t *is_ci)
3207 uint64_t zplver = ZPL_VERSION;
3210 zplver = zfs_zpl_version_map(spa_vers);
3211 fuids_ok = (zplver >= ZPL_VERSION_FUID);
3212 sa_ok = (zplver >= ZPL_VERSION_SA);
3214 error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, sa_ok,
3215 createprops, zplprops, is_ci);
3221 * "type" -> dmu_objset_type_t (int32)
3222 * (optional) "props" -> { prop -> value }
3225 * outnvl: propname -> error code (int32)
3228 zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3231 zfs_creat_t zct = { 0 };
3232 nvlist_t *nvprops = NULL;
3233 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
3235 dmu_objset_type_t type;
3236 boolean_t is_insensitive = B_FALSE;
3238 if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
3239 return (SET_ERROR(EINVAL));
3241 (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
3245 cbfunc = zfs_create_cb;
3249 cbfunc = zvol_create_cb;
3256 if (strchr(fsname, '@') ||
3257 strchr(fsname, '%'))
3258 return (SET_ERROR(EINVAL));
3260 zct.zct_props = nvprops;
3263 return (SET_ERROR(EINVAL));
3265 if (type == DMU_OST_ZVOL) {
3266 uint64_t volsize, volblocksize;
3268 if (nvprops == NULL)
3269 return (SET_ERROR(EINVAL));
3270 if (nvlist_lookup_uint64(nvprops,
3271 zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) != 0)
3272 return (SET_ERROR(EINVAL));
3274 if ((error = nvlist_lookup_uint64(nvprops,
3275 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
3276 &volblocksize)) != 0 && error != ENOENT)
3277 return (SET_ERROR(EINVAL));
3280 volblocksize = zfs_prop_default_numeric(
3281 ZFS_PROP_VOLBLOCKSIZE);
3283 if ((error = zvol_check_volblocksize(
3284 volblocksize)) != 0 ||
3285 (error = zvol_check_volsize(volsize,
3286 volblocksize)) != 0)
3288 } else if (type == DMU_OST_ZFS) {
3292 * We have to have normalization and
3293 * case-folding flags correct when we do the
3294 * file system creation, so go figure them out
3297 VERIFY(nvlist_alloc(&zct.zct_zplprops,
3298 NV_UNIQUE_NAME, KM_SLEEP) == 0);
3299 error = zfs_fill_zplprops(fsname, nvprops,
3300 zct.zct_zplprops, &is_insensitive);
3302 nvlist_free(zct.zct_zplprops);
3307 error = dmu_objset_create(fsname, type,
3308 is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
3309 nvlist_free(zct.zct_zplprops);
3312 * It would be nice to do this atomically.
3315 error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
3318 (void) dsl_destroy_head(fsname);
3321 if (error == 0 && type == DMU_OST_ZVOL)
3322 zvol_create_minors(fsname);
3329 * "origin" -> name of origin snapshot
3330 * (optional) "props" -> { prop -> value }
3333 * outnvl: propname -> error code (int32)
3336 zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3339 nvlist_t *nvprops = NULL;
3342 if (nvlist_lookup_string(innvl, "origin", &origin_name) != 0)
3343 return (SET_ERROR(EINVAL));
3344 (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
3346 if (strchr(fsname, '@') ||
3347 strchr(fsname, '%'))
3348 return (SET_ERROR(EINVAL));
3350 if (dataset_namecheck(origin_name, NULL, NULL) != 0)
3351 return (SET_ERROR(EINVAL));
3352 error = dmu_objset_clone(fsname, origin_name);
3357 * It would be nice to do this atomically.
3360 error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
3363 (void) dsl_destroy_head(fsname);
3367 zvol_create_minors(fsname);
3374 * "snaps" -> { snapshot1, snapshot2 }
3375 * (optional) "props" -> { prop -> value (string) }
3378 * outnvl: snapshot -> error code (int32)
3381 zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3384 nvlist_t *props = NULL;
3388 (void) nvlist_lookup_nvlist(innvl, "props", &props);
3389 if ((error = zfs_check_userprops(poolname, props)) != 0)
3392 if (!nvlist_empty(props) &&
3393 zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
3394 return (SET_ERROR(ENOTSUP));
3396 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
3397 return (SET_ERROR(EINVAL));
3398 poollen = strlen(poolname);
3399 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
3400 pair = nvlist_next_nvpair(snaps, pair)) {
3401 const char *name = nvpair_name(pair);
3402 const char *cp = strchr(name, '@');
3405 * The snap name must contain an @, and the part after it must
3406 * contain only valid characters.
3409 zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
3410 return (SET_ERROR(EINVAL));
3413 * The snap must be in the specified pool.
3415 if (strncmp(name, poolname, poollen) != 0 ||
3416 (name[poollen] != '/' && name[poollen] != '@'))
3417 return (SET_ERROR(EXDEV));
3419 /* This must be the only snap of this fs. */
3420 for (nvpair_t *pair2 = nvlist_next_nvpair(snaps, pair);
3421 pair2 != NULL; pair2 = nvlist_next_nvpair(snaps, pair2)) {
3422 if (strncmp(name, nvpair_name(pair2), cp - name + 1)
3424 return (SET_ERROR(EXDEV));
3429 error = dsl_dataset_snapshot(snaps, props, outnvl);
3434 * innvl: "message" -> string
3438 zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
3446 * The poolname in the ioctl is not set, we get it from the TSD,
3447 * which was set at the end of the last successful ioctl that allows
3448 * logging. The secpolicy func already checked that it is set.
3449 * Only one log ioctl is allowed after each successful ioctl, so
3450 * we clear the TSD here.
3452 poolname = tsd_get(zfs_allow_log_key);
3453 (void) tsd_set(zfs_allow_log_key, NULL);
3454 error = spa_open(poolname, &spa, FTAG);
3459 if (nvlist_lookup_string(innvl, "message", &message) != 0) {
3460 spa_close(spa, FTAG);
3461 return (SET_ERROR(EINVAL));
3464 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
3465 spa_close(spa, FTAG);
3466 return (SET_ERROR(ENOTSUP));
3469 error = spa_history_log(spa, message);
3470 spa_close(spa, FTAG);
3476 zfs_ioc_nextboot(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
3478 char name[MAXNAMELEN];
3486 if (nvlist_lookup_uint64(innvl,
3487 ZPOOL_CONFIG_POOL_GUID, &pool_guid) != 0)
3489 if (nvlist_lookup_uint64(innvl,
3490 ZPOOL_CONFIG_GUID, &vdev_guid) != 0)
3492 if (nvlist_lookup_string(innvl,
3493 "command", &command) != 0)
3496 mutex_enter(&spa_namespace_lock);
3497 spa = spa_by_guid(pool_guid, vdev_guid);
3499 strcpy(name, spa_name(spa));
3500 mutex_exit(&spa_namespace_lock);
3504 if ((error = spa_open(name, &spa, FTAG)) != 0)
3506 spa_vdev_state_enter(spa, SCL_ALL);
3507 vd = spa_lookup_by_guid(spa, vdev_guid, B_TRUE);
3509 (void) spa_vdev_state_exit(spa, NULL, ENXIO);
3510 spa_close(spa, FTAG);
3513 error = vdev_label_write_pad2(vd, command, strlen(command));
3514 (void) spa_vdev_state_exit(spa, NULL, 0);
3515 txg_wait_synced(spa->spa_dsl_pool, 0);
3516 spa_close(spa, FTAG);
3522 * The dp_config_rwlock must not be held when calling this, because the
3523 * unmount may need to write out data.
3525 * This function is best-effort. Callers must deal gracefully if it
3526 * remains mounted (or is remounted after this call).
3528 * Returns 0 if the argument is not a snapshot, or it is not currently a
3529 * filesystem, or we were able to unmount it. Returns error code otherwise.
3532 zfs_unmount_snap(const char *snapname)
3538 if (strchr(snapname, '@') == NULL)
3541 vfsp = zfs_get_vfs(snapname);
3545 zfsvfs = vfsp->vfs_data;
3546 ASSERT(!dsl_pool_config_held(dmu_objset_pool(zfsvfs->z_os)));
3548 err = vn_vfswlock(vfsp->vfs_vnodecovered);
3555 return (SET_ERROR(err));
3558 * Always force the unmount for snapshots.
3562 (void) dounmount(vfsp, MS_FORCE, kcred);
3565 (void) dounmount(vfsp, MS_FORCE, curthread);
3572 zfs_unmount_snap_cb(const char *snapname, void *arg)
3574 return (zfs_unmount_snap(snapname));
3578 * When a clone is destroyed, its origin may also need to be destroyed,
3579 * in which case it must be unmounted. This routine will do that unmount
3583 zfs_destroy_unmount_origin(const char *fsname)
3589 error = dmu_objset_hold(fsname, FTAG, &os);
3592 ds = dmu_objset_ds(os);
3593 if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev)) {
3594 char originname[ZFS_MAX_DATASET_NAME_LEN];
3595 dsl_dataset_name(ds->ds_prev, originname);
3596 dmu_objset_rele(os, FTAG);
3597 (void) zfs_unmount_snap(originname);
3599 dmu_objset_rele(os, FTAG);
3605 * "snaps" -> { snapshot1, snapshot2 }
3606 * (optional boolean) "defer"
3609 * outnvl: snapshot -> error code (int32)
3614 zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3621 if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
3622 return (SET_ERROR(EINVAL));
3623 defer = nvlist_exists(innvl, "defer");
3625 poollen = strlen(poolname);
3626 for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
3627 pair = nvlist_next_nvpair(snaps, pair)) {
3628 const char *name = nvpair_name(pair);
3631 * The snap must be in the specified pool to prevent the
3632 * invalid removal of zvol minors below.
3634 if (strncmp(name, poolname, poollen) != 0 ||
3635 (name[poollen] != '/' && name[poollen] != '@'))
3636 return (SET_ERROR(EXDEV));
3638 error = zfs_unmount_snap(name);
3641 #if defined(__FreeBSD__)
3642 zvol_remove_minors(name);
3646 return (dsl_destroy_snapshots_nvl(snaps, defer, outnvl));
3650 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3651 * All bookmarks must be in the same pool.
3654 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3657 * outnvl: bookmark -> error code (int32)
3662 zfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
3664 for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
3665 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
3669 * Verify the snapshot argument.
3671 if (nvpair_value_string(pair, &snap_name) != 0)
3672 return (SET_ERROR(EINVAL));
3675 /* Verify that the keys (bookmarks) are unique */
3676 for (nvpair_t *pair2 = nvlist_next_nvpair(innvl, pair);
3677 pair2 != NULL; pair2 = nvlist_next_nvpair(innvl, pair2)) {
3678 if (strcmp(nvpair_name(pair), nvpair_name(pair2)) == 0)
3679 return (SET_ERROR(EINVAL));
3683 return (dsl_bookmark_create(innvl, outnvl));
3688 * property 1, property 2, ...
3692 * bookmark name 1 -> { property 1, property 2, ... },
3693 * bookmark name 2 -> { property 1, property 2, ... }
3698 zfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
3700 return (dsl_get_bookmarks(fsname, innvl, outnvl));
3705 * bookmark name 1, bookmark name 2
3708 * outnvl: bookmark -> error code (int32)
3712 zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
3717 poollen = strlen(poolname);
3718 for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
3719 pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
3720 const char *name = nvpair_name(pair);
3721 const char *cp = strchr(name, '#');
3724 * The bookmark name must contain an #, and the part after it
3725 * must contain only valid characters.
3728 zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
3729 return (SET_ERROR(EINVAL));
3732 * The bookmark must be in the specified pool.
3734 if (strncmp(name, poolname, poollen) != 0 ||
3735 (name[poollen] != '/' && name[poollen] != '#'))
3736 return (SET_ERROR(EXDEV));
3739 error = dsl_bookmark_destroy(innvl, outnvl);
3745 * zc_name name of dataset to destroy
3746 * zc_objset_type type of objset
3747 * zc_defer_destroy mark for deferred destroy
3752 zfs_ioc_destroy(zfs_cmd_t *zc)
3756 if (zc->zc_objset_type == DMU_OST_ZFS) {
3757 err = zfs_unmount_snap(zc->zc_name);
3762 if (strchr(zc->zc_name, '@'))
3763 err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
3765 err = dsl_destroy_head(zc->zc_name);
3766 if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
3768 zvol_remove_minors(zc->zc_name);
3770 (void) zvol_remove_minor(zc->zc_name);
3776 * fsname is name of dataset to rollback (to most recent snapshot)
3778 * innvl is not used.
3780 * outnvl: "target" -> name of most recent snapshot
3785 zfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
3790 if (getzfsvfs(fsname, &zfsvfs) == 0) {
3791 error = zfs_suspend_fs(zfsvfs);
3795 error = dsl_dataset_rollback(fsname, zfsvfs, outnvl);
3796 resume_err = zfs_resume_fs(zfsvfs, fsname);
3797 error = error ? error : resume_err;
3800 VFS_RELE(zfsvfs->z_vfs);
3802 vfs_unbusy(zfsvfs->z_vfs);
3805 error = dsl_dataset_rollback(fsname, NULL, outnvl);
3811 recursive_unmount(const char *fsname, void *arg)
3813 const char *snapname = arg;
3814 char fullname[ZFS_MAX_DATASET_NAME_LEN];
3816 (void) snprintf(fullname, sizeof (fullname), "%s@%s", fsname, snapname);
3817 return (zfs_unmount_snap(fullname));
3822 * zc_name old name of dataset
3823 * zc_value new name of dataset
3824 * zc_cookie recursive flag (only valid for snapshots)
3829 zfs_ioc_rename(zfs_cmd_t *zc)
3831 boolean_t recursive = zc->zc_cookie & 1;
3833 boolean_t allow_mounted = B_TRUE;
3836 allow_mounted = (zc->zc_cookie & 2) != 0;
3839 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
3840 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
3841 strchr(zc->zc_value, '%'))
3842 return (SET_ERROR(EINVAL));
3844 at = strchr(zc->zc_name, '@');
3846 /* snaps must be in same fs */
3849 if (strncmp(zc->zc_name, zc->zc_value, at - zc->zc_name + 1))
3850 return (SET_ERROR(EXDEV));
3852 if (zc->zc_objset_type == DMU_OST_ZFS && !allow_mounted) {
3853 error = dmu_objset_find(zc->zc_name,
3854 recursive_unmount, at + 1,
3855 recursive ? DS_FIND_CHILDREN : 0);
3861 error = dsl_dataset_rename_snapshot(zc->zc_name,
3862 at + 1, strchr(zc->zc_value, '@') + 1, recursive);
3868 if (zc->zc_objset_type == DMU_OST_ZVOL)
3869 (void) zvol_remove_minor(zc->zc_name);
3871 return (dsl_dir_rename(zc->zc_name, zc->zc_value));
3876 zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
3878 const char *propname = nvpair_name(pair);
3879 boolean_t issnap = (strchr(dsname, '@') != NULL);
3880 zfs_prop_t prop = zfs_name_to_prop(propname);
3884 if (prop == ZPROP_INVAL) {
3885 if (zfs_prop_user(propname)) {
3886 if (err = zfs_secpolicy_write_perms(dsname,
3887 ZFS_DELEG_PERM_USERPROP, cr))
3892 if (!issnap && zfs_prop_userquota(propname)) {
3893 const char *perm = NULL;
3894 const char *uq_prefix =
3895 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA];
3896 const char *gq_prefix =
3897 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA];
3899 if (strncmp(propname, uq_prefix,
3900 strlen(uq_prefix)) == 0) {
3901 perm = ZFS_DELEG_PERM_USERQUOTA;
3902 } else if (strncmp(propname, gq_prefix,
3903 strlen(gq_prefix)) == 0) {
3904 perm = ZFS_DELEG_PERM_GROUPQUOTA;
3906 /* USERUSED and GROUPUSED are read-only */
3907 return (SET_ERROR(EINVAL));
3910 if (err = zfs_secpolicy_write_perms(dsname, perm, cr))
3915 return (SET_ERROR(EINVAL));
3919 return (SET_ERROR(EINVAL));
3921 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
3923 * dsl_prop_get_all_impl() returns properties in this
3927 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
3928 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3933 * Check that this value is valid for this pool version
3936 case ZFS_PROP_COMPRESSION:
3938 * If the user specified gzip compression, make sure
3939 * the SPA supports it. We ignore any errors here since
3940 * we'll catch them later.
3942 if (nvpair_value_uint64(pair, &intval) == 0) {
3943 if (intval >= ZIO_COMPRESS_GZIP_1 &&
3944 intval <= ZIO_COMPRESS_GZIP_9 &&
3945 zfs_earlier_version(dsname,
3946 SPA_VERSION_GZIP_COMPRESSION)) {
3947 return (SET_ERROR(ENOTSUP));
3950 if (intval == ZIO_COMPRESS_ZLE &&
3951 zfs_earlier_version(dsname,
3952 SPA_VERSION_ZLE_COMPRESSION))
3953 return (SET_ERROR(ENOTSUP));
3955 if (intval == ZIO_COMPRESS_LZ4) {
3958 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
3961 if (!spa_feature_is_enabled(spa,
3962 SPA_FEATURE_LZ4_COMPRESS)) {
3963 spa_close(spa, FTAG);
3964 return (SET_ERROR(ENOTSUP));
3966 spa_close(spa, FTAG);
3970 * If this is a bootable dataset then
3971 * verify that the compression algorithm
3972 * is supported for booting. We must return
3973 * something other than ENOTSUP since it
3974 * implies a downrev pool version.
3976 if (zfs_is_bootfs(dsname) &&
3977 !BOOTFS_COMPRESS_VALID(intval)) {
3978 return (SET_ERROR(ERANGE));
3983 case ZFS_PROP_COPIES:
3984 if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
3985 return (SET_ERROR(ENOTSUP));
3988 case ZFS_PROP_RECORDSIZE:
3989 /* Record sizes above 128k need the feature to be enabled */
3990 if (nvpair_value_uint64(pair, &intval) == 0 &&
3991 intval > SPA_OLD_MAXBLOCKSIZE) {
3995 * If this is a bootable dataset then
3996 * the we don't allow large (>128K) blocks,
3997 * because GRUB doesn't support them.
3999 if (zfs_is_bootfs(dsname) &&
4000 intval > SPA_OLD_MAXBLOCKSIZE) {
4001 return (SET_ERROR(ERANGE));
4005 * We don't allow setting the property above 1MB,
4006 * unless the tunable has been changed.
4008 if (intval > zfs_max_recordsize ||
4009 intval > SPA_MAXBLOCKSIZE)
4010 return (SET_ERROR(ERANGE));
4012 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
4015 if (!spa_feature_is_enabled(spa,
4016 SPA_FEATURE_LARGE_BLOCKS)) {
4017 spa_close(spa, FTAG);
4018 return (SET_ERROR(ENOTSUP));
4020 spa_close(spa, FTAG);
4024 case ZFS_PROP_SHARESMB:
4025 if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
4026 return (SET_ERROR(ENOTSUP));
4029 case ZFS_PROP_ACLINHERIT:
4030 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
4031 nvpair_value_uint64(pair, &intval) == 0) {
4032 if (intval == ZFS_ACL_PASSTHROUGH_X &&
4033 zfs_earlier_version(dsname,
4034 SPA_VERSION_PASSTHROUGH_X))
4035 return (SET_ERROR(ENOTSUP));
4039 case ZFS_PROP_CHECKSUM:
4040 case ZFS_PROP_DEDUP:
4042 spa_feature_t feature;
4045 /* dedup feature version checks */
4046 if (prop == ZFS_PROP_DEDUP &&
4047 zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
4048 return (SET_ERROR(ENOTSUP));
4050 if (nvpair_value_uint64(pair, &intval) != 0)
4051 return (SET_ERROR(EINVAL));
4053 /* check prop value is enabled in features */
4054 feature = zio_checksum_to_feature(intval & ZIO_CHECKSUM_MASK);
4055 if (feature == SPA_FEATURE_NONE)
4058 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
4061 * Salted checksums are not supported on root pools.
4063 if (spa_bootfs(spa) != 0 &&
4064 intval < ZIO_CHECKSUM_FUNCTIONS &&
4065 (zio_checksum_table[intval].ci_flags &
4066 ZCHECKSUM_FLAG_SALTED)) {
4067 spa_close(spa, FTAG);
4068 return (SET_ERROR(ERANGE));
4070 if (!spa_feature_is_enabled(spa, feature)) {
4071 spa_close(spa, FTAG);
4072 return (SET_ERROR(ENOTSUP));
4074 spa_close(spa, FTAG);
4079 return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
4083 * Checks for a race condition to make sure we don't increment a feature flag
4087 zfs_prop_activate_feature_check(void *arg, dmu_tx_t *tx)
4089 spa_t *spa = dmu_tx_pool(tx)->dp_spa;
4090 spa_feature_t *featurep = arg;
4092 if (!spa_feature_is_active(spa, *featurep))
4095 return (SET_ERROR(EBUSY));
4099 * The callback invoked on feature activation in the sync task caused by
4100 * zfs_prop_activate_feature.
4103 zfs_prop_activate_feature_sync(void *arg, dmu_tx_t *tx)
4105 spa_t *spa = dmu_tx_pool(tx)->dp_spa;
4106 spa_feature_t *featurep = arg;
4108 spa_feature_incr(spa, *featurep, tx);
4112 * Activates a feature on a pool in response to a property setting. This
4113 * creates a new sync task which modifies the pool to reflect the feature
4117 zfs_prop_activate_feature(spa_t *spa, spa_feature_t feature)
4121 /* EBUSY here indicates that the feature is already active */
4122 err = dsl_sync_task(spa_name(spa),
4123 zfs_prop_activate_feature_check, zfs_prop_activate_feature_sync,
4124 &feature, 2, ZFS_SPACE_CHECK_RESERVED);
4126 if (err != 0 && err != EBUSY)
4133 * Removes properties from the given props list that fail permission checks
4134 * needed to clear them and to restore them in case of a receive error. For each
4135 * property, make sure we have both set and inherit permissions.
4137 * Returns the first error encountered if any permission checks fail. If the
4138 * caller provides a non-NULL errlist, it also gives the complete list of names
4139 * of all the properties that failed a permission check along with the
4140 * corresponding error numbers. The caller is responsible for freeing the
4143 * If every property checks out successfully, zero is returned and the list
4144 * pointed at by errlist is NULL.
4147 zfs_check_clearable(char *dataset, nvlist_t *props, nvlist_t **errlist)
4150 nvpair_t *pair, *next_pair;
4157 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
4159 zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
4160 (void) strcpy(zc->zc_name, dataset);
4161 pair = nvlist_next_nvpair(props, NULL);
4162 while (pair != NULL) {
4163 next_pair = nvlist_next_nvpair(props, pair);
4165 (void) strcpy(zc->zc_value, nvpair_name(pair));
4166 if ((err = zfs_check_settable(dataset, pair, CRED())) != 0 ||
4167 (err = zfs_secpolicy_inherit_prop(zc, NULL, CRED())) != 0) {
4168 VERIFY(nvlist_remove_nvpair(props, pair) == 0);
4169 VERIFY(nvlist_add_int32(errors,
4170 zc->zc_value, err) == 0);
4174 kmem_free(zc, sizeof (zfs_cmd_t));
4176 if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
4177 nvlist_free(errors);
4180 VERIFY(nvpair_value_int32(pair, &rv) == 0);
4183 if (errlist == NULL)
4184 nvlist_free(errors);
4192 propval_equals(nvpair_t *p1, nvpair_t *p2)
4194 if (nvpair_type(p1) == DATA_TYPE_NVLIST) {
4195 /* dsl_prop_get_all_impl() format */
4197 VERIFY(nvpair_value_nvlist(p1, &attrs) == 0);
4198 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
4202 if (nvpair_type(p2) == DATA_TYPE_NVLIST) {
4204 VERIFY(nvpair_value_nvlist(p2, &attrs) == 0);
4205 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
4209 if (nvpair_type(p1) != nvpair_type(p2))
4212 if (nvpair_type(p1) == DATA_TYPE_STRING) {
4213 char *valstr1, *valstr2;
4215 VERIFY(nvpair_value_string(p1, (char **)&valstr1) == 0);
4216 VERIFY(nvpair_value_string(p2, (char **)&valstr2) == 0);
4217 return (strcmp(valstr1, valstr2) == 0);
4219 uint64_t intval1, intval2;
4221 VERIFY(nvpair_value_uint64(p1, &intval1) == 0);
4222 VERIFY(nvpair_value_uint64(p2, &intval2) == 0);
4223 return (intval1 == intval2);
4228 * Remove properties from props if they are not going to change (as determined
4229 * by comparison with origprops). Remove them from origprops as well, since we
4230 * do not need to clear or restore properties that won't change.
4233 props_reduce(nvlist_t *props, nvlist_t *origprops)
4235 nvpair_t *pair, *next_pair;
4237 if (origprops == NULL)
4238 return; /* all props need to be received */
4240 pair = nvlist_next_nvpair(props, NULL);
4241 while (pair != NULL) {
4242 const char *propname = nvpair_name(pair);
4245 next_pair = nvlist_next_nvpair(props, pair);
4247 if ((nvlist_lookup_nvpair(origprops, propname,
4248 &match) != 0) || !propval_equals(pair, match))
4249 goto next; /* need to set received value */
4251 /* don't clear the existing received value */
4252 (void) nvlist_remove_nvpair(origprops, match);
4253 /* don't bother receiving the property */
4254 (void) nvlist_remove_nvpair(props, pair);
4261 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4262 * For example, refquota cannot be set until after the receipt of a dataset,
4263 * because in replication streams, an older/earlier snapshot may exceed the
4264 * refquota. We want to receive the older/earlier snapshot, but setting
4265 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4266 * the older/earlier snapshot from being received (with EDQUOT).
4268 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4270 * libzfs will need to be judicious handling errors encountered by props
4271 * extracted by this function.
4274 extract_delay_props(nvlist_t *props)
4276 nvlist_t *delayprops;
4277 nvpair_t *nvp, *tmp;
4278 static const zfs_prop_t delayable[] = { ZFS_PROP_REFQUOTA, 0 };
4281 VERIFY(nvlist_alloc(&delayprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
4283 for (nvp = nvlist_next_nvpair(props, NULL); nvp != NULL;
4284 nvp = nvlist_next_nvpair(props, nvp)) {
4286 * strcmp() is safe because zfs_prop_to_name() always returns
4289 for (i = 0; delayable[i] != 0; i++) {
4290 if (strcmp(zfs_prop_to_name(delayable[i]),
4291 nvpair_name(nvp)) == 0) {
4295 if (delayable[i] != 0) {
4296 tmp = nvlist_prev_nvpair(props, nvp);
4297 VERIFY(nvlist_add_nvpair(delayprops, nvp) == 0);
4298 VERIFY(nvlist_remove_nvpair(props, nvp) == 0);
4303 if (nvlist_empty(delayprops)) {
4304 nvlist_free(delayprops);
4307 return (delayprops);
4311 static boolean_t zfs_ioc_recv_inject_err;
4316 * zc_name name of containing filesystem
4317 * zc_nvlist_src{_size} nvlist of properties to apply
4318 * zc_value name of snapshot to create
4319 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4320 * zc_cookie file descriptor to recv from
4321 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4322 * zc_guid force flag
4323 * zc_cleanup_fd cleanup-on-exit file descriptor
4324 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4325 * zc_resumable if data is incomplete assume sender will resume
4328 * zc_cookie number of bytes read
4329 * zc_nvlist_dst{_size} error for each unapplied received property
4330 * zc_obj zprop_errflags_t
4331 * zc_action_handle handle for this guid/ds mapping
4334 zfs_ioc_recv(zfs_cmd_t *zc)
4337 dmu_recv_cookie_t drc;
4338 boolean_t force = (boolean_t)zc->zc_guid;
4341 int props_error = 0;
4344 nvlist_t *props = NULL; /* sent properties */
4345 nvlist_t *origprops = NULL; /* existing properties */
4346 nvlist_t *delayprops = NULL; /* sent properties applied post-receive */
4347 char *origin = NULL;
4349 char tofs[ZFS_MAX_DATASET_NAME_LEN];
4350 cap_rights_t rights;
4351 boolean_t first_recvd_props = B_FALSE;
4353 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
4354 strchr(zc->zc_value, '@') == NULL ||
4355 strchr(zc->zc_value, '%'))
4356 return (SET_ERROR(EINVAL));
4358 (void) strcpy(tofs, zc->zc_value);
4359 tosnap = strchr(tofs, '@');
4362 if (zc->zc_nvlist_src != 0 &&
4363 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
4364 zc->zc_iflags, &props)) != 0)
4371 fget_read(curthread, fd, cap_rights_init(&rights, CAP_PREAD), &fp);
4375 return (SET_ERROR(EBADF));
4378 errors = fnvlist_alloc();
4380 if (zc->zc_string[0])
4381 origin = zc->zc_string;
4383 error = dmu_recv_begin(tofs, tosnap,
4384 &zc->zc_begin_record, force, zc->zc_resumable, origin, &drc);
4389 * Set properties before we receive the stream so that they are applied
4390 * to the new data. Note that we must call dmu_recv_stream() if
4391 * dmu_recv_begin() succeeds.
4393 if (props != NULL && !drc.drc_newfs) {
4394 if (spa_version(dsl_dataset_get_spa(drc.drc_ds)) >=
4395 SPA_VERSION_RECVD_PROPS &&
4396 !dsl_prop_get_hasrecvd(tofs))
4397 first_recvd_props = B_TRUE;
4400 * If new received properties are supplied, they are to
4401 * completely replace the existing received properties, so stash
4402 * away the existing ones.
4404 if (dsl_prop_get_received(tofs, &origprops) == 0) {
4405 nvlist_t *errlist = NULL;
4407 * Don't bother writing a property if its value won't
4408 * change (and avoid the unnecessary security checks).
4410 * The first receive after SPA_VERSION_RECVD_PROPS is a
4411 * special case where we blow away all local properties
4414 if (!first_recvd_props)
4415 props_reduce(props, origprops);
4416 if (zfs_check_clearable(tofs, origprops, &errlist) != 0)
4417 (void) nvlist_merge(errors, errlist, 0);
4418 nvlist_free(errlist);
4420 if (clear_received_props(tofs, origprops,
4421 first_recvd_props ? NULL : props) != 0)
4422 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
4424 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
4428 if (props != NULL) {
4429 props_error = dsl_prop_set_hasrecvd(tofs);
4431 if (props_error == 0) {
4432 delayprops = extract_delay_props(props);
4433 (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
4439 error = dmu_recv_stream(&drc, fp, &off, zc->zc_cleanup_fd,
4440 &zc->zc_action_handle);
4443 zfsvfs_t *zfsvfs = NULL;
4445 if (getzfsvfs(tofs, &zfsvfs) == 0) {
4449 error = zfs_suspend_fs(zfsvfs);
4451 * If the suspend fails, then the recv_end will
4452 * likely also fail, and clean up after itself.
4454 end_err = dmu_recv_end(&drc, zfsvfs);
4456 error = zfs_resume_fs(zfsvfs, tofs);
4457 error = error ? error : end_err;
4459 VFS_RELE(zfsvfs->z_vfs);
4461 vfs_unbusy(zfsvfs->z_vfs);
4464 error = dmu_recv_end(&drc, NULL);
4467 /* Set delayed properties now, after we're done receiving. */
4468 if (delayprops != NULL && error == 0) {
4469 (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
4470 delayprops, errors);
4474 if (delayprops != NULL) {
4476 * Merge delayed props back in with initial props, in case
4477 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4478 * we have to make sure clear_received_props() includes
4479 * the delayed properties).
4481 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4482 * using ASSERT() will be just like a VERIFY.
4484 ASSERT(nvlist_merge(props, delayprops, 0) == 0);
4485 nvlist_free(delayprops);
4489 * Now that all props, initial and delayed, are set, report the prop
4490 * errors to the caller.
4492 if (zc->zc_nvlist_dst_size != 0 &&
4493 (nvlist_smush(errors, zc->zc_nvlist_dst_size) != 0 ||
4494 put_nvlist(zc, errors) != 0)) {
4496 * Caller made zc->zc_nvlist_dst less than the minimum expected
4497 * size or supplied an invalid address.
4499 props_error = SET_ERROR(EINVAL);
4502 zc->zc_cookie = off - fp->f_offset;
4503 if (off >= 0 && off <= MAXOFFSET_T)
4507 if (zfs_ioc_recv_inject_err) {
4508 zfs_ioc_recv_inject_err = B_FALSE;
4515 zvol_create_minors(tofs);
4519 * On error, restore the original props.
4521 if (error != 0 && props != NULL && !drc.drc_newfs) {
4522 if (clear_received_props(tofs, props, NULL) != 0) {
4524 * We failed to clear the received properties.
4525 * Since we may have left a $recvd value on the
4526 * system, we can't clear the $hasrecvd flag.
4528 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4529 } else if (first_recvd_props) {
4530 dsl_prop_unset_hasrecvd(tofs);
4533 if (origprops == NULL && !drc.drc_newfs) {
4534 /* We failed to stash the original properties. */
4535 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4539 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4540 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4541 * explictly if we're restoring local properties cleared in the
4542 * first new-style receive.
4544 if (origprops != NULL &&
4545 zfs_set_prop_nvlist(tofs, (first_recvd_props ?
4546 ZPROP_SRC_LOCAL : ZPROP_SRC_RECEIVED),
4547 origprops, NULL) != 0) {
4549 * We stashed the original properties but failed to
4552 zc->zc_obj |= ZPROP_ERR_NORESTORE;
4557 nvlist_free(origprops);
4558 nvlist_free(errors);
4562 error = props_error;
4569 * zc_name name of snapshot to send
4570 * zc_cookie file descriptor to send stream to
4571 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4572 * zc_sendobj objsetid of snapshot to send
4573 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4574 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4575 * output size in zc_objset_type.
4576 * zc_flags lzc_send_flags
4579 * zc_objset_type estimated size, if zc_guid is set
4582 zfs_ioc_send(zfs_cmd_t *zc)
4586 boolean_t estimate = (zc->zc_guid != 0);
4587 boolean_t embedok = (zc->zc_flags & 0x1);
4588 boolean_t large_block_ok = (zc->zc_flags & 0x2);
4590 if (zc->zc_obj != 0) {
4592 dsl_dataset_t *tosnap;
4594 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4598 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
4600 dsl_pool_rele(dp, FTAG);
4604 if (dsl_dir_is_clone(tosnap->ds_dir))
4606 dsl_dir_phys(tosnap->ds_dir)->dd_origin_obj;
4607 dsl_dataset_rele(tosnap, FTAG);
4608 dsl_pool_rele(dp, FTAG);
4613 dsl_dataset_t *tosnap;
4614 dsl_dataset_t *fromsnap = NULL;
4616 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4620 error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
4622 dsl_pool_rele(dp, FTAG);
4626 if (zc->zc_fromobj != 0) {
4627 error = dsl_dataset_hold_obj(dp, zc->zc_fromobj,
4630 dsl_dataset_rele(tosnap, FTAG);
4631 dsl_pool_rele(dp, FTAG);
4636 error = dmu_send_estimate(tosnap, fromsnap,
4637 &zc->zc_objset_type);
4639 if (fromsnap != NULL)
4640 dsl_dataset_rele(fromsnap, FTAG);
4641 dsl_dataset_rele(tosnap, FTAG);
4642 dsl_pool_rele(dp, FTAG);
4645 cap_rights_t rights;
4648 fp = getf(zc->zc_cookie);
4650 fget_write(curthread, zc->zc_cookie,
4651 cap_rights_init(&rights, CAP_WRITE), &fp);
4654 return (SET_ERROR(EBADF));
4657 error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
4658 zc->zc_fromobj, embedok, large_block_ok,
4660 zc->zc_cookie, fp->f_vnode, &off);
4662 zc->zc_cookie, fp, &off);
4665 if (off >= 0 && off <= MAXOFFSET_T)
4667 releasef(zc->zc_cookie);
4674 * zc_name name of snapshot on which to report progress
4675 * zc_cookie file descriptor of send stream
4678 * zc_cookie number of bytes written in send stream thus far
4681 zfs_ioc_send_progress(zfs_cmd_t *zc)
4685 dmu_sendarg_t *dsp = NULL;
4688 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4692 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &ds);
4694 dsl_pool_rele(dp, FTAG);
4698 mutex_enter(&ds->ds_sendstream_lock);
4701 * Iterate over all the send streams currently active on this dataset.
4702 * If there's one which matches the specified file descriptor _and_ the
4703 * stream was started by the current process, return the progress of
4706 for (dsp = list_head(&ds->ds_sendstreams); dsp != NULL;
4707 dsp = list_next(&ds->ds_sendstreams, dsp)) {
4708 if (dsp->dsa_outfd == zc->zc_cookie &&
4709 dsp->dsa_proc == curproc)
4714 zc->zc_cookie = *(dsp->dsa_off);
4716 error = SET_ERROR(ENOENT);
4718 mutex_exit(&ds->ds_sendstream_lock);
4719 dsl_dataset_rele(ds, FTAG);
4720 dsl_pool_rele(dp, FTAG);
4725 zfs_ioc_inject_fault(zfs_cmd_t *zc)
4729 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
4730 &zc->zc_inject_record);
4733 zc->zc_guid = (uint64_t)id;
4739 zfs_ioc_clear_fault(zfs_cmd_t *zc)
4741 return (zio_clear_fault((int)zc->zc_guid));
4745 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
4747 int id = (int)zc->zc_guid;
4750 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
4751 &zc->zc_inject_record);
4759 zfs_ioc_error_log(zfs_cmd_t *zc)
4763 size_t count = (size_t)zc->zc_nvlist_dst_size;
4765 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
4768 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
4771 zc->zc_nvlist_dst_size = count;
4773 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
4775 spa_close(spa, FTAG);
4781 zfs_ioc_clear(zfs_cmd_t *zc)
4788 * On zpool clear we also fix up missing slogs
4790 mutex_enter(&spa_namespace_lock);
4791 spa = spa_lookup(zc->zc_name);
4793 mutex_exit(&spa_namespace_lock);
4794 return (SET_ERROR(EIO));
4796 if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
4797 /* we need to let spa_open/spa_load clear the chains */
4798 spa_set_log_state(spa, SPA_LOG_CLEAR);
4800 spa->spa_last_open_failed = 0;
4801 mutex_exit(&spa_namespace_lock);
4803 if (zc->zc_cookie & ZPOOL_NO_REWIND) {
4804 error = spa_open(zc->zc_name, &spa, FTAG);
4807 nvlist_t *config = NULL;
4809 if (zc->zc_nvlist_src == 0)
4810 return (SET_ERROR(EINVAL));
4812 if ((error = get_nvlist(zc->zc_nvlist_src,
4813 zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
4814 error = spa_open_rewind(zc->zc_name, &spa, FTAG,
4816 if (config != NULL) {
4819 if ((err = put_nvlist(zc, config)) != 0)
4821 nvlist_free(config);
4823 nvlist_free(policy);
4830 spa_vdev_state_enter(spa, SCL_NONE);
4832 if (zc->zc_guid == 0) {
4835 vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
4837 (void) spa_vdev_state_exit(spa, NULL, ENODEV);
4838 spa_close(spa, FTAG);
4839 return (SET_ERROR(ENODEV));
4843 vdev_clear(spa, vd);
4845 (void) spa_vdev_state_exit(spa, NULL, 0);
4848 * Resume any suspended I/Os.
4850 if (zio_resume(spa) != 0)
4851 error = SET_ERROR(EIO);
4853 spa_close(spa, FTAG);
4859 zfs_ioc_pool_reopen(zfs_cmd_t *zc)
4864 error = spa_open(zc->zc_name, &spa, FTAG);
4868 spa_vdev_state_enter(spa, SCL_NONE);
4871 * If a resilver is already in progress then set the
4872 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4873 * the scan as a side effect of the reopen. Otherwise, let
4874 * vdev_open() decided if a resilver is required.
4876 spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
4877 vdev_reopen(spa->spa_root_vdev);
4878 spa->spa_scrub_reopen = B_FALSE;
4880 (void) spa_vdev_state_exit(spa, NULL, 0);
4881 spa_close(spa, FTAG);
4886 * zc_name name of filesystem
4887 * zc_value name of origin snapshot
4890 * zc_string name of conflicting snapshot, if there is one
4893 zfs_ioc_promote(zfs_cmd_t *zc)
4898 * We don't need to unmount *all* the origin fs's snapshots, but
4901 cp = strchr(zc->zc_value, '@');
4904 (void) dmu_objset_find(zc->zc_value,
4905 zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
4906 return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
4910 * Retrieve a single {user|group}{used|quota}@... property.
4913 * zc_name name of filesystem
4914 * zc_objset_type zfs_userquota_prop_t
4915 * zc_value domain name (eg. "S-1-234-567-89")
4916 * zc_guid RID/UID/GID
4919 * zc_cookie property value
4922 zfs_ioc_userspace_one(zfs_cmd_t *zc)
4927 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
4928 return (SET_ERROR(EINVAL));
4930 error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs, B_FALSE);
4934 error = zfs_userspace_one(zfsvfs,
4935 zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
4936 zfsvfs_rele(zfsvfs, FTAG);
4943 * zc_name name of filesystem
4944 * zc_cookie zap cursor
4945 * zc_objset_type zfs_userquota_prop_t
4946 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4949 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4950 * zc_cookie zap cursor
4953 zfs_ioc_userspace_many(zfs_cmd_t *zc)
4956 int bufsize = zc->zc_nvlist_dst_size;
4959 return (SET_ERROR(ENOMEM));
4961 int error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs, B_FALSE);
4965 void *buf = kmem_alloc(bufsize, KM_SLEEP);
4967 error = zfs_userspace_many(zfsvfs, zc->zc_objset_type, &zc->zc_cookie,
4968 buf, &zc->zc_nvlist_dst_size);
4971 error = ddi_copyout(buf,
4972 (void *)(uintptr_t)zc->zc_nvlist_dst,
4973 zc->zc_nvlist_dst_size, zc->zc_iflags);
4975 kmem_free(buf, bufsize);
4976 zfsvfs_rele(zfsvfs, FTAG);
4983 * zc_name name of filesystem
4989 zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
4995 if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
4996 if (!dmu_objset_userused_enabled(zfsvfs->z_os)) {
4998 * If userused is not enabled, it may be because the
4999 * objset needs to be closed & reopened (to grow the
5000 * objset_phys_t). Suspend/resume the fs will do that.
5002 error = zfs_suspend_fs(zfsvfs);
5004 dmu_objset_refresh_ownership(zfsvfs->z_os,
5006 error = zfs_resume_fs(zfsvfs, zc->zc_name);
5010 error = dmu_objset_userspace_upgrade(zfsvfs->z_os);
5012 VFS_RELE(zfsvfs->z_vfs);
5014 vfs_unbusy(zfsvfs->z_vfs);
5017 /* XXX kind of reading contents without owning */
5018 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
5022 error = dmu_objset_userspace_upgrade(os);
5023 dmu_objset_rele(os, FTAG);
5031 * We don't want to have a hard dependency
5032 * against some special symbols in sharefs
5033 * nfs, and smbsrv. Determine them if needed when
5034 * the first file system is shared.
5035 * Neither sharefs, nfs or smbsrv are unloadable modules.
5037 int (*znfsexport_fs)(void *arg);
5038 int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
5039 int (*zsmbexport_fs)(void *arg, boolean_t add_share);
5041 int zfs_nfsshare_inited;
5042 int zfs_smbshare_inited;
5044 ddi_modhandle_t nfs_mod;
5045 ddi_modhandle_t sharefs_mod;
5046 ddi_modhandle_t smbsrv_mod;
5047 #endif /* illumos */
5048 kmutex_t zfs_share_lock;
5056 ASSERT(MUTEX_HELD(&zfs_share_lock));
5057 /* Both NFS and SMB shares also require sharetab support. */
5058 if (sharefs_mod == NULL && ((sharefs_mod =
5059 ddi_modopen("fs/sharefs",
5060 KRTLD_MODE_FIRST, &error)) == NULL)) {
5061 return (SET_ERROR(ENOSYS));
5063 if (zshare_fs == NULL && ((zshare_fs =
5064 (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
5065 ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
5066 return (SET_ERROR(ENOSYS));
5070 #endif /* illumos */
5073 zfs_ioc_share(zfs_cmd_t *zc)
5079 switch (zc->zc_share.z_sharetype) {
5081 case ZFS_UNSHARE_NFS:
5082 if (zfs_nfsshare_inited == 0) {
5083 mutex_enter(&zfs_share_lock);
5084 if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
5085 KRTLD_MODE_FIRST, &error)) == NULL)) {
5086 mutex_exit(&zfs_share_lock);
5087 return (SET_ERROR(ENOSYS));
5089 if (znfsexport_fs == NULL &&
5090 ((znfsexport_fs = (int (*)(void *))
5092 "nfs_export", &error)) == NULL)) {
5093 mutex_exit(&zfs_share_lock);
5094 return (SET_ERROR(ENOSYS));
5096 error = zfs_init_sharefs();
5098 mutex_exit(&zfs_share_lock);
5099 return (SET_ERROR(ENOSYS));
5101 zfs_nfsshare_inited = 1;
5102 mutex_exit(&zfs_share_lock);
5106 case ZFS_UNSHARE_SMB:
5107 if (zfs_smbshare_inited == 0) {
5108 mutex_enter(&zfs_share_lock);
5109 if (smbsrv_mod == NULL && ((smbsrv_mod =
5110 ddi_modopen("drv/smbsrv",
5111 KRTLD_MODE_FIRST, &error)) == NULL)) {
5112 mutex_exit(&zfs_share_lock);
5113 return (SET_ERROR(ENOSYS));
5115 if (zsmbexport_fs == NULL && ((zsmbexport_fs =
5116 (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
5117 "smb_server_share", &error)) == NULL)) {
5118 mutex_exit(&zfs_share_lock);
5119 return (SET_ERROR(ENOSYS));
5121 error = zfs_init_sharefs();
5123 mutex_exit(&zfs_share_lock);
5124 return (SET_ERROR(ENOSYS));
5126 zfs_smbshare_inited = 1;
5127 mutex_exit(&zfs_share_lock);
5131 return (SET_ERROR(EINVAL));
5134 switch (zc->zc_share.z_sharetype) {
5136 case ZFS_UNSHARE_NFS:
5138 znfsexport_fs((void *)
5139 (uintptr_t)zc->zc_share.z_exportdata))
5143 case ZFS_UNSHARE_SMB:
5144 if (error = zsmbexport_fs((void *)
5145 (uintptr_t)zc->zc_share.z_exportdata,
5146 zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
5153 opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
5154 zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
5155 SHAREFS_ADD : SHAREFS_REMOVE;
5158 * Add or remove share from sharetab
5160 error = zshare_fs(opcode,
5161 (void *)(uintptr_t)zc->zc_share.z_sharedata,
5162 zc->zc_share.z_sharemax);
5166 #else /* !illumos */
5168 #endif /* illumos */
5171 ace_t full_access[] = {
5172 {(uid_t)-1, ACE_ALL_PERMS, ACE_EVERYONE, 0}
5177 * zc_name name of containing filesystem
5178 * zc_obj object # beyond which we want next in-use object #
5181 * zc_obj next in-use object #
5184 zfs_ioc_next_obj(zfs_cmd_t *zc)
5186 objset_t *os = NULL;
5189 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
5193 error = dmu_object_next(os, &zc->zc_obj, B_FALSE,
5194 dsl_dataset_phys(os->os_dsl_dataset)->ds_prev_snap_txg);
5196 dmu_objset_rele(os, FTAG);
5202 * zc_name name of filesystem
5203 * zc_value prefix name for snapshot
5204 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5207 * zc_value short name of new snapshot
5210 zfs_ioc_tmp_snapshot(zfs_cmd_t *zc)
5217 error = zfs_onexit_fd_hold(zc->zc_cleanup_fd, &minor);
5221 snap_name = kmem_asprintf("%s-%016llx", zc->zc_value,
5222 (u_longlong_t)ddi_get_lbolt64());
5223 hold_name = kmem_asprintf("%%%s", zc->zc_value);
5225 error = dsl_dataset_snapshot_tmp(zc->zc_name, snap_name, minor,
5228 (void) strcpy(zc->zc_value, snap_name);
5231 zfs_onexit_fd_rele(zc->zc_cleanup_fd);
5237 * zc_name name of "to" snapshot
5238 * zc_value name of "from" snapshot
5239 * zc_cookie file descriptor to write diff data on
5242 * dmu_diff_record_t's to the file descriptor
5245 zfs_ioc_diff(zfs_cmd_t *zc)
5248 cap_rights_t rights;
5253 fp = getf(zc->zc_cookie);
5255 fget_write(curthread, zc->zc_cookie,
5256 cap_rights_init(&rights, CAP_WRITE), &fp);
5259 return (SET_ERROR(EBADF));
5264 error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off);
5266 error = dmu_diff(zc->zc_name, zc->zc_value, fp, &off);
5269 if (off >= 0 && off <= MAXOFFSET_T)
5271 releasef(zc->zc_cookie);
5278 * Remove all ACL files in shares dir
5281 zfs_smb_acl_purge(znode_t *dzp)
5284 zap_attribute_t zap;
5285 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
5288 for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id);
5289 (error = zap_cursor_retrieve(&zc, &zap)) == 0;
5290 zap_cursor_advance(&zc)) {
5291 if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
5295 zap_cursor_fini(&zc);
5298 #endif /* illumos */
5301 zfs_ioc_smb_acl(zfs_cmd_t *zc)
5306 vnode_t *resourcevp = NULL;
5315 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
5316 NO_FOLLOW, NULL, &vp)) != 0)
5319 /* Now make sure mntpnt and dataset are ZFS */
5321 if (strcmp(vp->v_vfsp->mnt_stat.f_fstypename, "zfs") != 0 ||
5322 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
5323 zc->zc_name) != 0)) {
5325 return (SET_ERROR(EINVAL));
5329 zfsvfs = dzp->z_zfsvfs;
5333 * Create share dir if its missing.
5335 mutex_enter(&zfsvfs->z_lock);
5336 if (zfsvfs->z_shares_dir == 0) {
5339 tx = dmu_tx_create(zfsvfs->z_os);
5340 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
5342 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
5343 error = dmu_tx_assign(tx, TXG_WAIT);
5347 error = zfs_create_share_dir(zfsvfs, tx);
5351 mutex_exit(&zfsvfs->z_lock);
5357 mutex_exit(&zfsvfs->z_lock);
5359 ASSERT(zfsvfs->z_shares_dir);
5360 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &sharedir)) != 0) {
5366 switch (zc->zc_cookie) {
5367 case ZFS_SMB_ACL_ADD:
5368 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
5369 vattr.va_type = VREG;
5370 vattr.va_mode = S_IFREG|0777;
5374 vsec.vsa_mask = VSA_ACE;
5375 vsec.vsa_aclentp = &full_access;
5376 vsec.vsa_aclentsz = sizeof (full_access);
5377 vsec.vsa_aclcnt = 1;
5379 error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
5380 &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
5382 VN_RELE(resourcevp);
5385 case ZFS_SMB_ACL_REMOVE:
5386 error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
5390 case ZFS_SMB_ACL_RENAME:
5391 if ((error = get_nvlist(zc->zc_nvlist_src,
5392 zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
5394 VN_RELE(ZTOV(sharedir));
5398 if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
5399 nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
5402 VN_RELE(ZTOV(sharedir));
5404 nvlist_free(nvlist);
5407 error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
5409 nvlist_free(nvlist);
5412 case ZFS_SMB_ACL_PURGE:
5413 error = zfs_smb_acl_purge(sharedir);
5417 error = SET_ERROR(EINVAL);
5422 VN_RELE(ZTOV(sharedir));
5427 #else /* !illumos */
5428 return (EOPNOTSUPP);
5429 #endif /* illumos */
5434 * "holds" -> { snapname -> holdname (string), ... }
5435 * (optional) "cleanup_fd" -> fd (int32)
5439 * snapname -> error value (int32)
5445 zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
5449 int cleanup_fd = -1;
5453 error = nvlist_lookup_nvlist(args, "holds", &holds);
5455 return (SET_ERROR(EINVAL));
5457 /* make sure the user didn't pass us any invalid (empty) tags */
5458 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
5459 pair = nvlist_next_nvpair(holds, pair)) {
5462 error = nvpair_value_string(pair, &htag);
5464 return (SET_ERROR(error));
5466 if (strlen(htag) == 0)
5467 return (SET_ERROR(EINVAL));
5470 if (nvlist_lookup_int32(args, "cleanup_fd", &cleanup_fd) == 0) {
5471 error = zfs_onexit_fd_hold(cleanup_fd, &minor);
5476 error = dsl_dataset_user_hold(holds, minor, errlist);
5478 zfs_onexit_fd_rele(cleanup_fd);
5483 * innvl is not used.
5486 * holdname -> time added (uint64 seconds since epoch)
5492 zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
5494 return (dsl_dataset_get_holds(snapname, outnvl));
5499 * snapname -> { holdname, ... }
5504 * snapname -> error value (int32)
5510 zfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
5512 return (dsl_dataset_user_release(holds, errlist));
5517 * zc_name name of new filesystem or snapshot
5518 * zc_value full name of old snapshot
5521 * zc_cookie space in bytes
5522 * zc_objset_type compressed space in bytes
5523 * zc_perm_action uncompressed space in bytes
5526 zfs_ioc_space_written(zfs_cmd_t *zc)
5530 dsl_dataset_t *new, *old;
5532 error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
5535 error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &new);
5537 dsl_pool_rele(dp, FTAG);
5540 error = dsl_dataset_hold(dp, zc->zc_value, FTAG, &old);
5542 dsl_dataset_rele(new, FTAG);
5543 dsl_pool_rele(dp, FTAG);
5547 error = dsl_dataset_space_written(old, new, &zc->zc_cookie,
5548 &zc->zc_objset_type, &zc->zc_perm_action);
5549 dsl_dataset_rele(old, FTAG);
5550 dsl_dataset_rele(new, FTAG);
5551 dsl_pool_rele(dp, FTAG);
5557 * "firstsnap" -> snapshot name
5561 * "used" -> space in bytes
5562 * "compressed" -> compressed space in bytes
5563 * "uncompressed" -> uncompressed space in bytes
5567 zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
5571 dsl_dataset_t *new, *old;
5573 uint64_t used, comp, uncomp;
5575 if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
5576 return (SET_ERROR(EINVAL));
5578 error = dsl_pool_hold(lastsnap, FTAG, &dp);
5582 error = dsl_dataset_hold(dp, lastsnap, FTAG, &new);
5583 if (error == 0 && !new->ds_is_snapshot) {
5584 dsl_dataset_rele(new, FTAG);
5585 error = SET_ERROR(EINVAL);
5588 dsl_pool_rele(dp, FTAG);
5591 error = dsl_dataset_hold(dp, firstsnap, FTAG, &old);
5592 if (error == 0 && !old->ds_is_snapshot) {
5593 dsl_dataset_rele(old, FTAG);
5594 error = SET_ERROR(EINVAL);
5597 dsl_dataset_rele(new, FTAG);
5598 dsl_pool_rele(dp, FTAG);
5602 error = dsl_dataset_space_wouldfree(old, new, &used, &comp, &uncomp);
5603 dsl_dataset_rele(old, FTAG);
5604 dsl_dataset_rele(new, FTAG);
5605 dsl_pool_rele(dp, FTAG);
5606 fnvlist_add_uint64(outnvl, "used", used);
5607 fnvlist_add_uint64(outnvl, "compressed", comp);
5608 fnvlist_add_uint64(outnvl, "uncompressed", uncomp);
5613 zfs_ioc_jail(zfs_cmd_t *zc)
5616 return (zone_dataset_attach(curthread->td_ucred, zc->zc_name,
5617 (int)zc->zc_jailid));
5621 zfs_ioc_unjail(zfs_cmd_t *zc)
5624 return (zone_dataset_detach(curthread->td_ucred, zc->zc_name,
5625 (int)zc->zc_jailid));
5630 * "fd" -> file descriptor to write stream to (int32)
5631 * (optional) "fromsnap" -> full snap name to send an incremental from
5632 * (optional) "largeblockok" -> (value ignored)
5633 * indicates that blocks > 128KB are permitted
5634 * (optional) "embedok" -> (value ignored)
5635 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5636 * (optional) "resume_object" and "resume_offset" -> (uint64)
5637 * if present, resume send stream from specified object and offset.
5644 zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5646 cap_rights_t rights;
5650 char *fromname = NULL;
5652 boolean_t largeblockok;
5654 uint64_t resumeobj = 0;
5655 uint64_t resumeoff = 0;
5657 error = nvlist_lookup_int32(innvl, "fd", &fd);
5659 return (SET_ERROR(EINVAL));
5661 (void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
5663 largeblockok = nvlist_exists(innvl, "largeblockok");
5664 embedok = nvlist_exists(innvl, "embedok");
5666 (void) nvlist_lookup_uint64(innvl, "resume_object", &resumeobj);
5667 (void) nvlist_lookup_uint64(innvl, "resume_offset", &resumeoff);
5670 file_t *fp = getf(fd);
5672 fget_write(curthread, fd, cap_rights_init(&rights, CAP_WRITE), &fp);
5675 return (SET_ERROR(EBADF));
5678 error = dmu_send(snapname, fromname, embedok, largeblockok, fd,
5680 resumeobj, resumeoff, fp->f_vnode, &off);
5682 resumeobj, resumeoff, fp, &off);
5686 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
5697 * Determine approximately how large a zfs send stream will be -- the number
5698 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5701 * (optional) "from" -> full snap or bookmark name to send an incremental
5706 * "space" -> bytes of space (uint64)
5710 zfs_ioc_send_space(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5713 dsl_dataset_t *tosnap;
5718 error = dsl_pool_hold(snapname, FTAG, &dp);
5722 error = dsl_dataset_hold(dp, snapname, FTAG, &tosnap);
5724 dsl_pool_rele(dp, FTAG);
5728 error = nvlist_lookup_string(innvl, "from", &fromname);
5730 if (strchr(fromname, '@') != NULL) {
5732 * If from is a snapshot, hold it and use the more
5733 * efficient dmu_send_estimate to estimate send space
5734 * size using deadlists.
5736 dsl_dataset_t *fromsnap;
5737 error = dsl_dataset_hold(dp, fromname, FTAG, &fromsnap);
5740 error = dmu_send_estimate(tosnap, fromsnap, &space);
5741 dsl_dataset_rele(fromsnap, FTAG);
5742 } else if (strchr(fromname, '#') != NULL) {
5744 * If from is a bookmark, fetch the creation TXG of the
5745 * snapshot it was created from and use that to find
5746 * blocks that were born after it.
5748 zfs_bookmark_phys_t frombm;
5750 error = dsl_bookmark_lookup(dp, fromname, tosnap,
5754 error = dmu_send_estimate_from_txg(tosnap,
5755 frombm.zbm_creation_txg, &space);
5758 * from is not properly formatted as a snapshot or
5761 error = SET_ERROR(EINVAL);
5765 // If estimating the size of a full send, use dmu_send_estimate
5766 error = dmu_send_estimate(tosnap, NULL, &space);
5769 fnvlist_add_uint64(outnvl, "space", space);
5772 dsl_dataset_rele(tosnap, FTAG);
5773 dsl_pool_rele(dp, FTAG);
5777 static zfs_ioc_vec_t zfs_ioc_vec[ZFS_IOC_LAST - ZFS_IOC_FIRST];
5780 zfs_ioctl_register_legacy(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5781 zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
5782 boolean_t log_history, zfs_ioc_poolcheck_t pool_check)
5784 zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
5786 ASSERT3U(ioc, >=, ZFS_IOC_FIRST);
5787 ASSERT3U(ioc, <, ZFS_IOC_LAST);
5788 ASSERT3P(vec->zvec_legacy_func, ==, NULL);
5789 ASSERT3P(vec->zvec_func, ==, NULL);
5791 vec->zvec_legacy_func = func;
5792 vec->zvec_secpolicy = secpolicy;
5793 vec->zvec_namecheck = namecheck;
5794 vec->zvec_allow_log = log_history;
5795 vec->zvec_pool_check = pool_check;
5799 * See the block comment at the beginning of this file for details on
5800 * each argument to this function.
5803 zfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
5804 zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
5805 zfs_ioc_poolcheck_t pool_check, boolean_t smush_outnvlist,
5806 boolean_t allow_log)
5808 zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
5810 ASSERT3U(ioc, >=, ZFS_IOC_FIRST);
5811 ASSERT3U(ioc, <, ZFS_IOC_LAST);
5812 ASSERT3P(vec->zvec_legacy_func, ==, NULL);
5813 ASSERT3P(vec->zvec_func, ==, NULL);
5815 /* if we are logging, the name must be valid */
5816 ASSERT(!allow_log || namecheck != NO_NAME);
5818 vec->zvec_name = name;
5819 vec->zvec_func = func;
5820 vec->zvec_secpolicy = secpolicy;
5821 vec->zvec_namecheck = namecheck;
5822 vec->zvec_pool_check = pool_check;
5823 vec->zvec_smush_outnvlist = smush_outnvlist;
5824 vec->zvec_allow_log = allow_log;
5828 zfs_ioctl_register_pool(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5829 zfs_secpolicy_func_t *secpolicy, boolean_t log_history,
5830 zfs_ioc_poolcheck_t pool_check)
5832 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5833 POOL_NAME, log_history, pool_check);
5837 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5838 zfs_secpolicy_func_t *secpolicy, zfs_ioc_poolcheck_t pool_check)
5840 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5841 DATASET_NAME, B_FALSE, pool_check);
5845 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
5847 zfs_ioctl_register_legacy(ioc, func, zfs_secpolicy_config,
5848 POOL_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5852 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5853 zfs_secpolicy_func_t *secpolicy)
5855 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5856 NO_NAME, B_FALSE, POOL_CHECK_NONE);
5860 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc,
5861 zfs_ioc_legacy_func_t *func, zfs_secpolicy_func_t *secpolicy)
5863 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5864 DATASET_NAME, B_FALSE, POOL_CHECK_SUSPENDED);
5868 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
5870 zfs_ioctl_register_dataset_read_secpolicy(ioc, func,
5871 zfs_secpolicy_read);
5875 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
5876 zfs_secpolicy_func_t *secpolicy)
5878 zfs_ioctl_register_legacy(ioc, func, secpolicy,
5879 DATASET_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5883 zfs_ioctl_init(void)
5885 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT,
5886 zfs_ioc_snapshot, zfs_secpolicy_snapshot, POOL_NAME,
5887 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5889 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY,
5890 zfs_ioc_log_history, zfs_secpolicy_log_history, NO_NAME,
5891 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
5893 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS,
5894 zfs_ioc_space_snaps, zfs_secpolicy_read, DATASET_NAME,
5895 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5897 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW,
5898 zfs_ioc_send_new, zfs_secpolicy_send_new, DATASET_NAME,
5899 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5901 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE,
5902 zfs_ioc_send_space, zfs_secpolicy_read, DATASET_NAME,
5903 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5905 zfs_ioctl_register("create", ZFS_IOC_CREATE,
5906 zfs_ioc_create, zfs_secpolicy_create_clone, DATASET_NAME,
5907 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5909 zfs_ioctl_register("clone", ZFS_IOC_CLONE,
5910 zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
5911 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5913 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
5914 zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
5915 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5917 zfs_ioctl_register("hold", ZFS_IOC_HOLD,
5918 zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
5919 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5920 zfs_ioctl_register("release", ZFS_IOC_RELEASE,
5921 zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
5922 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5924 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
5925 zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
5926 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5928 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
5929 zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
5930 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
5932 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK,
5933 zfs_ioc_bookmark, zfs_secpolicy_bookmark, POOL_NAME,
5934 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5936 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS,
5937 zfs_ioc_get_bookmarks, zfs_secpolicy_read, DATASET_NAME,
5938 POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5940 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS,
5941 zfs_ioc_destroy_bookmarks, zfs_secpolicy_destroy_bookmarks,
5943 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5945 /* IOCTLS that use the legacy function signature */
5947 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
5948 zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_READONLY);
5950 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE, zfs_ioc_pool_create,
5951 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5952 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN,
5954 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE,
5955 zfs_ioc_pool_upgrade);
5956 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD,
5958 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE,
5959 zfs_ioc_vdev_remove);
5960 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE,
5961 zfs_ioc_vdev_set_state);
5962 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH,
5963 zfs_ioc_vdev_attach);
5964 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH,
5965 zfs_ioc_vdev_detach);
5966 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH,
5967 zfs_ioc_vdev_setpath);
5968 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU,
5969 zfs_ioc_vdev_setfru);
5970 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS,
5971 zfs_ioc_pool_set_props);
5972 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT,
5973 zfs_ioc_vdev_split);
5974 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID,
5975 zfs_ioc_pool_reguid);
5977 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS,
5978 zfs_ioc_pool_configs, zfs_secpolicy_none);
5979 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT,
5980 zfs_ioc_pool_tryimport, zfs_secpolicy_config);
5981 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT,
5982 zfs_ioc_inject_fault, zfs_secpolicy_inject);
5983 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT,
5984 zfs_ioc_clear_fault, zfs_secpolicy_inject);
5985 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT,
5986 zfs_ioc_inject_list_next, zfs_secpolicy_inject);
5989 * pool destroy, and export don't log the history as part of
5990 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5991 * does the logging of those commands.
5993 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY, zfs_ioc_pool_destroy,
5994 zfs_secpolicy_config, B_FALSE, POOL_CHECK_NONE);
5995 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT, zfs_ioc_pool_export,
5996 zfs_secpolicy_config, B_FALSE, POOL_CHECK_NONE);
5998 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS, zfs_ioc_pool_stats,
5999 zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
6000 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS, zfs_ioc_pool_get_props,
6001 zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
6003 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG, zfs_ioc_error_log,
6004 zfs_secpolicy_inject, B_FALSE, POOL_CHECK_NONE);
6005 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME,
6006 zfs_ioc_dsobj_to_dsname,
6007 zfs_secpolicy_diff, B_FALSE, POOL_CHECK_NONE);
6008 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY,
6009 zfs_ioc_pool_get_history,
6010 zfs_secpolicy_config, B_FALSE, POOL_CHECK_SUSPENDED);
6012 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT, zfs_ioc_pool_import,
6013 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
6015 zfs_ioctl_register_pool(ZFS_IOC_CLEAR, zfs_ioc_clear,
6016 zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
6017 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
6018 zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
6020 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN,
6021 zfs_ioc_space_written);
6022 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS,
6023 zfs_ioc_objset_recvd_props);
6024 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ,
6026 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL,
6028 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS,
6029 zfs_ioc_objset_stats);
6030 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS,
6031 zfs_ioc_objset_zplprops);
6032 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT,
6033 zfs_ioc_dataset_list_next);
6034 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT,
6035 zfs_ioc_snapshot_list_next);
6036 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS,
6037 zfs_ioc_send_progress);
6039 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF,
6040 zfs_ioc_diff, zfs_secpolicy_diff);
6041 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS,
6042 zfs_ioc_obj_to_stats, zfs_secpolicy_diff);
6043 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH,
6044 zfs_ioc_obj_to_path, zfs_secpolicy_diff);
6045 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE,
6046 zfs_ioc_userspace_one, zfs_secpolicy_userspace_one);
6047 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY,
6048 zfs_ioc_userspace_many, zfs_secpolicy_userspace_many);
6049 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND,
6050 zfs_ioc_send, zfs_secpolicy_send);
6052 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP, zfs_ioc_set_prop,
6053 zfs_secpolicy_none);
6054 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
6055 zfs_secpolicy_destroy);
6056 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
6057 zfs_secpolicy_rename);
6058 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
6059 zfs_secpolicy_recv);
6060 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE, zfs_ioc_promote,
6061 zfs_secpolicy_promote);
6062 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP,
6063 zfs_ioc_inherit_prop, zfs_secpolicy_inherit_prop);
6064 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL, zfs_ioc_set_fsacl,
6065 zfs_secpolicy_set_fsacl);
6067 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE, zfs_ioc_share,
6068 zfs_secpolicy_share, POOL_CHECK_NONE);
6069 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL, zfs_ioc_smb_acl,
6070 zfs_secpolicy_smb_acl, POOL_CHECK_NONE);
6071 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE,
6072 zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
6073 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
6074 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT,
6075 zfs_ioc_tmp_snapshot, zfs_secpolicy_tmp_snapshot,
6076 POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
6079 zfs_ioctl_register_dataset_nolog(ZFS_IOC_JAIL, zfs_ioc_jail,
6080 zfs_secpolicy_config, POOL_CHECK_NONE);
6081 zfs_ioctl_register_dataset_nolog(ZFS_IOC_UNJAIL, zfs_ioc_unjail,
6082 zfs_secpolicy_config, POOL_CHECK_NONE);
6083 zfs_ioctl_register("fbsd_nextboot", ZFS_IOC_NEXTBOOT,
6084 zfs_ioc_nextboot, zfs_secpolicy_config, NO_NAME,
6085 POOL_CHECK_NONE, B_FALSE, B_FALSE);
6090 pool_status_check(const char *name, zfs_ioc_namecheck_t type,
6091 zfs_ioc_poolcheck_t check)
6096 ASSERT(type == POOL_NAME || type == DATASET_NAME);
6098 if (check & POOL_CHECK_NONE)
6101 error = spa_open(name, &spa, FTAG);
6103 if ((check & POOL_CHECK_SUSPENDED) && spa_suspended(spa))
6104 error = SET_ERROR(EAGAIN);
6105 else if ((check & POOL_CHECK_READONLY) && !spa_writeable(spa))
6106 error = SET_ERROR(EROFS);
6107 spa_close(spa, FTAG);
6113 * Find a free minor number.
6116 zfsdev_minor_alloc(void)
6118 static minor_t last_minor;
6121 ASSERT(MUTEX_HELD(&spa_namespace_lock));
6123 for (m = last_minor + 1; m != last_minor; m++) {
6124 if (m > ZFSDEV_MAX_MINOR)
6126 if (ddi_get_soft_state(zfsdev_state, m) == NULL) {
6136 zfs_ctldev_init(struct cdev *devp)
6139 zfs_soft_state_t *zs;
6141 ASSERT(MUTEX_HELD(&spa_namespace_lock));
6143 minor = zfsdev_minor_alloc();
6145 return (SET_ERROR(ENXIO));
6147 if (ddi_soft_state_zalloc(zfsdev_state, minor) != DDI_SUCCESS)
6148 return (SET_ERROR(EAGAIN));
6150 devfs_set_cdevpriv((void *)(uintptr_t)minor, zfsdev_close);
6152 zs = ddi_get_soft_state(zfsdev_state, minor);
6153 zs->zss_type = ZSST_CTLDEV;
6154 zfs_onexit_init((zfs_onexit_t **)&zs->zss_data);
6160 zfs_ctldev_destroy(zfs_onexit_t *zo, minor_t minor)
6162 ASSERT(MUTEX_HELD(&spa_namespace_lock));
6164 zfs_onexit_destroy(zo);
6165 ddi_soft_state_free(zfsdev_state, minor);
6169 zfsdev_get_soft_state(minor_t minor, enum zfs_soft_state_type which)
6171 zfs_soft_state_t *zp;
6173 zp = ddi_get_soft_state(zfsdev_state, minor);
6174 if (zp == NULL || zp->zss_type != which)
6177 return (zp->zss_data);
6181 zfsdev_open(struct cdev *devp, int flag, int mode, struct thread *td)
6186 if (getminor(*devp) != 0)
6187 return (zvol_open(devp, flag, otyp, cr));
6190 /* This is the control device. Allocate a new minor if requested. */
6192 mutex_enter(&spa_namespace_lock);
6193 error = zfs_ctldev_init(devp);
6194 mutex_exit(&spa_namespace_lock);
6201 zfsdev_close(void *data)
6204 minor_t minor = (minor_t)(uintptr_t)data;
6209 mutex_enter(&spa_namespace_lock);
6210 zo = zfsdev_get_soft_state(minor, ZSST_CTLDEV);
6212 mutex_exit(&spa_namespace_lock);
6215 zfs_ctldev_destroy(zo, minor);
6216 mutex_exit(&spa_namespace_lock);
6220 zfsdev_ioctl(struct cdev *dev, u_long zcmd, caddr_t arg, int flag,
6227 minor_t minor = getminor(dev);
6229 zfs_iocparm_t *zc_iocparm;
6230 int cflag, cmd, oldvecnum;
6231 boolean_t newioc, compat;
6232 void *compat_zc = NULL;
6233 cred_t *cr = td->td_ucred;
6235 const zfs_ioc_vec_t *vec;
6236 char *saved_poolname = NULL;
6237 nvlist_t *innvl = NULL;
6239 cflag = ZFS_CMD_COMPAT_NONE;
6241 newioc = B_TRUE; /* "new" style (zfs_iocparm_t) ioctl */
6243 len = IOCPARM_LEN(zcmd);
6244 vecnum = cmd = zcmd & 0xff;
6247 * Check if we are talking to supported older binaries
6248 * and translate zfs_cmd if necessary
6250 if (len != sizeof(zfs_iocparm_t)) {
6257 case sizeof(zfs_cmd_zcmd_t):
6258 cflag = ZFS_CMD_COMPAT_LZC;
6260 case sizeof(zfs_cmd_deadman_t):
6261 cflag = ZFS_CMD_COMPAT_DEADMAN;
6263 case sizeof(zfs_cmd_v28_t):
6264 cflag = ZFS_CMD_COMPAT_V28;
6266 case sizeof(zfs_cmd_v15_t):
6267 cflag = ZFS_CMD_COMPAT_V15;
6268 vecnum = zfs_ioctl_v15_to_v28[cmd];
6271 * Return without further handling
6272 * if the command is blacklisted.
6274 if (vecnum == ZFS_IOC_COMPAT_PASS)
6276 else if (vecnum == ZFS_IOC_COMPAT_FAIL)
6285 vecnum = cmd - ZFS_IOC_FIRST;
6286 ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
6289 if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
6290 return (SET_ERROR(EINVAL));
6291 vec = &zfs_ioc_vec[vecnum];
6293 zc = kmem_zalloc(sizeof(zfs_cmd_t), KM_SLEEP);
6296 error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
6298 error = SET_ERROR(EFAULT);
6301 #else /* !illumos */
6302 bzero(zc, sizeof(zfs_cmd_t));
6305 zc_iocparm = (void *)arg;
6307 switch (zc_iocparm->zfs_ioctl_version) {
6308 case ZFS_IOCVER_CURRENT:
6309 if (zc_iocparm->zfs_cmd_size != sizeof(zfs_cmd_t)) {
6310 error = SET_ERROR(EINVAL);
6314 case ZFS_IOCVER_INLANES:
6315 if (zc_iocparm->zfs_cmd_size != sizeof(zfs_cmd_inlanes_t)) {
6316 error = SET_ERROR(EFAULT);
6320 cflag = ZFS_CMD_COMPAT_INLANES;
6322 case ZFS_IOCVER_RESUME:
6323 if (zc_iocparm->zfs_cmd_size != sizeof(zfs_cmd_resume_t)) {
6324 error = SET_ERROR(EFAULT);
6328 cflag = ZFS_CMD_COMPAT_RESUME;
6330 case ZFS_IOCVER_EDBP:
6331 if (zc_iocparm->zfs_cmd_size != sizeof(zfs_cmd_edbp_t)) {
6332 error = SET_ERROR(EFAULT);
6336 cflag = ZFS_CMD_COMPAT_EDBP;
6338 case ZFS_IOCVER_ZCMD:
6339 if (zc_iocparm->zfs_cmd_size > sizeof(zfs_cmd_t) ||
6340 zc_iocparm->zfs_cmd_size < sizeof(zfs_cmd_zcmd_t)) {
6341 error = SET_ERROR(EFAULT);
6345 cflag = ZFS_CMD_COMPAT_ZCMD;
6348 error = SET_ERROR(EINVAL);
6354 ASSERT(sizeof(zfs_cmd_t) >= zc_iocparm->zfs_cmd_size);
6355 compat_zc = kmem_zalloc(sizeof(zfs_cmd_t), KM_SLEEP);
6356 bzero(compat_zc, sizeof(zfs_cmd_t));
6358 error = ddi_copyin((void *)(uintptr_t)zc_iocparm->zfs_cmd,
6359 compat_zc, zc_iocparm->zfs_cmd_size, flag);
6361 error = SET_ERROR(EFAULT);
6365 error = ddi_copyin((void *)(uintptr_t)zc_iocparm->zfs_cmd,
6366 zc, zc_iocparm->zfs_cmd_size, flag);
6368 error = SET_ERROR(EFAULT);
6376 ASSERT(compat_zc != NULL);
6377 zfs_cmd_compat_get(zc, compat_zc, cflag);
6379 ASSERT(compat_zc == NULL);
6380 zfs_cmd_compat_get(zc, arg, cflag);
6383 error = zfs_ioctl_compat_pre(zc, &vecnum, cflag);
6386 if (oldvecnum != vecnum)
6387 vec = &zfs_ioc_vec[vecnum];
6389 #endif /* !illumos */
6391 zc->zc_iflags = flag & FKIOCTL;
6392 if (zc->zc_nvlist_src_size != 0) {
6393 error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
6394 zc->zc_iflags, &innvl);
6399 /* rewrite innvl for backwards compatibility */
6401 innvl = zfs_ioctl_compat_innvl(zc, innvl, vecnum, cflag);
6404 * Ensure that all pool/dataset names are valid before we pass down to
6407 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
6408 switch (vec->zvec_namecheck) {
6410 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
6411 error = SET_ERROR(EINVAL);
6413 error = pool_status_check(zc->zc_name,
6414 vec->zvec_namecheck, vec->zvec_pool_check);
6418 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
6419 error = SET_ERROR(EINVAL);
6421 error = pool_status_check(zc->zc_name,
6422 vec->zvec_namecheck, vec->zvec_pool_check);
6430 error = vec->zvec_secpolicy(zc, innvl, cr);
6435 /* legacy ioctls can modify zc_name */
6436 len = strcspn(zc->zc_name, "/@#") + 1;
6437 saved_poolname = kmem_alloc(len, KM_SLEEP);
6438 (void) strlcpy(saved_poolname, zc->zc_name, len);
6440 if (vec->zvec_func != NULL) {
6444 nvlist_t *lognv = NULL;
6446 ASSERT(vec->zvec_legacy_func == NULL);
6449 * Add the innvl to the lognv before calling the func,
6450 * in case the func changes the innvl.
6452 if (vec->zvec_allow_log) {
6453 lognv = fnvlist_alloc();
6454 fnvlist_add_string(lognv, ZPOOL_HIST_IOCTL,
6456 if (!nvlist_empty(innvl)) {
6457 fnvlist_add_nvlist(lognv, ZPOOL_HIST_INPUT_NVL,
6462 outnvl = fnvlist_alloc();
6463 error = vec->zvec_func(zc->zc_name, innvl, outnvl);
6465 if (error == 0 && vec->zvec_allow_log &&
6466 spa_open(zc->zc_name, &spa, FTAG) == 0) {
6467 if (!nvlist_empty(outnvl)) {
6468 fnvlist_add_nvlist(lognv, ZPOOL_HIST_OUTPUT_NVL,
6471 (void) spa_history_log_nvl(spa, lognv);
6472 spa_close(spa, FTAG);
6474 fnvlist_free(lognv);
6476 /* rewrite outnvl for backwards compatibility */
6478 outnvl = zfs_ioctl_compat_outnvl(zc, outnvl, vecnum,
6481 if (!nvlist_empty(outnvl) || zc->zc_nvlist_dst_size != 0) {
6483 if (vec->zvec_smush_outnvlist) {
6484 smusherror = nvlist_smush(outnvl,
6485 zc->zc_nvlist_dst_size);
6487 if (smusherror == 0)
6488 puterror = put_nvlist(zc, outnvl);
6494 nvlist_free(outnvl);
6496 error = vec->zvec_legacy_func(zc);
6503 rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
6504 if (error == 0 && rc != 0)
6505 error = SET_ERROR(EFAULT);
6508 zfs_ioctl_compat_post(zc, cmd, cflag);
6510 ASSERT(compat_zc != NULL);
6511 ASSERT(sizeof(zfs_cmd_t) >= zc_iocparm->zfs_cmd_size);
6513 zfs_cmd_compat_put(zc, compat_zc, vecnum, cflag);
6514 rc = ddi_copyout(compat_zc,
6515 (void *)(uintptr_t)zc_iocparm->zfs_cmd,
6516 zc_iocparm->zfs_cmd_size, flag);
6517 if (error == 0 && rc != 0)
6518 error = SET_ERROR(EFAULT);
6519 kmem_free(compat_zc, sizeof (zfs_cmd_t));
6521 zfs_cmd_compat_put(zc, arg, vecnum, cflag);
6526 rc = ddi_copyout(zc, (void *)(uintptr_t)zc_iocparm->zfs_cmd,
6527 sizeof (zfs_cmd_t), flag);
6528 if (error == 0 && rc != 0)
6529 error = SET_ERROR(EFAULT);
6532 if (error == 0 && vec->zvec_allow_log) {
6533 char *s = tsd_get(zfs_allow_log_key);
6536 (void) tsd_set(zfs_allow_log_key, saved_poolname);
6538 if (saved_poolname != NULL)
6539 strfree(saved_poolname);
6542 kmem_free(zc, sizeof (zfs_cmd_t));
6548 zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
6550 if (cmd != DDI_ATTACH)
6551 return (DDI_FAILURE);
6553 if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
6554 DDI_PSEUDO, 0) == DDI_FAILURE)
6555 return (DDI_FAILURE);
6559 ddi_report_dev(dip);
6561 return (DDI_SUCCESS);
6565 zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
6567 if (spa_busy() || zfs_busy() || zvol_busy())
6568 return (DDI_FAILURE);
6570 if (cmd != DDI_DETACH)
6571 return (DDI_FAILURE);
6575 ddi_prop_remove_all(dip);
6576 ddi_remove_minor_node(dip, NULL);
6578 return (DDI_SUCCESS);
6583 zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
6586 case DDI_INFO_DEVT2DEVINFO:
6588 return (DDI_SUCCESS);
6590 case DDI_INFO_DEVT2INSTANCE:
6591 *result = (void *)0;
6592 return (DDI_SUCCESS);
6595 return (DDI_FAILURE);
6597 #endif /* illumos */
6600 * OK, so this is a little weird.
6602 * /dev/zfs is the control node, i.e. minor 0.
6603 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
6605 * /dev/zfs has basically nothing to do except serve up ioctls,
6606 * so most of the standard driver entry points are in zvol.c.
6609 static struct cb_ops zfs_cb_ops = {
6610 zfsdev_open, /* open */
6611 zfsdev_close, /* close */
6612 zvol_strategy, /* strategy */
6614 zvol_dump, /* dump */
6615 zvol_read, /* read */
6616 zvol_write, /* write */
6617 zfsdev_ioctl, /* ioctl */
6621 nochpoll, /* poll */
6622 ddi_prop_op, /* prop_op */
6623 NULL, /* streamtab */
6624 D_NEW | D_MP | D_64BIT, /* Driver compatibility flag */
6625 CB_REV, /* version */
6626 nodev, /* async read */
6627 nodev, /* async write */
6630 static struct dev_ops zfs_dev_ops = {
6631 DEVO_REV, /* version */
6633 zfs_info, /* info */
6634 nulldev, /* identify */
6635 nulldev, /* probe */
6636 zfs_attach, /* attach */
6637 zfs_detach, /* detach */
6639 &zfs_cb_ops, /* driver operations */
6640 NULL, /* no bus operations */
6642 ddi_quiesce_not_needed, /* quiesce */
6645 static struct modldrv zfs_modldrv = {
6651 static struct modlinkage modlinkage = {
6653 (void *)&zfs_modlfs,
6654 (void *)&zfs_modldrv,
6657 #endif /* illumos */
6659 static struct cdevsw zfs_cdevsw = {
6660 .d_version = D_VERSION,
6661 .d_open = zfsdev_open,
6662 .d_ioctl = zfsdev_ioctl,
6663 .d_name = ZFS_DEV_NAME
6667 zfs_allow_log_destroy(void *arg)
6669 char *poolname = arg;
6676 zfsdev = make_dev(&zfs_cdevsw, 0x0, UID_ROOT, GID_OPERATOR, 0666,
6684 destroy_dev(zfsdev);
6687 static struct root_hold_token *zfs_root_token;
6688 struct proc *zfsproc;
6696 spa_init(FREAD | FWRITE);
6701 if ((error = mod_install(&modlinkage)) != 0) {
6708 tsd_create(&zfs_fsyncer_key, NULL);
6709 tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
6710 tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy);
6712 error = ldi_ident_from_mod(&modlinkage, &zfs_li);
6714 mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
6724 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
6725 return (SET_ERROR(EBUSY));
6727 if ((error = mod_remove(&modlinkage)) != 0)
6733 if (zfs_nfsshare_inited)
6734 (void) ddi_modclose(nfs_mod);
6735 if (zfs_smbshare_inited)
6736 (void) ddi_modclose(smbsrv_mod);
6737 if (zfs_nfsshare_inited || zfs_smbshare_inited)
6738 (void) ddi_modclose(sharefs_mod);
6740 tsd_destroy(&zfs_fsyncer_key);
6741 ldi_ident_release(zfs_li);
6743 mutex_destroy(&zfs_share_lock);
6749 _info(struct modinfo *modinfop)
6751 return (mod_info(&modlinkage, modinfop));
6753 #endif /* illumos */
6755 static int zfs__init(void);
6756 static int zfs__fini(void);
6757 static void zfs_shutdown(void *, int);
6759 static eventhandler_tag zfs_shutdown_event_tag;
6762 #define ZFS_MIN_KSTACK_PAGES 4
6770 #if KSTACK_PAGES < ZFS_MIN_KSTACK_PAGES
6771 printf("ZFS NOTICE: KSTACK_PAGES is %d which could result in stack "
6772 "overflow panic!\nPlease consider adding "
6773 "'options KSTACK_PAGES=%d' to your kernel config\n", KSTACK_PAGES,
6774 ZFS_MIN_KSTACK_PAGES);
6777 zfs_root_token = root_mount_hold("ZFS");
6779 mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
6781 spa_init(FREAD | FWRITE);
6786 tsd_create(&zfs_fsyncer_key, NULL);
6787 tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
6788 tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy);
6789 tsd_create(&zfs_geom_probe_vdev_key, NULL);
6791 printf("ZFS storage pool version: features support (" SPA_VERSION_STRING ")\n");
6792 root_mount_rel(zfs_root_token);
6802 if (spa_busy() || zfs_busy() || zvol_busy() ||
6803 zio_injection_enabled) {
6812 tsd_destroy(&zfs_fsyncer_key);
6813 tsd_destroy(&rrw_tsd_key);
6814 tsd_destroy(&zfs_allow_log_key);
6816 mutex_destroy(&zfs_share_lock);
6822 zfs_shutdown(void *arg __unused, int howto __unused)
6826 * ZFS fini routines can not properly work in a panic-ed system.
6828 if (panicstr == NULL)
6834 zfs_modevent(module_t mod, int type, void *unused __unused)
6842 zfs_shutdown_event_tag = EVENTHANDLER_REGISTER(
6843 shutdown_post_sync, zfs_shutdown, NULL,
6844 SHUTDOWN_PRI_FIRST);
6848 if (err == 0 && zfs_shutdown_event_tag != NULL)
6849 EVENTHANDLER_DEREGISTER(shutdown_post_sync,
6850 zfs_shutdown_event_tag);
6857 return (EOPNOTSUPP);
6860 static moduledata_t zfs_mod = {
6865 DECLARE_MODULE(zfsctrl, zfs_mod, SI_SUB_VFS, SI_ORDER_ANY);
6866 MODULE_VERSION(zfsctrl, 1);
6867 MODULE_DEPEND(zfsctrl, opensolaris, 1, 1, 1);
6868 MODULE_DEPEND(zfsctrl, krpc, 1, 1, 1);
6869 MODULE_DEPEND(zfsctrl, acl_nfs4, 1, 1, 1);