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 * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
26 * Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
27 * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
28 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
29 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
30 * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
31 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
32 * Copyright (c) 2013 Steven Hartland. All rights reserved.
33 * Copyright (c) 2014 Integros [integros.com]
34 * Copyright 2016 Toomas Soome <tsoome@me.com>
35 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
36 * Copyright (c) 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
37 * Copyright (c) 2017 Datto Inc. All rights reserved.
38 * Copyright 2017 RackTop Systems.
44 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
45 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
47 * There are two ways that we handle ioctls: the legacy way where almost
48 * all of the logic is in the ioctl callback, and the new way where most
49 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
51 * Non-legacy ioctls should be registered by calling
52 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
53 * from userland by lzc_ioctl().
55 * The registration arguments are as follows:
58 * The name of the ioctl. This is used for history logging. If the
59 * ioctl returns successfully (the callback returns 0), and allow_log
60 * is true, then a history log entry will be recorded with the input &
61 * output nvlists. The log entry can be printed with "zpool history -i".
64 * The ioctl request number, which userland will pass to ioctl(2).
65 * The ioctl numbers can change from release to release, because
66 * the caller (libzfs) must be matched to the kernel.
68 * zfs_secpolicy_func_t *secpolicy
69 * This function will be called before the zfs_ioc_func_t, to
70 * determine if this operation is permitted. It should return EPERM
71 * on failure, and 0 on success. Checks include determining if the
72 * dataset is visible in this zone, and if the user has either all
73 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
74 * to do this operation on this dataset with "zfs allow".
76 * zfs_ioc_namecheck_t namecheck
77 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
78 * name, a dataset name, or nothing. If the name is not well-formed,
79 * the ioctl will fail and the callback will not be called.
80 * Therefore, the callback can assume that the name is well-formed
81 * (e.g. is null-terminated, doesn't have more than one '@' character,
82 * doesn't have invalid characters).
84 * zfs_ioc_poolcheck_t pool_check
85 * This specifies requirements on the pool state. If the pool does
86 * not meet them (is suspended or is readonly), the ioctl will fail
87 * and the callback will not be called. If any checks are specified
88 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
89 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
90 * POOL_CHECK_READONLY).
92 * boolean_t smush_outnvlist
93 * If smush_outnvlist is true, then the output is presumed to be a
94 * list of errors, and it will be "smushed" down to fit into the
95 * caller's buffer, by removing some entries and replacing them with a
96 * single "N_MORE_ERRORS" entry indicating how many were removed. See
97 * nvlist_smush() for details. If smush_outnvlist is false, and the
98 * outnvlist does not fit into the userland-provided buffer, then the
99 * ioctl will fail with ENOMEM.
101 * zfs_ioc_func_t *func
102 * The callback function that will perform the operation.
104 * The callback should return 0 on success, or an error number on
105 * failure. If the function fails, the userland ioctl will return -1,
106 * and errno will be set to the callback's return value. The callback
107 * will be called with the following arguments:
110 * The name of the pool or dataset to operate on, from
111 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
112 * expected type (pool, dataset, or none).
115 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
116 * NULL if no input nvlist was provided. Changes to this nvlist are
117 * ignored. If the input nvlist could not be deserialized, the
118 * ioctl will fail and the callback will not be called.
121 * The output nvlist, initially empty. The callback can fill it in,
122 * and it will be returned to userland by serializing it into
123 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
124 * fails (e.g. because the caller didn't supply a large enough
125 * buffer), then the overall ioctl will fail. See the
126 * 'smush_nvlist' argument above for additional behaviors.
128 * There are two typical uses of the output nvlist:
129 * - To return state, e.g. property values. In this case,
130 * smush_outnvlist should be false. If the buffer was not large
131 * enough, the caller will reallocate a larger buffer and try
134 * - To return multiple errors from an ioctl which makes on-disk
135 * changes. In this case, smush_outnvlist should be true.
136 * Ioctls which make on-disk modifications should generally not
137 * use the outnvl if they succeed, because the caller can not
138 * distinguish between the operation failing, and
139 * deserialization failing.
142 #include <sys/types.h>
143 #include <sys/param.h>
144 #include <sys/errno.h>
147 #include <sys/modctl.h>
148 #include <sys/open.h>
149 #include <sys/file.h>
150 #include <sys/kmem.h>
151 #include <sys/conf.h>
152 #include <sys/cmn_err.h>
153 #include <sys/stat.h>
154 #include <sys/zfs_ioctl.h>
155 #include <sys/zfs_vfsops.h>
156 #include <sys/zfs_znode.h>
159 #include <sys/spa_impl.h>
160 #include <sys/vdev.h>
161 #include <sys/vdev_impl.h>
162 #include <sys/priv_impl.h>
164 #include <sys/dsl_dir.h>
165 #include <sys/dsl_dataset.h>
166 #include <sys/dsl_prop.h>
167 #include <sys/dsl_deleg.h>
168 #include <sys/dmu_objset.h>
169 #include <sys/dmu_impl.h>
170 #include <sys/dmu_tx.h>
172 #include <sys/sunddi.h>
173 #include <sys/sunldi.h>
174 #include <sys/policy.h>
175 #include <sys/zone.h>
176 #include <sys/nvpair.h>
177 #include <sys/pathname.h>
178 #include <sys/mount.h>
180 #include <sys/fs/zfs.h>
181 #include <sys/zfs_ctldir.h>
182 #include <sys/zfs_dir.h>
183 #include <sys/zfs_onexit.h>
184 #include <sys/zvol.h>
185 #include <sys/dsl_scan.h>
186 #include <sharefs/share.h>
187 #include <sys/fm/util.h>
188 #include <sys/dsl_crypt.h>
190 #include <sys/dmu_send.h>
191 #include <sys/dsl_destroy.h>
192 #include <sys/dsl_bookmark.h>
193 #include <sys/dsl_userhold.h>
194 #include <sys/zfeature.h>
195 #include <sys/zio_checksum.h>
197 #include <linux/miscdevice.h>
198 #include <linux/slab.h>
200 #include "zfs_namecheck.h"
201 #include "zfs_prop.h"
202 #include "zfs_deleg.h"
203 #include "zfs_comutil.h"
206 * Limit maximum nvlist size. We don't want users passing in insane values
207 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
209 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
211 kmutex_t zfsdev_state_lock
;
212 zfsdev_state_t
*zfsdev_state_list
;
214 extern void zfs_init(void);
215 extern void zfs_fini(void);
217 uint_t zfs_fsyncer_key
;
218 extern uint_t rrw_tsd_key
;
219 static uint_t zfs_allow_log_key
;
221 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
222 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
223 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
229 } zfs_ioc_namecheck_t
;
232 POOL_CHECK_NONE
= 1 << 0,
233 POOL_CHECK_SUSPENDED
= 1 << 1,
234 POOL_CHECK_READONLY
= 1 << 2,
235 } zfs_ioc_poolcheck_t
;
237 typedef struct zfs_ioc_vec
{
238 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
239 zfs_ioc_func_t
*zvec_func
;
240 zfs_secpolicy_func_t
*zvec_secpolicy
;
241 zfs_ioc_namecheck_t zvec_namecheck
;
242 boolean_t zvec_allow_log
;
243 zfs_ioc_poolcheck_t zvec_pool_check
;
244 boolean_t zvec_smush_outnvlist
;
245 const char *zvec_name
;
248 /* This array is indexed by zfs_userquota_prop_t */
249 static const char *userquota_perms
[] = {
250 ZFS_DELEG_PERM_USERUSED
,
251 ZFS_DELEG_PERM_USERQUOTA
,
252 ZFS_DELEG_PERM_GROUPUSED
,
253 ZFS_DELEG_PERM_GROUPQUOTA
,
254 ZFS_DELEG_PERM_USEROBJUSED
,
255 ZFS_DELEG_PERM_USEROBJQUOTA
,
256 ZFS_DELEG_PERM_GROUPOBJUSED
,
257 ZFS_DELEG_PERM_GROUPOBJQUOTA
,
260 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
261 static int zfs_ioc_userobjspace_upgrade(zfs_cmd_t
*zc
);
262 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
264 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
266 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
268 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
269 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
272 history_str_free(char *buf
)
274 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
278 history_str_get(zfs_cmd_t
*zc
)
282 if (zc
->zc_history
== 0)
285 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
286 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
287 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
288 history_str_free(buf
);
292 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
298 * Check to see if the named dataset is currently defined as bootable
301 zfs_is_bootfs(const char *name
)
305 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
307 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
308 dmu_objset_rele(os
, FTAG
);
315 * Return non-zero if the spa version is less than requested version.
318 zfs_earlier_version(const char *name
, int version
)
322 if (spa_open(name
, &spa
, FTAG
) == 0) {
323 if (spa_version(spa
) < version
) {
324 spa_close(spa
, FTAG
);
327 spa_close(spa
, FTAG
);
333 * Return TRUE if the ZPL version is less than requested version.
336 zpl_earlier_version(const char *name
, int version
)
339 boolean_t rc
= B_TRUE
;
341 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
344 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
345 dmu_objset_rele(os
, FTAG
);
348 /* XXX reading from non-owned objset */
349 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
350 rc
= zplversion
< version
;
351 dmu_objset_rele(os
, FTAG
);
357 zfs_log_history(zfs_cmd_t
*zc
)
362 if ((buf
= history_str_get(zc
)) == NULL
)
365 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
366 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
367 (void) spa_history_log(spa
, buf
);
368 spa_close(spa
, FTAG
);
370 history_str_free(buf
);
374 * Policy for top-level read operations (list pools). Requires no privileges,
375 * and can be used in the local zone, as there is no associated dataset.
379 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
385 * Policy for dataset read operations (list children, get statistics). Requires
386 * no privileges, but must be visible in the local zone.
390 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
392 if (INGLOBALZONE(curproc
) ||
393 zone_dataset_visible(zc
->zc_name
, NULL
))
396 return (SET_ERROR(ENOENT
));
400 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
405 * The dataset must be visible by this zone -- check this first
406 * so they don't see EPERM on something they shouldn't know about.
408 if (!INGLOBALZONE(curproc
) &&
409 !zone_dataset_visible(dataset
, &writable
))
410 return (SET_ERROR(ENOENT
));
412 if (INGLOBALZONE(curproc
)) {
414 * If the fs is zoned, only root can access it from the
417 if (secpolicy_zfs(cr
) && zoned
)
418 return (SET_ERROR(EPERM
));
421 * If we are in a local zone, the 'zoned' property must be set.
424 return (SET_ERROR(EPERM
));
426 /* must be writable by this zone */
428 return (SET_ERROR(EPERM
));
434 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
438 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
439 return (SET_ERROR(ENOENT
));
441 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
445 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
449 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
450 return (SET_ERROR(ENOENT
));
452 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
456 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
457 const char *perm
, cred_t
*cr
)
461 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
463 error
= secpolicy_zfs(cr
);
465 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
471 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
478 * First do a quick check for root in the global zone, which
479 * is allowed to do all write_perms. This ensures that zfs_ioc_*
480 * will get to handle nonexistent datasets.
482 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
485 error
= dsl_pool_hold(name
, FTAG
, &dp
);
489 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
491 dsl_pool_rele(dp
, FTAG
);
495 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
497 dsl_dataset_rele(ds
, FTAG
);
498 dsl_pool_rele(dp
, FTAG
);
503 * Policy for setting the security label property.
505 * Returns 0 for success, non-zero for access and other errors.
508 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
511 char ds_hexsl
[MAXNAMELEN
];
512 bslabel_t ds_sl
, new_sl
;
513 boolean_t new_default
= FALSE
;
515 int needed_priv
= -1;
518 /* First get the existing dataset label. */
519 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
520 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
522 return (SET_ERROR(EPERM
));
524 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
527 /* The label must be translatable */
528 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
529 return (SET_ERROR(EINVAL
));
532 * In a non-global zone, disallow attempts to set a label that
533 * doesn't match that of the zone; otherwise no other checks
536 if (!INGLOBALZONE(curproc
)) {
537 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
538 return (SET_ERROR(EPERM
));
543 * For global-zone datasets (i.e., those whose zoned property is
544 * "off", verify that the specified new label is valid for the
547 if (dsl_prop_get_integer(name
,
548 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
549 return (SET_ERROR(EPERM
));
551 if (zfs_check_global_label(name
, strval
) != 0)
552 return (SET_ERROR(EPERM
));
556 * If the existing dataset label is nondefault, check if the
557 * dataset is mounted (label cannot be changed while mounted).
558 * Get the zfsvfs_t; if there isn't one, then the dataset isn't
559 * mounted (or isn't a dataset, doesn't exist, ...).
561 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
563 static char *setsl_tag
= "setsl_tag";
566 * Try to own the dataset; abort if there is any error,
567 * (e.g., already mounted, in use, or other error).
569 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
, B_TRUE
,
572 return (SET_ERROR(EPERM
));
574 dmu_objset_disown(os
, B_TRUE
, setsl_tag
);
577 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
581 if (hexstr_to_label(strval
, &new_sl
) != 0)
582 return (SET_ERROR(EPERM
));
584 if (blstrictdom(&ds_sl
, &new_sl
))
585 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
586 else if (blstrictdom(&new_sl
, &ds_sl
))
587 needed_priv
= PRIV_FILE_UPGRADE_SL
;
589 /* dataset currently has a default label */
591 needed_priv
= PRIV_FILE_UPGRADE_SL
;
595 if (needed_priv
!= -1)
596 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
599 return (SET_ERROR(ENOTSUP
));
600 #endif /* HAVE_MLSLABEL */
604 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
610 * Check permissions for special properties.
617 * Disallow setting of 'zoned' from within a local zone.
619 if (!INGLOBALZONE(curproc
))
620 return (SET_ERROR(EPERM
));
624 case ZFS_PROP_FILESYSTEM_LIMIT
:
625 case ZFS_PROP_SNAPSHOT_LIMIT
:
626 if (!INGLOBALZONE(curproc
)) {
628 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
630 * Unprivileged users are allowed to modify the
631 * limit on things *under* (ie. contained by)
632 * the thing they own.
634 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
636 return (SET_ERROR(EPERM
));
637 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
638 return (SET_ERROR(EPERM
));
642 case ZFS_PROP_MLSLABEL
:
643 if (!is_system_labeled())
644 return (SET_ERROR(EPERM
));
646 if (nvpair_value_string(propval
, &strval
) == 0) {
649 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
656 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
661 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
665 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
670 * permission to set permissions will be evaluated later in
671 * dsl_deleg_can_allow()
678 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
680 return (zfs_secpolicy_write_perms(zc
->zc_name
,
681 ZFS_DELEG_PERM_ROLLBACK
, cr
));
686 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
694 * Generate the current snapshot name from the given objsetid, then
695 * use that name for the secpolicy/zone checks.
697 cp
= strchr(zc
->zc_name
, '@');
699 return (SET_ERROR(EINVAL
));
700 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
704 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
706 dsl_pool_rele(dp
, FTAG
);
710 dsl_dataset_name(ds
, zc
->zc_name
);
712 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
713 ZFS_DELEG_PERM_SEND
, cr
);
714 dsl_dataset_rele(ds
, FTAG
);
715 dsl_pool_rele(dp
, FTAG
);
722 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
724 return (zfs_secpolicy_write_perms(zc
->zc_name
,
725 ZFS_DELEG_PERM_SEND
, cr
));
728 #ifdef HAVE_SMB_SHARE
731 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
736 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
737 NO_FOLLOW
, NULL
, &vp
)) != 0)
740 /* Now make sure mntpnt and dataset are ZFS */
742 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
743 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
744 zc
->zc_name
) != 0)) {
746 return (SET_ERROR(EPERM
));
750 return (dsl_deleg_access(zc
->zc_name
,
751 ZFS_DELEG_PERM_SHARE
, cr
));
753 #endif /* HAVE_SMB_SHARE */
756 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
758 #ifdef HAVE_SMB_SHARE
759 if (!INGLOBALZONE(curproc
))
760 return (SET_ERROR(EPERM
));
762 if (secpolicy_nfs(cr
) == 0) {
765 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
768 return (SET_ERROR(ENOTSUP
));
769 #endif /* HAVE_SMB_SHARE */
773 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
775 #ifdef HAVE_SMB_SHARE
776 if (!INGLOBALZONE(curproc
))
777 return (SET_ERROR(EPERM
));
779 if (secpolicy_smb(cr
) == 0) {
782 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
785 return (SET_ERROR(ENOTSUP
));
786 #endif /* HAVE_SMB_SHARE */
790 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
795 * Remove the @bla or /bla from the end of the name to get the parent.
797 (void) strncpy(parent
, datasetname
, parentsize
);
798 cp
= strrchr(parent
, '@');
802 cp
= strrchr(parent
, '/');
804 return (SET_ERROR(ENOENT
));
812 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
816 if ((error
= zfs_secpolicy_write_perms(name
,
817 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
820 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
825 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
827 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
831 * Destroying snapshots with delegated permissions requires
832 * descendant mount and destroy permissions.
836 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
839 nvpair_t
*pair
, *nextpair
;
842 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
843 return (SET_ERROR(EINVAL
));
844 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
846 nextpair
= nvlist_next_nvpair(snaps
, pair
);
847 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
848 if (error
== ENOENT
) {
850 * Ignore any snapshots that don't exist (we consider
851 * them "already destroyed"). Remove the name from the
852 * nvl here in case the snapshot is created between
853 * now and when we try to destroy it (in which case
854 * we don't want to destroy it since we haven't
855 * checked for permission).
857 fnvlist_remove_nvpair(snaps
, pair
);
868 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
870 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
873 if ((error
= zfs_secpolicy_write_perms(from
,
874 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
877 if ((error
= zfs_secpolicy_write_perms(from
,
878 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
881 if ((error
= zfs_get_parent(to
, parentname
,
882 sizeof (parentname
))) != 0)
885 if ((error
= zfs_secpolicy_write_perms(parentname
,
886 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
889 if ((error
= zfs_secpolicy_write_perms(parentname
,
890 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
898 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
900 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
905 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
908 dsl_dataset_t
*clone
;
911 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
912 ZFS_DELEG_PERM_PROMOTE
, cr
);
916 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
920 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
923 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
924 dsl_dataset_t
*origin
= NULL
;
928 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
929 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
931 dsl_dataset_rele(clone
, FTAG
);
932 dsl_pool_rele(dp
, FTAG
);
936 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
937 ZFS_DELEG_PERM_MOUNT
, cr
);
939 dsl_dataset_name(origin
, parentname
);
941 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
942 ZFS_DELEG_PERM_PROMOTE
, cr
);
944 dsl_dataset_rele(clone
, FTAG
);
945 dsl_dataset_rele(origin
, FTAG
);
947 dsl_pool_rele(dp
, FTAG
);
953 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
957 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
958 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
961 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
962 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
965 return (zfs_secpolicy_write_perms(zc
->zc_name
,
966 ZFS_DELEG_PERM_CREATE
, cr
));
971 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
973 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
977 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
979 return (zfs_secpolicy_write_perms(name
,
980 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
984 * Check for permission to create each snapshot in the nvlist.
988 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
994 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
995 return (SET_ERROR(EINVAL
));
996 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
997 pair
= nvlist_next_nvpair(snaps
, pair
)) {
998 char *name
= nvpair_name(pair
);
999 char *atp
= strchr(name
, '@');
1002 error
= SET_ERROR(EINVAL
);
1006 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
1015 * Check for permission to create each snapshot in the nvlist.
1019 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1024 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
1025 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1026 char *name
= nvpair_name(pair
);
1027 char *hashp
= strchr(name
, '#');
1029 if (hashp
== NULL
) {
1030 error
= SET_ERROR(EINVAL
);
1034 error
= zfs_secpolicy_write_perms(name
,
1035 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1045 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1047 nvpair_t
*pair
, *nextpair
;
1050 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1052 char *name
= nvpair_name(pair
);
1053 char *hashp
= strchr(name
, '#');
1054 nextpair
= nvlist_next_nvpair(innvl
, pair
);
1056 if (hashp
== NULL
) {
1057 error
= SET_ERROR(EINVAL
);
1062 error
= zfs_secpolicy_write_perms(name
,
1063 ZFS_DELEG_PERM_DESTROY
, cr
);
1065 if (error
== ENOENT
) {
1067 * Ignore any filesystems that don't exist (we consider
1068 * their bookmarks "already destroyed"). Remove
1069 * the name from the nvl here in case the filesystem
1070 * is created between now and when we try to destroy
1071 * the bookmark (in which case we don't want to
1072 * destroy it since we haven't checked for permission).
1074 fnvlist_remove_nvpair(innvl
, pair
);
1086 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1089 * Even root must have a proper TSD so that we know what pool
1092 if (tsd_get(zfs_allow_log_key
) == NULL
)
1093 return (SET_ERROR(EPERM
));
1098 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1100 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1104 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1105 sizeof (parentname
))) != 0)
1108 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1109 (error
= zfs_secpolicy_write_perms(origin
,
1110 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1113 if ((error
= zfs_secpolicy_write_perms(parentname
,
1114 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1117 return (zfs_secpolicy_write_perms(parentname
,
1118 ZFS_DELEG_PERM_MOUNT
, cr
));
1122 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1123 * SYS_CONFIG privilege, which is not available in a local zone.
1127 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1129 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1130 return (SET_ERROR(EPERM
));
1136 * Policy for object to name lookups.
1140 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1144 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1147 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1152 * Policy for fault injection. Requires all privileges.
1156 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1158 return (secpolicy_zinject(cr
));
1163 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1165 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1167 if (prop
== ZPROP_INVAL
) {
1168 if (!zfs_prop_user(zc
->zc_value
))
1169 return (SET_ERROR(EINVAL
));
1170 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1171 ZFS_DELEG_PERM_USERPROP
, cr
));
1173 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1179 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1181 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1185 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1186 return (SET_ERROR(EINVAL
));
1188 if (zc
->zc_value
[0] == 0) {
1190 * They are asking about a posix uid/gid. If it's
1191 * themself, allow it.
1193 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1194 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
||
1195 zc
->zc_objset_type
== ZFS_PROP_USEROBJUSED
||
1196 zc
->zc_objset_type
== ZFS_PROP_USEROBJQUOTA
) {
1197 if (zc
->zc_guid
== crgetuid(cr
))
1200 if (groupmember(zc
->zc_guid
, cr
))
1205 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1206 userquota_perms
[zc
->zc_objset_type
], cr
));
1210 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1212 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1216 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1217 return (SET_ERROR(EINVAL
));
1219 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1220 userquota_perms
[zc
->zc_objset_type
], cr
));
1225 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1227 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1233 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1239 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1241 return (SET_ERROR(EINVAL
));
1243 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1244 pair
= nvlist_next_nvpair(holds
, pair
)) {
1245 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1246 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1249 error
= zfs_secpolicy_write_perms(fsname
,
1250 ZFS_DELEG_PERM_HOLD
, cr
);
1259 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1264 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1265 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1266 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1267 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1270 error
= zfs_secpolicy_write_perms(fsname
,
1271 ZFS_DELEG_PERM_RELEASE
, cr
);
1279 * Policy for allowing temporary snapshots to be taken or released
1282 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1285 * A temporary snapshot is the same as a snapshot,
1286 * hold, destroy and release all rolled into one.
1287 * Delegated diff alone is sufficient that we allow this.
1291 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1292 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1295 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1297 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1299 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1301 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1306 zfs_secpolicy_load_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1308 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1309 ZFS_DELEG_PERM_LOAD_KEY
, cr
));
1313 zfs_secpolicy_change_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1315 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1316 ZFS_DELEG_PERM_CHANGE_KEY
, cr
));
1320 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1323 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1327 nvlist_t
*list
= NULL
;
1330 * Read in and unpack the user-supplied nvlist.
1333 return (SET_ERROR(EINVAL
));
1335 packed
= vmem_alloc(size
, KM_SLEEP
);
1337 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1339 vmem_free(packed
, size
);
1340 return (SET_ERROR(EFAULT
));
1343 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1344 vmem_free(packed
, size
);
1348 vmem_free(packed
, size
);
1355 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1356 * Entries will be removed from the end of the nvlist, and one int32 entry
1357 * named "N_MORE_ERRORS" will be added indicating how many entries were
1361 nvlist_smush(nvlist_t
*errors
, size_t max
)
1365 size
= fnvlist_size(errors
);
1368 nvpair_t
*more_errors
;
1372 return (SET_ERROR(ENOMEM
));
1374 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1375 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1378 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1380 fnvlist_remove_nvpair(errors
, pair
);
1382 size
= fnvlist_size(errors
);
1383 } while (size
> max
);
1385 fnvlist_remove_nvpair(errors
, more_errors
);
1386 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1387 ASSERT3U(fnvlist_size(errors
), <=, max
);
1394 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1396 char *packed
= NULL
;
1400 size
= fnvlist_size(nvl
);
1402 if (size
> zc
->zc_nvlist_dst_size
) {
1403 error
= SET_ERROR(ENOMEM
);
1405 packed
= fnvlist_pack(nvl
, &size
);
1406 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1407 size
, zc
->zc_iflags
) != 0)
1408 error
= SET_ERROR(EFAULT
);
1409 fnvlist_pack_free(packed
, size
);
1412 zc
->zc_nvlist_dst_size
= size
;
1413 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1418 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1423 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1426 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1427 dmu_objset_rele(os
, FTAG
);
1428 return (SET_ERROR(EINVAL
));
1431 mutex_enter(&os
->os_user_ptr_lock
);
1432 *zfvp
= dmu_objset_get_user(os
);
1433 /* bump s_active only when non-zero to prevent umount race */
1434 if (*zfvp
== NULL
|| (*zfvp
)->z_sb
== NULL
||
1435 !atomic_inc_not_zero(&((*zfvp
)->z_sb
->s_active
))) {
1436 error
= SET_ERROR(ESRCH
);
1438 mutex_exit(&os
->os_user_ptr_lock
);
1439 dmu_objset_rele(os
, FTAG
);
1444 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1445 * case its z_sb will be NULL, and it will be opened as the owner.
1446 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1447 * which prevents all inode ops from running.
1450 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1454 if (getzfsvfs(name
, zfvp
) != 0)
1455 error
= zfsvfs_create(name
, zfvp
);
1457 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1459 if ((*zfvp
)->z_unmounted
) {
1461 * XXX we could probably try again, since the unmounting
1462 * thread should be just about to disassociate the
1463 * objset from the zfsvfs.
1465 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1466 return (SET_ERROR(EBUSY
));
1473 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1475 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1478 deactivate_super(zfsvfs
->z_sb
);
1480 dmu_objset_disown(zfsvfs
->z_os
, B_TRUE
, zfsvfs
);
1481 zfsvfs_free(zfsvfs
);
1486 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1489 nvlist_t
*config
, *props
= NULL
;
1490 nvlist_t
*rootprops
= NULL
;
1491 nvlist_t
*zplprops
= NULL
;
1492 dsl_crypto_params_t
*dcp
= NULL
;
1494 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1495 zc
->zc_iflags
, &config
)))
1498 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1499 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1500 zc
->zc_iflags
, &props
))) {
1501 nvlist_free(config
);
1506 nvlist_t
*nvl
= NULL
;
1507 nvlist_t
*hidden_args
= NULL
;
1508 uint64_t version
= SPA_VERSION
;
1510 (void) nvlist_lookup_uint64(props
,
1511 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1512 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1513 error
= SET_ERROR(EINVAL
);
1514 goto pool_props_bad
;
1516 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1518 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1520 nvlist_free(config
);
1524 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1527 (void) nvlist_lookup_nvlist(props
, ZPOOL_HIDDEN_ARGS
,
1529 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
,
1530 rootprops
, hidden_args
, &dcp
);
1532 nvlist_free(config
);
1536 (void) nvlist_remove_all(props
, ZPOOL_HIDDEN_ARGS
);
1538 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1539 error
= zfs_fill_zplprops_root(version
, rootprops
,
1542 goto pool_props_bad
;
1545 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
, dcp
);
1548 * Set the remaining root properties
1550 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1551 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1552 (void) spa_destroy(zc
->zc_name
);
1555 nvlist_free(rootprops
);
1556 nvlist_free(zplprops
);
1557 nvlist_free(config
);
1559 dsl_crypto_params_free(dcp
, !!error
);
1565 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1568 zfs_log_history(zc
);
1569 error
= spa_destroy(zc
->zc_name
);
1575 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1577 nvlist_t
*config
, *props
= NULL
;
1581 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1582 zc
->zc_iflags
, &config
)) != 0)
1585 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1586 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1587 zc
->zc_iflags
, &props
))) {
1588 nvlist_free(config
);
1592 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1593 guid
!= zc
->zc_guid
)
1594 error
= SET_ERROR(EINVAL
);
1596 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1598 if (zc
->zc_nvlist_dst
!= 0) {
1601 if ((err
= put_nvlist(zc
, config
)) != 0)
1605 nvlist_free(config
);
1612 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1615 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1616 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1618 zfs_log_history(zc
);
1619 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1625 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1630 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1631 return (SET_ERROR(EEXIST
));
1633 error
= put_nvlist(zc
, configs
);
1635 nvlist_free(configs
);
1642 * zc_name name of the pool
1645 * zc_cookie real errno
1646 * zc_nvlist_dst config nvlist
1647 * zc_nvlist_dst_size size of config nvlist
1650 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1656 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1657 sizeof (zc
->zc_value
));
1659 if (config
!= NULL
) {
1660 ret
= put_nvlist(zc
, config
);
1661 nvlist_free(config
);
1664 * The config may be present even if 'error' is non-zero.
1665 * In this case we return success, and preserve the real errno
1668 zc
->zc_cookie
= error
;
1677 * Try to import the given pool, returning pool stats as appropriate so that
1678 * user land knows which devices are available and overall pool health.
1681 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1683 nvlist_t
*tryconfig
, *config
= NULL
;
1686 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1687 zc
->zc_iflags
, &tryconfig
)) != 0)
1690 config
= spa_tryimport(tryconfig
);
1692 nvlist_free(tryconfig
);
1695 return (SET_ERROR(EINVAL
));
1697 error
= put_nvlist(zc
, config
);
1698 nvlist_free(config
);
1705 * zc_name name of the pool
1706 * zc_cookie scan func (pool_scan_func_t)
1707 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1710 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1715 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1718 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1719 return (SET_ERROR(EINVAL
));
1721 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1722 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1723 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1724 error
= spa_scan_stop(spa
);
1726 error
= spa_scan(spa
, zc
->zc_cookie
);
1728 spa_close(spa
, FTAG
);
1734 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1739 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1742 spa_close(spa
, FTAG
);
1748 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1753 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1756 if (zc
->zc_cookie
< spa_version(spa
) ||
1757 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1758 spa_close(spa
, FTAG
);
1759 return (SET_ERROR(EINVAL
));
1762 spa_upgrade(spa
, zc
->zc_cookie
);
1763 spa_close(spa
, FTAG
);
1769 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1776 if ((size
= zc
->zc_history_len
) == 0)
1777 return (SET_ERROR(EINVAL
));
1779 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1782 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1783 spa_close(spa
, FTAG
);
1784 return (SET_ERROR(ENOTSUP
));
1787 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1788 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1789 &zc
->zc_history_len
, hist_buf
)) == 0) {
1790 error
= ddi_copyout(hist_buf
,
1791 (void *)(uintptr_t)zc
->zc_history
,
1792 zc
->zc_history_len
, zc
->zc_iflags
);
1795 spa_close(spa
, FTAG
);
1796 vmem_free(hist_buf
, size
);
1801 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1806 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1808 error
= spa_change_guid(spa
);
1809 spa_close(spa
, FTAG
);
1815 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1817 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1822 * zc_name name of filesystem
1823 * zc_obj object to find
1826 * zc_value name of object
1829 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1834 /* XXX reading from objset not owned */
1835 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1838 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1839 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1840 return (SET_ERROR(EINVAL
));
1842 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1843 sizeof (zc
->zc_value
));
1844 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1851 * zc_name name of filesystem
1852 * zc_obj object to find
1855 * zc_stat stats on object
1856 * zc_value path to object
1859 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1864 /* XXX reading from objset not owned */
1865 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1868 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1869 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1870 return (SET_ERROR(EINVAL
));
1872 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1873 sizeof (zc
->zc_value
));
1874 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1880 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1886 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1890 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1891 zc
->zc_iflags
, &config
);
1893 error
= spa_vdev_add(spa
, config
);
1894 nvlist_free(config
);
1896 spa_close(spa
, FTAG
);
1902 * zc_name name of the pool
1903 * zc_nvlist_conf nvlist of devices to remove
1904 * zc_cookie to stop the remove?
1907 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1912 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1915 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1916 spa_close(spa
, FTAG
);
1921 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1925 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1927 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1929 switch (zc
->zc_cookie
) {
1930 case VDEV_STATE_ONLINE
:
1931 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1934 case VDEV_STATE_OFFLINE
:
1935 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1938 case VDEV_STATE_FAULTED
:
1939 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1940 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
&&
1941 zc
->zc_obj
!= VDEV_AUX_EXTERNAL_PERSIST
)
1942 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1944 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1947 case VDEV_STATE_DEGRADED
:
1948 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1949 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1950 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1952 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1956 error
= SET_ERROR(EINVAL
);
1958 zc
->zc_cookie
= newstate
;
1959 spa_close(spa
, FTAG
);
1964 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1967 int replacing
= zc
->zc_cookie
;
1971 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1974 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1975 zc
->zc_iflags
, &config
)) == 0) {
1976 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1977 nvlist_free(config
);
1980 spa_close(spa
, FTAG
);
1985 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1990 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1993 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1995 spa_close(spa
, FTAG
);
2000 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
2003 nvlist_t
*config
, *props
= NULL
;
2005 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
2007 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2010 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2011 zc
->zc_iflags
, &config
))) {
2012 spa_close(spa
, FTAG
);
2016 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
2017 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2018 zc
->zc_iflags
, &props
))) {
2019 spa_close(spa
, FTAG
);
2020 nvlist_free(config
);
2024 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
2026 spa_close(spa
, FTAG
);
2028 nvlist_free(config
);
2035 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
2038 char *path
= zc
->zc_value
;
2039 uint64_t guid
= zc
->zc_guid
;
2042 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2046 error
= spa_vdev_setpath(spa
, guid
, path
);
2047 spa_close(spa
, FTAG
);
2052 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
2055 char *fru
= zc
->zc_value
;
2056 uint64_t guid
= zc
->zc_guid
;
2059 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2063 error
= spa_vdev_setfru(spa
, guid
, fru
);
2064 spa_close(spa
, FTAG
);
2069 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2074 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2076 if (zc
->zc_nvlist_dst
!= 0 &&
2077 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2078 dmu_objset_stats(os
, nv
);
2080 * NB: zvol_get_stats() will read the objset contents,
2081 * which we aren't supposed to do with a
2082 * DS_MODE_USER hold, because it could be
2083 * inconsistent. So this is a bit of a workaround...
2084 * XXX reading with out owning
2086 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2087 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2088 error
= zvol_get_stats(os
, nv
);
2096 error
= put_nvlist(zc
, nv
);
2105 * zc_name name of filesystem
2106 * zc_nvlist_dst_size size of buffer for property nvlist
2109 * zc_objset_stats stats
2110 * zc_nvlist_dst property nvlist
2111 * zc_nvlist_dst_size size of property nvlist
2114 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2119 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2121 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2122 dmu_objset_rele(os
, FTAG
);
2130 * zc_name name of filesystem
2131 * zc_nvlist_dst_size size of buffer for property nvlist
2134 * zc_nvlist_dst received property nvlist
2135 * zc_nvlist_dst_size size of received property nvlist
2137 * Gets received properties (distinct from local properties on or after
2138 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2139 * local property values.
2142 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2148 * Without this check, we would return local property values if the
2149 * caller has not already received properties on or after
2150 * SPA_VERSION_RECVD_PROPS.
2152 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2153 return (SET_ERROR(ENOTSUP
));
2155 if (zc
->zc_nvlist_dst
!= 0 &&
2156 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2157 error
= put_nvlist(zc
, nv
);
2165 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2171 * zfs_get_zplprop() will either find a value or give us
2172 * the default value (if there is one).
2174 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2176 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2182 * zc_name name of filesystem
2183 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2186 * zc_nvlist_dst zpl property nvlist
2187 * zc_nvlist_dst_size size of zpl property nvlist
2190 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2195 /* XXX reading without owning */
2196 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2199 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2202 * NB: nvl_add_zplprop() will read the objset contents,
2203 * which we aren't supposed to do with a DS_MODE_USER
2204 * hold, because it could be inconsistent.
2206 if (zc
->zc_nvlist_dst
!= 0 &&
2207 !zc
->zc_objset_stats
.dds_inconsistent
&&
2208 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2211 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2212 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2213 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2214 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2215 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2216 err
= put_nvlist(zc
, nv
);
2219 err
= SET_ERROR(ENOENT
);
2221 dmu_objset_rele(os
, FTAG
);
2226 dataset_name_hidden(const char *name
)
2229 * Skip over datasets that are not visible in this zone,
2230 * internal datasets (which have a $ in their name), and
2231 * temporary datasets (which have a % in their name).
2233 if (strchr(name
, '$') != NULL
)
2235 if (strchr(name
, '%') != NULL
)
2237 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2244 * zc_name name of filesystem
2245 * zc_cookie zap cursor
2246 * zc_nvlist_dst_size size of buffer for property nvlist
2249 * zc_name name of next filesystem
2250 * zc_cookie zap cursor
2251 * zc_objset_stats stats
2252 * zc_nvlist_dst property nvlist
2253 * zc_nvlist_dst_size size of property nvlist
2256 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2261 size_t orig_len
= strlen(zc
->zc_name
);
2264 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2265 if (error
== ENOENT
)
2266 error
= SET_ERROR(ESRCH
);
2270 p
= strrchr(zc
->zc_name
, '/');
2271 if (p
== NULL
|| p
[1] != '\0')
2272 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2273 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2276 error
= dmu_dir_list_next(os
,
2277 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2278 NULL
, &zc
->zc_cookie
);
2279 if (error
== ENOENT
)
2280 error
= SET_ERROR(ESRCH
);
2281 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2282 dmu_objset_rele(os
, FTAG
);
2285 * If it's an internal dataset (ie. with a '$' in its name),
2286 * don't try to get stats for it, otherwise we'll return ENOENT.
2288 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2289 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2290 if (error
== ENOENT
) {
2291 /* We lost a race with destroy, get the next one. */
2292 zc
->zc_name
[orig_len
] = '\0';
2301 * zc_name name of filesystem
2302 * zc_cookie zap cursor
2303 * zc_nvlist_dst_size size of buffer for property nvlist
2306 * zc_name name of next snapshot
2307 * zc_objset_stats stats
2308 * zc_nvlist_dst property nvlist
2309 * zc_nvlist_dst_size size of property nvlist
2312 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2317 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2319 return (error
== ENOENT
? ESRCH
: error
);
2323 * A dataset name of maximum length cannot have any snapshots,
2324 * so exit immediately.
2326 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2327 ZFS_MAX_DATASET_NAME_LEN
) {
2328 dmu_objset_rele(os
, FTAG
);
2329 return (SET_ERROR(ESRCH
));
2332 error
= dmu_snapshot_list_next(os
,
2333 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2334 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2337 if (error
== 0 && !zc
->zc_simple
) {
2339 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2341 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2345 error
= dmu_objset_from_ds(ds
, &ossnap
);
2347 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2348 dsl_dataset_rele(ds
, FTAG
);
2350 } else if (error
== ENOENT
) {
2351 error
= SET_ERROR(ESRCH
);
2354 dmu_objset_rele(os
, FTAG
);
2355 /* if we failed, undo the @ that we tacked on to zc_name */
2357 *strchr(zc
->zc_name
, '@') = '\0';
2362 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2364 const char *propname
= nvpair_name(pair
);
2366 unsigned int vallen
;
2369 zfs_userquota_prop_t type
;
2375 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2377 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2378 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2380 return (SET_ERROR(EINVAL
));
2384 * A correctly constructed propname is encoded as
2385 * userquota@<rid>-<domain>.
2387 if ((dash
= strchr(propname
, '-')) == NULL
||
2388 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2390 return (SET_ERROR(EINVAL
));
2397 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2399 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2400 zfsvfs_rele(zfsvfs
, FTAG
);
2407 * If the named property is one that has a special function to set its value,
2408 * return 0 on success and a positive error code on failure; otherwise if it is
2409 * not one of the special properties handled by this function, return -1.
2411 * XXX: It would be better for callers of the property interface if we handled
2412 * these special cases in dsl_prop.c (in the dsl layer).
2415 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2418 const char *propname
= nvpair_name(pair
);
2419 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2420 uint64_t intval
= 0;
2421 char *strval
= NULL
;
2424 if (prop
== ZPROP_INVAL
) {
2425 if (zfs_prop_userquota(propname
))
2426 return (zfs_prop_set_userquota(dsname
, pair
));
2430 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2432 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2433 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2437 /* all special properties are numeric except for keylocation */
2438 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
) {
2439 strval
= fnvpair_value_string(pair
);
2441 intval
= fnvpair_value_uint64(pair
);
2445 case ZFS_PROP_QUOTA
:
2446 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2448 case ZFS_PROP_REFQUOTA
:
2449 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2451 case ZFS_PROP_FILESYSTEM_LIMIT
:
2452 case ZFS_PROP_SNAPSHOT_LIMIT
:
2453 if (intval
== UINT64_MAX
) {
2454 /* clearing the limit, just do it */
2457 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2460 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2461 * default path to set the value in the nvlist.
2466 case ZFS_PROP_KEYLOCATION
:
2467 err
= dsl_crypto_can_set_keylocation(dsname
, strval
);
2470 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2471 * default path to set the value in the nvlist.
2476 case ZFS_PROP_RESERVATION
:
2477 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2479 case ZFS_PROP_REFRESERVATION
:
2480 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2482 case ZFS_PROP_VOLSIZE
:
2483 err
= zvol_set_volsize(dsname
, intval
);
2485 case ZFS_PROP_SNAPDEV
:
2486 err
= zvol_set_snapdev(dsname
, source
, intval
);
2488 case ZFS_PROP_VOLMODE
:
2489 err
= zvol_set_volmode(dsname
, source
, intval
);
2491 case ZFS_PROP_VERSION
:
2495 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2498 err
= zfs_set_version(zfsvfs
, intval
);
2499 zfsvfs_rele(zfsvfs
, FTAG
);
2501 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2504 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2505 (void) strcpy(zc
->zc_name
, dsname
);
2506 (void) zfs_ioc_userspace_upgrade(zc
);
2507 (void) zfs_ioc_userobjspace_upgrade(zc
);
2508 kmem_free(zc
, sizeof (zfs_cmd_t
));
2520 * This function is best effort. If it fails to set any of the given properties,
2521 * it continues to set as many as it can and returns the last error
2522 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2523 * with the list of names of all the properties that failed along with the
2524 * corresponding error numbers.
2526 * If every property is set successfully, zero is returned and errlist is not
2530 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2539 nvlist_t
*genericnvl
= fnvlist_alloc();
2540 nvlist_t
*retrynvl
= fnvlist_alloc();
2543 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2544 const char *propname
= nvpair_name(pair
);
2545 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2548 /* decode the property value */
2550 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2552 attrs
= fnvpair_value_nvlist(pair
);
2553 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2555 err
= SET_ERROR(EINVAL
);
2558 /* Validate value type */
2559 if (err
== 0 && source
== ZPROP_SRC_INHERITED
) {
2560 /* inherited properties are expected to be booleans */
2561 if (nvpair_type(propval
) != DATA_TYPE_BOOLEAN
)
2562 err
= SET_ERROR(EINVAL
);
2563 } else if (err
== 0 && prop
== ZPROP_INVAL
) {
2564 if (zfs_prop_user(propname
)) {
2565 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2566 err
= SET_ERROR(EINVAL
);
2567 } else if (zfs_prop_userquota(propname
)) {
2568 if (nvpair_type(propval
) !=
2569 DATA_TYPE_UINT64_ARRAY
)
2570 err
= SET_ERROR(EINVAL
);
2572 err
= SET_ERROR(EINVAL
);
2574 } else if (err
== 0) {
2575 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2576 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2577 err
= SET_ERROR(EINVAL
);
2578 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2581 intval
= fnvpair_value_uint64(propval
);
2583 switch (zfs_prop_get_type(prop
)) {
2584 case PROP_TYPE_NUMBER
:
2586 case PROP_TYPE_STRING
:
2587 err
= SET_ERROR(EINVAL
);
2589 case PROP_TYPE_INDEX
:
2590 if (zfs_prop_index_to_string(prop
,
2591 intval
, &unused
) != 0)
2592 err
= SET_ERROR(EINVAL
);
2596 "unknown property type");
2599 err
= SET_ERROR(EINVAL
);
2603 /* Validate permissions */
2605 err
= zfs_check_settable(dsname
, pair
, CRED());
2608 if (source
== ZPROP_SRC_INHERITED
)
2609 err
= -1; /* does not need special handling */
2611 err
= zfs_prop_set_special(dsname
, source
,
2615 * For better performance we build up a list of
2616 * properties to set in a single transaction.
2618 err
= nvlist_add_nvpair(genericnvl
, pair
);
2619 } else if (err
!= 0 && nvl
!= retrynvl
) {
2621 * This may be a spurious error caused by
2622 * receiving quota and reservation out of order.
2623 * Try again in a second pass.
2625 err
= nvlist_add_nvpair(retrynvl
, pair
);
2630 if (errlist
!= NULL
)
2631 fnvlist_add_int32(errlist
, propname
, err
);
2636 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2641 if (!nvlist_empty(genericnvl
) &&
2642 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2644 * If this fails, we still want to set as many properties as we
2645 * can, so try setting them individually.
2648 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2649 const char *propname
= nvpair_name(pair
);
2653 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2655 attrs
= fnvpair_value_nvlist(pair
);
2656 propval
= fnvlist_lookup_nvpair(attrs
,
2660 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2661 strval
= fnvpair_value_string(propval
);
2662 err
= dsl_prop_set_string(dsname
, propname
,
2664 } else if (nvpair_type(propval
) == DATA_TYPE_BOOLEAN
) {
2665 err
= dsl_prop_inherit(dsname
, propname
,
2668 intval
= fnvpair_value_uint64(propval
);
2669 err
= dsl_prop_set_int(dsname
, propname
, source
,
2674 if (errlist
!= NULL
) {
2675 fnvlist_add_int32(errlist
, propname
,
2682 nvlist_free(genericnvl
);
2683 nvlist_free(retrynvl
);
2689 * Check that all the properties are valid user properties.
2692 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2694 nvpair_t
*pair
= NULL
;
2697 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2698 const char *propname
= nvpair_name(pair
);
2700 if (!zfs_prop_user(propname
) ||
2701 nvpair_type(pair
) != DATA_TYPE_STRING
)
2702 return (SET_ERROR(EINVAL
));
2704 if ((error
= zfs_secpolicy_write_perms(fsname
,
2705 ZFS_DELEG_PERM_USERPROP
, CRED())))
2708 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2709 return (SET_ERROR(ENAMETOOLONG
));
2711 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2712 return (SET_ERROR(E2BIG
));
2718 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2722 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2725 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2726 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2729 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2734 clear_received_props(const char *dsname
, nvlist_t
*props
,
2738 nvlist_t
*cleared_props
= NULL
;
2739 props_skip(props
, skipped
, &cleared_props
);
2740 if (!nvlist_empty(cleared_props
)) {
2742 * Acts on local properties until the dataset has received
2743 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2745 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2746 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2747 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2749 nvlist_free(cleared_props
);
2755 * zc_name name of filesystem
2756 * zc_value name of property to set
2757 * zc_nvlist_src{_size} nvlist of properties to apply
2758 * zc_cookie received properties flag
2761 * zc_nvlist_dst{_size} error for each unapplied received property
2764 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2767 boolean_t received
= zc
->zc_cookie
;
2768 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2773 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2774 zc
->zc_iflags
, &nvl
)) != 0)
2778 nvlist_t
*origprops
;
2780 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2781 (void) clear_received_props(zc
->zc_name
,
2783 nvlist_free(origprops
);
2786 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2789 errors
= fnvlist_alloc();
2791 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2793 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2794 (void) put_nvlist(zc
, errors
);
2797 nvlist_free(errors
);
2804 * zc_name name of filesystem
2805 * zc_value name of property to inherit
2806 * zc_cookie revert to received value if TRUE
2811 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2813 const char *propname
= zc
->zc_value
;
2814 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2815 boolean_t received
= zc
->zc_cookie
;
2816 zprop_source_t source
= (received
2817 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2818 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2826 * Only check this in the non-received case. We want to allow
2827 * 'inherit -S' to revert non-inheritable properties like quota
2828 * and reservation to the received or default values even though
2829 * they are not considered inheritable.
2831 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2832 return (SET_ERROR(EINVAL
));
2835 if (prop
== ZPROP_INVAL
) {
2836 if (!zfs_prop_user(propname
))
2837 return (SET_ERROR(EINVAL
));
2839 type
= PROP_TYPE_STRING
;
2840 } else if (prop
== ZFS_PROP_VOLSIZE
|| prop
== ZFS_PROP_VERSION
) {
2841 return (SET_ERROR(EINVAL
));
2843 type
= zfs_prop_get_type(prop
);
2847 * zfs_prop_set_special() expects properties in the form of an
2848 * nvpair with type info.
2850 dummy
= fnvlist_alloc();
2853 case PROP_TYPE_STRING
:
2854 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2856 case PROP_TYPE_NUMBER
:
2857 case PROP_TYPE_INDEX
:
2858 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2861 err
= SET_ERROR(EINVAL
);
2865 pair
= nvlist_next_nvpair(dummy
, NULL
);
2867 err
= SET_ERROR(EINVAL
);
2869 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2870 if (err
== -1) /* property is not "special", needs handling */
2871 err
= dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
,
2881 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2888 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2889 zc
->zc_iflags
, &props
)))
2893 * If the only property is the configfile, then just do a spa_lookup()
2894 * to handle the faulted case.
2896 pair
= nvlist_next_nvpair(props
, NULL
);
2897 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2898 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2899 nvlist_next_nvpair(props
, pair
) == NULL
) {
2900 mutex_enter(&spa_namespace_lock
);
2901 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2902 spa_configfile_set(spa
, props
, B_FALSE
);
2903 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2905 mutex_exit(&spa_namespace_lock
);
2912 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2917 error
= spa_prop_set(spa
, props
);
2920 spa_close(spa
, FTAG
);
2926 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2930 nvlist_t
*nvp
= NULL
;
2932 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2934 * If the pool is faulted, there may be properties we can still
2935 * get (such as altroot and cachefile), so attempt to get them
2938 mutex_enter(&spa_namespace_lock
);
2939 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2940 error
= spa_prop_get(spa
, &nvp
);
2941 mutex_exit(&spa_namespace_lock
);
2943 error
= spa_prop_get(spa
, &nvp
);
2944 spa_close(spa
, FTAG
);
2947 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2948 error
= put_nvlist(zc
, nvp
);
2950 error
= SET_ERROR(EFAULT
);
2958 * zc_name name of filesystem
2959 * zc_nvlist_src{_size} nvlist of delegated permissions
2960 * zc_perm_action allow/unallow flag
2965 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2968 nvlist_t
*fsaclnv
= NULL
;
2970 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2971 zc
->zc_iflags
, &fsaclnv
)) != 0)
2975 * Verify nvlist is constructed correctly
2977 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2978 nvlist_free(fsaclnv
);
2979 return (SET_ERROR(EINVAL
));
2983 * If we don't have PRIV_SYS_MOUNT, then validate
2984 * that user is allowed to hand out each permission in
2988 error
= secpolicy_zfs(CRED());
2990 if (zc
->zc_perm_action
== B_FALSE
) {
2991 error
= dsl_deleg_can_allow(zc
->zc_name
,
2994 error
= dsl_deleg_can_unallow(zc
->zc_name
,
3000 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
3002 nvlist_free(fsaclnv
);
3008 * zc_name name of filesystem
3011 * zc_nvlist_src{_size} nvlist of delegated permissions
3014 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
3019 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
3020 error
= put_nvlist(zc
, nvp
);
3029 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
3031 zfs_creat_t
*zct
= arg
;
3033 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
3036 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
3040 * os parent objset pointer (NULL if root fs)
3041 * fuids_ok fuids allowed in this version of the spa?
3042 * sa_ok SAs allowed in this version of the spa?
3043 * createprops list of properties requested by creator
3046 * zplprops values for the zplprops we attach to the master node object
3047 * is_ci true if requested file system will be purely case-insensitive
3049 * Determine the settings for utf8only, normalization and
3050 * casesensitivity. Specific values may have been requested by the
3051 * creator and/or we can inherit values from the parent dataset. If
3052 * the file system is of too early a vintage, a creator can not
3053 * request settings for these properties, even if the requested
3054 * setting is the default value. We don't actually want to create dsl
3055 * properties for these, so remove them from the source nvlist after
3059 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
3060 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
3061 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3063 uint64_t sense
= ZFS_PROP_UNDEFINED
;
3064 uint64_t norm
= ZFS_PROP_UNDEFINED
;
3065 uint64_t u8
= ZFS_PROP_UNDEFINED
;
3068 ASSERT(zplprops
!= NULL
);
3070 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
3071 return (SET_ERROR(EINVAL
));
3074 * Pull out creator prop choices, if any.
3077 (void) nvlist_lookup_uint64(createprops
,
3078 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
3079 (void) nvlist_lookup_uint64(createprops
,
3080 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
3081 (void) nvlist_remove_all(createprops
,
3082 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3083 (void) nvlist_lookup_uint64(createprops
,
3084 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3085 (void) nvlist_remove_all(createprops
,
3086 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3087 (void) nvlist_lookup_uint64(createprops
,
3088 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3089 (void) nvlist_remove_all(createprops
,
3090 zfs_prop_to_name(ZFS_PROP_CASE
));
3094 * If the zpl version requested is whacky or the file system
3095 * or pool is version is too "young" to support normalization
3096 * and the creator tried to set a value for one of the props,
3099 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3100 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3101 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3102 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3103 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3104 sense
!= ZFS_PROP_UNDEFINED
)))
3105 return (SET_ERROR(ENOTSUP
));
3108 * Put the version in the zplprops
3110 VERIFY(nvlist_add_uint64(zplprops
,
3111 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3113 if (norm
== ZFS_PROP_UNDEFINED
&&
3114 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3116 VERIFY(nvlist_add_uint64(zplprops
,
3117 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3120 * If we're normalizing, names must always be valid UTF-8 strings.
3124 if (u8
== ZFS_PROP_UNDEFINED
&&
3125 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3127 VERIFY(nvlist_add_uint64(zplprops
,
3128 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3130 if (sense
== ZFS_PROP_UNDEFINED
&&
3131 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3133 VERIFY(nvlist_add_uint64(zplprops
,
3134 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3137 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3143 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3144 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3146 boolean_t fuids_ok
, sa_ok
;
3147 uint64_t zplver
= ZPL_VERSION
;
3148 objset_t
*os
= NULL
;
3149 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3155 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3156 cp
= strrchr(parentname
, '/');
3160 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3163 spa_vers
= spa_version(spa
);
3164 spa_close(spa
, FTAG
);
3166 zplver
= zfs_zpl_version_map(spa_vers
);
3167 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3168 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3171 * Open parent object set so we can inherit zplprop values.
3173 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3176 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3178 dmu_objset_rele(os
, FTAG
);
3183 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3184 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3188 uint64_t zplver
= ZPL_VERSION
;
3191 zplver
= zfs_zpl_version_map(spa_vers
);
3192 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3193 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3195 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3196 createprops
, zplprops
, is_ci
);
3202 * "type" -> dmu_objset_type_t (int32)
3203 * (optional) "props" -> { prop -> value }
3204 * (optional) "hidden_args" -> { "wkeydata" -> value }
3205 * raw uint8_t array of encryption wrapping key data (32 bytes)
3208 * outnvl: propname -> error code (int32)
3211 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3214 zfs_creat_t zct
= { 0 };
3215 nvlist_t
*nvprops
= NULL
;
3216 nvlist_t
*hidden_args
= NULL
;
3217 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3219 dmu_objset_type_t type
;
3220 boolean_t is_insensitive
= B_FALSE
;
3221 dsl_crypto_params_t
*dcp
= NULL
;
3223 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3224 return (SET_ERROR(EINVAL
));
3226 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3227 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
3231 cbfunc
= zfs_create_cb
;
3235 cbfunc
= zvol_create_cb
;
3242 if (strchr(fsname
, '@') ||
3243 strchr(fsname
, '%'))
3244 return (SET_ERROR(EINVAL
));
3246 zct
.zct_props
= nvprops
;
3249 return (SET_ERROR(EINVAL
));
3251 if (type
== DMU_OST_ZVOL
) {
3252 uint64_t volsize
, volblocksize
;
3254 if (nvprops
== NULL
)
3255 return (SET_ERROR(EINVAL
));
3256 if (nvlist_lookup_uint64(nvprops
,
3257 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3258 return (SET_ERROR(EINVAL
));
3260 if ((error
= nvlist_lookup_uint64(nvprops
,
3261 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3262 &volblocksize
)) != 0 && error
!= ENOENT
)
3263 return (SET_ERROR(EINVAL
));
3266 volblocksize
= zfs_prop_default_numeric(
3267 ZFS_PROP_VOLBLOCKSIZE
);
3269 if ((error
= zvol_check_volblocksize(fsname
,
3270 volblocksize
)) != 0 ||
3271 (error
= zvol_check_volsize(volsize
,
3272 volblocksize
)) != 0)
3274 } else if (type
== DMU_OST_ZFS
) {
3278 * We have to have normalization and
3279 * case-folding flags correct when we do the
3280 * file system creation, so go figure them out
3283 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3284 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3285 error
= zfs_fill_zplprops(fsname
, nvprops
,
3286 zct
.zct_zplprops
, &is_insensitive
);
3288 nvlist_free(zct
.zct_zplprops
);
3293 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, nvprops
,
3296 nvlist_free(zct
.zct_zplprops
);
3300 error
= dmu_objset_create(fsname
, type
,
3301 is_insensitive
? DS_FLAG_CI_DATASET
: 0, dcp
, cbfunc
, &zct
);
3303 nvlist_free(zct
.zct_zplprops
);
3304 dsl_crypto_params_free(dcp
, !!error
);
3307 * It would be nice to do this atomically.
3310 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3317 * Volumes will return EBUSY and cannot be destroyed
3318 * until all asynchronous minor handling has completed.
3319 * Wait for the spa_zvol_taskq to drain then retry.
3321 error2
= dsl_destroy_head(fsname
);
3322 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3323 error2
= spa_open(fsname
, &spa
, FTAG
);
3325 taskq_wait(spa
->spa_zvol_taskq
);
3326 spa_close(spa
, FTAG
);
3328 error2
= dsl_destroy_head(fsname
);
3337 * "origin" -> name of origin snapshot
3338 * (optional) "props" -> { prop -> value }
3339 * (optional) "hidden_args" -> { "wkeydata" -> value }
3340 * raw uint8_t array of encryption wrapping key data (32 bytes)
3344 * outnvl: propname -> error code (int32)
3347 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3350 nvlist_t
*nvprops
= NULL
;
3353 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3354 return (SET_ERROR(EINVAL
));
3355 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3357 if (strchr(fsname
, '@') ||
3358 strchr(fsname
, '%'))
3359 return (SET_ERROR(EINVAL
));
3361 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3362 return (SET_ERROR(EINVAL
));
3364 error
= dmu_objset_clone(fsname
, origin_name
);
3367 * It would be nice to do this atomically.
3370 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3373 (void) dsl_destroy_head(fsname
);
3380 * "snaps" -> { snapshot1, snapshot2 }
3381 * (optional) "props" -> { prop -> value (string) }
3384 * outnvl: snapshot -> error code (int32)
3387 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3390 nvlist_t
*props
= NULL
;
3392 nvpair_t
*pair
, *pair2
;
3394 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3395 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3398 if (!nvlist_empty(props
) &&
3399 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3400 return (SET_ERROR(ENOTSUP
));
3402 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3403 return (SET_ERROR(EINVAL
));
3404 poollen
= strlen(poolname
);
3405 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3406 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3407 const char *name
= nvpair_name(pair
);
3408 const char *cp
= strchr(name
, '@');
3411 * The snap name must contain an @, and the part after it must
3412 * contain only valid characters.
3415 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3416 return (SET_ERROR(EINVAL
));
3419 * The snap must be in the specified pool.
3421 if (strncmp(name
, poolname
, poollen
) != 0 ||
3422 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3423 return (SET_ERROR(EXDEV
));
3425 /* This must be the only snap of this fs. */
3426 for (pair2
= nvlist_next_nvpair(snaps
, pair
);
3427 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3428 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3430 return (SET_ERROR(EXDEV
));
3435 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3441 * innvl: "message" -> string
3445 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3453 * The poolname in the ioctl is not set, we get it from the TSD,
3454 * which was set at the end of the last successful ioctl that allows
3455 * logging. The secpolicy func already checked that it is set.
3456 * Only one log ioctl is allowed after each successful ioctl, so
3457 * we clear the TSD here.
3459 poolname
= tsd_get(zfs_allow_log_key
);
3460 if (poolname
== NULL
)
3461 return (SET_ERROR(EINVAL
));
3462 (void) tsd_set(zfs_allow_log_key
, NULL
);
3463 error
= spa_open(poolname
, &spa
, FTAG
);
3468 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3469 spa_close(spa
, FTAG
);
3470 return (SET_ERROR(EINVAL
));
3473 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3474 spa_close(spa
, FTAG
);
3475 return (SET_ERROR(ENOTSUP
));
3478 error
= spa_history_log(spa
, message
);
3479 spa_close(spa
, FTAG
);
3484 * The dp_config_rwlock must not be held when calling this, because the
3485 * unmount may need to write out data.
3487 * This function is best-effort. Callers must deal gracefully if it
3488 * remains mounted (or is remounted after this call).
3490 * Returns 0 if the argument is not a snapshot, or it is not currently a
3491 * filesystem, or we were able to unmount it. Returns error code otherwise.
3494 zfs_unmount_snap(const char *snapname
)
3498 if (strchr(snapname
, '@') == NULL
)
3501 err
= zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3502 if (err
!= 0 && err
!= ENOENT
)
3503 return (SET_ERROR(err
));
3510 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3512 return (zfs_unmount_snap(snapname
));
3516 * When a clone is destroyed, its origin may also need to be destroyed,
3517 * in which case it must be unmounted. This routine will do that unmount
3521 zfs_destroy_unmount_origin(const char *fsname
)
3527 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3530 ds
= dmu_objset_ds(os
);
3531 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3532 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3533 dsl_dataset_name(ds
->ds_prev
, originname
);
3534 dmu_objset_rele(os
, FTAG
);
3535 (void) zfs_unmount_snap(originname
);
3537 dmu_objset_rele(os
, FTAG
);
3543 * "snaps" -> { snapshot1, snapshot2 }
3544 * (optional boolean) "defer"
3547 * outnvl: snapshot -> error code (int32)
3551 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3557 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3558 return (SET_ERROR(EINVAL
));
3559 defer
= nvlist_exists(innvl
, "defer");
3561 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3562 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3563 (void) zfs_unmount_snap(nvpair_name(pair
));
3566 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3570 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3571 * All bookmarks must be in the same pool.
3574 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3577 * outnvl: bookmark -> error code (int32)
3582 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3584 nvpair_t
*pair
, *pair2
;
3586 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
3587 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3591 * Verify the snapshot argument.
3593 if (nvpair_value_string(pair
, &snap_name
) != 0)
3594 return (SET_ERROR(EINVAL
));
3597 /* Verify that the keys (bookmarks) are unique */
3598 for (pair2
= nvlist_next_nvpair(innvl
, pair
);
3599 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3600 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3601 return (SET_ERROR(EINVAL
));
3605 return (dsl_bookmark_create(innvl
, outnvl
));
3610 * property 1, property 2, ...
3614 * bookmark name 1 -> { property 1, property 2, ... },
3615 * bookmark name 2 -> { property 1, property 2, ... }
3620 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3622 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3627 * bookmark name 1, bookmark name 2
3630 * outnvl: bookmark -> error code (int32)
3634 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3640 poollen
= strlen(poolname
);
3641 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
3642 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3643 const char *name
= nvpair_name(pair
);
3644 const char *cp
= strchr(name
, '#');
3647 * The bookmark name must contain an #, and the part after it
3648 * must contain only valid characters.
3651 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3652 return (SET_ERROR(EINVAL
));
3655 * The bookmark must be in the specified pool.
3657 if (strncmp(name
, poolname
, poollen
) != 0 ||
3658 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3659 return (SET_ERROR(EXDEV
));
3662 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3668 * zc_name name of dataset to destroy
3669 * zc_objset_type type of objset
3670 * zc_defer_destroy mark for deferred destroy
3675 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3679 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3680 err
= zfs_unmount_snap(zc
->zc_name
);
3685 if (strchr(zc
->zc_name
, '@')) {
3686 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3688 err
= dsl_destroy_head(zc
->zc_name
);
3689 if (err
== EEXIST
) {
3691 * It is possible that the given DS may have
3692 * hidden child (%recv) datasets - "leftovers"
3693 * resulting from the previously interrupted
3696 * 6 extra bytes for /%recv
3698 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3700 if (snprintf(namebuf
, sizeof (namebuf
), "%s/%s",
3701 zc
->zc_name
, recv_clone_name
) >=
3703 return (SET_ERROR(EINVAL
));
3706 * Try to remove the hidden child (%recv) and after
3707 * that try to remove the target dataset.
3708 * If the hidden child (%recv) does not exist
3709 * the original error (EEXIST) will be returned
3711 err
= dsl_destroy_head(namebuf
);
3713 err
= dsl_destroy_head(zc
->zc_name
);
3714 else if (err
== ENOENT
)
3715 err
= SET_ERROR(EEXIST
);
3723 * fsname is name of dataset to rollback (to most recent snapshot)
3725 * innvl may contain name of expected target snapshot
3727 * outnvl: "target" -> name of most recent snapshot
3732 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3736 char *target
= NULL
;
3739 (void) nvlist_lookup_string(innvl
, "target", &target
);
3740 if (target
!= NULL
) {
3741 int fslen
= strlen(fsname
);
3743 if (strncmp(fsname
, target
, fslen
) != 0)
3744 return (SET_ERROR(EINVAL
));
3745 if (target
[fslen
] != '@')
3746 return (SET_ERROR(EINVAL
));
3749 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3752 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3753 error
= zfs_suspend_fs(zfsvfs
);
3757 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3759 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3760 error
= error
? error
: resume_err
;
3762 deactivate_super(zfsvfs
->z_sb
);
3763 } else if ((zv
= zvol_suspend(fsname
)) != NULL
) {
3764 error
= dsl_dataset_rollback(fsname
, target
, zvol_tag(zv
),
3768 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3774 recursive_unmount(const char *fsname
, void *arg
)
3776 const char *snapname
= arg
;
3780 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3781 error
= zfs_unmount_snap(fullname
);
3789 * zc_name old name of dataset
3790 * zc_value new name of dataset
3791 * zc_cookie recursive flag (only valid for snapshots)
3796 zfs_ioc_rename(zfs_cmd_t
*zc
)
3798 boolean_t recursive
= zc
->zc_cookie
& 1;
3801 /* "zfs rename" from and to ...%recv datasets should both fail */
3802 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
3803 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3804 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
3805 dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3806 strchr(zc
->zc_name
, '%') || strchr(zc
->zc_value
, '%'))
3807 return (SET_ERROR(EINVAL
));
3809 at
= strchr(zc
->zc_name
, '@');
3811 /* snaps must be in same fs */
3814 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3815 return (SET_ERROR(EXDEV
));
3817 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3818 error
= dmu_objset_find(zc
->zc_name
,
3819 recursive_unmount
, at
+ 1,
3820 recursive
? DS_FIND_CHILDREN
: 0);
3826 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3827 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3832 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3837 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3839 const char *propname
= nvpair_name(pair
);
3840 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3841 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3845 if (prop
== ZPROP_INVAL
) {
3846 if (zfs_prop_user(propname
)) {
3847 if ((err
= zfs_secpolicy_write_perms(dsname
,
3848 ZFS_DELEG_PERM_USERPROP
, cr
)))
3853 if (!issnap
&& zfs_prop_userquota(propname
)) {
3854 const char *perm
= NULL
;
3855 const char *uq_prefix
=
3856 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3857 const char *gq_prefix
=
3858 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3859 const char *uiq_prefix
=
3860 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
];
3861 const char *giq_prefix
=
3862 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
];
3864 if (strncmp(propname
, uq_prefix
,
3865 strlen(uq_prefix
)) == 0) {
3866 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3867 } else if (strncmp(propname
, uiq_prefix
,
3868 strlen(uiq_prefix
)) == 0) {
3869 perm
= ZFS_DELEG_PERM_USEROBJQUOTA
;
3870 } else if (strncmp(propname
, gq_prefix
,
3871 strlen(gq_prefix
)) == 0) {
3872 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3873 } else if (strncmp(propname
, giq_prefix
,
3874 strlen(giq_prefix
)) == 0) {
3875 perm
= ZFS_DELEG_PERM_GROUPOBJQUOTA
;
3877 /* USERUSED and GROUPUSED are read-only */
3878 return (SET_ERROR(EINVAL
));
3881 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3886 return (SET_ERROR(EINVAL
));
3890 return (SET_ERROR(EINVAL
));
3892 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3894 * dsl_prop_get_all_impl() returns properties in this
3898 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3899 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3904 * Check that this value is valid for this pool version
3907 case ZFS_PROP_COMPRESSION
:
3909 * If the user specified gzip compression, make sure
3910 * the SPA supports it. We ignore any errors here since
3911 * we'll catch them later.
3913 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3914 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3915 intval
<= ZIO_COMPRESS_GZIP_9
&&
3916 zfs_earlier_version(dsname
,
3917 SPA_VERSION_GZIP_COMPRESSION
)) {
3918 return (SET_ERROR(ENOTSUP
));
3921 if (intval
== ZIO_COMPRESS_ZLE
&&
3922 zfs_earlier_version(dsname
,
3923 SPA_VERSION_ZLE_COMPRESSION
))
3924 return (SET_ERROR(ENOTSUP
));
3926 if (intval
== ZIO_COMPRESS_LZ4
) {
3929 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3932 if (!spa_feature_is_enabled(spa
,
3933 SPA_FEATURE_LZ4_COMPRESS
)) {
3934 spa_close(spa
, FTAG
);
3935 return (SET_ERROR(ENOTSUP
));
3937 spa_close(spa
, FTAG
);
3941 * If this is a bootable dataset then
3942 * verify that the compression algorithm
3943 * is supported for booting. We must return
3944 * something other than ENOTSUP since it
3945 * implies a downrev pool version.
3947 if (zfs_is_bootfs(dsname
) &&
3948 !BOOTFS_COMPRESS_VALID(intval
)) {
3949 return (SET_ERROR(ERANGE
));
3954 case ZFS_PROP_COPIES
:
3955 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3956 return (SET_ERROR(ENOTSUP
));
3959 case ZFS_PROP_VOLBLOCKSIZE
:
3960 case ZFS_PROP_RECORDSIZE
:
3961 /* Record sizes above 128k need the feature to be enabled */
3962 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3963 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3967 * We don't allow setting the property above 1MB,
3968 * unless the tunable has been changed.
3970 if (intval
> zfs_max_recordsize
||
3971 intval
> SPA_MAXBLOCKSIZE
)
3972 return (SET_ERROR(ERANGE
));
3974 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3977 if (!spa_feature_is_enabled(spa
,
3978 SPA_FEATURE_LARGE_BLOCKS
)) {
3979 spa_close(spa
, FTAG
);
3980 return (SET_ERROR(ENOTSUP
));
3982 spa_close(spa
, FTAG
);
3986 case ZFS_PROP_DNODESIZE
:
3987 /* Dnode sizes above 512 need the feature to be enabled */
3988 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3989 intval
!= ZFS_DNSIZE_LEGACY
) {
3993 * If this is a bootable dataset then
3994 * we don't allow large (>512B) dnodes,
3995 * because GRUB doesn't support them.
3997 if (zfs_is_bootfs(dsname
) &&
3998 intval
!= ZFS_DNSIZE_LEGACY
) {
3999 return (SET_ERROR(EDOM
));
4002 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4005 if (!spa_feature_is_enabled(spa
,
4006 SPA_FEATURE_LARGE_DNODE
)) {
4007 spa_close(spa
, FTAG
);
4008 return (SET_ERROR(ENOTSUP
));
4010 spa_close(spa
, FTAG
);
4014 case ZFS_PROP_SHARESMB
:
4015 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
4016 return (SET_ERROR(ENOTSUP
));
4019 case ZFS_PROP_ACLINHERIT
:
4020 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4021 nvpair_value_uint64(pair
, &intval
) == 0) {
4022 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
4023 zfs_earlier_version(dsname
,
4024 SPA_VERSION_PASSTHROUGH_X
))
4025 return (SET_ERROR(ENOTSUP
));
4028 case ZFS_PROP_CHECKSUM
:
4029 case ZFS_PROP_DEDUP
:
4031 spa_feature_t feature
;
4036 /* dedup feature version checks */
4037 if (prop
== ZFS_PROP_DEDUP
&&
4038 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
4039 return (SET_ERROR(ENOTSUP
));
4041 if (nvpair_value_uint64(pair
, &intval
) != 0)
4042 return (SET_ERROR(EINVAL
));
4044 /* check prop value is enabled in features */
4045 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
4046 if (feature
== SPA_FEATURE_NONE
)
4049 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4052 * Salted checksums are not supported on root pools.
4054 if (spa_bootfs(spa
) != 0 &&
4055 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
4056 (zio_checksum_table
[intval
].ci_flags
&
4057 ZCHECKSUM_FLAG_SALTED
)) {
4058 spa_close(spa
, FTAG
);
4059 return (SET_ERROR(ERANGE
));
4061 if (!spa_feature_is_enabled(spa
, feature
)) {
4062 spa_close(spa
, FTAG
);
4063 return (SET_ERROR(ENOTSUP
));
4065 spa_close(spa
, FTAG
);
4073 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
4077 * Removes properties from the given props list that fail permission checks
4078 * needed to clear them and to restore them in case of a receive error. For each
4079 * property, make sure we have both set and inherit permissions.
4081 * Returns the first error encountered if any permission checks fail. If the
4082 * caller provides a non-NULL errlist, it also gives the complete list of names
4083 * of all the properties that failed a permission check along with the
4084 * corresponding error numbers. The caller is responsible for freeing the
4087 * If every property checks out successfully, zero is returned and the list
4088 * pointed at by errlist is NULL.
4091 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
4094 nvpair_t
*pair
, *next_pair
;
4101 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4103 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
4104 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
4105 pair
= nvlist_next_nvpair(props
, NULL
);
4106 while (pair
!= NULL
) {
4107 next_pair
= nvlist_next_nvpair(props
, pair
);
4109 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
4110 sizeof (zc
->zc_value
));
4111 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
4112 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
4113 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
4114 VERIFY(nvlist_add_int32(errors
,
4115 zc
->zc_value
, err
) == 0);
4119 kmem_free(zc
, sizeof (zfs_cmd_t
));
4121 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
4122 nvlist_free(errors
);
4125 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
4128 if (errlist
== NULL
)
4129 nvlist_free(errors
);
4137 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4139 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4140 /* dsl_prop_get_all_impl() format */
4142 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4143 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4147 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4149 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4150 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4154 if (nvpair_type(p1
) != nvpair_type(p2
))
4157 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4158 char *valstr1
, *valstr2
;
4160 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4161 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4162 return (strcmp(valstr1
, valstr2
) == 0);
4164 uint64_t intval1
, intval2
;
4166 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4167 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4168 return (intval1
== intval2
);
4173 * Remove properties from props if they are not going to change (as determined
4174 * by comparison with origprops). Remove them from origprops as well, since we
4175 * do not need to clear or restore properties that won't change.
4178 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4180 nvpair_t
*pair
, *next_pair
;
4182 if (origprops
== NULL
)
4183 return; /* all props need to be received */
4185 pair
= nvlist_next_nvpair(props
, NULL
);
4186 while (pair
!= NULL
) {
4187 const char *propname
= nvpair_name(pair
);
4190 next_pair
= nvlist_next_nvpair(props
, pair
);
4192 if ((nvlist_lookup_nvpair(origprops
, propname
,
4193 &match
) != 0) || !propval_equals(pair
, match
))
4194 goto next
; /* need to set received value */
4196 /* don't clear the existing received value */
4197 (void) nvlist_remove_nvpair(origprops
, match
);
4198 /* don't bother receiving the property */
4199 (void) nvlist_remove_nvpair(props
, pair
);
4206 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4207 * For example, refquota cannot be set until after the receipt of a dataset,
4208 * because in replication streams, an older/earlier snapshot may exceed the
4209 * refquota. We want to receive the older/earlier snapshot, but setting
4210 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4211 * the older/earlier snapshot from being received (with EDQUOT).
4213 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4215 * libzfs will need to be judicious handling errors encountered by props
4216 * extracted by this function.
4219 extract_delay_props(nvlist_t
*props
)
4221 nvlist_t
*delayprops
;
4222 nvpair_t
*nvp
, *tmp
;
4223 static const zfs_prop_t delayable
[] = {
4225 ZFS_PROP_KEYLOCATION
,
4230 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4232 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4233 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4235 * strcmp() is safe because zfs_prop_to_name() always returns
4238 for (i
= 0; delayable
[i
] != 0; i
++) {
4239 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4240 nvpair_name(nvp
)) == 0) {
4244 if (delayable
[i
] != 0) {
4245 tmp
= nvlist_prev_nvpair(props
, nvp
);
4246 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4247 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4252 if (nvlist_empty(delayprops
)) {
4253 nvlist_free(delayprops
);
4256 return (delayprops
);
4260 static boolean_t zfs_ioc_recv_inject_err
;
4264 * nvlist 'errors' is always allocated. It will contain descriptions of
4265 * encountered errors, if any. It's the callers responsibility to free.
4268 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
, nvlist_t
*recvprops
,
4269 nvlist_t
*localprops
, boolean_t force
, boolean_t resumable
, int input_fd
,
4270 dmu_replay_record_t
*begin_record
, int cleanup_fd
, uint64_t *read_bytes
,
4271 uint64_t *errflags
, uint64_t *action_handle
, nvlist_t
**errors
)
4273 dmu_recv_cookie_t drc
;
4275 int props_error
= 0;
4277 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4278 nvlist_t
*origprops
= NULL
; /* existing properties */
4279 nvlist_t
*origrecvd
= NULL
; /* existing received properties */
4280 boolean_t first_recvd_props
= B_FALSE
;
4285 *errors
= fnvlist_alloc();
4287 input_fp
= getf(input_fd
);
4288 if (input_fp
== NULL
)
4289 return (SET_ERROR(EBADF
));
4291 error
= dmu_recv_begin(tofs
, tosnap
,
4292 begin_record
, force
, resumable
, origin
, &drc
);
4297 * Set properties before we receive the stream so that they are applied
4298 * to the new data. Note that we must call dmu_recv_stream() if
4299 * dmu_recv_begin() succeeds.
4301 if (recvprops
!= NULL
&& !drc
.drc_newfs
) {
4302 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4303 SPA_VERSION_RECVD_PROPS
&&
4304 !dsl_prop_get_hasrecvd(tofs
))
4305 first_recvd_props
= B_TRUE
;
4308 * If new received properties are supplied, they are to
4309 * completely replace the existing received properties, so stash
4310 * away the existing ones.
4312 if (dsl_prop_get_received(tofs
, &origrecvd
) == 0) {
4313 nvlist_t
*errlist
= NULL
;
4315 * Don't bother writing a property if its value won't
4316 * change (and avoid the unnecessary security checks).
4318 * The first receive after SPA_VERSION_RECVD_PROPS is a
4319 * special case where we blow away all local properties
4322 if (!first_recvd_props
)
4323 props_reduce(recvprops
, origrecvd
);
4324 if (zfs_check_clearable(tofs
, origrecvd
, &errlist
) != 0)
4325 (void) nvlist_merge(*errors
, errlist
, 0);
4326 nvlist_free(errlist
);
4328 if (clear_received_props(tofs
, origrecvd
,
4329 first_recvd_props
? NULL
: recvprops
) != 0)
4330 *errflags
|= ZPROP_ERR_NOCLEAR
;
4332 *errflags
|= ZPROP_ERR_NOCLEAR
;
4337 * Stash away existing properties so we can restore them on error unless
4338 * we're doing the first receive after SPA_VERSION_RECVD_PROPS, in which
4339 * case "origrecvd" will take care of that.
4341 if (localprops
!= NULL
&& !drc
.drc_newfs
&& !first_recvd_props
) {
4343 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
4344 if (dsl_prop_get_all(os
, &origprops
) != 0) {
4345 *errflags
|= ZPROP_ERR_NOCLEAR
;
4347 dmu_objset_rele(os
, FTAG
);
4349 *errflags
|= ZPROP_ERR_NOCLEAR
;
4353 if (recvprops
!= NULL
) {
4354 props_error
= dsl_prop_set_hasrecvd(tofs
);
4356 if (props_error
== 0) {
4357 delayprops
= extract_delay_props(recvprops
);
4358 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4359 recvprops
, *errors
);
4363 if (localprops
!= NULL
) {
4364 nvlist_t
*oprops
= fnvlist_alloc();
4365 nvlist_t
*xprops
= fnvlist_alloc();
4366 nvpair_t
*nvp
= NULL
;
4368 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4369 if (nvpair_type(nvp
) == DATA_TYPE_BOOLEAN
) {
4371 const char *name
= nvpair_name(nvp
);
4372 zfs_prop_t prop
= zfs_name_to_prop(name
);
4373 if (prop
!= ZPROP_INVAL
) {
4374 if (!zfs_prop_inheritable(prop
))
4376 } else if (!zfs_prop_user(name
))
4378 fnvlist_add_boolean(xprops
, name
);
4380 /* -o property=value */
4381 fnvlist_add_nvpair(oprops
, nvp
);
4384 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4386 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
,
4389 nvlist_free(oprops
);
4390 nvlist_free(xprops
);
4393 off
= input_fp
->f_offset
;
4394 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4398 zfsvfs_t
*zfsvfs
= NULL
;
4399 zvol_state_t
*zv
= NULL
;
4401 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4406 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4407 error
= zfs_suspend_fs(zfsvfs
);
4409 * If the suspend fails, then the recv_end will
4410 * likely also fail, and clean up after itself.
4412 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4414 error
= zfs_resume_fs(zfsvfs
, ds
);
4415 error
= error
? error
: end_err
;
4416 deactivate_super(zfsvfs
->z_sb
);
4417 } else if ((zv
= zvol_suspend(tofs
)) != NULL
) {
4418 error
= dmu_recv_end(&drc
, zvol_tag(zv
));
4421 error
= dmu_recv_end(&drc
, NULL
);
4424 /* Set delayed properties now, after we're done receiving. */
4425 if (delayprops
!= NULL
&& error
== 0) {
4426 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4427 delayprops
, *errors
);
4431 if (delayprops
!= NULL
) {
4433 * Merge delayed props back in with initial props, in case
4434 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4435 * we have to make sure clear_received_props() includes
4436 * the delayed properties).
4438 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4439 * using ASSERT() will be just like a VERIFY.
4441 ASSERT(nvlist_merge(recvprops
, delayprops
, 0) == 0);
4442 nvlist_free(delayprops
);
4446 *read_bytes
= off
- input_fp
->f_offset
;
4447 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4448 input_fp
->f_offset
= off
;
4451 if (zfs_ioc_recv_inject_err
) {
4452 zfs_ioc_recv_inject_err
= B_FALSE
;
4458 * On error, restore the original props.
4460 if (error
!= 0 && recvprops
!= NULL
&& !drc
.drc_newfs
) {
4461 if (clear_received_props(tofs
, recvprops
, NULL
) != 0) {
4463 * We failed to clear the received properties.
4464 * Since we may have left a $recvd value on the
4465 * system, we can't clear the $hasrecvd flag.
4467 *errflags
|= ZPROP_ERR_NORESTORE
;
4468 } else if (first_recvd_props
) {
4469 dsl_prop_unset_hasrecvd(tofs
);
4472 if (origrecvd
== NULL
&& !drc
.drc_newfs
) {
4473 /* We failed to stash the original properties. */
4474 *errflags
|= ZPROP_ERR_NORESTORE
;
4478 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4479 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4480 * explicitly if we're restoring local properties cleared in the
4481 * first new-style receive.
4483 if (origrecvd
!= NULL
&&
4484 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4485 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4486 origrecvd
, NULL
) != 0) {
4488 * We stashed the original properties but failed to
4491 *errflags
|= ZPROP_ERR_NORESTORE
;
4494 if (error
!= 0 && localprops
!= NULL
&& !drc
.drc_newfs
&&
4495 !first_recvd_props
) {
4497 nvlist_t
*inheritprops
;
4500 if (origprops
== NULL
) {
4501 /* We failed to stash the original properties. */
4502 *errflags
|= ZPROP_ERR_NORESTORE
;
4506 /* Restore original props */
4507 setprops
= fnvlist_alloc();
4508 inheritprops
= fnvlist_alloc();
4510 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4511 const char *name
= nvpair_name(nvp
);
4515 if (!nvlist_exists(origprops
, name
)) {
4517 * Property was not present or was explicitly
4518 * inherited before the receive, restore this.
4520 fnvlist_add_boolean(inheritprops
, name
);
4523 attrs
= fnvlist_lookup_nvlist(origprops
, name
);
4524 source
= fnvlist_lookup_string(attrs
, ZPROP_SOURCE
);
4526 /* Skip received properties */
4527 if (strcmp(source
, ZPROP_SOURCE_VAL_RECVD
) == 0)
4530 if (strcmp(source
, tofs
) == 0) {
4531 /* Property was locally set */
4532 fnvlist_add_nvlist(setprops
, name
, attrs
);
4534 /* Property was implicitly inherited */
4535 fnvlist_add_boolean(inheritprops
, name
);
4539 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
, setprops
,
4541 *errflags
|= ZPROP_ERR_NORESTORE
;
4542 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
, inheritprops
,
4544 *errflags
|= ZPROP_ERR_NORESTORE
;
4546 nvlist_free(setprops
);
4547 nvlist_free(inheritprops
);
4551 nvlist_free(origrecvd
);
4552 nvlist_free(origprops
);
4555 error
= props_error
;
4562 * zc_name name of containing filesystem (unused)
4563 * zc_nvlist_src{_size} nvlist of properties to apply
4564 * zc_nvlist_conf{_size} nvlist of properties to exclude
4565 * (DATA_TYPE_BOOLEAN) and override (everything else)
4566 * zc_value name of snapshot to create
4567 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4568 * zc_cookie file descriptor to recv from
4569 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4570 * zc_guid force flag
4571 * zc_cleanup_fd cleanup-on-exit file descriptor
4572 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4575 * zc_cookie number of bytes read
4576 * zc_obj zprop_errflags_t
4577 * zc_action_handle handle for this guid/ds mapping
4578 * zc_nvlist_dst{_size} error for each unapplied received property
4581 zfs_ioc_recv(zfs_cmd_t
*zc
)
4583 dmu_replay_record_t begin_record
;
4584 nvlist_t
*errors
= NULL
;
4585 nvlist_t
*recvdprops
= NULL
;
4586 nvlist_t
*localprops
= NULL
;
4587 char *origin
= NULL
;
4589 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4592 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4593 strchr(zc
->zc_value
, '@') == NULL
||
4594 strchr(zc
->zc_value
, '%'))
4595 return (SET_ERROR(EINVAL
));
4597 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4598 tosnap
= strchr(tofs
, '@');
4601 if (zc
->zc_nvlist_src
!= 0 &&
4602 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4603 zc
->zc_iflags
, &recvdprops
)) != 0)
4606 if (zc
->zc_nvlist_conf
!= 0 &&
4607 (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
4608 zc
->zc_iflags
, &localprops
)) != 0)
4611 if (zc
->zc_string
[0])
4612 origin
= zc
->zc_string
;
4614 begin_record
.drr_type
= DRR_BEGIN
;
4615 begin_record
.drr_payloadlen
= 0;
4616 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4618 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvdprops
, localprops
,
4619 zc
->zc_guid
, B_FALSE
, zc
->zc_cookie
, &begin_record
,
4620 zc
->zc_cleanup_fd
, &zc
->zc_cookie
, &zc
->zc_obj
,
4621 &zc
->zc_action_handle
, &errors
);
4622 nvlist_free(recvdprops
);
4623 nvlist_free(localprops
);
4626 * Now that all props, initial and delayed, are set, report the prop
4627 * errors to the caller.
4629 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4630 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4631 put_nvlist(zc
, errors
) != 0)) {
4633 * Caller made zc->zc_nvlist_dst less than the minimum expected
4634 * size or supplied an invalid address.
4636 error
= SET_ERROR(EINVAL
);
4639 nvlist_free(errors
);
4646 * "snapname" -> full name of the snapshot to create
4647 * (optional) "props" -> received properties to set (nvlist)
4648 * (optional) "localprops" -> override and exclude properties (nvlist)
4649 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
4650 * "begin_record" -> non-byteswapped dmu_replay_record_t
4651 * "input_fd" -> file descriptor to read stream from (int32)
4652 * (optional) "force" -> force flag (value ignored)
4653 * (optional) "resumable" -> resumable flag (value ignored)
4654 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
4655 * (optional) "action_handle" -> handle for this guid/ds mapping
4659 * "read_bytes" -> number of bytes read
4660 * "error_flags" -> zprop_errflags_t
4661 * "action_handle" -> handle for this guid/ds mapping
4662 * "errors" -> error for each unapplied received property (nvlist)
4666 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4668 dmu_replay_record_t
*begin_record
;
4669 uint_t begin_record_size
;
4670 nvlist_t
*errors
= NULL
;
4671 nvlist_t
*recvprops
= NULL
;
4672 nvlist_t
*localprops
= NULL
;
4673 char *snapname
= NULL
;
4674 char *origin
= NULL
;
4676 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4678 boolean_t resumable
;
4679 uint64_t action_handle
= 0;
4680 uint64_t read_bytes
= 0;
4681 uint64_t errflags
= 0;
4683 int cleanup_fd
= -1;
4686 error
= nvlist_lookup_string(innvl
, "snapname", &snapname
);
4688 return (SET_ERROR(EINVAL
));
4690 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
4691 strchr(snapname
, '@') == NULL
||
4692 strchr(snapname
, '%'))
4693 return (SET_ERROR(EINVAL
));
4695 (void) strcpy(tofs
, snapname
);
4696 tosnap
= strchr(tofs
, '@');
4699 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
4700 if (error
&& error
!= ENOENT
)
4703 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
4704 (uchar_t
**)&begin_record
, &begin_record_size
);
4705 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
4706 return (SET_ERROR(EINVAL
));
4708 error
= nvlist_lookup_int32(innvl
, "input_fd", &input_fd
);
4710 return (SET_ERROR(EINVAL
));
4712 force
= nvlist_exists(innvl
, "force");
4713 resumable
= nvlist_exists(innvl
, "resumable");
4715 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
4716 if (error
&& error
!= ENOENT
)
4719 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
4720 if (error
&& error
!= ENOENT
)
4723 /* we still use "props" here for backwards compatibility */
4724 error
= nvlist_lookup_nvlist(innvl
, "props", &recvprops
);
4725 if (error
&& error
!= ENOENT
)
4728 error
= nvlist_lookup_nvlist(innvl
, "localprops", &localprops
);
4729 if (error
&& error
!= ENOENT
)
4732 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvprops
, localprops
,
4733 force
, resumable
, input_fd
, begin_record
, cleanup_fd
, &read_bytes
,
4734 &errflags
, &action_handle
, &errors
);
4736 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
4737 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
4738 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
4739 fnvlist_add_nvlist(outnvl
, "errors", errors
);
4741 nvlist_free(errors
);
4742 nvlist_free(recvprops
);
4743 nvlist_free(localprops
);
4750 * zc_name name of snapshot to send
4751 * zc_cookie file descriptor to send stream to
4752 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4753 * zc_sendobj objsetid of snapshot to send
4754 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4755 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4756 * output size in zc_objset_type.
4757 * zc_flags lzc_send_flags
4760 * zc_objset_type estimated size, if zc_guid is set
4762 * NOTE: This is no longer the preferred interface, any new functionality
4763 * should be added to zfs_ioc_send_new() instead.
4766 zfs_ioc_send(zfs_cmd_t
*zc
)
4770 boolean_t estimate
= (zc
->zc_guid
!= 0);
4771 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4772 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4773 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4774 boolean_t rawok
= (zc
->zc_flags
& 0x8);
4776 if (zc
->zc_obj
!= 0) {
4778 dsl_dataset_t
*tosnap
;
4780 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4784 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4786 dsl_pool_rele(dp
, FTAG
);
4790 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4792 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4793 dsl_dataset_rele(tosnap
, FTAG
);
4794 dsl_pool_rele(dp
, FTAG
);
4799 dsl_dataset_t
*tosnap
;
4800 dsl_dataset_t
*fromsnap
= NULL
;
4802 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4806 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
,
4809 dsl_pool_rele(dp
, FTAG
);
4813 if (zc
->zc_fromobj
!= 0) {
4814 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4817 dsl_dataset_rele(tosnap
, FTAG
);
4818 dsl_pool_rele(dp
, FTAG
);
4823 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
|| rawok
,
4824 &zc
->zc_objset_type
);
4826 if (fromsnap
!= NULL
)
4827 dsl_dataset_rele(fromsnap
, FTAG
);
4828 dsl_dataset_rele(tosnap
, FTAG
);
4829 dsl_pool_rele(dp
, FTAG
);
4831 file_t
*fp
= getf(zc
->zc_cookie
);
4833 return (SET_ERROR(EBADF
));
4836 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4837 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
, rawok
,
4838 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4840 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4842 releasef(zc
->zc_cookie
);
4849 * zc_name name of snapshot on which to report progress
4850 * zc_cookie file descriptor of send stream
4853 * zc_cookie number of bytes written in send stream thus far
4856 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4860 dmu_sendarg_t
*dsp
= NULL
;
4863 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4867 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4869 dsl_pool_rele(dp
, FTAG
);
4873 mutex_enter(&ds
->ds_sendstream_lock
);
4876 * Iterate over all the send streams currently active on this dataset.
4877 * If there's one which matches the specified file descriptor _and_ the
4878 * stream was started by the current process, return the progress of
4882 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4883 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4884 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4885 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4890 zc
->zc_cookie
= *(dsp
->dsa_off
);
4892 error
= SET_ERROR(ENOENT
);
4894 mutex_exit(&ds
->ds_sendstream_lock
);
4895 dsl_dataset_rele(ds
, FTAG
);
4896 dsl_pool_rele(dp
, FTAG
);
4901 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4905 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4906 &zc
->zc_inject_record
);
4909 zc
->zc_guid
= (uint64_t)id
;
4915 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4917 return (zio_clear_fault((int)zc
->zc_guid
));
4921 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4923 int id
= (int)zc
->zc_guid
;
4926 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4927 &zc
->zc_inject_record
);
4935 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4939 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4941 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4944 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4947 zc
->zc_nvlist_dst_size
= count
;
4949 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4951 spa_close(spa
, FTAG
);
4957 zfs_ioc_clear(zfs_cmd_t
*zc
)
4964 * On zpool clear we also fix up missing slogs
4966 mutex_enter(&spa_namespace_lock
);
4967 spa
= spa_lookup(zc
->zc_name
);
4969 mutex_exit(&spa_namespace_lock
);
4970 return (SET_ERROR(EIO
));
4972 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4973 /* we need to let spa_open/spa_load clear the chains */
4974 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4976 spa
->spa_last_open_failed
= 0;
4977 mutex_exit(&spa_namespace_lock
);
4979 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4980 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4983 nvlist_t
*config
= NULL
;
4985 if (zc
->zc_nvlist_src
== 0)
4986 return (SET_ERROR(EINVAL
));
4988 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4989 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4990 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4992 if (config
!= NULL
) {
4995 if ((err
= put_nvlist(zc
, config
)) != 0)
4997 nvlist_free(config
);
4999 nvlist_free(policy
);
5006 spa_vdev_state_enter(spa
, SCL_NONE
);
5008 if (zc
->zc_guid
== 0) {
5011 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
5013 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
5014 spa_close(spa
, FTAG
);
5015 return (SET_ERROR(ENODEV
));
5019 vdev_clear(spa
, vd
);
5021 (void) spa_vdev_state_exit(spa
, spa_suspended(spa
) ?
5022 NULL
: spa
->spa_root_vdev
, 0);
5025 * Resume any suspended I/Os.
5027 if (zio_resume(spa
) != 0)
5028 error
= SET_ERROR(EIO
);
5030 spa_close(spa
, FTAG
);
5036 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
5041 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
5045 spa_vdev_state_enter(spa
, SCL_NONE
);
5048 * If a resilver is already in progress then set the
5049 * spa_scrub_reopen flag to B_TRUE so that we don't restart
5050 * the scan as a side effect of the reopen. Otherwise, let
5051 * vdev_open() decided if a resilver is required.
5053 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
5054 vdev_reopen(spa
->spa_root_vdev
);
5055 spa
->spa_scrub_reopen
= B_FALSE
;
5057 (void) spa_vdev_state_exit(spa
, NULL
, 0);
5058 spa_close(spa
, FTAG
);
5063 * zc_name name of filesystem
5066 * zc_string name of conflicting snapshot, if there is one
5069 zfs_ioc_promote(zfs_cmd_t
*zc
)
5072 dsl_dataset_t
*ds
, *ods
;
5073 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
5077 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5078 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
5079 strchr(zc
->zc_name
, '%'))
5080 return (SET_ERROR(EINVAL
));
5082 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5086 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5088 dsl_pool_rele(dp
, FTAG
);
5092 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
5093 dsl_dataset_rele(ds
, FTAG
);
5094 dsl_pool_rele(dp
, FTAG
);
5095 return (SET_ERROR(EINVAL
));
5098 error
= dsl_dataset_hold_obj(dp
,
5099 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
5101 dsl_dataset_rele(ds
, FTAG
);
5102 dsl_pool_rele(dp
, FTAG
);
5106 dsl_dataset_name(ods
, origin
);
5107 dsl_dataset_rele(ods
, FTAG
);
5108 dsl_dataset_rele(ds
, FTAG
);
5109 dsl_pool_rele(dp
, FTAG
);
5112 * We don't need to unmount *all* the origin fs's snapshots, but
5115 cp
= strchr(origin
, '@');
5118 (void) dmu_objset_find(origin
,
5119 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
5120 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
5124 * Retrieve a single {user|group}{used|quota}@... property.
5127 * zc_name name of filesystem
5128 * zc_objset_type zfs_userquota_prop_t
5129 * zc_value domain name (eg. "S-1-234-567-89")
5130 * zc_guid RID/UID/GID
5133 * zc_cookie property value
5136 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
5141 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
5142 return (SET_ERROR(EINVAL
));
5144 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5148 error
= zfs_userspace_one(zfsvfs
,
5149 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
5150 zfsvfs_rele(zfsvfs
, FTAG
);
5157 * zc_name name of filesystem
5158 * zc_cookie zap cursor
5159 * zc_objset_type zfs_userquota_prop_t
5160 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
5163 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
5164 * zc_cookie zap cursor
5167 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
5170 int bufsize
= zc
->zc_nvlist_dst_size
;
5175 return (SET_ERROR(ENOMEM
));
5177 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5181 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
5183 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
5184 buf
, &zc
->zc_nvlist_dst_size
);
5187 error
= xcopyout(buf
,
5188 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5189 zc
->zc_nvlist_dst_size
);
5191 vmem_free(buf
, bufsize
);
5192 zfsvfs_rele(zfsvfs
, FTAG
);
5199 * zc_name name of filesystem
5205 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
5211 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
5212 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
5214 * If userused is not enabled, it may be because the
5215 * objset needs to be closed & reopened (to grow the
5216 * objset_phys_t). Suspend/resume the fs will do that.
5220 ds
= dmu_objset_ds(zfsvfs
->z_os
);
5221 error
= zfs_suspend_fs(zfsvfs
);
5223 dmu_objset_refresh_ownership(zfsvfs
->z_os
,
5225 error
= zfs_resume_fs(zfsvfs
, ds
);
5229 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
5230 deactivate_super(zfsvfs
->z_sb
);
5232 /* XXX kind of reading contents without owning */
5233 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5237 error
= dmu_objset_userspace_upgrade(os
);
5238 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
5246 * zc_name name of filesystem
5252 zfs_ioc_userobjspace_upgrade(zfs_cmd_t
*zc
)
5257 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5261 dsl_dataset_long_hold(dmu_objset_ds(os
), FTAG
);
5262 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5264 if (dmu_objset_userobjspace_upgradable(os
)) {
5265 mutex_enter(&os
->os_upgrade_lock
);
5266 if (os
->os_upgrade_id
== 0) {
5267 /* clear potential error code and retry */
5268 os
->os_upgrade_status
= 0;
5269 mutex_exit(&os
->os_upgrade_lock
);
5271 dmu_objset_userobjspace_upgrade(os
);
5273 mutex_exit(&os
->os_upgrade_lock
);
5276 taskq_wait_id(os
->os_spa
->spa_upgrade_taskq
, os
->os_upgrade_id
);
5277 error
= os
->os_upgrade_status
;
5280 dsl_dataset_long_rele(dmu_objset_ds(os
), FTAG
);
5281 dsl_dataset_rele_flags(dmu_objset_ds(os
), DS_HOLD_FLAG_DECRYPT
, FTAG
);
5287 zfs_ioc_share(zfs_cmd_t
*zc
)
5289 return (SET_ERROR(ENOSYS
));
5292 ace_t full_access
[] = {
5293 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
5298 * zc_name name of containing filesystem
5299 * zc_obj object # beyond which we want next in-use object #
5302 * zc_obj next in-use object #
5305 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
5307 objset_t
*os
= NULL
;
5310 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
5314 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
5316 dmu_objset_rele(os
, FTAG
);
5322 * zc_name name of filesystem
5323 * zc_value prefix name for snapshot
5324 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5327 * zc_value short name of new snapshot
5330 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5337 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5341 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5342 (u_longlong_t
)ddi_get_lbolt64());
5343 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5345 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5348 (void) strlcpy(zc
->zc_value
, snap_name
,
5349 sizeof (zc
->zc_value
));
5352 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5358 * zc_name name of "to" snapshot
5359 * zc_value name of "from" snapshot
5360 * zc_cookie file descriptor to write diff data on
5363 * dmu_diff_record_t's to the file descriptor
5366 zfs_ioc_diff(zfs_cmd_t
*zc
)
5372 fp
= getf(zc
->zc_cookie
);
5374 return (SET_ERROR(EBADF
));
5378 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5380 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5382 releasef(zc
->zc_cookie
);
5388 * Remove all ACL files in shares dir
5390 #ifdef HAVE_SMB_SHARE
5392 zfs_smb_acl_purge(znode_t
*dzp
)
5395 zap_attribute_t zap
;
5396 zfsvfs_t
*zfsvfs
= ZTOZSB(dzp
);
5399 for (zap_cursor_init(&zc
, zfsvfs
->z_os
, dzp
->z_id
);
5400 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5401 zap_cursor_advance(&zc
)) {
5402 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
5406 zap_cursor_fini(&zc
);
5409 #endif /* HAVE_SMB_SHARE */
5412 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5414 #ifdef HAVE_SMB_SHARE
5417 vnode_t
*resourcevp
= NULL
;
5426 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5427 NO_FOLLOW
, NULL
, &vp
)) != 0)
5430 /* Now make sure mntpnt and dataset are ZFS */
5432 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5433 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5434 zc
->zc_name
) != 0)) {
5436 return (SET_ERROR(EINVAL
));
5440 zfsvfs
= ZTOZSB(dzp
);
5444 * Create share dir if its missing.
5446 mutex_enter(&zfsvfs
->z_lock
);
5447 if (zfsvfs
->z_shares_dir
== 0) {
5450 tx
= dmu_tx_create(zfsvfs
->z_os
);
5451 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5453 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5454 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5458 error
= zfs_create_share_dir(zfsvfs
, tx
);
5462 mutex_exit(&zfsvfs
->z_lock
);
5468 mutex_exit(&zfsvfs
->z_lock
);
5470 ASSERT(zfsvfs
->z_shares_dir
);
5471 if ((error
= zfs_zget(zfsvfs
, zfsvfs
->z_shares_dir
, &sharedir
)) != 0) {
5477 switch (zc
->zc_cookie
) {
5478 case ZFS_SMB_ACL_ADD
:
5479 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5480 vattr
.va_mode
= S_IFREG
|0777;
5484 vsec
.vsa_mask
= VSA_ACE
;
5485 vsec
.vsa_aclentp
= &full_access
;
5486 vsec
.vsa_aclentsz
= sizeof (full_access
);
5487 vsec
.vsa_aclcnt
= 1;
5489 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
5490 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5492 VN_RELE(resourcevp
);
5495 case ZFS_SMB_ACL_REMOVE
:
5496 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5500 case ZFS_SMB_ACL_RENAME
:
5501 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5502 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5504 VN_RELE(ZTOV(sharedir
));
5508 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5509 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5512 VN_RELE(ZTOV(sharedir
));
5514 nvlist_free(nvlist
);
5517 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5519 nvlist_free(nvlist
);
5522 case ZFS_SMB_ACL_PURGE
:
5523 error
= zfs_smb_acl_purge(sharedir
);
5527 error
= SET_ERROR(EINVAL
);
5532 VN_RELE(ZTOV(sharedir
));
5538 return (SET_ERROR(ENOTSUP
));
5539 #endif /* HAVE_SMB_SHARE */
5544 * "holds" -> { snapname -> holdname (string), ... }
5545 * (optional) "cleanup_fd" -> fd (int32)
5549 * snapname -> error value (int32)
5555 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5559 int cleanup_fd
= -1;
5563 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5565 return (SET_ERROR(EINVAL
));
5567 /* make sure the user didn't pass us any invalid (empty) tags */
5568 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5569 pair
= nvlist_next_nvpair(holds
, pair
)) {
5572 error
= nvpair_value_string(pair
, &htag
);
5574 return (SET_ERROR(error
));
5576 if (strlen(htag
) == 0)
5577 return (SET_ERROR(EINVAL
));
5580 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5581 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5586 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5588 zfs_onexit_fd_rele(cleanup_fd
);
5593 * innvl is not used.
5596 * holdname -> time added (uint64 seconds since epoch)
5602 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5604 ASSERT3P(args
, ==, NULL
);
5605 return (dsl_dataset_get_holds(snapname
, outnvl
));
5610 * snapname -> { holdname, ... }
5615 * snapname -> error value (int32)
5621 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5623 return (dsl_dataset_user_release(holds
, errlist
));
5628 * zc_guid flags (ZEVENT_NONBLOCK)
5629 * zc_cleanup_fd zevent file descriptor
5632 * zc_nvlist_dst next nvlist event
5633 * zc_cookie dropped events since last get
5636 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5639 nvlist_t
*event
= NULL
;
5641 uint64_t dropped
= 0;
5644 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5649 error
= zfs_zevent_next(ze
, &event
,
5650 &zc
->zc_nvlist_dst_size
, &dropped
);
5651 if (event
!= NULL
) {
5652 zc
->zc_cookie
= dropped
;
5653 error
= put_nvlist(zc
, event
);
5657 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5660 if ((error
== 0) || (error
!= ENOENT
))
5663 error
= zfs_zevent_wait(ze
);
5668 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5675 * zc_cookie cleared events count
5678 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5682 zfs_zevent_drain_all(&count
);
5683 zc
->zc_cookie
= count
;
5690 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5691 * zc_cleanup zevent file descriptor
5694 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5700 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5704 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5705 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5712 * zc_name name of new filesystem or snapshot
5713 * zc_value full name of old snapshot
5716 * zc_cookie space in bytes
5717 * zc_objset_type compressed space in bytes
5718 * zc_perm_action uncompressed space in bytes
5721 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5725 dsl_dataset_t
*new, *old
;
5727 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5730 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5732 dsl_pool_rele(dp
, FTAG
);
5735 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5737 dsl_dataset_rele(new, FTAG
);
5738 dsl_pool_rele(dp
, FTAG
);
5742 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5743 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5744 dsl_dataset_rele(old
, FTAG
);
5745 dsl_dataset_rele(new, FTAG
);
5746 dsl_pool_rele(dp
, FTAG
);
5752 * "firstsnap" -> snapshot name
5756 * "used" -> space in bytes
5757 * "compressed" -> compressed space in bytes
5758 * "uncompressed" -> uncompressed space in bytes
5762 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5766 dsl_dataset_t
*new, *old
;
5768 uint64_t used
, comp
, uncomp
;
5770 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5771 return (SET_ERROR(EINVAL
));
5773 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5777 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5778 if (error
== 0 && !new->ds_is_snapshot
) {
5779 dsl_dataset_rele(new, FTAG
);
5780 error
= SET_ERROR(EINVAL
);
5783 dsl_pool_rele(dp
, FTAG
);
5786 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5787 if (error
== 0 && !old
->ds_is_snapshot
) {
5788 dsl_dataset_rele(old
, FTAG
);
5789 error
= SET_ERROR(EINVAL
);
5792 dsl_dataset_rele(new, FTAG
);
5793 dsl_pool_rele(dp
, FTAG
);
5797 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5798 dsl_dataset_rele(old
, FTAG
);
5799 dsl_dataset_rele(new, FTAG
);
5800 dsl_pool_rele(dp
, FTAG
);
5801 fnvlist_add_uint64(outnvl
, "used", used
);
5802 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5803 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5809 * "fd" -> file descriptor to write stream to (int32)
5810 * (optional) "fromsnap" -> full snap name to send an incremental from
5811 * (optional) "largeblockok" -> (value ignored)
5812 * indicates that blocks > 128KB are permitted
5813 * (optional) "embedok" -> (value ignored)
5814 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5815 * (optional) "compressok" -> (value ignored)
5816 * presence indicates compressed DRR_WRITE records are permitted
5817 * (optional) "rawok" -> (value ignored)
5818 * presence indicates raw encrypted records should be used.
5819 * (optional) "resume_object" and "resume_offset" -> (uint64)
5820 * if present, resume send stream from specified object and offset.
5827 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5831 char *fromname
= NULL
;
5834 boolean_t largeblockok
;
5836 boolean_t compressok
;
5838 uint64_t resumeobj
= 0;
5839 uint64_t resumeoff
= 0;
5841 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5843 return (SET_ERROR(EINVAL
));
5845 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5847 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5848 embedok
= nvlist_exists(innvl
, "embedok");
5849 compressok
= nvlist_exists(innvl
, "compressok");
5850 rawok
= nvlist_exists(innvl
, "rawok");
5852 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5853 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5855 if ((fp
= getf(fd
)) == NULL
)
5856 return (SET_ERROR(EBADF
));
5859 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5860 rawok
, fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5862 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5870 * Determine approximately how large a zfs send stream will be -- the number
5871 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5874 * (optional) "from" -> full snap or bookmark name to send an incremental
5876 * (optional) "largeblockok" -> (value ignored)
5877 * indicates that blocks > 128KB are permitted
5878 * (optional) "embedok" -> (value ignored)
5879 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5880 * (optional) "compressok" -> (value ignored)
5881 * presence indicates compressed DRR_WRITE records are permitted
5882 * (optional) "rawok" -> (value ignored)
5883 * presence indicates raw encrypted records should be used.
5887 * "space" -> bytes of space (uint64)
5891 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5894 dsl_dataset_t
*tosnap
;
5897 /* LINTED E_FUNC_SET_NOT_USED */
5898 boolean_t largeblockok
;
5899 /* LINTED E_FUNC_SET_NOT_USED */
5901 boolean_t compressok
;
5905 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5909 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5911 dsl_pool_rele(dp
, FTAG
);
5915 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5916 embedok
= nvlist_exists(innvl
, "embedok");
5917 compressok
= nvlist_exists(innvl
, "compressok");
5918 rawok
= nvlist_exists(innvl
, "rawok");
5920 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5922 if (strchr(fromname
, '@') != NULL
) {
5924 * If from is a snapshot, hold it and use the more
5925 * efficient dmu_send_estimate to estimate send space
5926 * size using deadlists.
5928 dsl_dataset_t
*fromsnap
;
5929 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5932 error
= dmu_send_estimate(tosnap
, fromsnap
,
5933 compressok
|| rawok
, &space
);
5934 dsl_dataset_rele(fromsnap
, FTAG
);
5935 } else if (strchr(fromname
, '#') != NULL
) {
5937 * If from is a bookmark, fetch the creation TXG of the
5938 * snapshot it was created from and use that to find
5939 * blocks that were born after it.
5941 zfs_bookmark_phys_t frombm
;
5943 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
5947 error
= dmu_send_estimate_from_txg(tosnap
,
5948 frombm
.zbm_creation_txg
, compressok
|| rawok
,
5952 * from is not properly formatted as a snapshot or
5955 error
= SET_ERROR(EINVAL
);
5959 // If estimating the size of a full send, use dmu_send_estimate
5960 error
= dmu_send_estimate(tosnap
, NULL
, compressok
|| rawok
,
5964 fnvlist_add_uint64(outnvl
, "space", space
);
5967 dsl_dataset_rele(tosnap
, FTAG
);
5968 dsl_pool_rele(dp
, FTAG
);
5973 * Sync the currently open TXG to disk for the specified pool.
5974 * This is somewhat similar to 'zfs_sync()'.
5975 * For cases that do not result in error this ioctl will wait for
5976 * the currently open TXG to commit before returning back to the caller.
5979 * "force" -> when true, force uberblock update even if there is no dirty data.
5980 * In addition this will cause the vdev configuration to be written
5981 * out including updating the zpool cache file. (boolean_t)
5988 zfs_ioc_pool_sync(const char *pool
, nvlist_t
*innvl
, nvlist_t
*onvl
)
5991 boolean_t force
= B_FALSE
;
5994 if ((err
= spa_open(pool
, &spa
, FTAG
)) != 0)
5998 if (nvlist_lookup_boolean_value(innvl
, "force", &force
) != 0) {
5999 err
= SET_ERROR(EINVAL
);
6005 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_WRITER
);
6006 vdev_config_dirty(spa
->spa_root_vdev
);
6007 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6009 txg_wait_synced(spa_get_dsl(spa
), 0);
6011 spa_close(spa
, FTAG
);
6017 * Load a user's wrapping key into the kernel.
6019 * "hidden_args" -> { "wkeydata" -> value }
6020 * raw uint8_t array of encryption wrapping key data (32 bytes)
6021 * (optional) "noop" -> (value ignored)
6022 * presence indicated key should only be verified, not loaded
6027 zfs_ioc_load_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6030 dsl_crypto_params_t
*dcp
= NULL
;
6031 nvlist_t
*hidden_args
;
6032 boolean_t noop
= nvlist_exists(innvl
, "noop");
6034 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6035 ret
= SET_ERROR(EINVAL
);
6039 ret
= nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6041 ret
= SET_ERROR(EINVAL
);
6045 ret
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, NULL
,
6050 ret
= spa_keystore_load_wkey(dsname
, dcp
, noop
);
6054 dsl_crypto_params_free(dcp
, noop
);
6059 dsl_crypto_params_free(dcp
, B_TRUE
);
6064 * Unload a user's wrapping key from the kernel.
6065 * Both innvl and outnvl are unused.
6069 zfs_ioc_unload_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6073 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6074 ret
= (SET_ERROR(EINVAL
));
6078 ret
= spa_keystore_unload_wkey(dsname
);
6087 * Changes a user's wrapping key used to decrypt a dataset. The keyformat,
6088 * keylocation, pbkdf2salt, and pbkdf2iters properties can also be specified
6089 * here to change how the key is derived in userspace.
6092 * "hidden_args" (optional) -> { "wkeydata" -> value }
6093 * raw uint8_t array of new encryption wrapping key data (32 bytes)
6094 * "props" (optional) -> { prop -> value }
6101 zfs_ioc_change_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6104 uint64_t cmd
= DCP_CMD_NONE
;
6105 dsl_crypto_params_t
*dcp
= NULL
;
6106 nvlist_t
*args
= NULL
, *hidden_args
= NULL
;
6108 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6109 ret
= (SET_ERROR(EINVAL
));
6113 (void) nvlist_lookup_uint64(innvl
, "crypt_cmd", &cmd
);
6114 (void) nvlist_lookup_nvlist(innvl
, "props", &args
);
6115 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6117 ret
= dsl_crypto_params_create_nvlist(cmd
, args
, hidden_args
, &dcp
);
6121 ret
= spa_keystore_change_key(dsname
, dcp
);
6125 dsl_crypto_params_free(dcp
, B_FALSE
);
6130 dsl_crypto_params_free(dcp
, B_TRUE
);
6134 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
6137 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6138 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6139 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
6141 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6143 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6144 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6145 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6146 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6148 vec
->zvec_legacy_func
= func
;
6149 vec
->zvec_secpolicy
= secpolicy
;
6150 vec
->zvec_namecheck
= namecheck
;
6151 vec
->zvec_allow_log
= log_history
;
6152 vec
->zvec_pool_check
= pool_check
;
6156 * See the block comment at the beginning of this file for details on
6157 * each argument to this function.
6160 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
6161 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6162 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
6163 boolean_t allow_log
)
6165 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6167 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6168 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6169 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6170 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6172 /* if we are logging, the name must be valid */
6173 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
6175 vec
->zvec_name
= name
;
6176 vec
->zvec_func
= func
;
6177 vec
->zvec_secpolicy
= secpolicy
;
6178 vec
->zvec_namecheck
= namecheck
;
6179 vec
->zvec_pool_check
= pool_check
;
6180 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
6181 vec
->zvec_allow_log
= allow_log
;
6185 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6186 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
6187 zfs_ioc_poolcheck_t pool_check
)
6189 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6190 POOL_NAME
, log_history
, pool_check
);
6194 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6195 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
6197 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6198 DATASET_NAME
, B_FALSE
, pool_check
);
6202 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6204 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
6205 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6209 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6210 zfs_secpolicy_func_t
*secpolicy
)
6212 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6213 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6217 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
6218 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
6220 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6221 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6225 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6227 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
6228 zfs_secpolicy_read
);
6232 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6233 zfs_secpolicy_func_t
*secpolicy
)
6235 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6236 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6240 zfs_ioctl_init(void)
6242 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
6243 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
6244 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6246 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
6247 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
6248 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
6250 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
6251 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
6252 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6254 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
6255 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
6256 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6258 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
6259 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
6260 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6262 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
6263 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6264 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6266 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
6267 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6268 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6270 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
6271 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
6272 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6274 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
6275 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
6276 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6277 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
6278 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
6279 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6281 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
6282 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
6283 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6285 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
6286 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
6287 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
6289 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
6290 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
6291 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6293 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
6294 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
6295 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6297 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
6298 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
6300 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6302 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
6303 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
6304 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6305 zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY
,
6306 zfs_ioc_load_key
, zfs_secpolicy_load_key
,
6307 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
);
6308 zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY
,
6309 zfs_ioc_unload_key
, zfs_secpolicy_load_key
,
6310 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
);
6311 zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY
,
6312 zfs_ioc_change_key
, zfs_secpolicy_change_key
,
6313 DATASET_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
,
6316 zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC
,
6317 zfs_ioc_pool_sync
, zfs_secpolicy_none
, POOL_NAME
,
6318 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
6320 /* IOCTLS that use the legacy function signature */
6322 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
6323 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
6325 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
6326 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6327 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
6329 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
6330 zfs_ioc_pool_upgrade
);
6331 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
6333 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
6334 zfs_ioc_vdev_remove
);
6335 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
6336 zfs_ioc_vdev_set_state
);
6337 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
6338 zfs_ioc_vdev_attach
);
6339 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
6340 zfs_ioc_vdev_detach
);
6341 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
6342 zfs_ioc_vdev_setpath
);
6343 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
6344 zfs_ioc_vdev_setfru
);
6345 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
6346 zfs_ioc_pool_set_props
);
6347 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
6348 zfs_ioc_vdev_split
);
6349 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
6350 zfs_ioc_pool_reguid
);
6352 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
6353 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
6354 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
6355 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
6356 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
6357 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
6358 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
6359 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
6360 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
6361 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
6364 * pool destroy, and export don't log the history as part of
6365 * zfsdev_ioctl, but rather zfs_ioc_pool_export
6366 * does the logging of those commands.
6368 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
6369 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6370 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
6371 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6373 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
6374 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6375 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
6376 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6378 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
6379 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6380 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
6381 zfs_ioc_dsobj_to_dsname
,
6382 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6383 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
6384 zfs_ioc_pool_get_history
,
6385 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6387 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
6388 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6390 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
6391 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_READONLY
);
6392 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
6393 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
6395 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
6396 zfs_ioc_space_written
);
6397 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
6398 zfs_ioc_objset_recvd_props
);
6399 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
6401 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
6403 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
6404 zfs_ioc_objset_stats
);
6405 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
6406 zfs_ioc_objset_zplprops
);
6407 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
6408 zfs_ioc_dataset_list_next
);
6409 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
6410 zfs_ioc_snapshot_list_next
);
6411 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
6412 zfs_ioc_send_progress
);
6414 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
6415 zfs_ioc_diff
, zfs_secpolicy_diff
);
6416 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
6417 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
6418 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
6419 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
6420 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
6421 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
6422 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
6423 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
6424 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
6425 zfs_ioc_send
, zfs_secpolicy_send
);
6427 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
6428 zfs_secpolicy_none
);
6429 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
6430 zfs_secpolicy_destroy
);
6431 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
6432 zfs_secpolicy_rename
);
6433 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
6434 zfs_secpolicy_recv
);
6435 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
6436 zfs_secpolicy_promote
);
6437 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
6438 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
6439 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
6440 zfs_secpolicy_set_fsacl
);
6442 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
6443 zfs_secpolicy_share
, POOL_CHECK_NONE
);
6444 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
6445 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
6446 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
6447 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
6448 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6449 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
6450 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
6451 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6456 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
6457 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6458 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
6459 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6460 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
6461 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6465 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
6466 zfs_ioc_poolcheck_t check
)
6471 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
6473 if (check
& POOL_CHECK_NONE
)
6476 error
= spa_open(name
, &spa
, FTAG
);
6478 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
6479 error
= SET_ERROR(EAGAIN
);
6480 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
6481 error
= SET_ERROR(EROFS
);
6482 spa_close(spa
, FTAG
);
6488 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
6492 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6493 if (zs
->zs_minor
== minor
) {
6497 return (zs
->zs_onexit
);
6499 return (zs
->zs_zevent
);
6510 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
6514 ptr
= zfsdev_get_state_impl(minor
, which
);
6520 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
6522 zfsdev_state_t
*zs
, *fpd
;
6524 ASSERT(filp
!= NULL
);
6525 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
6527 fpd
= filp
->private_data
;
6529 return (SET_ERROR(EBADF
));
6531 mutex_enter(&zfsdev_state_lock
);
6533 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6535 if (zs
->zs_minor
== -1)
6539 *minorp
= fpd
->zs_minor
;
6540 mutex_exit(&zfsdev_state_lock
);
6545 mutex_exit(&zfsdev_state_lock
);
6547 return (SET_ERROR(EBADF
));
6551 * Find a free minor number. The zfsdev_state_list is expected to
6552 * be short since it is only a list of currently open file handles.
6555 zfsdev_minor_alloc(void)
6557 static minor_t last_minor
= 0;
6560 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6562 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6563 if (m
> ZFSDEV_MAX_MINOR
)
6565 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
6575 zfsdev_state_init(struct file
*filp
)
6577 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6579 boolean_t newzs
= B_FALSE
;
6581 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6583 minor
= zfsdev_minor_alloc();
6585 return (SET_ERROR(ENXIO
));
6587 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6588 if (zs
->zs_minor
== -1)
6594 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6599 filp
->private_data
= zs
;
6601 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
6602 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
6606 * In order to provide for lock-free concurrent read access
6607 * to the minor list in zfsdev_get_state_impl(), new entries
6608 * must be completely written before linking them into the
6609 * list whereas existing entries are already linked; the last
6610 * operation must be updating zs_minor (from -1 to the new
6614 zs
->zs_minor
= minor
;
6616 zsprev
->zs_next
= zs
;
6619 zs
->zs_minor
= minor
;
6626 zfsdev_state_destroy(struct file
*filp
)
6630 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6631 ASSERT(filp
->private_data
!= NULL
);
6633 zs
= filp
->private_data
;
6635 zfs_onexit_destroy(zs
->zs_onexit
);
6636 zfs_zevent_destroy(zs
->zs_zevent
);
6642 zfsdev_open(struct inode
*ino
, struct file
*filp
)
6646 mutex_enter(&zfsdev_state_lock
);
6647 error
= zfsdev_state_init(filp
);
6648 mutex_exit(&zfsdev_state_lock
);
6654 zfsdev_release(struct inode
*ino
, struct file
*filp
)
6658 mutex_enter(&zfsdev_state_lock
);
6659 error
= zfsdev_state_destroy(filp
);
6660 mutex_exit(&zfsdev_state_lock
);
6666 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6670 int error
, rc
, flag
= 0;
6671 const zfs_ioc_vec_t
*vec
;
6672 char *saved_poolname
= NULL
;
6673 nvlist_t
*innvl
= NULL
;
6674 fstrans_cookie_t cookie
;
6676 vecnum
= cmd
- ZFS_IOC_FIRST
;
6677 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6678 return (-SET_ERROR(EINVAL
));
6679 vec
= &zfs_ioc_vec
[vecnum
];
6682 * The registered ioctl list may be sparse, verify that either
6683 * a normal or legacy handler are registered.
6685 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
6686 return (-SET_ERROR(EINVAL
));
6688 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6690 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6692 error
= SET_ERROR(EFAULT
);
6696 zc
->zc_iflags
= flag
& FKIOCTL
;
6697 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
6699 * Make sure the user doesn't pass in an insane value for
6700 * zc_nvlist_src_size. We have to check, since we will end
6701 * up allocating that much memory inside of get_nvlist(). This
6702 * prevents a nefarious user from allocating tons of kernel
6705 * Also, we return EINVAL instead of ENOMEM here. The reason
6706 * being that returning ENOMEM from an ioctl() has a special
6707 * connotation; that the user's size value is too small and
6708 * needs to be expanded to hold the nvlist. See
6709 * zcmd_expand_dst_nvlist() for details.
6711 error
= SET_ERROR(EINVAL
); /* User's size too big */
6713 } else if (zc
->zc_nvlist_src_size
!= 0) {
6714 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6715 zc
->zc_iflags
, &innvl
);
6721 * Ensure that all pool/dataset names are valid before we pass down to
6724 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6725 switch (vec
->zvec_namecheck
) {
6727 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6728 error
= SET_ERROR(EINVAL
);
6730 error
= pool_status_check(zc
->zc_name
,
6731 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6735 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6736 error
= SET_ERROR(EINVAL
);
6738 error
= pool_status_check(zc
->zc_name
,
6739 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6748 cookie
= spl_fstrans_mark();
6749 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
6750 spl_fstrans_unmark(cookie
);
6756 /* legacy ioctls can modify zc_name */
6757 saved_poolname
= strdup(zc
->zc_name
);
6758 if (saved_poolname
== NULL
) {
6759 error
= SET_ERROR(ENOMEM
);
6762 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
6765 if (vec
->zvec_func
!= NULL
) {
6769 nvlist_t
*lognv
= NULL
;
6771 ASSERT(vec
->zvec_legacy_func
== NULL
);
6774 * Add the innvl to the lognv before calling the func,
6775 * in case the func changes the innvl.
6777 if (vec
->zvec_allow_log
) {
6778 lognv
= fnvlist_alloc();
6779 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6781 if (!nvlist_empty(innvl
)) {
6782 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6787 outnvl
= fnvlist_alloc();
6788 cookie
= spl_fstrans_mark();
6789 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6790 spl_fstrans_unmark(cookie
);
6792 if (error
== 0 && vec
->zvec_allow_log
&&
6793 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6794 if (!nvlist_empty(outnvl
)) {
6795 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6798 (void) spa_history_log_nvl(spa
, lognv
);
6799 spa_close(spa
, FTAG
);
6801 fnvlist_free(lognv
);
6803 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6805 if (vec
->zvec_smush_outnvlist
) {
6806 smusherror
= nvlist_smush(outnvl
,
6807 zc
->zc_nvlist_dst_size
);
6809 if (smusherror
== 0)
6810 puterror
= put_nvlist(zc
, outnvl
);
6816 nvlist_free(outnvl
);
6818 cookie
= spl_fstrans_mark();
6819 error
= vec
->zvec_legacy_func(zc
);
6820 spl_fstrans_unmark(cookie
);
6825 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6826 if (error
== 0 && rc
!= 0)
6827 error
= SET_ERROR(EFAULT
);
6828 if (error
== 0 && vec
->zvec_allow_log
) {
6829 char *s
= tsd_get(zfs_allow_log_key
);
6832 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6834 if (saved_poolname
!= NULL
)
6835 strfree(saved_poolname
);
6838 kmem_free(zc
, sizeof (zfs_cmd_t
));
6842 #ifdef CONFIG_COMPAT
6844 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6846 return (zfsdev_ioctl(filp
, cmd
, arg
));
6849 #define zfsdev_compat_ioctl NULL
6852 static const struct file_operations zfsdev_fops
= {
6853 .open
= zfsdev_open
,
6854 .release
= zfsdev_release
,
6855 .unlocked_ioctl
= zfsdev_ioctl
,
6856 .compat_ioctl
= zfsdev_compat_ioctl
,
6857 .owner
= THIS_MODULE
,
6860 static struct miscdevice zfs_misc
= {
6861 .minor
= MISC_DYNAMIC_MINOR
,
6863 .fops
= &zfsdev_fops
,
6871 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6872 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6873 zfsdev_state_list
->zs_minor
= -1;
6875 error
= misc_register(&zfs_misc
);
6877 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
6887 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6889 misc_deregister(&zfs_misc
);
6890 mutex_destroy(&zfsdev_state_lock
);
6892 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6894 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
6898 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
6902 zfs_allow_log_destroy(void *arg
)
6904 char *poolname
= arg
;
6906 if (poolname
!= NULL
)
6911 #define ZFS_DEBUG_STR " (DEBUG mode)"
6913 #define ZFS_DEBUG_STR ""
6921 error
= -vn_set_pwd("/");
6924 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
6928 if ((error
= -zvol_init()) != 0)
6931 spa_init(FREAD
| FWRITE
);
6936 if ((error
= zfs_attach()) != 0)
6939 tsd_create(&zfs_fsyncer_key
, NULL
);
6940 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
6941 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
6943 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
6944 "ZFS pool version %s, ZFS filesystem version %s\n",
6945 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
6946 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
6947 #ifndef CONFIG_FS_POSIX_ACL
6948 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
6949 #endif /* CONFIG_FS_POSIX_ACL */
6957 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
6958 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
6959 ZFS_DEBUG_STR
, error
);
6972 tsd_destroy(&zfs_fsyncer_key
);
6973 tsd_destroy(&rrw_tsd_key
);
6974 tsd_destroy(&zfs_allow_log_key
);
6976 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
6977 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
6984 MODULE_DESCRIPTION("ZFS");
6985 MODULE_AUTHOR(ZFS_META_AUTHOR
);
6986 MODULE_LICENSE(ZFS_META_LICENSE
);
6987 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);
6988 #endif /* HAVE_SPL */