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
);
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_SNAPDEV
:
2188 err
= zvol_set_snapdev(dsname
, intval
);
2190 case ZFS_PROP_VERSION
:
2194 if ((err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_TRUE
)) != 0)
2197 err
= zfs_set_version(zsb
, intval
);
2198 zfs_sb_rele(zsb
, FTAG
);
2200 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2203 zc
= kmem_zalloc(sizeof (zfs_cmd_t
),
2204 KM_SLEEP
| KM_NODEBUG
);
2205 (void) strcpy(zc
->zc_name
, dsname
);
2206 (void) zfs_ioc_userspace_upgrade(zc
);
2207 kmem_free(zc
, sizeof (zfs_cmd_t
));
2211 case ZFS_PROP_COMPRESSION
:
2213 if (intval
== ZIO_COMPRESS_LZ4
) {
2214 zfeature_info_t
*feature
=
2215 &spa_feature_table
[SPA_FEATURE_LZ4_COMPRESS
];
2219 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
2222 dp
= spa
->spa_dsl_pool
;
2225 * Setting the LZ4 compression algorithm activates
2228 if (!spa_feature_is_active(spa
, feature
)) {
2229 if ((err
= zfs_prop_activate_feature(dp
,
2231 spa_close(spa
, FTAG
);
2236 spa_close(spa
, FTAG
);
2239 * We still want the default set action to be performed in the
2240 * caller, we only performed zfeature settings here.
2254 * This function is best effort. If it fails to set any of the given properties,
2255 * it continues to set as many as it can and returns the first error
2256 * encountered. If the caller provides a non-NULL errlist, it also gives the
2257 * complete list of names of all the properties it failed to set along with the
2258 * corresponding error numbers. The caller is responsible for freeing the
2261 * If every property is set successfully, zero is returned and the list pointed
2262 * at by errlist is NULL.
2265 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2273 nvlist_t
*genericnvl
;
2277 VERIFY(nvlist_alloc(&genericnvl
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2278 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2279 VERIFY(nvlist_alloc(&retrynvl
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2283 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2284 const char *propname
= nvpair_name(pair
);
2285 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2288 /* decode the property value */
2290 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2292 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2293 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2298 /* Validate value type */
2299 if (err
== 0 && prop
== ZPROP_INVAL
) {
2300 if (zfs_prop_user(propname
)) {
2301 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2303 } else if (zfs_prop_userquota(propname
)) {
2304 if (nvpair_type(propval
) !=
2305 DATA_TYPE_UINT64_ARRAY
)
2310 } else if (err
== 0) {
2311 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2312 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2314 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2317 VERIFY(nvpair_value_uint64(propval
,
2320 switch (zfs_prop_get_type(prop
)) {
2321 case PROP_TYPE_NUMBER
:
2323 case PROP_TYPE_STRING
:
2326 case PROP_TYPE_INDEX
:
2327 if (zfs_prop_index_to_string(prop
,
2328 intval
, &unused
) != 0)
2333 "unknown property type");
2340 /* Validate permissions */
2342 err
= zfs_check_settable(dsname
, pair
, CRED());
2345 err
= zfs_prop_set_special(dsname
, source
, pair
);
2348 * For better performance we build up a list of
2349 * properties to set in a single transaction.
2351 err
= nvlist_add_nvpair(genericnvl
, pair
);
2352 } else if (err
!= 0 && nvl
!= retrynvl
) {
2354 * This may be a spurious error caused by
2355 * receiving quota and reservation out of order.
2356 * Try again in a second pass.
2358 err
= nvlist_add_nvpair(retrynvl
, pair
);
2363 VERIFY(nvlist_add_int32(errors
, propname
, err
) == 0);
2366 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2371 if (!nvlist_empty(genericnvl
) &&
2372 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2374 * If this fails, we still want to set as many properties as we
2375 * can, so try setting them individually.
2378 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2379 const char *propname
= nvpair_name(pair
);
2383 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2385 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2386 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2390 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2391 VERIFY(nvpair_value_string(propval
,
2393 err
= dsl_prop_set(dsname
, propname
, source
, 1,
2394 strlen(strval
) + 1, strval
);
2396 VERIFY(nvpair_value_uint64(propval
,
2398 err
= dsl_prop_set(dsname
, propname
, source
, 8,
2403 VERIFY(nvlist_add_int32(errors
, propname
,
2408 nvlist_free(genericnvl
);
2409 nvlist_free(retrynvl
);
2411 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
2412 nvlist_free(errors
);
2415 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
2418 if (errlist
== NULL
)
2419 nvlist_free(errors
);
2427 * Check that all the properties are valid user properties.
2430 zfs_check_userprops(char *fsname
, nvlist_t
*nvl
)
2432 nvpair_t
*pair
= NULL
;
2435 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2436 const char *propname
= nvpair_name(pair
);
2439 if (!zfs_prop_user(propname
) ||
2440 nvpair_type(pair
) != DATA_TYPE_STRING
)
2443 if ((error
= zfs_secpolicy_write_perms(fsname
,
2444 ZFS_DELEG_PERM_USERPROP
, CRED())))
2447 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2448 return (ENAMETOOLONG
);
2450 VERIFY(nvpair_value_string(pair
, &valstr
) == 0);
2451 if (strlen(valstr
) >= ZAP_MAXVALUELEN
)
2458 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2462 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2465 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2466 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2469 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2474 clear_received_props(objset_t
*os
, const char *fs
, nvlist_t
*props
,
2478 nvlist_t
*cleared_props
= NULL
;
2479 props_skip(props
, skipped
, &cleared_props
);
2480 if (!nvlist_empty(cleared_props
)) {
2482 * Acts on local properties until the dataset has received
2483 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2485 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2486 (dsl_prop_get_hasrecvd(os
) ? ZPROP_SRC_RECEIVED
: 0));
2487 err
= zfs_set_prop_nvlist(fs
, flags
, cleared_props
, NULL
);
2489 nvlist_free(cleared_props
);
2495 * zc_name name of filesystem
2496 * zc_value name of property to set
2497 * zc_nvlist_src{_size} nvlist of properties to apply
2498 * zc_cookie received properties flag
2501 * zc_nvlist_dst{_size} error for each unapplied received property
2504 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2507 boolean_t received
= zc
->zc_cookie
;
2508 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2510 nvlist_t
*errors
= NULL
;
2513 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2514 zc
->zc_iflags
, &nvl
)) != 0)
2518 nvlist_t
*origprops
;
2521 if (dmu_objset_hold(zc
->zc_name
, FTAG
, &os
) == 0) {
2522 if (dsl_prop_get_received(os
, &origprops
) == 0) {
2523 (void) clear_received_props(os
,
2524 zc
->zc_name
, origprops
, nvl
);
2525 nvlist_free(origprops
);
2528 dsl_prop_set_hasrecvd(os
);
2529 dmu_objset_rele(os
, FTAG
);
2533 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, &errors
);
2535 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2536 (void) put_nvlist(zc
, errors
);
2539 nvlist_free(errors
);
2546 * zc_name name of filesystem
2547 * zc_value name of property to inherit
2548 * zc_cookie revert to received value if TRUE
2553 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2555 const char *propname
= zc
->zc_value
;
2556 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2557 boolean_t received
= zc
->zc_cookie
;
2558 zprop_source_t source
= (received
2559 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2560 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2569 * zfs_prop_set_special() expects properties in the form of an
2570 * nvpair with type info.
2572 if (prop
== ZPROP_INVAL
) {
2573 if (!zfs_prop_user(propname
))
2576 type
= PROP_TYPE_STRING
;
2577 } else if (prop
== ZFS_PROP_VOLSIZE
||
2578 prop
== ZFS_PROP_VERSION
) {
2581 type
= zfs_prop_get_type(prop
);
2584 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2587 case PROP_TYPE_STRING
:
2588 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2590 case PROP_TYPE_NUMBER
:
2591 case PROP_TYPE_INDEX
:
2592 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2599 pair
= nvlist_next_nvpair(dummy
, NULL
);
2600 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2603 return (err
); /* special property already handled */
2606 * Only check this in the non-received case. We want to allow
2607 * 'inherit -S' to revert non-inheritable properties like quota
2608 * and reservation to the received or default values even though
2609 * they are not considered inheritable.
2611 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2615 /* the property name has been validated by zfs_secpolicy_inherit() */
2616 return (dsl_prop_set(zc
->zc_name
, zc
->zc_value
, source
, 0, 0, NULL
));
2620 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2627 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2628 zc
->zc_iflags
, &props
)))
2632 * If the only property is the configfile, then just do a spa_lookup()
2633 * to handle the faulted case.
2635 pair
= nvlist_next_nvpair(props
, NULL
);
2636 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2637 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2638 nvlist_next_nvpair(props
, pair
) == NULL
) {
2639 mutex_enter(&spa_namespace_lock
);
2640 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2641 spa_configfile_set(spa
, props
, B_FALSE
);
2642 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2644 mutex_exit(&spa_namespace_lock
);
2651 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2656 error
= spa_prop_set(spa
, props
);
2659 spa_close(spa
, FTAG
);
2665 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2669 nvlist_t
*nvp
= NULL
;
2671 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2673 * If the pool is faulted, there may be properties we can still
2674 * get (such as altroot and cachefile), so attempt to get them
2677 mutex_enter(&spa_namespace_lock
);
2678 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2679 error
= spa_prop_get(spa
, &nvp
);
2680 mutex_exit(&spa_namespace_lock
);
2682 error
= spa_prop_get(spa
, &nvp
);
2683 spa_close(spa
, FTAG
);
2686 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2687 error
= put_nvlist(zc
, nvp
);
2697 * zc_name name of volume
2702 zfs_ioc_create_minor(zfs_cmd_t
*zc
)
2704 return (zvol_create_minor(zc
->zc_name
));
2709 * zc_name name of volume
2714 zfs_ioc_remove_minor(zfs_cmd_t
*zc
)
2716 return (zvol_remove_minor(zc
->zc_name
));
2721 * zc_name name of filesystem
2722 * zc_nvlist_src{_size} nvlist of delegated permissions
2723 * zc_perm_action allow/unallow flag
2728 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2731 nvlist_t
*fsaclnv
= NULL
;
2733 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2734 zc
->zc_iflags
, &fsaclnv
)) != 0)
2738 * Verify nvlist is constructed correctly
2740 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2741 nvlist_free(fsaclnv
);
2746 * If we don't have PRIV_SYS_MOUNT, then validate
2747 * that user is allowed to hand out each permission in
2751 error
= secpolicy_zfs(CRED());
2753 if (zc
->zc_perm_action
== B_FALSE
) {
2754 error
= dsl_deleg_can_allow(zc
->zc_name
,
2757 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2763 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2765 nvlist_free(fsaclnv
);
2771 * zc_name name of filesystem
2774 * zc_nvlist_src{_size} nvlist of delegated permissions
2777 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2782 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2783 error
= put_nvlist(zc
, nvp
);
2792 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2794 zfs_creat_t
*zct
= arg
;
2796 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2799 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2803 * createprops list of properties requested by creator
2804 * default_zplver zpl version to use if unspecified in createprops
2805 * fuids_ok fuids allowed in this version of the spa?
2806 * os parent objset pointer (NULL if root fs)
2809 * zplprops values for the zplprops we attach to the master node object
2810 * is_ci true if requested file system will be purely case-insensitive
2812 * Determine the settings for utf8only, normalization and
2813 * casesensitivity. Specific values may have been requested by the
2814 * creator and/or we can inherit values from the parent dataset. If
2815 * the file system is of too early a vintage, a creator can not
2816 * request settings for these properties, even if the requested
2817 * setting is the default value. We don't actually want to create dsl
2818 * properties for these, so remove them from the source nvlist after
2822 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2823 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2824 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2826 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2827 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2828 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2831 ASSERT(zplprops
!= NULL
);
2834 * Pull out creator prop choices, if any.
2837 (void) nvlist_lookup_uint64(createprops
,
2838 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2839 (void) nvlist_lookup_uint64(createprops
,
2840 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2841 (void) nvlist_remove_all(createprops
,
2842 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2843 (void) nvlist_lookup_uint64(createprops
,
2844 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2845 (void) nvlist_remove_all(createprops
,
2846 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2847 (void) nvlist_lookup_uint64(createprops
,
2848 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2849 (void) nvlist_remove_all(createprops
,
2850 zfs_prop_to_name(ZFS_PROP_CASE
));
2854 * If the zpl version requested is whacky or the file system
2855 * or pool is version is too "young" to support normalization
2856 * and the creator tried to set a value for one of the props,
2859 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
2860 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
2861 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
2862 (zplver
< ZPL_VERSION_NORMALIZATION
&&
2863 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
2864 sense
!= ZFS_PROP_UNDEFINED
)))
2868 * Put the version in the zplprops
2870 VERIFY(nvlist_add_uint64(zplprops
,
2871 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
2873 if (norm
== ZFS_PROP_UNDEFINED
&&
2874 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
2876 VERIFY(nvlist_add_uint64(zplprops
,
2877 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
2880 * If we're normalizing, names must always be valid UTF-8 strings.
2884 if (u8
== ZFS_PROP_UNDEFINED
&&
2885 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
2887 VERIFY(nvlist_add_uint64(zplprops
,
2888 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
2890 if (sense
== ZFS_PROP_UNDEFINED
&&
2891 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
2893 VERIFY(nvlist_add_uint64(zplprops
,
2894 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
2897 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
2903 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
2904 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2906 boolean_t fuids_ok
, sa_ok
;
2907 uint64_t zplver
= ZPL_VERSION
;
2908 objset_t
*os
= NULL
;
2909 char parentname
[MAXNAMELEN
];
2915 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
2916 cp
= strrchr(parentname
, '/');
2920 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
2923 spa_vers
= spa_version(spa
);
2924 spa_close(spa
, FTAG
);
2926 zplver
= zfs_zpl_version_map(spa_vers
);
2927 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
2928 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
2931 * Open parent object set so we can inherit zplprop values.
2933 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
2936 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
2938 dmu_objset_rele(os
, FTAG
);
2943 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
2944 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2948 uint64_t zplver
= ZPL_VERSION
;
2951 zplver
= zfs_zpl_version_map(spa_vers
);
2952 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
2953 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
2955 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
2956 createprops
, zplprops
, is_ci
);
2962 * zc_objset_type type of objset to create (fs vs zvol)
2963 * zc_name name of new objset
2964 * zc_value name of snapshot to clone from (may be empty)
2965 * zc_nvlist_src{_size} nvlist of properties to apply
2970 zfs_ioc_create(zfs_cmd_t
*zc
)
2975 nvlist_t
*nvprops
= NULL
;
2976 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
2977 dmu_objset_type_t type
= zc
->zc_objset_type
;
2982 cbfunc
= zfs_create_cb
;
2986 cbfunc
= zvol_create_cb
;
2993 if (strchr(zc
->zc_name
, '@') ||
2994 strchr(zc
->zc_name
, '%'))
2997 if (zc
->zc_nvlist_src
!= 0 &&
2998 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2999 zc
->zc_iflags
, &nvprops
)) != 0)
3002 zct
.zct_zplprops
= NULL
;
3003 zct
.zct_props
= nvprops
;
3005 if (zc
->zc_value
[0] != '\0') {
3007 * We're creating a clone of an existing snapshot.
3009 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3010 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0) {
3011 nvlist_free(nvprops
);
3015 error
= dmu_objset_hold(zc
->zc_value
, FTAG
, &clone
);
3017 nvlist_free(nvprops
);
3021 error
= dmu_objset_clone(zc
->zc_name
, dmu_objset_ds(clone
), 0);
3022 dmu_objset_rele(clone
, FTAG
);
3024 nvlist_free(nvprops
);
3028 boolean_t is_insensitive
= B_FALSE
;
3030 if (cbfunc
== NULL
) {
3031 nvlist_free(nvprops
);
3035 if (type
== DMU_OST_ZVOL
) {
3036 uint64_t volsize
, volblocksize
;
3038 if (nvprops
== NULL
||
3039 nvlist_lookup_uint64(nvprops
,
3040 zfs_prop_to_name(ZFS_PROP_VOLSIZE
),
3042 nvlist_free(nvprops
);
3046 if ((error
= nvlist_lookup_uint64(nvprops
,
3047 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3048 &volblocksize
)) != 0 && error
!= ENOENT
) {
3049 nvlist_free(nvprops
);
3054 volblocksize
= zfs_prop_default_numeric(
3055 ZFS_PROP_VOLBLOCKSIZE
);
3057 if ((error
= zvol_check_volblocksize(
3058 volblocksize
)) != 0 ||
3059 (error
= zvol_check_volsize(volsize
,
3060 volblocksize
)) != 0) {
3061 nvlist_free(nvprops
);
3064 } else if (type
== DMU_OST_ZFS
) {
3068 * We have to have normalization and
3069 * case-folding flags correct when we do the
3070 * file system creation, so go figure them out
3073 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3074 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3075 error
= zfs_fill_zplprops(zc
->zc_name
, nvprops
,
3076 zct
.zct_zplprops
, &is_insensitive
);
3078 nvlist_free(nvprops
);
3079 nvlist_free(zct
.zct_zplprops
);
3083 error
= dmu_objset_create(zc
->zc_name
, type
,
3084 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3085 nvlist_free(zct
.zct_zplprops
);
3089 * It would be nice to do this atomically.
3092 error
= zfs_set_prop_nvlist(zc
->zc_name
, ZPROP_SRC_LOCAL
,
3095 (void) dmu_objset_destroy(zc
->zc_name
, B_FALSE
);
3097 nvlist_free(nvprops
);
3103 * zc_name name of filesystem
3104 * zc_value short name of snapshot
3105 * zc_cookie recursive flag
3106 * zc_nvlist_src[_size] property list
3109 * zc_value short snapname (i.e. part after the '@')
3112 zfs_ioc_snapshot(zfs_cmd_t
*zc
)
3114 nvlist_t
*nvprops
= NULL
;
3116 boolean_t recursive
= zc
->zc_cookie
;
3118 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
3121 if (zc
->zc_nvlist_src
!= 0 &&
3122 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3123 zc
->zc_iflags
, &nvprops
)) != 0)
3126 error
= zfs_check_userprops(zc
->zc_name
, nvprops
);
3130 if (!nvlist_empty(nvprops
) &&
3131 zfs_earlier_version(zc
->zc_name
, SPA_VERSION_SNAP_PROPS
)) {
3136 error
= dmu_objset_snapshot(zc
->zc_name
, zc
->zc_value
, NULL
,
3137 nvprops
, recursive
, B_FALSE
, -1);
3140 nvlist_free(nvprops
);
3146 * name dataset name, or when 'arg == NULL' the full snapshot name
3147 * arg short snapshot name (i.e. part after the '@')
3150 zfs_unmount_snap(const char *name
, void *arg
)
3152 zfs_sb_t
*zsb
= NULL
;
3160 dsname
= strdup(name
);
3161 snapname
= strdup(arg
);
3163 ptr
= strchr(name
, '@');
3165 dsname
= strdup(name
);
3166 dsname
[ptr
- name
] = '\0';
3167 snapname
= strdup(ptr
+ 1);
3173 fullname
= kmem_asprintf("%s@%s", dsname
, snapname
);
3175 error
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
3177 error
= zfsctl_unmount_snapshot(zsb
, fullname
, MNT_FORCE
);
3178 zfs_sb_rele(zsb
, FTAG
);
3180 /* Allow ENOENT for consistency with upstream */
3181 if (error
== ENOENT
)
3194 * zc_name name of filesystem, snaps must be under it
3195 * zc_nvlist_src[_size] full names of snapshots to destroy
3196 * zc_defer_destroy mark for deferred destroy
3199 * zc_name on failure, name of failed snapshot
3202 zfs_ioc_destroy_snaps_nvl(zfs_cmd_t
*zc
)
3208 if ((err
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3209 zc
->zc_iflags
, &nvl
)) != 0)
3212 len
= strlen(zc
->zc_name
);
3213 for (pair
= nvlist_next_nvpair(nvl
, NULL
); pair
!= NULL
;
3214 pair
= nvlist_next_nvpair(nvl
, pair
)) {
3215 const char *name
= nvpair_name(pair
);
3217 * The snap name must be underneath the zc_name. This ensures
3218 * that our permission checks were legitimate.
3220 if (strncmp(zc
->zc_name
, name
, len
) != 0 ||
3221 (name
[len
] != '@' && name
[len
] != '/')) {
3226 (void) zfs_unmount_snap(name
, NULL
);
3227 (void) zvol_remove_minor(name
);
3230 err
= dmu_snapshots_destroy_nvl(nvl
, zc
->zc_defer_destroy
,
3238 * zc_name name of dataset to destroy
3239 * zc_objset_type type of objset
3240 * zc_defer_destroy mark for deferred destroy
3245 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3248 if (strchr(zc
->zc_name
, '@') && zc
->zc_objset_type
== DMU_OST_ZFS
) {
3249 err
= zfs_unmount_snap(zc
->zc_name
, NULL
);
3254 err
= dmu_objset_destroy(zc
->zc_name
, zc
->zc_defer_destroy
);
3255 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3256 (void) zvol_remove_minor(zc
->zc_name
);
3262 * zc_name name of dataset to rollback (to most recent snapshot)
3267 zfs_ioc_rollback(zfs_cmd_t
*zc
)
3269 dsl_dataset_t
*ds
, *clone
;
3274 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &ds
);
3278 /* must not be a snapshot */
3279 if (dsl_dataset_is_snapshot(ds
)) {
3280 dsl_dataset_rele(ds
, FTAG
);
3284 /* must have a most recent snapshot */
3285 if (ds
->ds_phys
->ds_prev_snap_txg
< TXG_INITIAL
) {
3286 dsl_dataset_rele(ds
, FTAG
);
3291 * Create clone of most recent snapshot.
3293 clone_name
= kmem_asprintf("%s/%%rollback", zc
->zc_name
);
3294 error
= dmu_objset_clone(clone_name
, ds
->ds_prev
, DS_FLAG_INCONSISTENT
);
3298 error
= dsl_dataset_own(clone_name
, B_TRUE
, FTAG
, &clone
);
3305 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
3306 error
= zfs_suspend_fs(zsb
);
3310 if (dsl_dataset_tryown(ds
, B_FALSE
, FTAG
)) {
3311 error
= dsl_dataset_clone_swap(clone
, ds
,
3313 dsl_dataset_disown(ds
, FTAG
);
3318 resume_err
= zfs_resume_fs(zsb
, zc
->zc_name
);
3319 error
= error
? error
: resume_err
;
3321 deactivate_super(zsb
->z_sb
);
3323 if (dsl_dataset_tryown(ds
, B_FALSE
, FTAG
)) {
3324 error
= dsl_dataset_clone_swap(clone
, ds
, B_TRUE
);
3325 dsl_dataset_disown(ds
, FTAG
);
3333 * Destroy clone (which also closes it).
3335 (void) dsl_dataset_destroy(clone
, FTAG
, B_FALSE
);
3338 strfree(clone_name
);
3340 dsl_dataset_rele(ds
, FTAG
);
3346 * zc_name old name of dataset
3347 * zc_value new name of dataset
3348 * zc_cookie recursive flag (only valid for snapshots)
3353 zfs_ioc_rename(zfs_cmd_t
*zc
)
3355 boolean_t recursive
= zc
->zc_cookie
& 1;
3358 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3359 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3360 strchr(zc
->zc_value
, '%'))
3364 * Unmount snapshot unless we're doing a recursive rename,
3365 * in which case the dataset code figures out which snapshots
3368 if (!recursive
&& strchr(zc
->zc_name
, '@') != NULL
&&
3369 zc
->zc_objset_type
== DMU_OST_ZFS
) {
3370 err
= zfs_unmount_snap(zc
->zc_name
, NULL
);
3375 err
= dmu_objset_rename(zc
->zc_name
, zc
->zc_value
, recursive
);
3376 if ((err
== 0) && (zc
->zc_objset_type
== DMU_OST_ZVOL
)) {
3377 (void) zvol_remove_minor(zc
->zc_name
);
3378 (void) zvol_create_minor(zc
->zc_value
);
3385 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3387 const char *propname
= nvpair_name(pair
);
3388 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3389 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3393 if (prop
== ZPROP_INVAL
) {
3394 if (zfs_prop_user(propname
)) {
3395 if ((err
= zfs_secpolicy_write_perms(dsname
,
3396 ZFS_DELEG_PERM_USERPROP
, cr
)))
3401 if (!issnap
&& zfs_prop_userquota(propname
)) {
3402 const char *perm
= NULL
;
3403 const char *uq_prefix
=
3404 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3405 const char *gq_prefix
=
3406 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3408 if (strncmp(propname
, uq_prefix
,
3409 strlen(uq_prefix
)) == 0) {
3410 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3411 } else if (strncmp(propname
, gq_prefix
,
3412 strlen(gq_prefix
)) == 0) {
3413 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3415 /* USERUSED and GROUPUSED are read-only */
3419 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3430 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3432 * dsl_prop_get_all_impl() returns properties in this
3436 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3437 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3442 * Check that this value is valid for this pool version
3445 case ZFS_PROP_COMPRESSION
:
3447 * If the user specified gzip compression, make sure
3448 * the SPA supports it. We ignore any errors here since
3449 * we'll catch them later.
3451 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3452 nvpair_value_uint64(pair
, &intval
) == 0) {
3453 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3454 intval
<= ZIO_COMPRESS_GZIP_9
&&
3455 zfs_earlier_version(dsname
,
3456 SPA_VERSION_GZIP_COMPRESSION
)) {
3460 if (intval
== ZIO_COMPRESS_ZLE
&&
3461 zfs_earlier_version(dsname
,
3462 SPA_VERSION_ZLE_COMPRESSION
))
3465 if (intval
== ZIO_COMPRESS_LZ4
) {
3466 zfeature_info_t
*feature
=
3468 SPA_FEATURE_LZ4_COMPRESS
];
3471 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3474 if (!spa_feature_is_enabled(spa
, feature
)) {
3475 spa_close(spa
, FTAG
);
3478 spa_close(spa
, FTAG
);
3482 * If this is a bootable dataset then
3483 * verify that the compression algorithm
3484 * is supported for booting. We must return
3485 * something other than ENOTSUP since it
3486 * implies a downrev pool version.
3488 if (zfs_is_bootfs(dsname
) &&
3489 !BOOTFS_COMPRESS_VALID(intval
)) {
3495 case ZFS_PROP_COPIES
:
3496 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3500 case ZFS_PROP_DEDUP
:
3501 if (zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3505 case ZFS_PROP_SHARESMB
:
3506 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3510 case ZFS_PROP_ACLINHERIT
:
3511 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3512 nvpair_value_uint64(pair
, &intval
) == 0) {
3513 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3514 zfs_earlier_version(dsname
,
3515 SPA_VERSION_PASSTHROUGH_X
))
3523 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3527 * Activates a feature on a pool in response to a property setting. This
3528 * creates a new sync task which modifies the pool to reflect the feature
3532 zfs_prop_activate_feature(dsl_pool_t
*dp
, zfeature_info_t
*feature
)
3536 /* EBUSY here indicates that the feature is already active */
3537 err
= dsl_sync_task_do(dp
, zfs_prop_activate_feature_check
,
3538 zfs_prop_activate_feature_sync
, dp
->dp_spa
, feature
, 2);
3540 if (err
!= 0 && err
!= EBUSY
)
3547 * Checks for a race condition to make sure we don't increment a feature flag
3552 zfs_prop_activate_feature_check(void *arg1
, void *arg2
, dmu_tx_t
*tx
)
3555 zfeature_info_t
*feature
= arg2
;
3557 if (!spa_feature_is_active(spa
, feature
))
3564 * The callback invoked on feature activation in the sync task caused by
3565 * zfs_prop_activate_feature.
3568 zfs_prop_activate_feature_sync(void *arg1
, void *arg2
, dmu_tx_t
*tx
)
3571 zfeature_info_t
*feature
= arg2
;
3573 spa_feature_incr(spa
, feature
, tx
);
3577 * Removes properties from the given props list that fail permission checks
3578 * needed to clear them and to restore them in case of a receive error. For each
3579 * property, make sure we have both set and inherit permissions.
3581 * Returns the first error encountered if any permission checks fail. If the
3582 * caller provides a non-NULL errlist, it also gives the complete list of names
3583 * of all the properties that failed a permission check along with the
3584 * corresponding error numbers. The caller is responsible for freeing the
3587 * If every property checks out successfully, zero is returned and the list
3588 * pointed at by errlist is NULL.
3591 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3594 nvpair_t
*pair
, *next_pair
;
3601 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3603 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
3604 (void) strcpy(zc
->zc_name
, dataset
);
3605 pair
= nvlist_next_nvpair(props
, NULL
);
3606 while (pair
!= NULL
) {
3607 next_pair
= nvlist_next_nvpair(props
, pair
);
3609 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3610 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3611 (err
= zfs_secpolicy_inherit(zc
, CRED())) != 0) {
3612 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3613 VERIFY(nvlist_add_int32(errors
,
3614 zc
->zc_value
, err
) == 0);
3618 kmem_free(zc
, sizeof (zfs_cmd_t
));
3620 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3621 nvlist_free(errors
);
3624 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3627 if (errlist
== NULL
)
3628 nvlist_free(errors
);
3636 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3638 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3639 /* dsl_prop_get_all_impl() format */
3641 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3642 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3646 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3648 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3649 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3653 if (nvpair_type(p1
) != nvpair_type(p2
))
3656 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
3657 char *valstr1
, *valstr2
;
3659 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
3660 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
3661 return (strcmp(valstr1
, valstr2
) == 0);
3663 uint64_t intval1
, intval2
;
3665 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
3666 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
3667 return (intval1
== intval2
);
3672 * Remove properties from props if they are not going to change (as determined
3673 * by comparison with origprops). Remove them from origprops as well, since we
3674 * do not need to clear or restore properties that won't change.
3677 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
3679 nvpair_t
*pair
, *next_pair
;
3681 if (origprops
== NULL
)
3682 return; /* all props need to be received */
3684 pair
= nvlist_next_nvpair(props
, NULL
);
3685 while (pair
!= NULL
) {
3686 const char *propname
= nvpair_name(pair
);
3689 next_pair
= nvlist_next_nvpair(props
, pair
);
3691 if ((nvlist_lookup_nvpair(origprops
, propname
,
3692 &match
) != 0) || !propval_equals(pair
, match
))
3693 goto next
; /* need to set received value */
3695 /* don't clear the existing received value */
3696 (void) nvlist_remove_nvpair(origprops
, match
);
3697 /* don't bother receiving the property */
3698 (void) nvlist_remove_nvpair(props
, pair
);
3705 static boolean_t zfs_ioc_recv_inject_err
;
3710 * zc_name name of containing filesystem
3711 * zc_nvlist_src{_size} nvlist of properties to apply
3712 * zc_value name of snapshot to create
3713 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3714 * zc_cookie file descriptor to recv from
3715 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3716 * zc_guid force flag
3717 * zc_cleanup_fd cleanup-on-exit file descriptor
3718 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
3721 * zc_cookie number of bytes read
3722 * zc_nvlist_dst{_size} error for each unapplied received property
3723 * zc_obj zprop_errflags_t
3724 * zc_action_handle handle for this guid/ds mapping
3727 zfs_ioc_recv(zfs_cmd_t
*zc
)
3731 dmu_recv_cookie_t drc
;
3732 boolean_t force
= (boolean_t
)zc
->zc_guid
;
3735 int props_error
= 0;
3738 nvlist_t
*props
= NULL
; /* sent properties */
3739 nvlist_t
*origprops
= NULL
; /* existing properties */
3740 objset_t
*origin
= NULL
;
3742 char tofs
[ZFS_MAXNAMELEN
];
3743 boolean_t first_recvd_props
= B_FALSE
;
3745 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3746 strchr(zc
->zc_value
, '@') == NULL
||
3747 strchr(zc
->zc_value
, '%'))
3750 (void) strcpy(tofs
, zc
->zc_value
);
3751 tosnap
= strchr(tofs
, '@');
3754 if (zc
->zc_nvlist_src
!= 0 &&
3755 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3756 zc
->zc_iflags
, &props
)) != 0)
3766 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3768 if (props
&& dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
3769 if ((spa_version(os
->os_spa
) >= SPA_VERSION_RECVD_PROPS
) &&
3770 !dsl_prop_get_hasrecvd(os
)) {
3771 first_recvd_props
= B_TRUE
;
3775 * If new received properties are supplied, they are to
3776 * completely replace the existing received properties, so stash
3777 * away the existing ones.
3779 if (dsl_prop_get_received(os
, &origprops
) == 0) {
3780 nvlist_t
*errlist
= NULL
;
3782 * Don't bother writing a property if its value won't
3783 * change (and avoid the unnecessary security checks).
3785 * The first receive after SPA_VERSION_RECVD_PROPS is a
3786 * special case where we blow away all local properties
3789 if (!first_recvd_props
)
3790 props_reduce(props
, origprops
);
3791 if (zfs_check_clearable(tofs
, origprops
,
3793 (void) nvlist_merge(errors
, errlist
, 0);
3794 nvlist_free(errlist
);
3797 dmu_objset_rele(os
, FTAG
);
3800 if (zc
->zc_string
[0]) {
3801 error
= dmu_objset_hold(zc
->zc_string
, FTAG
, &origin
);
3806 error
= dmu_recv_begin(tofs
, tosnap
, zc
->zc_top_ds
,
3807 &zc
->zc_begin_record
, force
, origin
, &drc
);
3809 dmu_objset_rele(origin
, FTAG
);
3814 * Set properties before we receive the stream so that they are applied
3815 * to the new data. Note that we must call dmu_recv_stream() if
3816 * dmu_recv_begin() succeeds.
3821 if (dmu_objset_from_ds(drc
.drc_logical_ds
, &os
) == 0) {
3822 if (drc
.drc_newfs
) {
3823 if (spa_version(os
->os_spa
) >=
3824 SPA_VERSION_RECVD_PROPS
)
3825 first_recvd_props
= B_TRUE
;
3826 } else if (origprops
!= NULL
) {
3827 if (clear_received_props(os
, tofs
, origprops
,
3828 first_recvd_props
? NULL
: props
) != 0)
3829 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3831 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3833 dsl_prop_set_hasrecvd(os
);
3834 } else if (!drc
.drc_newfs
) {
3835 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3838 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
3840 (void) nvlist_merge(errors
, errlist
, 0);
3841 nvlist_free(errlist
);
3844 if (fit_error_list(zc
, &errors
) != 0 || put_nvlist(zc
, errors
) != 0) {
3846 * Caller made zc->zc_nvlist_dst less than the minimum expected
3847 * size or supplied an invalid address.
3849 props_error
= EINVAL
;
3853 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
3854 &zc
->zc_action_handle
);
3857 zfs_sb_t
*zsb
= NULL
;
3859 if (get_zfs_sb(tofs
, &zsb
) == 0) {
3863 error
= zfs_suspend_fs(zsb
);
3865 * If the suspend fails, then the recv_end will
3866 * likely also fail, and clean up after itself.
3868 end_err
= dmu_recv_end(&drc
);
3870 error
= zfs_resume_fs(zsb
, tofs
);
3871 error
= error
? error
: end_err
;
3872 deactivate_super(zsb
->z_sb
);
3874 error
= dmu_recv_end(&drc
);
3878 zc
->zc_cookie
= off
- fp
->f_offset
;
3879 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
3883 if (zfs_ioc_recv_inject_err
) {
3884 zfs_ioc_recv_inject_err
= B_FALSE
;
3889 * On error, restore the original props.
3891 if (error
&& props
) {
3892 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
3893 if (clear_received_props(os
, tofs
, props
, NULL
) != 0) {
3895 * We failed to clear the received properties.
3896 * Since we may have left a $recvd value on the
3897 * system, we can't clear the $hasrecvd flag.
3899 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3900 } else if (first_recvd_props
) {
3901 dsl_prop_unset_hasrecvd(os
);
3903 dmu_objset_rele(os
, FTAG
);
3904 } else if (!drc
.drc_newfs
) {
3905 /* We failed to clear the received properties. */
3906 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3909 if (origprops
== NULL
&& !drc
.drc_newfs
) {
3910 /* We failed to stash the original properties. */
3911 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3915 * dsl_props_set() will not convert RECEIVED to LOCAL on or
3916 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
3917 * explictly if we're restoring local properties cleared in the
3918 * first new-style receive.
3920 if (origprops
!= NULL
&&
3921 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
3922 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
3923 origprops
, NULL
) != 0) {
3925 * We stashed the original properties but failed to
3928 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
3933 nvlist_free(origprops
);
3934 nvlist_free(errors
);
3938 error
= props_error
;
3945 * zc_name name of snapshot to send
3946 * zc_cookie file descriptor to send stream to
3947 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
3948 * zc_sendobj objsetid of snapshot to send
3949 * zc_fromobj objsetid of incremental fromsnap (may be zero)
3950 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
3951 * output size in zc_objset_type.
3956 zfs_ioc_send(zfs_cmd_t
*zc
)
3958 objset_t
*fromsnap
= NULL
;
3963 dsl_dataset_t
*dsfrom
= NULL
;
3966 boolean_t estimate
= (zc
->zc_guid
!= 0);
3968 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
3972 dp
= spa_get_dsl(spa
);
3973 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
3974 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
3975 rw_exit(&dp
->dp_config_rwlock
);
3977 spa_close(spa
, FTAG
);
3981 error
= dmu_objset_from_ds(ds
, &tosnap
);
3983 dsl_dataset_rele(ds
, FTAG
);
3984 spa_close(spa
, FTAG
);
3988 if (zc
->zc_fromobj
!= 0) {
3989 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
3990 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
, FTAG
, &dsfrom
);
3991 rw_exit(&dp
->dp_config_rwlock
);
3992 spa_close(spa
, FTAG
);
3994 dsl_dataset_rele(ds
, FTAG
);
3997 error
= dmu_objset_from_ds(dsfrom
, &fromsnap
);
3999 dsl_dataset_rele(dsfrom
, FTAG
);
4000 dsl_dataset_rele(ds
, FTAG
);
4004 spa_close(spa
, FTAG
);
4008 error
= dmu_send_estimate(tosnap
, fromsnap
, zc
->zc_obj
,
4009 &zc
->zc_objset_type
);
4011 file_t
*fp
= getf(zc
->zc_cookie
);
4013 dsl_dataset_rele(ds
, FTAG
);
4015 dsl_dataset_rele(dsfrom
, FTAG
);
4020 error
= dmu_send(tosnap
, fromsnap
, zc
->zc_obj
,
4021 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4023 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4025 releasef(zc
->zc_cookie
);
4028 dsl_dataset_rele(dsfrom
, FTAG
);
4029 dsl_dataset_rele(ds
, FTAG
);
4035 * zc_name name of snapshot on which to report progress
4036 * zc_cookie file descriptor of send stream
4039 * zc_cookie number of bytes written in send stream thus far
4042 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4045 dmu_sendarg_t
*dsp
= NULL
;
4048 if ((error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &ds
)) != 0)
4051 mutex_enter(&ds
->ds_sendstream_lock
);
4054 * Iterate over all the send streams currently active on this dataset.
4055 * If there's one which matches the specified file descriptor _and_ the
4056 * stream was started by the current process, return the progress of
4060 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4061 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4062 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4063 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4068 zc
->zc_cookie
= *(dsp
->dsa_off
);
4072 mutex_exit(&ds
->ds_sendstream_lock
);
4073 dsl_dataset_rele(ds
, FTAG
);
4078 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4082 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4083 &zc
->zc_inject_record
);
4086 zc
->zc_guid
= (uint64_t)id
;
4092 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4094 return (zio_clear_fault((int)zc
->zc_guid
));
4098 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4100 int id
= (int)zc
->zc_guid
;
4103 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4104 &zc
->zc_inject_record
);
4112 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4116 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4118 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4121 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4124 zc
->zc_nvlist_dst_size
= count
;
4126 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4128 spa_close(spa
, FTAG
);
4134 zfs_ioc_clear(zfs_cmd_t
*zc
)
4141 * On zpool clear we also fix up missing slogs
4143 mutex_enter(&spa_namespace_lock
);
4144 spa
= spa_lookup(zc
->zc_name
);
4146 mutex_exit(&spa_namespace_lock
);
4149 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4150 /* we need to let spa_open/spa_load clear the chains */
4151 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4153 spa
->spa_last_open_failed
= 0;
4154 mutex_exit(&spa_namespace_lock
);
4156 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4157 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4160 nvlist_t
*config
= NULL
;
4162 if (zc
->zc_nvlist_src
== 0)
4165 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4166 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4167 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4169 if (config
!= NULL
) {
4172 if ((err
= put_nvlist(zc
, config
)) != 0)
4174 nvlist_free(config
);
4176 nvlist_free(policy
);
4183 spa_vdev_state_enter(spa
, SCL_NONE
);
4185 if (zc
->zc_guid
== 0) {
4188 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4190 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4191 spa_close(spa
, FTAG
);
4196 vdev_clear(spa
, vd
);
4198 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4201 * Resume any suspended I/Os.
4203 if (zio_resume(spa
) != 0)
4206 spa_close(spa
, FTAG
);
4212 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4217 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4221 spa_vdev_state_enter(spa
, SCL_NONE
);
4224 * If a resilver is already in progress then set the
4225 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4226 * the scan as a side effect of the reopen. Otherwise, let
4227 * vdev_open() decided if a resilver is required.
4229 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4230 vdev_reopen(spa
->spa_root_vdev
);
4231 spa
->spa_scrub_reopen
= B_FALSE
;
4233 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4234 spa_close(spa
, FTAG
);
4239 * zc_name name of filesystem
4240 * zc_value name of origin snapshot
4243 * zc_string name of conflicting snapshot, if there is one
4246 zfs_ioc_promote(zfs_cmd_t
*zc
)
4251 * We don't need to unmount *all* the origin fs's snapshots, but
4254 cp
= strchr(zc
->zc_value
, '@');
4257 (void) dmu_objset_find(zc
->zc_value
,
4258 zfs_unmount_snap
, NULL
, DS_FIND_SNAPSHOTS
);
4259 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4263 * Retrieve a single {user|group}{used|quota}@... property.
4266 * zc_name name of filesystem
4267 * zc_objset_type zfs_userquota_prop_t
4268 * zc_value domain name (eg. "S-1-234-567-89")
4269 * zc_guid RID/UID/GID
4272 * zc_cookie property value
4275 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4280 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4283 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4287 error
= zfs_userspace_one(zsb
,
4288 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4289 zfs_sb_rele(zsb
, FTAG
);
4296 * zc_name name of filesystem
4297 * zc_cookie zap cursor
4298 * zc_objset_type zfs_userquota_prop_t
4299 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4302 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4303 * zc_cookie zap cursor
4306 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4309 int bufsize
= zc
->zc_nvlist_dst_size
;
4316 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4320 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
4322 error
= zfs_userspace_many(zsb
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4323 buf
, &zc
->zc_nvlist_dst_size
);
4326 error
= xcopyout(buf
,
4327 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4328 zc
->zc_nvlist_dst_size
);
4330 vmem_free(buf
, bufsize
);
4331 zfs_sb_rele(zsb
, FTAG
);
4338 * zc_name name of filesystem
4344 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4350 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
4351 if (!dmu_objset_userused_enabled(zsb
->z_os
)) {
4353 * If userused is not enabled, it may be because the
4354 * objset needs to be closed & reopened (to grow the
4355 * objset_phys_t). Suspend/resume the fs will do that.
4357 error
= zfs_suspend_fs(zsb
);
4359 error
= zfs_resume_fs(zsb
, zc
->zc_name
);
4362 error
= dmu_objset_userspace_upgrade(zsb
->z_os
);
4363 deactivate_super(zsb
->z_sb
);
4365 /* XXX kind of reading contents without owning */
4366 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4370 error
= dmu_objset_userspace_upgrade(os
);
4371 dmu_objset_rele(os
, FTAG
);
4378 zfs_ioc_share(zfs_cmd_t
*zc
)
4383 ace_t full_access
[] = {
4384 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4389 * zc_name name of containing filesystem
4390 * zc_obj object # beyond which we want next in-use object #
4393 * zc_obj next in-use object #
4396 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4398 objset_t
*os
= NULL
;
4401 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4405 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4406 os
->os_dsl_dataset
->ds_phys
->ds_prev_snap_txg
);
4408 dmu_objset_rele(os
, FTAG
);
4414 * zc_name name of filesystem
4415 * zc_value prefix name for snapshot
4416 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4421 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
4426 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
4427 (u_longlong_t
)ddi_get_lbolt64());
4429 if (strlen(snap_name
) >= MAXNAMELEN
) {
4434 error
= dmu_objset_snapshot(zc
->zc_name
, snap_name
, snap_name
,
4435 NULL
, B_FALSE
, B_TRUE
, zc
->zc_cleanup_fd
);
4441 (void) strcpy(zc
->zc_value
, snap_name
);
4448 * zc_name name of "to" snapshot
4449 * zc_value name of "from" snapshot
4450 * zc_cookie file descriptor to write diff data on
4453 * dmu_diff_record_t's to the file descriptor
4456 zfs_ioc_diff(zfs_cmd_t
*zc
)
4464 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &tosnap
);
4468 error
= dmu_objset_hold(zc
->zc_value
, FTAG
, &fromsnap
);
4470 dmu_objset_rele(tosnap
, FTAG
);
4474 fp
= getf(zc
->zc_cookie
);
4476 dmu_objset_rele(fromsnap
, FTAG
);
4477 dmu_objset_rele(tosnap
, FTAG
);
4483 error
= dmu_diff(tosnap
, fromsnap
, fp
->f_vnode
, &off
);
4485 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4487 releasef(zc
->zc_cookie
);
4489 dmu_objset_rele(fromsnap
, FTAG
);
4490 dmu_objset_rele(tosnap
, FTAG
);
4495 * Remove all ACL files in shares dir
4497 #ifdef HAVE_SMB_SHARE
4499 zfs_smb_acl_purge(znode_t
*dzp
)
4502 zap_attribute_t zap
;
4503 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
4506 for (zap_cursor_init(&zc
, zsb
->z_os
, dzp
->z_id
);
4507 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
4508 zap_cursor_advance(&zc
)) {
4509 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
4513 zap_cursor_fini(&zc
);
4516 #endif /* HAVE_SMB_SHARE */
4519 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
4521 #ifdef HAVE_SMB_SHARE
4524 vnode_t
*resourcevp
= NULL
;
4533 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
4534 NO_FOLLOW
, NULL
, &vp
)) != 0)
4537 /* Now make sure mntpnt and dataset are ZFS */
4539 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
4540 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
4541 zc
->zc_name
) != 0)) {
4551 * Create share dir if its missing.
4553 mutex_enter(&zsb
->z_lock
);
4554 if (zsb
->z_shares_dir
== 0) {
4557 tx
= dmu_tx_create(zsb
->z_os
);
4558 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
4560 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
4561 error
= dmu_tx_assign(tx
, TXG_WAIT
);
4565 error
= zfs_create_share_dir(zsb
, tx
);
4569 mutex_exit(&zsb
->z_lock
);
4575 mutex_exit(&zsb
->z_lock
);
4577 ASSERT(zsb
->z_shares_dir
);
4578 if ((error
= zfs_zget(zsb
, zsb
->z_shares_dir
, &sharedir
)) != 0) {
4584 switch (zc
->zc_cookie
) {
4585 case ZFS_SMB_ACL_ADD
:
4586 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
4587 vattr
.va_mode
= S_IFREG
|0777;
4591 vsec
.vsa_mask
= VSA_ACE
;
4592 vsec
.vsa_aclentp
= &full_access
;
4593 vsec
.vsa_aclentsz
= sizeof (full_access
);
4594 vsec
.vsa_aclcnt
= 1;
4596 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
4597 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
4599 VN_RELE(resourcevp
);
4602 case ZFS_SMB_ACL_REMOVE
:
4603 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
4607 case ZFS_SMB_ACL_RENAME
:
4608 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4609 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
4614 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
4615 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
4618 VN_RELE(ZTOV(sharedir
));
4620 nvlist_free(nvlist
);
4623 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
4625 nvlist_free(nvlist
);
4628 case ZFS_SMB_ACL_PURGE
:
4629 error
= zfs_smb_acl_purge(sharedir
);
4638 VN_RELE(ZTOV(sharedir
));
4645 #endif /* HAVE_SMB_SHARE */
4650 * zc_name name of filesystem
4651 * zc_value short name of snap
4652 * zc_string user-supplied tag for this hold
4653 * zc_cookie recursive flag
4654 * zc_temphold set if hold is temporary
4655 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4656 * zc_sendobj if non-zero, the objid for zc_name@zc_value
4657 * zc_createtxg if zc_sendobj is non-zero, snap must have zc_createtxg
4662 zfs_ioc_hold(zfs_cmd_t
*zc
)
4664 boolean_t recursive
= zc
->zc_cookie
;
4671 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
4674 if (zc
->zc_sendobj
== 0) {
4675 return (dsl_dataset_user_hold(zc
->zc_name
, zc
->zc_value
,
4676 zc
->zc_string
, recursive
, zc
->zc_temphold
,
4677 zc
->zc_cleanup_fd
));
4683 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4687 dp
= spa_get_dsl(spa
);
4688 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
4689 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
4690 rw_exit(&dp
->dp_config_rwlock
);
4691 spa_close(spa
, FTAG
);
4696 * Until we have a hold on this snapshot, it's possible that
4697 * zc_sendobj could've been destroyed and reused as part
4698 * of a later txg. Make sure we're looking at the right object.
4700 if (zc
->zc_createtxg
!= ds
->ds_phys
->ds_creation_txg
) {
4701 dsl_dataset_rele(ds
, FTAG
);
4705 if (zc
->zc_cleanup_fd
!= -1 && zc
->zc_temphold
) {
4706 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
4708 dsl_dataset_rele(ds
, FTAG
);
4713 error
= dsl_dataset_user_hold_for_send(ds
, zc
->zc_string
,
4717 dsl_register_onexit_hold_cleanup(ds
, zc
->zc_string
,
4720 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
4722 dsl_dataset_rele(ds
, FTAG
);
4729 * zc_name name of dataset from which we're releasing a user hold
4730 * zc_value short name of snap
4731 * zc_string user-supplied tag for this hold
4732 * zc_cookie recursive flag
4737 zfs_ioc_release(zfs_cmd_t
*zc
)
4739 boolean_t recursive
= zc
->zc_cookie
;
4741 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
4744 return (dsl_dataset_user_release(zc
->zc_name
, zc
->zc_value
,
4745 zc
->zc_string
, recursive
));
4750 * zc_name name of filesystem
4753 * zc_nvlist_src{_size} nvlist of snapshot holds
4756 zfs_ioc_get_holds(zfs_cmd_t
*zc
)
4761 if ((error
= dsl_dataset_get_holds(zc
->zc_name
, &nvp
)) == 0) {
4762 error
= put_nvlist(zc
, nvp
);
4771 * zc_guid flags (ZEVENT_NONBLOCK)
4774 * zc_nvlist_dst next nvlist event
4775 * zc_cookie dropped events since last get
4776 * zc_cleanup_fd cleanup-on-exit file descriptor
4779 zfs_ioc_events_next(zfs_cmd_t
*zc
)
4782 nvlist_t
*event
= NULL
;
4784 uint64_t dropped
= 0;
4787 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
4792 error
= zfs_zevent_next(ze
, &event
,
4793 &zc
->zc_nvlist_dst_size
, &dropped
);
4794 if (event
!= NULL
) {
4795 zc
->zc_cookie
= dropped
;
4796 error
= put_nvlist(zc
, event
);
4800 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
4803 if ((error
== 0) || (error
!= ENOENT
))
4806 error
= zfs_zevent_wait(ze
);
4811 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
4818 * zc_cookie cleared events count
4821 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
4825 zfs_zevent_drain_all(&count
);
4826 zc
->zc_cookie
= count
;
4833 * zc_name name of new filesystem or snapshot
4834 * zc_value full name of old snapshot
4837 * zc_cookie space in bytes
4838 * zc_objset_type compressed space in bytes
4839 * zc_perm_action uncompressed space in bytes
4842 zfs_ioc_space_written(zfs_cmd_t
*zc
)
4845 dsl_dataset_t
*new, *old
;
4847 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &new);
4850 error
= dsl_dataset_hold(zc
->zc_value
, FTAG
, &old
);
4852 dsl_dataset_rele(new, FTAG
);
4856 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
4857 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
4858 dsl_dataset_rele(old
, FTAG
);
4859 dsl_dataset_rele(new, FTAG
);
4865 * zc_name full name of last snapshot
4866 * zc_value full name of first snapshot
4869 * zc_cookie space in bytes
4870 * zc_objset_type compressed space in bytes
4871 * zc_perm_action uncompressed space in bytes
4874 zfs_ioc_space_snaps(zfs_cmd_t
*zc
)
4877 dsl_dataset_t
*new, *old
;
4879 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &new);
4882 error
= dsl_dataset_hold(zc
->zc_value
, FTAG
, &old
);
4884 dsl_dataset_rele(new, FTAG
);
4888 error
= dsl_dataset_space_wouldfree(old
, new, &zc
->zc_cookie
,
4889 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
4890 dsl_dataset_rele(old
, FTAG
);
4891 dsl_dataset_rele(new, FTAG
);
4896 * pool create, destroy, and export don't log the history as part of
4897 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
4898 * do the logging of those commands.
4900 static zfs_ioc_vec_t zfs_ioc_vec
[] = {
4901 { zfs_ioc_pool_create
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4903 { zfs_ioc_pool_destroy
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4905 { zfs_ioc_pool_import
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4907 { zfs_ioc_pool_export
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4909 { zfs_ioc_pool_configs
, zfs_secpolicy_none
, NO_NAME
, B_FALSE
,
4911 { zfs_ioc_pool_stats
, zfs_secpolicy_read
, POOL_NAME
, B_FALSE
,
4913 { zfs_ioc_pool_tryimport
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
4915 { zfs_ioc_pool_scan
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4916 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4917 { zfs_ioc_pool_freeze
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
4918 POOL_CHECK_READONLY
},
4919 { zfs_ioc_pool_upgrade
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4920 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4921 { zfs_ioc_pool_get_history
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4923 { zfs_ioc_vdev_add
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4924 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4925 { zfs_ioc_vdev_remove
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4926 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4927 { zfs_ioc_vdev_set_state
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4928 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4929 { zfs_ioc_vdev_attach
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4930 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4931 { zfs_ioc_vdev_detach
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4932 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4933 { zfs_ioc_vdev_setpath
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4934 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4935 { zfs_ioc_vdev_setfru
, zfs_secpolicy_config
, POOL_NAME
, B_FALSE
,
4936 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4937 { zfs_ioc_objset_stats
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4938 POOL_CHECK_SUSPENDED
},
4939 { zfs_ioc_objset_zplprops
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4941 { zfs_ioc_dataset_list_next
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4942 POOL_CHECK_SUSPENDED
},
4943 { zfs_ioc_snapshot_list_next
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4944 POOL_CHECK_SUSPENDED
},
4945 { zfs_ioc_set_prop
, zfs_secpolicy_none
, DATASET_NAME
, B_TRUE
,
4946 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4947 { zfs_ioc_create_minor
, zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
,
4949 { zfs_ioc_remove_minor
, zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
,
4951 { zfs_ioc_create
, zfs_secpolicy_create
, DATASET_NAME
, B_TRUE
,
4952 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4953 { zfs_ioc_destroy
, zfs_secpolicy_destroy
, DATASET_NAME
, B_TRUE
,
4954 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4955 { zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
, B_TRUE
,
4956 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4957 { zfs_ioc_rename
, zfs_secpolicy_rename
, DATASET_NAME
, B_TRUE
,
4958 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4959 { zfs_ioc_recv
, zfs_secpolicy_receive
, DATASET_NAME
, B_TRUE
,
4960 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4961 { zfs_ioc_send
, zfs_secpolicy_send
, DATASET_NAME
, B_FALSE
,
4963 { zfs_ioc_inject_fault
, zfs_secpolicy_inject
, NO_NAME
, B_FALSE
,
4965 { zfs_ioc_clear_fault
, zfs_secpolicy_inject
, NO_NAME
, B_FALSE
,
4967 { zfs_ioc_inject_list_next
, zfs_secpolicy_inject
, NO_NAME
, B_FALSE
,
4969 { zfs_ioc_error_log
, zfs_secpolicy_inject
, POOL_NAME
, B_FALSE
,
4971 { zfs_ioc_clear
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4973 { zfs_ioc_promote
, zfs_secpolicy_promote
, DATASET_NAME
, B_TRUE
,
4974 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4975 { zfs_ioc_destroy_snaps_nvl
, zfs_secpolicy_destroy_recursive
,
4976 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4977 { zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, DATASET_NAME
, B_TRUE
,
4978 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4979 { zfs_ioc_dsobj_to_dsname
, zfs_secpolicy_diff
, POOL_NAME
, B_FALSE
,
4981 { zfs_ioc_obj_to_path
, zfs_secpolicy_diff
, DATASET_NAME
, B_FALSE
,
4982 POOL_CHECK_SUSPENDED
},
4983 { zfs_ioc_pool_set_props
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
4984 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4985 { zfs_ioc_pool_get_props
, zfs_secpolicy_read
, POOL_NAME
, B_FALSE
,
4987 { zfs_ioc_set_fsacl
, zfs_secpolicy_fsacl
, DATASET_NAME
, B_TRUE
,
4988 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4989 { zfs_ioc_get_fsacl
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
4991 { zfs_ioc_share
, zfs_secpolicy_share
, DATASET_NAME
, B_FALSE
,
4993 { zfs_ioc_inherit_prop
, zfs_secpolicy_inherit
, DATASET_NAME
, B_TRUE
,
4994 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
4995 { zfs_ioc_smb_acl
, zfs_secpolicy_smb_acl
, DATASET_NAME
, B_FALSE
,
4997 { zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
, DATASET_NAME
,
4998 B_FALSE
, POOL_CHECK_NONE
},
4999 { zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
, DATASET_NAME
,
5000 B_FALSE
, POOL_CHECK_NONE
},
5001 { zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5002 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5003 { zfs_ioc_hold
, zfs_secpolicy_hold
, DATASET_NAME
, B_TRUE
,
5004 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5005 { zfs_ioc_release
, zfs_secpolicy_release
, DATASET_NAME
, B_TRUE
,
5006 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5007 { zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5008 POOL_CHECK_SUSPENDED
},
5009 { zfs_ioc_objset_recvd_props
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5011 { zfs_ioc_vdev_split
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
5012 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5013 { zfs_ioc_next_obj
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5015 { zfs_ioc_diff
, zfs_secpolicy_diff
, DATASET_NAME
, B_FALSE
,
5017 { zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
, DATASET_NAME
,
5018 B_FALSE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5019 { zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
, DATASET_NAME
, B_FALSE
,
5020 POOL_CHECK_SUSPENDED
},
5021 { zfs_ioc_events_next
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
5023 { zfs_ioc_events_clear
, zfs_secpolicy_config
, NO_NAME
, B_FALSE
,
5025 { zfs_ioc_pool_reguid
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
5026 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
},
5027 { zfs_ioc_space_written
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5028 POOL_CHECK_SUSPENDED
},
5029 { zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5030 POOL_CHECK_SUSPENDED
},
5031 { zfs_ioc_pool_reopen
, zfs_secpolicy_config
, POOL_NAME
, B_TRUE
,
5032 POOL_CHECK_SUSPENDED
},
5033 { zfs_ioc_send_progress
, zfs_secpolicy_read
, DATASET_NAME
, B_FALSE
,
5038 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5039 zfs_ioc_poolcheck_t check
)
5044 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5046 if (check
& POOL_CHECK_NONE
)
5049 error
= spa_open(name
, &spa
, FTAG
);
5051 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5053 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5055 spa_close(spa
, FTAG
);
5061 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
5065 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5067 for (zs
= list_head(&zfsdev_state_list
); zs
!= NULL
;
5068 zs
= list_next(&zfsdev_state_list
, zs
)) {
5069 if (zs
->zs_minor
== minor
) {
5071 case ZST_ONEXIT
: return (zs
->zs_onexit
);
5072 case ZST_ZEVENT
: return (zs
->zs_zevent
);
5073 case ZST_ALL
: return (zs
);
5082 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
5086 mutex_enter(&zfsdev_state_lock
);
5087 ptr
= zfsdev_get_state_impl(minor
, which
);
5088 mutex_exit(&zfsdev_state_lock
);
5094 zfsdev_getminor(struct file
*filp
)
5096 ASSERT(filp
!= NULL
);
5097 ASSERT(filp
->private_data
!= NULL
);
5099 return (((zfsdev_state_t
*)filp
->private_data
)->zs_minor
);
5103 * Find a free minor number. The zfsdev_state_list is expected to
5104 * be short since it is only a list of currently open file handles.
5107 zfsdev_minor_alloc(void)
5109 static minor_t last_minor
= 0;
5112 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5114 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5115 if (m
> ZFSDEV_MAX_MINOR
)
5117 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
5127 zfsdev_state_init(struct file
*filp
)
5132 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5134 minor
= zfsdev_minor_alloc();
5138 zs
= kmem_zalloc( sizeof(zfsdev_state_t
), KM_SLEEP
);
5141 zs
->zs_minor
= minor
;
5142 filp
->private_data
= zs
;
5144 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
5145 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
5147 list_insert_tail(&zfsdev_state_list
, zs
);
5153 zfsdev_state_destroy(struct file
*filp
)
5157 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5158 ASSERT(filp
->private_data
!= NULL
);
5160 zs
= filp
->private_data
;
5161 zfs_onexit_destroy(zs
->zs_onexit
);
5162 zfs_zevent_destroy(zs
->zs_zevent
);
5164 list_remove(&zfsdev_state_list
, zs
);
5165 kmem_free(zs
, sizeof(zfsdev_state_t
));
5171 zfsdev_open(struct inode
*ino
, struct file
*filp
)
5175 mutex_enter(&zfsdev_state_lock
);
5176 error
= zfsdev_state_init(filp
);
5177 mutex_exit(&zfsdev_state_lock
);
5183 zfsdev_release(struct inode
*ino
, struct file
*filp
)
5187 mutex_enter(&zfsdev_state_lock
);
5188 error
= zfsdev_state_destroy(filp
);
5189 mutex_exit(&zfsdev_state_lock
);
5195 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5199 int error
, rc
, flag
= 0;
5201 vec
= cmd
- ZFS_IOC
;
5202 if (vec
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
5205 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
5207 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
5211 if ((error
== 0) && !(flag
& FKIOCTL
))
5212 error
= zfs_ioc_vec
[vec
].zvec_secpolicy(zc
, CRED());
5215 * Ensure that all pool/dataset names are valid before we pass down to
5219 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5220 zc
->zc_iflags
= flag
& FKIOCTL
;
5221 switch (zfs_ioc_vec
[vec
].zvec_namecheck
) {
5223 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5225 error
= pool_status_check(zc
->zc_name
,
5226 zfs_ioc_vec
[vec
].zvec_namecheck
,
5227 zfs_ioc_vec
[vec
].zvec_pool_check
);
5231 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5233 error
= pool_status_check(zc
->zc_name
,
5234 zfs_ioc_vec
[vec
].zvec_namecheck
,
5235 zfs_ioc_vec
[vec
].zvec_pool_check
);
5244 error
= zfs_ioc_vec
[vec
].zvec_func(zc
);
5246 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
5250 if (zfs_ioc_vec
[vec
].zvec_his_log
)
5251 zfs_log_history(zc
);
5254 kmem_free(zc
, sizeof (zfs_cmd_t
));
5258 #ifdef CONFIG_COMPAT
5260 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5262 return zfsdev_ioctl(filp
, cmd
, arg
);
5265 #define zfsdev_compat_ioctl NULL
5268 static const struct file_operations zfsdev_fops
= {
5269 .open
= zfsdev_open
,
5270 .release
= zfsdev_release
,
5271 .unlocked_ioctl
= zfsdev_ioctl
,
5272 .compat_ioctl
= zfsdev_compat_ioctl
,
5273 .owner
= THIS_MODULE
,
5276 static struct miscdevice zfs_misc
= {
5277 .minor
= MISC_DYNAMIC_MINOR
,
5279 .fops
= &zfsdev_fops
,
5287 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
5288 list_create(&zfsdev_state_list
, sizeof (zfsdev_state_t
),
5289 offsetof(zfsdev_state_t
, zs_next
));
5291 error
= misc_register(&zfs_misc
);
5293 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
5305 error
= misc_deregister(&zfs_misc
);
5307 printk(KERN_INFO
"ZFS: misc_deregister() failed %d\n", error
);
5309 mutex_destroy(&zfsdev_state_lock
);
5310 list_destroy(&zfsdev_state_list
);
5313 uint_t zfs_fsyncer_key
;
5314 extern uint_t rrw_tsd_key
;
5317 #define ZFS_DEBUG_STR " (DEBUG mode)"
5319 #define ZFS_DEBUG_STR ""
5327 spa_init(FREAD
| FWRITE
);
5330 if ((error
= zvol_init()) != 0)
5333 if ((error
= zfs_attach()) != 0)
5336 tsd_create(&zfs_fsyncer_key
, NULL
);
5337 tsd_create(&rrw_tsd_key
, NULL
);
5339 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
5340 "ZFS pool version %s, ZFS filesystem version %s\n",
5341 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
5342 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
5351 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
5352 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
5353 ZFS_DEBUG_STR
, error
);
5366 tsd_destroy(&zfs_fsyncer_key
);
5367 tsd_destroy(&rrw_tsd_key
);
5369 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
5370 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
5376 spl_module_init(_init
);
5377 spl_module_exit(_fini
);
5379 MODULE_DESCRIPTION("ZFS");
5380 MODULE_AUTHOR(ZFS_META_AUTHOR
);
5381 MODULE_LICENSE(ZFS_META_LICENSE
);
5382 #endif /* HAVE_SPL */