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.
31 * Copyright (c) 2012 by Delphix. All rights reserved.
37 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
38 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
40 * There are two ways that we handle ioctls: the legacy way where almost
41 * all of the logic is in the ioctl callback, and the new way where most
42 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
44 * Non-legacy ioctls should be registered by calling
45 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
46 * from userland by lzc_ioctl().
48 * The registration arguments are as follows:
51 * The name of the ioctl. This is used for history logging. If the
52 * ioctl returns successfully (the callback returns 0), and allow_log
53 * is true, then a history log entry will be recorded with the input &
54 * output nvlists. The log entry can be printed with "zpool history -i".
57 * The ioctl request number, which userland will pass to ioctl(2).
58 * The ioctl numbers can change from release to release, because
59 * the caller (libzfs) must be matched to the kernel.
61 * zfs_secpolicy_func_t *secpolicy
62 * This function will be called before the zfs_ioc_func_t, to
63 * determine if this operation is permitted. It should return EPERM
64 * on failure, and 0 on success. Checks include determining if the
65 * dataset is visible in this zone, and if the user has either all
66 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
67 * to do this operation on this dataset with "zfs allow".
69 * zfs_ioc_namecheck_t namecheck
70 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
71 * name, a dataset name, or nothing. If the name is not well-formed,
72 * the ioctl will fail and the callback will not be called.
73 * Therefore, the callback can assume that the name is well-formed
74 * (e.g. is null-terminated, doesn't have more than one '@' character,
75 * doesn't have invalid characters).
77 * zfs_ioc_poolcheck_t pool_check
78 * This specifies requirements on the pool state. If the pool does
79 * not meet them (is suspended or is readonly), the ioctl will fail
80 * and the callback will not be called. If any checks are specified
81 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
82 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
83 * POOL_CHECK_READONLY).
85 * boolean_t smush_outnvlist
86 * If smush_outnvlist is true, then the output is presumed to be a
87 * list of errors, and it will be "smushed" down to fit into the
88 * caller's buffer, by removing some entries and replacing them with a
89 * single "N_MORE_ERRORS" entry indicating how many were removed. See
90 * nvlist_smush() for details. If smush_outnvlist is false, and the
91 * outnvlist does not fit into the userland-provided buffer, then the
92 * ioctl will fail with ENOMEM.
94 * zfs_ioc_func_t *func
95 * The callback function that will perform the operation.
97 * The callback should return 0 on success, or an error number on
98 * failure. If the function fails, the userland ioctl will return -1,
99 * and errno will be set to the callback's return value. The callback
100 * will be called with the following arguments:
103 * The name of the pool or dataset to operate on, from
104 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
105 * expected type (pool, dataset, or none).
108 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
109 * NULL if no input nvlist was provided. Changes to this nvlist are
110 * ignored. If the input nvlist could not be deserialized, the
111 * ioctl will fail and the callback will not be called.
114 * The output nvlist, initially empty. The callback can fill it in,
115 * and it will be returned to userland by serializing it into
116 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
117 * fails (e.g. because the caller didn't supply a large enough
118 * buffer), then the overall ioctl will fail. See the
119 * 'smush_nvlist' argument above for additional behaviors.
121 * There are two typical uses of the output nvlist:
122 * - To return state, e.g. property values. In this case,
123 * smush_outnvlist should be false. If the buffer was not large
124 * enough, the caller will reallocate a larger buffer and try
127 * - To return multiple errors from an ioctl which makes on-disk
128 * changes. In this case, smush_outnvlist should be true.
129 * Ioctls which make on-disk modifications should generally not
130 * use the outnvl if they succeed, because the caller can not
131 * distinguish between the operation failing, and
132 * deserialization failing.
135 #include <sys/types.h>
136 #include <sys/param.h>
137 #include <sys/errno.h>
140 #include <sys/modctl.h>
141 #include <sys/open.h>
142 #include <sys/file.h>
143 #include <sys/kmem.h>
144 #include <sys/conf.h>
145 #include <sys/cmn_err.h>
146 #include <sys/stat.h>
147 #include <sys/zfs_ioctl.h>
148 #include <sys/zfs_vfsops.h>
149 #include <sys/zfs_znode.h>
152 #include <sys/spa_impl.h>
153 #include <sys/vdev.h>
154 #include <sys/priv_impl.h>
156 #include <sys/dsl_dir.h>
157 #include <sys/dsl_dataset.h>
158 #include <sys/dsl_prop.h>
159 #include <sys/dsl_deleg.h>
160 #include <sys/dmu_objset.h>
161 #include <sys/dmu_impl.h>
163 #include <sys/sunddi.h>
164 #include <sys/sunldi.h>
165 #include <sys/policy.h>
166 #include <sys/zone.h>
167 #include <sys/nvpair.h>
168 #include <sys/pathname.h>
169 #include <sys/mount.h>
171 #include <sys/fs/zfs.h>
172 #include <sys/zfs_ctldir.h>
173 #include <sys/zfs_dir.h>
174 #include <sys/zfs_onexit.h>
175 #include <sys/zvol.h>
176 #include <sys/dsl_scan.h>
177 #include <sharefs/share.h>
178 #include <sys/dmu_objset.h>
179 #include <sys/fm/util.h>
181 #include <sys/zfeature.h>
183 #include <linux/miscdevice.h>
185 #include "zfs_namecheck.h"
186 #include "zfs_prop.h"
187 #include "zfs_deleg.h"
188 #include "zfs_comutil.h"
190 kmutex_t zfsdev_state_lock
;
191 list_t zfsdev_state_list
;
193 extern void zfs_init(void);
194 extern void zfs_fini(void);
196 uint_t zfs_fsyncer_key
;
197 extern uint_t rrw_tsd_key
;
198 static uint_t zfs_allow_log_key
;
200 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
201 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
202 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
208 } zfs_ioc_namecheck_t
;
211 POOL_CHECK_NONE
= 1 << 0,
212 POOL_CHECK_SUSPENDED
= 1 << 1,
213 POOL_CHECK_READONLY
= 1 << 2,
214 } zfs_ioc_poolcheck_t
;
216 typedef struct zfs_ioc_vec
{
217 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
218 zfs_ioc_func_t
*zvec_func
;
219 zfs_secpolicy_func_t
*zvec_secpolicy
;
220 zfs_ioc_namecheck_t zvec_namecheck
;
221 boolean_t zvec_allow_log
;
222 zfs_ioc_poolcheck_t zvec_pool_check
;
223 boolean_t zvec_smush_outnvlist
;
224 const char *zvec_name
;
227 /* This array is indexed by zfs_userquota_prop_t */
228 static const char *userquota_perms
[] = {
229 ZFS_DELEG_PERM_USERUSED
,
230 ZFS_DELEG_PERM_USERQUOTA
,
231 ZFS_DELEG_PERM_GROUPUSED
,
232 ZFS_DELEG_PERM_GROUPQUOTA
,
235 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
236 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
238 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
240 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
242 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
243 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
245 static int zfs_prop_activate_feature(dsl_pool_t
*dp
, zfeature_info_t
*feature
);
246 static int zfs_prop_activate_feature_check(void *arg1
, void *arg2
,
248 static void zfs_prop_activate_feature_sync(void *arg1
, void *arg2
,
252 history_str_free(char *buf
)
254 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
258 history_str_get(zfs_cmd_t
*zc
)
262 if (zc
->zc_history
== 0)
265 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
| KM_NODEBUG
);
266 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
267 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
268 history_str_free(buf
);
272 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
278 * Check to see if the named dataset is currently defined as bootable
281 zfs_is_bootfs(const char *name
)
285 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
287 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
288 dmu_objset_rele(os
, FTAG
);
295 * zfs_earlier_version
297 * Return non-zero if the spa version is less than requested version.
300 zfs_earlier_version(const char *name
, int version
)
304 if (spa_open(name
, &spa
, FTAG
) == 0) {
305 if (spa_version(spa
) < version
) {
306 spa_close(spa
, FTAG
);
309 spa_close(spa
, FTAG
);
315 * zpl_earlier_version
317 * Return TRUE if the ZPL version is less than requested version.
320 zpl_earlier_version(const char *name
, int version
)
323 boolean_t rc
= B_TRUE
;
325 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
328 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
329 dmu_objset_rele(os
, FTAG
);
332 /* XXX reading from non-owned objset */
333 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
334 rc
= zplversion
< version
;
335 dmu_objset_rele(os
, FTAG
);
341 zfs_log_history(zfs_cmd_t
*zc
)
346 if ((buf
= history_str_get(zc
)) == NULL
)
349 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
350 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
351 (void) spa_history_log(spa
, buf
);
352 spa_close(spa
, FTAG
);
354 history_str_free(buf
);
358 * Policy for top-level read operations (list pools). Requires no privileges,
359 * and can be used in the local zone, as there is no associated dataset.
363 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
369 * Policy for dataset read operations (list children, get statistics). Requires
370 * no privileges, but must be visible in the local zone.
374 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
376 if (INGLOBALZONE(curproc
) ||
377 zone_dataset_visible(zc
->zc_name
, NULL
))
384 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
389 * The dataset must be visible by this zone -- check this first
390 * so they don't see EPERM on something they shouldn't know about.
392 if (!INGLOBALZONE(curproc
) &&
393 !zone_dataset_visible(dataset
, &writable
))
396 if (INGLOBALZONE(curproc
)) {
398 * If the fs is zoned, only root can access it from the
401 if (secpolicy_zfs(cr
) && zoned
)
405 * If we are in a local zone, the 'zoned' property must be set.
410 /* must be writable by this zone */
418 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
422 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
425 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
429 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
433 rw_enter(&ds
->ds_dir
->dd_pool
->dp_config_rwlock
, RW_READER
);
434 if (dsl_prop_get_ds(ds
, "zoned", 8, 1, &zoned
, NULL
)) {
435 rw_exit(&ds
->ds_dir
->dd_pool
->dp_config_rwlock
);
438 rw_exit(&ds
->ds_dir
->dd_pool
->dp_config_rwlock
);
440 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
444 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
449 error
= dsl_dataset_hold(name
, FTAG
, &ds
);
453 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
455 error
= secpolicy_zfs(cr
);
457 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
460 dsl_dataset_rele(ds
, FTAG
);
465 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
466 const char *perm
, cred_t
*cr
)
470 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
472 error
= secpolicy_zfs(cr
);
474 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
480 * Policy for setting the security label property.
482 * Returns 0 for success, non-zero for access and other errors.
485 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
488 char ds_hexsl
[MAXNAMELEN
];
489 bslabel_t ds_sl
, new_sl
;
490 boolean_t new_default
= FALSE
;
492 int needed_priv
= -1;
495 /* First get the existing dataset label. */
496 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
497 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
501 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
504 /* The label must be translatable */
505 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
509 * In a non-global zone, disallow attempts to set a label that
510 * doesn't match that of the zone; otherwise no other checks
513 if (!INGLOBALZONE(curproc
)) {
514 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
520 * For global-zone datasets (i.e., those whose zoned property is
521 * "off", verify that the specified new label is valid for the
524 if (dsl_prop_get_integer(name
,
525 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
528 if (zfs_check_global_label(name
, strval
) != 0)
533 * If the existing dataset label is nondefault, check if the
534 * dataset is mounted (label cannot be changed while mounted).
535 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
536 * mounted (or isn't a dataset, doesn't exist, ...).
538 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
540 static char *setsl_tag
= "setsl_tag";
543 * Try to own the dataset; abort if there is any error,
544 * (e.g., already mounted, in use, or other error).
546 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
,
551 dmu_objset_disown(os
, setsl_tag
);
554 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
558 if (hexstr_to_label(strval
, &new_sl
) != 0)
561 if (blstrictdom(&ds_sl
, &new_sl
))
562 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
563 else if (blstrictdom(&new_sl
, &ds_sl
))
564 needed_priv
= PRIV_FILE_UPGRADE_SL
;
566 /* dataset currently has a default label */
568 needed_priv
= PRIV_FILE_UPGRADE_SL
;
572 if (needed_priv
!= -1)
573 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
577 #endif /* HAVE_MLSLABEL */
581 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
587 * Check permissions for special properties.
594 * Disallow setting of 'zoned' from within a local zone.
596 if (!INGLOBALZONE(curproc
))
601 if (!INGLOBALZONE(curproc
)) {
603 char setpoint
[MAXNAMELEN
];
605 * Unprivileged users are allowed to modify the
606 * quota on things *under* (ie. contained by)
607 * the thing they own.
609 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
612 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
617 case ZFS_PROP_MLSLABEL
:
618 if (!is_system_labeled())
621 if (nvpair_value_string(propval
, &strval
) == 0) {
624 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
631 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
636 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
640 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
645 * permission to set permissions will be evaluated later in
646 * dsl_deleg_can_allow()
653 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
655 return (zfs_secpolicy_write_perms(zc
->zc_name
,
656 ZFS_DELEG_PERM_ROLLBACK
, cr
));
661 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
670 * Generate the current snapshot name from the given objsetid, then
671 * use that name for the secpolicy/zone checks.
673 cp
= strchr(zc
->zc_name
, '@');
676 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
680 dp
= spa_get_dsl(spa
);
681 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
682 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
683 rw_exit(&dp
->dp_config_rwlock
);
684 spa_close(spa
, FTAG
);
688 dsl_dataset_name(ds
, zc
->zc_name
);
690 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
691 ZFS_DELEG_PERM_SEND
, cr
);
692 dsl_dataset_rele(ds
, FTAG
);
699 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
701 return (zfs_secpolicy_write_perms(zc
->zc_name
,
702 ZFS_DELEG_PERM_SEND
, cr
));
705 #ifdef HAVE_SMB_SHARE
708 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
713 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
714 NO_FOLLOW
, NULL
, &vp
)) != 0)
717 /* Now make sure mntpnt and dataset are ZFS */
719 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
720 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
721 zc
->zc_name
) != 0)) {
727 return (dsl_deleg_access(zc
->zc_name
,
728 ZFS_DELEG_PERM_SHARE
, cr
));
730 #endif /* HAVE_SMB_SHARE */
733 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
735 #ifdef HAVE_SMB_SHARE
736 if (!INGLOBALZONE(curproc
))
739 if (secpolicy_nfs(cr
) == 0) {
742 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
746 #endif /* HAVE_SMB_SHARE */
750 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
752 #ifdef HAVE_SMB_SHARE
753 if (!INGLOBALZONE(curproc
))
756 if (secpolicy_smb(cr
) == 0) {
759 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
763 #endif /* HAVE_SMB_SHARE */
767 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
772 * Remove the @bla or /bla from the end of the name to get the parent.
774 (void) strncpy(parent
, datasetname
, parentsize
);
775 cp
= strrchr(parent
, '@');
779 cp
= strrchr(parent
, '/');
789 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
793 if ((error
= zfs_secpolicy_write_perms(name
,
794 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
797 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
802 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
804 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
808 * Destroying snapshots with delegated permissions requires
809 * descendant mount and destroy permissions.
813 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
816 nvpair_t
*pair
, *nextpair
;
819 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
821 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
825 nextpair
= nvlist_next_nvpair(snaps
, pair
);
826 error
= dsl_dataset_hold(nvpair_name(pair
), FTAG
, &ds
);
828 dsl_dataset_rele(ds
, FTAG
);
829 } else if (error
== ENOENT
) {
831 * Ignore any snapshots that don't exist (we consider
832 * them "already destroyed"). Remove the name from the
833 * nvl here in case the snapshot is created between
834 * now and when we try to destroy it (in which case
835 * we don't want to destroy it since we haven't
836 * checked for permission).
838 fnvlist_remove_nvpair(snaps
, pair
);
844 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
853 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
855 char parentname
[MAXNAMELEN
];
858 if ((error
= zfs_secpolicy_write_perms(from
,
859 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
862 if ((error
= zfs_secpolicy_write_perms(from
,
863 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
866 if ((error
= zfs_get_parent(to
, parentname
,
867 sizeof (parentname
))) != 0)
870 if ((error
= zfs_secpolicy_write_perms(parentname
,
871 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
874 if ((error
= zfs_secpolicy_write_perms(parentname
,
875 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
883 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
885 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
890 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
892 char parentname
[MAXNAMELEN
];
896 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
897 ZFS_DELEG_PERM_PROMOTE
, cr
);
901 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &clone
);
904 dsl_dataset_t
*pclone
= NULL
;
906 dd
= clone
->os_dsl_dataset
->ds_dir
;
908 rw_enter(&dd
->dd_pool
->dp_config_rwlock
, RW_READER
);
909 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
910 dd
->dd_phys
->dd_origin_obj
, FTAG
, &pclone
);
911 rw_exit(&dd
->dd_pool
->dp_config_rwlock
);
913 dmu_objset_rele(clone
, FTAG
);
917 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
918 ZFS_DELEG_PERM_MOUNT
, cr
);
920 dsl_dataset_name(pclone
, parentname
);
921 dmu_objset_rele(clone
, FTAG
);
922 dsl_dataset_rele(pclone
, FTAG
);
924 error
= zfs_secpolicy_write_perms(parentname
,
925 ZFS_DELEG_PERM_PROMOTE
, cr
);
932 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
936 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
937 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
940 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
941 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
944 return (zfs_secpolicy_write_perms(zc
->zc_name
,
945 ZFS_DELEG_PERM_CREATE
, cr
));
949 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
951 return (zfs_secpolicy_write_perms(name
,
952 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
956 * Check for permission to create each snapshot in the nvlist.
960 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
966 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
968 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
969 pair
= nvlist_next_nvpair(snaps
, pair
)) {
970 char *name
= nvpair_name(pair
);
971 char *atp
= strchr(name
, '@');
978 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
988 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
991 * Even root must have a proper TSD so that we know what pool
994 if (tsd_get(zfs_allow_log_key
) == NULL
)
1000 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1002 char parentname
[MAXNAMELEN
];
1006 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1007 sizeof (parentname
))) != 0)
1010 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1011 (error
= zfs_secpolicy_write_perms(origin
,
1012 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1015 if ((error
= zfs_secpolicy_write_perms(parentname
,
1016 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1019 return (zfs_secpolicy_write_perms(parentname
,
1020 ZFS_DELEG_PERM_MOUNT
, cr
));
1024 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1025 * SYS_CONFIG privilege, which is not available in a local zone.
1029 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1031 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1038 * Policy for object to name lookups.
1042 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1046 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1049 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1054 * Policy for fault injection. Requires all privileges.
1058 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1060 return (secpolicy_zinject(cr
));
1065 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1067 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1069 if (prop
== ZPROP_INVAL
) {
1070 if (!zfs_prop_user(zc
->zc_value
))
1072 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1073 ZFS_DELEG_PERM_USERPROP
, cr
));
1075 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1081 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1083 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1087 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1090 if (zc
->zc_value
[0] == 0) {
1092 * They are asking about a posix uid/gid. If it's
1093 * themself, allow it.
1095 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1096 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
1097 if (zc
->zc_guid
== crgetuid(cr
))
1100 if (groupmember(zc
->zc_guid
, cr
))
1105 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1106 userquota_perms
[zc
->zc_objset_type
], cr
));
1110 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1112 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1116 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1119 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1120 userquota_perms
[zc
->zc_objset_type
], cr
));
1125 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1127 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1133 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1135 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1136 ZFS_DELEG_PERM_HOLD
, cr
));
1141 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1143 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1144 ZFS_DELEG_PERM_RELEASE
, cr
));
1148 * Policy for allowing temporary snapshots to be taken or released
1151 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1154 * A temporary snapshot is the same as a snapshot,
1155 * hold, destroy and release all rolled into one.
1156 * Delegated diff alone is sufficient that we allow this.
1160 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1161 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1164 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1166 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1168 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1170 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1175 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1178 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1182 nvlist_t
*list
= NULL
;
1185 * Read in and unpack the user-supplied nvlist.
1190 packed
= kmem_alloc(size
, KM_SLEEP
| KM_NODEBUG
);
1192 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1194 kmem_free(packed
, size
);
1198 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1199 kmem_free(packed
, size
);
1203 kmem_free(packed
, size
);
1210 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1211 * Entries will be removed from the end of the nvlist, and one int32 entry
1212 * named "N_MORE_ERRORS" will be added indicating how many entries were
1216 nvlist_smush(nvlist_t
*errors
, size_t max
)
1220 size
= fnvlist_size(errors
);
1223 nvpair_t
*more_errors
;
1229 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1230 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1233 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1235 fnvlist_remove_nvpair(errors
, pair
);
1237 size
= fnvlist_size(errors
);
1238 } while (size
> max
);
1240 fnvlist_remove_nvpair(errors
, more_errors
);
1241 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1242 ASSERT3U(fnvlist_size(errors
), <=, max
);
1249 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1251 char *packed
= NULL
;
1255 size
= fnvlist_size(nvl
);
1257 if (size
> zc
->zc_nvlist_dst_size
) {
1260 packed
= fnvlist_pack(nvl
, &size
);
1261 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1262 size
, zc
->zc_iflags
) != 0)
1264 fnvlist_pack_free(packed
, size
);
1267 zc
->zc_nvlist_dst_size
= size
;
1268 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1273 get_zfs_sb(const char *dsname
, zfs_sb_t
**zsbp
)
1278 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1281 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1282 dmu_objset_rele(os
, FTAG
);
1286 mutex_enter(&os
->os_user_ptr_lock
);
1287 *zsbp
= dmu_objset_get_user(os
);
1288 if (*zsbp
&& (*zsbp
)->z_sb
) {
1289 atomic_inc(&((*zsbp
)->z_sb
->s_active
));
1293 mutex_exit(&os
->os_user_ptr_lock
);
1294 dmu_objset_rele(os
, FTAG
);
1299 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1300 * case its z_sb will be NULL, and it will be opened as the owner.
1301 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1302 * which prevents all inode ops from running.
1305 zfs_sb_hold(const char *name
, void *tag
, zfs_sb_t
**zsbp
, boolean_t writer
)
1309 if (get_zfs_sb(name
, zsbp
) != 0)
1310 error
= zfs_sb_create(name
, zsbp
);
1312 rrw_enter(&(*zsbp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1314 if ((*zsbp
)->z_unmounted
) {
1316 * XXX we could probably try again, since the unmounting
1317 * thread should be just about to disassociate the
1318 * objset from the zfsvfs.
1320 rrw_exit(&(*zsbp
)->z_teardown_lock
, tag
);
1328 zfs_sb_rele(zfs_sb_t
*zsb
, void *tag
)
1330 rrw_exit(&zsb
->z_teardown_lock
, tag
);
1333 deactivate_super(zsb
->z_sb
);
1335 dmu_objset_disown(zsb
->z_os
, zsb
);
1341 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1344 nvlist_t
*config
, *props
= NULL
;
1345 nvlist_t
*rootprops
= NULL
;
1346 nvlist_t
*zplprops
= NULL
;
1348 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1349 zc
->zc_iflags
, &config
)))
1352 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1353 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1354 zc
->zc_iflags
, &props
))) {
1355 nvlist_free(config
);
1360 nvlist_t
*nvl
= NULL
;
1361 uint64_t version
= SPA_VERSION
;
1363 (void) nvlist_lookup_uint64(props
,
1364 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1365 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1367 goto pool_props_bad
;
1369 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1371 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1373 nvlist_free(config
);
1377 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1379 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1380 error
= zfs_fill_zplprops_root(version
, rootprops
,
1383 goto pool_props_bad
;
1386 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1389 * Set the remaining root properties
1391 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1392 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1393 (void) spa_destroy(zc
->zc_name
);
1396 nvlist_free(rootprops
);
1397 nvlist_free(zplprops
);
1398 nvlist_free(config
);
1405 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1408 zfs_log_history(zc
);
1409 error
= spa_destroy(zc
->zc_name
);
1411 zvol_remove_minors(zc
->zc_name
);
1416 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1418 nvlist_t
*config
, *props
= NULL
;
1422 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1423 zc
->zc_iflags
, &config
)) != 0)
1426 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1427 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1428 zc
->zc_iflags
, &props
))) {
1429 nvlist_free(config
);
1433 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1434 guid
!= zc
->zc_guid
)
1437 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1439 if (zc
->zc_nvlist_dst
!= 0) {
1442 if ((err
= put_nvlist(zc
, config
)) != 0)
1446 nvlist_free(config
);
1455 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1458 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1459 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1461 zfs_log_history(zc
);
1462 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1464 zvol_remove_minors(zc
->zc_name
);
1469 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1474 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1477 error
= put_nvlist(zc
, configs
);
1479 nvlist_free(configs
);
1486 * zc_name name of the pool
1489 * zc_cookie real errno
1490 * zc_nvlist_dst config nvlist
1491 * zc_nvlist_dst_size size of config nvlist
1494 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1500 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1501 sizeof (zc
->zc_value
));
1503 if (config
!= NULL
) {
1504 ret
= put_nvlist(zc
, config
);
1505 nvlist_free(config
);
1508 * The config may be present even if 'error' is non-zero.
1509 * In this case we return success, and preserve the real errno
1512 zc
->zc_cookie
= error
;
1521 * Try to import the given pool, returning pool stats as appropriate so that
1522 * user land knows which devices are available and overall pool health.
1525 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1527 nvlist_t
*tryconfig
, *config
;
1530 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1531 zc
->zc_iflags
, &tryconfig
)) != 0)
1534 config
= spa_tryimport(tryconfig
);
1536 nvlist_free(tryconfig
);
1541 error
= put_nvlist(zc
, config
);
1542 nvlist_free(config
);
1549 * zc_name name of the pool
1550 * zc_cookie scan func (pool_scan_func_t)
1553 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1558 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1561 if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1562 error
= spa_scan_stop(spa
);
1564 error
= spa_scan(spa
, zc
->zc_cookie
);
1566 spa_close(spa
, FTAG
);
1572 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1577 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1580 spa_close(spa
, FTAG
);
1586 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1591 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1594 if (zc
->zc_cookie
< spa_version(spa
) ||
1595 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1596 spa_close(spa
, FTAG
);
1600 spa_upgrade(spa
, zc
->zc_cookie
);
1601 spa_close(spa
, FTAG
);
1607 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1614 if ((size
= zc
->zc_history_len
) == 0)
1617 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1620 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1621 spa_close(spa
, FTAG
);
1625 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1626 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1627 &zc
->zc_history_len
, hist_buf
)) == 0) {
1628 error
= ddi_copyout(hist_buf
,
1629 (void *)(uintptr_t)zc
->zc_history
,
1630 zc
->zc_history_len
, zc
->zc_iflags
);
1633 spa_close(spa
, FTAG
);
1634 vmem_free(hist_buf
, size
);
1639 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1644 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1646 error
= spa_change_guid(spa
);
1647 spa_close(spa
, FTAG
);
1653 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1657 if ((error
= dsl_dsobj_to_dsname(zc
->zc_name
,zc
->zc_obj
,zc
->zc_value
)))
1665 * zc_name name of filesystem
1666 * zc_obj object to find
1669 * zc_value name of object
1672 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1677 /* XXX reading from objset not owned */
1678 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1680 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1681 dmu_objset_rele(os
, FTAG
);
1684 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1685 sizeof (zc
->zc_value
));
1686 dmu_objset_rele(os
, FTAG
);
1693 * zc_name name of filesystem
1694 * zc_obj object to find
1697 * zc_stat stats on object
1698 * zc_value path to object
1701 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1706 /* XXX reading from objset not owned */
1707 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1709 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1710 dmu_objset_rele(os
, FTAG
);
1713 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1714 sizeof (zc
->zc_value
));
1715 dmu_objset_rele(os
, FTAG
);
1721 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1725 nvlist_t
*config
, **l2cache
, **spares
;
1726 uint_t nl2cache
= 0, nspares
= 0;
1728 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1732 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1733 zc
->zc_iflags
, &config
);
1734 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_L2CACHE
,
1735 &l2cache
, &nl2cache
);
1737 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_SPARES
,
1741 * A root pool with concatenated devices is not supported.
1742 * Thus, can not add a device to a root pool.
1744 * Intent log device can not be added to a rootpool because
1745 * during mountroot, zil is replayed, a seperated log device
1746 * can not be accessed during the mountroot time.
1748 * l2cache and spare devices are ok to be added to a rootpool.
1750 if (spa_bootfs(spa
) != 0 && nl2cache
== 0 && nspares
== 0) {
1751 nvlist_free(config
);
1752 spa_close(spa
, FTAG
);
1757 error
= spa_vdev_add(spa
, config
);
1758 nvlist_free(config
);
1760 spa_close(spa
, FTAG
);
1766 * zc_name name of the pool
1767 * zc_nvlist_conf nvlist of devices to remove
1768 * zc_cookie to stop the remove?
1771 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1776 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1779 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1780 spa_close(spa
, FTAG
);
1785 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1789 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1791 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1793 switch (zc
->zc_cookie
) {
1794 case VDEV_STATE_ONLINE
:
1795 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1798 case VDEV_STATE_OFFLINE
:
1799 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1802 case VDEV_STATE_FAULTED
:
1803 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1804 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1805 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1807 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1810 case VDEV_STATE_DEGRADED
:
1811 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1812 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1813 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1815 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1821 zc
->zc_cookie
= newstate
;
1822 spa_close(spa
, FTAG
);
1827 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1830 int replacing
= zc
->zc_cookie
;
1834 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1837 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1838 zc
->zc_iflags
, &config
)) == 0) {
1839 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1840 nvlist_free(config
);
1843 spa_close(spa
, FTAG
);
1848 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1853 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1856 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1858 spa_close(spa
, FTAG
);
1863 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1866 nvlist_t
*config
, *props
= NULL
;
1868 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1870 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1873 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1874 zc
->zc_iflags
, &config
))) {
1875 spa_close(spa
, FTAG
);
1879 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1880 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1881 zc
->zc_iflags
, &props
))) {
1882 spa_close(spa
, FTAG
);
1883 nvlist_free(config
);
1887 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1889 spa_close(spa
, FTAG
);
1891 nvlist_free(config
);
1898 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1901 char *path
= zc
->zc_value
;
1902 uint64_t guid
= zc
->zc_guid
;
1905 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1909 error
= spa_vdev_setpath(spa
, guid
, path
);
1910 spa_close(spa
, FTAG
);
1915 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1918 char *fru
= zc
->zc_value
;
1919 uint64_t guid
= zc
->zc_guid
;
1922 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1926 error
= spa_vdev_setfru(spa
, guid
, fru
);
1927 spa_close(spa
, FTAG
);
1932 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
1937 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1939 if (zc
->zc_nvlist_dst
!= 0 &&
1940 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
1941 dmu_objset_stats(os
, nv
);
1943 * NB: zvol_get_stats() will read the objset contents,
1944 * which we aren't supposed to do with a
1945 * DS_MODE_USER hold, because it could be
1946 * inconsistent. So this is a bit of a workaround...
1947 * XXX reading with out owning
1949 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
1950 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
1951 error
= zvol_get_stats(os
, nv
);
1957 error
= put_nvlist(zc
, nv
);
1966 * zc_name name of filesystem
1967 * zc_nvlist_dst_size size of buffer for property nvlist
1970 * zc_objset_stats stats
1971 * zc_nvlist_dst property nvlist
1972 * zc_nvlist_dst_size size of property nvlist
1975 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
1977 objset_t
*os
= NULL
;
1980 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
1983 error
= zfs_ioc_objset_stats_impl(zc
, os
);
1985 dmu_objset_rele(os
, FTAG
);
1992 * zc_name name of filesystem
1993 * zc_nvlist_dst_size size of buffer for property nvlist
1996 * zc_nvlist_dst received property nvlist
1997 * zc_nvlist_dst_size size of received property nvlist
1999 * Gets received properties (distinct from local properties on or after
2000 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2001 * local property values.
2004 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2006 objset_t
*os
= NULL
;
2010 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2014 * Without this check, we would return local property values if the
2015 * caller has not already received properties on or after
2016 * SPA_VERSION_RECVD_PROPS.
2018 if (!dsl_prop_get_hasrecvd(os
)) {
2019 dmu_objset_rele(os
, FTAG
);
2023 if (zc
->zc_nvlist_dst
!= 0 &&
2024 (error
= dsl_prop_get_received(os
, &nv
)) == 0) {
2025 error
= put_nvlist(zc
, nv
);
2029 dmu_objset_rele(os
, FTAG
);
2034 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2040 * zfs_get_zplprop() will either find a value or give us
2041 * the default value (if there is one).
2043 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2045 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2051 * zc_name name of filesystem
2052 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2055 * zc_nvlist_dst zpl property nvlist
2056 * zc_nvlist_dst_size size of zpl property nvlist
2059 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2064 /* XXX reading without owning */
2065 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2068 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2071 * NB: nvl_add_zplprop() will read the objset contents,
2072 * which we aren't supposed to do with a DS_MODE_USER
2073 * hold, because it could be inconsistent.
2075 if (zc
->zc_nvlist_dst
!= 0 &&
2076 !zc
->zc_objset_stats
.dds_inconsistent
&&
2077 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2080 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2081 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2082 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2083 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2084 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2085 err
= put_nvlist(zc
, nv
);
2090 dmu_objset_rele(os
, FTAG
);
2095 dataset_name_hidden(const char *name
)
2098 * Skip over datasets that are not visible in this zone,
2099 * internal datasets (which have a $ in their name), and
2100 * temporary datasets (which have a % in their name).
2102 if (strchr(name
, '$') != NULL
)
2104 if (strchr(name
, '%') != NULL
)
2106 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2113 * zc_name name of filesystem
2114 * zc_cookie zap cursor
2115 * zc_nvlist_dst_size size of buffer for property nvlist
2118 * zc_name name of next filesystem
2119 * zc_cookie zap cursor
2120 * zc_objset_stats stats
2121 * zc_nvlist_dst property nvlist
2122 * zc_nvlist_dst_size size of property nvlist
2125 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2130 size_t orig_len
= strlen(zc
->zc_name
);
2133 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2134 if (error
== ENOENT
)
2139 p
= strrchr(zc
->zc_name
, '/');
2140 if (p
== NULL
|| p
[1] != '\0')
2141 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2142 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2145 * Pre-fetch the datasets. dmu_objset_prefetch() always returns 0
2146 * but is not declared void because its called by dmu_objset_find().
2148 if (zc
->zc_cookie
== 0) {
2149 uint64_t cookie
= 0;
2150 int len
= sizeof (zc
->zc_name
) - (p
- zc
->zc_name
);
2152 while (dmu_dir_list_next(os
, len
, p
, NULL
, &cookie
) == 0) {
2153 if (!dataset_name_hidden(zc
->zc_name
))
2154 (void) dmu_objset_prefetch(zc
->zc_name
, NULL
);
2159 error
= dmu_dir_list_next(os
,
2160 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2161 NULL
, &zc
->zc_cookie
);
2162 if (error
== ENOENT
)
2164 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2165 dmu_objset_rele(os
, FTAG
);
2168 * If it's an internal dataset (ie. with a '$' in its name),
2169 * don't try to get stats for it, otherwise we'll return ENOENT.
2171 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2172 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2173 if (error
== ENOENT
) {
2174 /* We lost a race with destroy, get the next one. */
2175 zc
->zc_name
[orig_len
] = '\0';
2184 * zc_name name of filesystem
2185 * zc_cookie zap cursor
2186 * zc_nvlist_dst_size size of buffer for property nvlist
2189 * zc_name name of next snapshot
2190 * zc_objset_stats stats
2191 * zc_nvlist_dst property nvlist
2192 * zc_nvlist_dst_size size of property nvlist
2195 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2201 if (zc
->zc_cookie
== 0 && !zc
->zc_simple
)
2202 (void) dmu_objset_find(zc
->zc_name
, dmu_objset_prefetch
,
2203 NULL
, DS_FIND_SNAPSHOTS
);
2205 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2207 return (error
== ENOENT
? ESRCH
: error
);
2210 * A dataset name of maximum length cannot have any snapshots,
2211 * so exit immediately.
2213 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >= MAXNAMELEN
) {
2214 dmu_objset_rele(os
, FTAG
);
2218 error
= dmu_snapshot_list_next(os
,
2219 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2220 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2223 if (error
== 0 && !zc
->zc_simple
) {
2225 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2228 * Since we probably don't have a hold on this snapshot,
2229 * it's possible that the objsetid could have been destroyed
2230 * and reused for a new objset. It's OK if this happens during
2231 * a zfs send operation, since the new createtxg will be
2232 * beyond the range we're interested in.
2234 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
2235 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2236 rw_exit(&dp
->dp_config_rwlock
);
2238 if (error
== ENOENT
) {
2239 /* Racing with destroy, get the next one. */
2240 *strchr(zc
->zc_name
, '@') = '\0';
2241 dmu_objset_rele(os
, FTAG
);
2247 error
= dmu_objset_from_ds(ds
, &ossnap
);
2249 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2250 dsl_dataset_rele(ds
, FTAG
);
2252 } else if (error
== ENOENT
) {
2256 dmu_objset_rele(os
, FTAG
);
2257 /* if we failed, undo the @ that we tacked on to zc_name */
2259 *strchr(zc
->zc_name
, '@') = '\0';
2264 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2266 const char *propname
= nvpair_name(pair
);
2268 unsigned int vallen
;
2271 zfs_userquota_prop_t type
;
2277 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2279 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2280 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2286 * A correctly constructed propname is encoded as
2287 * userquota@<rid>-<domain>.
2289 if ((dash
= strchr(propname
, '-')) == NULL
||
2290 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2299 err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
2301 err
= zfs_set_userquota(zsb
, type
, domain
, rid
, quota
);
2302 zfs_sb_rele(zsb
, FTAG
);
2309 * If the named property is one that has a special function to set its value,
2310 * return 0 on success and a positive error code on failure; otherwise if it is
2311 * not one of the special properties handled by this function, return -1.
2313 * XXX: It would be better for callers of the property interface if we handled
2314 * these special cases in dsl_prop.c (in the dsl layer).
2317 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2320 const char *propname
= nvpair_name(pair
);
2321 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2325 if (prop
== ZPROP_INVAL
) {
2326 if (zfs_prop_userquota(propname
))
2327 return (zfs_prop_set_userquota(dsname
, pair
));
2331 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2333 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2334 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2338 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2341 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2344 case ZFS_PROP_QUOTA
:
2345 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2347 case ZFS_PROP_REFQUOTA
:
2348 err
= dsl_dataset_set_quota(dsname
, source
, intval
);
2350 case ZFS_PROP_RESERVATION
:
2351 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2353 case ZFS_PROP_REFRESERVATION
:
2354 err
= dsl_dataset_set_reservation(dsname
, source
, intval
);
2356 case ZFS_PROP_VOLSIZE
:
2357 err
= zvol_set_volsize(dsname
, intval
);
2359 case ZFS_PROP_SNAPDEV
:
2360 err
= zvol_set_snapdev(dsname
, intval
);
2362 case ZFS_PROP_VERSION
:
2366 if ((err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_TRUE
)) != 0)
2369 err
= zfs_set_version(zsb
, intval
);
2370 zfs_sb_rele(zsb
, FTAG
);
2372 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2375 zc
= kmem_zalloc(sizeof (zfs_cmd_t
),
2376 KM_SLEEP
| KM_NODEBUG
);
2377 (void) strcpy(zc
->zc_name
, dsname
);
2378 (void) zfs_ioc_userspace_upgrade(zc
);
2379 kmem_free(zc
, sizeof (zfs_cmd_t
));
2383 case ZFS_PROP_COMPRESSION
:
2385 if (intval
== ZIO_COMPRESS_LZ4
) {
2386 zfeature_info_t
*feature
=
2387 &spa_feature_table
[SPA_FEATURE_LZ4_COMPRESS
];
2391 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
2394 dp
= spa
->spa_dsl_pool
;
2397 * Setting the LZ4 compression algorithm activates
2400 if (!spa_feature_is_active(spa
, feature
)) {
2401 if ((err
= zfs_prop_activate_feature(dp
,
2403 spa_close(spa
, FTAG
);
2408 spa_close(spa
, FTAG
);
2411 * We still want the default set action to be performed in the
2412 * caller, we only performed zfeature settings here.
2426 * This function is best effort. If it fails to set any of the given properties,
2427 * it continues to set as many as it can and returns the last error
2428 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2429 * with the list of names of all the properties that failed along with the
2430 * corresponding error numbers.
2432 * If every property is set successfully, zero is returned and errlist is not
2436 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2445 nvlist_t
*genericnvl
= fnvlist_alloc();
2446 nvlist_t
*retrynvl
= fnvlist_alloc();
2449 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2450 const char *propname
= nvpair_name(pair
);
2451 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2454 /* decode the property value */
2456 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2458 attrs
= fnvpair_value_nvlist(pair
);
2459 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2464 /* Validate value type */
2465 if (err
== 0 && prop
== ZPROP_INVAL
) {
2466 if (zfs_prop_user(propname
)) {
2467 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2469 } else if (zfs_prop_userquota(propname
)) {
2470 if (nvpair_type(propval
) !=
2471 DATA_TYPE_UINT64_ARRAY
)
2476 } else if (err
== 0) {
2477 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2478 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2480 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2483 intval
= fnvpair_value_uint64(propval
);
2485 switch (zfs_prop_get_type(prop
)) {
2486 case PROP_TYPE_NUMBER
:
2488 case PROP_TYPE_STRING
:
2491 case PROP_TYPE_INDEX
:
2492 if (zfs_prop_index_to_string(prop
,
2493 intval
, &unused
) != 0)
2498 "unknown property type");
2505 /* Validate permissions */
2507 err
= zfs_check_settable(dsname
, pair
, CRED());
2510 err
= zfs_prop_set_special(dsname
, source
, pair
);
2513 * For better performance we build up a list of
2514 * properties to set in a single transaction.
2516 err
= nvlist_add_nvpair(genericnvl
, pair
);
2517 } else if (err
!= 0 && nvl
!= retrynvl
) {
2519 * This may be a spurious error caused by
2520 * receiving quota and reservation out of order.
2521 * Try again in a second pass.
2523 err
= nvlist_add_nvpair(retrynvl
, pair
);
2528 if (errlist
!= NULL
)
2529 fnvlist_add_int32(errlist
, propname
, err
);
2534 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2539 if (!nvlist_empty(genericnvl
) &&
2540 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2542 * If this fails, we still want to set as many properties as we
2543 * can, so try setting them individually.
2546 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2547 const char *propname
= nvpair_name(pair
);
2551 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2553 attrs
= fnvpair_value_nvlist(pair
);
2554 propval
= fnvlist_lookup_nvpair(attrs
,
2558 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2559 strval
= fnvpair_value_string(propval
);
2560 err
= dsl_prop_set(dsname
, propname
, source
, 1,
2561 strlen(strval
) + 1, strval
);
2563 intval
= fnvpair_value_uint64(propval
);
2564 err
= dsl_prop_set(dsname
, propname
, source
, 8,
2569 if (errlist
!= NULL
) {
2570 fnvlist_add_int32(errlist
, propname
,
2577 nvlist_free(genericnvl
);
2578 nvlist_free(retrynvl
);
2584 * Check that all the properties are valid user properties.
2587 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2589 nvpair_t
*pair
= NULL
;
2592 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2593 const char *propname
= nvpair_name(pair
);
2596 if (!zfs_prop_user(propname
) ||
2597 nvpair_type(pair
) != DATA_TYPE_STRING
)
2600 if ((error
= zfs_secpolicy_write_perms(fsname
,
2601 ZFS_DELEG_PERM_USERPROP
, CRED())))
2604 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2605 return (ENAMETOOLONG
);
2607 VERIFY(nvpair_value_string(pair
, &valstr
) == 0);
2608 if (strlen(valstr
) >= ZAP_MAXVALUELEN
)
2615 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2619 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2622 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2623 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2626 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2631 clear_received_props(objset_t
*os
, const char *fs
, nvlist_t
*props
,
2635 nvlist_t
*cleared_props
= NULL
;
2636 props_skip(props
, skipped
, &cleared_props
);
2637 if (!nvlist_empty(cleared_props
)) {
2639 * Acts on local properties until the dataset has received
2640 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2642 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2643 (dsl_prop_get_hasrecvd(os
) ? ZPROP_SRC_RECEIVED
: 0));
2644 err
= zfs_set_prop_nvlist(fs
, flags
, cleared_props
, NULL
);
2646 nvlist_free(cleared_props
);
2652 * zc_name name of filesystem
2653 * zc_value name of property to set
2654 * zc_nvlist_src{_size} nvlist of properties to apply
2655 * zc_cookie received properties flag
2658 * zc_nvlist_dst{_size} error for each unapplied received property
2661 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2664 boolean_t received
= zc
->zc_cookie
;
2665 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2670 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2671 zc
->zc_iflags
, &nvl
)) != 0)
2675 nvlist_t
*origprops
;
2678 if (dmu_objset_hold(zc
->zc_name
, FTAG
, &os
) == 0) {
2679 if (dsl_prop_get_received(os
, &origprops
) == 0) {
2680 (void) clear_received_props(os
,
2681 zc
->zc_name
, origprops
, nvl
);
2682 nvlist_free(origprops
);
2685 dsl_prop_set_hasrecvd(os
);
2686 dmu_objset_rele(os
, FTAG
);
2690 errors
= fnvlist_alloc();
2691 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2693 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2694 (void) put_nvlist(zc
, errors
);
2697 nvlist_free(errors
);
2704 * zc_name name of filesystem
2705 * zc_value name of property to inherit
2706 * zc_cookie revert to received value if TRUE
2711 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2713 const char *propname
= zc
->zc_value
;
2714 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2715 boolean_t received
= zc
->zc_cookie
;
2716 zprop_source_t source
= (received
2717 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2718 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2727 * zfs_prop_set_special() expects properties in the form of an
2728 * nvpair with type info.
2730 if (prop
== ZPROP_INVAL
) {
2731 if (!zfs_prop_user(propname
))
2734 type
= PROP_TYPE_STRING
;
2735 } else if (prop
== ZFS_PROP_VOLSIZE
||
2736 prop
== ZFS_PROP_VERSION
) {
2739 type
= zfs_prop_get_type(prop
);
2742 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2745 case PROP_TYPE_STRING
:
2746 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2748 case PROP_TYPE_NUMBER
:
2749 case PROP_TYPE_INDEX
:
2750 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2757 pair
= nvlist_next_nvpair(dummy
, NULL
);
2758 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2761 return (err
); /* special property already handled */
2764 * Only check this in the non-received case. We want to allow
2765 * 'inherit -S' to revert non-inheritable properties like quota
2766 * and reservation to the received or default values even though
2767 * they are not considered inheritable.
2769 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2773 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2774 return (dsl_prop_set(zc
->zc_name
, zc
->zc_value
, source
, 0, 0, NULL
));
2778 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2785 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2786 zc
->zc_iflags
, &props
)))
2790 * If the only property is the configfile, then just do a spa_lookup()
2791 * to handle the faulted case.
2793 pair
= nvlist_next_nvpair(props
, NULL
);
2794 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2795 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2796 nvlist_next_nvpair(props
, pair
) == NULL
) {
2797 mutex_enter(&spa_namespace_lock
);
2798 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2799 spa_configfile_set(spa
, props
, B_FALSE
);
2800 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2802 mutex_exit(&spa_namespace_lock
);
2809 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2814 error
= spa_prop_set(spa
, props
);
2817 spa_close(spa
, FTAG
);
2823 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2827 nvlist_t
*nvp
= NULL
;
2829 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2831 * If the pool is faulted, there may be properties we can still
2832 * get (such as altroot and cachefile), so attempt to get them
2835 mutex_enter(&spa_namespace_lock
);
2836 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2837 error
= spa_prop_get(spa
, &nvp
);
2838 mutex_exit(&spa_namespace_lock
);
2840 error
= spa_prop_get(spa
, &nvp
);
2841 spa_close(spa
, FTAG
);
2844 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2845 error
= put_nvlist(zc
, nvp
);
2855 * zc_name name of volume
2860 zfs_ioc_create_minor(zfs_cmd_t
*zc
)
2862 return (zvol_create_minor(zc
->zc_name
));
2867 * zc_name name of volume
2872 zfs_ioc_remove_minor(zfs_cmd_t
*zc
)
2874 return (zvol_remove_minor(zc
->zc_name
));
2879 * zc_name name of filesystem
2880 * zc_nvlist_src{_size} nvlist of delegated permissions
2881 * zc_perm_action allow/unallow flag
2886 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2889 nvlist_t
*fsaclnv
= NULL
;
2891 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2892 zc
->zc_iflags
, &fsaclnv
)) != 0)
2896 * Verify nvlist is constructed correctly
2898 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2899 nvlist_free(fsaclnv
);
2904 * If we don't have PRIV_SYS_MOUNT, then validate
2905 * that user is allowed to hand out each permission in
2909 error
= secpolicy_zfs(CRED());
2911 if (zc
->zc_perm_action
== B_FALSE
) {
2912 error
= dsl_deleg_can_allow(zc
->zc_name
,
2915 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2921 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2923 nvlist_free(fsaclnv
);
2929 * zc_name name of filesystem
2932 * zc_nvlist_src{_size} nvlist of delegated permissions
2935 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2940 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2941 error
= put_nvlist(zc
, nvp
);
2950 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2952 zfs_creat_t
*zct
= arg
;
2954 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2957 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2961 * createprops list of properties requested by creator
2962 * default_zplver zpl version to use if unspecified in createprops
2963 * fuids_ok fuids allowed in this version of the spa?
2964 * os parent objset pointer (NULL if root fs)
2967 * zplprops values for the zplprops we attach to the master node object
2968 * is_ci true if requested file system will be purely case-insensitive
2970 * Determine the settings for utf8only, normalization and
2971 * casesensitivity. Specific values may have been requested by the
2972 * creator and/or we can inherit values from the parent dataset. If
2973 * the file system is of too early a vintage, a creator can not
2974 * request settings for these properties, even if the requested
2975 * setting is the default value. We don't actually want to create dsl
2976 * properties for these, so remove them from the source nvlist after
2980 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2981 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2982 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2984 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2985 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2986 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2989 ASSERT(zplprops
!= NULL
);
2992 * Pull out creator prop choices, if any.
2995 (void) nvlist_lookup_uint64(createprops
,
2996 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2997 (void) nvlist_lookup_uint64(createprops
,
2998 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2999 (void) nvlist_remove_all(createprops
,
3000 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3001 (void) nvlist_lookup_uint64(createprops
,
3002 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3003 (void) nvlist_remove_all(createprops
,
3004 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3005 (void) nvlist_lookup_uint64(createprops
,
3006 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3007 (void) nvlist_remove_all(createprops
,
3008 zfs_prop_to_name(ZFS_PROP_CASE
));
3012 * If the zpl version requested is whacky or the file system
3013 * or pool is version is too "young" to support normalization
3014 * and the creator tried to set a value for one of the props,
3017 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3018 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3019 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3020 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3021 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3022 sense
!= ZFS_PROP_UNDEFINED
)))
3026 * Put the version in the zplprops
3028 VERIFY(nvlist_add_uint64(zplprops
,
3029 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3031 if (norm
== ZFS_PROP_UNDEFINED
&&
3032 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3034 VERIFY(nvlist_add_uint64(zplprops
,
3035 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3038 * If we're normalizing, names must always be valid UTF-8 strings.
3042 if (u8
== ZFS_PROP_UNDEFINED
&&
3043 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3045 VERIFY(nvlist_add_uint64(zplprops
,
3046 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3048 if (sense
== ZFS_PROP_UNDEFINED
&&
3049 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3051 VERIFY(nvlist_add_uint64(zplprops
,
3052 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3055 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3061 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3062 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3064 boolean_t fuids_ok
, sa_ok
;
3065 uint64_t zplver
= ZPL_VERSION
;
3066 objset_t
*os
= NULL
;
3067 char parentname
[MAXNAMELEN
];
3073 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3074 cp
= strrchr(parentname
, '/');
3078 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3081 spa_vers
= spa_version(spa
);
3082 spa_close(spa
, FTAG
);
3084 zplver
= zfs_zpl_version_map(spa_vers
);
3085 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3086 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3089 * Open parent object set so we can inherit zplprop values.
3091 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3094 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3096 dmu_objset_rele(os
, FTAG
);
3101 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3102 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3106 uint64_t zplver
= ZPL_VERSION
;
3109 zplver
= zfs_zpl_version_map(spa_vers
);
3110 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3111 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3113 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3114 createprops
, zplprops
, is_ci
);
3120 * "type" -> dmu_objset_type_t (int32)
3121 * (optional) "props" -> { prop -> value }
3124 * outnvl: propname -> error code (int32)
3127 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3130 zfs_creat_t zct
= { 0 };
3131 nvlist_t
*nvprops
= NULL
;
3132 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3134 dmu_objset_type_t type
;
3135 boolean_t is_insensitive
= B_FALSE
;
3137 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3140 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3144 cbfunc
= zfs_create_cb
;
3148 cbfunc
= zvol_create_cb
;
3155 if (strchr(fsname
, '@') ||
3156 strchr(fsname
, '%'))
3159 zct
.zct_props
= nvprops
;
3164 if (type
== DMU_OST_ZVOL
) {
3165 uint64_t volsize
, volblocksize
;
3167 if (nvprops
== NULL
)
3169 if (nvlist_lookup_uint64(nvprops
,
3170 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3173 if ((error
= nvlist_lookup_uint64(nvprops
,
3174 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3175 &volblocksize
)) != 0 && error
!= ENOENT
)
3179 volblocksize
= zfs_prop_default_numeric(
3180 ZFS_PROP_VOLBLOCKSIZE
);
3182 if ((error
= zvol_check_volblocksize(
3183 volblocksize
)) != 0 ||
3184 (error
= zvol_check_volsize(volsize
,
3185 volblocksize
)) != 0)
3187 } else if (type
== DMU_OST_ZFS
) {
3191 * We have to have normalization and
3192 * case-folding flags correct when we do the
3193 * file system creation, so go figure them out
3196 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3197 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3198 error
= zfs_fill_zplprops(fsname
, nvprops
,
3199 zct
.zct_zplprops
, &is_insensitive
);
3201 nvlist_free(zct
.zct_zplprops
);
3206 error
= dmu_objset_create(fsname
, type
,
3207 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3208 nvlist_free(zct
.zct_zplprops
);
3211 * It would be nice to do this atomically.
3214 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3217 (void) dmu_objset_destroy(fsname
, B_FALSE
);
3224 * "origin" -> name of origin snapshot
3225 * (optional) "props" -> { prop -> value }
3229 * outnvl: propname -> error code (int32)
3232 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3235 nvlist_t
*nvprops
= NULL
;
3237 dsl_dataset_t
*origin
;
3239 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3241 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3243 if (strchr(fsname
, '@') ||
3244 strchr(fsname
, '%'))
3247 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3250 error
= dsl_dataset_hold(origin_name
, FTAG
, &origin
);
3254 error
= dmu_objset_clone(fsname
, origin
, 0);
3255 dsl_dataset_rele(origin
, FTAG
);
3260 * It would be nice to do this atomically.
3263 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3266 (void) dmu_objset_destroy(fsname
, B_FALSE
);
3273 * "snaps" -> { snapshot1, snapshot2 }
3274 * (optional) "props" -> { prop -> value (string) }
3277 * outnvl: snapshot -> error code (int32)
3281 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3284 nvlist_t
*props
= NULL
;
3286 nvpair_t
*pair
, *pair2
;
3288 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3289 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3292 if (!nvlist_empty(props
) &&
3293 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3296 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3298 poollen
= strlen(poolname
);
3299 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3300 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3301 const char *name
= nvpair_name(pair
);
3302 const char *cp
= strchr(name
, '@');
3305 * The snap name must contain an @, and the part after it must
3306 * contain only valid characters.
3308 if (cp
== NULL
|| snapshot_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3312 * The snap must be in the specified pool.
3314 if (strncmp(name
, poolname
, poollen
) != 0 ||
3315 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3318 /* This must be the only snap of this fs. */
3319 for (pair2
= nvlist_next_nvpair(snaps
, pair
);
3320 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3321 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3328 error
= dmu_objset_snapshot(snaps
, props
, outnvl
);
3333 * innvl: "message" -> string
3337 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3345 * The poolname in the ioctl is not set, we get it from the TSD,
3346 * which was set at the end of the last successful ioctl that allows
3347 * logging. The secpolicy func already checked that it is set.
3348 * Only one log ioctl is allowed after each successful ioctl, so
3349 * we clear the TSD here.
3351 poolname
= tsd_get(zfs_allow_log_key
);
3352 (void) tsd_set(zfs_allow_log_key
, NULL
);
3353 error
= spa_open(poolname
, &spa
, FTAG
);
3358 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3359 spa_close(spa
, FTAG
);
3363 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3364 spa_close(spa
, FTAG
);
3368 error
= spa_history_log(spa
, message
);
3369 spa_close(spa
, FTAG
);
3375 * name dataset name, or when 'arg == NULL' the full snapshot name
3376 * arg short snapshot name (i.e. part after the '@')
3380 zfs_unmount_snap(const char *name
, void *arg
)
3382 zfs_sb_t
*zsb
= NULL
;
3389 if ((ptr
= strchr(name
, '@')) == NULL
)
3392 dsname
= strdup(name
);
3393 dsname
[ptr
- name
] = '\0';
3394 snapname
= strdup(ptr
+ 1);
3395 fullname
= kmem_asprintf("%s@%s", dsname
, snapname
);
3396 error
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
3398 error
= zfsctl_unmount_snapshot(zsb
, fullname
, MNT_FORCE
);
3399 zfs_sb_rele(zsb
, FTAG
);
3401 /* Allow ENOENT for consistency with upstream */
3402 if (error
== ENOENT
)
3415 * "snaps" -> { snapshot1, snapshot2 }
3416 * (optional boolean) "defer"
3419 * outnvl: snapshot -> error code (int32)
3422 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3429 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3431 defer
= nvlist_exists(innvl
, "defer");
3433 poollen
= strlen(poolname
);
3434 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3435 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3436 const char *name
= nvpair_name(pair
);
3439 * The snap must be in the specified pool.
3441 if (strncmp(name
, poolname
, poollen
) != 0 ||
3442 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3446 * Ignore failures to unmount; dmu_snapshots_destroy_nvl()
3447 * will deal with this gracefully (by filling in outnvl).
3449 (void) zfs_unmount_snap(name
, NULL
);
3450 (void) zvol_remove_minor(name
);
3453 return (dmu_snapshots_destroy_nvl(snaps
, defer
, outnvl
));
3458 * zc_name name of dataset to destroy
3459 * zc_objset_type type of objset
3460 * zc_defer_destroy mark for deferred destroy
3465 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3468 if (strchr(zc
->zc_name
, '@') && zc
->zc_objset_type
== DMU_OST_ZFS
) {
3469 err
= zfs_unmount_snap(zc
->zc_name
, NULL
);
3474 err
= dmu_objset_destroy(zc
->zc_name
, zc
->zc_defer_destroy
);
3475 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3476 (void) zvol_remove_minor(zc
->zc_name
);
3482 * zc_name name of dataset to rollback (to most recent snapshot)
3487 zfs_ioc_rollback(zfs_cmd_t
*zc
)
3489 dsl_dataset_t
*ds
, *clone
;
3494 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &ds
);
3498 /* must not be a snapshot */
3499 if (dsl_dataset_is_snapshot(ds
)) {
3500 dsl_dataset_rele(ds
, FTAG
);
3504 /* must have a most recent snapshot */
3505 if (ds
->ds_phys
->ds_prev_snap_txg
< TXG_INITIAL
) {
3506 dsl_dataset_rele(ds
, FTAG
);
3511 * Create clone of most recent snapshot.
3513 clone_name
= kmem_asprintf("%s/%%rollback", zc
->zc_name
);
3514 error
= dmu_objset_clone(clone_name
, ds
->ds_prev
, DS_FLAG_INCONSISTENT
);
3518 error
= dsl_dataset_own(clone_name
, B_TRUE
, FTAG
, &clone
);
3525 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
3526 error
= zfs_suspend_fs(zsb
);
3530 if (dsl_dataset_tryown(ds
, B_FALSE
, FTAG
)) {
3531 error
= dsl_dataset_clone_swap(clone
, ds
,
3533 dsl_dataset_disown(ds
, FTAG
);
3538 resume_err
= zfs_resume_fs(zsb
, zc
->zc_name
);
3539 error
= error
? error
: resume_err
;
3541 deactivate_super(zsb
->z_sb
);
3543 if (dsl_dataset_tryown(ds
, B_FALSE
, FTAG
)) {
3544 error
= dsl_dataset_clone_swap(clone
, ds
, B_TRUE
);
3545 dsl_dataset_disown(ds
, FTAG
);
3553 * Destroy clone (which also closes it).
3555 (void) dsl_dataset_destroy(clone
, FTAG
, B_FALSE
);
3558 strfree(clone_name
);
3560 dsl_dataset_rele(ds
, FTAG
);
3566 * zc_name old name of dataset
3567 * zc_value new name of dataset
3568 * zc_cookie recursive flag (only valid for snapshots)
3573 zfs_ioc_rename(zfs_cmd_t
*zc
)
3575 boolean_t recursive
= zc
->zc_cookie
& 1;
3578 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3579 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3580 strchr(zc
->zc_value
, '%'))
3584 * Unmount snapshot unless we're doing a recursive rename,
3585 * in which case the dataset code figures out which snapshots
3588 if (!recursive
&& strchr(zc
->zc_name
, '@') != NULL
&&
3589 zc
->zc_objset_type
== DMU_OST_ZFS
) {
3590 err
= zfs_unmount_snap(zc
->zc_name
, NULL
);
3595 err
= dmu_objset_rename(zc
->zc_name
, zc
->zc_value
, recursive
);
3596 if ((err
== 0) && (zc
->zc_objset_type
== DMU_OST_ZVOL
)) {
3597 (void) zvol_remove_minor(zc
->zc_name
);
3598 (void) zvol_create_minor(zc
->zc_value
);
3605 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3607 const char *propname
= nvpair_name(pair
);
3608 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3609 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3613 if (prop
== ZPROP_INVAL
) {
3614 if (zfs_prop_user(propname
)) {
3615 if ((err
= zfs_secpolicy_write_perms(dsname
,
3616 ZFS_DELEG_PERM_USERPROP
, cr
)))
3621 if (!issnap
&& zfs_prop_userquota(propname
)) {
3622 const char *perm
= NULL
;
3623 const char *uq_prefix
=
3624 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3625 const char *gq_prefix
=
3626 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3628 if (strncmp(propname
, uq_prefix
,
3629 strlen(uq_prefix
)) == 0) {
3630 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3631 } else if (strncmp(propname
, gq_prefix
,
3632 strlen(gq_prefix
)) == 0) {
3633 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3635 /* USERUSED and GROUPUSED are read-only */
3639 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3650 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3652 * dsl_prop_get_all_impl() returns properties in this
3656 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3657 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3662 * Check that this value is valid for this pool version
3665 case ZFS_PROP_COMPRESSION
:
3667 * If the user specified gzip compression, make sure
3668 * the SPA supports it. We ignore any errors here since
3669 * we'll catch them later.
3671 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3672 nvpair_value_uint64(pair
, &intval
) == 0) {
3673 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3674 intval
<= ZIO_COMPRESS_GZIP_9
&&
3675 zfs_earlier_version(dsname
,
3676 SPA_VERSION_GZIP_COMPRESSION
)) {
3680 if (intval
== ZIO_COMPRESS_ZLE
&&
3681 zfs_earlier_version(dsname
,
3682 SPA_VERSION_ZLE_COMPRESSION
))
3685 if (intval
== ZIO_COMPRESS_LZ4
) {
3686 zfeature_info_t
*feature
=
3688 SPA_FEATURE_LZ4_COMPRESS
];
3691 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3694 if (!spa_feature_is_enabled(spa
, feature
)) {
3695 spa_close(spa
, FTAG
);
3698 spa_close(spa
, FTAG
);
3702 * If this is a bootable dataset then
3703 * verify that the compression algorithm
3704 * is supported for booting. We must return
3705 * something other than ENOTSUP since it
3706 * implies a downrev pool version.
3708 if (zfs_is_bootfs(dsname
) &&
3709 !BOOTFS_COMPRESS_VALID(intval
)) {
3715 case ZFS_PROP_COPIES
:
3716 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3720 case ZFS_PROP_DEDUP
:
3721 if (zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3725 case ZFS_PROP_SHARESMB
:
3726 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3730 case ZFS_PROP_ACLINHERIT
:
3731 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3732 nvpair_value_uint64(pair
, &intval
) == 0) {
3733 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3734 zfs_earlier_version(dsname
,
3735 SPA_VERSION_PASSTHROUGH_X
))
3743 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3747 * Activates a feature on a pool in response to a property setting. This
3748 * creates a new sync task which modifies the pool to reflect the feature
3752 zfs_prop_activate_feature(dsl_pool_t
*dp
, zfeature_info_t
*feature
)
3756 /* EBUSY here indicates that the feature is already active */
3757 err
= dsl_sync_task_do(dp
, zfs_prop_activate_feature_check
,
3758 zfs_prop_activate_feature_sync
, dp
->dp_spa
, feature
, 2);
3760 if (err
!= 0 && err
!= EBUSY
)
3767 * Checks for a race condition to make sure we don't increment a feature flag
3772 zfs_prop_activate_feature_check(void *arg1
, void *arg2
, dmu_tx_t
*tx
)
3775 zfeature_info_t
*feature
= arg2
;
3777 if (!spa_feature_is_active(spa
, feature
))
3784 * The callback invoked on feature activation in the sync task caused by
3785 * zfs_prop_activate_feature.
3788 zfs_prop_activate_feature_sync(void *arg1
, void *arg2
, dmu_tx_t
*tx
)
3791 zfeature_info_t
*feature
= arg2
;
3793 spa_feature_incr(spa
, feature
, tx
);
3797 * Removes properties from the given props list that fail permission checks
3798 * needed to clear them and to restore them in case of a receive error. For each
3799 * property, make sure we have both set and inherit permissions.
3801 * Returns the first error encountered if any permission checks fail. If the
3802 * caller provides a non-NULL errlist, it also gives the complete list of names
3803 * of all the properties that failed a permission check along with the
3804 * corresponding error numbers. The caller is responsible for freeing the
3807 * If every property checks out successfully, zero is returned and the list
3808 * pointed at by errlist is NULL.
3811 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3814 nvpair_t
*pair
, *next_pair
;
3821 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3823 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
3824 (void) strcpy(zc
->zc_name
, dataset
);
3825 pair
= nvlist_next_nvpair(props
, NULL
);
3826 while (pair
!= NULL
) {
3827 next_pair
= nvlist_next_nvpair(props
, pair
);
3829 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3830 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3831 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
3832 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3833 VERIFY(nvlist_add_int32(errors
,
3834 zc
->zc_value
, err
) == 0);
3838 kmem_free(zc
, sizeof (zfs_cmd_t
));
3840 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3841 nvlist_free(errors
);
3844 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3847 if (errlist
== NULL
)
3848 nvlist_free(errors
);
3856 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3858 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3859 /* dsl_prop_get_all_impl() format */
3861 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3862 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3866 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3868 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3869 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3873 if (nvpair_type(p1
) != nvpair_type(p2
))
3876 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
3877 char *valstr1
, *valstr2
;
3879 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
3880 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
3881 return (strcmp(valstr1
, valstr2
) == 0);
3883 uint64_t intval1
, intval2
;
3885 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
3886 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
3887 return (intval1
== intval2
);
3892 * Remove properties from props if they are not going to change (as determined
3893 * by comparison with origprops). Remove them from origprops as well, since we
3894 * do not need to clear or restore properties that won't change.
3897 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
3899 nvpair_t
*pair
, *next_pair
;
3901 if (origprops
== NULL
)
3902 return; /* all props need to be received */
3904 pair
= nvlist_next_nvpair(props
, NULL
);
3905 while (pair
!= NULL
) {
3906 const char *propname
= nvpair_name(pair
);
3909 next_pair
= nvlist_next_nvpair(props
, pair
);
3911 if ((nvlist_lookup_nvpair(origprops
, propname
,
3912 &match
) != 0) || !propval_equals(pair
, match
))
3913 goto next
; /* need to set received value */
3915 /* don't clear the existing received value */
3916 (void) nvlist_remove_nvpair(origprops
, match
);
3917 /* don't bother receiving the property */
3918 (void) nvlist_remove_nvpair(props
, pair
);
3925 static boolean_t zfs_ioc_recv_inject_err
;
3930 * zc_name name of containing filesystem
3931 * zc_nvlist_src{_size} nvlist of properties to apply
3932 * zc_value name of snapshot to create
3933 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3934 * zc_cookie file descriptor to recv from
3935 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3936 * zc_guid force flag
3937 * zc_cleanup_fd cleanup-on-exit file descriptor
3938 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
3941 * zc_cookie number of bytes read
3942 * zc_nvlist_dst{_size} error for each unapplied received property
3943 * zc_obj zprop_errflags_t
3944 * zc_action_handle handle for this guid/ds mapping
3947 zfs_ioc_recv(zfs_cmd_t
*zc
)
3951 dmu_recv_cookie_t drc
;
3952 boolean_t force
= (boolean_t
)zc
->zc_guid
;
3955 int props_error
= 0;
3958 nvlist_t
*props
= NULL
; /* sent properties */
3959 nvlist_t
*origprops
= NULL
; /* existing properties */
3960 objset_t
*origin
= NULL
;
3962 char tofs
[ZFS_MAXNAMELEN
];
3963 boolean_t first_recvd_props
= B_FALSE
;
3965 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3966 strchr(zc
->zc_value
, '@') == NULL
||
3967 strchr(zc
->zc_value
, '%'))
3970 (void) strcpy(tofs
, zc
->zc_value
);
3971 tosnap
= strchr(tofs
, '@');
3974 if (zc
->zc_nvlist_src
!= 0 &&
3975 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3976 zc
->zc_iflags
, &props
)) != 0)
3986 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3988 if (props
&& dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
3989 if ((spa_version(os
->os_spa
) >= SPA_VERSION_RECVD_PROPS
) &&
3990 !dsl_prop_get_hasrecvd(os
)) {
3991 first_recvd_props
= B_TRUE
;
3995 * If new received properties are supplied, they are to
3996 * completely replace the existing received properties, so stash
3997 * away the existing ones.
3999 if (dsl_prop_get_received(os
, &origprops
) == 0) {
4000 nvlist_t
*errlist
= NULL
;
4002 * Don't bother writing a property if its value won't
4003 * change (and avoid the unnecessary security checks).
4005 * The first receive after SPA_VERSION_RECVD_PROPS is a
4006 * special case where we blow away all local properties
4009 if (!first_recvd_props
)
4010 props_reduce(props
, origprops
);
4011 if (zfs_check_clearable(tofs
, origprops
,
4013 (void) nvlist_merge(errors
, errlist
, 0);
4014 nvlist_free(errlist
);
4017 dmu_objset_rele(os
, FTAG
);
4020 if (zc
->zc_string
[0]) {
4021 error
= dmu_objset_hold(zc
->zc_string
, FTAG
, &origin
);
4026 error
= dmu_recv_begin(tofs
, tosnap
, zc
->zc_top_ds
,
4027 &zc
->zc_begin_record
, force
, origin
, &drc
);
4029 dmu_objset_rele(origin
, FTAG
);
4034 * Set properties before we receive the stream so that they are applied
4035 * to the new data. Note that we must call dmu_recv_stream() if
4036 * dmu_recv_begin() succeeds.
4039 if (dmu_objset_from_ds(drc
.drc_logical_ds
, &os
) == 0) {
4040 if (drc
.drc_newfs
) {
4041 if (spa_version(os
->os_spa
) >=
4042 SPA_VERSION_RECVD_PROPS
)
4043 first_recvd_props
= B_TRUE
;
4044 } else if (origprops
!= NULL
) {
4045 if (clear_received_props(os
, tofs
, origprops
,
4046 first_recvd_props
? NULL
: props
) != 0)
4047 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4049 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4051 dsl_prop_set_hasrecvd(os
);
4052 } else if (!drc
.drc_newfs
) {
4053 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4056 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4060 if (zc
->zc_nvlist_dst_size
!= 0 &&
4061 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4062 put_nvlist(zc
, errors
) != 0)) {
4064 * Caller made zc->zc_nvlist_dst less than the minimum expected
4065 * size or supplied an invalid address.
4067 props_error
= EINVAL
;
4071 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
4072 &zc
->zc_action_handle
);
4075 zfs_sb_t
*zsb
= NULL
;
4077 if (get_zfs_sb(tofs
, &zsb
) == 0) {
4081 error
= zfs_suspend_fs(zsb
);
4083 * If the suspend fails, then the recv_end will
4084 * likely also fail, and clean up after itself.
4086 end_err
= dmu_recv_end(&drc
);
4088 error
= zfs_resume_fs(zsb
, tofs
);
4089 error
= error
? error
: end_err
;
4090 deactivate_super(zsb
->z_sb
);
4092 error
= dmu_recv_end(&drc
);
4096 zc
->zc_cookie
= off
- fp
->f_offset
;
4097 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4101 if (zfs_ioc_recv_inject_err
) {
4102 zfs_ioc_recv_inject_err
= B_FALSE
;
4107 * On error, restore the original props.
4109 if (error
&& props
) {
4110 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
4111 if (clear_received_props(os
, tofs
, props
, NULL
) != 0) {
4113 * We failed to clear the received properties.
4114 * Since we may have left a $recvd value on the
4115 * system, we can't clear the $hasrecvd flag.
4117 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4118 } else if (first_recvd_props
) {
4119 dsl_prop_unset_hasrecvd(os
);
4121 dmu_objset_rele(os
, FTAG
);
4122 } else if (!drc
.drc_newfs
) {
4123 /* We failed to clear the received properties. */
4124 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4127 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4128 /* We failed to stash the original properties. */
4129 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4133 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4134 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4135 * explictly if we're restoring local properties cleared in the
4136 * first new-style receive.
4138 if (origprops
!= NULL
&&
4139 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4140 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4141 origprops
, NULL
) != 0) {
4143 * We stashed the original properties but failed to
4146 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4151 nvlist_free(origprops
);
4152 nvlist_free(errors
);
4156 error
= props_error
;
4163 * zc_name name of snapshot to send
4164 * zc_cookie file descriptor to send stream to
4165 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4166 * zc_sendobj objsetid of snapshot to send
4167 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4168 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4169 * output size in zc_objset_type.
4174 zfs_ioc_send(zfs_cmd_t
*zc
)
4176 objset_t
*fromsnap
= NULL
;
4181 dsl_dataset_t
*dsfrom
= NULL
;
4184 boolean_t estimate
= (zc
->zc_guid
!= 0);
4186 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4190 dp
= spa_get_dsl(spa
);
4191 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
4192 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
4193 rw_exit(&dp
->dp_config_rwlock
);
4194 spa_close(spa
, FTAG
);
4198 error
= dmu_objset_from_ds(ds
, &tosnap
);
4200 dsl_dataset_rele(ds
, FTAG
);
4204 if (zc
->zc_fromobj
!= 0) {
4205 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
4206 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
, FTAG
, &dsfrom
);
4207 rw_exit(&dp
->dp_config_rwlock
);
4209 dsl_dataset_rele(ds
, FTAG
);
4212 error
= dmu_objset_from_ds(dsfrom
, &fromsnap
);
4214 dsl_dataset_rele(dsfrom
, FTAG
);
4215 dsl_dataset_rele(ds
, FTAG
);
4221 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
4223 if (fromsnap
!= NULL
) {
4224 dsl_dataset_rele(dsfrom
, FTAG
);
4225 dsl_dataset_rele(ds
, FTAG
);
4229 if (dsl_dir_is_clone(ds
->ds_dir
)) {
4230 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
4231 error
= dsl_dataset_hold_obj(dp
,
4232 ds
->ds_dir
->dd_phys
->dd_origin_obj
, FTAG
, &dsfrom
);
4233 rw_exit(&dp
->dp_config_rwlock
);
4235 dsl_dataset_rele(ds
, FTAG
);
4238 error
= dmu_objset_from_ds(dsfrom
, &fromsnap
);
4240 dsl_dataset_rele(dsfrom
, FTAG
);
4241 dsl_dataset_rele(ds
, FTAG
);
4248 error
= dmu_send_estimate(tosnap
, fromsnap
,
4249 &zc
->zc_objset_type
);
4251 file_t
*fp
= getf(zc
->zc_cookie
);
4253 dsl_dataset_rele(ds
, FTAG
);
4255 dsl_dataset_rele(dsfrom
, FTAG
);
4260 error
= dmu_send(tosnap
, fromsnap
,
4261 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4263 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4265 releasef(zc
->zc_cookie
);
4268 dsl_dataset_rele(dsfrom
, FTAG
);
4269 dsl_dataset_rele(ds
, FTAG
);
4275 * zc_name name of snapshot on which to report progress
4276 * zc_cookie file descriptor of send stream
4279 * zc_cookie number of bytes written in send stream thus far
4282 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4285 dmu_sendarg_t
*dsp
= NULL
;
4288 if ((error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &ds
)) != 0)
4291 mutex_enter(&ds
->ds_sendstream_lock
);
4294 * Iterate over all the send streams currently active on this dataset.
4295 * If there's one which matches the specified file descriptor _and_ the
4296 * stream was started by the current process, return the progress of
4300 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4301 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4302 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4303 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4308 zc
->zc_cookie
= *(dsp
->dsa_off
);
4312 mutex_exit(&ds
->ds_sendstream_lock
);
4313 dsl_dataset_rele(ds
, FTAG
);
4318 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4322 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4323 &zc
->zc_inject_record
);
4326 zc
->zc_guid
= (uint64_t)id
;
4332 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4334 return (zio_clear_fault((int)zc
->zc_guid
));
4338 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4340 int id
= (int)zc
->zc_guid
;
4343 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4344 &zc
->zc_inject_record
);
4352 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4356 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4358 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4361 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4364 zc
->zc_nvlist_dst_size
= count
;
4366 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4368 spa_close(spa
, FTAG
);
4374 zfs_ioc_clear(zfs_cmd_t
*zc
)
4381 * On zpool clear we also fix up missing slogs
4383 mutex_enter(&spa_namespace_lock
);
4384 spa
= spa_lookup(zc
->zc_name
);
4386 mutex_exit(&spa_namespace_lock
);
4389 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4390 /* we need to let spa_open/spa_load clear the chains */
4391 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4393 spa
->spa_last_open_failed
= 0;
4394 mutex_exit(&spa_namespace_lock
);
4396 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4397 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4400 nvlist_t
*config
= NULL
;
4402 if (zc
->zc_nvlist_src
== 0)
4405 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4406 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4407 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4409 if (config
!= NULL
) {
4412 if ((err
= put_nvlist(zc
, config
)) != 0)
4414 nvlist_free(config
);
4416 nvlist_free(policy
);
4423 spa_vdev_state_enter(spa
, SCL_NONE
);
4425 if (zc
->zc_guid
== 0) {
4428 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4430 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4431 spa_close(spa
, FTAG
);
4436 vdev_clear(spa
, vd
);
4438 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4441 * Resume any suspended I/Os.
4443 if (zio_resume(spa
) != 0)
4446 spa_close(spa
, FTAG
);
4452 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4457 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4461 spa_vdev_state_enter(spa
, SCL_NONE
);
4464 * If a resilver is already in progress then set the
4465 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4466 * the scan as a side effect of the reopen. Otherwise, let
4467 * vdev_open() decided if a resilver is required.
4469 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4470 vdev_reopen(spa
->spa_root_vdev
);
4471 spa
->spa_scrub_reopen
= B_FALSE
;
4473 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4474 spa_close(spa
, FTAG
);
4479 * zc_name name of filesystem
4480 * zc_value name of origin snapshot
4483 * zc_string name of conflicting snapshot, if there is one
4486 zfs_ioc_promote(zfs_cmd_t
*zc
)
4491 * We don't need to unmount *all* the origin fs's snapshots, but
4494 cp
= strchr(zc
->zc_value
, '@');
4497 (void) dmu_objset_find(zc
->zc_value
,
4498 zfs_unmount_snap
, NULL
, DS_FIND_SNAPSHOTS
);
4499 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4503 * Retrieve a single {user|group}{used|quota}@... property.
4506 * zc_name name of filesystem
4507 * zc_objset_type zfs_userquota_prop_t
4508 * zc_value domain name (eg. "S-1-234-567-89")
4509 * zc_guid RID/UID/GID
4512 * zc_cookie property value
4515 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4520 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4523 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4527 error
= zfs_userspace_one(zsb
,
4528 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4529 zfs_sb_rele(zsb
, FTAG
);
4536 * zc_name name of filesystem
4537 * zc_cookie zap cursor
4538 * zc_objset_type zfs_userquota_prop_t
4539 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4542 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4543 * zc_cookie zap cursor
4546 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4549 int bufsize
= zc
->zc_nvlist_dst_size
;
4556 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4560 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
4562 error
= zfs_userspace_many(zsb
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4563 buf
, &zc
->zc_nvlist_dst_size
);
4566 error
= xcopyout(buf
,
4567 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4568 zc
->zc_nvlist_dst_size
);
4570 vmem_free(buf
, bufsize
);
4571 zfs_sb_rele(zsb
, FTAG
);
4578 * zc_name name of filesystem
4584 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4590 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
4591 if (!dmu_objset_userused_enabled(zsb
->z_os
)) {
4593 * If userused is not enabled, it may be because the
4594 * objset needs to be closed & reopened (to grow the
4595 * objset_phys_t). Suspend/resume the fs will do that.
4597 error
= zfs_suspend_fs(zsb
);
4599 error
= zfs_resume_fs(zsb
, zc
->zc_name
);
4602 error
= dmu_objset_userspace_upgrade(zsb
->z_os
);
4603 deactivate_super(zsb
->z_sb
);
4605 /* XXX kind of reading contents without owning */
4606 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4610 error
= dmu_objset_userspace_upgrade(os
);
4611 dmu_objset_rele(os
, FTAG
);
4618 zfs_ioc_share(zfs_cmd_t
*zc
)
4623 ace_t full_access
[] = {
4624 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4629 * zc_name name of containing filesystem
4630 * zc_obj object # beyond which we want next in-use object #
4633 * zc_obj next in-use object #
4636 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4638 objset_t
*os
= NULL
;
4641 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4645 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4646 os
->os_dsl_dataset
->ds_phys
->ds_prev_snap_txg
);
4648 dmu_objset_rele(os
, FTAG
);
4654 * zc_name name of filesystem
4655 * zc_value prefix name for snapshot
4656 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4659 * zc_value short name of new snapshot
4662 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
4667 snap_name
= kmem_asprintf("%s@%s-%016llx", zc
->zc_name
, zc
->zc_value
,
4668 (u_longlong_t
)ddi_get_lbolt64());
4670 if (strlen(snap_name
) >= MAXPATHLEN
) {
4675 error
= dmu_objset_snapshot_tmp(snap_name
, "%temp", zc
->zc_cleanup_fd
);
4681 (void) strcpy(zc
->zc_value
, strchr(snap_name
, '@') + 1);
4688 * zc_name name of "to" snapshot
4689 * zc_value name of "from" snapshot
4690 * zc_cookie file descriptor to write diff data on
4693 * dmu_diff_record_t's to the file descriptor
4696 zfs_ioc_diff(zfs_cmd_t
*zc
)
4704 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &tosnap
);
4708 error
= dmu_objset_hold(zc
->zc_value
, FTAG
, &fromsnap
);
4710 dmu_objset_rele(tosnap
, FTAG
);
4714 fp
= getf(zc
->zc_cookie
);
4716 dmu_objset_rele(fromsnap
, FTAG
);
4717 dmu_objset_rele(tosnap
, FTAG
);
4723 error
= dmu_diff(tosnap
, fromsnap
, fp
->f_vnode
, &off
);
4725 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4727 releasef(zc
->zc_cookie
);
4729 dmu_objset_rele(fromsnap
, FTAG
);
4730 dmu_objset_rele(tosnap
, FTAG
);
4735 * Remove all ACL files in shares dir
4737 #ifdef HAVE_SMB_SHARE
4739 zfs_smb_acl_purge(znode_t
*dzp
)
4742 zap_attribute_t zap
;
4743 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
4746 for (zap_cursor_init(&zc
, zsb
->z_os
, dzp
->z_id
);
4747 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
4748 zap_cursor_advance(&zc
)) {
4749 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
4753 zap_cursor_fini(&zc
);
4756 #endif /* HAVE_SMB_SHARE */
4759 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
4761 #ifdef HAVE_SMB_SHARE
4764 vnode_t
*resourcevp
= NULL
;
4773 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
4774 NO_FOLLOW
, NULL
, &vp
)) != 0)
4777 /* Now make sure mntpnt and dataset are ZFS */
4779 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
4780 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
4781 zc
->zc_name
) != 0)) {
4791 * Create share dir if its missing.
4793 mutex_enter(&zsb
->z_lock
);
4794 if (zsb
->z_shares_dir
== 0) {
4797 tx
= dmu_tx_create(zsb
->z_os
);
4798 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
4800 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
4801 error
= dmu_tx_assign(tx
, TXG_WAIT
);
4805 error
= zfs_create_share_dir(zsb
, tx
);
4809 mutex_exit(&zsb
->z_lock
);
4815 mutex_exit(&zsb
->z_lock
);
4817 ASSERT(zsb
->z_shares_dir
);
4818 if ((error
= zfs_zget(zsb
, zsb
->z_shares_dir
, &sharedir
)) != 0) {
4824 switch (zc
->zc_cookie
) {
4825 case ZFS_SMB_ACL_ADD
:
4826 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
4827 vattr
.va_mode
= S_IFREG
|0777;
4831 vsec
.vsa_mask
= VSA_ACE
;
4832 vsec
.vsa_aclentp
= &full_access
;
4833 vsec
.vsa_aclentsz
= sizeof (full_access
);
4834 vsec
.vsa_aclcnt
= 1;
4836 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
4837 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
4839 VN_RELE(resourcevp
);
4842 case ZFS_SMB_ACL_REMOVE
:
4843 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
4847 case ZFS_SMB_ACL_RENAME
:
4848 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4849 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
4854 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
4855 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
4858 VN_RELE(ZTOV(sharedir
));
4860 nvlist_free(nvlist
);
4863 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
4865 nvlist_free(nvlist
);
4868 case ZFS_SMB_ACL_PURGE
:
4869 error
= zfs_smb_acl_purge(sharedir
);
4878 VN_RELE(ZTOV(sharedir
));
4885 #endif /* HAVE_SMB_SHARE */
4890 * zc_name name of filesystem
4891 * zc_value short name of snap
4892 * zc_string user-supplied tag for this hold
4893 * zc_cookie recursive flag
4894 * zc_temphold set if hold is temporary
4895 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4896 * zc_sendobj if non-zero, the objid for zc_name@zc_value
4897 * zc_createtxg if zc_sendobj is non-zero, snap must have zc_createtxg
4902 zfs_ioc_hold(zfs_cmd_t
*zc
)
4904 boolean_t recursive
= zc
->zc_cookie
;
4911 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
4914 if (zc
->zc_sendobj
== 0) {
4915 return (dsl_dataset_user_hold(zc
->zc_name
, zc
->zc_value
,
4916 zc
->zc_string
, recursive
, zc
->zc_temphold
,
4917 zc
->zc_cleanup_fd
));
4923 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4927 dp
= spa_get_dsl(spa
);
4928 rw_enter(&dp
->dp_config_rwlock
, RW_READER
);
4929 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
4930 rw_exit(&dp
->dp_config_rwlock
);
4931 spa_close(spa
, FTAG
);
4936 * Until we have a hold on this snapshot, it's possible that
4937 * zc_sendobj could've been destroyed and reused as part
4938 * of a later txg. Make sure we're looking at the right object.
4940 if (zc
->zc_createtxg
!= ds
->ds_phys
->ds_creation_txg
) {
4941 dsl_dataset_rele(ds
, FTAG
);
4945 if (zc
->zc_cleanup_fd
!= -1 && zc
->zc_temphold
) {
4946 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
4948 dsl_dataset_rele(ds
, FTAG
);
4953 error
= dsl_dataset_user_hold_for_send(ds
, zc
->zc_string
,
4957 dsl_register_onexit_hold_cleanup(ds
, zc
->zc_string
,
4960 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
4962 dsl_dataset_rele(ds
, FTAG
);
4969 * zc_name name of dataset from which we're releasing a user hold
4970 * zc_value short name of snap
4971 * zc_string user-supplied tag for this hold
4972 * zc_cookie recursive flag
4977 zfs_ioc_release(zfs_cmd_t
*zc
)
4979 boolean_t recursive
= zc
->zc_cookie
;
4981 if (snapshot_namecheck(zc
->zc_value
, NULL
, NULL
) != 0)
4984 return (dsl_dataset_user_release(zc
->zc_name
, zc
->zc_value
,
4985 zc
->zc_string
, recursive
));
4990 * zc_name name of filesystem
4993 * zc_nvlist_src{_size} nvlist of snapshot holds
4996 zfs_ioc_get_holds(zfs_cmd_t
*zc
)
5001 if ((error
= dsl_dataset_get_holds(zc
->zc_name
, &nvp
)) == 0) {
5002 error
= put_nvlist(zc
, nvp
);
5011 * zc_guid flags (ZEVENT_NONBLOCK)
5014 * zc_nvlist_dst next nvlist event
5015 * zc_cookie dropped events since last get
5016 * zc_cleanup_fd cleanup-on-exit file descriptor
5019 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5022 nvlist_t
*event
= NULL
;
5024 uint64_t dropped
= 0;
5027 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5032 error
= zfs_zevent_next(ze
, &event
,
5033 &zc
->zc_nvlist_dst_size
, &dropped
);
5034 if (event
!= NULL
) {
5035 zc
->zc_cookie
= dropped
;
5036 error
= put_nvlist(zc
, event
);
5040 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5043 if ((error
== 0) || (error
!= ENOENT
))
5046 error
= zfs_zevent_wait(ze
);
5051 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5058 * zc_cookie cleared events count
5061 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5065 zfs_zevent_drain_all(&count
);
5066 zc
->zc_cookie
= count
;
5073 * zc_name name of new filesystem or snapshot
5074 * zc_value full name of old snapshot
5077 * zc_cookie space in bytes
5078 * zc_objset_type compressed space in bytes
5079 * zc_perm_action uncompressed space in bytes
5082 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5085 dsl_dataset_t
*new, *old
;
5087 error
= dsl_dataset_hold(zc
->zc_name
, FTAG
, &new);
5090 error
= dsl_dataset_hold(zc
->zc_value
, FTAG
, &old
);
5092 dsl_dataset_rele(new, FTAG
);
5096 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5097 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5098 dsl_dataset_rele(old
, FTAG
);
5099 dsl_dataset_rele(new, FTAG
);
5105 * "firstsnap" -> snapshot name
5109 * "used" -> space in bytes
5110 * "compressed" -> compressed space in bytes
5111 * "uncompressed" -> uncompressed space in bytes
5115 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5118 dsl_dataset_t
*new, *old
;
5120 uint64_t used
, comp
, uncomp
;
5122 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5125 error
= dsl_dataset_hold(lastsnap
, FTAG
, &new);
5128 error
= dsl_dataset_hold(firstsnap
, FTAG
, &old
);
5130 dsl_dataset_rele(new, FTAG
);
5134 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5135 dsl_dataset_rele(old
, FTAG
);
5136 dsl_dataset_rele(new, FTAG
);
5137 fnvlist_add_uint64(outnvl
, "used", used
);
5138 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5139 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5145 * "fd" -> file descriptor to write stream to (int32)
5146 * (optional) "fromsnap" -> full snap name to send an incremental from
5153 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5155 objset_t
*fromsnap
= NULL
;
5162 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5166 error
= dmu_objset_hold(snapname
, FTAG
, &tosnap
);
5170 error
= nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5172 error
= dmu_objset_hold(fromname
, FTAG
, &fromsnap
);
5174 dmu_objset_rele(tosnap
, FTAG
);
5180 file_t
*fp
= getf(fd
);
5182 dmu_objset_rele(tosnap
, FTAG
);
5183 if (fromsnap
!= NULL
)
5184 dmu_objset_rele(fromsnap
, FTAG
);
5189 error
= dmu_send(tosnap
, fromsnap
, fd
, fp
->f_vnode
, &off
);
5191 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5195 if (fromsnap
!= NULL
)
5196 dmu_objset_rele(fromsnap
, FTAG
);
5197 dmu_objset_rele(tosnap
, FTAG
);
5202 * Determine approximately how large a zfs send stream will be -- the number
5203 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5206 * (optional) "fromsnap" -> full snap name to send an incremental from
5210 * "space" -> bytes of space (uint64)
5214 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5216 objset_t
*fromsnap
= NULL
;
5222 error
= dmu_objset_hold(snapname
, FTAG
, &tosnap
);
5226 error
= nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5228 error
= dmu_objset_hold(fromname
, FTAG
, &fromsnap
);
5230 dmu_objset_rele(tosnap
, FTAG
);
5235 error
= dmu_send_estimate(tosnap
, fromsnap
, &space
);
5236 fnvlist_add_uint64(outnvl
, "space", space
);
5238 if (fromsnap
!= NULL
)
5239 dmu_objset_rele(fromsnap
, FTAG
);
5240 dmu_objset_rele(tosnap
, FTAG
);
5245 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5248 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5249 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5250 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5252 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5254 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5255 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5256 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5257 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5259 vec
->zvec_legacy_func
= func
;
5260 vec
->zvec_secpolicy
= secpolicy
;
5261 vec
->zvec_namecheck
= namecheck
;
5262 vec
->zvec_allow_log
= log_history
;
5263 vec
->zvec_pool_check
= pool_check
;
5267 * See the block comment at the beginning of this file for details on
5268 * each argument to this function.
5271 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5272 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5273 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5274 boolean_t allow_log
)
5276 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5278 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5279 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5280 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5281 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5283 /* if we are logging, the name must be valid */
5284 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5286 vec
->zvec_name
= name
;
5287 vec
->zvec_func
= func
;
5288 vec
->zvec_secpolicy
= secpolicy
;
5289 vec
->zvec_namecheck
= namecheck
;
5290 vec
->zvec_pool_check
= pool_check
;
5291 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5292 vec
->zvec_allow_log
= allow_log
;
5296 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5297 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5298 zfs_ioc_poolcheck_t pool_check
)
5300 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5301 POOL_NAME
, log_history
, pool_check
);
5305 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5306 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5308 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5309 DATASET_NAME
, B_FALSE
, pool_check
);
5313 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5315 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5316 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5320 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5321 zfs_secpolicy_func_t
*secpolicy
)
5323 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5324 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5328 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5329 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5331 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5332 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5336 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5338 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5339 zfs_secpolicy_read
);
5343 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5344 zfs_secpolicy_func_t
*secpolicy
)
5346 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5347 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5351 zfs_ioctl_init(void)
5353 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5354 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5355 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5357 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5358 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5359 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5361 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5362 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5363 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5365 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5366 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5367 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5369 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5370 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5371 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5373 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5374 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5375 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5377 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5378 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5379 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5381 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5382 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5383 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5385 /* IOCTLS that use the legacy function signature */
5387 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5388 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5390 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5391 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5392 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5394 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5395 zfs_ioc_pool_upgrade
);
5396 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5398 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5399 zfs_ioc_vdev_remove
);
5400 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5401 zfs_ioc_vdev_set_state
);
5402 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5403 zfs_ioc_vdev_attach
);
5404 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5405 zfs_ioc_vdev_detach
);
5406 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5407 zfs_ioc_vdev_setpath
);
5408 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5409 zfs_ioc_vdev_setfru
);
5410 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5411 zfs_ioc_pool_set_props
);
5412 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5413 zfs_ioc_vdev_split
);
5414 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5415 zfs_ioc_pool_reguid
);
5417 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5418 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5419 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5420 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5421 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5422 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5423 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5424 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5425 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5426 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5429 * pool destroy, and export don't log the history as part of
5430 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5431 * does the logging of those commands.
5433 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5434 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5435 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5436 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5438 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5439 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5440 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5441 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5443 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5444 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5445 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5446 zfs_ioc_dsobj_to_dsname
,
5447 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5448 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5449 zfs_ioc_pool_get_history
,
5450 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5452 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5453 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5455 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5456 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5457 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5458 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5460 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5461 zfs_ioc_space_written
);
5462 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_HOLDS
,
5464 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5465 zfs_ioc_objset_recvd_props
);
5466 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5468 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5470 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5471 zfs_ioc_objset_stats
);
5472 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5473 zfs_ioc_objset_zplprops
);
5474 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5475 zfs_ioc_dataset_list_next
);
5476 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5477 zfs_ioc_snapshot_list_next
);
5478 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5479 zfs_ioc_send_progress
);
5481 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5482 zfs_ioc_diff
, zfs_secpolicy_diff
);
5483 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5484 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5485 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5486 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5487 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5488 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5489 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5490 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5491 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5492 zfs_ioc_send
, zfs_secpolicy_send
);
5494 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5495 zfs_secpolicy_none
);
5496 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5497 zfs_secpolicy_destroy
);
5498 zfs_ioctl_register_dataset_modify(ZFS_IOC_ROLLBACK
, zfs_ioc_rollback
,
5499 zfs_secpolicy_rollback
);
5500 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5501 zfs_secpolicy_rename
);
5502 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5503 zfs_secpolicy_recv
);
5504 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5505 zfs_secpolicy_promote
);
5506 zfs_ioctl_register_dataset_modify(ZFS_IOC_HOLD
, zfs_ioc_hold
,
5507 zfs_secpolicy_hold
);
5508 zfs_ioctl_register_dataset_modify(ZFS_IOC_RELEASE
, zfs_ioc_release
,
5509 zfs_secpolicy_release
);
5510 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5511 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5512 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5513 zfs_secpolicy_set_fsacl
);
5515 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5516 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5517 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5518 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5519 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5520 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5521 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5522 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5523 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5524 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5529 zfs_ioctl_register_legacy(ZFS_IOC_CREATE_MINOR
, zfs_ioc_create_minor
,
5530 zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5531 zfs_ioctl_register_legacy(ZFS_IOC_REMOVE_MINOR
, zfs_ioc_remove_minor
,
5532 zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5533 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
5534 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5535 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
5536 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5540 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5541 zfs_ioc_poolcheck_t check
)
5546 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5548 if (check
& POOL_CHECK_NONE
)
5551 error
= spa_open(name
, &spa
, FTAG
);
5553 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5555 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5557 spa_close(spa
, FTAG
);
5563 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
5567 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5569 for (zs
= list_head(&zfsdev_state_list
); zs
!= NULL
;
5570 zs
= list_next(&zfsdev_state_list
, zs
)) {
5571 if (zs
->zs_minor
== minor
) {
5573 case ZST_ONEXIT
: return (zs
->zs_onexit
);
5574 case ZST_ZEVENT
: return (zs
->zs_zevent
);
5575 case ZST_ALL
: return (zs
);
5584 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
5588 mutex_enter(&zfsdev_state_lock
);
5589 ptr
= zfsdev_get_state_impl(minor
, which
);
5590 mutex_exit(&zfsdev_state_lock
);
5596 zfsdev_getminor(struct file
*filp
)
5598 ASSERT(filp
!= NULL
);
5599 ASSERT(filp
->private_data
!= NULL
);
5601 return (((zfsdev_state_t
*)filp
->private_data
)->zs_minor
);
5605 * Find a free minor number. The zfsdev_state_list is expected to
5606 * be short since it is only a list of currently open file handles.
5609 zfsdev_minor_alloc(void)
5611 static minor_t last_minor
= 0;
5614 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5616 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5617 if (m
> ZFSDEV_MAX_MINOR
)
5619 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
5629 zfsdev_state_init(struct file
*filp
)
5634 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5636 minor
= zfsdev_minor_alloc();
5640 zs
= kmem_zalloc( sizeof(zfsdev_state_t
), KM_SLEEP
);
5643 zs
->zs_minor
= minor
;
5644 filp
->private_data
= zs
;
5646 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
5647 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
5649 list_insert_tail(&zfsdev_state_list
, zs
);
5655 zfsdev_state_destroy(struct file
*filp
)
5659 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5660 ASSERT(filp
->private_data
!= NULL
);
5662 zs
= filp
->private_data
;
5663 zfs_onexit_destroy(zs
->zs_onexit
);
5664 zfs_zevent_destroy(zs
->zs_zevent
);
5666 list_remove(&zfsdev_state_list
, zs
);
5667 kmem_free(zs
, sizeof(zfsdev_state_t
));
5673 zfsdev_open(struct inode
*ino
, struct file
*filp
)
5677 mutex_enter(&zfsdev_state_lock
);
5678 error
= zfsdev_state_init(filp
);
5679 mutex_exit(&zfsdev_state_lock
);
5685 zfsdev_release(struct inode
*ino
, struct file
*filp
)
5689 mutex_enter(&zfsdev_state_lock
);
5690 error
= zfsdev_state_destroy(filp
);
5691 mutex_exit(&zfsdev_state_lock
);
5697 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5701 int error
, rc
, len
, flag
= 0;
5702 const zfs_ioc_vec_t
*vec
;
5703 char saved_poolname
[MAXNAMELEN
];
5704 nvlist_t
*innvl
= NULL
;
5706 vecnum
= cmd
- ZFS_IOC_FIRST
;
5707 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
5709 vec
= &zfs_ioc_vec
[vecnum
];
5711 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
5713 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
5719 zc
->zc_iflags
= flag
& FKIOCTL
;
5720 if (zc
->zc_nvlist_src_size
!= 0) {
5721 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
5722 zc
->zc_iflags
, &innvl
);
5728 * Ensure that all pool/dataset names are valid before we pass down to
5731 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5732 switch (vec
->zvec_namecheck
) {
5734 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5737 error
= pool_status_check(zc
->zc_name
,
5738 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
5742 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5745 error
= pool_status_check(zc
->zc_name
,
5746 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
5754 if (error
== 0 && !(flag
& FKIOCTL
))
5755 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
5760 /* legacy ioctls can modify zc_name */
5761 (void) strlcpy(saved_poolname
, zc
->zc_name
, sizeof(saved_poolname
));
5762 len
= strcspn(saved_poolname
, "/@") + 1;
5763 saved_poolname
[len
] = '\0';
5765 if (vec
->zvec_func
!= NULL
) {
5769 nvlist_t
*lognv
= NULL
;
5771 ASSERT(vec
->zvec_legacy_func
== NULL
);
5774 * Add the innvl to the lognv before calling the func,
5775 * in case the func changes the innvl.
5777 if (vec
->zvec_allow_log
) {
5778 lognv
= fnvlist_alloc();
5779 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
5781 if (!nvlist_empty(innvl
)) {
5782 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
5787 outnvl
= fnvlist_alloc();
5788 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
5790 if (error
== 0 && vec
->zvec_allow_log
&&
5791 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
5792 if (!nvlist_empty(outnvl
)) {
5793 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
5796 (void) spa_history_log_nvl(spa
, lognv
);
5797 spa_close(spa
, FTAG
);
5799 fnvlist_free(lognv
);
5801 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
5803 if (vec
->zvec_smush_outnvlist
) {
5804 smusherror
= nvlist_smush(outnvl
,
5805 zc
->zc_nvlist_dst_size
);
5807 if (smusherror
== 0)
5808 puterror
= put_nvlist(zc
, outnvl
);
5814 nvlist_free(outnvl
);
5816 error
= vec
->zvec_legacy_func(zc
);
5821 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
5822 if (error
== 0 && rc
!= 0)
5824 if (error
== 0 && vec
->zvec_allow_log
) {
5825 char *s
= tsd_get(zfs_allow_log_key
);
5828 (void) tsd_set(zfs_allow_log_key
, strdup(saved_poolname
));
5831 kmem_free(zc
, sizeof (zfs_cmd_t
));
5835 #ifdef CONFIG_COMPAT
5837 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5839 return zfsdev_ioctl(filp
, cmd
, arg
);
5842 #define zfsdev_compat_ioctl NULL
5845 static const struct file_operations zfsdev_fops
= {
5846 .open
= zfsdev_open
,
5847 .release
= zfsdev_release
,
5848 .unlocked_ioctl
= zfsdev_ioctl
,
5849 .compat_ioctl
= zfsdev_compat_ioctl
,
5850 .owner
= THIS_MODULE
,
5853 static struct miscdevice zfs_misc
= {
5854 .minor
= MISC_DYNAMIC_MINOR
,
5856 .fops
= &zfsdev_fops
,
5864 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
5865 list_create(&zfsdev_state_list
, sizeof (zfsdev_state_t
),
5866 offsetof(zfsdev_state_t
, zs_next
));
5868 error
= misc_register(&zfs_misc
);
5870 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
5882 error
= misc_deregister(&zfs_misc
);
5884 printk(KERN_INFO
"ZFS: misc_deregister() failed %d\n", error
);
5886 mutex_destroy(&zfsdev_state_lock
);
5887 list_destroy(&zfsdev_state_list
);
5891 zfs_allow_log_destroy(void *arg
)
5893 char *poolname
= arg
;
5898 #define ZFS_DEBUG_STR " (DEBUG mode)"
5900 #define ZFS_DEBUG_STR ""
5908 spa_init(FREAD
| FWRITE
);
5911 if ((error
= zvol_init()) != 0)
5916 if ((error
= zfs_attach()) != 0)
5919 tsd_create(&zfs_fsyncer_key
, NULL
);
5920 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
5921 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
5923 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
5924 "ZFS pool version %s, ZFS filesystem version %s\n",
5925 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
5926 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
5935 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
5936 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
5937 ZFS_DEBUG_STR
, error
);
5950 tsd_destroy(&zfs_fsyncer_key
);
5951 tsd_destroy(&rrw_tsd_key
);
5952 tsd_destroy(&zfs_allow_log_key
);
5954 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
5955 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
5961 spl_module_init(_init
);
5962 spl_module_exit(_fini
);
5964 MODULE_DESCRIPTION("ZFS");
5965 MODULE_AUTHOR(ZFS_META_AUTHOR
);
5966 MODULE_LICENSE(ZFS_META_LICENSE
);
5967 #endif /* HAVE_SPL */