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>
162 #include <sys/dmu_tx.h>
164 #include <sys/sunddi.h>
165 #include <sys/sunldi.h>
166 #include <sys/policy.h>
167 #include <sys/zone.h>
168 #include <sys/nvpair.h>
169 #include <sys/pathname.h>
170 #include <sys/mount.h>
172 #include <sys/fs/zfs.h>
173 #include <sys/zfs_ctldir.h>
174 #include <sys/zfs_dir.h>
175 #include <sys/zfs_onexit.h>
176 #include <sys/zvol.h>
177 #include <sys/dsl_scan.h>
178 #include <sharefs/share.h>
179 #include <sys/fm/util.h>
181 #include <sys/dmu_send.h>
182 #include <sys/dsl_destroy.h>
183 #include <sys/dsl_userhold.h>
184 #include <sys/zfeature.h>
186 #include <linux/miscdevice.h>
188 #include "zfs_namecheck.h"
189 #include "zfs_prop.h"
190 #include "zfs_deleg.h"
191 #include "zfs_comutil.h"
193 kmutex_t zfsdev_state_lock
;
194 list_t zfsdev_state_list
;
196 extern void zfs_init(void);
197 extern void zfs_fini(void);
199 uint_t zfs_fsyncer_key
;
200 extern uint_t rrw_tsd_key
;
201 static uint_t zfs_allow_log_key
;
203 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
204 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
205 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
211 } zfs_ioc_namecheck_t
;
214 POOL_CHECK_NONE
= 1 << 0,
215 POOL_CHECK_SUSPENDED
= 1 << 1,
216 POOL_CHECK_READONLY
= 1 << 2,
217 } zfs_ioc_poolcheck_t
;
219 typedef struct zfs_ioc_vec
{
220 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
221 zfs_ioc_func_t
*zvec_func
;
222 zfs_secpolicy_func_t
*zvec_secpolicy
;
223 zfs_ioc_namecheck_t zvec_namecheck
;
224 boolean_t zvec_allow_log
;
225 zfs_ioc_poolcheck_t zvec_pool_check
;
226 boolean_t zvec_smush_outnvlist
;
227 const char *zvec_name
;
230 /* This array is indexed by zfs_userquota_prop_t */
231 static const char *userquota_perms
[] = {
232 ZFS_DELEG_PERM_USERUSED
,
233 ZFS_DELEG_PERM_USERQUOTA
,
234 ZFS_DELEG_PERM_GROUPUSED
,
235 ZFS_DELEG_PERM_GROUPQUOTA
,
238 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
239 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
241 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
243 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
245 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
246 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
248 static int zfs_prop_activate_feature(spa_t
*spa
, zfeature_info_t
*feature
);
251 history_str_free(char *buf
)
253 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
257 history_str_get(zfs_cmd_t
*zc
)
261 if (zc
->zc_history
== 0)
264 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
| KM_NODEBUG
);
265 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
266 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
267 history_str_free(buf
);
271 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
277 * Check to see if the named dataset is currently defined as bootable
280 zfs_is_bootfs(const char *name
)
284 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
286 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
287 dmu_objset_rele(os
, FTAG
);
294 * zfs_earlier_version
296 * Return non-zero if the spa version is less than requested version.
299 zfs_earlier_version(const char *name
, int version
)
303 if (spa_open(name
, &spa
, FTAG
) == 0) {
304 if (spa_version(spa
) < version
) {
305 spa_close(spa
, FTAG
);
308 spa_close(spa
, FTAG
);
314 * zpl_earlier_version
316 * Return TRUE if the ZPL version is less than requested version.
319 zpl_earlier_version(const char *name
, int version
)
322 boolean_t rc
= B_TRUE
;
324 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
327 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
328 dmu_objset_rele(os
, FTAG
);
331 /* XXX reading from non-owned objset */
332 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
333 rc
= zplversion
< version
;
334 dmu_objset_rele(os
, FTAG
);
340 zfs_log_history(zfs_cmd_t
*zc
)
345 if ((buf
= history_str_get(zc
)) == NULL
)
348 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
349 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
350 (void) spa_history_log(spa
, buf
);
351 spa_close(spa
, FTAG
);
353 history_str_free(buf
);
357 * Policy for top-level read operations (list pools). Requires no privileges,
358 * and can be used in the local zone, as there is no associated dataset.
362 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
368 * Policy for dataset read operations (list children, get statistics). Requires
369 * no privileges, but must be visible in the local zone.
373 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
375 if (INGLOBALZONE(curproc
) ||
376 zone_dataset_visible(zc
->zc_name
, NULL
))
383 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
388 * The dataset must be visible by this zone -- check this first
389 * so they don't see EPERM on something they shouldn't know about.
391 if (!INGLOBALZONE(curproc
) &&
392 !zone_dataset_visible(dataset
, &writable
))
395 if (INGLOBALZONE(curproc
)) {
397 * If the fs is zoned, only root can access it from the
400 if (secpolicy_zfs(cr
) && zoned
)
404 * If we are in a local zone, the 'zoned' property must be set.
409 /* must be writable by this zone */
417 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
421 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
424 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
428 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
432 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
435 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
439 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
440 const char *perm
, cred_t
*cr
)
444 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
446 error
= secpolicy_zfs(cr
);
448 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
454 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
460 error
= dsl_pool_hold(name
, FTAG
, &dp
);
464 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
466 dsl_pool_rele(dp
, FTAG
);
470 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
472 dsl_dataset_rele(ds
, FTAG
);
473 dsl_pool_rele(dp
, FTAG
);
478 * Policy for setting the security label property.
480 * Returns 0 for success, non-zero for access and other errors.
483 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
486 char ds_hexsl
[MAXNAMELEN
];
487 bslabel_t ds_sl
, new_sl
;
488 boolean_t new_default
= FALSE
;
490 int needed_priv
= -1;
493 /* First get the existing dataset label. */
494 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
495 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
499 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
502 /* The label must be translatable */
503 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
507 * In a non-global zone, disallow attempts to set a label that
508 * doesn't match that of the zone; otherwise no other checks
511 if (!INGLOBALZONE(curproc
)) {
512 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
518 * For global-zone datasets (i.e., those whose zoned property is
519 * "off", verify that the specified new label is valid for the
522 if (dsl_prop_get_integer(name
,
523 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
526 if (zfs_check_global_label(name
, strval
) != 0)
531 * If the existing dataset label is nondefault, check if the
532 * dataset is mounted (label cannot be changed while mounted).
533 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
534 * mounted (or isn't a dataset, doesn't exist, ...).
536 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
538 static char *setsl_tag
= "setsl_tag";
541 * Try to own the dataset; abort if there is any error,
542 * (e.g., already mounted, in use, or other error).
544 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
,
549 dmu_objset_disown(os
, setsl_tag
);
552 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
556 if (hexstr_to_label(strval
, &new_sl
) != 0)
559 if (blstrictdom(&ds_sl
, &new_sl
))
560 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
561 else if (blstrictdom(&new_sl
, &ds_sl
))
562 needed_priv
= PRIV_FILE_UPGRADE_SL
;
564 /* dataset currently has a default label */
566 needed_priv
= PRIV_FILE_UPGRADE_SL
;
570 if (needed_priv
!= -1)
571 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
575 #endif /* HAVE_MLSLABEL */
579 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
585 * Check permissions for special properties.
592 * Disallow setting of 'zoned' from within a local zone.
594 if (!INGLOBALZONE(curproc
))
599 if (!INGLOBALZONE(curproc
)) {
601 char setpoint
[MAXNAMELEN
];
603 * Unprivileged users are allowed to modify the
604 * quota on things *under* (ie. contained by)
605 * the thing they own.
607 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
610 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
615 case ZFS_PROP_MLSLABEL
:
616 if (!is_system_labeled())
619 if (nvpair_value_string(propval
, &strval
) == 0) {
622 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
629 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
634 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
638 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
643 * permission to set permissions will be evaluated later in
644 * dsl_deleg_can_allow()
651 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
653 return (zfs_secpolicy_write_perms(zc
->zc_name
,
654 ZFS_DELEG_PERM_ROLLBACK
, cr
));
659 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
667 * Generate the current snapshot name from the given objsetid, then
668 * use that name for the secpolicy/zone checks.
670 cp
= strchr(zc
->zc_name
, '@');
673 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
677 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
679 dsl_pool_rele(dp
, FTAG
);
683 dsl_dataset_name(ds
, zc
->zc_name
);
685 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
686 ZFS_DELEG_PERM_SEND
, cr
);
687 dsl_dataset_rele(ds
, FTAG
);
688 dsl_pool_rele(dp
, FTAG
);
695 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
697 return (zfs_secpolicy_write_perms(zc
->zc_name
,
698 ZFS_DELEG_PERM_SEND
, cr
));
701 #ifdef HAVE_SMB_SHARE
704 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
709 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
710 NO_FOLLOW
, NULL
, &vp
)) != 0)
713 /* Now make sure mntpnt and dataset are ZFS */
715 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
716 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
717 zc
->zc_name
) != 0)) {
723 return (dsl_deleg_access(zc
->zc_name
,
724 ZFS_DELEG_PERM_SHARE
, cr
));
726 #endif /* HAVE_SMB_SHARE */
729 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
731 #ifdef HAVE_SMB_SHARE
732 if (!INGLOBALZONE(curproc
))
735 if (secpolicy_nfs(cr
) == 0) {
738 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
742 #endif /* HAVE_SMB_SHARE */
746 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
748 #ifdef HAVE_SMB_SHARE
749 if (!INGLOBALZONE(curproc
))
752 if (secpolicy_smb(cr
) == 0) {
755 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
759 #endif /* HAVE_SMB_SHARE */
763 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
768 * Remove the @bla or /bla from the end of the name to get the parent.
770 (void) strncpy(parent
, datasetname
, parentsize
);
771 cp
= strrchr(parent
, '@');
775 cp
= strrchr(parent
, '/');
785 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
789 if ((error
= zfs_secpolicy_write_perms(name
,
790 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
793 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
798 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
800 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
804 * Destroying snapshots with delegated permissions requires
805 * descendant mount and destroy permissions.
809 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
812 nvpair_t
*pair
, *nextpair
;
815 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
817 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
822 error
= dsl_pool_hold(nvpair_name(pair
), FTAG
, &dp
);
825 nextpair
= nvlist_next_nvpair(snaps
, pair
);
826 error
= dsl_dataset_hold(dp
, nvpair_name(pair
), FTAG
, &ds
);
828 dsl_dataset_rele(ds
, FTAG
);
829 dsl_pool_rele(dp
, FTAG
);
832 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
),
834 } else if (error
== ENOENT
) {
836 * Ignore any snapshots that don't exist (we consider
837 * them "already destroyed"). Remove the name from the
838 * nvl here in case the snapshot is created between
839 * now and when we try to destroy it (in which case
840 * we don't want to destroy it since we haven't
841 * checked for permission).
843 fnvlist_remove_nvpair(snaps
, pair
);
854 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
856 char parentname
[MAXNAMELEN
];
859 if ((error
= zfs_secpolicy_write_perms(from
,
860 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
863 if ((error
= zfs_secpolicy_write_perms(from
,
864 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
867 if ((error
= zfs_get_parent(to
, parentname
,
868 sizeof (parentname
))) != 0)
871 if ((error
= zfs_secpolicy_write_perms(parentname
,
872 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
875 if ((error
= zfs_secpolicy_write_perms(parentname
,
876 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
884 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
886 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
891 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
894 dsl_dataset_t
*clone
;
897 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
898 ZFS_DELEG_PERM_PROMOTE
, cr
);
902 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
906 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
909 char parentname
[MAXNAMELEN
];
910 dsl_dataset_t
*origin
= NULL
;
914 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
915 dd
->dd_phys
->dd_origin_obj
, FTAG
, &origin
);
917 dsl_dataset_rele(clone
, FTAG
);
918 dsl_pool_rele(dp
, FTAG
);
922 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
923 ZFS_DELEG_PERM_MOUNT
, cr
);
925 dsl_dataset_name(origin
, parentname
);
927 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
928 ZFS_DELEG_PERM_PROMOTE
, cr
);
930 dsl_dataset_rele(clone
, FTAG
);
931 dsl_dataset_rele(origin
, FTAG
);
933 dsl_pool_rele(dp
, FTAG
);
939 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
943 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
944 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
947 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
948 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
951 return (zfs_secpolicy_write_perms(zc
->zc_name
,
952 ZFS_DELEG_PERM_CREATE
, cr
));
956 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
958 return (zfs_secpolicy_write_perms(name
,
959 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
963 * Check for permission to create each snapshot in the nvlist.
967 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
973 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
975 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
976 pair
= nvlist_next_nvpair(snaps
, pair
)) {
977 char *name
= nvpair_name(pair
);
978 char *atp
= strchr(name
, '@');
985 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
995 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
998 * Even root must have a proper TSD so that we know what pool
1001 if (tsd_get(zfs_allow_log_key
) == NULL
)
1007 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1009 char parentname
[MAXNAMELEN
];
1013 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1014 sizeof (parentname
))) != 0)
1017 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1018 (error
= zfs_secpolicy_write_perms(origin
,
1019 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1022 if ((error
= zfs_secpolicy_write_perms(parentname
,
1023 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1026 return (zfs_secpolicy_write_perms(parentname
,
1027 ZFS_DELEG_PERM_MOUNT
, cr
));
1031 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1032 * SYS_CONFIG privilege, which is not available in a local zone.
1036 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1038 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1045 * Policy for object to name lookups.
1049 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1053 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1056 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1061 * Policy for fault injection. Requires all privileges.
1065 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1067 return (secpolicy_zinject(cr
));
1072 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1074 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1076 if (prop
== ZPROP_INVAL
) {
1077 if (!zfs_prop_user(zc
->zc_value
))
1079 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1080 ZFS_DELEG_PERM_USERPROP
, cr
));
1082 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1088 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1090 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1094 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1097 if (zc
->zc_value
[0] == 0) {
1099 * They are asking about a posix uid/gid. If it's
1100 * themself, allow it.
1102 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1103 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
1104 if (zc
->zc_guid
== crgetuid(cr
))
1107 if (groupmember(zc
->zc_guid
, cr
))
1112 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1113 userquota_perms
[zc
->zc_objset_type
], cr
));
1117 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1119 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1123 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1126 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1127 userquota_perms
[zc
->zc_objset_type
], cr
));
1132 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1134 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1140 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1146 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1150 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1151 pair
= nvlist_next_nvpair(holds
, pair
)) {
1152 char fsname
[MAXNAMELEN
];
1153 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1156 error
= zfs_secpolicy_write_perms(fsname
,
1157 ZFS_DELEG_PERM_HOLD
, cr
);
1166 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1171 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1172 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1173 char fsname
[MAXNAMELEN
];
1174 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1177 error
= zfs_secpolicy_write_perms(fsname
,
1178 ZFS_DELEG_PERM_RELEASE
, cr
);
1186 * Policy for allowing temporary snapshots to be taken or released
1189 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1192 * A temporary snapshot is the same as a snapshot,
1193 * hold, destroy and release all rolled into one.
1194 * Delegated diff alone is sufficient that we allow this.
1198 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1199 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1202 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1204 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1206 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1208 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1213 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1216 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1220 nvlist_t
*list
= NULL
;
1223 * Read in and unpack the user-supplied nvlist.
1228 packed
= kmem_alloc(size
, KM_SLEEP
| KM_NODEBUG
);
1230 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1232 kmem_free(packed
, size
);
1236 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1237 kmem_free(packed
, size
);
1241 kmem_free(packed
, size
);
1248 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1249 * Entries will be removed from the end of the nvlist, and one int32 entry
1250 * named "N_MORE_ERRORS" will be added indicating how many entries were
1254 nvlist_smush(nvlist_t
*errors
, size_t max
)
1258 size
= fnvlist_size(errors
);
1261 nvpair_t
*more_errors
;
1267 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1268 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1271 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1273 fnvlist_remove_nvpair(errors
, pair
);
1275 size
= fnvlist_size(errors
);
1276 } while (size
> max
);
1278 fnvlist_remove_nvpair(errors
, more_errors
);
1279 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1280 ASSERT3U(fnvlist_size(errors
), <=, max
);
1287 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1289 char *packed
= NULL
;
1293 size
= fnvlist_size(nvl
);
1295 if (size
> zc
->zc_nvlist_dst_size
) {
1298 packed
= fnvlist_pack(nvl
, &size
);
1299 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1300 size
, zc
->zc_iflags
) != 0)
1302 fnvlist_pack_free(packed
, size
);
1305 zc
->zc_nvlist_dst_size
= size
;
1306 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1311 get_zfs_sb(const char *dsname
, zfs_sb_t
**zsbp
)
1316 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1319 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1320 dmu_objset_rele(os
, FTAG
);
1324 mutex_enter(&os
->os_user_ptr_lock
);
1325 *zsbp
= dmu_objset_get_user(os
);
1326 if (*zsbp
&& (*zsbp
)->z_sb
) {
1327 atomic_inc(&((*zsbp
)->z_sb
->s_active
));
1331 mutex_exit(&os
->os_user_ptr_lock
);
1332 dmu_objset_rele(os
, FTAG
);
1337 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1338 * case its z_sb will be NULL, and it will be opened as the owner.
1339 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1340 * which prevents all inode ops from running.
1343 zfs_sb_hold(const char *name
, void *tag
, zfs_sb_t
**zsbp
, boolean_t writer
)
1347 if (get_zfs_sb(name
, zsbp
) != 0)
1348 error
= zfs_sb_create(name
, zsbp
);
1350 rrw_enter(&(*zsbp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1352 if ((*zsbp
)->z_unmounted
) {
1354 * XXX we could probably try again, since the unmounting
1355 * thread should be just about to disassociate the
1356 * objset from the zfsvfs.
1358 rrw_exit(&(*zsbp
)->z_teardown_lock
, tag
);
1366 zfs_sb_rele(zfs_sb_t
*zsb
, void *tag
)
1368 rrw_exit(&zsb
->z_teardown_lock
, tag
);
1371 deactivate_super(zsb
->z_sb
);
1373 dmu_objset_disown(zsb
->z_os
, zsb
);
1379 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1382 nvlist_t
*config
, *props
= NULL
;
1383 nvlist_t
*rootprops
= NULL
;
1384 nvlist_t
*zplprops
= NULL
;
1386 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1387 zc
->zc_iflags
, &config
)))
1390 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1391 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1392 zc
->zc_iflags
, &props
))) {
1393 nvlist_free(config
);
1398 nvlist_t
*nvl
= NULL
;
1399 uint64_t version
= SPA_VERSION
;
1401 (void) nvlist_lookup_uint64(props
,
1402 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1403 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1405 goto pool_props_bad
;
1407 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1409 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1411 nvlist_free(config
);
1415 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1417 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1418 error
= zfs_fill_zplprops_root(version
, rootprops
,
1421 goto pool_props_bad
;
1424 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1427 * Set the remaining root properties
1429 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1430 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1431 (void) spa_destroy(zc
->zc_name
);
1434 nvlist_free(rootprops
);
1435 nvlist_free(zplprops
);
1436 nvlist_free(config
);
1443 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1446 zfs_log_history(zc
);
1447 error
= spa_destroy(zc
->zc_name
);
1449 zvol_remove_minors(zc
->zc_name
);
1454 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1456 nvlist_t
*config
, *props
= NULL
;
1460 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1461 zc
->zc_iflags
, &config
)) != 0)
1464 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1465 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1466 zc
->zc_iflags
, &props
))) {
1467 nvlist_free(config
);
1471 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1472 guid
!= zc
->zc_guid
)
1475 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1477 if (zc
->zc_nvlist_dst
!= 0) {
1480 if ((err
= put_nvlist(zc
, config
)) != 0)
1484 nvlist_free(config
);
1493 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1496 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1497 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1499 zfs_log_history(zc
);
1500 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1502 zvol_remove_minors(zc
->zc_name
);
1507 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1512 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1515 error
= put_nvlist(zc
, configs
);
1517 nvlist_free(configs
);
1524 * zc_name name of the pool
1527 * zc_cookie real errno
1528 * zc_nvlist_dst config nvlist
1529 * zc_nvlist_dst_size size of config nvlist
1532 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1538 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1539 sizeof (zc
->zc_value
));
1541 if (config
!= NULL
) {
1542 ret
= put_nvlist(zc
, config
);
1543 nvlist_free(config
);
1546 * The config may be present even if 'error' is non-zero.
1547 * In this case we return success, and preserve the real errno
1550 zc
->zc_cookie
= error
;
1559 * Try to import the given pool, returning pool stats as appropriate so that
1560 * user land knows which devices are available and overall pool health.
1563 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1565 nvlist_t
*tryconfig
, *config
;
1568 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1569 zc
->zc_iflags
, &tryconfig
)) != 0)
1572 config
= spa_tryimport(tryconfig
);
1574 nvlist_free(tryconfig
);
1579 error
= put_nvlist(zc
, config
);
1580 nvlist_free(config
);
1587 * zc_name name of the pool
1588 * zc_cookie scan func (pool_scan_func_t)
1591 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1596 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1599 if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1600 error
= spa_scan_stop(spa
);
1602 error
= spa_scan(spa
, zc
->zc_cookie
);
1604 spa_close(spa
, FTAG
);
1610 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1615 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1618 spa_close(spa
, FTAG
);
1624 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1629 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1632 if (zc
->zc_cookie
< spa_version(spa
) ||
1633 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1634 spa_close(spa
, FTAG
);
1638 spa_upgrade(spa
, zc
->zc_cookie
);
1639 spa_close(spa
, FTAG
);
1645 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1652 if ((size
= zc
->zc_history_len
) == 0)
1655 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1658 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1659 spa_close(spa
, FTAG
);
1663 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1664 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1665 &zc
->zc_history_len
, hist_buf
)) == 0) {
1666 error
= ddi_copyout(hist_buf
,
1667 (void *)(uintptr_t)zc
->zc_history
,
1668 zc
->zc_history_len
, zc
->zc_iflags
);
1671 spa_close(spa
, FTAG
);
1672 vmem_free(hist_buf
, size
);
1677 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1682 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1684 error
= spa_change_guid(spa
);
1685 spa_close(spa
, FTAG
);
1691 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1693 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1698 * zc_name name of filesystem
1699 * zc_obj object to find
1702 * zc_value name of object
1705 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1710 /* XXX reading from objset not owned */
1711 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1713 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1714 dmu_objset_rele(os
, FTAG
);
1717 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1718 sizeof (zc
->zc_value
));
1719 dmu_objset_rele(os
, FTAG
);
1726 * zc_name name of filesystem
1727 * zc_obj object to find
1730 * zc_stat stats on object
1731 * zc_value path to object
1734 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1739 /* XXX reading from objset not owned */
1740 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1742 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1743 dmu_objset_rele(os
, FTAG
);
1746 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1747 sizeof (zc
->zc_value
));
1748 dmu_objset_rele(os
, FTAG
);
1754 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1758 nvlist_t
*config
, **l2cache
, **spares
;
1759 uint_t nl2cache
= 0, nspares
= 0;
1761 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1765 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1766 zc
->zc_iflags
, &config
);
1767 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_L2CACHE
,
1768 &l2cache
, &nl2cache
);
1770 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_SPARES
,
1774 * A root pool with concatenated devices is not supported.
1775 * Thus, can not add a device to a root pool.
1777 * Intent log device can not be added to a rootpool because
1778 * during mountroot, zil is replayed, a seperated log device
1779 * can not be accessed during the mountroot time.
1781 * l2cache and spare devices are ok to be added to a rootpool.
1783 if (spa_bootfs(spa
) != 0 && nl2cache
== 0 && nspares
== 0) {
1784 nvlist_free(config
);
1785 spa_close(spa
, FTAG
);
1790 error
= spa_vdev_add(spa
, config
);
1791 nvlist_free(config
);
1793 spa_close(spa
, FTAG
);
1799 * zc_name name of the pool
1800 * zc_nvlist_conf nvlist of devices to remove
1801 * zc_cookie to stop the remove?
1804 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1809 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1812 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1813 spa_close(spa
, FTAG
);
1818 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1822 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1824 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1826 switch (zc
->zc_cookie
) {
1827 case VDEV_STATE_ONLINE
:
1828 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1831 case VDEV_STATE_OFFLINE
:
1832 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1835 case VDEV_STATE_FAULTED
:
1836 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1837 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1838 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1840 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1843 case VDEV_STATE_DEGRADED
:
1844 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1845 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1846 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1848 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1854 zc
->zc_cookie
= newstate
;
1855 spa_close(spa
, FTAG
);
1860 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1863 int replacing
= zc
->zc_cookie
;
1867 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1870 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1871 zc
->zc_iflags
, &config
)) == 0) {
1872 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1873 nvlist_free(config
);
1876 spa_close(spa
, FTAG
);
1881 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1886 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1889 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1891 spa_close(spa
, FTAG
);
1896 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1899 nvlist_t
*config
, *props
= NULL
;
1901 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1903 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1906 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1907 zc
->zc_iflags
, &config
))) {
1908 spa_close(spa
, FTAG
);
1912 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1913 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1914 zc
->zc_iflags
, &props
))) {
1915 spa_close(spa
, FTAG
);
1916 nvlist_free(config
);
1920 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1922 spa_close(spa
, FTAG
);
1924 nvlist_free(config
);
1931 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1934 char *path
= zc
->zc_value
;
1935 uint64_t guid
= zc
->zc_guid
;
1938 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1942 error
= spa_vdev_setpath(spa
, guid
, path
);
1943 spa_close(spa
, FTAG
);
1948 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1951 char *fru
= zc
->zc_value
;
1952 uint64_t guid
= zc
->zc_guid
;
1955 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1959 error
= spa_vdev_setfru(spa
, guid
, fru
);
1960 spa_close(spa
, FTAG
);
1965 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
1970 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1972 if (zc
->zc_nvlist_dst
!= 0 &&
1973 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
1974 dmu_objset_stats(os
, nv
);
1976 * NB: zvol_get_stats() will read the objset contents,
1977 * which we aren't supposed to do with a
1978 * DS_MODE_USER hold, because it could be
1979 * inconsistent. So this is a bit of a workaround...
1980 * XXX reading with out owning
1982 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
1983 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
1984 error
= zvol_get_stats(os
, nv
);
1990 error
= put_nvlist(zc
, nv
);
1999 * zc_name name of filesystem
2000 * zc_nvlist_dst_size size of buffer for property nvlist
2003 * zc_objset_stats stats
2004 * zc_nvlist_dst property nvlist
2005 * zc_nvlist_dst_size size of property nvlist
2008 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2013 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2015 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2016 dmu_objset_rele(os
, FTAG
);
2024 * zc_name name of filesystem
2025 * zc_nvlist_dst_size size of buffer for property nvlist
2028 * zc_nvlist_dst received property nvlist
2029 * zc_nvlist_dst_size size of received property nvlist
2031 * Gets received properties (distinct from local properties on or after
2032 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2033 * local property values.
2036 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2042 * Without this check, we would return local property values if the
2043 * caller has not already received properties on or after
2044 * SPA_VERSION_RECVD_PROPS.
2046 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2049 if (zc
->zc_nvlist_dst
!= 0 &&
2050 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2051 error
= put_nvlist(zc
, nv
);
2059 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2065 * zfs_get_zplprop() will either find a value or give us
2066 * the default value (if there is one).
2068 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2070 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2076 * zc_name name of filesystem
2077 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2080 * zc_nvlist_dst zpl property nvlist
2081 * zc_nvlist_dst_size size of zpl property nvlist
2084 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2089 /* XXX reading without owning */
2090 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2093 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2096 * NB: nvl_add_zplprop() will read the objset contents,
2097 * which we aren't supposed to do with a DS_MODE_USER
2098 * hold, because it could be inconsistent.
2100 if (zc
->zc_nvlist_dst
!= 0 &&
2101 !zc
->zc_objset_stats
.dds_inconsistent
&&
2102 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2105 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2106 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2107 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2108 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2109 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2110 err
= put_nvlist(zc
, nv
);
2115 dmu_objset_rele(os
, FTAG
);
2120 dataset_name_hidden(const char *name
)
2123 * Skip over datasets that are not visible in this zone,
2124 * internal datasets (which have a $ in their name), and
2125 * temporary datasets (which have a % in their name).
2127 if (strchr(name
, '$') != NULL
)
2129 if (strchr(name
, '%') != NULL
)
2131 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2138 * zc_name name of filesystem
2139 * zc_cookie zap cursor
2140 * zc_nvlist_dst_size size of buffer for property nvlist
2143 * zc_name name of next filesystem
2144 * zc_cookie zap cursor
2145 * zc_objset_stats stats
2146 * zc_nvlist_dst property nvlist
2147 * zc_nvlist_dst_size size of property nvlist
2150 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2155 size_t orig_len
= strlen(zc
->zc_name
);
2158 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2159 if (error
== ENOENT
)
2164 p
= strrchr(zc
->zc_name
, '/');
2165 if (p
== NULL
|| p
[1] != '\0')
2166 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2167 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2170 error
= dmu_dir_list_next(os
,
2171 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2172 NULL
, &zc
->zc_cookie
);
2173 if (error
== ENOENT
)
2175 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2176 dmu_objset_rele(os
, FTAG
);
2179 * If it's an internal dataset (ie. with a '$' in its name),
2180 * don't try to get stats for it, otherwise we'll return ENOENT.
2182 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2183 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2184 if (error
== ENOENT
) {
2185 /* We lost a race with destroy, get the next one. */
2186 zc
->zc_name
[orig_len
] = '\0';
2195 * zc_name name of filesystem
2196 * zc_cookie zap cursor
2197 * zc_nvlist_dst_size size of buffer for property nvlist
2200 * zc_name name of next snapshot
2201 * zc_objset_stats stats
2202 * zc_nvlist_dst property nvlist
2203 * zc_nvlist_dst_size size of property nvlist
2206 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2211 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2213 return (error
== ENOENT
? ESRCH
: error
);
2217 * A dataset name of maximum length cannot have any snapshots,
2218 * so exit immediately.
2220 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >= MAXNAMELEN
) {
2221 dmu_objset_rele(os
, FTAG
);
2225 error
= dmu_snapshot_list_next(os
,
2226 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2227 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2230 if (error
== 0 && !zc
->zc_simple
) {
2232 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2234 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2238 error
= dmu_objset_from_ds(ds
, &ossnap
);
2240 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2241 dsl_dataset_rele(ds
, FTAG
);
2243 } else if (error
== ENOENT
) {
2247 dmu_objset_rele(os
, FTAG
);
2248 /* if we failed, undo the @ that we tacked on to zc_name */
2250 *strchr(zc
->zc_name
, '@') = '\0';
2255 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2257 const char *propname
= nvpair_name(pair
);
2259 unsigned int vallen
;
2262 zfs_userquota_prop_t type
;
2268 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2270 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2271 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2277 * A correctly constructed propname is encoded as
2278 * userquota@<rid>-<domain>.
2280 if ((dash
= strchr(propname
, '-')) == NULL
||
2281 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2290 err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
2292 err
= zfs_set_userquota(zsb
, type
, domain
, rid
, quota
);
2293 zfs_sb_rele(zsb
, FTAG
);
2300 * If the named property is one that has a special function to set its value,
2301 * return 0 on success and a positive error code on failure; otherwise if it is
2302 * not one of the special properties handled by this function, return -1.
2304 * XXX: It would be better for callers of the property interface if we handled
2305 * these special cases in dsl_prop.c (in the dsl layer).
2308 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2311 const char *propname
= nvpair_name(pair
);
2312 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2316 if (prop
== ZPROP_INVAL
) {
2317 if (zfs_prop_userquota(propname
))
2318 return (zfs_prop_set_userquota(dsname
, pair
));
2322 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2324 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2325 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2329 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2332 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2335 case ZFS_PROP_QUOTA
:
2336 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2338 case ZFS_PROP_REFQUOTA
:
2339 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2341 case ZFS_PROP_RESERVATION
:
2342 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2344 case ZFS_PROP_REFRESERVATION
:
2345 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2347 case ZFS_PROP_VOLSIZE
:
2348 err
= zvol_set_volsize(dsname
, intval
);
2350 case ZFS_PROP_SNAPDEV
:
2351 err
= zvol_set_snapdev(dsname
, intval
);
2353 case ZFS_PROP_VERSION
:
2357 if ((err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_TRUE
)) != 0)
2360 err
= zfs_set_version(zsb
, intval
);
2361 zfs_sb_rele(zsb
, FTAG
);
2363 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2366 zc
= kmem_zalloc(sizeof (zfs_cmd_t
),
2367 KM_SLEEP
| KM_NODEBUG
);
2368 (void) strcpy(zc
->zc_name
, dsname
);
2369 (void) zfs_ioc_userspace_upgrade(zc
);
2370 kmem_free(zc
, sizeof (zfs_cmd_t
));
2374 case ZFS_PROP_COMPRESSION
:
2376 if (intval
== ZIO_COMPRESS_LZ4
) {
2377 zfeature_info_t
*feature
=
2378 &spa_feature_table
[SPA_FEATURE_LZ4_COMPRESS
];
2381 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
2385 * Setting the LZ4 compression algorithm activates
2388 if (!spa_feature_is_active(spa
, feature
)) {
2389 if ((err
= zfs_prop_activate_feature(spa
,
2391 spa_close(spa
, FTAG
);
2396 spa_close(spa
, FTAG
);
2399 * We still want the default set action to be performed in the
2400 * caller, we only performed zfeature settings here.
2414 * This function is best effort. If it fails to set any of the given properties,
2415 * it continues to set as many as it can and returns the last error
2416 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2417 * with the list of names of all the properties that failed along with the
2418 * corresponding error numbers.
2420 * If every property is set successfully, zero is returned and errlist is not
2424 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2433 nvlist_t
*genericnvl
= fnvlist_alloc();
2434 nvlist_t
*retrynvl
= fnvlist_alloc();
2437 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2438 const char *propname
= nvpair_name(pair
);
2439 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2442 /* decode the property value */
2444 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2446 attrs
= fnvpair_value_nvlist(pair
);
2447 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2452 /* Validate value type */
2453 if (err
== 0 && prop
== ZPROP_INVAL
) {
2454 if (zfs_prop_user(propname
)) {
2455 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2457 } else if (zfs_prop_userquota(propname
)) {
2458 if (nvpair_type(propval
) !=
2459 DATA_TYPE_UINT64_ARRAY
)
2464 } else if (err
== 0) {
2465 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2466 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2468 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2471 intval
= fnvpair_value_uint64(propval
);
2473 switch (zfs_prop_get_type(prop
)) {
2474 case PROP_TYPE_NUMBER
:
2476 case PROP_TYPE_STRING
:
2479 case PROP_TYPE_INDEX
:
2480 if (zfs_prop_index_to_string(prop
,
2481 intval
, &unused
) != 0)
2486 "unknown property type");
2493 /* Validate permissions */
2495 err
= zfs_check_settable(dsname
, pair
, CRED());
2498 err
= zfs_prop_set_special(dsname
, source
, pair
);
2501 * For better performance we build up a list of
2502 * properties to set in a single transaction.
2504 err
= nvlist_add_nvpair(genericnvl
, pair
);
2505 } else if (err
!= 0 && nvl
!= retrynvl
) {
2507 * This may be a spurious error caused by
2508 * receiving quota and reservation out of order.
2509 * Try again in a second pass.
2511 err
= nvlist_add_nvpair(retrynvl
, pair
);
2516 if (errlist
!= NULL
)
2517 fnvlist_add_int32(errlist
, propname
, err
);
2522 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2527 if (!nvlist_empty(genericnvl
) &&
2528 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2530 * If this fails, we still want to set as many properties as we
2531 * can, so try setting them individually.
2534 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2535 const char *propname
= nvpair_name(pair
);
2539 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2541 attrs
= fnvpair_value_nvlist(pair
);
2542 propval
= fnvlist_lookup_nvpair(attrs
,
2546 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2547 strval
= fnvpair_value_string(propval
);
2548 err
= dsl_prop_set_string(dsname
, propname
,
2551 intval
= fnvpair_value_uint64(propval
);
2552 err
= dsl_prop_set_int(dsname
, propname
, source
,
2557 if (errlist
!= NULL
) {
2558 fnvlist_add_int32(errlist
, propname
,
2565 nvlist_free(genericnvl
);
2566 nvlist_free(retrynvl
);
2572 * Check that all the properties are valid user properties.
2575 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2577 nvpair_t
*pair
= NULL
;
2580 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2581 const char *propname
= nvpair_name(pair
);
2584 if (!zfs_prop_user(propname
) ||
2585 nvpair_type(pair
) != DATA_TYPE_STRING
)
2588 if ((error
= zfs_secpolicy_write_perms(fsname
,
2589 ZFS_DELEG_PERM_USERPROP
, CRED())))
2592 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2593 return (ENAMETOOLONG
);
2595 VERIFY(nvpair_value_string(pair
, &valstr
) == 0);
2596 if (strlen(valstr
) >= ZAP_MAXVALUELEN
)
2603 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2607 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2610 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2611 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2614 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2619 clear_received_props(const char *dsname
, nvlist_t
*props
,
2623 nvlist_t
*cleared_props
= NULL
;
2624 props_skip(props
, skipped
, &cleared_props
);
2625 if (!nvlist_empty(cleared_props
)) {
2627 * Acts on local properties until the dataset has received
2628 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2630 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2631 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2632 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2634 nvlist_free(cleared_props
);
2640 * zc_name name of filesystem
2641 * zc_value name of property to set
2642 * zc_nvlist_src{_size} nvlist of properties to apply
2643 * zc_cookie received properties flag
2646 * zc_nvlist_dst{_size} error for each unapplied received property
2649 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2652 boolean_t received
= zc
->zc_cookie
;
2653 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2658 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2659 zc
->zc_iflags
, &nvl
)) != 0)
2663 nvlist_t
*origprops
;
2665 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2666 (void) clear_received_props(zc
->zc_name
,
2668 nvlist_free(origprops
);
2671 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2674 errors
= fnvlist_alloc();
2676 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2678 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2679 (void) put_nvlist(zc
, errors
);
2682 nvlist_free(errors
);
2689 * zc_name name of filesystem
2690 * zc_value name of property to inherit
2691 * zc_cookie revert to received value if TRUE
2696 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2698 const char *propname
= zc
->zc_value
;
2699 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2700 boolean_t received
= zc
->zc_cookie
;
2701 zprop_source_t source
= (received
2702 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2703 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2712 * zfs_prop_set_special() expects properties in the form of an
2713 * nvpair with type info.
2715 if (prop
== ZPROP_INVAL
) {
2716 if (!zfs_prop_user(propname
))
2719 type
= PROP_TYPE_STRING
;
2720 } else if (prop
== ZFS_PROP_VOLSIZE
||
2721 prop
== ZFS_PROP_VERSION
) {
2724 type
= zfs_prop_get_type(prop
);
2727 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2730 case PROP_TYPE_STRING
:
2731 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2733 case PROP_TYPE_NUMBER
:
2734 case PROP_TYPE_INDEX
:
2735 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2742 pair
= nvlist_next_nvpair(dummy
, NULL
);
2743 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2746 return (err
); /* special property already handled */
2749 * Only check this in the non-received case. We want to allow
2750 * 'inherit -S' to revert non-inheritable properties like quota
2751 * and reservation to the received or default values even though
2752 * they are not considered inheritable.
2754 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2758 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2759 return (dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
, source
));
2763 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2770 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2771 zc
->zc_iflags
, &props
)))
2775 * If the only property is the configfile, then just do a spa_lookup()
2776 * to handle the faulted case.
2778 pair
= nvlist_next_nvpair(props
, NULL
);
2779 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2780 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2781 nvlist_next_nvpair(props
, pair
) == NULL
) {
2782 mutex_enter(&spa_namespace_lock
);
2783 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2784 spa_configfile_set(spa
, props
, B_FALSE
);
2785 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2787 mutex_exit(&spa_namespace_lock
);
2794 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2799 error
= spa_prop_set(spa
, props
);
2802 spa_close(spa
, FTAG
);
2808 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2812 nvlist_t
*nvp
= NULL
;
2814 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2816 * If the pool is faulted, there may be properties we can still
2817 * get (such as altroot and cachefile), so attempt to get them
2820 mutex_enter(&spa_namespace_lock
);
2821 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2822 error
= spa_prop_get(spa
, &nvp
);
2823 mutex_exit(&spa_namespace_lock
);
2825 error
= spa_prop_get(spa
, &nvp
);
2826 spa_close(spa
, FTAG
);
2829 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2830 error
= put_nvlist(zc
, nvp
);
2840 * zc_name name of volume
2845 zfs_ioc_create_minor(zfs_cmd_t
*zc
)
2847 return (zvol_create_minor(zc
->zc_name
));
2852 * zc_name name of volume
2857 zfs_ioc_remove_minor(zfs_cmd_t
*zc
)
2859 return (zvol_remove_minor(zc
->zc_name
));
2864 * zc_name name of filesystem
2865 * zc_nvlist_src{_size} nvlist of delegated permissions
2866 * zc_perm_action allow/unallow flag
2871 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2874 nvlist_t
*fsaclnv
= NULL
;
2876 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2877 zc
->zc_iflags
, &fsaclnv
)) != 0)
2881 * Verify nvlist is constructed correctly
2883 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2884 nvlist_free(fsaclnv
);
2889 * If we don't have PRIV_SYS_MOUNT, then validate
2890 * that user is allowed to hand out each permission in
2894 error
= secpolicy_zfs(CRED());
2896 if (zc
->zc_perm_action
== B_FALSE
) {
2897 error
= dsl_deleg_can_allow(zc
->zc_name
,
2900 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2906 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2908 nvlist_free(fsaclnv
);
2914 * zc_name name of filesystem
2917 * zc_nvlist_src{_size} nvlist of delegated permissions
2920 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2925 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2926 error
= put_nvlist(zc
, nvp
);
2935 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2937 zfs_creat_t
*zct
= arg
;
2939 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2942 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2946 * createprops list of properties requested by creator
2947 * default_zplver zpl version to use if unspecified in createprops
2948 * fuids_ok fuids allowed in this version of the spa?
2949 * os parent objset pointer (NULL if root fs)
2952 * zplprops values for the zplprops we attach to the master node object
2953 * is_ci true if requested file system will be purely case-insensitive
2955 * Determine the settings for utf8only, normalization and
2956 * casesensitivity. Specific values may have been requested by the
2957 * creator and/or we can inherit values from the parent dataset. If
2958 * the file system is of too early a vintage, a creator can not
2959 * request settings for these properties, even if the requested
2960 * setting is the default value. We don't actually want to create dsl
2961 * properties for these, so remove them from the source nvlist after
2965 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2966 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2967 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2969 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2970 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2971 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2974 ASSERT(zplprops
!= NULL
);
2977 * Pull out creator prop choices, if any.
2980 (void) nvlist_lookup_uint64(createprops
,
2981 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2982 (void) nvlist_lookup_uint64(createprops
,
2983 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2984 (void) nvlist_remove_all(createprops
,
2985 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2986 (void) nvlist_lookup_uint64(createprops
,
2987 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2988 (void) nvlist_remove_all(createprops
,
2989 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2990 (void) nvlist_lookup_uint64(createprops
,
2991 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2992 (void) nvlist_remove_all(createprops
,
2993 zfs_prop_to_name(ZFS_PROP_CASE
));
2997 * If the zpl version requested is whacky or the file system
2998 * or pool is version is too "young" to support normalization
2999 * and the creator tried to set a value for one of the props,
3002 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3003 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3004 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3005 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3006 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3007 sense
!= ZFS_PROP_UNDEFINED
)))
3011 * Put the version in the zplprops
3013 VERIFY(nvlist_add_uint64(zplprops
,
3014 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3016 if (norm
== ZFS_PROP_UNDEFINED
&&
3017 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3019 VERIFY(nvlist_add_uint64(zplprops
,
3020 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3023 * If we're normalizing, names must always be valid UTF-8 strings.
3027 if (u8
== ZFS_PROP_UNDEFINED
&&
3028 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3030 VERIFY(nvlist_add_uint64(zplprops
,
3031 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3033 if (sense
== ZFS_PROP_UNDEFINED
&&
3034 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3036 VERIFY(nvlist_add_uint64(zplprops
,
3037 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3040 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3046 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3047 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3049 boolean_t fuids_ok
, sa_ok
;
3050 uint64_t zplver
= ZPL_VERSION
;
3051 objset_t
*os
= NULL
;
3052 char parentname
[MAXNAMELEN
];
3058 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3059 cp
= strrchr(parentname
, '/');
3063 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3066 spa_vers
= spa_version(spa
);
3067 spa_close(spa
, FTAG
);
3069 zplver
= zfs_zpl_version_map(spa_vers
);
3070 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3071 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3074 * Open parent object set so we can inherit zplprop values.
3076 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3079 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3081 dmu_objset_rele(os
, FTAG
);
3086 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3087 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3091 uint64_t zplver
= ZPL_VERSION
;
3094 zplver
= zfs_zpl_version_map(spa_vers
);
3095 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3096 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3098 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3099 createprops
, zplprops
, is_ci
);
3105 * "type" -> dmu_objset_type_t (int32)
3106 * (optional) "props" -> { prop -> value }
3109 * outnvl: propname -> error code (int32)
3112 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3115 zfs_creat_t zct
= { 0 };
3116 nvlist_t
*nvprops
= NULL
;
3117 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3119 dmu_objset_type_t type
;
3120 boolean_t is_insensitive
= B_FALSE
;
3122 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3125 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3129 cbfunc
= zfs_create_cb
;
3133 cbfunc
= zvol_create_cb
;
3140 if (strchr(fsname
, '@') ||
3141 strchr(fsname
, '%'))
3144 zct
.zct_props
= nvprops
;
3149 if (type
== DMU_OST_ZVOL
) {
3150 uint64_t volsize
, volblocksize
;
3152 if (nvprops
== NULL
)
3154 if (nvlist_lookup_uint64(nvprops
,
3155 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3158 if ((error
= nvlist_lookup_uint64(nvprops
,
3159 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3160 &volblocksize
)) != 0 && error
!= ENOENT
)
3164 volblocksize
= zfs_prop_default_numeric(
3165 ZFS_PROP_VOLBLOCKSIZE
);
3167 if ((error
= zvol_check_volblocksize(
3168 volblocksize
)) != 0 ||
3169 (error
= zvol_check_volsize(volsize
,
3170 volblocksize
)) != 0)
3172 } else if (type
== DMU_OST_ZFS
) {
3176 * We have to have normalization and
3177 * case-folding flags correct when we do the
3178 * file system creation, so go figure them out
3181 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3182 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3183 error
= zfs_fill_zplprops(fsname
, nvprops
,
3184 zct
.zct_zplprops
, &is_insensitive
);
3186 nvlist_free(zct
.zct_zplprops
);
3191 error
= dmu_objset_create(fsname
, type
,
3192 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3193 nvlist_free(zct
.zct_zplprops
);
3196 * It would be nice to do this atomically.
3199 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3202 (void) dsl_destroy_head(fsname
);
3209 * "origin" -> name of origin snapshot
3210 * (optional) "props" -> { prop -> value }
3214 * outnvl: propname -> error code (int32)
3217 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3220 nvlist_t
*nvprops
= NULL
;
3223 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3225 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3227 if (strchr(fsname
, '@') ||
3228 strchr(fsname
, '%'))
3231 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3233 error
= dmu_objset_clone(fsname
, origin_name
);
3238 * It would be nice to do this atomically.
3241 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3244 (void) dsl_destroy_head(fsname
);
3251 * "snaps" -> { snapshot1, snapshot2 }
3252 * (optional) "props" -> { prop -> value (string) }
3255 * outnvl: snapshot -> error code (int32)
3258 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3261 nvlist_t
*props
= NULL
;
3263 nvpair_t
*pair
, *pair2
;
3265 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3266 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3269 if (!nvlist_empty(props
) &&
3270 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3273 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3275 poollen
= strlen(poolname
);
3276 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3277 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3278 const char *name
= nvpair_name(pair
);
3279 const char *cp
= strchr(name
, '@');
3282 * The snap name must contain an @, and the part after it must
3283 * contain only valid characters.
3285 if (cp
== NULL
|| snapshot_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3289 * The snap must be in the specified pool.
3291 if (strncmp(name
, poolname
, poollen
) != 0 ||
3292 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3295 /* This must be the only snap of this fs. */
3296 for (pair2
= nvlist_next_nvpair(snaps
, pair
);
3297 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3298 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3305 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3310 * innvl: "message" -> string
3314 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3322 * The poolname in the ioctl is not set, we get it from the TSD,
3323 * which was set at the end of the last successful ioctl that allows
3324 * logging. The secpolicy func already checked that it is set.
3325 * Only one log ioctl is allowed after each successful ioctl, so
3326 * we clear the TSD here.
3328 poolname
= tsd_get(zfs_allow_log_key
);
3329 (void) tsd_set(zfs_allow_log_key
, NULL
);
3330 error
= spa_open(poolname
, &spa
, FTAG
);
3335 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3336 spa_close(spa
, FTAG
);
3340 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3341 spa_close(spa
, FTAG
);
3345 error
= spa_history_log(spa
, message
);
3346 spa_close(spa
, FTAG
);
3351 * The dp_config_rwlock must not be held when calling this, because the
3352 * unmount may need to write out data.
3354 * This function is best-effort. Callers must deal gracefully if it
3355 * remains mounted (or is remounted after this call).
3358 zfs_unmount_snap(const char *snapname
)
3360 zfs_sb_t
*zsb
= NULL
;
3365 if ((ptr
= strchr(snapname
, '@')) == NULL
)
3368 dsname
= strdup(snapname
);
3369 dsname
[ptr
- snapname
] = '\0';
3370 snapname
= strdup(ptr
+ 1);
3371 fullname
= kmem_asprintf("%s@%s", dsname
, snapname
);
3372 if (zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
) == 0) {
3373 ASSERT(!dsl_pool_config_held(dmu_objset_pool(zsb
->z_os
)));
3374 (void) zfsctl_unmount_snapshot(zsb
, fullname
, MNT_FORCE
);
3375 zfs_sb_rele(zsb
, FTAG
);
3386 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3388 zfs_unmount_snap(snapname
);
3393 * When a clone is destroyed, its origin may also need to be destroyed,
3394 * in which case it must be unmounted. This routine will do that unmount
3398 zfs_destroy_unmount_origin(const char *fsname
)
3404 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3407 ds
= dmu_objset_ds(os
);
3408 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3409 char originname
[MAXNAMELEN
];
3410 dsl_dataset_name(ds
->ds_prev
, originname
);
3411 dmu_objset_rele(os
, FTAG
);
3412 zfs_unmount_snap(originname
);
3414 dmu_objset_rele(os
, FTAG
);
3420 * "snaps" -> { snapshot1, snapshot2 }
3421 * (optional boolean) "defer"
3424 * outnvl: snapshot -> error code (int32)
3427 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3434 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3436 defer
= nvlist_exists(innvl
, "defer");
3438 poollen
= strlen(poolname
);
3439 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3440 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3441 const char *name
= nvpair_name(pair
);
3444 * The snap must be in the specified pool.
3446 if (strncmp(name
, poolname
, poollen
) != 0 ||
3447 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3450 zfs_unmount_snap(name
);
3451 (void) zvol_remove_minor(name
);
3454 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3459 * zc_name name of dataset to destroy
3460 * zc_objset_type type of objset
3461 * zc_defer_destroy mark for deferred destroy
3466 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3469 if (strchr(zc
->zc_name
, '@') && zc
->zc_objset_type
== DMU_OST_ZFS
)
3470 zfs_unmount_snap(zc
->zc_name
);
3472 if (strchr(zc
->zc_name
, '@'))
3473 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3475 err
= dsl_destroy_head(zc
->zc_name
);
3476 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3477 (void) zvol_remove_minor(zc
->zc_name
);
3483 * zc_name name of dataset to rollback (to most recent snapshot)
3488 zfs_ioc_rollback(zfs_cmd_t
*zc
)
3493 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
3494 error
= zfs_suspend_fs(zsb
);
3498 error
= dsl_dataset_rollback(zc
->zc_name
);
3499 resume_err
= zfs_resume_fs(zsb
, zc
->zc_name
);
3500 error
= error
? error
: resume_err
;
3502 deactivate_super(zsb
->z_sb
);
3504 error
= dsl_dataset_rollback(zc
->zc_name
);
3510 recursive_unmount(const char *fsname
, void *arg
)
3512 const char *snapname
= arg
;
3515 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3516 zfs_unmount_snap(fullname
);
3523 * zc_name old name of dataset
3524 * zc_value new name of dataset
3525 * zc_cookie recursive flag (only valid for snapshots)
3530 zfs_ioc_rename(zfs_cmd_t
*zc
)
3532 boolean_t recursive
= zc
->zc_cookie
& 1;
3536 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3537 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3538 strchr(zc
->zc_value
, '%'))
3541 at
= strchr(zc
->zc_name
, '@');
3543 /* snaps must be in same fs */
3544 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3547 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3548 int error
= dmu_objset_find(zc
->zc_name
,
3549 recursive_unmount
, at
+ 1,
3550 recursive
? DS_FIND_CHILDREN
: 0);
3554 return (dsl_dataset_rename_snapshot(zc
->zc_name
,
3555 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
));
3557 err
= dsl_dir_rename(zc
->zc_name
, zc
->zc_value
);
3558 if (!err
&& zc
->zc_objset_type
== DMU_OST_ZVOL
) {
3559 (void) zvol_remove_minor(zc
->zc_name
);
3560 (void) zvol_create_minor(zc
->zc_value
);
3567 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3569 const char *propname
= nvpair_name(pair
);
3570 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3571 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3575 if (prop
== ZPROP_INVAL
) {
3576 if (zfs_prop_user(propname
)) {
3577 if ((err
= zfs_secpolicy_write_perms(dsname
,
3578 ZFS_DELEG_PERM_USERPROP
, cr
)))
3583 if (!issnap
&& zfs_prop_userquota(propname
)) {
3584 const char *perm
= NULL
;
3585 const char *uq_prefix
=
3586 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3587 const char *gq_prefix
=
3588 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3590 if (strncmp(propname
, uq_prefix
,
3591 strlen(uq_prefix
)) == 0) {
3592 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3593 } else if (strncmp(propname
, gq_prefix
,
3594 strlen(gq_prefix
)) == 0) {
3595 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3597 /* USERUSED and GROUPUSED are read-only */
3601 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3612 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3614 * dsl_prop_get_all_impl() returns properties in this
3618 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3619 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3624 * Check that this value is valid for this pool version
3627 case ZFS_PROP_COMPRESSION
:
3629 * If the user specified gzip compression, make sure
3630 * the SPA supports it. We ignore any errors here since
3631 * we'll catch them later.
3633 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3634 nvpair_value_uint64(pair
, &intval
) == 0) {
3635 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3636 intval
<= ZIO_COMPRESS_GZIP_9
&&
3637 zfs_earlier_version(dsname
,
3638 SPA_VERSION_GZIP_COMPRESSION
)) {
3642 if (intval
== ZIO_COMPRESS_ZLE
&&
3643 zfs_earlier_version(dsname
,
3644 SPA_VERSION_ZLE_COMPRESSION
))
3647 if (intval
== ZIO_COMPRESS_LZ4
) {
3648 zfeature_info_t
*feature
=
3650 SPA_FEATURE_LZ4_COMPRESS
];
3653 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3656 if (!spa_feature_is_enabled(spa
, feature
)) {
3657 spa_close(spa
, FTAG
);
3660 spa_close(spa
, FTAG
);
3664 * If this is a bootable dataset then
3665 * verify that the compression algorithm
3666 * is supported for booting. We must return
3667 * something other than ENOTSUP since it
3668 * implies a downrev pool version.
3670 if (zfs_is_bootfs(dsname
) &&
3671 !BOOTFS_COMPRESS_VALID(intval
)) {
3677 case ZFS_PROP_COPIES
:
3678 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3682 case ZFS_PROP_DEDUP
:
3683 if (zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3687 case ZFS_PROP_SHARESMB
:
3688 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3692 case ZFS_PROP_ACLINHERIT
:
3693 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3694 nvpair_value_uint64(pair
, &intval
) == 0) {
3695 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3696 zfs_earlier_version(dsname
,
3697 SPA_VERSION_PASSTHROUGH_X
))
3705 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3709 * Checks for a race condition to make sure we don't increment a feature flag
3713 zfs_prop_activate_feature_check(void *arg
, dmu_tx_t
*tx
)
3715 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3716 zfeature_info_t
*feature
= arg
;
3718 if (!spa_feature_is_active(spa
, feature
))
3725 * The callback invoked on feature activation in the sync task caused by
3726 * zfs_prop_activate_feature.
3729 zfs_prop_activate_feature_sync(void *arg
, dmu_tx_t
*tx
)
3731 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3732 zfeature_info_t
*feature
= arg
;
3734 spa_feature_incr(spa
, feature
, tx
);
3738 * Activates a feature on a pool in response to a property setting. This
3739 * creates a new sync task which modifies the pool to reflect the feature
3743 zfs_prop_activate_feature(spa_t
*spa
, zfeature_info_t
*feature
)
3747 /* EBUSY here indicates that the feature is already active */
3748 err
= dsl_sync_task(spa_name(spa
),
3749 zfs_prop_activate_feature_check
, zfs_prop_activate_feature_sync
,
3752 if (err
!= 0 && err
!= EBUSY
)
3759 * Removes properties from the given props list that fail permission checks
3760 * needed to clear them and to restore them in case of a receive error. For each
3761 * property, make sure we have both set and inherit permissions.
3763 * Returns the first error encountered if any permission checks fail. If the
3764 * caller provides a non-NULL errlist, it also gives the complete list of names
3765 * of all the properties that failed a permission check along with the
3766 * corresponding error numbers. The caller is responsible for freeing the
3769 * If every property checks out successfully, zero is returned and the list
3770 * pointed at by errlist is NULL.
3773 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3776 nvpair_t
*pair
, *next_pair
;
3783 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3785 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
3786 (void) strcpy(zc
->zc_name
, dataset
);
3787 pair
= nvlist_next_nvpair(props
, NULL
);
3788 while (pair
!= NULL
) {
3789 next_pair
= nvlist_next_nvpair(props
, pair
);
3791 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3792 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3793 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
3794 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3795 VERIFY(nvlist_add_int32(errors
,
3796 zc
->zc_value
, err
) == 0);
3800 kmem_free(zc
, sizeof (zfs_cmd_t
));
3802 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3803 nvlist_free(errors
);
3806 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3809 if (errlist
== NULL
)
3810 nvlist_free(errors
);
3818 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3820 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3821 /* dsl_prop_get_all_impl() format */
3823 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3824 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3828 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3830 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3831 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3835 if (nvpair_type(p1
) != nvpair_type(p2
))
3838 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
3839 char *valstr1
, *valstr2
;
3841 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
3842 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
3843 return (strcmp(valstr1
, valstr2
) == 0);
3845 uint64_t intval1
, intval2
;
3847 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
3848 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
3849 return (intval1
== intval2
);
3854 * Remove properties from props if they are not going to change (as determined
3855 * by comparison with origprops). Remove them from origprops as well, since we
3856 * do not need to clear or restore properties that won't change.
3859 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
3861 nvpair_t
*pair
, *next_pair
;
3863 if (origprops
== NULL
)
3864 return; /* all props need to be received */
3866 pair
= nvlist_next_nvpair(props
, NULL
);
3867 while (pair
!= NULL
) {
3868 const char *propname
= nvpair_name(pair
);
3871 next_pair
= nvlist_next_nvpair(props
, pair
);
3873 if ((nvlist_lookup_nvpair(origprops
, propname
,
3874 &match
) != 0) || !propval_equals(pair
, match
))
3875 goto next
; /* need to set received value */
3877 /* don't clear the existing received value */
3878 (void) nvlist_remove_nvpair(origprops
, match
);
3879 /* don't bother receiving the property */
3880 (void) nvlist_remove_nvpair(props
, pair
);
3887 static boolean_t zfs_ioc_recv_inject_err
;
3892 * zc_name name of containing filesystem
3893 * zc_nvlist_src{_size} nvlist of properties to apply
3894 * zc_value name of snapshot to create
3895 * zc_string name of clone origin (if DRR_FLAG_CLONE)
3896 * zc_cookie file descriptor to recv from
3897 * zc_begin_record the BEGIN record of the stream (not byteswapped)
3898 * zc_guid force flag
3899 * zc_cleanup_fd cleanup-on-exit file descriptor
3900 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
3903 * zc_cookie number of bytes read
3904 * zc_nvlist_dst{_size} error for each unapplied received property
3905 * zc_obj zprop_errflags_t
3906 * zc_action_handle handle for this guid/ds mapping
3909 zfs_ioc_recv(zfs_cmd_t
*zc
)
3912 dmu_recv_cookie_t drc
;
3913 boolean_t force
= (boolean_t
)zc
->zc_guid
;
3916 int props_error
= 0;
3919 nvlist_t
*props
= NULL
; /* sent properties */
3920 nvlist_t
*origprops
= NULL
; /* existing properties */
3921 char *origin
= NULL
;
3923 char tofs
[ZFS_MAXNAMELEN
];
3924 boolean_t first_recvd_props
= B_FALSE
;
3926 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3927 strchr(zc
->zc_value
, '@') == NULL
||
3928 strchr(zc
->zc_value
, '%'))
3931 (void) strcpy(tofs
, zc
->zc_value
);
3932 tosnap
= strchr(tofs
, '@');
3935 if (zc
->zc_nvlist_src
!= 0 &&
3936 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3937 zc
->zc_iflags
, &props
)) != 0)
3947 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3949 if (zc
->zc_string
[0])
3950 origin
= zc
->zc_string
;
3952 error
= dmu_recv_begin(tofs
, tosnap
,
3953 &zc
->zc_begin_record
, force
, origin
, &drc
);
3958 * Set properties before we receive the stream so that they are applied
3959 * to the new data. Note that we must call dmu_recv_stream() if
3960 * dmu_recv_begin() succeeds.
3962 if (props
!= NULL
&& !drc
.drc_newfs
) {
3963 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
3964 SPA_VERSION_RECVD_PROPS
&&
3965 !dsl_prop_get_hasrecvd(tofs
))
3966 first_recvd_props
= B_TRUE
;
3969 * If new received properties are supplied, they are to
3970 * completely replace the existing received properties, so stash
3971 * away the existing ones.
3973 if (dsl_prop_get_received(tofs
, &origprops
) == 0) {
3974 nvlist_t
*errlist
= NULL
;
3976 * Don't bother writing a property if its value won't
3977 * change (and avoid the unnecessary security checks).
3979 * The first receive after SPA_VERSION_RECVD_PROPS is a
3980 * special case where we blow away all local properties
3983 if (!first_recvd_props
)
3984 props_reduce(props
, origprops
);
3985 if (zfs_check_clearable(tofs
, origprops
, &errlist
) != 0)
3986 (void) nvlist_merge(errors
, errlist
, 0);
3987 nvlist_free(errlist
);
3989 if (clear_received_props(tofs
, origprops
,
3990 first_recvd_props
? NULL
: props
) != 0)
3991 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3993 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
3997 if (props
!= NULL
) {
3998 props_error
= dsl_prop_set_hasrecvd(tofs
);
4000 if (props_error
== 0) {
4001 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4006 if (zc
->zc_nvlist_dst_size
!= 0 &&
4007 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4008 put_nvlist(zc
, errors
) != 0)) {
4010 * Caller made zc->zc_nvlist_dst less than the minimum expected
4011 * size or supplied an invalid address.
4013 props_error
= EINVAL
;
4017 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
4018 &zc
->zc_action_handle
);
4021 zfs_sb_t
*zsb
= NULL
;
4023 if (get_zfs_sb(tofs
, &zsb
) == 0) {
4027 error
= zfs_suspend_fs(zsb
);
4029 * If the suspend fails, then the recv_end will
4030 * likely also fail, and clean up after itself.
4032 end_err
= dmu_recv_end(&drc
);
4034 error
= zfs_resume_fs(zsb
, tofs
);
4035 error
= error
? error
: end_err
;
4036 deactivate_super(zsb
->z_sb
);
4038 error
= dmu_recv_end(&drc
);
4042 zc
->zc_cookie
= off
- fp
->f_offset
;
4043 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4047 if (zfs_ioc_recv_inject_err
) {
4048 zfs_ioc_recv_inject_err
= B_FALSE
;
4053 * On error, restore the original props.
4055 if (error
!= 0 && props
!= NULL
&& !drc
.drc_newfs
) {
4056 if (clear_received_props(tofs
, props
, NULL
) != 0) {
4058 * We failed to clear the received properties.
4059 * Since we may have left a $recvd value on the
4060 * system, we can't clear the $hasrecvd flag.
4062 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4063 } else if (first_recvd_props
) {
4064 dsl_prop_unset_hasrecvd(tofs
);
4067 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4068 /* We failed to stash the original properties. */
4069 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4073 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4074 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4075 * explictly if we're restoring local properties cleared in the
4076 * first new-style receive.
4078 if (origprops
!= NULL
&&
4079 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4080 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4081 origprops
, NULL
) != 0) {
4083 * We stashed the original properties but failed to
4086 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4091 nvlist_free(origprops
);
4092 nvlist_free(errors
);
4096 error
= props_error
;
4103 * zc_name name of snapshot to send
4104 * zc_cookie file descriptor to send stream to
4105 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4106 * zc_sendobj objsetid of snapshot to send
4107 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4108 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4109 * output size in zc_objset_type.
4114 zfs_ioc_send(zfs_cmd_t
*zc
)
4118 boolean_t estimate
= (zc
->zc_guid
!= 0);
4120 if (zc
->zc_obj
!= 0) {
4122 dsl_dataset_t
*tosnap
;
4124 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4128 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4130 dsl_pool_rele(dp
, FTAG
);
4134 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4135 zc
->zc_fromobj
= tosnap
->ds_dir
->dd_phys
->dd_origin_obj
;
4136 dsl_dataset_rele(tosnap
, FTAG
);
4137 dsl_pool_rele(dp
, FTAG
);
4142 dsl_dataset_t
*tosnap
;
4143 dsl_dataset_t
*fromsnap
= NULL
;
4145 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4149 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4151 dsl_pool_rele(dp
, FTAG
);
4155 if (zc
->zc_fromobj
!= 0) {
4156 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4159 dsl_dataset_rele(tosnap
, FTAG
);
4160 dsl_pool_rele(dp
, FTAG
);
4165 error
= dmu_send_estimate(tosnap
, fromsnap
,
4166 &zc
->zc_objset_type
);
4168 if (fromsnap
!= NULL
)
4169 dsl_dataset_rele(fromsnap
, FTAG
);
4170 dsl_dataset_rele(tosnap
, FTAG
);
4171 dsl_pool_rele(dp
, FTAG
);
4173 file_t
*fp
= getf(zc
->zc_cookie
);
4178 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4179 zc
->zc_fromobj
, zc
->zc_cookie
, fp
->f_vnode
, &off
);
4181 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4183 releasef(zc
->zc_cookie
);
4190 * zc_name name of snapshot on which to report progress
4191 * zc_cookie file descriptor of send stream
4194 * zc_cookie number of bytes written in send stream thus far
4197 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4201 dmu_sendarg_t
*dsp
= NULL
;
4204 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4208 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4210 dsl_pool_rele(dp
, FTAG
);
4214 mutex_enter(&ds
->ds_sendstream_lock
);
4217 * Iterate over all the send streams currently active on this dataset.
4218 * If there's one which matches the specified file descriptor _and_ the
4219 * stream was started by the current process, return the progress of
4223 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4224 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4225 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4226 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4231 zc
->zc_cookie
= *(dsp
->dsa_off
);
4235 mutex_exit(&ds
->ds_sendstream_lock
);
4236 dsl_dataset_rele(ds
, FTAG
);
4237 dsl_pool_rele(dp
, FTAG
);
4242 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4246 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4247 &zc
->zc_inject_record
);
4250 zc
->zc_guid
= (uint64_t)id
;
4256 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4258 return (zio_clear_fault((int)zc
->zc_guid
));
4262 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4264 int id
= (int)zc
->zc_guid
;
4267 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4268 &zc
->zc_inject_record
);
4276 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4280 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4282 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4285 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4288 zc
->zc_nvlist_dst_size
= count
;
4290 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4292 spa_close(spa
, FTAG
);
4298 zfs_ioc_clear(zfs_cmd_t
*zc
)
4305 * On zpool clear we also fix up missing slogs
4307 mutex_enter(&spa_namespace_lock
);
4308 spa
= spa_lookup(zc
->zc_name
);
4310 mutex_exit(&spa_namespace_lock
);
4313 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4314 /* we need to let spa_open/spa_load clear the chains */
4315 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4317 spa
->spa_last_open_failed
= 0;
4318 mutex_exit(&spa_namespace_lock
);
4320 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4321 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4324 nvlist_t
*config
= NULL
;
4326 if (zc
->zc_nvlist_src
== 0)
4329 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4330 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4331 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4333 if (config
!= NULL
) {
4336 if ((err
= put_nvlist(zc
, config
)) != 0)
4338 nvlist_free(config
);
4340 nvlist_free(policy
);
4347 spa_vdev_state_enter(spa
, SCL_NONE
);
4349 if (zc
->zc_guid
== 0) {
4352 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4354 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4355 spa_close(spa
, FTAG
);
4360 vdev_clear(spa
, vd
);
4362 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4365 * Resume any suspended I/Os.
4367 if (zio_resume(spa
) != 0)
4370 spa_close(spa
, FTAG
);
4376 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4381 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4385 spa_vdev_state_enter(spa
, SCL_NONE
);
4388 * If a resilver is already in progress then set the
4389 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4390 * the scan as a side effect of the reopen. Otherwise, let
4391 * vdev_open() decided if a resilver is required.
4393 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4394 vdev_reopen(spa
->spa_root_vdev
);
4395 spa
->spa_scrub_reopen
= B_FALSE
;
4397 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4398 spa_close(spa
, FTAG
);
4403 * zc_name name of filesystem
4404 * zc_value name of origin snapshot
4407 * zc_string name of conflicting snapshot, if there is one
4410 zfs_ioc_promote(zfs_cmd_t
*zc
)
4415 * We don't need to unmount *all* the origin fs's snapshots, but
4418 cp
= strchr(zc
->zc_value
, '@');
4421 (void) dmu_objset_find(zc
->zc_value
,
4422 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
4423 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4427 * Retrieve a single {user|group}{used|quota}@... property.
4430 * zc_name name of filesystem
4431 * zc_objset_type zfs_userquota_prop_t
4432 * zc_value domain name (eg. "S-1-234-567-89")
4433 * zc_guid RID/UID/GID
4436 * zc_cookie property value
4439 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4444 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4447 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4451 error
= zfs_userspace_one(zsb
,
4452 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4453 zfs_sb_rele(zsb
, FTAG
);
4460 * zc_name name of filesystem
4461 * zc_cookie zap cursor
4462 * zc_objset_type zfs_userquota_prop_t
4463 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4466 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4467 * zc_cookie zap cursor
4470 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4473 int bufsize
= zc
->zc_nvlist_dst_size
;
4480 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4484 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
4486 error
= zfs_userspace_many(zsb
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4487 buf
, &zc
->zc_nvlist_dst_size
);
4490 error
= xcopyout(buf
,
4491 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4492 zc
->zc_nvlist_dst_size
);
4494 vmem_free(buf
, bufsize
);
4495 zfs_sb_rele(zsb
, FTAG
);
4502 * zc_name name of filesystem
4508 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4514 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
4515 if (!dmu_objset_userused_enabled(zsb
->z_os
)) {
4517 * If userused is not enabled, it may be because the
4518 * objset needs to be closed & reopened (to grow the
4519 * objset_phys_t). Suspend/resume the fs will do that.
4521 error
= zfs_suspend_fs(zsb
);
4523 error
= zfs_resume_fs(zsb
, zc
->zc_name
);
4526 error
= dmu_objset_userspace_upgrade(zsb
->z_os
);
4527 deactivate_super(zsb
->z_sb
);
4529 /* XXX kind of reading contents without owning */
4530 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4534 error
= dmu_objset_userspace_upgrade(os
);
4535 dmu_objset_rele(os
, FTAG
);
4542 zfs_ioc_share(zfs_cmd_t
*zc
)
4547 ace_t full_access
[] = {
4548 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4553 * zc_name name of containing filesystem
4554 * zc_obj object # beyond which we want next in-use object #
4557 * zc_obj next in-use object #
4560 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4562 objset_t
*os
= NULL
;
4565 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4569 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4570 os
->os_dsl_dataset
->ds_phys
->ds_prev_snap_txg
);
4572 dmu_objset_rele(os
, FTAG
);
4578 * zc_name name of filesystem
4579 * zc_value prefix name for snapshot
4580 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4583 * zc_value short name of new snapshot
4586 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
4593 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
4597 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
4598 (u_longlong_t
)ddi_get_lbolt64());
4599 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
4601 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
4604 (void) strcpy(zc
->zc_value
, snap_name
);
4607 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
4613 * zc_name name of "to" snapshot
4614 * zc_value name of "from" snapshot
4615 * zc_cookie file descriptor to write diff data on
4618 * dmu_diff_record_t's to the file descriptor
4621 zfs_ioc_diff(zfs_cmd_t
*zc
)
4627 fp
= getf(zc
->zc_cookie
);
4633 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
4635 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4637 releasef(zc
->zc_cookie
);
4643 * Remove all ACL files in shares dir
4645 #ifdef HAVE_SMB_SHARE
4647 zfs_smb_acl_purge(znode_t
*dzp
)
4650 zap_attribute_t zap
;
4651 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
4654 for (zap_cursor_init(&zc
, zsb
->z_os
, dzp
->z_id
);
4655 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
4656 zap_cursor_advance(&zc
)) {
4657 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
4661 zap_cursor_fini(&zc
);
4664 #endif /* HAVE_SMB_SHARE */
4667 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
4669 #ifdef HAVE_SMB_SHARE
4672 vnode_t
*resourcevp
= NULL
;
4681 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
4682 NO_FOLLOW
, NULL
, &vp
)) != 0)
4685 /* Now make sure mntpnt and dataset are ZFS */
4687 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
4688 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
4689 zc
->zc_name
) != 0)) {
4699 * Create share dir if its missing.
4701 mutex_enter(&zsb
->z_lock
);
4702 if (zsb
->z_shares_dir
== 0) {
4705 tx
= dmu_tx_create(zsb
->z_os
);
4706 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
4708 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
4709 error
= dmu_tx_assign(tx
, TXG_WAIT
);
4713 error
= zfs_create_share_dir(zsb
, tx
);
4717 mutex_exit(&zsb
->z_lock
);
4723 mutex_exit(&zsb
->z_lock
);
4725 ASSERT(zsb
->z_shares_dir
);
4726 if ((error
= zfs_zget(zsb
, zsb
->z_shares_dir
, &sharedir
)) != 0) {
4732 switch (zc
->zc_cookie
) {
4733 case ZFS_SMB_ACL_ADD
:
4734 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
4735 vattr
.va_mode
= S_IFREG
|0777;
4739 vsec
.vsa_mask
= VSA_ACE
;
4740 vsec
.vsa_aclentp
= &full_access
;
4741 vsec
.vsa_aclentsz
= sizeof (full_access
);
4742 vsec
.vsa_aclcnt
= 1;
4744 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
4745 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
4747 VN_RELE(resourcevp
);
4750 case ZFS_SMB_ACL_REMOVE
:
4751 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
4755 case ZFS_SMB_ACL_RENAME
:
4756 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4757 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
4762 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
4763 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
4766 VN_RELE(ZTOV(sharedir
));
4768 nvlist_free(nvlist
);
4771 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
4773 nvlist_free(nvlist
);
4776 case ZFS_SMB_ACL_PURGE
:
4777 error
= zfs_smb_acl_purge(sharedir
);
4786 VN_RELE(ZTOV(sharedir
));
4793 #endif /* HAVE_SMB_SHARE */
4798 * "holds" -> { snapname -> holdname (string), ... }
4799 * (optional) "cleanup_fd" -> fd (int32)
4803 * snapname -> error value (int32)
4809 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
4812 int cleanup_fd
= -1;
4816 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
4820 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
4821 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
4826 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
4828 zfs_onexit_fd_rele(cleanup_fd
);
4833 * innvl is not used.
4836 * holdname -> time added (uint64 seconds since epoch)
4842 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
4844 return (dsl_dataset_get_holds(snapname
, outnvl
));
4849 * snapname -> { holdname, ... }
4854 * snapname -> error value (int32)
4860 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
4865 * The release may cause the snapshot to be destroyed; make sure it
4868 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
4869 pair
= nvlist_next_nvpair(holds
, pair
))
4870 zfs_unmount_snap(nvpair_name(pair
));
4872 return (dsl_dataset_user_release(holds
, errlist
));
4877 * zc_guid flags (ZEVENT_NONBLOCK)
4880 * zc_nvlist_dst next nvlist event
4881 * zc_cookie dropped events since last get
4882 * zc_cleanup_fd cleanup-on-exit file descriptor
4885 zfs_ioc_events_next(zfs_cmd_t
*zc
)
4888 nvlist_t
*event
= NULL
;
4890 uint64_t dropped
= 0;
4893 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
4898 error
= zfs_zevent_next(ze
, &event
,
4899 &zc
->zc_nvlist_dst_size
, &dropped
);
4900 if (event
!= NULL
) {
4901 zc
->zc_cookie
= dropped
;
4902 error
= put_nvlist(zc
, event
);
4906 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
4909 if ((error
== 0) || (error
!= ENOENT
))
4912 error
= zfs_zevent_wait(ze
);
4917 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
4924 * zc_cookie cleared events count
4927 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
4931 zfs_zevent_drain_all(&count
);
4932 zc
->zc_cookie
= count
;
4939 * zc_name name of new filesystem or snapshot
4940 * zc_value full name of old snapshot
4943 * zc_cookie space in bytes
4944 * zc_objset_type compressed space in bytes
4945 * zc_perm_action uncompressed space in bytes
4948 zfs_ioc_space_written(zfs_cmd_t
*zc
)
4952 dsl_dataset_t
*new, *old
;
4954 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4957 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
4959 dsl_pool_rele(dp
, FTAG
);
4962 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
4964 dsl_dataset_rele(new, FTAG
);
4965 dsl_pool_rele(dp
, FTAG
);
4969 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
4970 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
4971 dsl_dataset_rele(old
, FTAG
);
4972 dsl_dataset_rele(new, FTAG
);
4973 dsl_pool_rele(dp
, FTAG
);
4979 * "firstsnap" -> snapshot name
4983 * "used" -> space in bytes
4984 * "compressed" -> compressed space in bytes
4985 * "uncompressed" -> uncompressed space in bytes
4989 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4993 dsl_dataset_t
*new, *old
;
4995 uint64_t used
, comp
, uncomp
;
4997 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5000 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5004 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5006 dsl_pool_rele(dp
, FTAG
);
5009 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5011 dsl_dataset_rele(new, FTAG
);
5012 dsl_pool_rele(dp
, FTAG
);
5016 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5017 dsl_dataset_rele(old
, FTAG
);
5018 dsl_dataset_rele(new, FTAG
);
5019 dsl_pool_rele(dp
, FTAG
);
5020 fnvlist_add_uint64(outnvl
, "used", used
);
5021 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5022 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5028 * "fd" -> file descriptor to write stream to (int32)
5029 * (optional) "fromsnap" -> full snap name to send an incremental from
5036 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5040 char *fromname
= NULL
;
5044 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5048 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5050 if ((fp
= getf(fd
)) == NULL
)
5054 error
= dmu_send(snapname
, fromname
, fd
, fp
->f_vnode
, &off
);
5056 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5064 * Determine approximately how large a zfs send stream will be -- the number
5065 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5068 * (optional) "fromsnap" -> full snap name to send an incremental from
5072 * "space" -> bytes of space (uint64)
5076 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5079 dsl_dataset_t
*fromsnap
= NULL
;
5080 dsl_dataset_t
*tosnap
;
5085 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5089 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5091 dsl_pool_rele(dp
, FTAG
);
5095 error
= nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5097 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5099 dsl_dataset_rele(tosnap
, FTAG
);
5100 dsl_pool_rele(dp
, FTAG
);
5105 error
= dmu_send_estimate(tosnap
, fromsnap
, &space
);
5106 fnvlist_add_uint64(outnvl
, "space", space
);
5108 if (fromsnap
!= NULL
)
5109 dsl_dataset_rele(fromsnap
, FTAG
);
5110 dsl_dataset_rele(tosnap
, FTAG
);
5111 dsl_pool_rele(dp
, FTAG
);
5116 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5119 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5120 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5121 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5123 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5125 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5126 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5127 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5128 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5130 vec
->zvec_legacy_func
= func
;
5131 vec
->zvec_secpolicy
= secpolicy
;
5132 vec
->zvec_namecheck
= namecheck
;
5133 vec
->zvec_allow_log
= log_history
;
5134 vec
->zvec_pool_check
= pool_check
;
5138 * See the block comment at the beginning of this file for details on
5139 * each argument to this function.
5142 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5143 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5144 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5145 boolean_t allow_log
)
5147 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5149 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5150 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5151 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5152 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5154 /* if we are logging, the name must be valid */
5155 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5157 vec
->zvec_name
= name
;
5158 vec
->zvec_func
= func
;
5159 vec
->zvec_secpolicy
= secpolicy
;
5160 vec
->zvec_namecheck
= namecheck
;
5161 vec
->zvec_pool_check
= pool_check
;
5162 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5163 vec
->zvec_allow_log
= allow_log
;
5167 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5168 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5169 zfs_ioc_poolcheck_t pool_check
)
5171 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5172 POOL_NAME
, log_history
, pool_check
);
5176 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5177 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5179 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5180 DATASET_NAME
, B_FALSE
, pool_check
);
5184 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5186 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5187 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5191 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5192 zfs_secpolicy_func_t
*secpolicy
)
5194 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5195 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5199 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5200 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5202 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5203 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5207 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5209 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5210 zfs_secpolicy_read
);
5214 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5215 zfs_secpolicy_func_t
*secpolicy
)
5217 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5218 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5222 zfs_ioctl_init(void)
5224 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5225 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5226 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5228 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5229 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5230 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5232 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5233 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5234 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5236 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5237 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5238 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5240 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5241 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5242 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5244 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5245 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5246 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5248 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5249 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5250 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5252 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5253 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5254 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5256 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
5257 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
5258 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5259 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
5260 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
5261 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5263 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
5264 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
5265 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5267 /* IOCTLS that use the legacy function signature */
5269 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5270 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5272 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5273 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5274 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5276 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5277 zfs_ioc_pool_upgrade
);
5278 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5280 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5281 zfs_ioc_vdev_remove
);
5282 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5283 zfs_ioc_vdev_set_state
);
5284 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5285 zfs_ioc_vdev_attach
);
5286 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5287 zfs_ioc_vdev_detach
);
5288 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5289 zfs_ioc_vdev_setpath
);
5290 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5291 zfs_ioc_vdev_setfru
);
5292 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5293 zfs_ioc_pool_set_props
);
5294 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5295 zfs_ioc_vdev_split
);
5296 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5297 zfs_ioc_pool_reguid
);
5299 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5300 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5301 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5302 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5303 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5304 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5305 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5306 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5307 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5308 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5311 * pool destroy, and export don't log the history as part of
5312 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5313 * does the logging of those commands.
5315 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5316 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5317 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5318 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5320 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5321 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5322 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5323 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5325 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5326 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5327 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5328 zfs_ioc_dsobj_to_dsname
,
5329 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5330 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5331 zfs_ioc_pool_get_history
,
5332 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5334 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5335 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5337 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5338 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5339 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5340 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5342 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5343 zfs_ioc_space_written
);
5344 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5345 zfs_ioc_objset_recvd_props
);
5346 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5348 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5350 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5351 zfs_ioc_objset_stats
);
5352 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5353 zfs_ioc_objset_zplprops
);
5354 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5355 zfs_ioc_dataset_list_next
);
5356 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5357 zfs_ioc_snapshot_list_next
);
5358 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5359 zfs_ioc_send_progress
);
5361 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5362 zfs_ioc_diff
, zfs_secpolicy_diff
);
5363 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5364 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5365 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5366 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5367 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5368 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5369 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5370 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5371 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5372 zfs_ioc_send
, zfs_secpolicy_send
);
5374 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5375 zfs_secpolicy_none
);
5376 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5377 zfs_secpolicy_destroy
);
5378 zfs_ioctl_register_dataset_modify(ZFS_IOC_ROLLBACK
, zfs_ioc_rollback
,
5379 zfs_secpolicy_rollback
);
5380 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5381 zfs_secpolicy_rename
);
5382 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5383 zfs_secpolicy_recv
);
5384 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5385 zfs_secpolicy_promote
);
5386 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5387 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5388 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5389 zfs_secpolicy_set_fsacl
);
5391 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5392 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5393 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5394 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5395 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5396 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5397 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5398 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5399 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5400 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5405 zfs_ioctl_register_legacy(ZFS_IOC_CREATE_MINOR
, zfs_ioc_create_minor
,
5406 zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5407 zfs_ioctl_register_legacy(ZFS_IOC_REMOVE_MINOR
, zfs_ioc_remove_minor
,
5408 zfs_secpolicy_config
, DATASET_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5409 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
5410 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5411 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
5412 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5416 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5417 zfs_ioc_poolcheck_t check
)
5422 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5424 if (check
& POOL_CHECK_NONE
)
5427 error
= spa_open(name
, &spa
, FTAG
);
5429 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5431 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5433 spa_close(spa
, FTAG
);
5439 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
5443 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5445 for (zs
= list_head(&zfsdev_state_list
); zs
!= NULL
;
5446 zs
= list_next(&zfsdev_state_list
, zs
)) {
5447 if (zs
->zs_minor
== minor
) {
5449 case ZST_ONEXIT
: return (zs
->zs_onexit
);
5450 case ZST_ZEVENT
: return (zs
->zs_zevent
);
5451 case ZST_ALL
: return (zs
);
5460 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
5464 mutex_enter(&zfsdev_state_lock
);
5465 ptr
= zfsdev_get_state_impl(minor
, which
);
5466 mutex_exit(&zfsdev_state_lock
);
5472 zfsdev_getminor(struct file
*filp
)
5474 ASSERT(filp
!= NULL
);
5475 ASSERT(filp
->private_data
!= NULL
);
5477 return (((zfsdev_state_t
*)filp
->private_data
)->zs_minor
);
5481 * Find a free minor number. The zfsdev_state_list is expected to
5482 * be short since it is only a list of currently open file handles.
5485 zfsdev_minor_alloc(void)
5487 static minor_t last_minor
= 0;
5490 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5492 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5493 if (m
> ZFSDEV_MAX_MINOR
)
5495 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
5505 zfsdev_state_init(struct file
*filp
)
5510 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5512 minor
= zfsdev_minor_alloc();
5516 zs
= kmem_zalloc( sizeof(zfsdev_state_t
), KM_SLEEP
);
5519 zs
->zs_minor
= minor
;
5520 filp
->private_data
= zs
;
5522 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
5523 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
5525 list_insert_tail(&zfsdev_state_list
, zs
);
5531 zfsdev_state_destroy(struct file
*filp
)
5535 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5536 ASSERT(filp
->private_data
!= NULL
);
5538 zs
= filp
->private_data
;
5539 zfs_onexit_destroy(zs
->zs_onexit
);
5540 zfs_zevent_destroy(zs
->zs_zevent
);
5542 list_remove(&zfsdev_state_list
, zs
);
5543 kmem_free(zs
, sizeof(zfsdev_state_t
));
5549 zfsdev_open(struct inode
*ino
, struct file
*filp
)
5553 mutex_enter(&zfsdev_state_lock
);
5554 error
= zfsdev_state_init(filp
);
5555 mutex_exit(&zfsdev_state_lock
);
5561 zfsdev_release(struct inode
*ino
, struct file
*filp
)
5565 mutex_enter(&zfsdev_state_lock
);
5566 error
= zfsdev_state_destroy(filp
);
5567 mutex_exit(&zfsdev_state_lock
);
5573 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5577 int error
, rc
, len
, flag
= 0;
5578 const zfs_ioc_vec_t
*vec
;
5579 char saved_poolname
[MAXNAMELEN
];
5580 nvlist_t
*innvl
= NULL
;
5582 vecnum
= cmd
- ZFS_IOC_FIRST
;
5583 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
5585 vec
= &zfs_ioc_vec
[vecnum
];
5587 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
| KM_NODEBUG
);
5589 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
5595 zc
->zc_iflags
= flag
& FKIOCTL
;
5596 if (zc
->zc_nvlist_src_size
!= 0) {
5597 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
5598 zc
->zc_iflags
, &innvl
);
5604 * Ensure that all pool/dataset names are valid before we pass down to
5607 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5608 switch (vec
->zvec_namecheck
) {
5610 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5613 error
= pool_status_check(zc
->zc_name
,
5614 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
5618 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5621 error
= pool_status_check(zc
->zc_name
,
5622 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
5630 if (error
== 0 && !(flag
& FKIOCTL
))
5631 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
5636 /* legacy ioctls can modify zc_name */
5637 (void) strlcpy(saved_poolname
, zc
->zc_name
, sizeof(saved_poolname
));
5638 len
= strcspn(saved_poolname
, "/@") + 1;
5639 saved_poolname
[len
] = '\0';
5641 if (vec
->zvec_func
!= NULL
) {
5645 nvlist_t
*lognv
= NULL
;
5647 ASSERT(vec
->zvec_legacy_func
== NULL
);
5650 * Add the innvl to the lognv before calling the func,
5651 * in case the func changes the innvl.
5653 if (vec
->zvec_allow_log
) {
5654 lognv
= fnvlist_alloc();
5655 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
5657 if (!nvlist_empty(innvl
)) {
5658 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
5663 outnvl
= fnvlist_alloc();
5664 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
5666 if (error
== 0 && vec
->zvec_allow_log
&&
5667 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
5668 if (!nvlist_empty(outnvl
)) {
5669 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
5672 (void) spa_history_log_nvl(spa
, lognv
);
5673 spa_close(spa
, FTAG
);
5675 fnvlist_free(lognv
);
5677 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
5679 if (vec
->zvec_smush_outnvlist
) {
5680 smusherror
= nvlist_smush(outnvl
,
5681 zc
->zc_nvlist_dst_size
);
5683 if (smusherror
== 0)
5684 puterror
= put_nvlist(zc
, outnvl
);
5690 nvlist_free(outnvl
);
5692 error
= vec
->zvec_legacy_func(zc
);
5697 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
5698 if (error
== 0 && rc
!= 0)
5700 if (error
== 0 && vec
->zvec_allow_log
) {
5701 char *s
= tsd_get(zfs_allow_log_key
);
5704 (void) tsd_set(zfs_allow_log_key
, strdup(saved_poolname
));
5707 kmem_free(zc
, sizeof (zfs_cmd_t
));
5711 #ifdef CONFIG_COMPAT
5713 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
5715 return zfsdev_ioctl(filp
, cmd
, arg
);
5718 #define zfsdev_compat_ioctl NULL
5721 static const struct file_operations zfsdev_fops
= {
5722 .open
= zfsdev_open
,
5723 .release
= zfsdev_release
,
5724 .unlocked_ioctl
= zfsdev_ioctl
,
5725 .compat_ioctl
= zfsdev_compat_ioctl
,
5726 .owner
= THIS_MODULE
,
5729 static struct miscdevice zfs_misc
= {
5730 .minor
= MISC_DYNAMIC_MINOR
,
5732 .fops
= &zfsdev_fops
,
5740 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
5741 list_create(&zfsdev_state_list
, sizeof (zfsdev_state_t
),
5742 offsetof(zfsdev_state_t
, zs_next
));
5744 error
= misc_register(&zfs_misc
);
5746 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
5758 error
= misc_deregister(&zfs_misc
);
5760 printk(KERN_INFO
"ZFS: misc_deregister() failed %d\n", error
);
5762 mutex_destroy(&zfsdev_state_lock
);
5763 list_destroy(&zfsdev_state_list
);
5767 zfs_allow_log_destroy(void *arg
)
5769 char *poolname
= arg
;
5774 #define ZFS_DEBUG_STR " (DEBUG mode)"
5776 #define ZFS_DEBUG_STR ""
5784 spa_init(FREAD
| FWRITE
);
5787 if ((error
= zvol_init()) != 0)
5792 if ((error
= zfs_attach()) != 0)
5795 tsd_create(&zfs_fsyncer_key
, NULL
);
5796 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
5797 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
5799 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
5800 "ZFS pool version %s, ZFS filesystem version %s\n",
5801 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
5802 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
5811 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
5812 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
5813 ZFS_DEBUG_STR
, error
);
5826 tsd_destroy(&zfs_fsyncer_key
);
5827 tsd_destroy(&rrw_tsd_key
);
5828 tsd_destroy(&zfs_allow_log_key
);
5830 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
5831 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
5837 spl_module_init(_init
);
5838 spl_module_exit(_fini
);
5840 MODULE_DESCRIPTION("ZFS");
5841 MODULE_AUTHOR(ZFS_META_AUTHOR
);
5842 MODULE_LICENSE(ZFS_META_LICENSE
);
5843 #endif /* HAVE_SPL */