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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
26 #include <sys/param.h>
27 #include <sys/errno.h>
30 #include <sys/modctl.h>
35 #include <sys/cmn_err.h>
37 #include <sys/zfs_ioctl.h>
38 #include <sys/zfs_vfsops.h>
39 #include <sys/zfs_znode.h>
42 #include <sys/spa_impl.h>
44 #include <sys/priv_impl.h>
46 #include <sys/dsl_dir.h>
47 #include <sys/dsl_dataset.h>
48 #include <sys/dsl_prop.h>
49 #include <sys/dsl_deleg.h>
50 #include <sys/dmu_objset.h>
52 #include <sys/sunddi.h>
53 #include <sys/sunldi.h>
54 #include <sys/policy.h>
56 #include <sys/nvpair.h>
57 #include <sys/pathname.h>
58 #include <sys/mount.h>
60 #include <sys/fs/zfs.h>
61 #include <sys/zfs_ctldir.h>
62 #include <sys/zfs_dir.h>
64 #include <sys/dsl_scan.h>
65 #include <sharefs/share.h>
66 #include <sys/dmu_objset.h>
68 #include "zfs_namecheck.h"
70 #include "zfs_deleg.h"
71 #include "zfs_comutil.h"
73 extern struct modlfs zfs_modlfs;
75 extern void zfs_init(void);
76 extern void zfs_fini(void);
78 ldi_ident_t zfs_li = NULL;
81 typedef int zfs_ioc_func_t(zfs_cmd_t *);
82 typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
88 } zfs_ioc_namecheck_t;
90 typedef struct zfs_ioc_vec {
91 zfs_ioc_func_t *zvec_func;
92 zfs_secpolicy_func_t *zvec_secpolicy;
93 zfs_ioc_namecheck_t zvec_namecheck;
94 boolean_t zvec_his_log;
95 boolean_t zvec_pool_check;
98 /* This array is indexed by zfs_userquota_prop_t */
99 static const char *userquota_perms[] = {
100 ZFS_DELEG_PERM_USERUSED,
101 ZFS_DELEG_PERM_USERQUOTA,
102 ZFS_DELEG_PERM_GROUPUSED,
103 ZFS_DELEG_PERM_GROUPQUOTA,
106 static int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
107 static int zfs_check_settable(const char *name, nvpair_t *property,
109 static int zfs_check_clearable(char *dataset, nvlist_t *props,
111 static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
113 int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t **);
115 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
117 __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
124 * Get rid of annoying "../common/" prefix to filename.
126 newfile = strrchr(file, '/');
127 if (newfile != NULL) {
128 newfile = newfile + 1; /* Get rid of leading / */
134 (void) vsnprintf(buf, sizeof (buf), fmt, adx);
138 * To get this data, use the zfs-dprintf probe as so:
139 * dtrace -q -n 'zfs-dprintf \
140 * /stringof(arg0) == "dbuf.c"/ \
141 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
143 * arg1 = function name
147 DTRACE_PROBE4(zfs__dprintf,
148 char *, newfile, char *, func, int, line, char *, buf);
152 history_str_free(char *buf)
154 kmem_free(buf, HIS_MAX_RECORD_LEN);
158 history_str_get(zfs_cmd_t *zc)
162 if (zc->zc_history == NULL)
165 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
166 if (copyinstr((void *)(uintptr_t)zc->zc_history,
167 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
168 history_str_free(buf);
172 buf[HIS_MAX_RECORD_LEN -1] = '\0';
178 * Check to see if the named dataset is currently defined as bootable
181 zfs_is_bootfs(const char *name)
185 if (dmu_objset_hold(name, FTAG, &os) == 0) {
187 ret = (dmu_objset_id(os) == spa_bootfs(dmu_objset_spa(os)));
188 dmu_objset_rele(os, FTAG);
195 * zfs_earlier_version
197 * Return non-zero if the spa version is less than requested version.
200 zfs_earlier_version(const char *name, int version)
204 if (spa_open(name, &spa, FTAG) == 0) {
205 if (spa_version(spa) < version) {
206 spa_close(spa, FTAG);
209 spa_close(spa, FTAG);
215 * zpl_earlier_version
217 * Return TRUE if the ZPL version is less than requested version.
220 zpl_earlier_version(const char *name, int version)
223 boolean_t rc = B_TRUE;
225 if (dmu_objset_hold(name, FTAG, &os) == 0) {
228 if (dmu_objset_type(os) != DMU_OST_ZFS) {
229 dmu_objset_rele(os, FTAG);
232 /* XXX reading from non-owned objset */
233 if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
234 rc = zplversion < version;
235 dmu_objset_rele(os, FTAG);
241 zfs_log_history(zfs_cmd_t *zc)
246 if ((buf = history_str_get(zc)) == NULL)
249 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
250 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
251 (void) spa_history_log(spa, buf, LOG_CMD_NORMAL);
252 spa_close(spa, FTAG);
254 history_str_free(buf);
258 * Policy for top-level read operations (list pools). Requires no privileges,
259 * and can be used in the local zone, as there is no associated dataset.
263 zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
269 * Policy for dataset read operations (list children, get statistics). Requires
270 * no privileges, but must be visible in the local zone.
274 zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
276 if (INGLOBALZONE(curproc) ||
277 zone_dataset_visible(zc->zc_name, NULL))
284 zfs_dozonecheck(const char *dataset, cred_t *cr)
290 * The dataset must be visible by this zone -- check this first
291 * so they don't see EPERM on something they shouldn't know about.
293 if (!INGLOBALZONE(curproc) &&
294 !zone_dataset_visible(dataset, &writable))
297 if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
300 if (INGLOBALZONE(curproc)) {
302 * If the fs is zoned, only root can access it from the
305 if (secpolicy_zfs(cr) && zoned)
309 * If we are in a local zone, the 'zoned' property must be set.
314 /* must be writable by this zone */
322 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
326 error = zfs_dozonecheck(name, cr);
328 error = secpolicy_zfs(cr);
330 error = dsl_deleg_access(name, perm, cr);
336 * Policy for setting the security label property.
338 * Returns 0 for success, non-zero for access and other errors.
341 zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
343 char ds_hexsl[MAXNAMELEN];
344 bslabel_t ds_sl, new_sl;
345 boolean_t new_default = FALSE;
347 int needed_priv = -1;
350 /* First get the existing dataset label. */
351 error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
352 1, sizeof (ds_hexsl), &ds_hexsl, NULL);
356 if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
359 /* The label must be translatable */
360 if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
364 * In a non-global zone, disallow attempts to set a label that
365 * doesn't match that of the zone; otherwise no other checks
368 if (!INGLOBALZONE(curproc)) {
369 if (new_default || !blequal(&new_sl, CR_SL(CRED())))
375 * For global-zone datasets (i.e., those whose zoned property is
376 * "off", verify that the specified new label is valid for the
379 if (dsl_prop_get_integer(name,
380 zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
383 if (zfs_check_global_label(name, strval) != 0)
388 * If the existing dataset label is nondefault, check if the
389 * dataset is mounted (label cannot be changed while mounted).
390 * Get the zfsvfs; if there isn't one, then the dataset isn't
391 * mounted (or isn't a dataset, doesn't exist, ...).
393 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
395 static char *setsl_tag = "setsl_tag";
398 * Try to own the dataset; abort if there is any error,
399 * (e.g., already mounted, in use, or other error).
401 error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
406 dmu_objset_disown(os, setsl_tag);
409 needed_priv = PRIV_FILE_DOWNGRADE_SL;
413 if (hexstr_to_label(strval, &new_sl) != 0)
416 if (blstrictdom(&ds_sl, &new_sl))
417 needed_priv = PRIV_FILE_DOWNGRADE_SL;
418 else if (blstrictdom(&new_sl, &ds_sl))
419 needed_priv = PRIV_FILE_UPGRADE_SL;
421 /* dataset currently has a default label */
423 needed_priv = PRIV_FILE_UPGRADE_SL;
427 if (needed_priv != -1)
428 return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
433 zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
439 * Check permissions for special properties.
444 * Disallow setting of 'zoned' from within a local zone.
446 if (!INGLOBALZONE(curproc))
451 if (!INGLOBALZONE(curproc)) {
453 char setpoint[MAXNAMELEN];
455 * Unprivileged users are allowed to modify the
456 * quota on things *under* (ie. contained by)
457 * the thing they own.
459 if (dsl_prop_get_integer(dsname, "zoned", &zoned,
462 if (!zoned || strlen(dsname) <= strlen(setpoint))
467 case ZFS_PROP_MLSLABEL:
468 if (!is_system_labeled())
471 if (nvpair_value_string(propval, &strval) == 0) {
474 err = zfs_set_slabel_policy(dsname, strval, CRED());
481 return (zfs_secpolicy_write_perms(dsname, zfs_prop_to_name(prop), cr));
485 zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
489 error = zfs_dozonecheck(zc->zc_name, cr);
494 * permission to set permissions will be evaluated later in
495 * dsl_deleg_can_allow()
501 zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
503 return (zfs_secpolicy_write_perms(zc->zc_name,
504 ZFS_DELEG_PERM_ROLLBACK, cr));
508 zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
510 return (zfs_secpolicy_write_perms(zc->zc_name,
511 ZFS_DELEG_PERM_SEND, cr));
515 zfs_secpolicy_deleg_share(zfs_cmd_t *zc, cred_t *cr)
520 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
521 NO_FOLLOW, NULL, &vp)) != 0)
524 /* Now make sure mntpnt and dataset are ZFS */
526 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
527 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
528 zc->zc_name) != 0)) {
534 return (dsl_deleg_access(zc->zc_name,
535 ZFS_DELEG_PERM_SHARE, cr));
539 zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
541 if (!INGLOBALZONE(curproc))
544 if (secpolicy_nfs(cr) == 0) {
547 return (zfs_secpolicy_deleg_share(zc, cr));
552 zfs_secpolicy_smb_acl(zfs_cmd_t *zc, cred_t *cr)
554 if (!INGLOBALZONE(curproc))
557 if (secpolicy_smb(cr) == 0) {
560 return (zfs_secpolicy_deleg_share(zc, cr));
565 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
570 * Remove the @bla or /bla from the end of the name to get the parent.
572 (void) strncpy(parent, datasetname, parentsize);
573 cp = strrchr(parent, '@');
577 cp = strrchr(parent, '/');
587 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
591 if ((error = zfs_secpolicy_write_perms(name,
592 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
595 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
599 zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
601 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
605 * Destroying snapshots with delegated permissions requires
606 * descendent mount and destroy permissions.
607 * Reassemble the full filesystem@snap name so dsl_deleg_access()
608 * can do the correct permission check.
610 * Since this routine is used when doing a recursive destroy of snapshots
611 * and destroying snapshots requires descendent permissions, a successfull
612 * check of the top level snapshot applies to snapshots of all descendent
616 zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, cred_t *cr)
621 dsname = kmem_asprintf("%s@%s", zc->zc_name, zc->zc_value);
623 error = zfs_secpolicy_destroy_perms(dsname, cr);
630 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
632 char parentname[MAXNAMELEN];
635 if ((error = zfs_secpolicy_write_perms(from,
636 ZFS_DELEG_PERM_RENAME, cr)) != 0)
639 if ((error = zfs_secpolicy_write_perms(from,
640 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
643 if ((error = zfs_get_parent(to, parentname,
644 sizeof (parentname))) != 0)
647 if ((error = zfs_secpolicy_write_perms(parentname,
648 ZFS_DELEG_PERM_CREATE, cr)) != 0)
651 if ((error = zfs_secpolicy_write_perms(parentname,
652 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
659 zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
661 return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
665 zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
667 char parentname[MAXNAMELEN];
671 error = zfs_secpolicy_write_perms(zc->zc_name,
672 ZFS_DELEG_PERM_PROMOTE, cr);
676 error = dmu_objset_hold(zc->zc_name, FTAG, &clone);
679 dsl_dataset_t *pclone = NULL;
681 dd = clone->os_dsl_dataset->ds_dir;
683 rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
684 error = dsl_dataset_hold_obj(dd->dd_pool,
685 dd->dd_phys->dd_origin_obj, FTAG, &pclone);
686 rw_exit(&dd->dd_pool->dp_config_rwlock);
688 dmu_objset_rele(clone, FTAG);
692 error = zfs_secpolicy_write_perms(zc->zc_name,
693 ZFS_DELEG_PERM_MOUNT, cr);
695 dsl_dataset_name(pclone, parentname);
696 dmu_objset_rele(clone, FTAG);
697 dsl_dataset_rele(pclone, FTAG);
699 error = zfs_secpolicy_write_perms(parentname,
700 ZFS_DELEG_PERM_PROMOTE, cr);
706 zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
710 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
711 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
714 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
715 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
718 return (zfs_secpolicy_write_perms(zc->zc_name,
719 ZFS_DELEG_PERM_CREATE, cr));
723 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
725 return (zfs_secpolicy_write_perms(name,
726 ZFS_DELEG_PERM_SNAPSHOT, cr));
730 zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
733 return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
737 zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
739 char parentname[MAXNAMELEN];
742 if ((error = zfs_get_parent(zc->zc_name, parentname,
743 sizeof (parentname))) != 0)
746 if (zc->zc_value[0] != '\0') {
747 if ((error = zfs_secpolicy_write_perms(zc->zc_value,
748 ZFS_DELEG_PERM_CLONE, cr)) != 0)
752 if ((error = zfs_secpolicy_write_perms(parentname,
753 ZFS_DELEG_PERM_CREATE, cr)) != 0)
756 error = zfs_secpolicy_write_perms(parentname,
757 ZFS_DELEG_PERM_MOUNT, cr);
763 zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
767 error = secpolicy_fs_unmount(cr, NULL);
769 error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
775 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
776 * SYS_CONFIG privilege, which is not available in a local zone.
780 zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
782 if (secpolicy_sys_config(cr, B_FALSE) != 0)
789 * Policy for fault injection. Requires all privileges.
793 zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
795 return (secpolicy_zinject(cr));
799 zfs_secpolicy_inherit(zfs_cmd_t *zc, cred_t *cr)
801 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
803 if (prop == ZPROP_INVAL) {
804 if (!zfs_prop_user(zc->zc_value))
806 return (zfs_secpolicy_write_perms(zc->zc_name,
807 ZFS_DELEG_PERM_USERPROP, cr));
809 return (zfs_secpolicy_setprop(zc->zc_name, prop,
815 zfs_secpolicy_userspace_one(zfs_cmd_t *zc, cred_t *cr)
817 int err = zfs_secpolicy_read(zc, cr);
821 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
824 if (zc->zc_value[0] == 0) {
826 * They are asking about a posix uid/gid. If it's
827 * themself, allow it.
829 if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
830 zc->zc_objset_type == ZFS_PROP_USERQUOTA) {
831 if (zc->zc_guid == crgetuid(cr))
834 if (groupmember(zc->zc_guid, cr))
839 return (zfs_secpolicy_write_perms(zc->zc_name,
840 userquota_perms[zc->zc_objset_type], cr));
844 zfs_secpolicy_userspace_many(zfs_cmd_t *zc, cred_t *cr)
846 int err = zfs_secpolicy_read(zc, cr);
850 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
853 return (zfs_secpolicy_write_perms(zc->zc_name,
854 userquota_perms[zc->zc_objset_type], cr));
858 zfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, cred_t *cr)
860 return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION,
865 zfs_secpolicy_hold(zfs_cmd_t *zc, cred_t *cr)
867 return (zfs_secpolicy_write_perms(zc->zc_name,
868 ZFS_DELEG_PERM_HOLD, cr));
872 zfs_secpolicy_release(zfs_cmd_t *zc, cred_t *cr)
874 return (zfs_secpolicy_write_perms(zc->zc_name,
875 ZFS_DELEG_PERM_RELEASE, cr));
879 * Returns the nvlist as specified by the user in the zfs_cmd_t.
882 get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
886 nvlist_t *list = NULL;
889 * Read in and unpack the user-supplied nvlist.
894 packed = kmem_alloc(size, KM_SLEEP);
896 if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
898 kmem_free(packed, size);
902 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
903 kmem_free(packed, size);
907 kmem_free(packed, size);
914 fit_error_list(zfs_cmd_t *zc, nvlist_t **errors)
918 VERIFY(nvlist_size(*errors, &size, NV_ENCODE_NATIVE) == 0);
920 if (size > zc->zc_nvlist_dst_size) {
921 nvpair_t *more_errors;
924 if (zc->zc_nvlist_dst_size < 1024)
927 VERIFY(nvlist_add_int32(*errors, ZPROP_N_MORE_ERRORS, 0) == 0);
928 more_errors = nvlist_prev_nvpair(*errors, NULL);
931 nvpair_t *pair = nvlist_prev_nvpair(*errors,
933 VERIFY(nvlist_remove_nvpair(*errors, pair) == 0);
935 VERIFY(nvlist_size(*errors, &size,
936 NV_ENCODE_NATIVE) == 0);
937 } while (size > zc->zc_nvlist_dst_size);
939 VERIFY(nvlist_remove_nvpair(*errors, more_errors) == 0);
940 VERIFY(nvlist_add_int32(*errors, ZPROP_N_MORE_ERRORS, n) == 0);
941 ASSERT(nvlist_size(*errors, &size, NV_ENCODE_NATIVE) == 0);
942 ASSERT(size <= zc->zc_nvlist_dst_size);
949 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
955 VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
957 if (size > zc->zc_nvlist_dst_size) {
960 packed = kmem_alloc(size, KM_SLEEP);
961 VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
963 if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
964 size, zc->zc_iflags) != 0)
966 kmem_free(packed, size);
969 zc->zc_nvlist_dst_size = size;
974 getzfsvfs(const char *dsname, zfsvfs_t **zfvp)
979 error = dmu_objset_hold(dsname, FTAG, &os);
982 if (dmu_objset_type(os) != DMU_OST_ZFS) {
983 dmu_objset_rele(os, FTAG);
987 mutex_enter(&os->os_user_ptr_lock);
988 *zfvp = dmu_objset_get_user(os);
990 VFS_HOLD((*zfvp)->z_vfs);
994 mutex_exit(&os->os_user_ptr_lock);
995 dmu_objset_rele(os, FTAG);
1000 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1001 * case its z_vfs will be NULL, and it will be opened as the owner.
1004 zfsvfs_hold(const char *name, void *tag, zfsvfs_t **zfvp)
1008 if (getzfsvfs(name, zfvp) != 0)
1009 error = zfsvfs_create(name, zfvp);
1011 rrw_enter(&(*zfvp)->z_teardown_lock, RW_READER, tag);
1012 if ((*zfvp)->z_unmounted) {
1014 * XXX we could probably try again, since the unmounting
1015 * thread should be just about to disassociate the
1016 * objset from the zfsvfs.
1018 rrw_exit(&(*zfvp)->z_teardown_lock, tag);
1026 zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
1028 rrw_exit(&zfsvfs->z_teardown_lock, tag);
1030 if (zfsvfs->z_vfs) {
1031 VFS_RELE(zfsvfs->z_vfs);
1033 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1034 zfsvfs_free(zfsvfs);
1039 zfs_ioc_pool_create(zfs_cmd_t *zc)
1042 nvlist_t *config, *props = NULL;
1043 nvlist_t *rootprops = NULL;
1044 nvlist_t *zplprops = NULL;
1047 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1048 zc->zc_iflags, &config))
1051 if (zc->zc_nvlist_src_size != 0 && (error =
1052 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1053 zc->zc_iflags, &props))) {
1054 nvlist_free(config);
1059 nvlist_t *nvl = NULL;
1060 uint64_t version = SPA_VERSION;
1062 (void) nvlist_lookup_uint64(props,
1063 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
1064 if (version < SPA_VERSION_INITIAL || version > SPA_VERSION) {
1066 goto pool_props_bad;
1068 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
1070 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
1072 nvlist_free(config);
1076 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
1078 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1079 error = zfs_fill_zplprops_root(version, rootprops,
1082 goto pool_props_bad;
1085 buf = history_str_get(zc);
1087 error = spa_create(zc->zc_name, config, props, buf, zplprops);
1090 * Set the remaining root properties
1092 if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
1093 ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
1094 (void) spa_destroy(zc->zc_name);
1097 history_str_free(buf);
1100 nvlist_free(rootprops);
1101 nvlist_free(zplprops);
1102 nvlist_free(config);
1109 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
1112 zfs_log_history(zc);
1113 error = spa_destroy(zc->zc_name);
1115 zvol_remove_minors(zc->zc_name);
1120 zfs_ioc_pool_import(zfs_cmd_t *zc)
1122 nvlist_t *config, *props = NULL;
1126 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1127 zc->zc_iflags, &config)) != 0)
1130 if (zc->zc_nvlist_src_size != 0 && (error =
1131 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1132 zc->zc_iflags, &props))) {
1133 nvlist_free(config);
1137 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1138 guid != zc->zc_guid)
1140 else if (zc->zc_cookie)
1141 error = spa_import_verbatim(zc->zc_name, config, props);
1143 error = spa_import(zc->zc_name, config, props);
1145 if (zc->zc_nvlist_dst != 0)
1146 (void) put_nvlist(zc, config);
1148 nvlist_free(config);
1157 zfs_ioc_pool_export(zfs_cmd_t *zc)
1160 boolean_t force = (boolean_t)zc->zc_cookie;
1161 boolean_t hardforce = (boolean_t)zc->zc_guid;
1163 zfs_log_history(zc);
1164 error = spa_export(zc->zc_name, NULL, force, hardforce);
1166 zvol_remove_minors(zc->zc_name);
1171 zfs_ioc_pool_configs(zfs_cmd_t *zc)
1176 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
1179 error = put_nvlist(zc, configs);
1181 nvlist_free(configs);
1187 zfs_ioc_pool_stats(zfs_cmd_t *zc)
1193 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
1194 sizeof (zc->zc_value));
1196 if (config != NULL) {
1197 ret = put_nvlist(zc, config);
1198 nvlist_free(config);
1201 * The config may be present even if 'error' is non-zero.
1202 * In this case we return success, and preserve the real errno
1205 zc->zc_cookie = error;
1214 * Try to import the given pool, returning pool stats as appropriate so that
1215 * user land knows which devices are available and overall pool health.
1218 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
1220 nvlist_t *tryconfig, *config;
1223 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1224 zc->zc_iflags, &tryconfig)) != 0)
1227 config = spa_tryimport(tryconfig);
1229 nvlist_free(tryconfig);
1234 error = put_nvlist(zc, config);
1235 nvlist_free(config);
1242 * zc_name name of the pool
1243 * zc_cookie scan func (pool_scan_func_t)
1246 zfs_ioc_pool_scan(zfs_cmd_t *zc)
1251 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1254 if (zc->zc_cookie == POOL_SCAN_NONE)
1255 error = spa_scan_stop(spa);
1257 error = spa_scan(spa, zc->zc_cookie);
1259 spa_close(spa, FTAG);
1265 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
1270 error = spa_open(zc->zc_name, &spa, FTAG);
1273 spa_close(spa, FTAG);
1279 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
1284 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1287 if (zc->zc_cookie < spa_version(spa) || zc->zc_cookie > SPA_VERSION) {
1288 spa_close(spa, FTAG);
1292 spa_upgrade(spa, zc->zc_cookie);
1293 spa_close(spa, FTAG);
1299 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
1306 if ((size = zc->zc_history_len) == 0)
1309 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1312 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
1313 spa_close(spa, FTAG);
1317 hist_buf = kmem_alloc(size, KM_SLEEP);
1318 if ((error = spa_history_get(spa, &zc->zc_history_offset,
1319 &zc->zc_history_len, hist_buf)) == 0) {
1320 error = ddi_copyout(hist_buf,
1321 (void *)(uintptr_t)zc->zc_history,
1322 zc->zc_history_len, zc->zc_iflags);
1325 spa_close(spa, FTAG);
1326 kmem_free(hist_buf, size);
1331 zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
1335 if (error = dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value))
1343 * zc_name name of filesystem
1344 * zc_obj object to find
1347 * zc_value name of object
1350 zfs_ioc_obj_to_path(zfs_cmd_t *zc)
1355 /* XXX reading from objset not owned */
1356 if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
1358 if (dmu_objset_type(os) != DMU_OST_ZFS) {
1359 dmu_objset_rele(os, FTAG);
1362 error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
1363 sizeof (zc->zc_value));
1364 dmu_objset_rele(os, FTAG);
1370 zfs_ioc_vdev_add(zfs_cmd_t *zc)
1374 nvlist_t *config, **l2cache, **spares;
1375 uint_t nl2cache = 0, nspares = 0;
1377 error = spa_open(zc->zc_name, &spa, FTAG);
1381 error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1382 zc->zc_iflags, &config);
1383 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
1384 &l2cache, &nl2cache);
1386 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
1390 * A root pool with concatenated devices is not supported.
1391 * Thus, can not add a device to a root pool.
1393 * Intent log device can not be added to a rootpool because
1394 * during mountroot, zil is replayed, a seperated log device
1395 * can not be accessed during the mountroot time.
1397 * l2cache and spare devices are ok to be added to a rootpool.
1399 if (spa_bootfs(spa) != 0 && nl2cache == 0 && nspares == 0) {
1400 nvlist_free(config);
1401 spa_close(spa, FTAG);
1406 error = spa_vdev_add(spa, config);
1407 nvlist_free(config);
1409 spa_close(spa, FTAG);
1415 * zc_name name of the pool
1416 * zc_nvlist_conf nvlist of devices to remove
1417 * zc_cookie to stop the remove?
1420 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
1425 error = spa_open(zc->zc_name, &spa, FTAG);
1428 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
1429 spa_close(spa, FTAG);
1434 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
1438 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1440 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1442 switch (zc->zc_cookie) {
1443 case VDEV_STATE_ONLINE:
1444 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
1447 case VDEV_STATE_OFFLINE:
1448 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
1451 case VDEV_STATE_FAULTED:
1452 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1453 zc->zc_obj != VDEV_AUX_EXTERNAL)
1454 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1456 error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
1459 case VDEV_STATE_DEGRADED:
1460 if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
1461 zc->zc_obj != VDEV_AUX_EXTERNAL)
1462 zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
1464 error = vdev_degrade(spa, zc->zc_guid, zc->zc_obj);
1470 zc->zc_cookie = newstate;
1471 spa_close(spa, FTAG);
1476 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
1479 int replacing = zc->zc_cookie;
1483 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1486 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1487 zc->zc_iflags, &config)) == 0) {
1488 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
1489 nvlist_free(config);
1492 spa_close(spa, FTAG);
1497 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
1502 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1505 error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
1507 spa_close(spa, FTAG);
1512 zfs_ioc_vdev_split(zfs_cmd_t *zc)
1515 nvlist_t *config, *props = NULL;
1517 boolean_t exp = !!(zc->zc_cookie & ZPOOL_EXPORT_AFTER_SPLIT);
1519 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1522 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1523 zc->zc_iflags, &config)) {
1524 spa_close(spa, FTAG);
1528 if (zc->zc_nvlist_src_size != 0 && (error =
1529 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1530 zc->zc_iflags, &props))) {
1531 spa_close(spa, FTAG);
1532 nvlist_free(config);
1536 error = spa_vdev_split_mirror(spa, zc->zc_string, config, props, exp);
1538 spa_close(spa, FTAG);
1540 nvlist_free(config);
1547 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
1550 char *path = zc->zc_value;
1551 uint64_t guid = zc->zc_guid;
1554 error = spa_open(zc->zc_name, &spa, FTAG);
1558 error = spa_vdev_setpath(spa, guid, path);
1559 spa_close(spa, FTAG);
1564 zfs_ioc_vdev_setfru(zfs_cmd_t *zc)
1567 char *fru = zc->zc_value;
1568 uint64_t guid = zc->zc_guid;
1571 error = spa_open(zc->zc_name, &spa, FTAG);
1575 error = spa_vdev_setfru(spa, guid, fru);
1576 spa_close(spa, FTAG);
1582 * zc_name name of filesystem
1583 * zc_nvlist_dst_size size of buffer for property nvlist
1586 * zc_objset_stats stats
1587 * zc_nvlist_dst property nvlist
1588 * zc_nvlist_dst_size size of property nvlist
1591 zfs_ioc_objset_stats(zfs_cmd_t *zc)
1593 objset_t *os = NULL;
1597 if (error = dmu_objset_hold(zc->zc_name, FTAG, &os))
1600 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
1602 if (zc->zc_nvlist_dst != 0 &&
1603 (error = dsl_prop_get_all(os, &nv)) == 0) {
1604 dmu_objset_stats(os, nv);
1606 * NB: zvol_get_stats() will read the objset contents,
1607 * which we aren't supposed to do with a
1608 * DS_MODE_USER hold, because it could be
1609 * inconsistent. So this is a bit of a workaround...
1610 * XXX reading with out owning
1612 if (!zc->zc_objset_stats.dds_inconsistent) {
1613 if (dmu_objset_type(os) == DMU_OST_ZVOL)
1614 VERIFY(zvol_get_stats(os, nv) == 0);
1616 error = put_nvlist(zc, nv);
1620 dmu_objset_rele(os, FTAG);
1626 * zc_name name of filesystem
1627 * zc_nvlist_dst_size size of buffer for property nvlist
1630 * zc_nvlist_dst received property nvlist
1631 * zc_nvlist_dst_size size of received property nvlist
1633 * Gets received properties (distinct from local properties on or after
1634 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
1635 * local property values.
1638 zfs_ioc_objset_recvd_props(zfs_cmd_t *zc)
1640 objset_t *os = NULL;
1644 if (error = dmu_objset_hold(zc->zc_name, FTAG, &os))
1648 * Without this check, we would return local property values if the
1649 * caller has not already received properties on or after
1650 * SPA_VERSION_RECVD_PROPS.
1652 if (!dsl_prop_get_hasrecvd(os)) {
1653 dmu_objset_rele(os, FTAG);
1657 if (zc->zc_nvlist_dst != 0 &&
1658 (error = dsl_prop_get_received(os, &nv)) == 0) {
1659 error = put_nvlist(zc, nv);
1663 dmu_objset_rele(os, FTAG);
1668 nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
1674 * zfs_get_zplprop() will either find a value or give us
1675 * the default value (if there is one).
1677 if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
1679 VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
1685 * zc_name name of filesystem
1686 * zc_nvlist_dst_size size of buffer for zpl property nvlist
1689 * zc_nvlist_dst zpl property nvlist
1690 * zc_nvlist_dst_size size of zpl property nvlist
1693 zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
1698 /* XXX reading without owning */
1699 if (err = dmu_objset_hold(zc->zc_name, FTAG, &os))
1702 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
1705 * NB: nvl_add_zplprop() will read the objset contents,
1706 * which we aren't supposed to do with a DS_MODE_USER
1707 * hold, because it could be inconsistent.
1709 if (zc->zc_nvlist_dst != NULL &&
1710 !zc->zc_objset_stats.dds_inconsistent &&
1711 dmu_objset_type(os) == DMU_OST_ZFS) {
1714 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1715 if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
1716 (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
1717 (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
1718 (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
1719 err = put_nvlist(zc, nv);
1724 dmu_objset_rele(os, FTAG);
1729 dataset_name_hidden(const char *name)
1732 * Skip over datasets that are not visible in this zone,
1733 * internal datasets (which have a $ in their name), and
1734 * temporary datasets (which have a % in their name).
1736 if (strchr(name, '$') != NULL)
1738 if (strchr(name, '%') != NULL)
1740 if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
1747 * zc_name name of filesystem
1748 * zc_cookie zap cursor
1749 * zc_nvlist_dst_size size of buffer for property nvlist
1752 * zc_name name of next filesystem
1753 * zc_cookie zap cursor
1754 * zc_objset_stats stats
1755 * zc_nvlist_dst property nvlist
1756 * zc_nvlist_dst_size size of property nvlist
1759 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
1764 size_t orig_len = strlen(zc->zc_name);
1767 if (error = dmu_objset_hold(zc->zc_name, FTAG, &os)) {
1768 if (error == ENOENT)
1773 p = strrchr(zc->zc_name, '/');
1774 if (p == NULL || p[1] != '\0')
1775 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
1776 p = zc->zc_name + strlen(zc->zc_name);
1779 * Pre-fetch the datasets. dmu_objset_prefetch() always returns 0
1780 * but is not declared void because its called by dmu_objset_find().
1782 if (zc->zc_cookie == 0) {
1783 uint64_t cookie = 0;
1784 int len = sizeof (zc->zc_name) - (p - zc->zc_name);
1786 while (dmu_dir_list_next(os, len, p, NULL, &cookie) == 0)
1787 (void) dmu_objset_prefetch(p, NULL);
1791 error = dmu_dir_list_next(os,
1792 sizeof (zc->zc_name) - (p - zc->zc_name), p,
1793 NULL, &zc->zc_cookie);
1794 if (error == ENOENT)
1796 } while (error == 0 && dataset_name_hidden(zc->zc_name) &&
1797 !(zc->zc_iflags & FKIOCTL));
1798 dmu_objset_rele(os, FTAG);
1801 * If it's an internal dataset (ie. with a '$' in its name),
1802 * don't try to get stats for it, otherwise we'll return ENOENT.
1804 if (error == 0 && strchr(zc->zc_name, '$') == NULL) {
1805 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
1806 if (error == ENOENT) {
1807 /* We lost a race with destroy, get the next one. */
1808 zc->zc_name[orig_len] = '\0';
1817 * zc_name name of filesystem
1818 * zc_cookie zap cursor
1819 * zc_nvlist_dst_size size of buffer for property nvlist
1822 * zc_name name of next snapshot
1823 * zc_objset_stats stats
1824 * zc_nvlist_dst property nvlist
1825 * zc_nvlist_dst_size size of property nvlist
1828 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
1834 if (zc->zc_cookie == 0)
1835 (void) dmu_objset_find(zc->zc_name, dmu_objset_prefetch,
1836 NULL, DS_FIND_SNAPSHOTS);
1838 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
1840 return (error == ENOENT ? ESRCH : error);
1843 * A dataset name of maximum length cannot have any snapshots,
1844 * so exit immediately.
1846 if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
1847 dmu_objset_rele(os, FTAG);
1851 error = dmu_snapshot_list_next(os,
1852 sizeof (zc->zc_name) - strlen(zc->zc_name),
1853 zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie, NULL);
1854 dmu_objset_rele(os, FTAG);
1856 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
1857 if (error == ENOENT) {
1858 /* We lost a race with destroy, get the next one. */
1859 *strchr(zc->zc_name, '@') = '\0';
1862 } else if (error == ENOENT) {
1866 /* if we failed, undo the @ that we tacked on to zc_name */
1868 *strchr(zc->zc_name, '@') = '\0';
1873 zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
1875 const char *propname = nvpair_name(pair);
1877 unsigned int vallen;
1880 zfs_userquota_prop_t type;
1886 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
1888 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
1889 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
1895 * A correctly constructed propname is encoded as
1896 * userquota@<rid>-<domain>.
1898 if ((dash = strchr(propname, '-')) == NULL ||
1899 nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
1908 err = zfsvfs_hold(dsname, FTAG, &zfsvfs);
1910 err = zfs_set_userquota(zfsvfs, type, domain, rid, quota);
1911 zfsvfs_rele(zfsvfs, FTAG);
1918 * If the named property is one that has a special function to set its value,
1919 * return 0 on success and a positive error code on failure; otherwise if it is
1920 * not one of the special properties handled by this function, return -1.
1922 * XXX: It would be better for callers of the property interface if we handled
1923 * these special cases in dsl_prop.c (in the dsl layer).
1926 zfs_prop_set_special(const char *dsname, zprop_source_t source,
1929 const char *propname = nvpair_name(pair);
1930 zfs_prop_t prop = zfs_name_to_prop(propname);
1934 if (prop == ZPROP_INVAL) {
1935 if (zfs_prop_userquota(propname))
1936 return (zfs_prop_set_userquota(dsname, pair));
1940 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
1942 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
1943 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
1947 if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
1950 VERIFY(0 == nvpair_value_uint64(pair, &intval));
1953 case ZFS_PROP_QUOTA:
1954 err = dsl_dir_set_quota(dsname, source, intval);
1956 case ZFS_PROP_REFQUOTA:
1957 err = dsl_dataset_set_quota(dsname, source, intval);
1959 case ZFS_PROP_RESERVATION:
1960 err = dsl_dir_set_reservation(dsname, source, intval);
1962 case ZFS_PROP_REFRESERVATION:
1963 err = dsl_dataset_set_reservation(dsname, source, intval);
1965 case ZFS_PROP_VOLSIZE:
1966 err = zvol_set_volsize(dsname, ddi_driver_major(zfs_dip),
1969 case ZFS_PROP_VERSION:
1973 if ((err = zfsvfs_hold(dsname, FTAG, &zfsvfs)) != 0)
1976 err = zfs_set_version(zfsvfs, intval);
1977 zfsvfs_rele(zfsvfs, FTAG);
1979 if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
1982 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
1983 (void) strcpy(zc->zc_name, dsname);
1984 (void) zfs_ioc_userspace_upgrade(zc);
1985 kmem_free(zc, sizeof (zfs_cmd_t));
1998 * This function is best effort. If it fails to set any of the given properties,
1999 * it continues to set as many as it can and returns the first error
2000 * encountered. If the caller provides a non-NULL errlist, it also gives the
2001 * complete list of names of all the properties it failed to set along with the
2002 * corresponding error numbers. The caller is responsible for freeing the
2005 * If every property is set successfully, zero is returned and the list pointed
2006 * at by errlist is NULL.
2009 zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
2017 nvlist_t *genericnvl;
2021 VERIFY(nvlist_alloc(&genericnvl, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2022 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2023 VERIFY(nvlist_alloc(&retrynvl, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2027 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2028 const char *propname = nvpair_name(pair);
2029 zfs_prop_t prop = zfs_name_to_prop(propname);
2032 /* decode the property value */
2034 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2036 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2037 if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2042 /* Validate value type */
2043 if (err == 0 && prop == ZPROP_INVAL) {
2044 if (zfs_prop_user(propname)) {
2045 if (nvpair_type(propval) != DATA_TYPE_STRING)
2047 } else if (zfs_prop_userquota(propname)) {
2048 if (nvpair_type(propval) !=
2049 DATA_TYPE_UINT64_ARRAY)
2052 } else if (err == 0) {
2053 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2054 if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
2056 } else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
2059 VERIFY(nvpair_value_uint64(propval,
2062 switch (zfs_prop_get_type(prop)) {
2063 case PROP_TYPE_NUMBER:
2065 case PROP_TYPE_STRING:
2068 case PROP_TYPE_INDEX:
2069 if (zfs_prop_index_to_string(prop,
2070 intval, &unused) != 0)
2075 "unknown property type");
2082 /* Validate permissions */
2084 err = zfs_check_settable(dsname, pair, CRED());
2087 err = zfs_prop_set_special(dsname, source, pair);
2090 * For better performance we build up a list of
2091 * properties to set in a single transaction.
2093 err = nvlist_add_nvpair(genericnvl, pair);
2094 } else if (err != 0 && nvl != retrynvl) {
2096 * This may be a spurious error caused by
2097 * receiving quota and reservation out of order.
2098 * Try again in a second pass.
2100 err = nvlist_add_nvpair(retrynvl, pair);
2105 VERIFY(nvlist_add_int32(errors, propname, err) == 0);
2108 if (nvl != retrynvl && !nvlist_empty(retrynvl)) {
2113 if (!nvlist_empty(genericnvl) &&
2114 dsl_props_set(dsname, source, genericnvl) != 0) {
2116 * If this fails, we still want to set as many properties as we
2117 * can, so try setting them individually.
2120 while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) {
2121 const char *propname = nvpair_name(pair);
2125 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
2127 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
2128 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
2132 if (nvpair_type(propval) == DATA_TYPE_STRING) {
2133 VERIFY(nvpair_value_string(propval,
2135 err = dsl_prop_set(dsname, propname, source, 1,
2136 strlen(strval) + 1, strval);
2138 VERIFY(nvpair_value_uint64(propval,
2140 err = dsl_prop_set(dsname, propname, source, 8,
2145 VERIFY(nvlist_add_int32(errors, propname,
2150 nvlist_free(genericnvl);
2151 nvlist_free(retrynvl);
2153 if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
2154 nvlist_free(errors);
2157 VERIFY(nvpair_value_int32(pair, &rv) == 0);
2160 if (errlist == NULL)
2161 nvlist_free(errors);
2169 * Check that all the properties are valid user properties.
2172 zfs_check_userprops(char *fsname, nvlist_t *nvl)
2174 nvpair_t *pair = NULL;
2177 while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
2178 const char *propname = nvpair_name(pair);
2181 if (!zfs_prop_user(propname) ||
2182 nvpair_type(pair) != DATA_TYPE_STRING)
2185 if (error = zfs_secpolicy_write_perms(fsname,
2186 ZFS_DELEG_PERM_USERPROP, CRED()))
2189 if (strlen(propname) >= ZAP_MAXNAMELEN)
2190 return (ENAMETOOLONG);
2192 VERIFY(nvpair_value_string(pair, &valstr) == 0);
2193 if (strlen(valstr) >= ZAP_MAXVALUELEN)
2200 props_skip(nvlist_t *props, nvlist_t *skipped, nvlist_t **newprops)
2204 VERIFY(nvlist_alloc(newprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2207 while ((pair = nvlist_next_nvpair(props, pair)) != NULL) {
2208 if (nvlist_exists(skipped, nvpair_name(pair)))
2211 VERIFY(nvlist_add_nvpair(*newprops, pair) == 0);
2216 clear_received_props(objset_t *os, const char *fs, nvlist_t *props,
2220 nvlist_t *cleared_props = NULL;
2221 props_skip(props, skipped, &cleared_props);
2222 if (!nvlist_empty(cleared_props)) {
2224 * Acts on local properties until the dataset has received
2225 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2227 zprop_source_t flags = (ZPROP_SRC_NONE |
2228 (dsl_prop_get_hasrecvd(os) ? ZPROP_SRC_RECEIVED : 0));
2229 err = zfs_set_prop_nvlist(fs, flags, cleared_props, NULL);
2231 nvlist_free(cleared_props);
2237 * zc_name name of filesystem
2238 * zc_value name of property to set
2239 * zc_nvlist_src{_size} nvlist of properties to apply
2240 * zc_cookie received properties flag
2243 * zc_nvlist_dst{_size} error for each unapplied received property
2246 zfs_ioc_set_prop(zfs_cmd_t *zc)
2249 boolean_t received = zc->zc_cookie;
2250 zprop_source_t source = (received ? ZPROP_SRC_RECEIVED :
2252 nvlist_t *errors = NULL;
2255 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2256 zc->zc_iflags, &nvl)) != 0)
2260 nvlist_t *origprops;
2263 if (dmu_objset_hold(zc->zc_name, FTAG, &os) == 0) {
2264 if (dsl_prop_get_received(os, &origprops) == 0) {
2265 (void) clear_received_props(os,
2266 zc->zc_name, origprops, nvl);
2267 nvlist_free(origprops);
2270 dsl_prop_set_hasrecvd(os);
2271 dmu_objset_rele(os, FTAG);
2275 error = zfs_set_prop_nvlist(zc->zc_name, source, nvl, &errors);
2277 if (zc->zc_nvlist_dst != NULL && errors != NULL) {
2278 (void) put_nvlist(zc, errors);
2281 nvlist_free(errors);
2288 * zc_name name of filesystem
2289 * zc_value name of property to inherit
2290 * zc_cookie revert to received value if TRUE
2295 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
2297 const char *propname = zc->zc_value;
2298 zfs_prop_t prop = zfs_name_to_prop(propname);
2299 boolean_t received = zc->zc_cookie;
2300 zprop_source_t source = (received
2301 ? ZPROP_SRC_NONE /* revert to received value, if any */
2302 : ZPROP_SRC_INHERITED); /* explicitly inherit */
2311 * zfs_prop_set_special() expects properties in the form of an
2312 * nvpair with type info.
2314 if (prop == ZPROP_INVAL) {
2315 if (!zfs_prop_user(propname))
2318 type = PROP_TYPE_STRING;
2319 } else if (prop == ZFS_PROP_VOLSIZE ||
2320 prop == ZFS_PROP_VERSION) {
2323 type = zfs_prop_get_type(prop);
2326 VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
2329 case PROP_TYPE_STRING:
2330 VERIFY(0 == nvlist_add_string(dummy, propname, ""));
2332 case PROP_TYPE_NUMBER:
2333 case PROP_TYPE_INDEX:
2334 VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
2341 pair = nvlist_next_nvpair(dummy, NULL);
2342 err = zfs_prop_set_special(zc->zc_name, source, pair);
2345 return (err); /* special property already handled */
2348 * Only check this in the non-received case. We want to allow
2349 * 'inherit -S' to revert non-inheritable properties like quota
2350 * and reservation to the received or default values even though
2351 * they are not considered inheritable.
2353 if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
2357 /* the property name has been validated by zfs_secpolicy_inherit() */
2358 return (dsl_prop_set(zc->zc_name, zc->zc_value, source, 0, 0, NULL));
2362 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
2369 if (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2370 zc->zc_iflags, &props))
2374 * If the only property is the configfile, then just do a spa_lookup()
2375 * to handle the faulted case.
2377 pair = nvlist_next_nvpair(props, NULL);
2378 if (pair != NULL && strcmp(nvpair_name(pair),
2379 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
2380 nvlist_next_nvpair(props, pair) == NULL) {
2381 mutex_enter(&spa_namespace_lock);
2382 if ((spa = spa_lookup(zc->zc_name)) != NULL) {
2383 spa_configfile_set(spa, props, B_FALSE);
2384 spa_config_sync(spa, B_FALSE, B_TRUE);
2386 mutex_exit(&spa_namespace_lock);
2393 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2398 error = spa_prop_set(spa, props);
2401 spa_close(spa, FTAG);
2407 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
2411 nvlist_t *nvp = NULL;
2413 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
2415 * If the pool is faulted, there may be properties we can still
2416 * get (such as altroot and cachefile), so attempt to get them
2419 mutex_enter(&spa_namespace_lock);
2420 if ((spa = spa_lookup(zc->zc_name)) != NULL)
2421 error = spa_prop_get(spa, &nvp);
2422 mutex_exit(&spa_namespace_lock);
2424 error = spa_prop_get(spa, &nvp);
2425 spa_close(spa, FTAG);
2428 if (error == 0 && zc->zc_nvlist_dst != NULL)
2429 error = put_nvlist(zc, nvp);
2439 * zc_name name of filesystem
2440 * zc_nvlist_src{_size} nvlist of delegated permissions
2441 * zc_perm_action allow/unallow flag
2446 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
2449 nvlist_t *fsaclnv = NULL;
2451 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2452 zc->zc_iflags, &fsaclnv)) != 0)
2456 * Verify nvlist is constructed correctly
2458 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
2459 nvlist_free(fsaclnv);
2464 * If we don't have PRIV_SYS_MOUNT, then validate
2465 * that user is allowed to hand out each permission in
2469 error = secpolicy_zfs(CRED());
2471 if (zc->zc_perm_action == B_FALSE) {
2472 error = dsl_deleg_can_allow(zc->zc_name,
2475 error = dsl_deleg_can_unallow(zc->zc_name,
2481 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
2483 nvlist_free(fsaclnv);
2489 * zc_name name of filesystem
2492 * zc_nvlist_src{_size} nvlist of delegated permissions
2495 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
2500 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
2501 error = put_nvlist(zc, nvp);
2509 * Search the vfs list for a specified resource. Returns a pointer to it
2510 * or NULL if no suitable entry is found. The caller of this routine
2511 * is responsible for releasing the returned vfs pointer.
2514 zfs_get_vfs(const char *resource)
2517 struct vfs *vfs_found = NULL;
2519 vfs_list_read_lock();
2522 if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
2527 vfsp = vfsp->vfs_next;
2528 } while (vfsp != rootvfs);
2535 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
2537 zfs_creat_t *zct = arg;
2539 zfs_create_fs(os, cr, zct->zct_zplprops, tx);
2542 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2546 * createprops list of properties requested by creator
2547 * default_zplver zpl version to use if unspecified in createprops
2548 * fuids_ok fuids allowed in this version of the spa?
2549 * os parent objset pointer (NULL if root fs)
2552 * zplprops values for the zplprops we attach to the master node object
2553 * is_ci true if requested file system will be purely case-insensitive
2555 * Determine the settings for utf8only, normalization and
2556 * casesensitivity. Specific values may have been requested by the
2557 * creator and/or we can inherit values from the parent dataset. If
2558 * the file system is of too early a vintage, a creator can not
2559 * request settings for these properties, even if the requested
2560 * setting is the default value. We don't actually want to create dsl
2561 * properties for these, so remove them from the source nvlist after
2565 zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
2566 boolean_t fuids_ok, boolean_t sa_ok, nvlist_t *createprops,
2567 nvlist_t *zplprops, boolean_t *is_ci)
2569 uint64_t sense = ZFS_PROP_UNDEFINED;
2570 uint64_t norm = ZFS_PROP_UNDEFINED;
2571 uint64_t u8 = ZFS_PROP_UNDEFINED;
2573 ASSERT(zplprops != NULL);
2576 * Pull out creator prop choices, if any.
2579 (void) nvlist_lookup_uint64(createprops,
2580 zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
2581 (void) nvlist_lookup_uint64(createprops,
2582 zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
2583 (void) nvlist_remove_all(createprops,
2584 zfs_prop_to_name(ZFS_PROP_NORMALIZE));
2585 (void) nvlist_lookup_uint64(createprops,
2586 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
2587 (void) nvlist_remove_all(createprops,
2588 zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
2589 (void) nvlist_lookup_uint64(createprops,
2590 zfs_prop_to_name(ZFS_PROP_CASE), &sense);
2591 (void) nvlist_remove_all(createprops,
2592 zfs_prop_to_name(ZFS_PROP_CASE));
2596 * If the zpl version requested is whacky or the file system
2597 * or pool is version is too "young" to support normalization
2598 * and the creator tried to set a value for one of the props,
2601 if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
2602 (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
2603 (zplver >= ZPL_VERSION_SA && !sa_ok) ||
2604 (zplver < ZPL_VERSION_NORMALIZATION &&
2605 (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
2606 sense != ZFS_PROP_UNDEFINED)))
2610 * Put the version in the zplprops
2612 VERIFY(nvlist_add_uint64(zplprops,
2613 zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
2615 if (norm == ZFS_PROP_UNDEFINED)
2616 VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
2617 VERIFY(nvlist_add_uint64(zplprops,
2618 zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
2621 * If we're normalizing, names must always be valid UTF-8 strings.
2625 if (u8 == ZFS_PROP_UNDEFINED)
2626 VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
2627 VERIFY(nvlist_add_uint64(zplprops,
2628 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
2630 if (sense == ZFS_PROP_UNDEFINED)
2631 VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
2632 VERIFY(nvlist_add_uint64(zplprops,
2633 zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
2636 *is_ci = (sense == ZFS_CASE_INSENSITIVE);
2642 zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
2643 nvlist_t *zplprops, boolean_t *is_ci)
2645 boolean_t fuids_ok, sa_ok;
2646 uint64_t zplver = ZPL_VERSION;
2647 objset_t *os = NULL;
2648 char parentname[MAXNAMELEN];
2654 (void) strlcpy(parentname, dataset, sizeof (parentname));
2655 cp = strrchr(parentname, '/');
2659 if ((error = spa_open(dataset, &spa, FTAG)) != 0)
2662 spa_vers = spa_version(spa);
2663 spa_close(spa, FTAG);
2665 zplver = zfs_zpl_version_map(spa_vers);
2666 fuids_ok = (zplver >= ZPL_VERSION_FUID);
2667 sa_ok = (zplver >= ZPL_VERSION_SA);
2670 * Open parent object set so we can inherit zplprop values.
2672 if ((error = dmu_objset_hold(parentname, FTAG, &os)) != 0)
2675 error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, sa_ok, createprops,
2677 dmu_objset_rele(os, FTAG);
2682 zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
2683 nvlist_t *zplprops, boolean_t *is_ci)
2687 uint64_t zplver = ZPL_VERSION;
2690 zplver = zfs_zpl_version_map(spa_vers);
2691 fuids_ok = (zplver >= ZPL_VERSION_FUID);
2692 sa_ok = (zplver >= ZPL_VERSION_SA);
2694 error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, sa_ok,
2695 createprops, zplprops, is_ci);
2701 * zc_objset_type type of objset to create (fs vs zvol)
2702 * zc_name name of new objset
2703 * zc_value name of snapshot to clone from (may be empty)
2704 * zc_nvlist_src{_size} nvlist of properties to apply
2709 zfs_ioc_create(zfs_cmd_t *zc)
2714 nvlist_t *nvprops = NULL;
2715 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
2716 dmu_objset_type_t type = zc->zc_objset_type;
2721 cbfunc = zfs_create_cb;
2725 cbfunc = zvol_create_cb;
2732 if (strchr(zc->zc_name, '@') ||
2733 strchr(zc->zc_name, '%'))
2736 if (zc->zc_nvlist_src != NULL &&
2737 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2738 zc->zc_iflags, &nvprops)) != 0)
2741 zct.zct_zplprops = NULL;
2742 zct.zct_props = nvprops;
2744 if (zc->zc_value[0] != '\0') {
2746 * We're creating a clone of an existing snapshot.
2748 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
2749 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
2750 nvlist_free(nvprops);
2754 error = dmu_objset_hold(zc->zc_value, FTAG, &clone);
2756 nvlist_free(nvprops);
2760 error = dmu_objset_clone(zc->zc_name, dmu_objset_ds(clone), 0);
2761 dmu_objset_rele(clone, FTAG);
2763 nvlist_free(nvprops);
2767 boolean_t is_insensitive = B_FALSE;
2769 if (cbfunc == NULL) {
2770 nvlist_free(nvprops);
2774 if (type == DMU_OST_ZVOL) {
2775 uint64_t volsize, volblocksize;
2777 if (nvprops == NULL ||
2778 nvlist_lookup_uint64(nvprops,
2779 zfs_prop_to_name(ZFS_PROP_VOLSIZE),
2781 nvlist_free(nvprops);
2785 if ((error = nvlist_lookup_uint64(nvprops,
2786 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
2787 &volblocksize)) != 0 && error != ENOENT) {
2788 nvlist_free(nvprops);
2793 volblocksize = zfs_prop_default_numeric(
2794 ZFS_PROP_VOLBLOCKSIZE);
2796 if ((error = zvol_check_volblocksize(
2797 volblocksize)) != 0 ||
2798 (error = zvol_check_volsize(volsize,
2799 volblocksize)) != 0) {
2800 nvlist_free(nvprops);
2803 } else if (type == DMU_OST_ZFS) {
2807 * We have to have normalization and
2808 * case-folding flags correct when we do the
2809 * file system creation, so go figure them out
2812 VERIFY(nvlist_alloc(&zct.zct_zplprops,
2813 NV_UNIQUE_NAME, KM_SLEEP) == 0);
2814 error = zfs_fill_zplprops(zc->zc_name, nvprops,
2815 zct.zct_zplprops, &is_insensitive);
2817 nvlist_free(nvprops);
2818 nvlist_free(zct.zct_zplprops);
2822 error = dmu_objset_create(zc->zc_name, type,
2823 is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
2824 nvlist_free(zct.zct_zplprops);
2828 * It would be nice to do this atomically.
2831 error = zfs_set_prop_nvlist(zc->zc_name, ZPROP_SRC_LOCAL,
2834 (void) dmu_objset_destroy(zc->zc_name, B_FALSE);
2836 nvlist_free(nvprops);
2842 * zc_name name of filesystem
2843 * zc_value short name of snapshot
2844 * zc_cookie recursive flag
2845 * zc_nvlist_src[_size] property list
2848 * zc_value short snapname (i.e. part after the '@')
2851 zfs_ioc_snapshot(zfs_cmd_t *zc)
2853 nvlist_t *nvprops = NULL;
2855 boolean_t recursive = zc->zc_cookie;
2857 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2860 if (zc->zc_nvlist_src != NULL &&
2861 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2862 zc->zc_iflags, &nvprops)) != 0)
2865 error = zfs_check_userprops(zc->zc_name, nvprops);
2869 if (!nvlist_empty(nvprops) &&
2870 zfs_earlier_version(zc->zc_name, SPA_VERSION_SNAP_PROPS)) {
2875 error = dmu_objset_snapshot(zc->zc_name, zc->zc_value,
2876 nvprops, recursive);
2879 nvlist_free(nvprops);
2884 zfs_unmount_snap(const char *name, void *arg)
2889 char *snapname = arg;
2890 char *fullname = kmem_asprintf("%s@%s", name, snapname);
2891 vfsp = zfs_get_vfs(fullname);
2893 } else if (strchr(name, '@')) {
2894 vfsp = zfs_get_vfs(name);
2899 * Always force the unmount for snapshots.
2901 int flag = MS_FORCE;
2904 if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
2909 if ((err = dounmount(vfsp, flag, kcred)) != 0)
2917 * zc_name name of filesystem
2918 * zc_value short name of snapshot
2919 * zc_defer_destroy mark for deferred destroy
2924 zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
2928 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2930 err = dmu_objset_find(zc->zc_name,
2931 zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2934 return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value,
2935 zc->zc_defer_destroy));
2940 * zc_name name of dataset to destroy
2941 * zc_objset_type type of objset
2942 * zc_defer_destroy mark for deferred destroy
2947 zfs_ioc_destroy(zfs_cmd_t *zc)
2950 if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
2951 err = zfs_unmount_snap(zc->zc_name, NULL);
2956 err = dmu_objset_destroy(zc->zc_name, zc->zc_defer_destroy);
2957 if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
2958 (void) zvol_remove_minor(zc->zc_name);
2964 * zc_name name of dataset to rollback (to most recent snapshot)
2969 zfs_ioc_rollback(zfs_cmd_t *zc)
2971 dsl_dataset_t *ds, *clone;
2976 error = dsl_dataset_hold(zc->zc_name, FTAG, &ds);
2980 /* must not be a snapshot */
2981 if (dsl_dataset_is_snapshot(ds)) {
2982 dsl_dataset_rele(ds, FTAG);
2986 /* must have a most recent snapshot */
2987 if (ds->ds_phys->ds_prev_snap_txg < TXG_INITIAL) {
2988 dsl_dataset_rele(ds, FTAG);
2993 * Create clone of most recent snapshot.
2995 clone_name = kmem_asprintf("%s/%%rollback", zc->zc_name);
2996 error = dmu_objset_clone(clone_name, ds->ds_prev, DS_FLAG_INCONSISTENT);
3000 error = dsl_dataset_own(clone_name, B_TRUE, FTAG, &clone);
3007 if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
3008 error = zfs_suspend_fs(zfsvfs);
3012 if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
3013 error = dsl_dataset_clone_swap(clone, ds,
3015 dsl_dataset_disown(ds, FTAG);
3020 resume_err = zfs_resume_fs(zfsvfs, zc->zc_name);
3021 error = error ? error : resume_err;
3023 VFS_RELE(zfsvfs->z_vfs);
3025 if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
3026 error = dsl_dataset_clone_swap(clone, ds, B_TRUE);
3027 dsl_dataset_disown(ds, FTAG);
3035 * Destroy clone (which also closes it).
3037 (void) dsl_dataset_destroy(clone, FTAG, B_FALSE);
3040 strfree(clone_name);
3042 dsl_dataset_rele(ds, FTAG);
3048 * zc_name old name of dataset
3049 * zc_value new name of dataset
3050 * zc_cookie recursive flag (only valid for snapshots)
3055 zfs_ioc_rename(zfs_cmd_t *zc)
3057 boolean_t recursive = zc->zc_cookie & 1;
3059 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
3060 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
3061 strchr(zc->zc_value, '%'))
3065 * Unmount snapshot unless we're doing a recursive rename,
3066 * in which case the dataset code figures out which snapshots
3069 if (!recursive && strchr(zc->zc_name, '@') != NULL &&
3070 zc->zc_objset_type == DMU_OST_ZFS) {
3071 int err = zfs_unmount_snap(zc->zc_name, NULL);
3075 if (zc->zc_objset_type == DMU_OST_ZVOL)
3076 (void) zvol_remove_minor(zc->zc_name);
3077 return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
3081 zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
3083 const char *propname = nvpair_name(pair);
3084 boolean_t issnap = (strchr(dsname, '@') != NULL);
3085 zfs_prop_t prop = zfs_name_to_prop(propname);
3089 if (prop == ZPROP_INVAL) {
3090 if (zfs_prop_user(propname)) {
3091 if (err = zfs_secpolicy_write_perms(dsname,
3092 ZFS_DELEG_PERM_USERPROP, cr))
3097 if (!issnap && zfs_prop_userquota(propname)) {
3098 const char *perm = NULL;
3099 const char *uq_prefix =
3100 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA];
3101 const char *gq_prefix =
3102 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA];
3104 if (strncmp(propname, uq_prefix,
3105 strlen(uq_prefix)) == 0) {
3106 perm = ZFS_DELEG_PERM_USERQUOTA;
3107 } else if (strncmp(propname, gq_prefix,
3108 strlen(gq_prefix)) == 0) {
3109 perm = ZFS_DELEG_PERM_GROUPQUOTA;
3111 /* USERUSED and GROUPUSED are read-only */
3115 if (err = zfs_secpolicy_write_perms(dsname, perm, cr))
3126 if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
3128 * dsl_prop_get_all_impl() returns properties in this
3132 VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
3133 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3138 * Check that this value is valid for this pool version
3141 case ZFS_PROP_COMPRESSION:
3143 * If the user specified gzip compression, make sure
3144 * the SPA supports it. We ignore any errors here since
3145 * we'll catch them later.
3147 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3148 nvpair_value_uint64(pair, &intval) == 0) {
3149 if (intval >= ZIO_COMPRESS_GZIP_1 &&
3150 intval <= ZIO_COMPRESS_GZIP_9 &&
3151 zfs_earlier_version(dsname,
3152 SPA_VERSION_GZIP_COMPRESSION)) {
3156 if (intval == ZIO_COMPRESS_ZLE &&
3157 zfs_earlier_version(dsname,
3158 SPA_VERSION_ZLE_COMPRESSION))
3162 * If this is a bootable dataset then
3163 * verify that the compression algorithm
3164 * is supported for booting. We must return
3165 * something other than ENOTSUP since it
3166 * implies a downrev pool version.
3168 if (zfs_is_bootfs(dsname) &&
3169 !BOOTFS_COMPRESS_VALID(intval)) {
3175 case ZFS_PROP_COPIES:
3176 if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
3180 case ZFS_PROP_DEDUP:
3181 if (zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
3185 case ZFS_PROP_SHARESMB:
3186 if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
3190 case ZFS_PROP_ACLINHERIT:
3191 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3192 nvpair_value_uint64(pair, &intval) == 0) {
3193 if (intval == ZFS_ACL_PASSTHROUGH_X &&
3194 zfs_earlier_version(dsname,
3195 SPA_VERSION_PASSTHROUGH_X))
3201 return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
3205 * Removes properties from the given props list that fail permission checks
3206 * needed to clear them and to restore them in case of a receive error. For each
3207 * property, make sure we have both set and inherit permissions.
3209 * Returns the first error encountered if any permission checks fail. If the
3210 * caller provides a non-NULL errlist, it also gives the complete list of names
3211 * of all the properties that failed a permission check along with the
3212 * corresponding error numbers. The caller is responsible for freeing the
3215 * If every property checks out successfully, zero is returned and the list
3216 * pointed at by errlist is NULL.
3219 zfs_check_clearable(char *dataset, nvlist_t *props, nvlist_t **errlist)
3222 nvpair_t *pair, *next_pair;
3229 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
3231 zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
3232 (void) strcpy(zc->zc_name, dataset);
3233 pair = nvlist_next_nvpair(props, NULL);
3234 while (pair != NULL) {
3235 next_pair = nvlist_next_nvpair(props, pair);
3237 (void) strcpy(zc->zc_value, nvpair_name(pair));
3238 if ((err = zfs_check_settable(dataset, pair, CRED())) != 0 ||
3239 (err = zfs_secpolicy_inherit(zc, CRED())) != 0) {
3240 VERIFY(nvlist_remove_nvpair(props, pair) == 0);
3241 VERIFY(nvlist_add_int32(errors,
3242 zc->zc_value, err) == 0);
3246 kmem_free(zc, sizeof (zfs_cmd_t));
3248 if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
3249 nvlist_free(errors);
3252 VERIFY(nvpair_value_int32(pair, &rv) == 0);
3255 if (errlist == NULL)
3256 nvlist_free(errors);
3264 propval_equals(nvpair_t *p1, nvpair_t *p2)
3266 if (nvpair_type(p1) == DATA_TYPE_NVLIST) {
3267 /* dsl_prop_get_all_impl() format */
3269 VERIFY(nvpair_value_nvlist(p1, &attrs) == 0);
3270 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3274 if (nvpair_type(p2) == DATA_TYPE_NVLIST) {
3276 VERIFY(nvpair_value_nvlist(p2, &attrs) == 0);
3277 VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
3281 if (nvpair_type(p1) != nvpair_type(p2))
3284 if (nvpair_type(p1) == DATA_TYPE_STRING) {
3285 char *valstr1, *valstr2;
3287 VERIFY(nvpair_value_string(p1, (char **)&valstr1) == 0);
3288 VERIFY(nvpair_value_string(p2, (char **)&valstr2) == 0);
3289 return (strcmp(valstr1, valstr2) == 0);
3291 uint64_t intval1, intval2;
3293 VERIFY(nvpair_value_uint64(p1, &intval1) == 0);
3294 VERIFY(nvpair_value_uint64(p2, &intval2) == 0);
3295 return (intval1 == intval2);
3300 * Remove properties from props if they are not going to change (as determined
3301 * by comparison with origprops). Remove them from origprops as well, since we
3302 * do not need to clear or restore properties that won't change.
3305 props_reduce(nvlist_t *props, nvlist_t *origprops)
3307 nvpair_t *pair, *next_pair;
3309 if (origprops == NULL)
3310 return; /* all props need to be received */
3312 pair = nvlist_next_nvpair(props, NULL);
3313 while (pair != NULL) {
3314 const char *propname = nvpair_name(pair);
3317 next_pair = nvlist_next_nvpair(props, pair);
3319 if ((nvlist_lookup_nvpair(origprops, propname,
3320 &match) != 0) || !propval_equals(pair, match))
3321 goto next; /* need to set received value */
3323 /* don't clear the existing received value */
3324 (void) nvlist_remove_nvpair(origprops, match);
3325 /* don't bother receiving the property */
3326 (void) nvlist_remove_nvpair(props, pair);
3333 static boolean_t zfs_ioc_recv_inject_err;
3338 * zc_name name of containing filesystem
3339 * zc_nvlist_src{_size} nvlist of properties to apply
3340 * zc_value name of snapshot to create
3341 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3342 * zc_cookie file descriptor to recv from
3343 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3344 * zc_guid force flag
3347 * zc_cookie number of bytes read
3348 * zc_nvlist_dst{_size} error for each unapplied received property
3349 * zc_obj zprop_errflags_t
3352 zfs_ioc_recv(zfs_cmd_t *zc)
3356 dmu_recv_cookie_t drc;
3357 boolean_t force = (boolean_t)zc->zc_guid;
3360 int props_error = 0;
3363 nvlist_t *props = NULL; /* sent properties */
3364 nvlist_t *origprops = NULL; /* existing properties */
3365 objset_t *origin = NULL;
3367 char tofs[ZFS_MAXNAMELEN];
3368 boolean_t first_recvd_props = B_FALSE;
3370 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
3371 strchr(zc->zc_value, '@') == NULL ||
3372 strchr(zc->zc_value, '%'))
3375 (void) strcpy(tofs, zc->zc_value);
3376 tosnap = strchr(tofs, '@');
3379 if (zc->zc_nvlist_src != NULL &&
3380 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
3381 zc->zc_iflags, &props)) != 0)
3391 VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
3393 if (props && dmu_objset_hold(tofs, FTAG, &os) == 0) {
3394 if ((spa_version(os->os_spa) >= SPA_VERSION_RECVD_PROPS) &&
3395 !dsl_prop_get_hasrecvd(os)) {
3396 first_recvd_props = B_TRUE;
3400 * If new received properties are supplied, they are to
3401 * completely replace the existing received properties, so stash
3402 * away the existing ones.
3404 if (dsl_prop_get_received(os, &origprops) == 0) {
3405 nvlist_t *errlist = NULL;
3407 * Don't bother writing a property if its value won't
3408 * change (and avoid the unnecessary security checks).
3410 * The first receive after SPA_VERSION_RECVD_PROPS is a
3411 * special case where we blow away all local properties
3414 if (!first_recvd_props)
3415 props_reduce(props, origprops);
3416 if (zfs_check_clearable(tofs, origprops,
3418 (void) nvlist_merge(errors, errlist, 0);
3419 nvlist_free(errlist);
3422 dmu_objset_rele(os, FTAG);
3425 if (zc->zc_string[0]) {
3426 error = dmu_objset_hold(zc->zc_string, FTAG, &origin);
3431 error = dmu_recv_begin(tofs, tosnap, zc->zc_top_ds,
3432 &zc->zc_begin_record, force, origin, &drc);
3434 dmu_objset_rele(origin, FTAG);
3439 * Set properties before we receive the stream so that they are applied
3440 * to the new data. Note that we must call dmu_recv_stream() if
3441 * dmu_recv_begin() succeeds.
3446 if (dmu_objset_from_ds(drc.drc_logical_ds, &os) == 0) {
3447 if (drc.drc_newfs) {
3448 if (spa_version(os->os_spa) >=
3449 SPA_VERSION_RECVD_PROPS)
3450 first_recvd_props = B_TRUE;
3451 } else if (origprops != NULL) {
3452 if (clear_received_props(os, tofs, origprops,
3453 first_recvd_props ? NULL : props) != 0)
3454 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
3456 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
3458 dsl_prop_set_hasrecvd(os);
3459 } else if (!drc.drc_newfs) {
3460 zc->zc_obj |= ZPROP_ERR_NOCLEAR;
3463 (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
3465 (void) nvlist_merge(errors, errlist, 0);
3466 nvlist_free(errlist);
3469 if (fit_error_list(zc, &errors) != 0 || put_nvlist(zc, errors) != 0) {
3471 * Caller made zc->zc_nvlist_dst less than the minimum expected
3472 * size or supplied an invalid address.
3474 props_error = EINVAL;
3478 error = dmu_recv_stream(&drc, fp->f_vnode, &off);
3481 zfsvfs_t *zfsvfs = NULL;
3483 if (getzfsvfs(tofs, &zfsvfs) == 0) {
3487 error = zfs_suspend_fs(zfsvfs);
3489 * If the suspend fails, then the recv_end will
3490 * likely also fail, and clean up after itself.
3492 end_err = dmu_recv_end(&drc);
3494 error = zfs_resume_fs(zfsvfs, tofs);
3495 error = error ? error : end_err;
3496 VFS_RELE(zfsvfs->z_vfs);
3498 error = dmu_recv_end(&drc);
3502 zc->zc_cookie = off - fp->f_offset;
3503 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
3507 if (zfs_ioc_recv_inject_err) {
3508 zfs_ioc_recv_inject_err = B_FALSE;
3513 * On error, restore the original props.
3515 if (error && props) {
3516 if (dmu_objset_hold(tofs, FTAG, &os) == 0) {
3517 if (clear_received_props(os, tofs, props, NULL) != 0) {
3519 * We failed to clear the received properties.
3520 * Since we may have left a $recvd value on the
3521 * system, we can't clear the $hasrecvd flag.
3523 zc->zc_obj |= ZPROP_ERR_NORESTORE;
3524 } else if (first_recvd_props) {
3525 dsl_prop_unset_hasrecvd(os);
3527 dmu_objset_rele(os, FTAG);
3528 } else if (!drc.drc_newfs) {
3529 /* We failed to clear the received properties. */
3530 zc->zc_obj |= ZPROP_ERR_NORESTORE;
3533 if (origprops == NULL && !drc.drc_newfs) {
3534 /* We failed to stash the original properties. */
3535 zc->zc_obj |= ZPROP_ERR_NORESTORE;
3539 * dsl_props_set() will not convert RECEIVED to LOCAL on or
3540 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
3541 * explictly if we're restoring local properties cleared in the
3542 * first new-style receive.
3544 if (origprops != NULL &&
3545 zfs_set_prop_nvlist(tofs, (first_recvd_props ?
3546 ZPROP_SRC_LOCAL : ZPROP_SRC_RECEIVED),
3547 origprops, NULL) != 0) {
3549 * We stashed the original properties but failed to
3552 zc->zc_obj |= ZPROP_ERR_NORESTORE;
3557 nvlist_free(origprops);
3558 nvlist_free(errors);
3562 error = props_error;
3569 * zc_name name of snapshot to send
3570 * zc_value short name of incremental fromsnap (may be empty)
3571 * zc_cookie file descriptor to send stream to
3572 * zc_obj fromorigin flag (mutually exclusive with zc_value)
3577 zfs_ioc_send(zfs_cmd_t *zc)
3579 objset_t *fromsnap = NULL;
3585 error = dmu_objset_hold(zc->zc_name, FTAG, &tosnap);
3589 if (zc->zc_value[0] != '\0') {
3593 buf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
3594 (void) strncpy(buf, zc->zc_name, MAXPATHLEN);
3595 cp = strchr(buf, '@');
3598 (void) strncat(buf, zc->zc_value, MAXPATHLEN);
3599 error = dmu_objset_hold(buf, FTAG, &fromsnap);
3600 kmem_free(buf, MAXPATHLEN);
3602 dmu_objset_rele(tosnap, FTAG);
3607 fp = getf(zc->zc_cookie);
3609 dmu_objset_rele(tosnap, FTAG);
3611 dmu_objset_rele(fromsnap, FTAG);
3616 error = dmu_sendbackup(tosnap, fromsnap, zc->zc_obj, fp->f_vnode, &off);
3618 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
3620 releasef(zc->zc_cookie);
3622 dmu_objset_rele(fromsnap, FTAG);
3623 dmu_objset_rele(tosnap, FTAG);
3628 zfs_ioc_inject_fault(zfs_cmd_t *zc)
3632 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
3633 &zc->zc_inject_record);
3636 zc->zc_guid = (uint64_t)id;
3642 zfs_ioc_clear_fault(zfs_cmd_t *zc)
3644 return (zio_clear_fault((int)zc->zc_guid));
3648 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
3650 int id = (int)zc->zc_guid;
3653 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
3654 &zc->zc_inject_record);
3662 zfs_ioc_error_log(zfs_cmd_t *zc)
3666 size_t count = (size_t)zc->zc_nvlist_dst_size;
3668 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
3671 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
3674 zc->zc_nvlist_dst_size = count;
3676 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
3678 spa_close(spa, FTAG);
3684 zfs_ioc_clear(zfs_cmd_t *zc)
3691 * On zpool clear we also fix up missing slogs
3693 mutex_enter(&spa_namespace_lock);
3694 spa = spa_lookup(zc->zc_name);
3696 mutex_exit(&spa_namespace_lock);
3699 if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
3700 /* we need to let spa_open/spa_load clear the chains */
3701 spa_set_log_state(spa, SPA_LOG_CLEAR);
3703 spa->spa_last_open_failed = 0;
3704 mutex_exit(&spa_namespace_lock);
3706 if (zc->zc_cookie & ZPOOL_NO_REWIND) {
3707 error = spa_open(zc->zc_name, &spa, FTAG);
3710 nvlist_t *config = NULL;
3712 if (zc->zc_nvlist_src == NULL)
3715 if ((error = get_nvlist(zc->zc_nvlist_src,
3716 zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
3717 error = spa_open_rewind(zc->zc_name, &spa, FTAG,
3719 if (config != NULL) {
3720 (void) put_nvlist(zc, config);
3721 nvlist_free(config);
3723 nvlist_free(policy);
3730 spa_vdev_state_enter(spa, SCL_NONE);
3732 if (zc->zc_guid == 0) {
3735 vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
3737 (void) spa_vdev_state_exit(spa, NULL, ENODEV);
3738 spa_close(spa, FTAG);
3743 vdev_clear(spa, vd);
3745 (void) spa_vdev_state_exit(spa, NULL, 0);
3748 * Resume any suspended I/Os.
3750 if (zio_resume(spa) != 0)
3753 spa_close(spa, FTAG);
3760 * zc_name name of filesystem
3761 * zc_value name of origin snapshot
3764 * zc_string name of conflicting snapshot, if there is one
3767 zfs_ioc_promote(zfs_cmd_t *zc)
3772 * We don't need to unmount *all* the origin fs's snapshots, but
3775 cp = strchr(zc->zc_value, '@');
3778 (void) dmu_objset_find(zc->zc_value,
3779 zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
3780 return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
3784 * Retrieve a single {user|group}{used|quota}@... property.
3787 * zc_name name of filesystem
3788 * zc_objset_type zfs_userquota_prop_t
3789 * zc_value domain name (eg. "S-1-234-567-89")
3790 * zc_guid RID/UID/GID
3793 * zc_cookie property value
3796 zfs_ioc_userspace_one(zfs_cmd_t *zc)
3801 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
3804 error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs);
3808 error = zfs_userspace_one(zfsvfs,
3809 zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
3810 zfsvfs_rele(zfsvfs, FTAG);
3817 * zc_name name of filesystem
3818 * zc_cookie zap cursor
3819 * zc_objset_type zfs_userquota_prop_t
3820 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
3823 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
3824 * zc_cookie zap cursor
3827 zfs_ioc_userspace_many(zfs_cmd_t *zc)
3830 int bufsize = zc->zc_nvlist_dst_size;
3835 int error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs);
3839 void *buf = kmem_alloc(bufsize, KM_SLEEP);
3841 error = zfs_userspace_many(zfsvfs, zc->zc_objset_type, &zc->zc_cookie,
3842 buf, &zc->zc_nvlist_dst_size);
3845 error = xcopyout(buf,
3846 (void *)(uintptr_t)zc->zc_nvlist_dst,
3847 zc->zc_nvlist_dst_size);
3849 kmem_free(buf, bufsize);
3850 zfsvfs_rele(zfsvfs, FTAG);
3857 * zc_name name of filesystem
3863 zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
3869 if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
3870 if (!dmu_objset_userused_enabled(zfsvfs->z_os)) {
3872 * If userused is not enabled, it may be because the
3873 * objset needs to be closed & reopened (to grow the
3874 * objset_phys_t). Suspend/resume the fs will do that.
3876 error = zfs_suspend_fs(zfsvfs);
3878 error = zfs_resume_fs(zfsvfs, zc->zc_name);
3881 error = dmu_objset_userspace_upgrade(zfsvfs->z_os);
3882 VFS_RELE(zfsvfs->z_vfs);
3884 /* XXX kind of reading contents without owning */
3885 error = dmu_objset_hold(zc->zc_name, FTAG, &os);
3889 error = dmu_objset_userspace_upgrade(os);
3890 dmu_objset_rele(os, FTAG);
3897 * We don't want to have a hard dependency
3898 * against some special symbols in sharefs
3899 * nfs, and smbsrv. Determine them if needed when
3900 * the first file system is shared.
3901 * Neither sharefs, nfs or smbsrv are unloadable modules.
3903 int (*znfsexport_fs)(void *arg);
3904 int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
3905 int (*zsmbexport_fs)(void *arg, boolean_t add_share);
3907 int zfs_nfsshare_inited;
3908 int zfs_smbshare_inited;
3910 ddi_modhandle_t nfs_mod;
3911 ddi_modhandle_t sharefs_mod;
3912 ddi_modhandle_t smbsrv_mod;
3913 kmutex_t zfs_share_lock;
3920 ASSERT(MUTEX_HELD(&zfs_share_lock));
3921 /* Both NFS and SMB shares also require sharetab support. */
3922 if (sharefs_mod == NULL && ((sharefs_mod =
3923 ddi_modopen("fs/sharefs",
3924 KRTLD_MODE_FIRST, &error)) == NULL)) {
3927 if (zshare_fs == NULL && ((zshare_fs =
3928 (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
3929 ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
3936 zfs_ioc_share(zfs_cmd_t *zc)
3941 switch (zc->zc_share.z_sharetype) {
3943 case ZFS_UNSHARE_NFS:
3944 if (zfs_nfsshare_inited == 0) {
3945 mutex_enter(&zfs_share_lock);
3946 if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
3947 KRTLD_MODE_FIRST, &error)) == NULL)) {
3948 mutex_exit(&zfs_share_lock);
3951 if (znfsexport_fs == NULL &&
3952 ((znfsexport_fs = (int (*)(void *))
3954 "nfs_export", &error)) == NULL)) {
3955 mutex_exit(&zfs_share_lock);
3958 error = zfs_init_sharefs();
3960 mutex_exit(&zfs_share_lock);
3963 zfs_nfsshare_inited = 1;
3964 mutex_exit(&zfs_share_lock);
3968 case ZFS_UNSHARE_SMB:
3969 if (zfs_smbshare_inited == 0) {
3970 mutex_enter(&zfs_share_lock);
3971 if (smbsrv_mod == NULL && ((smbsrv_mod =
3972 ddi_modopen("drv/smbsrv",
3973 KRTLD_MODE_FIRST, &error)) == NULL)) {
3974 mutex_exit(&zfs_share_lock);
3977 if (zsmbexport_fs == NULL && ((zsmbexport_fs =
3978 (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
3979 "smb_server_share", &error)) == NULL)) {
3980 mutex_exit(&zfs_share_lock);
3983 error = zfs_init_sharefs();
3985 mutex_exit(&zfs_share_lock);
3988 zfs_smbshare_inited = 1;
3989 mutex_exit(&zfs_share_lock);
3996 switch (zc->zc_share.z_sharetype) {
3998 case ZFS_UNSHARE_NFS:
4000 znfsexport_fs((void *)
4001 (uintptr_t)zc->zc_share.z_exportdata))
4005 case ZFS_UNSHARE_SMB:
4006 if (error = zsmbexport_fs((void *)
4007 (uintptr_t)zc->zc_share.z_exportdata,
4008 zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
4015 opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
4016 zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
4017 SHAREFS_ADD : SHAREFS_REMOVE;
4020 * Add or remove share from sharetab
4022 error = zshare_fs(opcode,
4023 (void *)(uintptr_t)zc->zc_share.z_sharedata,
4024 zc->zc_share.z_sharemax);
4030 ace_t full_access[] = {
4031 {(uid_t)-1, ACE_ALL_PERMS, ACE_EVERYONE, 0}
4035 * Remove all ACL files in shares dir
4038 zfs_smb_acl_purge(znode_t *dzp)
4041 zap_attribute_t zap;
4042 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
4045 for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id);
4046 (error = zap_cursor_retrieve(&zc, &zap)) == 0;
4047 zap_cursor_advance(&zc)) {
4048 if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
4052 zap_cursor_fini(&zc);
4057 zfs_ioc_smb_acl(zfs_cmd_t *zc)
4061 vnode_t *resourcevp = NULL;
4070 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
4071 NO_FOLLOW, NULL, &vp)) != 0)
4074 /* Now make sure mntpnt and dataset are ZFS */
4076 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
4077 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
4078 zc->zc_name) != 0)) {
4084 zfsvfs = dzp->z_zfsvfs;
4088 * Create share dir if its missing.
4090 mutex_enter(&zfsvfs->z_lock);
4091 if (zfsvfs->z_shares_dir == 0) {
4094 tx = dmu_tx_create(zfsvfs->z_os);
4095 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
4097 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
4098 error = dmu_tx_assign(tx, TXG_WAIT);
4102 error = zfs_create_share_dir(zfsvfs, tx);
4106 mutex_exit(&zfsvfs->z_lock);
4112 mutex_exit(&zfsvfs->z_lock);
4114 ASSERT(zfsvfs->z_shares_dir);
4115 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &sharedir)) != 0) {
4121 switch (zc->zc_cookie) {
4122 case ZFS_SMB_ACL_ADD:
4123 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
4124 vattr.va_type = VREG;
4125 vattr.va_mode = S_IFREG|0777;
4129 vsec.vsa_mask = VSA_ACE;
4130 vsec.vsa_aclentp = &full_access;
4131 vsec.vsa_aclentsz = sizeof (full_access);
4132 vsec.vsa_aclcnt = 1;
4134 error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
4135 &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
4137 VN_RELE(resourcevp);
4140 case ZFS_SMB_ACL_REMOVE:
4141 error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
4145 case ZFS_SMB_ACL_RENAME:
4146 if ((error = get_nvlist(zc->zc_nvlist_src,
4147 zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
4152 if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
4153 nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
4156 VN_RELE(ZTOV(sharedir));
4158 nvlist_free(nvlist);
4161 error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
4163 nvlist_free(nvlist);
4166 case ZFS_SMB_ACL_PURGE:
4167 error = zfs_smb_acl_purge(sharedir);
4176 VN_RELE(ZTOV(sharedir));
4185 * zc_name name of filesystem
4186 * zc_value short name of snap
4187 * zc_string user-supplied tag for this reference
4188 * zc_cookie recursive flag
4189 * zc_temphold set if hold is temporary
4194 zfs_ioc_hold(zfs_cmd_t *zc)
4196 boolean_t recursive = zc->zc_cookie;
4198 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
4201 return (dsl_dataset_user_hold(zc->zc_name, zc->zc_value,
4202 zc->zc_string, recursive, zc->zc_temphold));
4207 * zc_name name of dataset from which we're releasing a user reference
4208 * zc_value short name of snap
4209 * zc_string user-supplied tag for this reference
4210 * zc_cookie recursive flag
4215 zfs_ioc_release(zfs_cmd_t *zc)
4217 boolean_t recursive = zc->zc_cookie;
4219 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
4222 return (dsl_dataset_user_release(zc->zc_name, zc->zc_value,
4223 zc->zc_string, recursive));
4228 * zc_name name of filesystem
4231 * zc_nvlist_src{_size} nvlist of snapshot holds
4234 zfs_ioc_get_holds(zfs_cmd_t *zc)
4239 if ((error = dsl_dataset_get_holds(zc->zc_name, &nvp)) == 0) {
4240 error = put_nvlist(zc, nvp);
4248 * pool create, destroy, and export don't log the history as part of
4249 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
4250 * do the logging of those commands.
4252 static zfs_ioc_vec_t zfs_ioc_vec[] = {
4253 { zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4255 { zfs_ioc_pool_destroy, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4257 { zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4259 { zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4261 { zfs_ioc_pool_configs, zfs_secpolicy_none, NO_NAME, B_FALSE,
4263 { zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE,
4265 { zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE,
4267 { zfs_ioc_pool_scan, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4269 { zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE,
4271 { zfs_ioc_pool_upgrade, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4273 { zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4275 { zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4277 { zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4279 { zfs_ioc_vdev_set_state, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4281 { zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4283 { zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4285 { zfs_ioc_vdev_setpath, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4287 { zfs_ioc_vdev_setfru, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4289 { zfs_ioc_objset_stats, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4291 { zfs_ioc_objset_zplprops, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4293 { zfs_ioc_dataset_list_next, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4295 { zfs_ioc_snapshot_list_next, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4297 { zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE, B_TRUE },
4298 { zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE, B_TRUE },
4299 { zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE,
4301 { zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE,
4303 { zfs_ioc_rename, zfs_secpolicy_rename, DATASET_NAME, B_TRUE, B_TRUE },
4304 { zfs_ioc_recv, zfs_secpolicy_receive, DATASET_NAME, B_TRUE, B_TRUE },
4305 { zfs_ioc_send, zfs_secpolicy_send, DATASET_NAME, B_TRUE, B_FALSE },
4306 { zfs_ioc_inject_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE,
4308 { zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE,
4310 { zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE,
4312 { zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE,
4314 { zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE, B_FALSE },
4315 { zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE,
4317 { zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, DATASET_NAME,
4319 { zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE,
4321 { zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE,
4323 { zfs_ioc_obj_to_path, zfs_secpolicy_config, DATASET_NAME, B_FALSE,
4325 { zfs_ioc_pool_set_props, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4327 { zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE,
4329 { zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE,
4331 { zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4333 { zfs_ioc_share, zfs_secpolicy_share, DATASET_NAME, B_FALSE, B_FALSE },
4334 { zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE,
4336 { zfs_ioc_smb_acl, zfs_secpolicy_smb_acl, DATASET_NAME, B_FALSE,
4338 { zfs_ioc_userspace_one, zfs_secpolicy_userspace_one,
4339 DATASET_NAME, B_FALSE, B_FALSE },
4340 { zfs_ioc_userspace_many, zfs_secpolicy_userspace_many,
4341 DATASET_NAME, B_FALSE, B_FALSE },
4342 { zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
4343 DATASET_NAME, B_FALSE, B_TRUE },
4344 { zfs_ioc_hold, zfs_secpolicy_hold, DATASET_NAME, B_TRUE, B_TRUE },
4345 { zfs_ioc_release, zfs_secpolicy_release, DATASET_NAME, B_TRUE,
4347 { zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4349 { zfs_ioc_objset_recvd_props, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
4351 { zfs_ioc_vdev_split, zfs_secpolicy_config, POOL_NAME, B_TRUE,
4356 pool_status_check(const char *name, zfs_ioc_namecheck_t type)
4361 ASSERT(type == POOL_NAME || type == DATASET_NAME);
4363 error = spa_open(name, &spa, FTAG);
4365 if (spa_suspended(spa))
4367 spa_close(spa, FTAG);
4373 zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
4379 if (getminor(dev) != 0)
4380 return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
4382 vec = cmd - ZFS_IOC;
4383 ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
4385 if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
4388 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
4390 error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
4394 if ((error == 0) && !(flag & FKIOCTL))
4395 error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
4398 * Ensure that all pool/dataset names are valid before we pass down to
4402 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
4403 zc->zc_iflags = flag & FKIOCTL;
4404 switch (zfs_ioc_vec[vec].zvec_namecheck) {
4406 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
4408 if (zfs_ioc_vec[vec].zvec_pool_check)
4409 error = pool_status_check(zc->zc_name,
4410 zfs_ioc_vec[vec].zvec_namecheck);
4414 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
4416 if (zfs_ioc_vec[vec].zvec_pool_check)
4417 error = pool_status_check(zc->zc_name,
4418 zfs_ioc_vec[vec].zvec_namecheck);
4427 error = zfs_ioc_vec[vec].zvec_func(zc);
4429 rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
4433 if (zfs_ioc_vec[vec].zvec_his_log)
4434 zfs_log_history(zc);
4437 kmem_free(zc, sizeof (zfs_cmd_t));
4442 zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
4444 if (cmd != DDI_ATTACH)
4445 return (DDI_FAILURE);
4447 if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
4448 DDI_PSEUDO, 0) == DDI_FAILURE)
4449 return (DDI_FAILURE);
4453 ddi_report_dev(dip);
4455 return (DDI_SUCCESS);
4459 zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
4461 if (spa_busy() || zfs_busy() || zvol_busy())
4462 return (DDI_FAILURE);
4464 if (cmd != DDI_DETACH)
4465 return (DDI_FAILURE);
4469 ddi_prop_remove_all(dip);
4470 ddi_remove_minor_node(dip, NULL);
4472 return (DDI_SUCCESS);
4477 zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
4480 case DDI_INFO_DEVT2DEVINFO:
4482 return (DDI_SUCCESS);
4484 case DDI_INFO_DEVT2INSTANCE:
4485 *result = (void *)0;
4486 return (DDI_SUCCESS);
4489 return (DDI_FAILURE);
4493 * OK, so this is a little weird.
4495 * /dev/zfs is the control node, i.e. minor 0.
4496 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
4498 * /dev/zfs has basically nothing to do except serve up ioctls,
4499 * so most of the standard driver entry points are in zvol.c.
4501 static struct cb_ops zfs_cb_ops = {
4502 zvol_open, /* open */
4503 zvol_close, /* close */
4504 zvol_strategy, /* strategy */
4506 zvol_dump, /* dump */
4507 zvol_read, /* read */
4508 zvol_write, /* write */
4509 zfsdev_ioctl, /* ioctl */
4513 nochpoll, /* poll */
4514 ddi_prop_op, /* prop_op */
4515 NULL, /* streamtab */
4516 D_NEW | D_MP | D_64BIT, /* Driver compatibility flag */
4517 CB_REV, /* version */
4518 nodev, /* async read */
4519 nodev, /* async write */
4522 static struct dev_ops zfs_dev_ops = {
4523 DEVO_REV, /* version */
4525 zfs_info, /* info */
4526 nulldev, /* identify */
4527 nulldev, /* probe */
4528 zfs_attach, /* attach */
4529 zfs_detach, /* detach */
4531 &zfs_cb_ops, /* driver operations */
4532 NULL, /* no bus operations */
4534 ddi_quiesce_not_needed, /* quiesce */
4537 static struct modldrv zfs_modldrv = {
4543 static struct modlinkage modlinkage = {
4545 (void *)&zfs_modlfs,
4546 (void *)&zfs_modldrv,
4551 uint_t zfs_fsyncer_key;
4552 extern uint_t rrw_tsd_key;
4559 spa_init(FREAD | FWRITE);
4563 if ((error = mod_install(&modlinkage)) != 0) {
4570 tsd_create(&zfs_fsyncer_key, NULL);
4571 tsd_create(&rrw_tsd_key, NULL);
4573 error = ldi_ident_from_mod(&modlinkage, &zfs_li);
4575 mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
4585 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
4588 if ((error = mod_remove(&modlinkage)) != 0)
4594 if (zfs_nfsshare_inited)
4595 (void) ddi_modclose(nfs_mod);
4596 if (zfs_smbshare_inited)
4597 (void) ddi_modclose(smbsrv_mod);
4598 if (zfs_nfsshare_inited || zfs_smbshare_inited)
4599 (void) ddi_modclose(sharefs_mod);
4601 tsd_destroy(&zfs_fsyncer_key);
4602 ldi_ident_release(zfs_li);
4604 mutex_destroy(&zfs_share_lock);
4610 _info(struct modinfo *modinfop)
4612 return (mod_info(&modlinkage, modinfop));