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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/errno.h>
31 #include <sys/modctl.h>
36 #include <sys/cmn_err.h>
38 #include <sys/zfs_ioctl.h>
39 #include <sys/zfs_znode.h>
42 #include <sys/spa_impl.h>
44 #include <sys/vdev_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 <sharefs/share.h>
65 #include <sys/dmu_objset.h>
67 #include "zfs_namecheck.h"
69 #include "zfs_deleg.h"
71 extern struct modlfs zfs_modlfs;
73 extern void zfs_init(void);
74 extern void zfs_fini(void);
76 ldi_ident_t zfs_li = NULL;
79 typedef int zfs_ioc_func_t(zfs_cmd_t *);
80 typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
86 } zfs_ioc_namecheck_t;
88 typedef struct zfs_ioc_vec {
89 zfs_ioc_func_t *zvec_func;
90 zfs_secpolicy_func_t *zvec_secpolicy;
91 zfs_ioc_namecheck_t zvec_namecheck;
92 boolean_t zvec_his_log;
93 boolean_t zvec_pool_check;
96 /* This array is indexed by zfs_userquota_prop_t */
97 static const char *userquota_perms[] = {
98 ZFS_DELEG_PERM_USERUSED,
99 ZFS_DELEG_PERM_USERQUOTA,
100 ZFS_DELEG_PERM_GROUPUSED,
101 ZFS_DELEG_PERM_GROUPQUOTA,
104 static int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
105 static void clear_props(char *dataset, nvlist_t *props, nvlist_t *newprops);
106 static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
108 int zfs_set_prop_nvlist(const char *, nvlist_t *);
110 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
112 __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
119 * Get rid of annoying "../common/" prefix to filename.
121 newfile = strrchr(file, '/');
122 if (newfile != NULL) {
123 newfile = newfile + 1; /* Get rid of leading / */
129 (void) vsnprintf(buf, sizeof (buf), fmt, adx);
133 * To get this data, use the zfs-dprintf probe as so:
134 * dtrace -q -n 'zfs-dprintf \
135 * /stringof(arg0) == "dbuf.c"/ \
136 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
138 * arg1 = function name
142 DTRACE_PROBE4(zfs__dprintf,
143 char *, newfile, char *, func, int, line, char *, buf);
147 history_str_free(char *buf)
149 kmem_free(buf, HIS_MAX_RECORD_LEN);
153 history_str_get(zfs_cmd_t *zc)
157 if (zc->zc_history == NULL)
160 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
161 if (copyinstr((void *)(uintptr_t)zc->zc_history,
162 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
163 history_str_free(buf);
167 buf[HIS_MAX_RECORD_LEN -1] = '\0';
173 * Check to see if the named dataset is currently defined as bootable
176 zfs_is_bootfs(const char *name)
179 boolean_t ret = B_FALSE;
181 if (spa_open(name, &spa, FTAG) == 0) {
182 if (spa->spa_bootfs) {
185 if (dmu_objset_open(name, DMU_OST_ZFS,
186 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
187 ret = (dmu_objset_id(os) == spa->spa_bootfs);
188 dmu_objset_close(os);
191 spa_close(spa, FTAG);
197 * zfs_earlier_version
199 * Return non-zero if the spa version is less than requested version.
202 zfs_earlier_version(const char *name, int version)
206 if (spa_open(name, &spa, FTAG) == 0) {
207 if (spa_version(spa) < version) {
208 spa_close(spa, FTAG);
211 spa_close(spa, FTAG);
217 * zpl_earlier_version
219 * Return TRUE if the ZPL version is less than requested version.
222 zpl_earlier_version(const char *name, int version)
225 boolean_t rc = B_TRUE;
227 if (dmu_objset_open(name, DMU_OST_ANY,
228 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
231 if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
232 rc = zplversion < version;
233 dmu_objset_close(os);
239 zfs_log_history(zfs_cmd_t *zc)
244 if ((buf = history_str_get(zc)) == NULL)
247 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
248 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
249 (void) spa_history_log(spa, buf, LOG_CMD_NORMAL);
250 spa_close(spa, FTAG);
252 history_str_free(buf);
256 * Policy for top-level read operations (list pools). Requires no privileges,
257 * and can be used in the local zone, as there is no associated dataset.
261 zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
267 * Policy for dataset read operations (list children, get statistics). Requires
268 * no privileges, but must be visible in the local zone.
272 zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
274 if (INGLOBALZONE(curproc) ||
275 zone_dataset_visible(zc->zc_name, NULL))
282 zfs_dozonecheck(const char *dataset, cred_t *cr)
288 * The dataset must be visible by this zone -- check this first
289 * so they don't see EPERM on something they shouldn't know about.
291 if (!INGLOBALZONE(curproc) &&
292 !zone_dataset_visible(dataset, &writable))
295 if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
298 if (INGLOBALZONE(curproc)) {
300 * If the fs is zoned, only root can access it from the
303 if (secpolicy_zfs(cr) && zoned)
307 * If we are in a local zone, the 'zoned' property must be set.
312 /* must be writable by this zone */
320 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
324 error = zfs_dozonecheck(name, cr);
326 error = secpolicy_zfs(cr);
328 error = dsl_deleg_access(name, perm, cr);
334 zfs_secpolicy_setprop(const char *name, zfs_prop_t prop, cred_t *cr)
337 * Check permissions for special properties.
342 * Disallow setting of 'zoned' from within a local zone.
344 if (!INGLOBALZONE(curproc))
349 if (!INGLOBALZONE(curproc)) {
351 char setpoint[MAXNAMELEN];
353 * Unprivileged users are allowed to modify the
354 * quota on things *under* (ie. contained by)
355 * the thing they own.
357 if (dsl_prop_get_integer(name, "zoned", &zoned,
360 if (!zoned || strlen(name) <= strlen(setpoint))
366 return (zfs_secpolicy_write_perms(name, zfs_prop_to_name(prop), cr));
370 zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
374 error = zfs_dozonecheck(zc->zc_name, cr);
379 * permission to set permissions will be evaluated later in
380 * dsl_deleg_can_allow()
386 zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
389 error = zfs_secpolicy_write_perms(zc->zc_name,
390 ZFS_DELEG_PERM_ROLLBACK, cr);
392 error = zfs_secpolicy_write_perms(zc->zc_name,
393 ZFS_DELEG_PERM_MOUNT, cr);
398 zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
400 return (zfs_secpolicy_write_perms(zc->zc_name,
401 ZFS_DELEG_PERM_SEND, cr));
405 zfs_secpolicy_deleg_share(zfs_cmd_t *zc, cred_t *cr)
410 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
411 NO_FOLLOW, NULL, &vp)) != 0)
414 /* Now make sure mntpnt and dataset are ZFS */
416 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
417 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
418 zc->zc_name) != 0)) {
424 return (dsl_deleg_access(zc->zc_name,
425 ZFS_DELEG_PERM_SHARE, cr));
429 zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
431 if (!INGLOBALZONE(curproc))
434 if (secpolicy_nfs(cr) == 0) {
437 return (zfs_secpolicy_deleg_share(zc, cr));
442 zfs_secpolicy_smb_acl(zfs_cmd_t *zc, cred_t *cr)
444 if (!INGLOBALZONE(curproc))
447 if (secpolicy_smb(cr) == 0) {
450 return (zfs_secpolicy_deleg_share(zc, cr));
455 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
460 * Remove the @bla or /bla from the end of the name to get the parent.
462 (void) strncpy(parent, datasetname, parentsize);
463 cp = strrchr(parent, '@');
467 cp = strrchr(parent, '/');
477 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
481 if ((error = zfs_secpolicy_write_perms(name,
482 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
485 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
489 zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
491 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
495 * Must have sys_config privilege to check the iscsi permission
499 zfs_secpolicy_iscsi(zfs_cmd_t *zc, cred_t *cr)
501 return (secpolicy_zfs(cr));
505 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
507 char parentname[MAXNAMELEN];
510 if ((error = zfs_secpolicy_write_perms(from,
511 ZFS_DELEG_PERM_RENAME, cr)) != 0)
514 if ((error = zfs_secpolicy_write_perms(from,
515 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
518 if ((error = zfs_get_parent(to, parentname,
519 sizeof (parentname))) != 0)
522 if ((error = zfs_secpolicy_write_perms(parentname,
523 ZFS_DELEG_PERM_CREATE, cr)) != 0)
526 if ((error = zfs_secpolicy_write_perms(parentname,
527 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
534 zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
536 return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
540 zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
542 char parentname[MAXNAMELEN];
546 error = zfs_secpolicy_write_perms(zc->zc_name,
547 ZFS_DELEG_PERM_PROMOTE, cr);
551 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
552 DS_MODE_USER | DS_MODE_READONLY, &clone);
555 dsl_dataset_t *pclone = NULL;
557 dd = clone->os->os_dsl_dataset->ds_dir;
559 rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
560 error = dsl_dataset_hold_obj(dd->dd_pool,
561 dd->dd_phys->dd_origin_obj, FTAG, &pclone);
562 rw_exit(&dd->dd_pool->dp_config_rwlock);
564 dmu_objset_close(clone);
568 error = zfs_secpolicy_write_perms(zc->zc_name,
569 ZFS_DELEG_PERM_MOUNT, cr);
571 dsl_dataset_name(pclone, parentname);
572 dmu_objset_close(clone);
573 dsl_dataset_rele(pclone, FTAG);
575 error = zfs_secpolicy_write_perms(parentname,
576 ZFS_DELEG_PERM_PROMOTE, cr);
582 zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
586 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
587 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
590 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
591 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
594 return (zfs_secpolicy_write_perms(zc->zc_name,
595 ZFS_DELEG_PERM_CREATE, cr));
599 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
603 if ((error = zfs_secpolicy_write_perms(name,
604 ZFS_DELEG_PERM_SNAPSHOT, cr)) != 0)
607 error = zfs_secpolicy_write_perms(name,
608 ZFS_DELEG_PERM_MOUNT, cr);
614 zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
617 return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
621 zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
623 char parentname[MAXNAMELEN];
626 if ((error = zfs_get_parent(zc->zc_name, parentname,
627 sizeof (parentname))) != 0)
630 if (zc->zc_value[0] != '\0') {
631 if ((error = zfs_secpolicy_write_perms(zc->zc_value,
632 ZFS_DELEG_PERM_CLONE, cr)) != 0)
636 if ((error = zfs_secpolicy_write_perms(parentname,
637 ZFS_DELEG_PERM_CREATE, cr)) != 0)
640 error = zfs_secpolicy_write_perms(parentname,
641 ZFS_DELEG_PERM_MOUNT, cr);
647 zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
651 error = secpolicy_fs_unmount(cr, NULL);
653 error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
659 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
660 * SYS_CONFIG privilege, which is not available in a local zone.
664 zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
666 if (secpolicy_sys_config(cr, B_FALSE) != 0)
673 * Just like zfs_secpolicy_config, except that we will check for
674 * mount permission on the dataset for permission to create/remove
678 zfs_secpolicy_minor(zfs_cmd_t *zc, cred_t *cr)
680 if (secpolicy_sys_config(cr, B_FALSE) != 0) {
681 return (dsl_deleg_access(zc->zc_name,
682 ZFS_DELEG_PERM_MOUNT, cr));
689 * Policy for fault injection. Requires all privileges.
693 zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
695 return (secpolicy_zinject(cr));
699 zfs_secpolicy_inherit(zfs_cmd_t *zc, cred_t *cr)
701 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
703 if (prop == ZPROP_INVAL) {
704 if (!zfs_prop_user(zc->zc_value))
706 return (zfs_secpolicy_write_perms(zc->zc_name,
707 ZFS_DELEG_PERM_USERPROP, cr));
709 if (!zfs_prop_inheritable(prop))
711 return (zfs_secpolicy_setprop(zc->zc_name, prop, cr));
716 zfs_secpolicy_userspace_one(zfs_cmd_t *zc, cred_t *cr)
718 int err = zfs_secpolicy_read(zc, cr);
722 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
725 if (zc->zc_value[0] == 0) {
727 * They are asking about a posix uid/gid. If it's
728 * themself, allow it.
730 if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
731 zc->zc_objset_type == ZFS_PROP_USERQUOTA) {
732 if (zc->zc_guid == crgetuid(cr))
735 if (groupmember(zc->zc_guid, cr))
740 return (zfs_secpolicy_write_perms(zc->zc_name,
741 userquota_perms[zc->zc_objset_type], cr));
745 zfs_secpolicy_userspace_many(zfs_cmd_t *zc, cred_t *cr)
747 int err = zfs_secpolicy_read(zc, cr);
751 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
754 return (zfs_secpolicy_write_perms(zc->zc_name,
755 userquota_perms[zc->zc_objset_type], cr));
759 zfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, cred_t *cr)
761 return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION, cr));
765 * Returns the nvlist as specified by the user in the zfs_cmd_t.
768 get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
772 nvlist_t *list = NULL;
775 * Read in and unpack the user-supplied nvlist.
780 packed = kmem_alloc(size, KM_SLEEP);
782 if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
784 kmem_free(packed, size);
788 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
789 kmem_free(packed, size);
793 kmem_free(packed, size);
800 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
806 VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
808 if (size > zc->zc_nvlist_dst_size) {
811 packed = kmem_alloc(size, KM_SLEEP);
812 VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
814 error = ddi_copyout(packed,
815 (void *)(uintptr_t)zc->zc_nvlist_dst, size, zc->zc_iflags);
816 kmem_free(packed, size);
819 zc->zc_nvlist_dst_size = size;
824 getzfsvfs(const char *dsname, zfsvfs_t **zvp)
829 error = dmu_objset_open(dsname, DMU_OST_ZFS,
830 DS_MODE_USER | DS_MODE_READONLY, &os);
834 mutex_enter(&os->os->os_user_ptr_lock);
835 *zvp = dmu_objset_get_user(os);
837 VFS_HOLD((*zvp)->z_vfs);
841 mutex_exit(&os->os->os_user_ptr_lock);
842 dmu_objset_close(os);
847 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
848 * case its z_vfs will be NULL, and it will be opened as the owner.
851 zfsvfs_hold(const char *name, boolean_t readonly, void *tag, zfsvfs_t **zvp)
854 int mode = DS_MODE_OWNER | (readonly ? DS_MODE_READONLY : 0);
856 if (getzfsvfs(name, zvp) != 0)
857 error = zfsvfs_create(name, mode, zvp);
859 rrw_enter(&(*zvp)->z_teardown_lock, RW_READER, tag);
860 if ((*zvp)->z_unmounted) {
862 * XXX we could probably try again, since the unmounting
863 * thread should be just about to disassociate the
864 * objset from the zfsvfs.
866 rrw_exit(&(*zvp)->z_teardown_lock, tag);
874 zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
876 rrw_exit(&zfsvfs->z_teardown_lock, tag);
879 VFS_RELE(zfsvfs->z_vfs);
881 dmu_objset_close(zfsvfs->z_os);
887 zfs_ioc_pool_create(zfs_cmd_t *zc)
890 nvlist_t *config, *props = NULL;
891 nvlist_t *rootprops = NULL;
892 nvlist_t *zplprops = NULL;
895 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
896 zc->zc_iflags, &config))
899 if (zc->zc_nvlist_src_size != 0 && (error =
900 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
901 zc->zc_iflags, &props))) {
907 nvlist_t *nvl = NULL;
908 uint64_t version = SPA_VERSION;
910 (void) nvlist_lookup_uint64(props,
911 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
912 if (version < SPA_VERSION_INITIAL || version > SPA_VERSION) {
916 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
918 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
924 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
926 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
927 error = zfs_fill_zplprops_root(version, rootprops,
933 buf = history_str_get(zc);
935 error = spa_create(zc->zc_name, config, props, buf, zplprops);
938 * Set the remaining root properties
941 (error = zfs_set_prop_nvlist(zc->zc_name, rootprops)) != 0)
942 (void) spa_destroy(zc->zc_name);
945 history_str_free(buf);
948 nvlist_free(rootprops);
949 nvlist_free(zplprops);
957 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
961 error = spa_destroy(zc->zc_name);
966 zfs_ioc_pool_import(zfs_cmd_t *zc)
969 nvlist_t *config, *props = NULL;
972 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
973 zc->zc_iflags, &config)) != 0)
976 if (zc->zc_nvlist_src_size != 0 && (error =
977 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
978 zc->zc_iflags, &props))) {
983 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
986 else if (zc->zc_cookie)
987 error = spa_import_verbatim(zc->zc_name, config,
990 error = spa_import(zc->zc_name, config, props);
1001 zfs_ioc_pool_export(zfs_cmd_t *zc)
1004 boolean_t force = (boolean_t)zc->zc_cookie;
1005 boolean_t hardforce = (boolean_t)zc->zc_guid;
1007 zfs_log_history(zc);
1008 error = spa_export(zc->zc_name, NULL, force, hardforce);
1013 zfs_ioc_pool_configs(zfs_cmd_t *zc)
1018 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
1021 error = put_nvlist(zc, configs);
1023 nvlist_free(configs);
1029 zfs_ioc_pool_stats(zfs_cmd_t *zc)
1035 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
1036 sizeof (zc->zc_value));
1038 if (config != NULL) {
1039 ret = put_nvlist(zc, config);
1040 nvlist_free(config);
1043 * The config may be present even if 'error' is non-zero.
1044 * In this case we return success, and preserve the real errno
1047 zc->zc_cookie = error;
1056 * Try to import the given pool, returning pool stats as appropriate so that
1057 * user land knows which devices are available and overall pool health.
1060 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
1062 nvlist_t *tryconfig, *config;
1065 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1066 zc->zc_iflags, &tryconfig)) != 0)
1069 config = spa_tryimport(tryconfig);
1071 nvlist_free(tryconfig);
1076 error = put_nvlist(zc, config);
1077 nvlist_free(config);
1083 zfs_ioc_pool_scrub(zfs_cmd_t *zc)
1088 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1091 error = spa_scrub(spa, zc->zc_cookie);
1093 spa_close(spa, FTAG);
1099 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
1104 error = spa_open(zc->zc_name, &spa, FTAG);
1107 spa_close(spa, FTAG);
1113 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
1118 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1121 if (zc->zc_cookie < spa_version(spa) || zc->zc_cookie > SPA_VERSION) {
1122 spa_close(spa, FTAG);
1126 spa_upgrade(spa, zc->zc_cookie);
1127 spa_close(spa, FTAG);
1133 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
1140 if ((size = zc->zc_history_len) == 0)
1143 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1146 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
1147 spa_close(spa, FTAG);
1151 hist_buf = kmem_alloc(size, KM_SLEEP);
1152 if ((error = spa_history_get(spa, &zc->zc_history_offset,
1153 &zc->zc_history_len, hist_buf)) == 0) {
1154 error = ddi_copyout(hist_buf,
1155 (void *)(uintptr_t)zc->zc_history,
1156 zc->zc_history_len, zc->zc_iflags);
1159 spa_close(spa, FTAG);
1160 kmem_free(hist_buf, size);
1165 zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
1169 if (error = dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value))
1176 zfs_ioc_obj_to_path(zfs_cmd_t *zc)
1181 if ((error = dmu_objset_open(zc->zc_name, DMU_OST_ZFS,
1182 DS_MODE_USER | DS_MODE_READONLY, &osp)) != 0)
1184 error = zfs_obj_to_path(osp, zc->zc_obj, zc->zc_value,
1185 sizeof (zc->zc_value));
1186 dmu_objset_close(osp);
1192 zfs_ioc_vdev_add(zfs_cmd_t *zc)
1196 nvlist_t *config, **l2cache, **spares;
1197 uint_t nl2cache = 0, nspares = 0;
1199 error = spa_open(zc->zc_name, &spa, FTAG);
1203 error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1204 zc->zc_iflags, &config);
1205 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
1206 &l2cache, &nl2cache);
1208 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
1212 * A root pool with concatenated devices is not supported.
1213 * Thus, can not add a device to a root pool.
1215 * Intent log device can not be added to a rootpool because
1216 * during mountroot, zil is replayed, a seperated log device
1217 * can not be accessed during the mountroot time.
1219 * l2cache and spare devices are ok to be added to a rootpool.
1221 if (spa->spa_bootfs != 0 && nl2cache == 0 && nspares == 0) {
1222 spa_close(spa, FTAG);
1227 error = spa_vdev_add(spa, config);
1228 nvlist_free(config);
1230 spa_close(spa, FTAG);
1235 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
1240 error = spa_open(zc->zc_name, &spa, FTAG);
1243 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
1244 spa_close(spa, FTAG);
1249 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
1253 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1255 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1257 switch (zc->zc_cookie) {
1258 case VDEV_STATE_ONLINE:
1259 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
1262 case VDEV_STATE_OFFLINE:
1263 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
1266 case VDEV_STATE_FAULTED:
1267 error = vdev_fault(spa, zc->zc_guid);
1270 case VDEV_STATE_DEGRADED:
1271 error = vdev_degrade(spa, zc->zc_guid);
1277 zc->zc_cookie = newstate;
1278 spa_close(spa, FTAG);
1283 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
1286 int replacing = zc->zc_cookie;
1290 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1293 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1294 zc->zc_iflags, &config)) == 0) {
1295 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
1296 nvlist_free(config);
1299 spa_close(spa, FTAG);
1304 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
1309 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1312 error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
1314 spa_close(spa, FTAG);
1319 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
1322 char *path = zc->zc_value;
1323 uint64_t guid = zc->zc_guid;
1326 error = spa_open(zc->zc_name, &spa, FTAG);
1330 error = spa_vdev_setpath(spa, guid, path);
1331 spa_close(spa, FTAG);
1336 zfs_ioc_vdev_setfru(zfs_cmd_t *zc)
1339 char *fru = zc->zc_value;
1340 uint64_t guid = zc->zc_guid;
1343 error = spa_open(zc->zc_name, &spa, FTAG);
1347 error = spa_vdev_setfru(spa, guid, fru);
1348 spa_close(spa, FTAG);
1354 * zc_name name of filesystem
1355 * zc_nvlist_dst_size size of buffer for property nvlist
1358 * zc_objset_stats stats
1359 * zc_nvlist_dst property nvlist
1360 * zc_nvlist_dst_size size of property nvlist
1363 zfs_ioc_objset_stats(zfs_cmd_t *zc)
1365 objset_t *os = NULL;
1369 if (error = dmu_objset_open(zc->zc_name,
1370 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os))
1373 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
1375 if (zc->zc_nvlist_dst != 0 &&
1376 (error = dsl_prop_get_all(os, &nv, FALSE)) == 0) {
1377 dmu_objset_stats(os, nv);
1379 * NB: zvol_get_stats() will read the objset contents,
1380 * which we aren't supposed to do with a
1381 * DS_MODE_USER hold, because it could be
1382 * inconsistent. So this is a bit of a workaround...
1384 if (!zc->zc_objset_stats.dds_inconsistent) {
1385 if (dmu_objset_type(os) == DMU_OST_ZVOL)
1386 VERIFY(zvol_get_stats(os, nv) == 0);
1388 error = put_nvlist(zc, nv);
1392 dmu_objset_close(os);
1397 nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
1403 * zfs_get_zplprop() will either find a value or give us
1404 * the default value (if there is one).
1406 if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
1408 VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
1414 * zc_name name of filesystem
1415 * zc_nvlist_dst_size size of buffer for zpl property nvlist
1418 * zc_nvlist_dst zpl property nvlist
1419 * zc_nvlist_dst_size size of zpl property nvlist
1422 zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
1427 if (err = dmu_objset_open(zc->zc_name,
1428 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os))
1431 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
1434 * NB: nvl_add_zplprop() will read the objset contents,
1435 * which we aren't supposed to do with a DS_MODE_USER
1436 * hold, because it could be inconsistent.
1438 if (zc->zc_nvlist_dst != NULL &&
1439 !zc->zc_objset_stats.dds_inconsistent &&
1440 dmu_objset_type(os) == DMU_OST_ZFS) {
1443 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1444 if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
1445 (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
1446 (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
1447 (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
1448 err = put_nvlist(zc, nv);
1453 dmu_objset_close(os);
1458 dataset_name_hidden(const char *name)
1461 * Skip over datasets that are not visible in this zone,
1462 * internal datasets (which have a $ in their name), and
1463 * temporary datasets (which have a % in their name).
1465 if (strchr(name, '$') != NULL)
1467 if (strchr(name, '%') != NULL)
1469 if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
1476 * zc_name name of filesystem
1477 * zc_cookie zap cursor
1478 * zc_nvlist_dst_size size of buffer for property nvlist
1481 * zc_name name of next filesystem
1482 * zc_cookie zap cursor
1483 * zc_objset_stats stats
1484 * zc_nvlist_dst property nvlist
1485 * zc_nvlist_dst_size size of property nvlist
1488 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
1494 if (error = dmu_objset_open(zc->zc_name,
1495 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os)) {
1496 if (error == ENOENT)
1501 p = strrchr(zc->zc_name, '/');
1502 if (p == NULL || p[1] != '\0')
1503 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
1504 p = zc->zc_name + strlen(zc->zc_name);
1507 * Pre-fetch the datasets. dmu_objset_prefetch() always returns 0
1508 * but is not declared void because its called by dmu_objset_find().
1510 if (zc->zc_cookie == 0) {
1511 uint64_t cookie = 0;
1512 int len = sizeof (zc->zc_name) - (p - zc->zc_name);
1514 while (dmu_dir_list_next(os, len, p, NULL, &cookie) == 0)
1515 (void) dmu_objset_prefetch(p, NULL);
1519 error = dmu_dir_list_next(os,
1520 sizeof (zc->zc_name) - (p - zc->zc_name), p,
1521 NULL, &zc->zc_cookie);
1522 if (error == ENOENT)
1524 } while (error == 0 && dataset_name_hidden(zc->zc_name));
1525 dmu_objset_close(os);
1528 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
1535 * zc_name name of filesystem
1536 * zc_cookie zap cursor
1537 * zc_nvlist_dst_size size of buffer for property nvlist
1540 * zc_name name of next snapshot
1541 * zc_objset_stats stats
1542 * zc_nvlist_dst property nvlist
1543 * zc_nvlist_dst_size size of property nvlist
1546 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
1551 error = dmu_objset_open(zc->zc_name,
1552 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os);
1554 return (error == ENOENT ? ESRCH : error);
1556 if (zc->zc_cookie == 0) {
1557 (void) dmu_objset_find(zc->zc_name, dmu_objset_prefetch,
1558 NULL, DS_FIND_SNAPSHOTS);
1561 * A dataset name of maximum length cannot have any snapshots,
1562 * so exit immediately.
1564 if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
1565 dmu_objset_close(os);
1569 error = dmu_snapshot_list_next(os,
1570 sizeof (zc->zc_name) - strlen(zc->zc_name),
1571 zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie, NULL);
1572 dmu_objset_close(os);
1574 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
1575 else if (error == ENOENT)
1578 /* if we failed, undo the @ that we tacked on to zc_name */
1580 *strchr(zc->zc_name, '@') = '\0';
1585 zfs_set_prop_nvlist(const char *name, nvlist_t *nvl)
1591 nvlist_t *genericnvl;
1592 boolean_t issnap = (strchr(name, '@') != NULL);
1595 * First validate permission to set all of the properties
1598 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
1599 const char *propname = nvpair_name(elem);
1600 zfs_prop_t prop = zfs_name_to_prop(propname);
1602 if (prop == ZPROP_INVAL) {
1604 * If this is a user-defined property, it must be a
1605 * string, and there is no further validation to do.
1607 if (zfs_prop_user(propname) &&
1608 nvpair_type(elem) == DATA_TYPE_STRING) {
1609 if (error = zfs_secpolicy_write_perms(name,
1610 ZFS_DELEG_PERM_USERPROP, CRED()))
1615 if (!issnap && zfs_prop_userquota(propname) &&
1616 nvpair_type(elem) == DATA_TYPE_UINT64_ARRAY) {
1618 const char *up = zfs_userquota_prop_prefixes
1619 [ZFS_PROP_USERQUOTA];
1620 if (strncmp(propname, up, strlen(up)) == 0)
1621 perm = ZFS_DELEG_PERM_USERQUOTA;
1623 perm = ZFS_DELEG_PERM_GROUPQUOTA;
1624 if (error = zfs_secpolicy_write_perms(name,
1636 if ((error = zfs_secpolicy_setprop(name, prop, CRED())) != 0)
1640 * Check that this value is valid for this pool version
1643 case ZFS_PROP_COMPRESSION:
1645 * If the user specified gzip compression, make sure
1646 * the SPA supports it. We ignore any errors here since
1647 * we'll catch them later.
1649 if (nvpair_type(elem) == DATA_TYPE_UINT64 &&
1650 nvpair_value_uint64(elem, &intval) == 0) {
1651 if (intval >= ZIO_COMPRESS_GZIP_1 &&
1652 intval <= ZIO_COMPRESS_GZIP_9 &&
1653 zfs_earlier_version(name,
1654 SPA_VERSION_GZIP_COMPRESSION))
1658 * If this is a bootable dataset then
1659 * verify that the compression algorithm
1660 * is supported for booting. We must return
1661 * something other than ENOTSUP since it
1662 * implies a downrev pool version.
1664 if (zfs_is_bootfs(name) &&
1665 !BOOTFS_COMPRESS_VALID(intval))
1670 case ZFS_PROP_COPIES:
1671 if (zfs_earlier_version(name, SPA_VERSION_DITTO_BLOCKS))
1675 case ZFS_PROP_SHARESMB:
1676 if (zpl_earlier_version(name, ZPL_VERSION_FUID))
1680 case ZFS_PROP_ACLINHERIT:
1681 if (nvpair_type(elem) == DATA_TYPE_UINT64 &&
1682 nvpair_value_uint64(elem, &intval) == 0)
1683 if (intval == ZFS_ACL_PASSTHROUGH_X &&
1684 zfs_earlier_version(name,
1685 SPA_VERSION_PASSTHROUGH_X))
1690 VERIFY(nvlist_alloc(&genericnvl, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1692 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
1693 const char *propname = nvpair_name(elem);
1694 zfs_prop_t prop = zfs_name_to_prop(propname);
1696 if (prop == ZPROP_INVAL) {
1697 if (zfs_prop_userquota(propname)) {
1699 unsigned int vallen;
1701 zfs_userquota_prop_t type;
1706 VERIFY(nvpair_value_uint64_array(elem,
1707 &valary, &vallen) == 0);
1708 VERIFY(vallen == 3);
1713 strlen(zfs_userquota_prop_prefixes[type]);
1715 error = zfsvfs_hold(name, B_FALSE, FTAG,
1718 error = zfs_set_userquota(zfsvfs,
1719 type, domain, rid, quota);
1720 zfsvfs_rele(zfsvfs, FTAG);
1726 } else if (zfs_prop_user(propname)) {
1727 VERIFY(nvpair_value_string(elem, &strval) == 0);
1728 error = dsl_prop_set(name, propname, 1,
1729 strlen(strval) + 1, strval);
1738 case ZFS_PROP_QUOTA:
1739 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1740 (error = dsl_dir_set_quota(name, intval)) != 0)
1744 case ZFS_PROP_REFQUOTA:
1745 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1746 (error = dsl_dataset_set_quota(name, intval)) != 0)
1750 case ZFS_PROP_RESERVATION:
1751 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1752 (error = dsl_dir_set_reservation(name,
1757 case ZFS_PROP_REFRESERVATION:
1758 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1759 (error = dsl_dataset_set_reservation(name,
1764 case ZFS_PROP_VOLSIZE:
1765 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1766 (error = zvol_set_volsize(name,
1767 ddi_driver_major(zfs_dip), intval)) != 0)
1771 case ZFS_PROP_VOLBLOCKSIZE:
1772 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1773 (error = zvol_set_volblocksize(name, intval)) != 0)
1777 case ZFS_PROP_VERSION:
1781 if ((error = nvpair_value_uint64(elem, &intval)) != 0)
1783 if ((error = zfsvfs_hold(name, B_FALSE, FTAG,
1786 error = zfs_set_version(zfsvfs, intval);
1787 zfsvfs_rele(zfsvfs, FTAG);
1789 if (error == 0 && intval >= ZPL_VERSION_USERSPACE) {
1790 zfs_cmd_t zc = { 0 };
1791 (void) strcpy(zc.zc_name, name);
1792 (void) zfs_ioc_userspace_upgrade(&zc);
1800 if (nvpair_type(elem) == DATA_TYPE_STRING) {
1801 if (zfs_prop_get_type(prop) !=
1806 } else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
1809 VERIFY(nvpair_value_uint64(elem, &intval) == 0);
1811 switch (zfs_prop_get_type(prop)) {
1812 case PROP_TYPE_NUMBER:
1814 case PROP_TYPE_STRING:
1817 case PROP_TYPE_INDEX:
1818 if (zfs_prop_index_to_string(prop,
1819 intval, &unused) != 0) {
1826 "unknown property type");
1833 if ((error = nvlist_add_nvpair(genericnvl, elem)) != 0)
1838 if (nvlist_next_nvpair(genericnvl, NULL) != NULL) {
1839 error = dsl_props_set(name, genericnvl);
1842 nvlist_free(genericnvl);
1847 * Check that all the properties are valid user properties.
1850 zfs_check_userprops(char *fsname, nvlist_t *nvl)
1852 nvpair_t *elem = NULL;
1855 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
1856 const char *propname = nvpair_name(elem);
1859 if (!zfs_prop_user(propname) ||
1860 nvpair_type(elem) != DATA_TYPE_STRING)
1863 if (error = zfs_secpolicy_write_perms(fsname,
1864 ZFS_DELEG_PERM_USERPROP, CRED()))
1867 if (strlen(propname) >= ZAP_MAXNAMELEN)
1868 return (ENAMETOOLONG);
1870 VERIFY(nvpair_value_string(elem, &valstr) == 0);
1871 if (strlen(valstr) >= ZAP_MAXVALUELEN)
1879 * zc_name name of filesystem
1880 * zc_value name of property to set
1881 * zc_nvlist_src{_size} nvlist of properties to apply
1882 * zc_cookie clear existing local props?
1887 zfs_ioc_set_prop(zfs_cmd_t *zc)
1892 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1893 zc->zc_iflags, &nvl)) != 0)
1896 if (zc->zc_cookie) {
1897 nvlist_t *origprops;
1900 if (dmu_objset_open(zc->zc_name, DMU_OST_ANY,
1901 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
1902 if (dsl_prop_get_all(os, &origprops, TRUE) == 0) {
1903 clear_props(zc->zc_name, origprops, nvl);
1904 nvlist_free(origprops);
1906 dmu_objset_close(os);
1911 error = zfs_set_prop_nvlist(zc->zc_name, nvl);
1919 * zc_name name of filesystem
1920 * zc_value name of property to inherit
1925 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
1927 /* the property name has been validated by zfs_secpolicy_inherit() */
1928 return (dsl_prop_set(zc->zc_name, zc->zc_value, 0, 0, NULL));
1932 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
1939 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1940 zc->zc_iflags, &props)))
1944 * If the only property is the configfile, then just do a spa_lookup()
1945 * to handle the faulted case.
1947 elem = nvlist_next_nvpair(props, NULL);
1948 if (elem != NULL && strcmp(nvpair_name(elem),
1949 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
1950 nvlist_next_nvpair(props, elem) == NULL) {
1951 mutex_enter(&spa_namespace_lock);
1952 if ((spa = spa_lookup(zc->zc_name)) != NULL) {
1953 spa_configfile_set(spa, props, B_FALSE);
1954 spa_config_sync(spa, B_FALSE, B_TRUE);
1956 mutex_exit(&spa_namespace_lock);
1961 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
1966 error = spa_prop_set(spa, props);
1969 spa_close(spa, FTAG);
1975 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
1979 nvlist_t *nvp = NULL;
1981 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
1983 * If the pool is faulted, there may be properties we can still
1984 * get (such as altroot and cachefile), so attempt to get them
1987 mutex_enter(&spa_namespace_lock);
1988 if ((spa = spa_lookup(zc->zc_name)) != NULL)
1989 error = spa_prop_get(spa, &nvp);
1990 mutex_exit(&spa_namespace_lock);
1992 error = spa_prop_get(spa, &nvp);
1993 spa_close(spa, FTAG);
1996 if (error == 0 && zc->zc_nvlist_dst != NULL)
1997 error = put_nvlist(zc, nvp);
2006 zfs_ioc_iscsi_perm_check(zfs_cmd_t *zc)
2016 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2017 zc->zc_iflags, &nvp)) != 0) {
2021 if ((error = nvlist_lookup_uint32(nvp,
2022 ZFS_DELEG_PERM_UID, &uid)) != 0) {
2027 if ((error = nvlist_lookup_uint32(nvp,
2028 ZFS_DELEG_PERM_GID, &gid)) != 0) {
2033 if ((error = nvlist_lookup_uint32_array(nvp, ZFS_DELEG_PERM_GROUPS,
2034 &groups, &group_cnt)) != 0) {
2038 usercred = cralloc();
2039 if ((crsetugid(usercred, uid, gid) != 0) ||
2040 (crsetgroups(usercred, group_cnt, (gid_t *)groups) != 0)) {
2046 error = dsl_deleg_access(zc->zc_name,
2047 zfs_prop_to_name(ZFS_PROP_SHAREISCSI), usercred);
2054 * zc_name name of filesystem
2055 * zc_nvlist_src{_size} nvlist of delegated permissions
2056 * zc_perm_action allow/unallow flag
2061 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
2064 nvlist_t *fsaclnv = NULL;
2066 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2067 zc->zc_iflags, &fsaclnv)) != 0)
2071 * Verify nvlist is constructed correctly
2073 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
2074 nvlist_free(fsaclnv);
2079 * If we don't have PRIV_SYS_MOUNT, then validate
2080 * that user is allowed to hand out each permission in
2084 error = secpolicy_zfs(CRED());
2086 if (zc->zc_perm_action == B_FALSE) {
2087 error = dsl_deleg_can_allow(zc->zc_name,
2090 error = dsl_deleg_can_unallow(zc->zc_name,
2096 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
2098 nvlist_free(fsaclnv);
2104 * zc_name name of filesystem
2107 * zc_nvlist_src{_size} nvlist of delegated permissions
2110 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
2115 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
2116 error = put_nvlist(zc, nvp);
2125 * zc_name name of volume
2130 zfs_ioc_create_minor(zfs_cmd_t *zc)
2132 return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip)));
2137 * zc_name name of volume
2142 zfs_ioc_remove_minor(zfs_cmd_t *zc)
2144 return (zvol_remove_minor(zc->zc_name));
2148 * Search the vfs list for a specified resource. Returns a pointer to it
2149 * or NULL if no suitable entry is found. The caller of this routine
2150 * is responsible for releasing the returned vfs pointer.
2153 zfs_get_vfs(const char *resource)
2156 struct vfs *vfs_found = NULL;
2158 vfs_list_read_lock();
2161 if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
2166 vfsp = vfsp->vfs_next;
2167 } while (vfsp != rootvfs);
2174 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
2176 zfs_creat_t *zct = arg;
2178 zfs_create_fs(os, cr, zct->zct_zplprops, tx);
2181 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2185 * createprops list of properties requested by creator
2186 * default_zplver zpl version to use if unspecified in createprops
2187 * fuids_ok fuids allowed in this version of the spa?
2188 * os parent objset pointer (NULL if root fs)
2191 * zplprops values for the zplprops we attach to the master node object
2192 * is_ci true if requested file system will be purely case-insensitive
2194 * Determine the settings for utf8only, normalization and
2195 * casesensitivity. Specific values may have been requested by the
2196 * creator and/or we can inherit values from the parent dataset. If
2197 * the file system is of too early a vintage, a creator can not
2198 * request settings for these properties, even if the requested
2199 * setting is the default value. We don't actually want to create dsl
2200 * properties for these, so remove them from the source nvlist after
2204 zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
2205 boolean_t fuids_ok, nvlist_t *createprops, nvlist_t *zplprops,
2208 uint64_t sense = ZFS_PROP_UNDEFINED;
2209 uint64_t norm = ZFS_PROP_UNDEFINED;
2210 uint64_t u8 = ZFS_PROP_UNDEFINED;
2212 ASSERT(zplprops != NULL);
2215 * Pull out creator prop choices, if any.
2218 (void) nvlist_lookup_uint64(createprops,
2219 zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
2220 (void) nvlist_lookup_uint64(createprops,
2221 zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
2222 (void) nvlist_remove_all(createprops,
2223 zfs_prop_to_name(ZFS_PROP_NORMALIZE));
2224 (void) nvlist_lookup_uint64(createprops,
2225 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
2226 (void) nvlist_remove_all(createprops,
2227 zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
2228 (void) nvlist_lookup_uint64(createprops,
2229 zfs_prop_to_name(ZFS_PROP_CASE), &sense);
2230 (void) nvlist_remove_all(createprops,
2231 zfs_prop_to_name(ZFS_PROP_CASE));
2235 * If the zpl version requested is whacky or the file system
2236 * or pool is version is too "young" to support normalization
2237 * and the creator tried to set a value for one of the props,
2240 if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
2241 (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
2242 (zplver < ZPL_VERSION_NORMALIZATION &&
2243 (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
2244 sense != ZFS_PROP_UNDEFINED)))
2248 * Put the version in the zplprops
2250 VERIFY(nvlist_add_uint64(zplprops,
2251 zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
2253 if (norm == ZFS_PROP_UNDEFINED)
2254 VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
2255 VERIFY(nvlist_add_uint64(zplprops,
2256 zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
2259 * If we're normalizing, names must always be valid UTF-8 strings.
2263 if (u8 == ZFS_PROP_UNDEFINED)
2264 VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
2265 VERIFY(nvlist_add_uint64(zplprops,
2266 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
2268 if (sense == ZFS_PROP_UNDEFINED)
2269 VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
2270 VERIFY(nvlist_add_uint64(zplprops,
2271 zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
2274 *is_ci = (sense == ZFS_CASE_INSENSITIVE);
2280 zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
2281 nvlist_t *zplprops, boolean_t *is_ci)
2283 boolean_t fuids_ok = B_TRUE;
2284 uint64_t zplver = ZPL_VERSION;
2285 objset_t *os = NULL;
2286 char parentname[MAXNAMELEN];
2290 (void) strlcpy(parentname, dataset, sizeof (parentname));
2291 cp = strrchr(parentname, '/');
2295 if (zfs_earlier_version(dataset, SPA_VERSION_USERSPACE))
2296 zplver = ZPL_VERSION_USERSPACE - 1;
2297 if (zfs_earlier_version(dataset, SPA_VERSION_FUID)) {
2298 zplver = ZPL_VERSION_FUID - 1;
2303 * Open parent object set so we can inherit zplprop values.
2305 if ((error = dmu_objset_open(parentname, DMU_OST_ANY,
2306 DS_MODE_USER | DS_MODE_READONLY, &os)) != 0)
2309 error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, createprops,
2311 dmu_objset_close(os);
2316 zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
2317 nvlist_t *zplprops, boolean_t *is_ci)
2319 boolean_t fuids_ok = B_TRUE;
2320 uint64_t zplver = ZPL_VERSION;
2323 if (spa_vers < SPA_VERSION_FUID) {
2324 zplver = ZPL_VERSION_FUID - 1;
2328 error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, createprops,
2335 * zc_objset_type type of objset to create (fs vs zvol)
2336 * zc_name name of new objset
2337 * zc_value name of snapshot to clone from (may be empty)
2338 * zc_nvlist_src{_size} nvlist of properties to apply
2343 zfs_ioc_create(zfs_cmd_t *zc)
2348 nvlist_t *nvprops = NULL;
2349 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
2350 dmu_objset_type_t type = zc->zc_objset_type;
2355 cbfunc = zfs_create_cb;
2359 cbfunc = zvol_create_cb;
2366 if (strchr(zc->zc_name, '@') ||
2367 strchr(zc->zc_name, '%'))
2370 if (zc->zc_nvlist_src != NULL &&
2371 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2372 zc->zc_iflags, &nvprops)) != 0)
2375 zct.zct_zplprops = NULL;
2376 zct.zct_props = nvprops;
2378 if (zc->zc_value[0] != '\0') {
2380 * We're creating a clone of an existing snapshot.
2382 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
2383 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
2384 nvlist_free(nvprops);
2388 error = dmu_objset_open(zc->zc_value, type,
2389 DS_MODE_USER | DS_MODE_READONLY, &clone);
2391 nvlist_free(nvprops);
2395 error = dmu_objset_create(zc->zc_name, type, clone, 0,
2398 dmu_objset_close(clone);
2399 nvlist_free(nvprops);
2402 dmu_objset_close(clone);
2404 boolean_t is_insensitive = B_FALSE;
2406 if (cbfunc == NULL) {
2407 nvlist_free(nvprops);
2411 if (type == DMU_OST_ZVOL) {
2412 uint64_t volsize, volblocksize;
2414 if (nvprops == NULL ||
2415 nvlist_lookup_uint64(nvprops,
2416 zfs_prop_to_name(ZFS_PROP_VOLSIZE),
2418 nvlist_free(nvprops);
2422 if ((error = nvlist_lookup_uint64(nvprops,
2423 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
2424 &volblocksize)) != 0 && error != ENOENT) {
2425 nvlist_free(nvprops);
2430 volblocksize = zfs_prop_default_numeric(
2431 ZFS_PROP_VOLBLOCKSIZE);
2433 if ((error = zvol_check_volblocksize(
2434 volblocksize)) != 0 ||
2435 (error = zvol_check_volsize(volsize,
2436 volblocksize)) != 0) {
2437 nvlist_free(nvprops);
2440 } else if (type == DMU_OST_ZFS) {
2444 * We have to have normalization and
2445 * case-folding flags correct when we do the
2446 * file system creation, so go figure them out
2449 VERIFY(nvlist_alloc(&zct.zct_zplprops,
2450 NV_UNIQUE_NAME, KM_SLEEP) == 0);
2451 error = zfs_fill_zplprops(zc->zc_name, nvprops,
2452 zct.zct_zplprops, &is_insensitive);
2454 nvlist_free(nvprops);
2455 nvlist_free(zct.zct_zplprops);
2459 error = dmu_objset_create(zc->zc_name, type, NULL,
2460 is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
2461 nvlist_free(zct.zct_zplprops);
2465 * It would be nice to do this atomically.
2468 if ((error = zfs_set_prop_nvlist(zc->zc_name, nvprops)) != 0)
2469 (void) dmu_objset_destroy(zc->zc_name);
2471 nvlist_free(nvprops);
2477 * zc_name name of filesystem
2478 * zc_value short name of snapshot
2479 * zc_cookie recursive flag
2480 * zc_nvlist_src[_size] property list
2485 zfs_ioc_snapshot(zfs_cmd_t *zc)
2487 nvlist_t *nvprops = NULL;
2489 boolean_t recursive = zc->zc_cookie;
2491 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2494 if (zc->zc_nvlist_src != NULL &&
2495 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2496 zc->zc_iflags, &nvprops)) != 0)
2499 error = zfs_check_userprops(zc->zc_name, nvprops);
2503 if (nvprops != NULL && nvlist_next_nvpair(nvprops, NULL) != NULL &&
2504 zfs_earlier_version(zc->zc_name, SPA_VERSION_SNAP_PROPS)) {
2509 error = dmu_objset_snapshot(zc->zc_name, zc->zc_value,
2510 nvprops, recursive);
2513 nvlist_free(nvprops);
2518 zfs_unmount_snap(char *name, void *arg)
2523 char *snapname = arg;
2524 int len = strlen(name) + strlen(snapname) + 2;
2525 char *buf = kmem_alloc(len, KM_SLEEP);
2527 (void) strcpy(buf, name);
2528 (void) strcat(buf, "@");
2529 (void) strcat(buf, snapname);
2530 vfsp = zfs_get_vfs(buf);
2531 kmem_free(buf, len);
2532 } else if (strchr(name, '@')) {
2533 vfsp = zfs_get_vfs(name);
2538 * Always force the unmount for snapshots.
2540 int flag = MS_FORCE;
2543 if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
2548 if ((err = dounmount(vfsp, flag, kcred)) != 0)
2556 * zc_name name of filesystem
2557 * zc_value short name of snapshot
2562 zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
2566 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2568 err = dmu_objset_find(zc->zc_name,
2569 zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2572 return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value));
2577 * zc_name name of dataset to destroy
2578 * zc_objset_type type of objset
2583 zfs_ioc_destroy(zfs_cmd_t *zc)
2585 if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
2586 int err = zfs_unmount_snap(zc->zc_name, NULL);
2591 return (dmu_objset_destroy(zc->zc_name));
2596 * zc_name name of dataset to rollback (to most recent snapshot)
2601 zfs_ioc_rollback(zfs_cmd_t *zc)
2605 zfsvfs_t *zfsvfs = NULL;
2608 * Get the zfsvfs for the receiving objset. There
2609 * won't be one if we're operating on a zvol, if the
2610 * objset doesn't exist yet, or is not mounted.
2612 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, DS_MODE_USER, &os);
2616 if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
2619 error = zfs_suspend_fs(zfsvfs, NULL, &mode);
2623 error = dmu_objset_rollback(os);
2624 resume_err = zfs_resume_fs(zfsvfs, zc->zc_name, mode);
2625 error = error ? error : resume_err;
2627 dmu_objset_close(os);
2629 VFS_RELE(zfsvfs->z_vfs);
2631 error = dmu_objset_rollback(os);
2633 /* Note, the dmu_objset_rollback() releases the objset for us. */
2640 * zc_name old name of dataset
2641 * zc_value new name of dataset
2642 * zc_cookie recursive flag (only valid for snapshots)
2647 zfs_ioc_rename(zfs_cmd_t *zc)
2649 boolean_t recursive = zc->zc_cookie & 1;
2651 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
2652 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
2653 strchr(zc->zc_value, '%'))
2657 * Unmount snapshot unless we're doing a recursive rename,
2658 * in which case the dataset code figures out which snapshots
2661 if (!recursive && strchr(zc->zc_name, '@') != NULL &&
2662 zc->zc_objset_type == DMU_OST_ZFS) {
2663 int err = zfs_unmount_snap(zc->zc_name, NULL);
2667 return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
2671 clear_props(char *dataset, nvlist_t *props, nvlist_t *newprops)
2678 zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
2679 (void) strcpy(zc->zc_name, dataset);
2680 for (prop = nvlist_next_nvpair(props, NULL); prop;
2681 prop = nvlist_next_nvpair(props, prop)) {
2682 if (newprops != NULL &&
2683 nvlist_exists(newprops, nvpair_name(prop)))
2685 (void) strcpy(zc->zc_value, nvpair_name(prop));
2686 if (zfs_secpolicy_inherit(zc, CRED()) == 0)
2687 (void) zfs_ioc_inherit_prop(zc);
2689 kmem_free(zc, sizeof (zfs_cmd_t));
2694 * zc_name name of containing filesystem
2695 * zc_nvlist_src{_size} nvlist of properties to apply
2696 * zc_value name of snapshot to create
2697 * zc_string name of clone origin (if DRR_FLAG_CLONE)
2698 * zc_cookie file descriptor to recv from
2699 * zc_begin_record the BEGIN record of the stream (not byteswapped)
2700 * zc_guid force flag
2703 * zc_cookie number of bytes read
2706 zfs_ioc_recv(zfs_cmd_t *zc)
2710 dmu_recv_cookie_t drc;
2711 zfsvfs_t *zfsvfs = NULL;
2712 boolean_t force = (boolean_t)zc->zc_guid;
2715 nvlist_t *props = NULL;
2716 nvlist_t *origprops = NULL;
2717 objset_t *origin = NULL;
2719 char tofs[ZFS_MAXNAMELEN];
2721 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
2722 strchr(zc->zc_value, '@') == NULL ||
2723 strchr(zc->zc_value, '%'))
2726 (void) strcpy(tofs, zc->zc_value);
2727 tosnap = strchr(tofs, '@');
2731 if (zc->zc_nvlist_src != NULL &&
2732 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2733 zc->zc_iflags, &props)) != 0)
2743 if (getzfsvfs(tofs, &zfsvfs) == 0) {
2744 if (!mutex_tryenter(&zfsvfs->z_online_recv_lock)) {
2745 VFS_RELE(zfsvfs->z_vfs);
2751 * If new properties are supplied, they are to completely
2752 * replace the existing ones, so stash away the existing ones.
2755 (void) dsl_prop_get_all(zfsvfs->z_os, &origprops, TRUE);
2756 } else if (props && dmu_objset_open(tofs, DMU_OST_ANY,
2757 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
2759 * Get the props even if there was no zfsvfs (zvol or
2762 (void) dsl_prop_get_all(os, &origprops, TRUE);
2764 dmu_objset_close(os);
2767 if (zc->zc_string[0]) {
2768 error = dmu_objset_open(zc->zc_string, DMU_OST_ANY,
2769 DS_MODE_USER | DS_MODE_READONLY, &origin);
2774 error = dmu_recv_begin(tofs, tosnap, &zc->zc_begin_record,
2775 force, origin, zfsvfs != NULL, &drc);
2777 dmu_objset_close(origin);
2782 * Reset properties. We do this before we receive the stream
2783 * so that the properties are applied to the new data.
2786 clear_props(tofs, origprops, props);
2788 * XXX - Note, this is all-or-nothing; should be best-effort.
2790 (void) zfs_set_prop_nvlist(tofs, props);
2794 error = dmu_recv_stream(&drc, fp->f_vnode, &off);
2796 if (error == 0 && zfsvfs) {
2801 osname = kmem_alloc(MAXNAMELEN, KM_SLEEP);
2802 error = zfs_suspend_fs(zfsvfs, osname, &mode);
2806 error = dmu_recv_end(&drc);
2807 resume_err = zfs_resume_fs(zfsvfs, osname, mode);
2808 error = error ? error : resume_err;
2810 dmu_recv_abort_cleanup(&drc);
2812 kmem_free(osname, MAXNAMELEN);
2813 } else if (error == 0) {
2814 error = dmu_recv_end(&drc);
2817 zc->zc_cookie = off - fp->f_offset;
2818 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
2822 * On error, restore the original props.
2824 if (error && props) {
2825 clear_props(tofs, props, NULL);
2826 (void) zfs_set_prop_nvlist(tofs, origprops);
2830 mutex_exit(&zfsvfs->z_online_recv_lock);
2831 VFS_RELE(zfsvfs->z_vfs);
2834 nvlist_free(origprops);
2841 * zc_name name of snapshot to send
2842 * zc_value short name of incremental fromsnap (may be empty)
2843 * zc_cookie file descriptor to send stream to
2844 * zc_obj fromorigin flag (mutually exclusive with zc_value)
2849 zfs_ioc_send(zfs_cmd_t *zc)
2851 objset_t *fromsnap = NULL;
2857 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
2858 DS_MODE_USER | DS_MODE_READONLY, &tosnap);
2862 if (zc->zc_value[0] != '\0') {
2866 buf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
2867 (void) strncpy(buf, zc->zc_name, MAXPATHLEN);
2868 cp = strchr(buf, '@');
2871 (void) strncat(buf, zc->zc_value, MAXPATHLEN);
2872 error = dmu_objset_open(buf, DMU_OST_ANY,
2873 DS_MODE_USER | DS_MODE_READONLY, &fromsnap);
2874 kmem_free(buf, MAXPATHLEN);
2876 dmu_objset_close(tosnap);
2881 fp = getf(zc->zc_cookie);
2883 dmu_objset_close(tosnap);
2885 dmu_objset_close(fromsnap);
2890 error = dmu_sendbackup(tosnap, fromsnap, zc->zc_obj, fp->f_vnode, &off);
2892 if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
2894 releasef(zc->zc_cookie);
2896 dmu_objset_close(fromsnap);
2897 dmu_objset_close(tosnap);
2902 zfs_ioc_inject_fault(zfs_cmd_t *zc)
2906 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
2907 &zc->zc_inject_record);
2910 zc->zc_guid = (uint64_t)id;
2916 zfs_ioc_clear_fault(zfs_cmd_t *zc)
2918 return (zio_clear_fault((int)zc->zc_guid));
2922 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
2924 int id = (int)zc->zc_guid;
2927 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
2928 &zc->zc_inject_record);
2936 zfs_ioc_error_log(zfs_cmd_t *zc)
2940 size_t count = (size_t)zc->zc_nvlist_dst_size;
2942 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2945 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
2948 zc->zc_nvlist_dst_size = count;
2950 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
2952 spa_close(spa, FTAG);
2958 zfs_ioc_clear(zfs_cmd_t *zc)
2965 * On zpool clear we also fix up missing slogs
2967 mutex_enter(&spa_namespace_lock);
2968 spa = spa_lookup(zc->zc_name);
2970 mutex_exit(&spa_namespace_lock);
2973 if (spa->spa_log_state == SPA_LOG_MISSING) {
2974 /* we need to let spa_open/spa_load clear the chains */
2975 spa->spa_log_state = SPA_LOG_CLEAR;
2977 mutex_exit(&spa_namespace_lock);
2979 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2982 spa_vdev_state_enter(spa);
2984 if (zc->zc_guid == 0) {
2987 vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
2989 (void) spa_vdev_state_exit(spa, NULL, ENODEV);
2990 spa_close(spa, FTAG);
2995 vdev_clear(spa, vd);
2997 (void) spa_vdev_state_exit(spa, NULL, 0);
3000 * Resume any suspended I/Os.
3002 if (zio_resume(spa) != 0)
3005 spa_close(spa, FTAG);
3012 * zc_name name of filesystem
3013 * zc_value name of origin snapshot
3018 zfs_ioc_promote(zfs_cmd_t *zc)
3023 * We don't need to unmount *all* the origin fs's snapshots, but
3026 cp = strchr(zc->zc_value, '@');
3029 (void) dmu_objset_find(zc->zc_value,
3030 zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
3031 return (dsl_dataset_promote(zc->zc_name));
3035 * Retrieve a single {user|group}{used|quota}@... property.
3038 * zc_name name of filesystem
3039 * zc_objset_type zfs_userquota_prop_t
3040 * zc_value domain name (eg. "S-1-234-567-89")
3041 * zc_guid RID/UID/GID
3044 * zc_cookie property value
3047 zfs_ioc_userspace_one(zfs_cmd_t *zc)
3052 if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
3055 error = zfsvfs_hold(zc->zc_name, B_TRUE, FTAG, &zfsvfs);
3059 error = zfs_userspace_one(zfsvfs,
3060 zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
3061 zfsvfs_rele(zfsvfs, FTAG);
3068 * zc_name name of filesystem
3069 * zc_cookie zap cursor
3070 * zc_objset_type zfs_userquota_prop_t
3071 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
3074 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
3075 * zc_cookie zap cursor
3078 zfs_ioc_userspace_many(zfs_cmd_t *zc)
3083 error = zfsvfs_hold(zc->zc_name, B_TRUE, FTAG, &zfsvfs);
3087 int bufsize = zc->zc_nvlist_dst_size;
3088 void *buf = kmem_alloc(bufsize, KM_SLEEP);
3090 error = zfs_userspace_many(zfsvfs, zc->zc_objset_type, &zc->zc_cookie,
3091 buf, &zc->zc_nvlist_dst_size);
3094 error = xcopyout(buf,
3095 (void *)(uintptr_t)zc->zc_nvlist_dst,
3096 zc->zc_nvlist_dst_size);
3098 kmem_free(buf, bufsize);
3099 zfsvfs_rele(zfsvfs, FTAG);
3106 * zc_name name of filesystem
3112 zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
3118 if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
3119 if (!dmu_objset_userused_enabled(zfsvfs->z_os->os)) {
3121 * If userused is not enabled, it may be because the
3122 * objset needs to be closed & reopened (to grow the
3123 * objset_phys_t). Suspend/resume the fs will do that.
3126 error = zfs_suspend_fs(zfsvfs, NULL, &mode);
3128 error = zfs_resume_fs(zfsvfs,
3133 error = dmu_objset_userspace_upgrade(zfsvfs->z_os);
3134 VFS_RELE(zfsvfs->z_vfs);
3136 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
3141 error = dmu_objset_userspace_upgrade(os);
3142 dmu_objset_close(os);
3149 * We don't want to have a hard dependency
3150 * against some special symbols in sharefs
3151 * nfs, and smbsrv. Determine them if needed when
3152 * the first file system is shared.
3153 * Neither sharefs, nfs or smbsrv are unloadable modules.
3155 int (*znfsexport_fs)(void *arg);
3156 int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
3157 int (*zsmbexport_fs)(void *arg, boolean_t add_share);
3159 int zfs_nfsshare_inited;
3160 int zfs_smbshare_inited;
3162 ddi_modhandle_t nfs_mod;
3163 ddi_modhandle_t sharefs_mod;
3164 ddi_modhandle_t smbsrv_mod;
3165 kmutex_t zfs_share_lock;
3172 ASSERT(MUTEX_HELD(&zfs_share_lock));
3173 /* Both NFS and SMB shares also require sharetab support. */
3174 if (sharefs_mod == NULL && ((sharefs_mod =
3175 ddi_modopen("fs/sharefs",
3176 KRTLD_MODE_FIRST, &error)) == NULL)) {
3179 if (zshare_fs == NULL && ((zshare_fs =
3180 (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
3181 ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
3188 zfs_ioc_share(zfs_cmd_t *zc)
3193 switch (zc->zc_share.z_sharetype) {
3195 case ZFS_UNSHARE_NFS:
3196 if (zfs_nfsshare_inited == 0) {
3197 mutex_enter(&zfs_share_lock);
3198 if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
3199 KRTLD_MODE_FIRST, &error)) == NULL)) {
3200 mutex_exit(&zfs_share_lock);
3203 if (znfsexport_fs == NULL &&
3204 ((znfsexport_fs = (int (*)(void *))
3206 "nfs_export", &error)) == NULL)) {
3207 mutex_exit(&zfs_share_lock);
3210 error = zfs_init_sharefs();
3212 mutex_exit(&zfs_share_lock);
3215 zfs_nfsshare_inited = 1;
3216 mutex_exit(&zfs_share_lock);
3220 case ZFS_UNSHARE_SMB:
3221 if (zfs_smbshare_inited == 0) {
3222 mutex_enter(&zfs_share_lock);
3223 if (smbsrv_mod == NULL && ((smbsrv_mod =
3224 ddi_modopen("drv/smbsrv",
3225 KRTLD_MODE_FIRST, &error)) == NULL)) {
3226 mutex_exit(&zfs_share_lock);
3229 if (zsmbexport_fs == NULL && ((zsmbexport_fs =
3230 (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
3231 "smb_server_share", &error)) == NULL)) {
3232 mutex_exit(&zfs_share_lock);
3235 error = zfs_init_sharefs();
3237 mutex_exit(&zfs_share_lock);
3240 zfs_smbshare_inited = 1;
3241 mutex_exit(&zfs_share_lock);
3248 switch (zc->zc_share.z_sharetype) {
3250 case ZFS_UNSHARE_NFS:
3252 znfsexport_fs((void *)
3253 (uintptr_t)zc->zc_share.z_exportdata))
3257 case ZFS_UNSHARE_SMB:
3258 if (error = zsmbexport_fs((void *)
3259 (uintptr_t)zc->zc_share.z_exportdata,
3260 zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
3267 opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
3268 zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
3269 SHAREFS_ADD : SHAREFS_REMOVE;
3272 * Add or remove share from sharetab
3274 error = zshare_fs(opcode,
3275 (void *)(uintptr_t)zc->zc_share.z_sharedata,
3276 zc->zc_share.z_sharemax);
3282 ace_t full_access[] = {
3283 {(uid_t)-1, ACE_ALL_PERMS, ACE_EVERYONE, 0}
3287 * Remove all ACL files in shares dir
3290 zfs_smb_acl_purge(znode_t *dzp)
3293 zap_attribute_t zap;
3294 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3297 for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id);
3298 (error = zap_cursor_retrieve(&zc, &zap)) == 0;
3299 zap_cursor_advance(&zc)) {
3300 if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
3304 zap_cursor_fini(&zc);
3309 zfs_ioc_smb_acl(zfs_cmd_t *zc)
3313 vnode_t *resourcevp = NULL;
3322 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
3323 NO_FOLLOW, NULL, &vp)) != 0)
3326 /* Now make sure mntpnt and dataset are ZFS */
3328 if (vp->v_vfsp->vfs_fstype != zfsfstype ||
3329 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
3330 zc->zc_name) != 0)) {
3336 zfsvfs = dzp->z_zfsvfs;
3340 * Create share dir if its missing.
3342 mutex_enter(&zfsvfs->z_lock);
3343 if (zfsvfs->z_shares_dir == 0) {
3346 tx = dmu_tx_create(zfsvfs->z_os);
3347 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
3349 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
3350 error = dmu_tx_assign(tx, TXG_WAIT);
3354 error = zfs_create_share_dir(zfsvfs, tx);
3358 mutex_exit(&zfsvfs->z_lock);
3364 mutex_exit(&zfsvfs->z_lock);
3366 ASSERT(zfsvfs->z_shares_dir);
3367 if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &sharedir)) != 0) {
3373 switch (zc->zc_cookie) {
3374 case ZFS_SMB_ACL_ADD:
3375 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
3376 vattr.va_type = VREG;
3377 vattr.va_mode = S_IFREG|0777;
3381 vsec.vsa_mask = VSA_ACE;
3382 vsec.vsa_aclentp = &full_access;
3383 vsec.vsa_aclentsz = sizeof (full_access);
3384 vsec.vsa_aclcnt = 1;
3386 error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
3387 &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
3389 VN_RELE(resourcevp);
3392 case ZFS_SMB_ACL_REMOVE:
3393 error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
3397 case ZFS_SMB_ACL_RENAME:
3398 if ((error = get_nvlist(zc->zc_nvlist_src,
3399 zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
3404 if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
3405 nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
3408 VN_RELE(ZTOV(sharedir));
3412 error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
3414 nvlist_free(nvlist);
3417 case ZFS_SMB_ACL_PURGE:
3418 error = zfs_smb_acl_purge(sharedir);
3427 VN_RELE(ZTOV(sharedir));
3435 * pool create, destroy, and export don't log the history as part of
3436 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
3437 * do the logging of those commands.
3439 static zfs_ioc_vec_t zfs_ioc_vec[] = {
3440 { zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3442 { zfs_ioc_pool_destroy, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3444 { zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3446 { zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3448 { zfs_ioc_pool_configs, zfs_secpolicy_none, NO_NAME, B_FALSE,
3450 { zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE,
3452 { zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE,
3454 { zfs_ioc_pool_scrub, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3456 { zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE,
3458 { zfs_ioc_pool_upgrade, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3460 { zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3462 { zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3464 { zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3466 { zfs_ioc_vdev_set_state, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3468 { zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3470 { zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3472 { zfs_ioc_vdev_setpath, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3474 { zfs_ioc_vdev_setfru, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3476 { zfs_ioc_objset_stats, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
3478 { zfs_ioc_objset_zplprops, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
3480 { zfs_ioc_dataset_list_next, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
3482 { zfs_ioc_snapshot_list_next, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
3484 { zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE, B_TRUE },
3485 { zfs_ioc_create_minor, zfs_secpolicy_minor, DATASET_NAME, B_FALSE,
3487 { zfs_ioc_remove_minor, zfs_secpolicy_minor, DATASET_NAME, B_FALSE,
3489 { zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE, B_TRUE },
3490 { zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE,
3492 { zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE,
3494 { zfs_ioc_rename, zfs_secpolicy_rename, DATASET_NAME, B_TRUE, B_TRUE },
3495 { zfs_ioc_recv, zfs_secpolicy_receive, DATASET_NAME, B_TRUE, B_TRUE },
3496 { zfs_ioc_send, zfs_secpolicy_send, DATASET_NAME, B_TRUE, B_FALSE },
3497 { zfs_ioc_inject_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE,
3499 { zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE,
3501 { zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE,
3503 { zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE,
3505 { zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE, B_FALSE },
3506 { zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE,
3508 { zfs_ioc_destroy_snaps, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE,
3510 { zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE,
3512 { zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE,
3514 { zfs_ioc_obj_to_path, zfs_secpolicy_config, NO_NAME, B_FALSE,
3516 { zfs_ioc_pool_set_props, zfs_secpolicy_config, POOL_NAME, B_TRUE,
3518 { zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE,
3520 { zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE,
3522 { zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
3524 { zfs_ioc_iscsi_perm_check, zfs_secpolicy_iscsi, DATASET_NAME, B_FALSE,
3526 { zfs_ioc_share, zfs_secpolicy_share, DATASET_NAME, B_FALSE, B_FALSE },
3527 { zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE,
3529 { zfs_ioc_smb_acl, zfs_secpolicy_smb_acl, DATASET_NAME, B_FALSE,
3531 { zfs_ioc_userspace_one, zfs_secpolicy_userspace_one,
3532 DATASET_NAME, B_FALSE, B_FALSE },
3533 { zfs_ioc_userspace_many, zfs_secpolicy_userspace_many,
3534 DATASET_NAME, B_FALSE, B_FALSE },
3535 { zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
3536 DATASET_NAME, B_FALSE, B_TRUE },
3540 pool_status_check(const char *name, zfs_ioc_namecheck_t type)
3545 ASSERT(type == POOL_NAME || type == DATASET_NAME);
3547 error = spa_open(name, &spa, FTAG);
3549 if (spa_suspended(spa))
3551 spa_close(spa, FTAG);
3557 zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
3563 if (getminor(dev) != 0)
3564 return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
3566 vec = cmd - ZFS_IOC;
3567 ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
3569 if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
3572 zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
3574 error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
3577 error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
3580 * Ensure that all pool/dataset names are valid before we pass down to
3584 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
3585 zc->zc_iflags = flag & FKIOCTL;
3586 switch (zfs_ioc_vec[vec].zvec_namecheck) {
3588 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
3590 if (zfs_ioc_vec[vec].zvec_pool_check)
3591 error = pool_status_check(zc->zc_name,
3592 zfs_ioc_vec[vec].zvec_namecheck);
3596 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
3598 if (zfs_ioc_vec[vec].zvec_pool_check)
3599 error = pool_status_check(zc->zc_name,
3600 zfs_ioc_vec[vec].zvec_namecheck);
3609 error = zfs_ioc_vec[vec].zvec_func(zc);
3611 rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
3614 if (zfs_ioc_vec[vec].zvec_his_log)
3615 zfs_log_history(zc);
3618 kmem_free(zc, sizeof (zfs_cmd_t));
3623 zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
3625 if (cmd != DDI_ATTACH)
3626 return (DDI_FAILURE);
3628 if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
3629 DDI_PSEUDO, 0) == DDI_FAILURE)
3630 return (DDI_FAILURE);
3634 ddi_report_dev(dip);
3636 return (DDI_SUCCESS);
3640 zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3642 if (spa_busy() || zfs_busy() || zvol_busy())
3643 return (DDI_FAILURE);
3645 if (cmd != DDI_DETACH)
3646 return (DDI_FAILURE);
3650 ddi_prop_remove_all(dip);
3651 ddi_remove_minor_node(dip, NULL);
3653 return (DDI_SUCCESS);
3658 zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
3661 case DDI_INFO_DEVT2DEVINFO:
3663 return (DDI_SUCCESS);
3665 case DDI_INFO_DEVT2INSTANCE:
3666 *result = (void *)0;
3667 return (DDI_SUCCESS);
3670 return (DDI_FAILURE);
3674 * OK, so this is a little weird.
3676 * /dev/zfs is the control node, i.e. minor 0.
3677 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
3679 * /dev/zfs has basically nothing to do except serve up ioctls,
3680 * so most of the standard driver entry points are in zvol.c.
3682 static struct cb_ops zfs_cb_ops = {
3683 zvol_open, /* open */
3684 zvol_close, /* close */
3685 zvol_strategy, /* strategy */
3687 zvol_dump, /* dump */
3688 zvol_read, /* read */
3689 zvol_write, /* write */
3690 zfsdev_ioctl, /* ioctl */
3694 nochpoll, /* poll */
3695 ddi_prop_op, /* prop_op */
3696 NULL, /* streamtab */
3697 D_NEW | D_MP | D_64BIT, /* Driver compatibility flag */
3698 CB_REV, /* version */
3699 nodev, /* async read */
3700 nodev, /* async write */
3703 static struct dev_ops zfs_dev_ops = {
3704 DEVO_REV, /* version */
3706 zfs_info, /* info */
3707 nulldev, /* identify */
3708 nulldev, /* probe */
3709 zfs_attach, /* attach */
3710 zfs_detach, /* detach */
3712 &zfs_cb_ops, /* driver operations */
3713 NULL, /* no bus operations */
3715 ddi_quiesce_not_needed, /* quiesce */
3718 static struct modldrv zfs_modldrv = {
3724 static struct modlinkage modlinkage = {
3726 (void *)&zfs_modlfs,
3727 (void *)&zfs_modldrv,
3732 uint_t zfs_fsyncer_key;
3733 extern uint_t rrw_tsd_key;
3740 spa_init(FREAD | FWRITE);
3744 if ((error = mod_install(&modlinkage)) != 0) {
3751 tsd_create(&zfs_fsyncer_key, NULL);
3752 tsd_create(&rrw_tsd_key, NULL);
3754 error = ldi_ident_from_mod(&modlinkage, &zfs_li);
3756 mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
3766 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
3769 if ((error = mod_remove(&modlinkage)) != 0)
3775 if (zfs_nfsshare_inited)
3776 (void) ddi_modclose(nfs_mod);
3777 if (zfs_smbshare_inited)
3778 (void) ddi_modclose(smbsrv_mod);
3779 if (zfs_nfsshare_inited || zfs_smbshare_inited)
3780 (void) ddi_modclose(sharefs_mod);
3782 tsd_destroy(&zfs_fsyncer_key);
3783 ldi_ident_release(zfs_li);
3785 mutex_destroy(&zfs_share_lock);
3791 _info(struct modinfo *modinfop)
3793 return (mod_info(&modlinkage, modinfop));