4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Portions Copyright 2011 Martin Matuska
25 * Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
26 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
30 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/errno.h>
38 #include <sys/modctl.h>
43 #include <sys/cmn_err.h>
45 #include <sys/zfs_ioctl.h>
46 #include <sys/zfs_vfsops.h>
47 #include <sys/zfs_znode.h>
50 #include <sys/spa_impl.h>
52 #include <sys/priv_impl.h>
54 #include <sys/dsl_dir.h>
55 #include <sys/dsl_dataset.h>
56 #include <sys/dsl_prop.h>
57 #include <sys/dsl_deleg.h>
58 #include <sys/dmu_objset.h>
59 #include <sys/dmu_impl.h>
61 #include <sys/sunddi.h>
62 #include <sys/sunldi.h>
63 #include <sys/policy.h>
65 #include <sys/nvpair.h>
66 #include <sys/pathname.h>
67 #include <sys/mount.h>
69 #include <sys/fs/zfs.h>
70 #include <sys/zfs_ctldir.h>
71 #include <sys/zfs_dir.h>
72 #include <sys/zfs_onexit.h>
74 #include <sys/dsl_scan.h>
75 #include <sharefs/share.h>
76 #include <sys/dmu_objset.h>
77 #include <sys/fm/util.h>
79 #include <sys/zfeature.h>
81 #include <linux/miscdevice.h>
83 #include "zfs_namecheck.h"
85 #include "zfs_deleg.h"
86 #include "zfs_comutil.h"
88 kmutex_t zfsdev_state_lock
;
89 list_t zfsdev_state_list
;
91 extern void zfs_init(void);
92 extern void zfs_fini(void);
94 typedef int zfs_ioc_func_t(zfs_cmd_t
*);
95 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, cred_t
*);
101 } zfs_ioc_namecheck_t
;
104 POOL_CHECK_NONE
= 1 << 0,
105 POOL_CHECK_SUSPENDED
= 1 << 1,
106 POOL_CHECK_READONLY
= 1 << 2
107 } zfs_ioc_poolcheck_t
;
109 typedef struct zfs_ioc_vec
{
110 zfs_ioc_func_t
*zvec_func
;
111 zfs_secpolicy_func_t
*zvec_secpolicy
;
112 zfs_ioc_namecheck_t zvec_namecheck
;
113 boolean_t zvec_his_log
;
114 zfs_ioc_poolcheck_t zvec_pool_check
;
117 /* This array is indexed by zfs_userquota_prop_t */
118 static const char *userquota_perms
[] = {
119 ZFS_DELEG_PERM_USERUSED
,
120 ZFS_DELEG_PERM_USERQUOTA
,
121 ZFS_DELEG_PERM_GROUPUSED
,
122 ZFS_DELEG_PERM_GROUPQUOTA
,
125 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
126 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
128 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
130 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
132 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
**);
134 static int zfs_prop_activate_feature(dsl_pool_t
*dp
, zfeature_info_t
*feature
);
135 static int zfs_prop_activate_feature_check(void *arg1
, void *arg2
,
137 static void zfs_prop_activate_feature_sync(void *arg1
, void *arg2
,
141 history_str_free(char *buf
)
143 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
147 history_str_get(zfs_cmd_t
*zc
)
151 if (zc
->zc_history
== 0)
154 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
| KM_NODEBUG
);
155 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
156 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
157 history_str_free(buf
);
161 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
167 * Check to see if the named dataset is currently defined as bootable
170 zfs_is_bootfs(const char *name
)
174 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
176 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
177 dmu_objset_rele(os
, FTAG
);
184 * zfs_earlier_version
186 * Return non-zero if the spa version is less than requested version.
189 zfs_earlier_version(const char *name
, int version
)
193 if (spa_open(name
, &spa
, FTAG
) == 0) {
194 if (spa_version(spa
) < version
) {
195 spa_close(spa
, FTAG
);
198 spa_close(spa
, FTAG
);
204 * zpl_earlier_version
206 * Return TRUE if the ZPL version is less than requested version.
209 zpl_earlier_version(const char *name
, int version
)
212 boolean_t rc
= B_TRUE
;
214 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
217 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
218 dmu_objset_rele(os
, FTAG
);
221 /* XXX reading from non-owned objset */
222 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
223 rc
= zplversion
< version
;
224 dmu_objset_rele(os
, FTAG
);
230 zfs_log_history(zfs_cmd_t
*zc
)
235 if ((buf
= history_str_get(zc
)) == NULL
)
238 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
239 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
240 (void) spa_history_log(spa
, buf
, LOG_CMD_NORMAL
);
241 spa_close(spa
, FTAG
);
243 history_str_free(buf
);
247 * Policy for top-level read operations (list pools). Requires no privileges,
248 * and can be used in the local zone, as there is no associated dataset.
252 zfs_secpolicy_none(zfs_cmd_t
*zc
, cred_t
*cr
)
258 * Policy for dataset read operations (list children, get statistics). Requires
259 * no privileges, but must be visible in the local zone.
263 zfs_secpolicy_read(zfs_cmd_t
*zc
, cred_t
*cr
)
265 if (INGLOBALZONE(curproc
) ||
266 zone_dataset_visible(zc
->zc_name
, NULL
))
273 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, 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(curproc
) &&
282 !zone_dataset_visible(dataset
, &writable
))
285 if (INGLOBALZONE(curproc
)) {
287 * If the fs is zoned, only root can access it from the
290 if (secpolicy_zfs(cr
) && zoned
)
294 * If we are in a local zone, the 'zoned' property must be set.
299 /* must be writable by this zone */
307 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
311 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
314 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
318 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
322 rw_enter(&ds
->ds_dir
->dd_pool
->dp_config_rwlock
, RW_READER
);
323 if (dsl_prop_get_ds(ds
, "zoned", 8, 1, &zoned
, NULL
)) {
324 rw_exit(&ds
->ds_dir
->dd_pool
->dp_config_rwlock
);
327 rw_exit(&ds
->ds_dir
->dd_pool
->dp_config_rwlock
);
329 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
333 * If name ends in a '@', then require recursive permissions.
336 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
339 boolean_t descendent
= B_FALSE
;
343 at
= strchr(name
, '@');
344 if (at
!= NULL
&& at
[1] == '\0') {
349 error
= dsl_dataset_hold(name
, FTAG
, &ds
);
355 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
357 error
= secpolicy_zfs(cr
);
359 error
= dsl_deleg_access_impl(ds
, descendent
, perm
, cr
);
362 dsl_dataset_rele(ds
, FTAG
);
367 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
368 const char *perm
, cred_t
*cr
)
372 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
374 error
= secpolicy_zfs(cr
);
376 error
= dsl_deleg_access_impl(ds
, B_FALSE
, perm
, cr
);
382 * Policy for setting the security label property.
384 * Returns 0 for success, non-zero for access and other errors.
387 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
390 char ds_hexsl
[MAXNAMELEN
];
391 bslabel_t ds_sl
, new_sl
;
392 boolean_t new_default
= FALSE
;
394 int needed_priv
= -1;
397 /* First get the existing dataset label. */
398 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
399 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
403 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
406 /* The label must be translatable */
407 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
411 * In a non-global zone, disallow attempts to set a label that
412 * doesn't match that of the zone; otherwise no other checks
415 if (!INGLOBALZONE(curproc
)) {
416 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
422 * For global-zone datasets (i.e., those whose zoned property is
423 * "off", verify that the specified new label is valid for the
426 if (dsl_prop_get_integer(name
,
427 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
430 if (zfs_check_global_label(name
, strval
) != 0)
435 * If the existing dataset label is nondefault, check if the
436 * dataset is mounted (label cannot be changed while mounted).
437 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
438 * mounted (or isn't a dataset, doesn't exist, ...).
440 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
442 static char *setsl_tag
= "setsl_tag";
445 * Try to own the dataset; abort if there is any error,
446 * (e.g., already mounted, in use, or other error).
448 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
,
453 dmu_objset_disown(os
, setsl_tag
);
456 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
460 if (hexstr_to_label(strval
, &new_sl
) != 0)
463 if (blstrictdom(&ds_sl
, &new_sl
))
464 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
465 else if (blstrictdom(&new_sl
, &ds_sl
))
466 needed_priv
= PRIV_FILE_UPGRADE_SL
;
468 /* dataset currently has a default label */
470 needed_priv
= PRIV_FILE_UPGRADE_SL
;
474 if (needed_priv
!= -1)
475 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
479 #endif /* HAVE_MLSLABEL */
483 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
489 * Check permissions for special properties.
496 * Disallow setting of 'zoned' from within a local zone.
498 if (!INGLOBALZONE(curproc
))
503 if (!INGLOBALZONE(curproc
)) {
505 char setpoint
[MAXNAMELEN
];
507 * Unprivileged users are allowed to modify the
508 * quota on things *under* (ie. contained by)
509 * the thing they own.
511 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
514 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
519 case ZFS_PROP_MLSLABEL
:
520 if (!is_system_labeled())
523 if (nvpair_value_string(propval
, &strval
) == 0) {
526 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
533 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
537 zfs_secpolicy_fsacl(zfs_cmd_t
*zc
, cred_t
*cr
)
541 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
546 * permission to set permissions will be evaluated later in
547 * dsl_deleg_can_allow()
553 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, cred_t
*cr
)
555 return (zfs_secpolicy_write_perms(zc
->zc_name
,
556 ZFS_DELEG_PERM_ROLLBACK
, cr
));
560 zfs_secpolicy_send(zfs_cmd_t
*zc
, cred_t
*cr
)
569 * Generate the current snapshot name from the given objsetid, then
570 * use that name for the secpolicy/zone checks.
572 cp
= strchr(zc
->zc_name
, '@');
575 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
579 dp
= spa_get_dsl(spa
);
580 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
581 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
582 rw_exit(&dp
->dp_config_rwlock
);
583 spa_close(spa
, FTAG
);
587 dsl_dataset_name(ds
, zc
->zc_name
);
589 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
590 ZFS_DELEG_PERM_SEND
, cr
);
591 dsl_dataset_rele(ds
, FTAG
);
596 #ifdef HAVE_SMB_SHARE
598 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, cred_t
*cr
)
603 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
604 NO_FOLLOW
, NULL
, &vp
)) != 0)
607 /* Now make sure mntpnt and dataset are ZFS */
609 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
610 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
611 zc
->zc_name
) != 0)) {
617 return (dsl_deleg_access(zc
->zc_name
,
618 ZFS_DELEG_PERM_SHARE
, cr
));
620 #endif /* HAVE_SMB_SHARE */
623 zfs_secpolicy_share(zfs_cmd_t
*zc
, cred_t
*cr
)
625 #ifdef HAVE_SMB_SHARE
626 if (!INGLOBALZONE(curproc
))
629 if (secpolicy_nfs(cr
) == 0) {
632 return (zfs_secpolicy_deleg_share(zc
, cr
));
636 #endif /* HAVE_SMB_SHARE */
640 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, cred_t
*cr
)
642 #ifdef HAVE_SMB_SHARE
643 if (!INGLOBALZONE(curproc
))
646 if (secpolicy_smb(cr
) == 0) {
649 return (zfs_secpolicy_deleg_share(zc
, cr
));
653 #endif /* HAVE_SMB_SHARE */
657 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
662 * Remove the @bla or /bla from the end of the name to get the parent.
664 (void) strncpy(parent
, datasetname
, parentsize
);
665 cp
= strrchr(parent
, '@');
669 cp
= strrchr(parent
, '/');
679 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
683 if ((error
= zfs_secpolicy_write_perms(name
,
684 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
687 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
691 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, cred_t
*cr
)
693 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
697 * Destroying snapshots with delegated permissions requires
698 * descendent mount and destroy permissions.
701 zfs_secpolicy_destroy_recursive(zfs_cmd_t
*zc
, cred_t
*cr
)
706 dsname
= kmem_asprintf("%s@", zc
->zc_name
);
708 error
= zfs_secpolicy_destroy_perms(dsname
, cr
);
710 error
= zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
);
717 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
719 char parentname
[MAXNAMELEN
];
722 if ((error
= zfs_secpolicy_write_perms(from
,
723 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
726 if ((error
= zfs_secpolicy_write_perms(from
,
727 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
730 if ((error
= zfs_get_parent(to
, parentname
,
731 sizeof (parentname
))) != 0)
734 if ((error
= zfs_secpolicy_write_perms(parentname
,
735 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
738 if ((error
= zfs_secpolicy_write_perms(parentname
,
739 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
746 zfs_secpolicy_rename(zfs_cmd_t
*zc
, cred_t
*cr
)
748 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
752 zfs_secpolicy_promote(zfs_cmd_t
*zc
, cred_t
*cr
)
754 char parentname
[MAXNAMELEN
];
758 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
759 ZFS_DELEG_PERM_PROMOTE
, cr
);
763 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &clone
);
766 dsl_dataset_t
*pclone
= NULL
;
768 dd
= clone
->os_dsl_dataset
->ds_dir
;
770 rw_enter(&dd
->dd_pool
->dp_config_rwlock
, RW_READER
);
771 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
772 dd
->dd_phys
->dd_origin_obj
, FTAG
, &pclone
);
773 rw_exit(&dd
->dd_pool
->dp_config_rwlock
);
775 dmu_objset_rele(clone
, FTAG
);
779 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
780 ZFS_DELEG_PERM_MOUNT
, cr
);
782 dsl_dataset_name(pclone
, parentname
);
783 dmu_objset_rele(clone
, FTAG
);
784 dsl_dataset_rele(pclone
, FTAG
);
786 error
= zfs_secpolicy_write_perms(parentname
,
787 ZFS_DELEG_PERM_PROMOTE
, cr
);
793 zfs_secpolicy_receive(zfs_cmd_t
*zc
, cred_t
*cr
)
797 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
798 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
801 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
802 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
805 return (zfs_secpolicy_write_perms(zc
->zc_name
,
806 ZFS_DELEG_PERM_CREATE
, cr
));
810 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
812 return (zfs_secpolicy_write_perms(name
,
813 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
817 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, cred_t
*cr
)
820 return (zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
));
824 zfs_secpolicy_create(zfs_cmd_t
*zc
, cred_t
*cr
)
826 char parentname
[MAXNAMELEN
];
829 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
830 sizeof (parentname
))) != 0)
833 if (zc
->zc_value
[0] != '\0') {
834 if ((error
= zfs_secpolicy_write_perms(zc
->zc_value
,
835 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
839 if ((error
= zfs_secpolicy_write_perms(parentname
,
840 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
843 error
= zfs_secpolicy_write_perms(parentname
,
844 ZFS_DELEG_PERM_MOUNT
, cr
);
850 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
851 * SYS_CONFIG privilege, which is not available in a local zone.
855 zfs_secpolicy_config(zfs_cmd_t
*zc
, cred_t
*cr
)
857 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
864 * Policy for object to name lookups.
868 zfs_secpolicy_diff(zfs_cmd_t
*zc
, cred_t
*cr
)
872 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
875 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
880 * Policy for fault injection. Requires all privileges.
884 zfs_secpolicy_inject(zfs_cmd_t
*zc
, cred_t
*cr
)
886 return (secpolicy_zinject(cr
));
890 zfs_secpolicy_inherit(zfs_cmd_t
*zc
, cred_t
*cr
)
892 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
894 if (prop
== ZPROP_INVAL
) {
895 if (!zfs_prop_user(zc
->zc_value
))
897 return (zfs_secpolicy_write_perms(zc
->zc_name
,
898 ZFS_DELEG_PERM_USERPROP
, cr
));
900 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
906 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, cred_t
*cr
)
908 int err
= zfs_secpolicy_read(zc
, cr
);
912 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
915 if (zc
->zc_value
[0] == 0) {
917 * They are asking about a posix uid/gid. If it's
918 * themself, allow it.
920 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
921 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
922 if (zc
->zc_guid
== crgetuid(cr
))
925 if (groupmember(zc
->zc_guid
, cr
))
930 return (zfs_secpolicy_write_perms(zc
->zc_name
,
931 userquota_perms
[zc
->zc_objset_type
], cr
));
935 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, cred_t
*cr
)
937 int err
= zfs_secpolicy_read(zc
, cr
);
941 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
944 return (zfs_secpolicy_write_perms(zc
->zc_name
,
945 userquota_perms
[zc
->zc_objset_type
], cr
));
949 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, cred_t
*cr
)
951 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
956 zfs_secpolicy_hold(zfs_cmd_t
*zc
, cred_t
*cr
)
958 return (zfs_secpolicy_write_perms(zc
->zc_name
,
959 ZFS_DELEG_PERM_HOLD
, cr
));
963 zfs_secpolicy_release(zfs_cmd_t
*zc
, cred_t
*cr
)
965 return (zfs_secpolicy_write_perms(zc
->zc_name
,
966 ZFS_DELEG_PERM_RELEASE
, cr
));
970 * Policy for allowing temporary snapshots to be taken or released
973 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, cred_t
*cr
)
976 * A temporary snapshot is the same as a snapshot,
977 * hold, destroy and release all rolled into one.
978 * Delegated diff alone is sufficient that we allow this.
982 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
983 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
986 error
= zfs_secpolicy_snapshot(zc
, cr
);
988 error
= zfs_secpolicy_hold(zc
, cr
);
990 error
= zfs_secpolicy_release(zc
, cr
);
992 error
= zfs_secpolicy_destroy(zc
, cr
);
997 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1000 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1004 nvlist_t
*list
= NULL
;
1007 * Read in and unpack the user-supplied nvlist.
1012 packed
= kmem_alloc(size
, KM_SLEEP
| KM_NODEBUG
);
1014 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1016 kmem_free(packed
, size
);
1020 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1021 kmem_free(packed
, size
);
1025 kmem_free(packed
, size
);
1032 fit_error_list(zfs_cmd_t
*zc
, nvlist_t
**errors
)
1036 VERIFY(nvlist_size(*errors
, &size
, NV_ENCODE_NATIVE
) == 0);
1038 if (size
> zc
->zc_nvlist_dst_size
) {
1039 nvpair_t
*more_errors
;
1042 if (zc
->zc_nvlist_dst_size
< 1024)
1045 VERIFY(nvlist_add_int32(*errors
, ZPROP_N_MORE_ERRORS
, 0) == 0);
1046 more_errors
= nvlist_prev_nvpair(*errors
, NULL
);
1049 nvpair_t
*pair
= nvlist_prev_nvpair(*errors
,
1051 VERIFY(nvlist_remove_nvpair(*errors
, pair
) == 0);
1053 VERIFY(nvlist_size(*errors
, &size
,
1054 NV_ENCODE_NATIVE
) == 0);
1055 } while (size
> zc
->zc_nvlist_dst_size
);
1057 VERIFY(nvlist_remove_nvpair(*errors
, more_errors
) == 0);
1058 VERIFY(nvlist_add_int32(*errors
, ZPROP_N_MORE_ERRORS
, n
) == 0);
1059 ASSERT(nvlist_size(*errors
, &size
, NV_ENCODE_NATIVE
) == 0);
1060 ASSERT(size
<= zc
->zc_nvlist_dst_size
);
1067 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1069 char *packed
= NULL
;
1073 VERIFY(nvlist_size(nvl
, &size
, NV_ENCODE_NATIVE
) == 0);
1075 if (size
> zc
->zc_nvlist_dst_size
) {
1078 packed
= kmem_alloc(size
, KM_SLEEP
| KM_NODEBUG
);
1079 VERIFY(nvlist_pack(nvl
, &packed
, &size
, NV_ENCODE_NATIVE
,
1081 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1082 size
, zc
->zc_iflags
) != 0)
1084 kmem_free(packed
, size
);
1087 zc
->zc_nvlist_dst_size
= size
;
1092 get_zfs_sb(const char *dsname
, zfs_sb_t
**zsbp
)
1097 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1100 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1101 dmu_objset_rele(os
, FTAG
);
1105 mutex_enter(&os
->os_user_ptr_lock
);
1106 *zsbp
= dmu_objset_get_user(os
);
1107 if (*zsbp
&& (*zsbp
)->z_sb
) {
1108 atomic_inc(&((*zsbp
)->z_sb
->s_active
));
1112 mutex_exit(&os
->os_user_ptr_lock
);
1113 dmu_objset_rele(os
, FTAG
);
1118 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1119 * case its z_sb will be NULL, and it will be opened as the owner.
1120 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1121 * which prevents all inode ops from running.
1124 zfs_sb_hold(const char *name
, void *tag
, zfs_sb_t
**zsbp
, boolean_t writer
)
1128 if (get_zfs_sb(name
, zsbp
) != 0)
1129 error
= zfs_sb_create(name
, zsbp
);
1131 rrw_enter(&(*zsbp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1133 if ((*zsbp
)->z_unmounted
) {
1135 * XXX we could probably try again, since the unmounting
1136 * thread should be just about to disassociate the
1137 * objset from the zfsvfs.
1139 rrw_exit(&(*zsbp
)->z_teardown_lock
, tag
);
1147 zfs_sb_rele(zfs_sb_t
*zsb
, void *tag
)
1149 rrw_exit(&zsb
->z_teardown_lock
, tag
);
1152 deactivate_super(zsb
->z_sb
);
1154 dmu_objset_disown(zsb
->z_os
, zsb
);
1160 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1163 nvlist_t
*config
, *props
= NULL
;
1164 nvlist_t
*rootprops
= NULL
;
1165 nvlist_t
*zplprops
= NULL
;
1168 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1169 zc
->zc_iflags
, &config
)))
1172 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1173 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1174 zc
->zc_iflags
, &props
))) {
1175 nvlist_free(config
);
1180 nvlist_t
*nvl
= NULL
;
1181 uint64_t version
= SPA_VERSION
;
1183 (void) nvlist_lookup_uint64(props
,
1184 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1185 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1187 goto pool_props_bad
;
1189 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1191 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1193 nvlist_free(config
);
1197 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1199 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1200 error
= zfs_fill_zplprops_root(version
, rootprops
,
1203 goto pool_props_bad
;
1206 buf
= history_str_get(zc
);
1208 error
= spa_create(zc
->zc_name
, config
, props
, buf
, zplprops
);
1211 * Set the remaining root properties
1213 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1214 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1215 (void) spa_destroy(zc
->zc_name
);
1218 history_str_free(buf
);
1221 nvlist_free(rootprops
);
1222 nvlist_free(zplprops
);
1223 nvlist_free(config
);
1230 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1233 zfs_log_history(zc
);
1234 error
= spa_destroy(zc
->zc_name
);
1236 zvol_remove_minors(zc
->zc_name
);
1241 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1243 nvlist_t
*config
, *props
= NULL
;
1247 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1248 zc
->zc_iflags
, &config
)) != 0)
1251 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1252 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1253 zc
->zc_iflags
, &props
))) {
1254 nvlist_free(config
);
1258 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1259 guid
!= zc
->zc_guid
)
1262 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1264 if (zc
->zc_nvlist_dst
!= 0) {
1267 if ((err
= put_nvlist(zc
, config
)) != 0)
1272 zvol_create_minors(zc
->zc_name
);
1274 nvlist_free(config
);
1283 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1286 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1287 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1289 zfs_log_history(zc
);
1290 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1292 zvol_remove_minors(zc
->zc_name
);
1297 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1302 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1305 error
= put_nvlist(zc
, configs
);
1307 nvlist_free(configs
);
1314 * zc_name name of the pool
1317 * zc_cookie real errno
1318 * zc_nvlist_dst config nvlist
1319 * zc_nvlist_dst_size size of config nvlist
1322 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1328 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1329 sizeof (zc
->zc_value
));
1331 if (config
!= NULL
) {
1332 ret
= put_nvlist(zc
, config
);
1333 nvlist_free(config
);
1336 * The config may be present even if 'error' is non-zero.
1337 * In this case we return success, and preserve the real errno
1340 zc
->zc_cookie
= error
;
1349 * Try to import the given pool, returning pool stats as appropriate so that
1350 * user land knows which devices are available and overall pool health.
1353 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1355 nvlist_t
*tryconfig
, *config
;
1358 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1359 zc
->zc_iflags
, &tryconfig
)) != 0)
1362 config
= spa_tryimport(tryconfig
);
1364 nvlist_free(tryconfig
);
1369 error
= put_nvlist(zc
, config
);
1370 nvlist_free(config
);
1377 * zc_name name of the pool
1378 * zc_cookie scan func (pool_scan_func_t)
1381 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1386 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1389 if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1390 error
= spa_scan_stop(spa
);
1392 error
= spa_scan(spa
, zc
->zc_cookie
);
1394 spa_close(spa
, FTAG
);
1400 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1405 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1408 spa_close(spa
, FTAG
);
1414 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1419 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1422 if (zc
->zc_cookie
< spa_version(spa
) ||
1423 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1424 spa_close(spa
, FTAG
);
1428 spa_upgrade(spa
, zc
->zc_cookie
);
1429 spa_close(spa
, FTAG
);
1435 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1442 if ((size
= zc
->zc_history_len
) == 0)
1445 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1448 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1449 spa_close(spa
, FTAG
);
1453 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1454 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1455 &zc
->zc_history_len
, hist_buf
)) == 0) {
1456 error
= ddi_copyout(hist_buf
,
1457 (void *)(uintptr_t)zc
->zc_history
,
1458 zc
->zc_history_len
, zc
->zc_iflags
);
1461 spa_close(spa
, FTAG
);
1462 vmem_free(hist_buf
, size
);
1467 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1472 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1474 error
= spa_change_guid(spa
);
1475 spa_close(spa
, FTAG
);
1481 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1485 if ((error
= dsl_dsobj_to_dsname(zc
->zc_name
,zc
->zc_obj
,zc
->zc_value
)))
1493 * zc_name name of filesystem
1494 * zc_obj object to find
1497 * zc_value name of object
1500 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1505 /* XXX reading from objset not owned */
1506 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1508 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1509 dmu_objset_rele(os
, FTAG
);
1512 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1513 sizeof (zc
->zc_value
));
1514 dmu_objset_rele(os
, FTAG
);
1521 * zc_name name of filesystem
1522 * zc_obj object to find
1525 * zc_stat stats on object
1526 * zc_value path to object
1529 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1534 /* XXX reading from objset not owned */
1535 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1537 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1538 dmu_objset_rele(os
, FTAG
);
1541 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1542 sizeof (zc
->zc_value
));
1543 dmu_objset_rele(os
, FTAG
);
1549 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1553 nvlist_t
*config
, **l2cache
, **spares
;
1554 uint_t nl2cache
= 0, nspares
= 0;
1556 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1560 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1561 zc
->zc_iflags
, &config
);
1562 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_L2CACHE
,
1563 &l2cache
, &nl2cache
);
1565 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_SPARES
,
1569 * A root pool with concatenated devices is not supported.
1570 * Thus, can not add a device to a root pool.
1572 * Intent log device can not be added to a rootpool because
1573 * during mountroot, zil is replayed, a seperated log device
1574 * can not be accessed during the mountroot time.
1576 * l2cache and spare devices are ok to be added to a rootpool.
1578 if (spa_bootfs(spa
) != 0 && nl2cache
== 0 && nspares
== 0) {
1579 nvlist_free(config
);
1580 spa_close(spa
, FTAG
);
1585 error
= spa_vdev_add(spa
, config
);
1586 nvlist_free(config
);
1588 spa_close(spa
, FTAG
);
1594 * zc_name name of the pool
1595 * zc_nvlist_conf nvlist of devices to remove
1596 * zc_cookie to stop the remove?
1599 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1604 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1607 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1608 spa_close(spa
, FTAG
);
1613 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1617 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1619 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1621 switch (zc
->zc_cookie
) {
1622 case VDEV_STATE_ONLINE
:
1623 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1626 case VDEV_STATE_OFFLINE
:
1627 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1630 case VDEV_STATE_FAULTED
:
1631 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1632 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1633 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1635 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1638 case VDEV_STATE_DEGRADED
:
1639 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1640 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1641 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1643 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1649 zc
->zc_cookie
= newstate
;
1650 spa_close(spa
, FTAG
);
1655 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1658 int replacing
= zc
->zc_cookie
;
1662 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1665 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1666 zc
->zc_iflags
, &config
)) == 0) {
1667 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1668 nvlist_free(config
);
1671 spa_close(spa
, FTAG
);
1676 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1681 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1684 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1686 spa_close(spa
, FTAG
);
1691 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1694 nvlist_t
*config
, *props
= NULL
;
1696 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1698 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1701 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1702 zc
->zc_iflags
, &config
))) {
1703 spa_close(spa
, FTAG
);
1707 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1708 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1709 zc
->zc_iflags
, &props
))) {
1710 spa_close(spa
, FTAG
);
1711 nvlist_free(config
);
1715 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1717 spa_close(spa
, FTAG
);
1719 nvlist_free(config
);
1726 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1729 char *path
= zc
->zc_value
;
1730 uint64_t guid
= zc
->zc_guid
;
1733 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1737 error
= spa_vdev_setpath(spa
, guid
, path
);
1738 spa_close(spa
, FTAG
);
1743 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1746 char *fru
= zc
->zc_value
;
1747 uint64_t guid
= zc
->zc_guid
;
1750 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1754 error
= spa_vdev_setfru(spa
, guid
, fru
);
1755 spa_close(spa
, FTAG
);
1760 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
1765 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1767 if (zc
->zc_nvlist_dst
!= 0 &&
1768 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
1769 dmu_objset_stats(os
, nv
);
1771 * NB: zvol_get_stats() will read the objset contents,
1772 * which we aren't supposed to do with a
1773 * DS_MODE_USER hold, because it could be
1774 * inconsistent. So this is a bit of a workaround...
1775 * XXX reading with out owning
1777 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
1778 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
1779 error
= zvol_get_stats(os
, nv
);
1782 VERIFY3S(error
, ==, 0);
1785 error
= put_nvlist(zc
, nv
);
1794 * zc_name name of filesystem
1795 * zc_nvlist_dst_size size of buffer for property nvlist
1798 * zc_objset_stats stats
1799 * zc_nvlist_dst property nvlist
1800 * zc_nvlist_dst_size size of property nvlist
1803 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
1805 objset_t
*os
= NULL
;
1808 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
1811 error
= zfs_ioc_objset_stats_impl(zc
, os
);
1813 dmu_objset_rele(os
, FTAG
);
1820 * zc_name name of filesystem
1821 * zc_nvlist_dst_size size of buffer for property nvlist
1824 * zc_nvlist_dst received property nvlist
1825 * zc_nvlist_dst_size size of received property nvlist
1827 * Gets received properties (distinct from local properties on or after
1828 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
1829 * local property values.
1832 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
1834 objset_t
*os
= NULL
;
1838 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
1842 * Without this check, we would return local property values if the
1843 * caller has not already received properties on or after
1844 * SPA_VERSION_RECVD_PROPS.
1846 if (!dsl_prop_get_hasrecvd(os
)) {
1847 dmu_objset_rele(os
, FTAG
);
1851 if (zc
->zc_nvlist_dst
!= 0 &&
1852 (error
= dsl_prop_get_received(os
, &nv
)) == 0) {
1853 error
= put_nvlist(zc
, nv
);
1857 dmu_objset_rele(os
, FTAG
);
1862 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
1868 * zfs_get_zplprop() will either find a value or give us
1869 * the default value (if there is one).
1871 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
1873 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
1879 * zc_name name of filesystem
1880 * zc_nvlist_dst_size size of buffer for zpl property nvlist
1883 * zc_nvlist_dst zpl property nvlist
1884 * zc_nvlist_dst_size size of zpl property nvlist
1887 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
1892 /* XXX reading without owning */
1893 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
1896 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1899 * NB: nvl_add_zplprop() will read the objset contents,
1900 * which we aren't supposed to do with a DS_MODE_USER
1901 * hold, because it could be inconsistent.
1903 if (zc
->zc_nvlist_dst
!= 0 &&
1904 !zc
->zc_objset_stats
.dds_inconsistent
&&
1905 dmu_objset_type(os
) == DMU_OST_ZFS
) {
1908 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1909 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
1910 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
1911 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
1912 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
1913 err
= put_nvlist(zc
, nv
);
1918 dmu_objset_rele(os
, FTAG
);
1923 dataset_name_hidden(const char *name
)
1926 * Skip over datasets that are not visible in this zone,
1927 * internal datasets (which have a $ in their name), and
1928 * temporary datasets (which have a % in their name).
1930 if (strchr(name
, '$') != NULL
)
1932 if (strchr(name
, '%') != NULL
)
1934 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
1941 * zc_name name of filesystem
1942 * zc_cookie zap cursor
1943 * zc_nvlist_dst_size size of buffer for property nvlist
1946 * zc_name name of next filesystem
1947 * zc_cookie zap cursor
1948 * zc_objset_stats stats
1949 * zc_nvlist_dst property nvlist
1950 * zc_nvlist_dst_size size of property nvlist
1953 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
1958 size_t orig_len
= strlen(zc
->zc_name
);
1961 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
1962 if (error
== ENOENT
)
1967 p
= strrchr(zc
->zc_name
, '/');
1968 if (p
== NULL
|| p
[1] != '\0')
1969 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
1970 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
1973 * Pre-fetch the datasets. dmu_objset_prefetch() always returns 0
1974 * but is not declared void because its called by dmu_objset_find().
1976 if (zc
->zc_cookie
== 0) {
1977 uint64_t cookie
= 0;
1978 int len
= sizeof (zc
->zc_name
) - (p
- zc
->zc_name
);
1980 while (dmu_dir_list_next(os
, len
, p
, NULL
, &cookie
) == 0) {
1981 if (!dataset_name_hidden(zc
->zc_name
))
1982 (void) dmu_objset_prefetch(zc
->zc_name
, NULL
);
1987 error
= dmu_dir_list_next(os
,
1988 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
1989 NULL
, &zc
->zc_cookie
);
1990 if (error
== ENOENT
)
1992 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
1993 dmu_objset_rele(os
, FTAG
);
1996 * If it's an internal dataset (ie. with a '$' in its name),
1997 * don't try to get stats for it, otherwise we'll return ENOENT.
1999 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2000 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2001 if (error
== ENOENT
) {
2002 /* We lost a race with destroy, get the next one. */
2003 zc
->zc_name
[orig_len
] = '\0';
2012 * zc_name name of filesystem
2013 * zc_cookie zap cursor
2014 * zc_nvlist_dst_size size of buffer for property nvlist
2017 * zc_name name of next snapshot
2018 * zc_objset_stats stats
2019 * zc_nvlist_dst property nvlist
2020 * zc_nvlist_dst_size size of property nvlist
2023 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2029 if (zc
->zc_cookie
== 0 && !zc
->zc_simple
)
2030 (void) dmu_objset_find(zc
->zc_name
, dmu_objset_prefetch
,
2031 NULL
, DS_FIND_SNAPSHOTS
);
2033 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2035 return (error
== ENOENT
? ESRCH
: error
);
2038 * A dataset name of maximum length cannot have any snapshots,
2039 * so exit immediately.
2041 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >= MAXNAMELEN
) {
2042 dmu_objset_rele(os
, FTAG
);
2046 error
= dmu_snapshot_list_next(os
,
2047 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2048 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2051 if (error
== 0 && !zc
->zc_simple
) {
2053 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2056 * Since we probably don't have a hold on this snapshot,
2057 * it's possible that the objsetid could have been destroyed
2058 * and reused for a new objset. It's OK if this happens during
2059 * a zfs send operation, since the new createtxg will be
2060 * beyond the range we're interested in.
2062 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
2063 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2064 rw_exit(&dp
->dp_config_rwlock
);
2066 if (error
== ENOENT
) {
2067 /* Racing with destroy, get the next one. */
2068 *strchr(zc
->zc_name
, '@') = '\0';
2069 dmu_objset_rele(os
, FTAG
);
2075 error
= dmu_objset_from_ds(ds
, &ossnap
);
2077 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2078 dsl_dataset_rele(ds
, FTAG
);
2080 } else if (error
== ENOENT
) {
2084 dmu_objset_rele(os
, FTAG
);
2085 /* if we failed, undo the @ that we tacked on to zc_name */
2087 *strchr(zc
->zc_name
, '@') = '\0';
2092 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2094 const char *propname
= nvpair_name(pair
);
2096 unsigned int vallen
;
2099 zfs_userquota_prop_t type
;
2105 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2107 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2108 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2114 * A correctly constructed propname is encoded as
2115 * userquota@<rid>-<domain>.
2117 if ((dash
= strchr(propname
, '-')) == NULL
||
2118 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2127 err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
2129 err
= zfs_set_userquota(zsb
, type
, domain
, rid
, quota
);
2130 zfs_sb_rele(zsb
, FTAG
);
2137 * If the named property is one that has a special function to set its value,
2138 * return 0 on success and a positive error code on failure; otherwise if it is
2139 * not one of the special properties handled by this function, return -1.
2141 * XXX: It would be better for callers of the property interface if we handled
2142 * these special cases in dsl_prop.c (in the dsl layer).
2145 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2148 const char *propname
= nvpair_name(pair
);
2149 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2153 if (prop
== ZPROP_INVAL
) {
2154 if (zfs_prop_userquota(propname
))
2155 return (zfs_prop_set_userquota(dsname
, pair
));
2159 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2161 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2162 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2166 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2169 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2172 case ZFS_PROP_QUOTA
:
2173 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2175 case ZFS_PROP_REFQUOTA
:
2176 err
= dsl_dataset_set_quota(dsname
, source
, intval
);
2178 case ZFS_PROP_RESERVATION
:
2179 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2181 case ZFS_PROP_REFRESERVATION
:
2182 err
= dsl_dataset_set_reservation(dsname
, source
, intval
);
2184 case ZFS_PROP_VOLSIZE
:
2185 err
= zvol_set_volsize(dsname
, intval
);
2187 case ZFS_PROP_VERSION
:
2191 if ((err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_TRUE
)) != 0)
2194 err
= zfs_set_version(zsb
, intval
);
2195 zfs_sb_rele(zsb
, FTAG
);
2197 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2200 zc
= kmem_zalloc(sizeof (zfs_cmd_t
),
2201 KM_SLEEP
| KM_NODEBUG
);
2202 (void) strcpy(zc
->zc_name
, dsname
);
2203 (void) zfs_ioc_userspace_upgrade(zc
);
2204 kmem_free(zc
, sizeof (zfs_cmd_t
));
2208 case ZFS_PROP_COMPRESSION
:
2210 if (intval
== ZIO_COMPRESS_LZ4
) {
2211 zfeature_info_t
*feature
=
2212 &spa_feature_table
[SPA_FEATURE_LZ4_COMPRESS
];
2216 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
2219 dp
= spa
->spa_dsl_pool
;
2222 * Setting the LZ4 compression algorithm activates
2225 if (!spa_feature_is_active(spa
, feature
)) {
2226 if ((err
= zfs_prop_activate_feature(dp
,
2228 spa_close(spa
, FTAG
);
2233 spa_close(spa
, FTAG
);
2236 * We still want the default set action to be performed in the
2237 * caller, we only performed zfeature settings here.
2251 * This function is best effort. If it fails to set any of the given properties,
2252 * it continues to set as many as it can and returns the first error
2253 * encountered. If the caller provides a non-NULL errlist, it also gives the
2254 * complete list of names of all the properties it failed to set along with the
2255 * corresponding error numbers. The caller is responsible for freeing the
2258 * If every property is set successfully, zero is returned and the list pointed
2259 * at by errlist is NULL.
2262 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2270 nvlist_t
*genericnvl
;
2274 VERIFY(nvlist_alloc(&genericnvl
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2275 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2276 VERIFY(nvlist_alloc(&retrynvl
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2280 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2281 const char *propname
= nvpair_name(pair
);
2282 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2285 /* decode the property value */
2287 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2289 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2290 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2295 /* Validate value type */
2296 if (err
== 0 && prop
== ZPROP_INVAL
) {
2297 if (zfs_prop_user(propname
)) {
2298 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2300 } else if (zfs_prop_userquota(propname
)) {
2301 if (nvpair_type(propval
) !=
2302 DATA_TYPE_UINT64_ARRAY
)
2307 } else if (err
== 0) {
2308 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2309 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2311 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2314 VERIFY(nvpair_value_uint64(propval
,
2317 switch (zfs_prop_get_type(prop
)) {
2318 case PROP_TYPE_NUMBER
:
2320 case PROP_TYPE_STRING
:
2323 case PROP_TYPE_INDEX
:
2324 if (zfs_prop_index_to_string(prop
,
2325 intval
, &unused
) != 0)
2330 "unknown property type");
2337 /* Validate permissions */
2339 err
= zfs_check_settable(dsname
, pair
, CRED());
2342 err
= zfs_prop_set_special(dsname
, source
, pair
);
2345 * For better performance we build up a list of
2346 * properties to set in a single transaction.
2348 err
= nvlist_add_nvpair(genericnvl
, pair
);
2349 } else if (err
!= 0 && nvl
!= retrynvl
) {
2351 * This may be a spurious error caused by
2352 * receiving quota and reservation out of order.
2353 * Try again in a second pass.
2355 err
= nvlist_add_nvpair(retrynvl
, pair
);
2360 VERIFY(nvlist_add_int32(errors
, propname
, err
) == 0);
2363 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2368 if (!nvlist_empty(genericnvl
) &&
2369 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2371 * If this fails, we still want to set as many properties as we
2372 * can, so try setting them individually.
2375 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2376 const char *propname
= nvpair_name(pair
);
2380 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2382 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2383 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2387 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2388 VERIFY(nvpair_value_string(propval
,
2390 err
= dsl_prop_set(dsname
, propname
, source
, 1,
2391 strlen(strval
) + 1, strval
);
2393 VERIFY(nvpair_value_uint64(propval
,
2395 err
= dsl_prop_set(dsname
, propname
, source
, 8,
2400 VERIFY(nvlist_add_int32(errors
, propname
,
2405 nvlist_free(genericnvl
);
2406 nvlist_free(retrynvl
);
2408 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
2409 nvlist_free(errors
);
2412 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
2415 if (errlist
== NULL
)
2416 nvlist_free(errors
);
2424 * Check that all the properties are valid user properties.
2427 zfs_check_userprops(char *fsname
, nvlist_t
*nvl
)
2429 nvpair_t
*pair
= NULL
;
2432 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2433 const char *propname
= nvpair_name(pair
);
2436 if (!zfs_prop_user(propname
) ||
2437 nvpair_type(pair
) != DATA_TYPE_STRING
)
2440 if ((error
= zfs_secpolicy_write_perms(fsname
,
2441 ZFS_DELEG_PERM_USERPROP
, CRED())))
2444 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2445 return (ENAMETOOLONG
);
2447 VERIFY(nvpair_value_string(pair
, &valstr
) == 0);
2448 if (strlen(valstr
) >= ZAP_MAXVALUELEN
)
2455 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2459 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2462 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2463 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2466 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2471 clear_received_props(objset_t
*os
, const char *fs
, nvlist_t
*props
,
2475 nvlist_t
*cleared_props
= NULL
;
2476 props_skip(props
, skipped
, &cleared_props
);
2477 if (!nvlist_empty(cleared_props
)) {
2479 * Acts on local properties until the dataset has received
2480 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2482 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2483 (dsl_prop_get_hasrecvd(os
) ? ZPROP_SRC_RECEIVED
: 0));
2484 err
= zfs_set_prop_nvlist(fs
, flags
, cleared_props
, NULL
);
2486 nvlist_free(cleared_props
);
2492 * zc_name name of filesystem
2493 * zc_value name of property to set
2494 * zc_nvlist_src{_size} nvlist of properties to apply
2495 * zc_cookie received properties flag
2498 * zc_nvlist_dst{_size} error for each unapplied received property
2501 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2504 boolean_t received
= zc
->zc_cookie
;
2505 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2507 nvlist_t
*errors
= NULL
;
2510 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2511 zc
->zc_iflags
, &nvl
)) != 0)
2515 nvlist_t
*origprops
;
2518 if (dmu_objset_hold(zc
->zc_name
, FTAG
, &os
) == 0) {
2519 if (dsl_prop_get_received(os
, &origprops
) == 0) {
2520 (void) clear_received_props(os
,
2521 zc
->zc_name
, origprops
, nvl
);
2522 nvlist_free(origprops
);
2525 dsl_prop_set_hasrecvd(os
);
2526 dmu_objset_rele(os
, FTAG
);
2530 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, &errors
);
2532 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2533 (void) put_nvlist(zc
, errors
);
2536 nvlist_free(errors
);
2543 * zc_name name of filesystem
2544 * zc_value name of property to inherit
2545 * zc_cookie revert to received value if TRUE
2550 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2552 const char *propname
= zc
->zc_value
;
2553 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2554 boolean_t received
= zc
->zc_cookie
;
2555 zprop_source_t source
= (received
2556 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2557 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2566 * zfs_prop_set_special() expects properties in the form of an
2567 * nvpair with type info.
2569 if (prop
== ZPROP_INVAL
) {
2570 if (!zfs_prop_user(propname
))
2573 type
= PROP_TYPE_STRING
;
2574 } else if (prop
== ZFS_PROP_VOLSIZE
||
2575 prop
== ZFS_PROP_VERSION
) {
2578 type
= zfs_prop_get_type(prop
);
2581 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2584 case PROP_TYPE_STRING
:
2585 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2587 case PROP_TYPE_NUMBER
:
2588 case PROP_TYPE_INDEX
:
2589 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2596 pair
= nvlist_next_nvpair(dummy
, NULL
);
2597 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2600 return (err
); /* special property already handled */
2603 * Only check this in the non-received case. We want to allow
2604 * 'inherit -S' to revert non-inheritable properties like quota
2605 * and reservation to the received or default values even though
2606 * they are not considered inheritable.
2608 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2612 /* the property name has been validated by zfs_secpolicy_inherit() */
2613 return (dsl_prop_set(zc
->zc_name
, zc
->zc_value
, source
, 0, 0, NULL
));
2617 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2624 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2625 zc
->zc_iflags
, &props
)))
2629 * If the only property is the configfile, then just do a spa_lookup()
2630 * to handle the faulted case.
2632 pair
= nvlist_next_nvpair(props
, NULL
);
2633 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2634 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2635 nvlist_next_nvpair(props
, pair
) == NULL
) {
2636 mutex_enter(&spa_namespace_lock
);
2637 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2638 spa_configfile_set(spa
, props
, B_FALSE
);
2639 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2641 mutex_exit(&spa_namespace_lock
);
2648 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2653 error
= spa_prop_set(spa
, props
);
2656 spa_close(spa
, FTAG
);
2662 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2666 nvlist_t
*nvp
= NULL
;
2668 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2670 * If the pool is faulted, there may be properties we can still
2671 * get (such as altroot and cachefile), so attempt to get them
2674 mutex_enter(&spa_namespace_lock
);
2675 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2676 error
= spa_prop_get(spa
, &nvp
);
2677 mutex_exit(&spa_namespace_lock
);
2679 error
= spa_prop_get(spa
, &nvp
);
2680 spa_close(spa
, FTAG
);
2683 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2684 error
= put_nvlist(zc
, nvp
);
2694 * zc_name name of volume
2699 zfs_ioc_create_minor(zfs_cmd_t
*zc
)
2701 return (zvol_create_minor(zc
->zc_name
));
2706 * zc_name name of volume
2711 zfs_ioc_remove_minor(zfs_cmd_t
*zc
)
2713 return (zvol_remove_minor(zc
->zc_name
));
2718 * zc_name name of filesystem
2719 * zc_nvlist_src{_size} nvlist of delegated permissions
2720 * zc_perm_action allow/unallow flag
2725 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2728 nvlist_t
*fsaclnv
= NULL
;
2730 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2731 zc
->zc_iflags
, &fsaclnv
)) != 0)
2735 * Verify nvlist is constructed correctly
2737 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2738 nvlist_free(fsaclnv
);
2743 * If we don't have PRIV_SYS_MOUNT, then validate
2744 * that user is allowed to hand out each permission in
2748 error
= secpolicy_zfs(CRED());
2750 if (zc
->zc_perm_action
== B_FALSE
) {
2751 error
= dsl_deleg_can_allow(zc
->zc_name
,
2754 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2760 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2762 nvlist_free(fsaclnv
);
2768 * zc_name name of filesystem
2771 * zc_nvlist_src{_size} nvlist of delegated permissions
2774 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2779 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2780 error
= put_nvlist(zc
, nvp
);
2789 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2791 zfs_creat_t
*zct
= arg
;
2793 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2796 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2800 * createprops list of properties requested by creator
2801 * default_zplver zpl version to use if unspecified in createprops
2802 * fuids_ok fuids allowed in this version of the spa?
2803 * os parent objset pointer (NULL if root fs)
2806 * zplprops values for the zplprops we attach to the master node object
2807 * is_ci true if requested file system will be purely case-insensitive
2809 * Determine the settings for utf8only, normalization and
2810 * casesensitivity. Specific values may have been requested by the
2811 * creator and/or we can inherit values from the parent dataset. If
2812 * the file system is of too early a vintage, a creator can not
2813 * request settings for these properties, even if the requested
2814 * setting is the default value. We don't actually want to create dsl
2815 * properties for these, so remove them from the source nvlist after
2819 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2820 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2821 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2823 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2824 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2825 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2828 ASSERT(zplprops
!= NULL
);
2831 * Pull out creator prop choices, if any.
2834 (void) nvlist_lookup_uint64(createprops
,
2835 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2836 (void) nvlist_lookup_uint64(createprops
,
2837 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2838 (void) nvlist_remove_all(createprops
,
2839 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2840 (void) nvlist_lookup_uint64(createprops
,
2841 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2842 (void) nvlist_remove_all(createprops
,
2843 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2844 (void) nvlist_lookup_uint64(createprops
,
2845 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2846 (void) nvlist_remove_all(createprops
,
2847 zfs_prop_to_name(ZFS_PROP_CASE
));
2851 * If the zpl version requested is whacky or the file system
2852 * or pool is version is too "young" to support normalization
2853 * and the creator tried to set a value for one of the props,
2856 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
2857 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
2858 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
2859 (zplver
< ZPL_VERSION_NORMALIZATION
&&
2860 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
2861 sense
!= ZFS_PROP_UNDEFINED
)))
2865 * Put the version in the zplprops
2867 VERIFY(nvlist_add_uint64(zplprops
,
2868 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
2870 if (norm
== ZFS_PROP_UNDEFINED
&&
2871 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
2873 VERIFY(nvlist_add_uint64(zplprops
,
2874 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
2877 * If we're normalizing, names must always be valid UTF-8 strings.
2881 if (u8
== ZFS_PROP_UNDEFINED
&&
2882 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
2884 VERIFY(nvlist_add_uint64(zplprops
,
2885 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
2887 if (sense
== ZFS_PROP_UNDEFINED
&&
2888 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
2890 VERIFY(nvlist_add_uint64(zplprops
,
2891 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
2894 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
2900 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
2901 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2903 boolean_t fuids_ok
, sa_ok
;
2904 uint64_t zplver
= ZPL_VERSION
;
2905 objset_t
*os
= NULL
;
2906 char parentname
[MAXNAMELEN
];
2912 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
2913 cp
= strrchr(parentname
, '/');
2917 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
2920 spa_vers
= spa_version(spa
);
2921 spa_close(spa
, FTAG
);
2923 zplver
= zfs_zpl_version_map(spa_vers
);
2924 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
2925 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
2928 * Open parent object set so we can inherit zplprop values.
2930 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
2933 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
2935 dmu_objset_rele(os
, FTAG
);
2940 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
2941 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2945 uint64_t zplver
= ZPL_VERSION
;
2948 zplver
= zfs_zpl_version_map(spa_vers
);
2949 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
2950 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
2952 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
2953 createprops
, zplprops
, is_ci
);
2959 * zc_objset_type type of objset to create (fs vs zvol)
2960 * zc_name name of new objset
2961 * zc_value name of snapshot to clone from (may be empty)
2962 * zc_nvlist_src{_size} nvlist of properties to apply
2967 zfs_ioc_create(zfs_cmd_t
*zc
)
2972 nvlist_t
*nvprops
= NULL
;
2973 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
2974 dmu_objset_type_t type
= zc
->zc_objset_type
;
2979 cbfunc
= zfs_create_cb
;
2983 cbfunc
= zvol_create_cb
;
2990 if (strchr(zc
->zc_name
, '@') ||
2991 strchr(zc
->zc_name
, '%'))
2994 if (zc
->zc_nvlist_src
!= 0 &&
2995 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2996 zc
->zc_iflags
, &nvprops
)) != 0)
2999 zct
.zct_zplprops
= NULL
;
3000 zct
.zct_props
= nvprops
;
3002 if (zc
->zc_value
[0] != '\0') {
3004 * We're creating a clone of an existing snapshot.
3006 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3007 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0) {
3008 nvlist_free(nvprops
);
3012 error
= dmu_objset_hold(zc
->zc_value
, FTAG
, &clone
);
3014 nvlist_free(nvprops
);
3018 error
= dmu_objset_clone(zc
->zc_name
, dmu_objset_ds(clone
), 0);
3019 dmu_objset_rele(clone
, FTAG
);
3021 nvlist_free(nvprops
);
3025 boolean_t is_insensitive
= B_FALSE
;
3027 if (cbfunc
== NULL
) {
3028 nvlist_free(nvprops
);
3032 if (type
== DMU_OST_ZVOL
) {
3033 uint64_t volsize
, volblocksize
;
3035 if (nvprops
== NULL
||
3036 nvlist_lookup_uint64(nvprops
,
3037 zfs_prop_to_name(ZFS_PROP_VOLSIZE
),
3039 nvlist_free(nvprops
);
3043 if ((error
= nvlist_lookup_uint64(nvprops
,
3044 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3045 &volblocksize
)) != 0 && error
!= ENOENT
) {
3046 nvlist_free(nvprops
);
3051 volblocksize
= zfs_prop_default_numeric(
3052 ZFS_PROP_VOLBLOCKSIZE
);
3054 if ((error
= zvol_check_volblocksize(
3055 volblocksize
)) != 0 ||
3056 (error
= zvol_check_volsize(volsize
,
3057 volblocksize
)) != 0) {
3058 nvlist_free(nvprops
);
3061 } else if (type
== DMU_OST_ZFS
) {
3065 * We have to have normalization and
3066 * case-folding flags correct when we do the
3067 * file system creation, so go figure them out
3070 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3071 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3072 error
= zfs_fill_zplprops(zc
->zc_name
, nvprops
,
3073 zct
.zct_zplprops
, &is_insensitive
);
3075 nvlist_free(nvprops
);
3076 nvlist_free(zct
.zct_zplprops
);
3080 error
= dmu_objset_create(zc
->zc_name
, type
,
3081 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3082 nvlist_free(zct
.zct_zplprops
);
3086 * It would be nice to do this atomically.
3089 error
= zfs_set_prop_nvlist(zc
->zc_name
, ZPROP_SRC_LOCAL
,
3092 (void) dmu_objset_destroy(zc
->zc_name
, B_FALSE
);
3094 nvlist_free(nvprops
);
3100 * zc_name name of filesystem
3101 * zc_value short name of snapshot
3102 * zc_cookie recursive flag
3103 * zc_nvlist_src[_size] property list
3106 * zc_value short snapname (i.e. part after the '@')
3109 zfs_ioc_snapshot(zfs_cmd_t
*zc
)
3111 nvlist_t
*nvprops
= NULL
;
3113 boolean_t recursive
= zc
->zc_cookie
;
3115 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
3118 if (zc
->zc_nvlist_src
!= 0 &&
3119 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3120 zc
->zc_iflags
, &nvprops
)) != 0)
3123 error
= zfs_check_userprops(zc
->zc_name
, nvprops
);
3127 if (!nvlist_empty(nvprops
) &&
3128 zfs_earlier_version(zc
->zc_name
, SPA_VERSION_SNAP_PROPS
)) {
3133 error
= dmu_objset_snapshot(zc
->zc_name
, zc
->zc_value
, NULL
,
3134 nvprops
, recursive
, B_FALSE
, -1);
3137 nvlist_free(nvprops
);
3143 * name dataset name, or when 'arg == NULL' the full snapshot name
3144 * arg short snapshot name (i.e. part after the '@')
3147 zfs_unmount_snap(const char *name
, void *arg
)
3149 zfs_sb_t
*zsb
= NULL
;
3157 dsname
= strdup(name
);
3158 snapname
= strdup(arg
);
3160 ptr
= strchr(name
, '@');
3162 dsname
= strdup(name
);
3163 dsname
[ptr
- name
] = '\0';
3164 snapname
= strdup(ptr
+ 1);
3170 fullname
= kmem_asprintf("%s@%s", dsname
, snapname
);
3172 error
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
3174 error
= zfsctl_unmount_snapshot(zsb
, fullname
, MNT_FORCE
);
3175 zfs_sb_rele(zsb
, FTAG
);
3177 /* Allow ENOENT for consistency with upstream */
3178 if (error
== ENOENT
)
3191 * zc_name name of filesystem, snaps must be under it
3192 * zc_nvlist_src[_size] full names of snapshots to destroy
3193 * zc_defer_destroy mark for deferred destroy
3196 * zc_name on failure, name of failed snapshot
3199 zfs_ioc_destroy_snaps_nvl(zfs_cmd_t
*zc
)
3205 if ((err
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3206 zc
->zc_iflags
, &nvl
)) != 0)
3209 len
= strlen(zc
->zc_name
);
3210 for (pair
= nvlist_next_nvpair(nvl
, NULL
); pair
!= NULL
;
3211 pair
= nvlist_next_nvpair(nvl
, pair
)) {
3212 const char *name
= nvpair_name(pair
);
3214 * The snap name must be underneath the zc_name. This ensures
3215 * that our permission checks were legitimate.
3217 if (strncmp(zc
->zc_name
, name
, len
) != 0 ||
3218 (name
[len
] != '@' && name
[len
] != '/')) {
3223 (void) zfs_unmount_snap(name
, NULL
);
3224 (void) zvol_remove_minor(name
);
3227 err
= dmu_snapshots_destroy_nvl(nvl
, zc
->zc_defer_destroy
,
3235 * zc_name name of dataset to destroy
3236 * zc_objset_type type of objset
3237 * zc_defer_destroy mark for deferred destroy
3242 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3245 if (strchr(zc
->zc_name
, '@') && zc
->zc_objset_type
== DMU_OST_ZFS
) {
3246 err
= zfs_unmount_snap(zc
->zc_name
, NULL
);
3251 err
= dmu_objset_destroy(zc
->zc_name
, zc
->zc_defer_destroy
);
3252 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3253 (void) zvol_remove_minor(zc
->zc_name
);
3259 * zc_name name of dataset to rollback (to most recent snapshot)
3264 zfs_ioc_rollback(zfs_cmd_t
*zc
)
3266 dsl_dataset_t
*ds
, *clone
;
3271 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &ds
);
3275 /* must not be a snapshot */
3276 if (dsl_dataset_is_snapshot(ds
)) {
3277 dsl_dataset_rele(ds
, FTAG
);
3281 /* must have a most recent snapshot */
3282 if (ds
->ds_phys
->ds_prev_snap_txg
< TXG_INITIAL
) {
3283 dsl_dataset_rele(ds
, FTAG
);
3288 * Create clone of most recent snapshot.
3290 clone_name
= kmem_asprintf("%s/%%rollback", zc
->zc_name
);
3291 error
= dmu_objset_clone(clone_name
, ds
->ds_prev
, DS_FLAG_INCONSISTENT
);
3295 error
= dsl_dataset_own(clone_name
, B_TRUE
, FTAG
, &clone
);
3302 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
3303 error
= zfs_suspend_fs(zsb
);
3307 if (dsl_dataset_tryown(ds
, B_FALSE
, FTAG
)) {
3308 error
= dsl_dataset_clone_swap(clone
, ds
,
3310 dsl_dataset_disown(ds
, FTAG
);
3315 resume_err
= zfs_resume_fs(zsb
, zc
->zc_name
);
3316 error
= error
? error
: resume_err
;
3318 deactivate_super(zsb
->z_sb
);
3320 if (dsl_dataset_tryown(ds
, B_FALSE
, FTAG
)) {
3321 error
= dsl_dataset_clone_swap(clone
, ds
, B_TRUE
);
3322 dsl_dataset_disown(ds
, FTAG
);
3330 * Destroy clone (which also closes it).
3332 (void) dsl_dataset_destroy(clone
, FTAG
, B_FALSE
);
3335 strfree(clone_name
);
3337 dsl_dataset_rele(ds
, FTAG
);
3343 * zc_name old name of dataset
3344 * zc_value new name of dataset
3345 * zc_cookie recursive flag (only valid for snapshots)
3350 zfs_ioc_rename(zfs_cmd_t
*zc
)
3352 boolean_t recursive
= zc
->zc_cookie
& 1;
3355 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3356 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3357 strchr(zc
->zc_value
, '%'))
3361 * Unmount snapshot unless we're doing a recursive rename,
3362 * in which case the dataset code figures out which snapshots
3365 if (!recursive
&& strchr(zc
->zc_name
, '@') != NULL
&&
3366 zc
->zc_objset_type
== DMU_OST_ZFS
) {
3367 err
= zfs_unmount_snap(zc
->zc_name
, NULL
);
3372 err
= dmu_objset_rename(zc
->zc_name
, zc
->zc_value
, recursive
);
3373 if ((err
== 0) && (zc
->zc_objset_type
== DMU_OST_ZVOL
)) {
3374 (void) zvol_remove_minor(zc
->zc_name
);
3375 (void) zvol_create_minor(zc
->zc_value
);
3382 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3384 const char *propname
= nvpair_name(pair
);
3385 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3386 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3390 if (prop
== ZPROP_INVAL
) {
3391 if (zfs_prop_user(propname
)) {
3392 if ((err
= zfs_secpolicy_write_perms(dsname
,
3393 ZFS_DELEG_PERM_USERPROP
, cr
)))
3398 if (!issnap
&& zfs_prop_userquota(propname
)) {
3399 const char *perm
= NULL
;
3400 const char *uq_prefix
=
3401 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3402 const char *gq_prefix
=
3403 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3405 if (strncmp(propname
, uq_prefix
,
3406 strlen(uq_prefix
)) == 0) {
3407 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3408 } else if (strncmp(propname
, gq_prefix
,
3409 strlen(gq_prefix
)) == 0) {
3410 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3412 /* USERUSED and GROUPUSED are read-only */
3416 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3427 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3429 * dsl_prop_get_all_impl() returns properties in this
3433 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3434 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3439 * Check that this value is valid for this pool version
3442 case ZFS_PROP_COMPRESSION
:
3444 * If the user specified gzip compression, make sure
3445 * the SPA supports it. We ignore any errors here since
3446 * we'll catch them later.
3448 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3449 nvpair_value_uint64(pair
, &intval
) == 0) {
3450 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3451 intval
<= ZIO_COMPRESS_GZIP_9
&&
3452 zfs_earlier_version(dsname
,
3453 SPA_VERSION_GZIP_COMPRESSION
)) {
3457 if (intval
== ZIO_COMPRESS_ZLE
&&
3458 zfs_earlier_version(dsname
,
3459 SPA_VERSION_ZLE_COMPRESSION
))
3462 if (intval
== ZIO_COMPRESS_LZ4
) {
3463 zfeature_info_t
*feature
=
3465 SPA_FEATURE_LZ4_COMPRESS
];
3468 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3471 if (!spa_feature_is_enabled(spa
, feature
)) {
3472 spa_close(spa
, FTAG
);
3475 spa_close(spa
, FTAG
);
3479 * If this is a bootable dataset then
3480 * verify that the compression algorithm
3481 * is supported for booting. We must return
3482 * something other than ENOTSUP since it
3483 * implies a downrev pool version.
3485 if (zfs_is_bootfs(dsname
) &&
3486 !BOOTFS_COMPRESS_VALID(intval
)) {
3492 case ZFS_PROP_COPIES
:
3493 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3497 case ZFS_PROP_DEDUP
:
3498 if (zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3502 case ZFS_PROP_SHARESMB
:
3503 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3507 case ZFS_PROP_ACLINHERIT
:
3508 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3509 nvpair_value_uint64(pair
, &intval
) == 0) {
3510 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3511 zfs_earlier_version(dsname
,
3512 SPA_VERSION_PASSTHROUGH_X
))
3520 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3524 * Activates a feature on a pool in response to a property setting. This
3525 * creates a new sync task which modifies the pool to reflect the feature
3529 zfs_prop_activate_feature(dsl_pool_t
*dp
, zfeature_info_t
*feature
)
3533 /* EBUSY here indicates that the feature is already active */
3534 err
= dsl_sync_task_do(dp
, zfs_prop_activate_feature_check
,
3535 zfs_prop_activate_feature_sync
, dp
->dp_spa
, feature
, 2);
3537 if (err
!= 0 && err
!= EBUSY
)
3544 * Checks for a race condition to make sure we don't increment a feature flag
3549 zfs_prop_activate_feature_check(void *arg1
, void *arg2
, dmu_tx_t
*tx
)
3552 zfeature_info_t
*feature
= arg2
;
3554 if (!spa_feature_is_active(spa
, feature
))
3561 * The callback invoked on feature activation in the sync task caused by
3562 * zfs_prop_activate_feature.
3565 zfs_prop_activate_feature_sync(void *arg1
, void *arg2
, dmu_tx_t
*tx
)
3568 zfeature_info_t
*feature
= arg2
;
3570 spa_feature_incr(spa
, feature
, tx
);
3574 * Removes properties from the given props list that fail permission checks
3575 * needed to clear them and to restore them in case of a receive error. For each
3576 * property, make sure we have both set and inherit permissions.
3578 * Returns the first error encountered if any permission checks fail. If the
3579 * caller provides a non-NULL errlist, it also gives the complete list of names
3580 * of all the properties that failed a permission check along with the
3581 * corresponding error numbers. The caller is responsible for freeing the
3584 * If every property checks out successfully, zero is returned and the list
3585 * pointed at by errlist is NULL.
3588 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3591 nvpair_t
*pair
, *next_pair
;
3598 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3600 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
3601 (void) strcpy(zc
->zc_name
, dataset
);
3602 pair
= nvlist_next_nvpair(props
, NULL
);
3603 while (pair
!= NULL
) {
3604 next_pair
= nvlist_next_nvpair(props
, pair
);
3606 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3607 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3608 (err
= zfs_secpolicy_inherit(zc
, CRED())) != 0) {
3609 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3610 VERIFY(nvlist_add_int32(errors
,
3611 zc
->zc_value
, err
) == 0);
3615 kmem_free(zc
, sizeof (zfs_cmd_t
));
3617 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3618 nvlist_free(errors
);
3621 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3624 if (errlist
== NULL
)
3625 nvlist_free(errors
);
3633 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3635 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3636 /* dsl_prop_get_all_impl() format */
3638 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3639 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3643 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3645 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3646 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3650 if (nvpair_type(p1
) != nvpair_type(p2
))
3653 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
3654 char *valstr1
, *valstr2
;
3656 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
3657 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
3658 return (strcmp(valstr1
, valstr2
) == 0);
3660 uint64_t intval1
, intval2
;
3662 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
3663 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
3664 return (intval1
== intval2
);
3669 * Remove properties from props if they are not going to change (as determined
3670 * by comparison with origprops). Remove them from origprops as well, since we
3671 * do not need to clear or restore properties that won't change.
3674 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
3676 nvpair_t
*pair
, *next_pair
;
3678 if (origprops
== NULL
)
3679 return; /* all props need to be received */
3681 pair
= nvlist_next_nvpair(props
, NULL
);
3682 while (pair
!= NULL
) {
3683 const char *propname
= nvpair_name(pair
);
3686 next_pair
= nvlist_next_nvpair(props
, pair
);
3688 if ((nvlist_lookup_nvpair(origprops
, propname
,
3689 &match
) != 0) || !propval_equals(pair
, match
))
3690 goto next
; /* need to set received value */
3692 /* don't clear the existing received value */
3693 (void) nvlist_remove_nvpair(origprops
, match
);
3694 /* don't bother receiving the property */
3695 (void) nvlist_remove_nvpair(props
, pair
);
3702 static boolean_t zfs_ioc_recv_inject_err
;
3707 * zc_name name of containing filesystem
3708 * zc_nvlist_src{_size} nvlist of properties to apply
3709 * zc_value name of snapshot to create
3710 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3711 * zc_cookie file descriptor to recv from
3712 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3713 * zc_guid force flag
3714 * zc_cleanup_fd cleanup-on-exit file descriptor
3715 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
3718 * zc_cookie number of bytes read
3719 * zc_nvlist_dst{_size} error for each unapplied received property
3720 * zc_obj zprop_errflags_t
3721 * zc_action_handle handle for this guid/ds mapping
3724 zfs_ioc_recv(zfs_cmd_t
*zc
)
3728 dmu_recv_cookie_t drc
;
3729 boolean_t force
= (boolean_t
)zc
->zc_guid
;
3732 int props_error
= 0;
3735 nvlist_t
*props
= NULL
; /* sent properties */
3736 nvlist_t
*origprops
= NULL
; /* existing properties */
3737 objset_t
*origin
= NULL
;
3739 char tofs
[ZFS_MAXNAMELEN
];
3740 boolean_t first_recvd_props
= B_FALSE
;
3742 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3743 strchr(zc
->zc_value
, '@') == NULL
||
3744 strchr(zc
->zc_value
, '%'))
3747 (void) strcpy(tofs
, zc
->zc_value
);
3748 tosnap
= strchr(tofs
, '@');
3751 if (zc
->zc_nvlist_src
!= 0 &&
3752 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3753 zc
->zc_iflags
, &props
)) != 0)
3763 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3765 if (props
&& dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
3766 if ((spa_version(os
->os_spa
) >= SPA_VERSION_RECVD_PROPS
) &&
3767 !dsl_prop_get_hasrecvd(os
)) {
3768 first_recvd_props
= B_TRUE
;
3772 * If new received properties are supplied, they are to
3773 * completely replace the existing received properties, so stash
3774 * away the existing ones.
3776 if (dsl_prop_get_received(os
, &origprops
) == 0) {
3777 nvlist_t
*errlist
= NULL
;
3779 * Don't bother writing a property if its value won't
3780 * change (and avoid the unnecessary security checks).
3782 * The first receive after SPA_VERSION_RECVD_PROPS is a
3783 * special case where we blow away all local properties
3786 if (!first_recvd_props
)
3787 props_reduce(props
, origprops
);
3788 if (zfs_check_clearable(tofs
, origprops
,
3790 (void) nvlist_merge(errors
, errlist
, 0);
3791 nvlist_free(errlist
);
3794 dmu_objset_rele(os
, FTAG
);
3797 if (zc
->zc_string
[0]) {
3798 error
= dmu_objset_hold(zc
->zc_string
, FTAG
, &origin
);
3803 error
= dmu_recv_begin(tofs
, tosnap
, zc
->zc_top_ds
,
3804 &zc
->zc_begin_record
, force
, origin
, &drc
);
3806 dmu_objset_rele(origin
, FTAG
);
3811 * Set properties before we receive the stream so that they are applied
3812 * to the new data. Note that we must call dmu_recv_stream() if
3813 * dmu_recv_begin() succeeds.
3818 if (dmu_objset_from_ds(drc
.drc_logical_ds
, &os
) == 0) {
3819 if (drc
.drc_newfs
) {
3820 if (spa_version(os
->os_spa
) >=
3821 SPA_VERSION_RECVD_PROPS
)
3822 first_recvd_props
= B_TRUE
;
3823 } else if (origprops
!= NULL
) {
3824 if (clear_received_props(os
, tofs
, origprops
,
3825 first_recvd_props
? NULL
: props
) != 0)
3826 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3828 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3830 dsl_prop_set_hasrecvd(os
);
3831 } else if (!drc
.drc_newfs
) {
3832 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3835 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
3837 (void) nvlist_merge(errors
, errlist
, 0);
3838 nvlist_free(errlist
);
3841 if (fit_error_list(zc
, &errors
) != 0 || put_nvlist(zc
, errors
) != 0) {
3843 * Caller made zc->zc_nvlist_dst less than the minimum expected
3844 * size or supplied an invalid address.
3846 props_error
= EINVAL
;
3850 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
3851 &zc
->zc_action_handle
);
3854 zfs_sb_t
*zsb
= NULL
;
3856 if (get_zfs_sb(tofs
, &zsb
) == 0) {
3860 error
= zfs_suspend_fs(zsb
);
3862 * If the suspend fails, then the recv_end will
3863 * likely also fail, and clean up after itself.
3865 end_err
= dmu_recv_end(&drc
);
3867 error
= zfs_resume_fs(zsb
, tofs
);
3868 error
= error
? error
: end_err
;
3869 deactivate_super(zsb
->z_sb
);
3871 error
= dmu_recv_end(&drc
);
3875 zc
->zc_cookie
= off
- fp
->f_offset
;
3876 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
3880 if (zfs_ioc_recv_inject_err
) {
3881 zfs_ioc_recv_inject_err
= B_FALSE
;
3886 * On error, restore the original props.
3888 if (error
&& props
) {
3889 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
3890 if (clear_received_props(os
, tofs
, props
, NULL
) != 0) {
3892 * We failed to clear the received properties.
3893 * Since we may have left a $recvd value on the
3894 * system, we can't clear the $hasrecvd flag.
3896 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3897 } else if (first_recvd_props
) {
3898 dsl_prop_unset_hasrecvd(os
);
3900 dmu_objset_rele(os
, FTAG
);
3901 } else if (!drc
.drc_newfs
) {
3902 /* We failed to clear the received properties. */
3903 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3906 if (origprops
== NULL
&& !drc
.drc_newfs
) {
3907 /* We failed to stash the original properties. */
3908 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3912 * dsl_props_set() will not convert RECEIVED to LOCAL on or
3913 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
3914 * explictly if we're restoring local properties cleared in the
3915 * first new-style receive.
3917 if (origprops
!= NULL
&&
3918 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
3919 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
3920 origprops
, NULL
) != 0) {
3922 * We stashed the original properties but failed to
3925 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3930 nvlist_free(origprops
);
3931 nvlist_free(errors
);
3935 error
= props_error
;
3942 * zc_name name of snapshot to send
3943 * zc_cookie file descriptor to send stream to
3944 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
3945 * zc_sendobj objsetid of snapshot to send
3946 * zc_fromobj objsetid of incremental fromsnap (may be zero)
3947 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
3948 * output size in zc_objset_type.
3953 zfs_ioc_send(zfs_cmd_t
*zc
)
3955 objset_t
*fromsnap
= NULL
;
3960 dsl_dataset_t
*dsfrom
= NULL
;
3963 boolean_t estimate
= (zc
->zc_guid
!= 0);
3965 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
3969 dp
= spa_get_dsl(spa
);
3970 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
3971 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
3972 rw_exit(&dp
->dp_config_rwlock
);
3974 spa_close(spa
, FTAG
);
3978 error
= dmu_objset_from_ds(ds
, &tosnap
);
3980 dsl_dataset_rele(ds
, FTAG
);
3981 spa_close(spa
, FTAG
);
3985 if (zc
->zc_fromobj
!= 0) {
3986 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
3987 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
, FTAG
, &dsfrom
);
3988 rw_exit(&dp
->dp_config_rwlock
);
3989 spa_close(spa
, FTAG
);
3991 dsl_dataset_rele(ds
, FTAG
);
3994 error
= dmu_objset_from_ds(dsfrom
, &fromsnap
);
3996 dsl_dataset_rele(dsfrom
, FTAG
);
3997 dsl_dataset_rele(ds
, FTAG
);
4001 spa_close(spa
, FTAG
);
4005 error
= dmu_send_estimate(tosnap
, fromsnap
, zc
->zc_obj
,
4006 &zc
->zc_objset_type
);
4008 file_t
*fp
= getf(zc
->zc_cookie
);
4010 dsl_dataset_rele(ds
, FTAG
);
4012 dsl_dataset_rele(dsfrom
, FTAG
);
4017 error
= dmu_send(tosnap
, fromsnap
, zc
->zc_obj
,
4018 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4020 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4022 releasef(zc
->zc_cookie
);
4025 dsl_dataset_rele(dsfrom
, FTAG
);
4026 dsl_dataset_rele(ds
, FTAG
);
4032 * zc_name name of snapshot on which to report progress
4033 * zc_cookie file descriptor of send stream
4036 * zc_cookie number of bytes written in send stream thus far
4039 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4042 dmu_sendarg_t
*dsp
= NULL
;
4045 if ((error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &ds
)) != 0)
4048 mutex_enter(&ds
->ds_sendstream_lock
);
4051 * Iterate over all the send streams currently active on this dataset.
4052 * If there's one which matches the specified file descriptor _and_ the
4053 * stream was started by the current process, return the progress of
4057 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4058 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4059 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4060 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4065 zc
->zc_cookie
= *(dsp
->dsa_off
);
4069 mutex_exit(&ds
->ds_sendstream_lock
);
4070 dsl_dataset_rele(ds
, FTAG
);
4075 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4079 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4080 &zc
->zc_inject_record
);
4083 zc
->zc_guid
= (uint64_t)id
;
4089 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4091 return (zio_clear_fault((int)zc
->zc_guid
));
4095 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4097 int id
= (int)zc
->zc_guid
;
4100 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4101 &zc
->zc_inject_record
);
4109 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4113 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4115 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4118 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4121 zc
->zc_nvlist_dst_size
= count
;
4123 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4125 spa_close(spa
, FTAG
);
4131 zfs_ioc_clear(zfs_cmd_t
*zc
)
4138 * On zpool clear we also fix up missing slogs
4140 mutex_enter(&spa_namespace_lock
);
4141 spa
= spa_lookup(zc
->zc_name
);
4143 mutex_exit(&spa_namespace_lock
);
4146 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4147 /* we need to let spa_open/spa_load clear the chains */
4148 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4150 spa
->spa_last_open_failed
= 0;
4151 mutex_exit(&spa_namespace_lock
);
4153 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4154 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4157 nvlist_t
*config
= NULL
;
4159 if (zc
->zc_nvlist_src
== 0)
4162 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4163 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4164 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4166 if (config
!= NULL
) {
4169 if ((err
= put_nvlist(zc
, config
)) != 0)
4171 nvlist_free(config
);
4173 nvlist_free(policy
);
4180 spa_vdev_state_enter(spa
, SCL_NONE
);
4182 if (zc
->zc_guid
== 0) {
4185 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4187 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4188 spa_close(spa
, FTAG
);
4193 vdev_clear(spa
, vd
);
4195 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4198 * Resume any suspended I/Os.
4200 if (zio_resume(spa
) != 0)
4203 spa_close(spa
, FTAG
);
4209 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4214 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4218 spa_vdev_state_enter(spa
, SCL_NONE
);
4221 * If a resilver is already in progress then set the
4222 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4223 * the scan as a side effect of the reopen. Otherwise, let
4224 * vdev_open() decided if a resilver is required.
4226 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4227 vdev_reopen(spa
->spa_root_vdev
);
4228 spa
->spa_scrub_reopen
= B_FALSE
;
4230 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4231 spa_close(spa
, FTAG
);
4236 * zc_name name of filesystem
4237 * zc_value name of origin snapshot
4240 * zc_string name of conflicting snapshot, if there is one
4243 zfs_ioc_promote(zfs_cmd_t
*zc
)
4248 * We don't need to unmount *all* the origin fs's snapshots, but
4251 cp
= strchr(zc
->zc_value
, '@');
4254 (void) dmu_objset_find(zc
->zc_value
,
4255 zfs_unmount_snap
, NULL
, DS_FIND_SNAPSHOTS
);
4256 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4260 * Retrieve a single {user|group}{used|quota}@... property.
4263 * zc_name name of filesystem
4264 * zc_objset_type zfs_userquota_prop_t
4265 * zc_value domain name (eg. "S-1-234-567-89")
4266 * zc_guid RID/UID/GID
4269 * zc_cookie property value
4272 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4277 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4280 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4284 error
= zfs_userspace_one(zsb
,
4285 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4286 zfs_sb_rele(zsb
, FTAG
);
4293 * zc_name name of filesystem
4294 * zc_cookie zap cursor
4295 * zc_objset_type zfs_userquota_prop_t
4296 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4299 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4300 * zc_cookie zap cursor
4303 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4306 int bufsize
= zc
->zc_nvlist_dst_size
;
4313 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4317 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
4319 error
= zfs_userspace_many(zsb
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4320 buf
, &zc
->zc_nvlist_dst_size
);
4323 error
= xcopyout(buf
,
4324 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4325 zc
->zc_nvlist_dst_size
);
4327 vmem_free(buf
, bufsize
);
4328 zfs_sb_rele(zsb
, FTAG
);
4335 * zc_name name of filesystem
4341 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4347 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
4348 if (!dmu_objset_userused_enabled(zsb
->z_os
)) {
4350 * If userused is not enabled, it may be because the
4351 * objset needs to be closed & reopened (to grow the
4352 * objset_phys_t). Suspend/resume the fs will do that.
4354 error
= zfs_suspend_fs(zsb
);
4356 error
= zfs_resume_fs(zsb
, zc
->zc_name
);
4359 error
= dmu_objset_userspace_upgrade(zsb
->z_os
);
4360 deactivate_super(zsb
->z_sb
);
4362 /* XXX kind of reading contents without owning */
4363 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4367 error
= dmu_objset_userspace_upgrade(os
);
4368 dmu_objset_rele(os
, FTAG
);
4375 zfs_ioc_share(zfs_cmd_t
*zc
)
4380 ace_t full_access
[] = {
4381 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4386 * zc_name name of containing filesystem
4387 * zc_obj object # beyond which we want next in-use object #
4390 * zc_obj next in-use object #
4393 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4395 objset_t
*os
= NULL
;
4398 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4402 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4403 os
->os_dsl_dataset
->ds_phys
->ds_prev_snap_txg
);
4405 dmu_objset_rele(os
, FTAG
);
4411 * zc_name name of filesystem
4412 * zc_value prefix name for snapshot
4413 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4418 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
4423 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
4424 (u_longlong_t
)ddi_get_lbolt64());
4426 if (strlen(snap_name
) >= MAXNAMELEN
) {
4431 error
= dmu_objset_snapshot(zc
->zc_name
, snap_name
, snap_name
,
4432 NULL
, B_FALSE
, B_TRUE
, zc
->zc_cleanup_fd
);
4438 (void) strcpy(zc
->zc_value
, snap_name
);
4445 * zc_name name of "to" snapshot
4446 * zc_value name of "from" snapshot
4447 * zc_cookie file descriptor to write diff data on
4450 * dmu_diff_record_t's to the file descriptor
4453 zfs_ioc_diff(zfs_cmd_t
*zc
)
4461 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &tosnap
);
4465 error
= dmu_objset_hold(zc
->zc_value
, FTAG
, &fromsnap
);
4467 dmu_objset_rele(tosnap
, FTAG
);
4471 fp
= getf(zc
->zc_cookie
);
4473 dmu_objset_rele(fromsnap
, FTAG
);
4474 dmu_objset_rele(tosnap
, FTAG
);
4480 error
= dmu_diff(tosnap
, fromsnap
, fp
->f_vnode
, &off
);
4482 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4484 releasef(zc
->zc_cookie
);
4486 dmu_objset_rele(fromsnap
, FTAG
);
4487 dmu_objset_rele(tosnap
, FTAG
);
4492 * Remove all ACL files in shares dir
4494 #ifdef HAVE_SMB_SHARE
4496 zfs_smb_acl_purge(znode_t
*dzp
)
4499 zap_attribute_t zap
;
4500 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
4503 for (zap_cursor_init(&zc
, zsb
->z_os
, dzp
->z_id
);
4504 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
4505 zap_cursor_advance(&zc
)) {
4506 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
4510 zap_cursor_fini(&zc
);
4513 #endif /* HAVE_SMB_SHARE */
4516 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
4518 #ifdef HAVE_SMB_SHARE
4521 vnode_t
*resourcevp
= NULL
;
4530 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
4531 NO_FOLLOW
, NULL
, &vp
)) != 0)
4534 /* Now make sure mntpnt and dataset are ZFS */
4536 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
4537 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
4538 zc
->zc_name
) != 0)) {
4548 * Create share dir if its missing.
4550 mutex_enter(&zsb
->z_lock
);
4551 if (zsb
->z_shares_dir
== 0) {
4554 tx
= dmu_tx_create(zsb
->z_os
);
4555 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
4557 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
4558 error
= dmu_tx_assign(tx
, TXG_WAIT
);
4562 error
= zfs_create_share_dir(zsb
, tx
);
4566 mutex_exit(&zsb
->z_lock
);
4572 mutex_exit(&zsb
->z_lock
);
4574 ASSERT(zsb
->z_shares_dir
);
4575 if ((error
= zfs_zget(zsb
, zsb
->z_shares_dir
, &sharedir
)) != 0) {
4581 switch (zc
->zc_cookie
) {
4582 case ZFS_SMB_ACL_ADD
:
4583 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
4584 vattr
.va_mode
= S_IFREG
|0777;
4588 vsec
.vsa_mask
= VSA_ACE
;
4589 vsec
.vsa_aclentp
= &full_access
;
4590 vsec
.vsa_aclentsz
= sizeof (full_access
);
4591 vsec
.vsa_aclcnt
= 1;
4593 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
4594 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
4596 VN_RELE(resourcevp
);
4599 case ZFS_SMB_ACL_REMOVE
:
4600 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
4604 case ZFS_SMB_ACL_RENAME
:
4605 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4606 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
4611 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
4612 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
4615 VN_RELE(ZTOV(sharedir
));
4617 nvlist_free(nvlist
);
4620 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
4622 nvlist_free(nvlist
);
4625 case ZFS_SMB_ACL_PURGE
:
4626 error
= zfs_smb_acl_purge(sharedir
);
4635 VN_RELE(ZTOV(sharedir
));
4642 #endif /* HAVE_SMB_SHARE */
4647 * zc_name name of filesystem
4648 * zc_value short name of snap
4649 * zc_string user-supplied tag for this hold
4650 * zc_cookie recursive flag
4651 * zc_temphold set if hold is temporary
4652 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4653 * zc_sendobj if non-zero, the objid for zc_name@zc_value
4654 * zc_createtxg if zc_sendobj is non-zero, snap must have zc_createtxg
4659 zfs_ioc_hold(zfs_cmd_t
*zc
)
4661 boolean_t recursive
= zc
->zc_cookie
;
4668 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
4671 if (zc
->zc_sendobj
== 0) {
4672 return (dsl_dataset_user_hold(zc
->zc_name
, zc
->zc_value
,
4673 zc
->zc_string
, recursive
, zc
->zc_temphold
,
4674 zc
->zc_cleanup_fd
));
4680 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4684 dp
= spa_get_dsl(spa
);
4685 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
4686 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
4687 rw_exit(&dp
->dp_config_rwlock
);
4688 spa_close(spa
, FTAG
);
4693 * Until we have a hold on this snapshot, it's possible that
4694 * zc_sendobj could've been destroyed and reused as part
4695 * of a later txg. Make sure we're looking at the right object.
4697 if (zc
->zc_createtxg
!= ds
->ds_phys
->ds_creation_txg
) {
4698 dsl_dataset_rele(ds
, FTAG
);
4702 if (zc
->zc_cleanup_fd
!= -1 && zc
->zc_temphold
) {
4703 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
4705 dsl_dataset_rele(ds
, FTAG
);
4710 error
= dsl_dataset_user_hold_for_send(ds
, zc
->zc_string
,
4714 dsl_register_onexit_hold_cleanup(ds
, zc
->zc_string
,
4717 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
4719 dsl_dataset_rele(ds
, FTAG
);
4726 * zc_name name of dataset from which we're releasing a user hold
4727 * zc_value short name of snap
4728 * zc_string user-supplied tag for this hold
4729 * zc_cookie recursive flag
4734 zfs_ioc_release(zfs_cmd_t
*zc
)
4736 boolean_t recursive
= zc
->zc_cookie
;
4738 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
4741 return (dsl_dataset_user_release(zc
->zc_name
, zc
->zc_value
,
4742 zc
->zc_string
, recursive
));
4747 * zc_name name of filesystem
4750 * zc_nvlist_src{_size} nvlist of snapshot holds
4753 zfs_ioc_get_holds(zfs_cmd_t
*zc
)
4758 if ((error
= dsl_dataset_get_holds(zc
->zc_name
, &nvp
)) == 0) {
4759 error
= put_nvlist(zc
, nvp
);
4768 * zc_guid flags (ZEVENT_NONBLOCK)
4771 * zc_nvlist_dst next nvlist event
4772 * zc_cookie dropped events since last get
4773 * zc_cleanup_fd cleanup-on-exit file descriptor
4776 zfs_ioc_events_next(zfs_cmd_t
*zc
)
4779 nvlist_t
*event
= NULL
;
4781 uint64_t dropped
= 0;
4784 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
4789 error
= zfs_zevent_next(ze
, &event
,
4790 &zc
->zc_nvlist_dst_size
, &dropped
);
4791 if (event
!= NULL
) {
4792 zc
->zc_cookie
= dropped
;
4793 error
= put_nvlist(zc
, event
);
4797 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
4800 if ((error
== 0) || (error
!= ENOENT
))
4803 error
= zfs_zevent_wait(ze
);
4808 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
4815 * zc_cookie cleared events count
4818 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
4822 zfs_zevent_drain_all(&count
);
4823 zc
->zc_cookie
= count
;
4830 * zc_name name of new filesystem or snapshot
4831 * zc_value full name of old snapshot
4834 * zc_cookie space in bytes
4835 * zc_objset_type compressed space in bytes
4836 * zc_perm_action uncompressed space in bytes
4839 zfs_ioc_space_written(zfs_cmd_t
*zc
)
4842 dsl_dataset_t
*new, *old
;
4844 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &new);
4847 error
= dsl_dataset_hold(zc
->zc_value
, FTAG
, &old
);
4849 dsl_dataset_rele(new, FTAG
);
4853 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
4854 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
4855 dsl_dataset_rele(old
, FTAG
);
4856 dsl_dataset_rele(new, FTAG
);
4862 * zc_name full name of last snapshot
4863 * zc_value full name of first snapshot
4866 * zc_cookie space in bytes
4867 * zc_objset_type compressed space in bytes
4868 * zc_perm_action uncompressed space in bytes
4871 zfs_ioc_space_snaps(zfs_cmd_t
*zc
)
4874 dsl_dataset_t
*new, *old
;
4876 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &new);
4879 error
= dsl_dataset_hold(zc
->zc_value
, FTAG
, &old
);
4881 dsl_dataset_rele(new, FTAG
);
4885 error
= dsl_dataset_space_wouldfree(old
, new, &zc
->zc_cookie
,
4886 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
4887 dsl_dataset_rele(old
, FTAG
);
4888 dsl_dataset_rele(new, FTAG
);
4893 * pool create, destroy, and export don't log the history as part of
4894 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
4895 * do the logging of those commands.
4897 static zfs_ioc_vec_t zfs_ioc_vec
[] = {
4898 { zfs_ioc_pool_create
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4900 { zfs_ioc_pool_destroy
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4902 { zfs_ioc_pool_import
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4904 { zfs_ioc_pool_export
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4906 { zfs_ioc_pool_configs
, zfs_secpolicy_none
, NO_NAME
, B_FALSE
,
4908 { zfs_ioc_pool_stats
, zfs_secpolicy_read
, POOL_NAME
, B_FALSE
,
4910 { zfs_ioc_pool_tryimport
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
4912 { zfs_ioc_pool_scan
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4913 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4914 { zfs_ioc_pool_freeze
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
4915 POOL_CHECK_READONLY
},
4916 { zfs_ioc_pool_upgrade
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4917 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4918 { zfs_ioc_pool_get_history
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4920 { zfs_ioc_vdev_add
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4921 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4922 { zfs_ioc_vdev_remove
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4923 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4924 { zfs_ioc_vdev_set_state
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4925 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4926 { zfs_ioc_vdev_attach
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4927 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4928 { zfs_ioc_vdev_detach
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4929 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4930 { zfs_ioc_vdev_setpath
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4931 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4932 { zfs_ioc_vdev_setfru
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4933 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4934 { zfs_ioc_objset_stats
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4935 POOL_CHECK_SUSPENDED
},
4936 { zfs_ioc_objset_zplprops
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4938 { zfs_ioc_dataset_list_next
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4939 POOL_CHECK_SUSPENDED
},
4940 { zfs_ioc_snapshot_list_next
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4941 POOL_CHECK_SUSPENDED
},
4942 { zfs_ioc_set_prop
, zfs_secpolicy_none
, DATASET_NAME
, B_TRUE
,
4943 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4944 { zfs_ioc_create_minor
, zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
,
4946 { zfs_ioc_remove_minor
, zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
,
4948 { zfs_ioc_create
, zfs_secpolicy_create
, DATASET_NAME
, B_TRUE
,
4949 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4950 { zfs_ioc_destroy
, zfs_secpolicy_destroy
, DATASET_NAME
, B_TRUE
,
4951 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4952 { zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
, B_TRUE
,
4953 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4954 { zfs_ioc_rename
, zfs_secpolicy_rename
, DATASET_NAME
, B_TRUE
,
4955 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4956 { zfs_ioc_recv
, zfs_secpolicy_receive
, DATASET_NAME
, B_TRUE
,
4957 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4958 { zfs_ioc_send
, zfs_secpolicy_send
, DATASET_NAME
, B_FALSE
,
4960 { zfs_ioc_inject_fault
, zfs_secpolicy_inject
, NO_NAME
, B_FALSE
,
4962 { zfs_ioc_clear_fault
, zfs_secpolicy_inject
, NO_NAME
, B_FALSE
,
4964 { zfs_ioc_inject_list_next
, zfs_secpolicy_inject
, NO_NAME
, B_FALSE
,
4966 { zfs_ioc_error_log
, zfs_secpolicy_inject
, POOL_NAME
, B_FALSE
,
4968 { zfs_ioc_clear
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4970 { zfs_ioc_promote
, zfs_secpolicy_promote
, DATASET_NAME
, B_TRUE
,
4971 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4972 { zfs_ioc_destroy_snaps_nvl
, zfs_secpolicy_destroy_recursive
,
4973 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4974 { zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, DATASET_NAME
, B_TRUE
,
4975 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4976 { zfs_ioc_dsobj_to_dsname
, zfs_secpolicy_diff
, POOL_NAME
, B_FALSE
,
4978 { zfs_ioc_obj_to_path
, zfs_secpolicy_diff
, DATASET_NAME
, B_FALSE
,
4979 POOL_CHECK_SUSPENDED
},
4980 { zfs_ioc_pool_set_props
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4981 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4982 { zfs_ioc_pool_get_props
, zfs_secpolicy_read
, POOL_NAME
, B_FALSE
,
4984 { zfs_ioc_set_fsacl
, zfs_secpolicy_fsacl
, DATASET_NAME
, B_TRUE
,
4985 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4986 { zfs_ioc_get_fsacl
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4988 { zfs_ioc_share
, zfs_secpolicy_share
, DATASET_NAME
, B_FALSE
,
4990 { zfs_ioc_inherit_prop
, zfs_secpolicy_inherit
, DATASET_NAME
, B_TRUE
,
4991 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4992 { zfs_ioc_smb_acl
, zfs_secpolicy_smb_acl
, DATASET_NAME
, B_FALSE
,
4994 { zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
, DATASET_NAME
,
4995 B_FALSE
, POOL_CHECK_NONE
},
4996 { zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
, DATASET_NAME
,
4997 B_FALSE
, POOL_CHECK_NONE
},
4998 { zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
4999 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5000 { zfs_ioc_hold
, zfs_secpolicy_hold
, DATASET_NAME
, B_TRUE
,
5001 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5002 { zfs_ioc_release
, zfs_secpolicy_release
, DATASET_NAME
, B_TRUE
,
5003 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5004 { zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5005 POOL_CHECK_SUSPENDED
},
5006 { zfs_ioc_objset_recvd_props
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5008 { zfs_ioc_vdev_split
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
5009 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5010 { zfs_ioc_next_obj
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5012 { zfs_ioc_diff
, zfs_secpolicy_diff
, DATASET_NAME
, B_FALSE
,
5014 { zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
, DATASET_NAME
,
5015 B_FALSE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5016 { zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
, DATASET_NAME
, B_FALSE
,
5017 POOL_CHECK_SUSPENDED
},
5018 { zfs_ioc_events_next
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
5020 { zfs_ioc_events_clear
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
5022 { zfs_ioc_pool_reguid
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
5023 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5024 { zfs_ioc_space_written
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5025 POOL_CHECK_SUSPENDED
},
5026 { zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5027 POOL_CHECK_SUSPENDED
},
5028 { zfs_ioc_pool_reopen
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
5029 POOL_CHECK_SUSPENDED
},
5030 { zfs_ioc_send_progress
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5035 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5036 zfs_ioc_poolcheck_t check
)
5041 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5043 if (check
& POOL_CHECK_NONE
)
5046 error
= spa_open(name
, &spa
, FTAG
);
5048 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5050 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5052 spa_close(spa
, FTAG
);
5058 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
5062 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5064 for (zs
= list_head(&zfsdev_state_list
); zs
!= NULL
;
5065 zs
= list_next(&zfsdev_state_list
, zs
)) {
5066 if (zs
->zs_minor
== minor
) {
5068 case ZST_ONEXIT
: return (zs
->zs_onexit
);
5069 case ZST_ZEVENT
: return (zs
->zs_zevent
);
5070 case ZST_ALL
: return (zs
);
5079 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
5083 mutex_enter(&zfsdev_state_lock
);
5084 ptr
= zfsdev_get_state_impl(minor
, which
);
5085 mutex_exit(&zfsdev_state_lock
);
5091 zfsdev_getminor(struct file
*filp
)
5093 ASSERT(filp
!= NULL
);
5094 ASSERT(filp
->private_data
!= NULL
);
5096 return (((zfsdev_state_t
*)filp
->private_data
)->zs_minor
);
5100 * Find a free minor number. The zfsdev_state_list is expected to
5101 * be short since it is only a list of currently open file handles.
5104 zfsdev_minor_alloc(void)
5106 static minor_t last_minor
= 0;
5109 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5111 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5112 if (m
> ZFSDEV_MAX_MINOR
)
5114 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
5124 zfsdev_state_init(struct file
*filp
)
5129 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5131 minor
= zfsdev_minor_alloc();
5135 zs
= kmem_zalloc( sizeof(zfsdev_state_t
), KM_SLEEP
);
5140 zs
->zs_minor
= minor
;
5141 filp
->private_data
= zs
;
5143 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
5144 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
5146 list_insert_tail(&zfsdev_state_list
, zs
);
5152 zfsdev_state_destroy(struct file
*filp
)
5156 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5157 ASSERT(filp
->private_data
!= NULL
);
5159 zs
= filp
->private_data
;
5160 zfs_onexit_destroy(zs
->zs_onexit
);
5161 zfs_zevent_destroy(zs
->zs_zevent
);
5163 list_remove(&zfsdev_state_list
, zs
);
5164 kmem_free(zs
, sizeof(zfsdev_state_t
));
5170 zfsdev_open(struct inode
*ino
, struct file
*filp
)
5174 mutex_enter(&zfsdev_state_lock
);
5175 error
= zfsdev_state_init(filp
);
5176 mutex_exit(&zfsdev_state_lock
);
5182 zfsdev_release(struct inode
*ino
, struct file
*filp
)
5186 mutex_enter(&zfsdev_state_lock
);
5187 error
= zfsdev_state_destroy(filp
);
5188 mutex_exit(&zfsdev_state_lock
);
5194 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5198 int error
, rc
, flag
= 0;
5200 vec
= cmd
- ZFS_IOC
;
5201 if (vec
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
5204 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
5206 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
5210 if ((error
== 0) && !(flag
& FKIOCTL
))
5211 error
= zfs_ioc_vec
[vec
].zvec_secpolicy(zc
, CRED());
5214 * Ensure that all pool/dataset names are valid before we pass down to
5218 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5219 zc
->zc_iflags
= flag
& FKIOCTL
;
5220 switch (zfs_ioc_vec
[vec
].zvec_namecheck
) {
5222 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5224 error
= pool_status_check(zc
->zc_name
,
5225 zfs_ioc_vec
[vec
].zvec_namecheck
,
5226 zfs_ioc_vec
[vec
].zvec_pool_check
);
5230 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5232 error
= pool_status_check(zc
->zc_name
,
5233 zfs_ioc_vec
[vec
].zvec_namecheck
,
5234 zfs_ioc_vec
[vec
].zvec_pool_check
);
5243 error
= zfs_ioc_vec
[vec
].zvec_func(zc
);
5245 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
5249 if (zfs_ioc_vec
[vec
].zvec_his_log
)
5250 zfs_log_history(zc
);
5253 kmem_free(zc
, sizeof (zfs_cmd_t
));
5257 #ifdef CONFIG_COMPAT
5259 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5261 return zfsdev_ioctl(filp
, cmd
, arg
);
5264 #define zfsdev_compat_ioctl NULL
5267 static const struct file_operations zfsdev_fops
= {
5268 .open
= zfsdev_open
,
5269 .release
= zfsdev_release
,
5270 .unlocked_ioctl
= zfsdev_ioctl
,
5271 .compat_ioctl
= zfsdev_compat_ioctl
,
5272 .owner
= THIS_MODULE
,
5275 static struct miscdevice zfs_misc
= {
5276 .minor
= MISC_DYNAMIC_MINOR
,
5278 .fops
= &zfsdev_fops
,
5286 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
5287 list_create(&zfsdev_state_list
, sizeof (zfsdev_state_t
),
5288 offsetof(zfsdev_state_t
, zs_next
));
5290 error
= misc_register(&zfs_misc
);
5292 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
5304 error
= misc_deregister(&zfs_misc
);
5306 printk(KERN_INFO
"ZFS: misc_deregister() failed %d\n", error
);
5308 mutex_destroy(&zfsdev_state_lock
);
5309 list_destroy(&zfsdev_state_list
);
5312 uint_t zfs_fsyncer_key
;
5313 extern uint_t rrw_tsd_key
;
5316 #define ZFS_DEBUG_STR " (DEBUG mode)"
5318 #define ZFS_DEBUG_STR ""
5326 spa_init(FREAD
| FWRITE
);
5329 if ((error
= zvol_init()) != 0)
5332 if ((error
= zfs_attach()) != 0)
5335 tsd_create(&zfs_fsyncer_key
, NULL
);
5336 tsd_create(&rrw_tsd_key
, NULL
);
5338 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
5339 "ZFS pool version %s, ZFS filesystem version %s\n",
5340 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
5341 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
5350 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
5351 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
5352 ZFS_DEBUG_STR
, error
);
5365 tsd_destroy(&zfs_fsyncer_key
);
5366 tsd_destroy(&rrw_tsd_key
);
5368 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
5369 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
5375 spl_module_init(_init
);
5376 spl_module_exit(_fini
);
5378 MODULE_DESCRIPTION("ZFS");
5379 MODULE_AUTHOR(ZFS_META_AUTHOR
);
5380 MODULE_LICENSE(ZFS_META_LICENSE
);
5381 #endif /* HAVE_SPL */