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 2008 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/systm.h>
30 #include <sys/kernel.h>
32 #include <sys/malloc.h>
33 #include <sys/mutex.h>
35 #include <sys/errno.h>
41 #include <sys/cmn_err.h>
43 #include <sys/zfs_ioctl.h>
44 #include <sys/zfs_znode.h>
47 #include <sys/spa_impl.h>
49 #include <sys/vdev_impl.h>
51 #include <sys/dsl_dir.h>
52 #include <sys/dsl_dataset.h>
53 #include <sys/dsl_prop.h>
54 #include <sys/dsl_deleg.h>
55 #include <sys/dmu_objset.h>
56 #include <sys/sunddi.h>
57 #include <sys/policy.h>
59 #include <sys/nvpair.h>
60 #include <sys/mount.h>
61 #include <sys/taskqueue.h>
63 #include <sys/varargs.h>
64 #include <sys/fs/zfs.h>
65 #include <sys/zfs_ctldir.h>
66 #include <sys/zfs_dir.h>
68 #include <sys/dmu_objset.h>
70 #include "zfs_namecheck.h"
72 #include "zfs_deleg.h"
74 CTASSERT(sizeof(zfs_cmd_t) <= PAGE_SIZE);
76 static struct cdev *zfsdev;
78 extern void zfs_init(void);
79 extern void zfs_fini(void);
81 typedef int zfs_ioc_func_t(zfs_cmd_t *);
82 typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
84 typedef struct zfs_ioc_vec {
85 zfs_ioc_func_t *zvec_func;
86 zfs_secpolicy_func_t *zvec_secpolicy;
92 boolean_t zvec_his_log;
95 static void clear_props(char *dataset, nvlist_t *props);
96 static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
98 int zfs_set_prop_nvlist(const char *, nvlist_t *);
100 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
102 __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
109 * Get rid of annoying "../common/" prefix to filename.
111 newfile = strrchr(file, '/');
112 if (newfile != NULL) {
113 newfile = newfile + 1; /* Get rid of leading / */
119 (void) vsnprintf(buf, sizeof (buf), fmt, adx);
123 * To get this data, use the zfs-dprintf probe as so:
124 * dtrace -q -n 'zfs-dprintf \
125 * /stringof(arg0) == "dbuf.c"/ \
126 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
128 * arg1 = function name
132 DTRACE_PROBE4(zfs__dprintf,
133 char *, newfile, char *, func, int, line, char *, buf);
137 history_str_free(char *buf)
139 kmem_free(buf, HIS_MAX_RECORD_LEN);
143 history_str_get(zfs_cmd_t *zc)
147 if (zc->zc_history == 0)
150 buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
151 if (copyinstr((void *)(uintptr_t)zc->zc_history,
152 buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
153 history_str_free(buf);
157 buf[HIS_MAX_RECORD_LEN -1] = '\0';
163 * Check to see if the named dataset is currently defined as bootable
166 zfs_is_bootfs(const char *name)
169 boolean_t ret = B_FALSE;
171 if (spa_open(name, &spa, FTAG) == 0) {
172 if (spa->spa_bootfs) {
175 if (dmu_objset_open(name, DMU_OST_ZFS,
176 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
177 ret = (dmu_objset_id(os) == spa->spa_bootfs);
178 dmu_objset_close(os);
181 spa_close(spa, FTAG);
187 * zfs_earlier_version
189 * Return non-zero if the spa version is less than requested version.
192 zfs_earlier_version(const char *name, int version)
196 if (spa_open(name, &spa, FTAG) == 0) {
197 if (spa_version(spa) < version) {
198 spa_close(spa, FTAG);
201 spa_close(spa, FTAG);
207 * zpl_earlier_version
209 * Return TRUE if the ZPL version is less than requested version.
212 zpl_earlier_version(const char *name, int version)
215 boolean_t rc = B_TRUE;
217 if (dmu_objset_open(name, DMU_OST_ANY,
218 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
221 if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
222 rc = zplversion < version;
223 dmu_objset_close(os);
229 zfs_log_history(zfs_cmd_t *zc)
234 if ((buf = history_str_get(zc)) == NULL)
237 if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
238 if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
239 (void) spa_history_log(spa, buf, LOG_CMD_NORMAL);
240 spa_close(spa, FTAG);
242 history_str_free(buf);
246 * Policy for top-level read operations (list pools). Requires no privileges,
247 * and can be used in the local zone, as there is no associated dataset.
251 zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
257 * Policy for dataset read operations (list children, get statistics). Requires
258 * no privileges, but must be visible in the local zone.
262 zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
264 if (INGLOBALZONE(curthread) ||
265 zone_dataset_visible(zc->zc_name, NULL))
272 zfs_dozonecheck(const char *dataset, cred_t *cr)
278 * The dataset must be visible by this zone -- check this first
279 * so they don't see EPERM on something they shouldn't know about.
281 if (!INGLOBALZONE(curthread) &&
282 !zone_dataset_visible(dataset, &writable))
285 if (dsl_prop_get_integer(dataset, "jailed", &zoned, NULL))
288 if (INGLOBALZONE(curthread)) {
290 * If the fs is zoned, only root can access it from the
293 if (secpolicy_zfs(cr) && zoned)
297 * If we are in a local zone, the 'zoned' property must be set.
302 /* must be writable by this zone */
310 zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
314 error = zfs_dozonecheck(name, cr);
316 error = secpolicy_zfs(cr);
318 error = dsl_deleg_access(name, perm, cr);
324 zfs_secpolicy_setprop(const char *name, zfs_prop_t prop, cred_t *cr)
327 * Check permissions for special properties.
332 * Disallow setting of 'zoned' from within a local zone.
334 if (!INGLOBALZONE(curthread))
339 if (!INGLOBALZONE(curthread)) {
341 char setpoint[MAXNAMELEN];
343 * Unprivileged users are allowed to modify the
344 * quota on things *under* (ie. contained by)
345 * the thing they own.
347 if (dsl_prop_get_integer(name, "zoned", &zoned,
350 if (!zoned || strlen(name) <= strlen(setpoint))
356 return (zfs_secpolicy_write_perms(name, zfs_prop_to_name(prop), cr));
360 zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
364 error = zfs_dozonecheck(zc->zc_name, cr);
369 * permission to set permissions will be evaluated later in
370 * dsl_deleg_can_allow()
376 zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
379 error = zfs_secpolicy_write_perms(zc->zc_name,
380 ZFS_DELEG_PERM_ROLLBACK, cr);
382 error = zfs_secpolicy_write_perms(zc->zc_name,
383 ZFS_DELEG_PERM_MOUNT, cr);
388 zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
390 return (zfs_secpolicy_write_perms(zc->zc_name,
391 ZFS_DELEG_PERM_SEND, cr));
395 zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
397 if (!INGLOBALZONE(curthread))
400 if (secpolicy_nfs(cr) == 0) {
406 if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
407 NO_FOLLOW, NULL, &vp)) != 0)
410 /* Now make sure mntpnt and dataset are ZFS */
412 if (strcmp(vp->v_vfsp->mnt_stat.f_fstypename, "zfs") != 0 ||
413 (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
414 zc->zc_name) != 0)) {
420 return (dsl_deleg_access(zc->zc_name,
421 ZFS_DELEG_PERM_SHARE, cr));
426 zfs_get_parent(const char *datasetname, char *parent, int parentsize)
431 * Remove the @bla or /bla from the end of the name to get the parent.
433 (void) strncpy(parent, datasetname, parentsize);
434 cp = strrchr(parent, '@');
438 cp = strrchr(parent, '/');
448 zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
452 if ((error = zfs_secpolicy_write_perms(name,
453 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
456 return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
460 zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
462 return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
466 * Must have sys_config privilege to check the iscsi permission
470 zfs_secpolicy_iscsi(zfs_cmd_t *zc, cred_t *cr)
472 return (secpolicy_zfs(cr));
476 zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
478 char parentname[MAXNAMELEN];
481 if ((error = zfs_secpolicy_write_perms(from,
482 ZFS_DELEG_PERM_RENAME, cr)) != 0)
485 if ((error = zfs_secpolicy_write_perms(from,
486 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
489 if ((error = zfs_get_parent(to, parentname,
490 sizeof (parentname))) != 0)
493 if ((error = zfs_secpolicy_write_perms(parentname,
494 ZFS_DELEG_PERM_CREATE, cr)) != 0)
497 if ((error = zfs_secpolicy_write_perms(parentname,
498 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
505 zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
507 return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
511 zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
513 char parentname[MAXNAMELEN];
517 error = zfs_secpolicy_write_perms(zc->zc_name,
518 ZFS_DELEG_PERM_PROMOTE, cr);
522 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
523 DS_MODE_USER | DS_MODE_READONLY, &clone);
526 dsl_dataset_t *pclone = NULL;
528 dd = clone->os->os_dsl_dataset->ds_dir;
530 rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
531 error = dsl_dataset_hold_obj(dd->dd_pool,
532 dd->dd_phys->dd_origin_obj, FTAG, &pclone);
533 rw_exit(&dd->dd_pool->dp_config_rwlock);
535 dmu_objset_close(clone);
539 error = zfs_secpolicy_write_perms(zc->zc_name,
540 ZFS_DELEG_PERM_MOUNT, cr);
542 dsl_dataset_name(pclone, parentname);
543 dmu_objset_close(clone);
544 dsl_dataset_rele(pclone, FTAG);
546 error = zfs_secpolicy_write_perms(parentname,
547 ZFS_DELEG_PERM_PROMOTE, cr);
553 zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
557 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
558 ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
561 if ((error = zfs_secpolicy_write_perms(zc->zc_name,
562 ZFS_DELEG_PERM_MOUNT, cr)) != 0)
565 return (zfs_secpolicy_write_perms(zc->zc_name,
566 ZFS_DELEG_PERM_CREATE, cr));
570 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
574 if ((error = zfs_secpolicy_write_perms(name,
575 ZFS_DELEG_PERM_SNAPSHOT, cr)) != 0)
578 error = zfs_secpolicy_write_perms(name,
579 ZFS_DELEG_PERM_MOUNT, cr);
585 zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
588 return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
592 zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
594 char parentname[MAXNAMELEN];
597 if ((error = zfs_get_parent(zc->zc_name, parentname,
598 sizeof (parentname))) != 0)
601 if (zc->zc_value[0] != '\0') {
602 if ((error = zfs_secpolicy_write_perms(zc->zc_value,
603 ZFS_DELEG_PERM_CLONE, cr)) != 0)
607 if ((error = zfs_secpolicy_write_perms(parentname,
608 ZFS_DELEG_PERM_CREATE, cr)) != 0)
611 error = zfs_secpolicy_write_perms(parentname,
612 ZFS_DELEG_PERM_MOUNT, cr);
618 zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
622 error = secpolicy_fs_unmount(cr, NULL);
624 error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
630 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
631 * SYS_CONFIG privilege, which is not available in a local zone.
635 zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
637 if (secpolicy_sys_config(cr, B_FALSE) != 0)
644 * Just like zfs_secpolicy_config, except that we will check for
645 * mount permission on the dataset for permission to create/remove
649 zfs_secpolicy_minor(zfs_cmd_t *zc, cred_t *cr)
651 if (secpolicy_sys_config(cr, B_FALSE) != 0) {
652 return (dsl_deleg_access(zc->zc_name,
653 ZFS_DELEG_PERM_MOUNT, cr));
660 * Policy for fault injection. Requires all privileges.
664 zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
666 return (secpolicy_zinject(cr));
670 zfs_secpolicy_inherit(zfs_cmd_t *zc, cred_t *cr)
672 zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
674 if (prop == ZPROP_INVAL) {
675 if (!zfs_prop_user(zc->zc_value))
677 return (zfs_secpolicy_write_perms(zc->zc_name,
678 ZFS_DELEG_PERM_USERPROP, cr));
680 if (!zfs_prop_inheritable(prop))
682 return (zfs_secpolicy_setprop(zc->zc_name, prop, cr));
687 * Policy for dataset backup operations (sendbackup).
688 * Requires SYS_MOUNT privilege, and must be writable in the local zone.
691 zfs_secpolicy_operator(const char *dataset, cred_t *cr)
695 if (!INGLOBALZONE(curthread) && !zone_dataset_visible(dataset, &writable))
697 if (secpolicy_zfs(cr) != 0 && !groupmember(GID_OPERATOR, cr))
703 * Returns the nvlist as specified by the user in the zfs_cmd_t.
706 get_nvlist(uint64_t nvl, uint64_t size, nvlist_t **nvp)
710 nvlist_t *list = NULL;
713 * Read in and unpack the user-supplied nvlist.
718 packed = kmem_alloc(size, KM_SLEEP);
720 if ((error = xcopyin((void *)(uintptr_t)nvl, packed, size)) != 0) {
721 kmem_free(packed, size);
725 if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
726 kmem_free(packed, size);
730 kmem_free(packed, size);
737 put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
743 VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
745 if (size > zc->zc_nvlist_dst_size) {
747 * Solaris returns ENOMEM here, because even if an error is
748 * returned from an ioctl(2), new zc_nvlist_dst_size will be
749 * passed to the userland. This is not the case for FreeBSD.
750 * We need to return 0, so the kernel will copy the
751 * zc_nvlist_dst_size back and the userland can discover that a
752 * bigger buffer is needed.
756 packed = kmem_alloc(size, KM_SLEEP);
757 VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
759 error = xcopyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
761 kmem_free(packed, size);
764 zc->zc_nvlist_dst_size = size;
769 zfs_ioc_pool_create(zfs_cmd_t *zc)
772 nvlist_t *config, *props = NULL;
773 nvlist_t *rootprops = NULL;
774 nvlist_t *zplprops = NULL;
777 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
781 if (zc->zc_nvlist_src_size != 0 && (error =
782 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size, &props))) {
788 nvlist_t *nvl = NULL;
789 uint64_t version = SPA_VERSION;
791 (void) nvlist_lookup_uint64(props,
792 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
793 if (version < SPA_VERSION_INITIAL || version > SPA_VERSION) {
797 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
799 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
805 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
807 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
808 error = zfs_fill_zplprops_root(version, rootprops,
814 buf = history_str_get(zc);
816 error = spa_create(zc->zc_name, config, props, buf, zplprops);
819 * Set the remaining root properties
822 (error = zfs_set_prop_nvlist(zc->zc_name, rootprops)) != 0)
823 (void) spa_destroy(zc->zc_name);
826 history_str_free(buf);
829 nvlist_free(rootprops);
830 nvlist_free(zplprops);
838 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
842 error = spa_destroy(zc->zc_name);
847 zfs_ioc_pool_import(zfs_cmd_t *zc)
850 nvlist_t *config, *props = NULL;
853 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
857 if (zc->zc_nvlist_src_size != 0 && (error =
858 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size, &props))) {
863 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
866 else if (zc->zc_cookie)
867 error = spa_import_faulted(zc->zc_name, config,
870 error = spa_import(zc->zc_name, config, props);
881 zfs_ioc_pool_export(zfs_cmd_t *zc)
884 boolean_t force = (boolean_t)zc->zc_cookie;
887 error = spa_export(zc->zc_name, NULL, force);
892 zfs_ioc_pool_configs(zfs_cmd_t *zc)
897 if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
900 error = put_nvlist(zc, configs);
902 nvlist_free(configs);
908 zfs_ioc_pool_stats(zfs_cmd_t *zc)
914 error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
915 sizeof (zc->zc_value));
917 if (config != NULL) {
918 ret = put_nvlist(zc, config);
922 * The config may be present even if 'error' is non-zero.
923 * In this case we return success, and preserve the real errno
926 zc->zc_cookie = error;
935 * Try to import the given pool, returning pool stats as appropriate so that
936 * user land knows which devices are available and overall pool health.
939 zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
941 nvlist_t *tryconfig, *config;
944 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
948 config = spa_tryimport(tryconfig);
950 nvlist_free(tryconfig);
955 error = put_nvlist(zc, config);
962 zfs_ioc_pool_scrub(zfs_cmd_t *zc)
967 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
970 error = spa_scrub(spa, zc->zc_cookie);
972 spa_close(spa, FTAG);
978 zfs_ioc_pool_freeze(zfs_cmd_t *zc)
983 error = spa_open(zc->zc_name, &spa, FTAG);
986 spa_close(spa, FTAG);
992 zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
997 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1000 if (zc->zc_cookie < spa_version(spa) || zc->zc_cookie > SPA_VERSION) {
1001 spa_close(spa, FTAG);
1005 spa_upgrade(spa, zc->zc_cookie);
1006 spa_close(spa, FTAG);
1012 zfs_ioc_pool_get_history(zfs_cmd_t *zc)
1019 if ((size = zc->zc_history_len) == 0)
1022 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1025 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
1026 spa_close(spa, FTAG);
1030 hist_buf = kmem_alloc(size, KM_SLEEP);
1031 if ((error = spa_history_get(spa, &zc->zc_history_offset,
1032 &zc->zc_history_len, hist_buf)) == 0) {
1033 error = xcopyout(hist_buf,
1034 (char *)(uintptr_t)zc->zc_history,
1035 zc->zc_history_len);
1038 spa_close(spa, FTAG);
1039 kmem_free(hist_buf, size);
1044 zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
1048 if (error = dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value))
1055 zfs_ioc_obj_to_path(zfs_cmd_t *zc)
1060 if ((error = dmu_objset_open(zc->zc_name, DMU_OST_ZFS,
1061 DS_MODE_USER | DS_MODE_READONLY, &osp)) != 0)
1063 error = zfs_obj_to_path(osp, zc->zc_obj, zc->zc_value,
1064 sizeof (zc->zc_value));
1065 dmu_objset_close(osp);
1071 zfs_ioc_vdev_add(zfs_cmd_t *zc)
1075 nvlist_t *config, **l2cache, **spares;
1076 uint_t nl2cache = 0, nspares = 0;
1078 error = spa_open(zc->zc_name, &spa, FTAG);
1082 error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1084 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
1085 &l2cache, &nl2cache);
1087 (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
1091 * A root pool with concatenated devices is not supported.
1092 * Thus, can not add a device to a root pool.
1094 * Intent log device can not be added to a rootpool because
1095 * during mountroot, zil is replayed, a seperated log device
1096 * can not be accessed during the mountroot time.
1098 * l2cache and spare devices are ok to be added to a rootpool.
1100 if (spa->spa_bootfs != 0 && nl2cache == 0 && nspares == 0) {
1101 spa_close(spa, FTAG);
1106 error = spa_vdev_add(spa, config);
1107 nvlist_free(config);
1109 spa_close(spa, FTAG);
1114 zfs_ioc_vdev_remove(zfs_cmd_t *zc)
1119 error = spa_open(zc->zc_name, &spa, FTAG);
1122 error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
1123 spa_close(spa, FTAG);
1128 zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
1132 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1134 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1136 switch (zc->zc_cookie) {
1137 case VDEV_STATE_ONLINE:
1138 error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
1141 case VDEV_STATE_OFFLINE:
1142 error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
1145 case VDEV_STATE_FAULTED:
1146 error = vdev_fault(spa, zc->zc_guid);
1149 case VDEV_STATE_DEGRADED:
1150 error = vdev_degrade(spa, zc->zc_guid);
1156 zc->zc_cookie = newstate;
1157 spa_close(spa, FTAG);
1162 zfs_ioc_vdev_attach(zfs_cmd_t *zc)
1165 int replacing = zc->zc_cookie;
1169 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1172 if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1174 error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
1175 nvlist_free(config);
1178 spa_close(spa, FTAG);
1183 zfs_ioc_vdev_detach(zfs_cmd_t *zc)
1188 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1191 error = spa_vdev_detach(spa, zc->zc_guid, B_FALSE);
1193 spa_close(spa, FTAG);
1198 zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
1201 char *path = zc->zc_value;
1202 uint64_t guid = zc->zc_guid;
1205 error = spa_open(zc->zc_name, &spa, FTAG);
1209 error = spa_vdev_setpath(spa, guid, path);
1210 spa_close(spa, FTAG);
1216 * zc_name name of filesystem
1217 * zc_nvlist_dst_size size of buffer for property nvlist
1220 * zc_objset_stats stats
1221 * zc_nvlist_dst property nvlist
1222 * zc_nvlist_dst_size size of property nvlist
1225 zfs_ioc_objset_stats(zfs_cmd_t *zc)
1227 objset_t *os = NULL;
1231 if (error = dmu_objset_open(zc->zc_name,
1232 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os))
1235 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
1237 if (zc->zc_nvlist_dst != 0 &&
1238 (error = dsl_prop_get_all(os, &nv, FALSE)) == 0) {
1239 dmu_objset_stats(os, nv);
1241 * NB: zvol_get_stats() will read the objset contents,
1242 * which we aren't supposed to do with a
1243 * DS_MODE_USER hold, because it could be
1244 * inconsistent. So this is a bit of a workaround...
1246 if (!zc->zc_objset_stats.dds_inconsistent) {
1247 if (dmu_objset_type(os) == DMU_OST_ZVOL)
1248 VERIFY(zvol_get_stats(os, nv) == 0);
1250 error = put_nvlist(zc, nv);
1254 dmu_objset_close(os);
1255 if (error == ENOMEM)
1261 nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
1267 * zfs_get_zplprop() will either find a value or give us
1268 * the default value (if there is one).
1270 if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
1272 VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
1278 * zc_name name of filesystem
1279 * zc_nvlist_dst_size size of buffer for zpl property nvlist
1282 * zc_nvlist_dst zpl property nvlist
1283 * zc_nvlist_dst_size size of zpl property nvlist
1286 zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
1291 if (err = dmu_objset_open(zc->zc_name,
1292 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os))
1295 dmu_objset_fast_stat(os, &zc->zc_objset_stats);
1298 * NB: nvl_add_zplprop() will read the objset contents,
1299 * which we aren't supposed to do with a DS_MODE_USER
1300 * hold, because it could be inconsistent.
1302 if (zc->zc_nvlist_dst != 0 &&
1303 !zc->zc_objset_stats.dds_inconsistent &&
1304 dmu_objset_type(os) == DMU_OST_ZFS) {
1307 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1308 if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
1309 (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
1310 (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
1311 (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
1312 err = put_nvlist(zc, nv);
1317 dmu_objset_close(os);
1323 * zc_name name of filesystem
1324 * zc_cookie zap cursor
1325 * zc_nvlist_dst_size size of buffer for property nvlist
1328 * zc_name name of next filesystem
1329 * zc_objset_stats stats
1330 * zc_nvlist_dst property nvlist
1331 * zc_nvlist_dst_size size of property nvlist
1334 zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
1340 if (error = dmu_objset_open(zc->zc_name,
1341 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os)) {
1342 if (error == ENOENT)
1347 p = strrchr(zc->zc_name, '/');
1348 if (p == NULL || p[1] != '\0')
1349 (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
1350 p = zc->zc_name + strlen(zc->zc_name);
1353 error = dmu_dir_list_next(os,
1354 sizeof (zc->zc_name) - (p - zc->zc_name), p,
1355 NULL, &zc->zc_cookie);
1356 if (error == ENOENT)
1358 } while (error == 0 && !INGLOBALZONE(curthread) &&
1359 !zone_dataset_visible(zc->zc_name, NULL));
1360 dmu_objset_close(os);
1363 * If it's a hidden dataset (ie. with a '$' in its name), don't
1364 * try to get stats for it. Userland will skip over it.
1366 if (error == 0 && strchr(zc->zc_name, '$') == NULL)
1367 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
1374 * zc_name name of filesystem
1375 * zc_cookie zap cursor
1376 * zc_nvlist_dst_size size of buffer for property nvlist
1379 * zc_name name of next snapshot
1380 * zc_objset_stats stats
1381 * zc_nvlist_dst property nvlist
1382 * zc_nvlist_dst_size size of property nvlist
1385 zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
1390 error = dmu_objset_open(zc->zc_name,
1391 DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os);
1393 return (error == ENOENT ? ESRCH : error);
1396 * A dataset name of maximum length cannot have any snapshots,
1397 * so exit immediately.
1399 if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
1400 dmu_objset_close(os);
1404 error = dmu_snapshot_list_next(os,
1405 sizeof (zc->zc_name) - strlen(zc->zc_name),
1406 zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie, NULL);
1407 dmu_objset_close(os);
1409 error = zfs_ioc_objset_stats(zc); /* fill in the stats */
1410 else if (error == ENOENT)
1413 /* if we failed, undo the @ that we tacked on to zc_name */
1415 *strchr(zc->zc_name, '@') = '\0';
1420 zfs_set_prop_nvlist(const char *name, nvlist_t *nvl)
1428 * First validate permission to set all of the properties
1431 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
1432 const char *propname = nvpair_name(elem);
1433 zfs_prop_t prop = zfs_name_to_prop(propname);
1435 if (prop == ZPROP_INVAL) {
1437 * If this is a user-defined property, it must be a
1438 * string, and there is no further validation to do.
1440 if (!zfs_prop_user(propname) ||
1441 nvpair_type(elem) != DATA_TYPE_STRING)
1444 if (error = zfs_secpolicy_write_perms(name,
1445 ZFS_DELEG_PERM_USERPROP, CRED()))
1450 if ((error = zfs_secpolicy_setprop(name, prop, CRED())) != 0)
1454 * Check that this value is valid for this pool version
1457 case ZFS_PROP_COMPRESSION:
1459 * If the user specified gzip compression, make sure
1460 * the SPA supports it. We ignore any errors here since
1461 * we'll catch them later.
1463 if (nvpair_type(elem) == DATA_TYPE_UINT64 &&
1464 nvpair_value_uint64(elem, &intval) == 0) {
1465 if (intval >= ZIO_COMPRESS_GZIP_1 &&
1466 intval <= ZIO_COMPRESS_GZIP_9 &&
1467 zfs_earlier_version(name,
1468 SPA_VERSION_GZIP_COMPRESSION))
1472 * If this is a bootable dataset then
1473 * verify that the compression algorithm
1474 * is supported for booting. We must return
1475 * something other than ENOTSUP since it
1476 * implies a downrev pool version.
1478 if (zfs_is_bootfs(name) &&
1479 !BOOTFS_COMPRESS_VALID(intval))
1484 case ZFS_PROP_COPIES:
1485 if (zfs_earlier_version(name,
1486 SPA_VERSION_DITTO_BLOCKS))
1490 case ZFS_PROP_SHARESMB:
1491 if (zpl_earlier_version(name, ZPL_VERSION_FUID))
1498 while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
1499 const char *propname = nvpair_name(elem);
1500 zfs_prop_t prop = zfs_name_to_prop(propname);
1502 if (prop == ZPROP_INVAL) {
1503 VERIFY(nvpair_value_string(elem, &strval) == 0);
1504 error = dsl_prop_set(name, propname, 1,
1505 strlen(strval) + 1, strval);
1513 case ZFS_PROP_QUOTA:
1514 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1515 (error = dsl_dir_set_quota(name, intval)) != 0)
1519 case ZFS_PROP_REFQUOTA:
1520 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1521 (error = dsl_dataset_set_quota(name, intval)) != 0)
1525 case ZFS_PROP_RESERVATION:
1526 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1527 (error = dsl_dir_set_reservation(name,
1532 case ZFS_PROP_REFRESERVATION:
1533 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1534 (error = dsl_dataset_set_reservation(name,
1539 case ZFS_PROP_VOLSIZE:
1540 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1541 (error = zvol_set_volsize(name,
1542 ddi_driver_major(zfs_dip), intval)) != 0)
1546 case ZFS_PROP_VOLBLOCKSIZE:
1547 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1548 (error = zvol_set_volblocksize(name, intval)) != 0)
1552 case ZFS_PROP_VERSION:
1553 if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
1554 (error = zfs_set_version(name, intval)) != 0)
1559 if (nvpair_type(elem) == DATA_TYPE_STRING) {
1560 if (zfs_prop_get_type(prop) !=
1563 VERIFY(nvpair_value_string(elem, &strval) == 0);
1564 if ((error = dsl_prop_set(name,
1565 nvpair_name(elem), 1, strlen(strval) + 1,
1568 } else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
1571 VERIFY(nvpair_value_uint64(elem, &intval) == 0);
1573 switch (zfs_prop_get_type(prop)) {
1574 case PROP_TYPE_NUMBER:
1576 case PROP_TYPE_STRING:
1578 case PROP_TYPE_INDEX:
1579 if (zfs_prop_index_to_string(prop,
1580 intval, &unused) != 0)
1585 "unknown property type");
1589 if ((error = dsl_prop_set(name, propname,
1590 8, 1, &intval)) != 0)
1604 * zc_name name of filesystem
1605 * zc_value name of property to inherit
1606 * zc_nvlist_src{_size} nvlist of properties to apply
1607 * zc_cookie clear existing local props?
1612 zfs_ioc_set_prop(zfs_cmd_t *zc)
1617 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1621 if (zc->zc_cookie) {
1622 nvlist_t *origprops;
1625 if (dmu_objset_open(zc->zc_name, DMU_OST_ANY,
1626 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
1627 if (dsl_prop_get_all(os, &origprops, TRUE) == 0) {
1628 clear_props(zc->zc_name, origprops);
1629 nvlist_free(origprops);
1631 dmu_objset_close(os);
1636 error = zfs_set_prop_nvlist(zc->zc_name, nvl);
1644 * zc_name name of filesystem
1645 * zc_value name of property to inherit
1650 zfs_ioc_inherit_prop(zfs_cmd_t *zc)
1652 /* the property name has been validated by zfs_secpolicy_inherit() */
1653 return (dsl_prop_set(zc->zc_name, zc->zc_value, 0, 0, NULL));
1657 zfs_ioc_pool_set_props(zfs_cmd_t *zc)
1663 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1667 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
1672 error = spa_prop_set(spa, props);
1675 spa_close(spa, FTAG);
1681 zfs_ioc_pool_get_props(zfs_cmd_t *zc)
1685 nvlist_t *nvp = NULL;
1687 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1690 error = spa_prop_get(spa, &nvp);
1692 if (error == 0 && zc->zc_nvlist_dst != 0)
1693 error = put_nvlist(zc, nvp);
1697 spa_close(spa, FTAG);
1705 zfs_ioc_iscsi_perm_check(zfs_cmd_t *zc)
1716 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1721 if ((error = nvlist_lookup_uint32(nvp,
1722 ZFS_DELEG_PERM_UID, &uid)) != 0) {
1727 if ((error = nvlist_lookup_uint32(nvp,
1728 ZFS_DELEG_PERM_GID, &gid)) != 0) {
1733 if ((error = nvlist_lookup_uint32_array(nvp, ZFS_DELEG_PERM_GROUPS,
1734 &groups, &group_cnt)) != 0) {
1738 usercred = cralloc();
1739 if ((crsetugid(usercred, uid, gid) != 0) ||
1740 (crsetgroups(usercred, group_cnt, (gid_t *)groups) != 0)) {
1746 error = dsl_deleg_access(zc->zc_name,
1747 zfs_prop_to_name(ZFS_PROP_SHAREISCSI), usercred);
1757 * zc_name name of filesystem
1758 * zc_nvlist_src{_size} nvlist of delegated permissions
1759 * zc_perm_action allow/unallow flag
1764 zfs_ioc_set_fsacl(zfs_cmd_t *zc)
1767 nvlist_t *fsaclnv = NULL;
1769 if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1774 * Verify nvlist is constructed correctly
1776 if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
1777 nvlist_free(fsaclnv);
1782 * If we don't have PRIV_SYS_MOUNT, then validate
1783 * that user is allowed to hand out each permission in
1787 error = secpolicy_zfs(CRED());
1789 if (zc->zc_perm_action == B_FALSE) {
1790 error = dsl_deleg_can_allow(zc->zc_name,
1793 error = dsl_deleg_can_unallow(zc->zc_name,
1799 error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
1801 nvlist_free(fsaclnv);
1807 * zc_name name of filesystem
1810 * zc_nvlist_src{_size} nvlist of delegated permissions
1813 zfs_ioc_get_fsacl(zfs_cmd_t *zc)
1818 if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
1819 error = put_nvlist(zc, nvp);
1828 * zc_name name of volume
1833 zfs_ioc_create_minor(zfs_cmd_t *zc)
1835 return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip)));
1840 * zc_name name of volume
1845 zfs_ioc_remove_minor(zfs_cmd_t *zc)
1847 return (zvol_remove_minor(zc->zc_name));
1851 * Search the vfs list for a specified resource. Returns a pointer to it
1852 * or NULL if no suitable entry is found. The caller of this routine
1853 * is responsible for releasing the returned vfs pointer.
1856 zfs_get_vfs(const char *resource)
1860 mtx_lock(&mountlist_mtx);
1861 TAILQ_FOREACH(vfsp, &mountlist, mnt_list) {
1862 if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
1867 mtx_unlock(&mountlist_mtx);
1873 zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
1875 zfs_creat_t *zct = arg;
1877 zfs_create_fs(os, cr, zct->zct_zplprops, tx);
1880 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
1884 * createprops list of properties requested by creator
1885 * default_zplver zpl version to use if unspecified in createprops
1886 * fuids_ok fuids allowed in this version of the spa?
1887 * os parent objset pointer (NULL if root fs)
1890 * zplprops values for the zplprops we attach to the master node object
1891 * is_ci true if requested file system will be purely case-insensitive
1893 * Determine the settings for utf8only, normalization and
1894 * casesensitivity. Specific values may have been requested by the
1895 * creator and/or we can inherit values from the parent dataset. If
1896 * the file system is of too early a vintage, a creator can not
1897 * request settings for these properties, even if the requested
1898 * setting is the default value. We don't actually want to create dsl
1899 * properties for these, so remove them from the source nvlist after
1903 zfs_fill_zplprops_impl(objset_t *os, uint64_t default_zplver,
1904 boolean_t fuids_ok, nvlist_t *createprops, nvlist_t *zplprops,
1907 uint64_t zplver = default_zplver;
1908 uint64_t sense = ZFS_PROP_UNDEFINED;
1909 uint64_t norm = ZFS_PROP_UNDEFINED;
1910 uint64_t u8 = ZFS_PROP_UNDEFINED;
1912 ASSERT(zplprops != NULL);
1915 * Pull out creator prop choices, if any.
1918 (void) nvlist_lookup_uint64(createprops,
1919 zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
1920 (void) nvlist_lookup_uint64(createprops,
1921 zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
1922 (void) nvlist_remove_all(createprops,
1923 zfs_prop_to_name(ZFS_PROP_NORMALIZE));
1924 (void) nvlist_lookup_uint64(createprops,
1925 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
1926 (void) nvlist_remove_all(createprops,
1927 zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
1928 (void) nvlist_lookup_uint64(createprops,
1929 zfs_prop_to_name(ZFS_PROP_CASE), &sense);
1930 (void) nvlist_remove_all(createprops,
1931 zfs_prop_to_name(ZFS_PROP_CASE));
1935 * If the zpl version requested is whacky or the file system
1936 * or pool is version is too "young" to support normalization
1937 * and the creator tried to set a value for one of the props,
1940 if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
1941 (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
1942 (zplver < ZPL_VERSION_NORMALIZATION &&
1943 (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
1944 sense != ZFS_PROP_UNDEFINED)))
1948 * Put the version in the zplprops
1950 VERIFY(nvlist_add_uint64(zplprops,
1951 zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
1953 if (norm == ZFS_PROP_UNDEFINED)
1954 VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
1955 VERIFY(nvlist_add_uint64(zplprops,
1956 zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
1959 * If we're normalizing, names must always be valid UTF-8 strings.
1963 if (u8 == ZFS_PROP_UNDEFINED)
1964 VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
1965 VERIFY(nvlist_add_uint64(zplprops,
1966 zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
1968 if (sense == ZFS_PROP_UNDEFINED)
1969 VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
1970 VERIFY(nvlist_add_uint64(zplprops,
1971 zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
1974 *is_ci = (sense == ZFS_CASE_INSENSITIVE);
1980 zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
1981 nvlist_t *zplprops, boolean_t *is_ci)
1983 boolean_t fuids_ok = B_TRUE;
1984 uint64_t zplver = ZPL_VERSION;
1985 objset_t *os = NULL;
1986 char parentname[MAXNAMELEN];
1990 (void) strlcpy(parentname, dataset, sizeof (parentname));
1991 cp = strrchr(parentname, '/');
1995 if (zfs_earlier_version(dataset, SPA_VERSION_FUID)) {
1996 zplver = ZPL_VERSION_FUID - 1;
2001 * Open parent object set so we can inherit zplprop values.
2003 if ((error = dmu_objset_open(parentname, DMU_OST_ANY,
2004 DS_MODE_USER | DS_MODE_READONLY, &os)) != 0)
2007 error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, createprops,
2009 dmu_objset_close(os);
2014 zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
2015 nvlist_t *zplprops, boolean_t *is_ci)
2017 boolean_t fuids_ok = B_TRUE;
2018 uint64_t zplver = ZPL_VERSION;
2021 if (spa_vers < SPA_VERSION_FUID) {
2022 zplver = ZPL_VERSION_FUID - 1;
2026 error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, createprops,
2033 * zc_objset_type type of objset to create (fs vs zvol)
2034 * zc_name name of new objset
2035 * zc_value name of snapshot to clone from (may be empty)
2036 * zc_nvlist_src{_size} nvlist of properties to apply
2041 zfs_ioc_create(zfs_cmd_t *zc)
2046 nvlist_t *nvprops = NULL;
2047 void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
2048 dmu_objset_type_t type = zc->zc_objset_type;
2053 cbfunc = zfs_create_cb;
2057 cbfunc = zvol_create_cb;
2064 if (strchr(zc->zc_name, '@') ||
2065 strchr(zc->zc_name, '%'))
2068 if (zc->zc_nvlist_src != 0 &&
2069 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2073 zct.zct_zplprops = NULL;
2074 zct.zct_props = nvprops;
2076 if (zc->zc_value[0] != '\0') {
2078 * We're creating a clone of an existing snapshot.
2080 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
2081 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
2082 nvlist_free(nvprops);
2086 error = dmu_objset_open(zc->zc_value, type,
2087 DS_MODE_USER | DS_MODE_READONLY, &clone);
2089 nvlist_free(nvprops);
2093 error = dmu_objset_create(zc->zc_name, type, clone, 0,
2096 dmu_objset_close(clone);
2097 nvlist_free(nvprops);
2100 dmu_objset_close(clone);
2102 boolean_t is_insensitive = B_FALSE;
2104 if (cbfunc == NULL) {
2105 nvlist_free(nvprops);
2109 if (type == DMU_OST_ZVOL) {
2110 uint64_t volsize, volblocksize;
2112 if (nvprops == NULL ||
2113 nvlist_lookup_uint64(nvprops,
2114 zfs_prop_to_name(ZFS_PROP_VOLSIZE),
2116 nvlist_free(nvprops);
2120 if ((error = nvlist_lookup_uint64(nvprops,
2121 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
2122 &volblocksize)) != 0 && error != ENOENT) {
2123 nvlist_free(nvprops);
2128 volblocksize = zfs_prop_default_numeric(
2129 ZFS_PROP_VOLBLOCKSIZE);
2131 if ((error = zvol_check_volblocksize(
2132 volblocksize)) != 0 ||
2133 (error = zvol_check_volsize(volsize,
2134 volblocksize)) != 0) {
2135 nvlist_free(nvprops);
2138 } else if (type == DMU_OST_ZFS) {
2142 * We have to have normalization and
2143 * case-folding flags correct when we do the
2144 * file system creation, so go figure them out
2147 VERIFY(nvlist_alloc(&zct.zct_zplprops,
2148 NV_UNIQUE_NAME, KM_SLEEP) == 0);
2149 error = zfs_fill_zplprops(zc->zc_name, nvprops,
2150 zct.zct_zplprops, &is_insensitive);
2152 nvlist_free(nvprops);
2153 nvlist_free(zct.zct_zplprops);
2157 error = dmu_objset_create(zc->zc_name, type, NULL,
2158 is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
2159 nvlist_free(zct.zct_zplprops);
2163 * It would be nice to do this atomically.
2166 if ((error = zfs_set_prop_nvlist(zc->zc_name, nvprops)) != 0)
2167 (void) dmu_objset_destroy(zc->zc_name);
2169 nvlist_free(nvprops);
2173 struct snap_prop_arg {
2175 const char *snapname;
2179 set_snap_props(char *name, void *arg)
2181 struct snap_prop_arg *snpa = arg;
2182 int len = strlen(name) + strlen(snpa->snapname) + 2;
2183 char *buf = kmem_alloc(len, KM_SLEEP);
2186 (void) snprintf(buf, len, "%s@%s", name, snpa->snapname);
2187 err = zfs_set_prop_nvlist(buf, snpa->nvprops);
2189 (void) dmu_objset_destroy(buf);
2190 kmem_free(buf, len);
2196 * zc_name name of filesystem
2197 * zc_value short name of snapshot
2198 * zc_cookie recursive flag
2203 zfs_ioc_snapshot(zfs_cmd_t *zc)
2205 nvlist_t *nvprops = NULL;
2207 boolean_t recursive = zc->zc_cookie;
2209 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2212 if (zc->zc_nvlist_src != 0 &&
2213 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2217 error = dmu_objset_snapshot(zc->zc_name, zc->zc_value, recursive);
2220 * It would be nice to do this atomically.
2223 struct snap_prop_arg snpa;
2224 snpa.nvprops = nvprops;
2225 snpa.snapname = zc->zc_value;
2227 error = dmu_objset_find(zc->zc_name,
2228 set_snap_props, &snpa, DS_FIND_CHILDREN);
2230 (void) dmu_snapshots_destroy(zc->zc_name,
2234 error = set_snap_props(zc->zc_name, &snpa);
2237 nvlist_free(nvprops);
2242 zfs_unmount_snap(char *name, void *arg)
2247 char *snapname = arg;
2248 int len = strlen(name) + strlen(snapname) + 2;
2249 char *buf = kmem_alloc(len, KM_SLEEP);
2251 (void) strcpy(buf, name);
2252 (void) strcat(buf, "@");
2253 (void) strcat(buf, snapname);
2254 vfsp = zfs_get_vfs(buf);
2255 kmem_free(buf, len);
2256 } else if (strchr(name, '@')) {
2257 vfsp = zfs_get_vfs(name);
2262 * Always force the unmount for snapshots.
2264 int flag = MS_FORCE;
2267 if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
2272 mtx_lock(&Giant); /* dounmount() */
2273 dounmount(vfsp, flag, curthread);
2274 mtx_unlock(&Giant); /* dounmount() */
2281 * zc_name name of filesystem
2282 * zc_value short name of snapshot
2287 zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
2291 if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2293 err = dmu_objset_find(zc->zc_name,
2294 zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2297 return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value));
2302 * zc_name name of dataset to destroy
2303 * zc_objset_type type of objset
2308 zfs_ioc_destroy(zfs_cmd_t *zc)
2310 if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
2311 int err = zfs_unmount_snap(zc->zc_name, NULL);
2316 return (dmu_objset_destroy(zc->zc_name));
2321 * zc_name name of dataset to rollback (to most recent snapshot)
2326 zfs_ioc_rollback(zfs_cmd_t *zc)
2330 zfsvfs_t *zfsvfs = NULL;
2333 * Get the zfsvfs for the receiving objset. There
2334 * won't be one if we're operating on a zvol, if the
2335 * objset doesn't exist yet, or is not mounted.
2337 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, DS_MODE_USER, &os);
2341 if (dmu_objset_type(os) == DMU_OST_ZFS) {
2342 mutex_enter(&os->os->os_user_ptr_lock);
2343 zfsvfs = dmu_objset_get_user(os);
2345 VFS_HOLD(zfsvfs->z_vfs);
2346 mutex_exit(&os->os->os_user_ptr_lock);
2349 if (zfsvfs != NULL) {
2350 char osname[MAXNAMELEN];
2353 error = zfs_suspend_fs(zfsvfs, osname, &mode);
2357 ASSERT(strcmp(osname, zc->zc_name) == 0);
2358 error = dmu_objset_rollback(os);
2359 resume_err = zfs_resume_fs(zfsvfs, osname, mode);
2360 error = error ? error : resume_err;
2362 dmu_objset_close(os);
2364 VFS_RELE(zfsvfs->z_vfs);
2366 error = dmu_objset_rollback(os);
2368 /* Note, the dmu_objset_rollback() releases the objset for us. */
2375 * zc_name old name of dataset
2376 * zc_value new name of dataset
2377 * zc_cookie recursive flag (only valid for snapshots)
2382 zfs_ioc_rename(zfs_cmd_t *zc)
2384 boolean_t recursive = zc->zc_cookie & 1;
2386 zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
2387 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
2388 strchr(zc->zc_value, '%'))
2392 * Unmount snapshot unless we're doing a recursive rename,
2393 * in which case the dataset code figures out which snapshots
2396 if (!recursive && strchr(zc->zc_name, '@') != NULL &&
2397 zc->zc_objset_type == DMU_OST_ZFS) {
2398 int err = zfs_unmount_snap(zc->zc_name, NULL);
2402 return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
2406 clear_props(char *dataset, nvlist_t *props)
2413 zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
2414 (void) strcpy(zc->zc_name, dataset);
2415 for (prop = nvlist_next_nvpair(props, NULL); prop;
2416 prop = nvlist_next_nvpair(props, prop)) {
2417 (void) strcpy(zc->zc_value, nvpair_name(prop));
2418 if (zfs_secpolicy_inherit(zc, CRED()) == 0)
2419 (void) zfs_ioc_inherit_prop(zc);
2421 kmem_free(zc, sizeof (zfs_cmd_t));
2426 * zc_name name of containing filesystem
2427 * zc_nvlist_src{_size} nvlist of properties to apply
2428 * zc_value name of snapshot to create
2429 * zc_string name of clone origin (if DRR_FLAG_CLONE)
2430 * zc_cookie file descriptor to recv from
2431 * zc_begin_record the BEGIN record of the stream (not byteswapped)
2432 * zc_guid force flag
2435 * zc_cookie number of bytes read
2438 zfs_ioc_recv(zfs_cmd_t *zc)
2442 dmu_recv_cookie_t drc;
2443 zfsvfs_t *zfsvfs = NULL;
2444 boolean_t force = (boolean_t)zc->zc_guid;
2447 nvlist_t *props = NULL;
2448 nvlist_t *origprops = NULL;
2449 objset_t *origin = NULL;
2451 char tofs[ZFS_MAXNAMELEN];
2453 if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
2454 strchr(zc->zc_value, '@') == NULL ||
2455 strchr(zc->zc_value, '%'))
2458 (void) strcpy(tofs, zc->zc_value);
2459 tosnap = strchr(tofs, '@');
2463 if (zc->zc_nvlist_src != 0 &&
2464 (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
2475 if (dmu_objset_open(tofs, DMU_OST_ANY,
2476 DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
2478 * Try to get the zfsvfs for the receiving objset.
2479 * There won't be one if we're operating on a zvol,
2480 * if the objset doesn't exist yet, or is not mounted.
2482 mutex_enter(&os->os->os_user_ptr_lock);
2483 if (zfsvfs = dmu_objset_get_user(os)) {
2484 if (!mutex_tryenter(&zfsvfs->z_online_recv_lock)) {
2485 mutex_exit(&os->os->os_user_ptr_lock);
2486 dmu_objset_close(os);
2491 VFS_HOLD(zfsvfs->z_vfs);
2493 mutex_exit(&os->os->os_user_ptr_lock);
2496 * If new properties are supplied, they are to completely
2497 * replace the existing ones, so stash away the existing ones.
2500 (void) dsl_prop_get_all(os, &origprops, TRUE);
2502 dmu_objset_close(os);
2505 if (zc->zc_string[0]) {
2506 error = dmu_objset_open(zc->zc_string, DMU_OST_ANY,
2507 DS_MODE_USER | DS_MODE_READONLY, &origin);
2512 error = dmu_recv_begin(tofs, tosnap, &zc->zc_begin_record,
2513 force, origin, zfsvfs != NULL, &drc);
2515 dmu_objset_close(origin);
2520 * Reset properties. We do this before we receive the stream
2521 * so that the properties are applied to the new data.
2524 clear_props(tofs, origprops);
2526 * XXX - Note, this is all-or-nothing; should be best-effort.
2528 (void) zfs_set_prop_nvlist(tofs, props);
2532 error = dmu_recv_stream(&drc, fp, &off);
2534 if (error == 0 && zfsvfs) {
2535 char osname[MAXNAMELEN];
2539 error = zfs_suspend_fs(zfsvfs, osname, &mode);
2543 error = dmu_recv_end(&drc);
2544 resume_err = zfs_resume_fs(zfsvfs, osname, mode);
2545 error = error ? error : resume_err;
2547 dmu_recv_abort_cleanup(&drc);
2549 } else if (error == 0) {
2550 error = dmu_recv_end(&drc);
2553 zc->zc_cookie = off - fp->f_offset;
2554 if (off >= 0 && off <= MAXOFFSET_T)
2558 * On error, restore the original props.
2560 if (error && props) {
2561 clear_props(tofs, props);
2562 (void) zfs_set_prop_nvlist(tofs, origprops);
2566 mutex_exit(&zfsvfs->z_online_recv_lock);
2567 VFS_RELE(zfsvfs->z_vfs);
2570 nvlist_free(origprops);
2577 * zc_name name of snapshot to send
2578 * zc_value short name of incremental fromsnap (may be empty)
2579 * zc_cookie file descriptor to send stream to
2580 * zc_obj fromorigin flag (mutually exclusive with zc_value)
2585 zfs_ioc_send(zfs_cmd_t *zc)
2587 objset_t *fromsnap = NULL;
2593 error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
2594 DS_MODE_USER | DS_MODE_READONLY, &tosnap);
2598 if (zc->zc_value[0] != '\0') {
2599 char buf[MAXPATHLEN];
2602 (void) strncpy(buf, zc->zc_name, sizeof (buf));
2603 cp = strchr(buf, '@');
2606 (void) strlcat(buf, zc->zc_value, sizeof (buf));
2607 error = dmu_objset_open(buf, DMU_OST_ANY,
2608 DS_MODE_USER | DS_MODE_READONLY, &fromsnap);
2610 dmu_objset_close(tosnap);
2615 fp = getf(zc->zc_cookie, 1);
2617 dmu_objset_close(tosnap);
2619 dmu_objset_close(fromsnap);
2624 error = dmu_sendbackup(tosnap, fromsnap, zc->zc_obj, fp, &off);
2626 if (off >= 0 && off <= MAXOFFSET_T)
2630 dmu_objset_close(fromsnap);
2631 dmu_objset_close(tosnap);
2636 zfs_ioc_inject_fault(zfs_cmd_t *zc)
2640 error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
2641 &zc->zc_inject_record);
2644 zc->zc_guid = (uint64_t)id;
2650 zfs_ioc_clear_fault(zfs_cmd_t *zc)
2652 return (zio_clear_fault((int)zc->zc_guid));
2656 zfs_ioc_inject_list_next(zfs_cmd_t *zc)
2658 int id = (int)zc->zc_guid;
2661 error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
2662 &zc->zc_inject_record);
2670 zfs_ioc_error_log(zfs_cmd_t *zc)
2674 size_t count = (size_t)zc->zc_nvlist_dst_size;
2676 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2679 error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
2682 zc->zc_nvlist_dst_size = count;
2684 zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
2686 spa_close(spa, FTAG);
2692 zfs_ioc_clear(zfs_cmd_t *zc)
2699 * On zpool clear we also fix up missing slogs
2701 mutex_enter(&spa_namespace_lock);
2702 spa = spa_lookup(zc->zc_name);
2704 mutex_exit(&spa_namespace_lock);
2707 if (spa->spa_log_state == SPA_LOG_MISSING) {
2708 /* we need to let spa_open/spa_load clear the chains */
2709 spa->spa_log_state = SPA_LOG_CLEAR;
2711 mutex_exit(&spa_namespace_lock);
2713 if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
2716 spa_vdev_state_enter(spa);
2718 if (zc->zc_guid == 0) {
2721 vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
2723 (void) spa_vdev_state_exit(spa, NULL, ENODEV);
2724 spa_close(spa, FTAG);
2729 vdev_clear(spa, vd);
2731 (void) spa_vdev_state_exit(spa, NULL, 0);
2734 * Resume any suspended I/Os.
2738 spa_close(spa, FTAG);
2745 * zc_name name of filesystem
2746 * zc_value name of origin snapshot
2751 zfs_ioc_promote(zfs_cmd_t *zc)
2756 * We don't need to unmount *all* the origin fs's snapshots, but
2759 cp = strchr(zc->zc_value, '@');
2762 (void) dmu_objset_find(zc->zc_value,
2763 zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
2764 return (dsl_dataset_promote(zc->zc_name));
2769 * We don't want to have a hard dependency
2770 * against some special symbols in sharefs
2771 * nfs, and smbsrv. Determine them if needed when
2772 * the first file system is shared.
2773 * Neither sharefs, nfs or smbsrv are unloadable modules.
2775 int (*znfsexport_fs)(void *arg);
2776 int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
2777 int (*zsmbexport_fs)(void *arg, boolean_t add_share);
2779 int zfs_nfsshare_inited;
2780 int zfs_smbshare_inited;
2782 ddi_modhandle_t nfs_mod;
2783 ddi_modhandle_t sharefs_mod;
2784 ddi_modhandle_t smbsrv_mod;
2786 kmutex_t zfs_share_lock;
2794 ASSERT(MUTEX_HELD(&zfs_share_lock));
2795 /* Both NFS and SMB shares also require sharetab support. */
2796 if (sharefs_mod == NULL && ((sharefs_mod =
2797 ddi_modopen("fs/sharefs",
2798 KRTLD_MODE_FIRST, &error)) == NULL)) {
2801 if (zshare_fs == NULL && ((zshare_fs =
2802 (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
2803 ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
2811 zfs_ioc_share(zfs_cmd_t *zc)
2817 switch (zc->zc_share.z_sharetype) {
2819 case ZFS_UNSHARE_NFS:
2820 if (zfs_nfsshare_inited == 0) {
2821 mutex_enter(&zfs_share_lock);
2822 if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
2823 KRTLD_MODE_FIRST, &error)) == NULL)) {
2824 mutex_exit(&zfs_share_lock);
2827 if (znfsexport_fs == NULL &&
2828 ((znfsexport_fs = (int (*)(void *))
2830 "nfs_export", &error)) == NULL)) {
2831 mutex_exit(&zfs_share_lock);
2834 error = zfs_init_sharefs();
2836 mutex_exit(&zfs_share_lock);
2839 zfs_nfsshare_inited = 1;
2840 mutex_exit(&zfs_share_lock);
2844 case ZFS_UNSHARE_SMB:
2845 if (zfs_smbshare_inited == 0) {
2846 mutex_enter(&zfs_share_lock);
2847 if (smbsrv_mod == NULL && ((smbsrv_mod =
2848 ddi_modopen("drv/smbsrv",
2849 KRTLD_MODE_FIRST, &error)) == NULL)) {
2850 mutex_exit(&zfs_share_lock);
2853 if (zsmbexport_fs == NULL && ((zsmbexport_fs =
2854 (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
2855 "smb_server_share", &error)) == NULL)) {
2856 mutex_exit(&zfs_share_lock);
2859 error = zfs_init_sharefs();
2861 mutex_exit(&zfs_share_lock);
2864 zfs_smbshare_inited = 1;
2865 mutex_exit(&zfs_share_lock);
2872 switch (zc->zc_share.z_sharetype) {
2874 case ZFS_UNSHARE_NFS:
2876 znfsexport_fs((void *)
2877 (uintptr_t)zc->zc_share.z_exportdata))
2881 case ZFS_UNSHARE_SMB:
2882 if (error = zsmbexport_fs((void *)
2883 (uintptr_t)zc->zc_share.z_exportdata,
2884 zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
2885 B_TRUE : B_FALSE)) {
2891 opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
2892 zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
2893 SHAREFS_ADD : SHAREFS_REMOVE;
2896 * Add or remove share from sharetab
2898 error = zshare_fs(opcode,
2899 (void *)(uintptr_t)zc->zc_share.z_sharedata,
2900 zc->zc_share.z_sharemax);
2909 * pool create, destroy, and export don't log the history as part of
2910 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
2911 * do the logging of those commands.
2914 zfs_ioc_jail(zfs_cmd_t *zc)
2917 return (zone_dataset_attach(curthread->td_ucred, zc->zc_name,
2918 (int)zc->zc_jailid));
2922 zfs_ioc_unjail(zfs_cmd_t *zc)
2925 return (zone_dataset_detach(curthread->td_ucred, zc->zc_name,
2926 (int)zc->zc_jailid));
2929 static zfs_ioc_vec_t zfs_ioc_vec[] = {
2930 { zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE },
2931 { zfs_ioc_pool_destroy, zfs_secpolicy_config, POOL_NAME, B_FALSE },
2932 { zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2933 { zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE },
2934 { zfs_ioc_pool_configs, zfs_secpolicy_none, NO_NAME, B_FALSE },
2935 { zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE },
2936 { zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE },
2937 { zfs_ioc_pool_scrub, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2938 { zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE },
2939 { zfs_ioc_pool_upgrade, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2940 { zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE },
2941 { zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2942 { zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2943 { zfs_ioc_vdev_set_state, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2944 { zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2945 { zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2946 { zfs_ioc_vdev_setpath, zfs_secpolicy_config, POOL_NAME, B_FALSE },
2947 { zfs_ioc_objset_stats, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
2948 { zfs_ioc_objset_zplprops, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
2949 { zfs_ioc_dataset_list_next, zfs_secpolicy_read,
2950 DATASET_NAME, B_FALSE },
2951 { zfs_ioc_snapshot_list_next, zfs_secpolicy_read,
2952 DATASET_NAME, B_FALSE },
2953 { zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE },
2954 { zfs_ioc_create_minor, zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
2955 { zfs_ioc_remove_minor, zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
2956 { zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE },
2957 { zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
2958 { zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE },
2959 { zfs_ioc_rename, zfs_secpolicy_rename, DATASET_NAME, B_TRUE },
2960 { zfs_ioc_recv, zfs_secpolicy_receive, DATASET_NAME, B_TRUE },
2961 { zfs_ioc_send, zfs_secpolicy_send, DATASET_NAME, B_TRUE },
2962 { zfs_ioc_inject_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
2963 { zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
2964 { zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE },
2965 { zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE },
2966 { zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2967 { zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE },
2968 { zfs_ioc_destroy_snaps, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
2969 { zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE },
2970 { zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE },
2971 { zfs_ioc_obj_to_path, zfs_secpolicy_config, NO_NAME, B_FALSE },
2972 { zfs_ioc_pool_set_props, zfs_secpolicy_config, POOL_NAME, B_TRUE },
2973 { zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE },
2974 { zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE },
2975 { zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
2976 { zfs_ioc_iscsi_perm_check, zfs_secpolicy_iscsi,
2977 DATASET_NAME, B_FALSE },
2978 { zfs_ioc_share, zfs_secpolicy_share, DATASET_NAME, B_FALSE },
2979 { zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE },
2980 { zfs_ioc_jail, zfs_secpolicy_config, DATASET_NAME, B_TRUE },
2981 { zfs_ioc_unjail, zfs_secpolicy_config, DATASET_NAME, B_TRUE }
2985 zfsdev_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
2988 zfs_cmd_t *zc = (void *)addr;
2994 if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
2997 error = zfs_ioc_vec[vec].zvec_secpolicy(zc, td->td_ucred);
3000 * Ensure that all pool/dataset names are valid before we pass down to
3004 zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
3005 switch (zfs_ioc_vec[vec].zvec_namecheck) {
3007 if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
3012 if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
3022 error = zfs_ioc_vec[vec].zvec_func(zc);
3025 if (zfs_ioc_vec[vec].zvec_his_log == B_TRUE)
3026 zfs_log_history(zc);
3033 * OK, so this is a little weird.
3035 * /dev/zfs is the control node, i.e. minor 0.
3036 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
3038 * /dev/zfs has basically nothing to do except serve up ioctls,
3039 * so most of the standard driver entry points are in zvol.c.
3041 static struct cdevsw zfs_cdevsw = {
3042 .d_version = D_VERSION,
3043 .d_ioctl = zfsdev_ioctl,
3044 .d_name = ZFS_DEV_NAME
3050 zfsdev = make_dev(&zfs_cdevsw, 0x0, UID_ROOT, GID_OPERATOR, 0666,
3058 destroy_dev(zfsdev);
3061 static struct root_hold_token *zfs_root_token;
3062 struct proc *zfsproc;
3064 uint_t zfs_fsyncer_key;
3065 extern uint_t rrw_tsd_key;
3068 zfs_modevent(module_t mod, int type, void *unused __unused)
3074 zfs_root_token = root_mount_hold("ZFS");
3076 mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
3078 spa_init(FREAD | FWRITE);
3082 tsd_create(&zfs_fsyncer_key, NULL);
3083 tsd_create(&rrw_tsd_key, NULL);
3085 printf("ZFS storage pool version " SPA_VERSION_STRING "\n");
3086 root_mount_rel(zfs_root_token);
3091 if (spa_busy() || zfs_busy() || zvol_busy() ||
3092 zio_injection_enabled) {
3102 tsd_destroy(&zfs_fsyncer_key);
3103 tsd_destroy(&rrw_tsd_key);
3105 mutex_destroy(&zfs_share_lock);
3114 static moduledata_t zfs_mod = {
3119 DECLARE_MODULE(zfsctrl, zfs_mod, SI_SUB_VFS, SI_ORDER_ANY);
3120 MODULE_DEPEND(zfsctrl, opensolaris, 1, 1, 1);
3121 MODULE_DEPEND(zfsctrl, krpc, 1, 1, 1);