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, 2017 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.
39 * Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
45 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
46 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
48 * There are two ways that we handle ioctls: the legacy way where almost
49 * all of the logic is in the ioctl callback, and the new way where most
50 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
52 * Non-legacy ioctls should be registered by calling
53 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
54 * from userland by lzc_ioctl().
56 * The registration arguments are as follows:
59 * The name of the ioctl. This is used for history logging. If the
60 * ioctl returns successfully (the callback returns 0), and allow_log
61 * is true, then a history log entry will be recorded with the input &
62 * output nvlists. The log entry can be printed with "zpool history -i".
65 * The ioctl request number, which userland will pass to ioctl(2).
66 * The ioctl numbers can change from release to release, because
67 * the caller (libzfs) must be matched to the kernel.
69 * zfs_secpolicy_func_t *secpolicy
70 * This function will be called before the zfs_ioc_func_t, to
71 * determine if this operation is permitted. It should return EPERM
72 * on failure, and 0 on success. Checks include determining if the
73 * dataset is visible in this zone, and if the user has either all
74 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
75 * to do this operation on this dataset with "zfs allow".
77 * zfs_ioc_namecheck_t namecheck
78 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
79 * name, a dataset name, or nothing. If the name is not well-formed,
80 * the ioctl will fail and the callback will not be called.
81 * Therefore, the callback can assume that the name is well-formed
82 * (e.g. is null-terminated, doesn't have more than one '@' character,
83 * doesn't have invalid characters).
85 * zfs_ioc_poolcheck_t pool_check
86 * This specifies requirements on the pool state. If the pool does
87 * not meet them (is suspended or is readonly), the ioctl will fail
88 * and the callback will not be called. If any checks are specified
89 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
90 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
91 * POOL_CHECK_READONLY).
93 * boolean_t smush_outnvlist
94 * If smush_outnvlist is true, then the output is presumed to be a
95 * list of errors, and it will be "smushed" down to fit into the
96 * caller's buffer, by removing some entries and replacing them with a
97 * single "N_MORE_ERRORS" entry indicating how many were removed. See
98 * nvlist_smush() for details. If smush_outnvlist is false, and the
99 * outnvlist does not fit into the userland-provided buffer, then the
100 * ioctl will fail with ENOMEM.
102 * zfs_ioc_func_t *func
103 * The callback function that will perform the operation.
105 * The callback should return 0 on success, or an error number on
106 * failure. If the function fails, the userland ioctl will return -1,
107 * and errno will be set to the callback's return value. The callback
108 * will be called with the following arguments:
111 * The name of the pool or dataset to operate on, from
112 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
113 * expected type (pool, dataset, or none).
116 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
117 * NULL if no input nvlist was provided. Changes to this nvlist are
118 * ignored. If the input nvlist could not be deserialized, the
119 * ioctl will fail and the callback will not be called.
122 * The output nvlist, initially empty. The callback can fill it in,
123 * and it will be returned to userland by serializing it into
124 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
125 * fails (e.g. because the caller didn't supply a large enough
126 * buffer), then the overall ioctl will fail. See the
127 * 'smush_nvlist' argument above for additional behaviors.
129 * There are two typical uses of the output nvlist:
130 * - To return state, e.g. property values. In this case,
131 * smush_outnvlist should be false. If the buffer was not large
132 * enough, the caller will reallocate a larger buffer and try
135 * - To return multiple errors from an ioctl which makes on-disk
136 * changes. In this case, smush_outnvlist should be true.
137 * Ioctls which make on-disk modifications should generally not
138 * use the outnvl if they succeed, because the caller can not
139 * distinguish between the operation failing, and
140 * deserialization failing.
143 #include <sys/types.h>
144 #include <sys/param.h>
145 #include <sys/errno.h>
148 #include <sys/modctl.h>
149 #include <sys/open.h>
150 #include <sys/file.h>
151 #include <sys/kmem.h>
152 #include <sys/conf.h>
153 #include <sys/cmn_err.h>
154 #include <sys/stat.h>
155 #include <sys/zfs_ioctl.h>
156 #include <sys/zfs_vfsops.h>
157 #include <sys/zfs_znode.h>
160 #include <sys/spa_impl.h>
161 #include <sys/vdev.h>
162 #include <sys/vdev_impl.h>
163 #include <sys/priv_impl.h>
165 #include <sys/dsl_dir.h>
166 #include <sys/dsl_dataset.h>
167 #include <sys/dsl_prop.h>
168 #include <sys/dsl_deleg.h>
169 #include <sys/dmu_objset.h>
170 #include <sys/dmu_impl.h>
171 #include <sys/dmu_tx.h>
173 #include <sys/sunddi.h>
174 #include <sys/sunldi.h>
175 #include <sys/policy.h>
176 #include <sys/zone.h>
177 #include <sys/nvpair.h>
178 #include <sys/pathname.h>
179 #include <sys/mount.h>
181 #include <sys/fs/zfs.h>
182 #include <sys/zfs_ctldir.h>
183 #include <sys/zfs_dir.h>
184 #include <sys/zfs_onexit.h>
185 #include <sys/zvol.h>
186 #include <sys/dsl_scan.h>
187 #include <sharefs/share.h>
188 #include <sys/fm/util.h>
189 #include <sys/dsl_crypt.h>
191 #include <sys/dmu_send.h>
192 #include <sys/dsl_destroy.h>
193 #include <sys/dsl_bookmark.h>
194 #include <sys/dsl_userhold.h>
195 #include <sys/zfeature.h>
197 #include <sys/zio_checksum.h>
199 #include <linux/miscdevice.h>
200 #include <linux/slab.h>
202 #include "zfs_namecheck.h"
203 #include "zfs_prop.h"
204 #include "zfs_deleg.h"
205 #include "zfs_comutil.h"
207 #include <sys/lua/lua.h>
208 #include <sys/lua/lauxlib.h>
211 * Limit maximum nvlist size. We don't want users passing in insane values
212 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
214 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
216 kmutex_t zfsdev_state_lock
;
217 zfsdev_state_t
*zfsdev_state_list
;
219 extern void zfs_init(void);
220 extern void zfs_fini(void);
222 uint_t zfs_fsyncer_key
;
223 extern uint_t rrw_tsd_key
;
224 static uint_t zfs_allow_log_key
;
226 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
227 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
228 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
234 } zfs_ioc_namecheck_t
;
237 POOL_CHECK_NONE
= 1 << 0,
238 POOL_CHECK_SUSPENDED
= 1 << 1,
239 POOL_CHECK_READONLY
= 1 << 2,
240 } zfs_ioc_poolcheck_t
;
242 typedef struct zfs_ioc_vec
{
243 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
244 zfs_ioc_func_t
*zvec_func
;
245 zfs_secpolicy_func_t
*zvec_secpolicy
;
246 zfs_ioc_namecheck_t zvec_namecheck
;
247 boolean_t zvec_allow_log
;
248 zfs_ioc_poolcheck_t zvec_pool_check
;
249 boolean_t zvec_smush_outnvlist
;
250 const char *zvec_name
;
253 /* This array is indexed by zfs_userquota_prop_t */
254 static const char *userquota_perms
[] = {
255 ZFS_DELEG_PERM_USERUSED
,
256 ZFS_DELEG_PERM_USERQUOTA
,
257 ZFS_DELEG_PERM_GROUPUSED
,
258 ZFS_DELEG_PERM_GROUPQUOTA
,
259 ZFS_DELEG_PERM_USEROBJUSED
,
260 ZFS_DELEG_PERM_USEROBJQUOTA
,
261 ZFS_DELEG_PERM_GROUPOBJUSED
,
262 ZFS_DELEG_PERM_GROUPOBJQUOTA
,
263 ZFS_DELEG_PERM_PROJECTUSED
,
264 ZFS_DELEG_PERM_PROJECTQUOTA
,
265 ZFS_DELEG_PERM_PROJECTOBJUSED
,
266 ZFS_DELEG_PERM_PROJECTOBJQUOTA
,
269 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
270 static int zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
);
271 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
273 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
275 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
277 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
278 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
281 history_str_free(char *buf
)
283 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
287 history_str_get(zfs_cmd_t
*zc
)
291 if (zc
->zc_history
== 0)
294 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
295 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
296 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
297 history_str_free(buf
);
301 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
307 * Check to see if the named dataset is currently defined as bootable
310 zfs_is_bootfs(const char *name
)
314 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
316 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
317 dmu_objset_rele(os
, FTAG
);
324 * Return non-zero if the spa version is less than requested version.
327 zfs_earlier_version(const char *name
, int version
)
331 if (spa_open(name
, &spa
, FTAG
) == 0) {
332 if (spa_version(spa
) < version
) {
333 spa_close(spa
, FTAG
);
336 spa_close(spa
, FTAG
);
342 * Return TRUE if the ZPL version is less than requested version.
345 zpl_earlier_version(const char *name
, int version
)
348 boolean_t rc
= B_TRUE
;
350 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
353 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
354 dmu_objset_rele(os
, FTAG
);
357 /* XXX reading from non-owned objset */
358 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
359 rc
= zplversion
< version
;
360 dmu_objset_rele(os
, FTAG
);
366 zfs_log_history(zfs_cmd_t
*zc
)
371 if ((buf
= history_str_get(zc
)) == NULL
)
374 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
375 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
376 (void) spa_history_log(spa
, buf
);
377 spa_close(spa
, FTAG
);
379 history_str_free(buf
);
383 * Policy for top-level read operations (list pools). Requires no privileges,
384 * and can be used in the local zone, as there is no associated dataset.
388 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
394 * Policy for dataset read operations (list children, get statistics). Requires
395 * no privileges, but must be visible in the local zone.
399 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
401 if (INGLOBALZONE(curproc
) ||
402 zone_dataset_visible(zc
->zc_name
, NULL
))
405 return (SET_ERROR(ENOENT
));
409 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
414 * The dataset must be visible by this zone -- check this first
415 * so they don't see EPERM on something they shouldn't know about.
417 if (!INGLOBALZONE(curproc
) &&
418 !zone_dataset_visible(dataset
, &writable
))
419 return (SET_ERROR(ENOENT
));
421 if (INGLOBALZONE(curproc
)) {
423 * If the fs is zoned, only root can access it from the
426 if (secpolicy_zfs(cr
) && zoned
)
427 return (SET_ERROR(EPERM
));
430 * If we are in a local zone, the 'zoned' property must be set.
433 return (SET_ERROR(EPERM
));
435 /* must be writable by this zone */
437 return (SET_ERROR(EPERM
));
443 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
447 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
448 return (SET_ERROR(ENOENT
));
450 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
454 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
458 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
459 return (SET_ERROR(ENOENT
));
461 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
465 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
466 const char *perm
, cred_t
*cr
)
470 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
472 error
= secpolicy_zfs(cr
);
474 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
480 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
487 * First do a quick check for root in the global zone, which
488 * is allowed to do all write_perms. This ensures that zfs_ioc_*
489 * will get to handle nonexistent datasets.
491 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
494 error
= dsl_pool_hold(name
, FTAG
, &dp
);
498 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
500 dsl_pool_rele(dp
, FTAG
);
504 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
506 dsl_dataset_rele(ds
, FTAG
);
507 dsl_pool_rele(dp
, FTAG
);
512 * Policy for setting the security label property.
514 * Returns 0 for success, non-zero for access and other errors.
517 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
520 char ds_hexsl
[MAXNAMELEN
];
521 bslabel_t ds_sl
, new_sl
;
522 boolean_t new_default
= FALSE
;
524 int needed_priv
= -1;
527 /* First get the existing dataset label. */
528 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
529 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
531 return (SET_ERROR(EPERM
));
533 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
536 /* The label must be translatable */
537 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
538 return (SET_ERROR(EINVAL
));
541 * In a non-global zone, disallow attempts to set a label that
542 * doesn't match that of the zone; otherwise no other checks
545 if (!INGLOBALZONE(curproc
)) {
546 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
547 return (SET_ERROR(EPERM
));
552 * For global-zone datasets (i.e., those whose zoned property is
553 * "off", verify that the specified new label is valid for the
556 if (dsl_prop_get_integer(name
,
557 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
558 return (SET_ERROR(EPERM
));
560 if (zfs_check_global_label(name
, strval
) != 0)
561 return (SET_ERROR(EPERM
));
565 * If the existing dataset label is nondefault, check if the
566 * dataset is mounted (label cannot be changed while mounted).
567 * Get the zfsvfs_t; if there isn't one, then the dataset isn't
568 * mounted (or isn't a dataset, doesn't exist, ...).
570 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
572 static char *setsl_tag
= "setsl_tag";
575 * Try to own the dataset; abort if there is any error,
576 * (e.g., already mounted, in use, or other error).
578 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
, B_TRUE
,
581 return (SET_ERROR(EPERM
));
583 dmu_objset_disown(os
, B_TRUE
, setsl_tag
);
586 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
590 if (hexstr_to_label(strval
, &new_sl
) != 0)
591 return (SET_ERROR(EPERM
));
593 if (blstrictdom(&ds_sl
, &new_sl
))
594 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
595 else if (blstrictdom(&new_sl
, &ds_sl
))
596 needed_priv
= PRIV_FILE_UPGRADE_SL
;
598 /* dataset currently has a default label */
600 needed_priv
= PRIV_FILE_UPGRADE_SL
;
604 if (needed_priv
!= -1)
605 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
608 return (SET_ERROR(ENOTSUP
));
609 #endif /* HAVE_MLSLABEL */
613 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
619 * Check permissions for special properties.
626 * Disallow setting of 'zoned' from within a local zone.
628 if (!INGLOBALZONE(curproc
))
629 return (SET_ERROR(EPERM
));
633 case ZFS_PROP_FILESYSTEM_LIMIT
:
634 case ZFS_PROP_SNAPSHOT_LIMIT
:
635 if (!INGLOBALZONE(curproc
)) {
637 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
639 * Unprivileged users are allowed to modify the
640 * limit on things *under* (ie. contained by)
641 * the thing they own.
643 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
645 return (SET_ERROR(EPERM
));
646 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
647 return (SET_ERROR(EPERM
));
651 case ZFS_PROP_MLSLABEL
:
652 if (!is_system_labeled())
653 return (SET_ERROR(EPERM
));
655 if (nvpair_value_string(propval
, &strval
) == 0) {
658 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
665 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
670 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
674 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
679 * permission to set permissions will be evaluated later in
680 * dsl_deleg_can_allow()
687 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
689 return (zfs_secpolicy_write_perms(zc
->zc_name
,
690 ZFS_DELEG_PERM_ROLLBACK
, cr
));
695 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
703 * Generate the current snapshot name from the given objsetid, then
704 * use that name for the secpolicy/zone checks.
706 cp
= strchr(zc
->zc_name
, '@');
708 return (SET_ERROR(EINVAL
));
709 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
713 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
715 dsl_pool_rele(dp
, FTAG
);
719 dsl_dataset_name(ds
, zc
->zc_name
);
721 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
722 ZFS_DELEG_PERM_SEND
, cr
);
723 dsl_dataset_rele(ds
, FTAG
);
724 dsl_pool_rele(dp
, FTAG
);
731 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
733 return (zfs_secpolicy_write_perms(zc
->zc_name
,
734 ZFS_DELEG_PERM_SEND
, cr
));
737 #ifdef HAVE_SMB_SHARE
740 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
745 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
746 NO_FOLLOW
, NULL
, &vp
)) != 0)
749 /* Now make sure mntpnt and dataset are ZFS */
751 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
752 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
753 zc
->zc_name
) != 0)) {
755 return (SET_ERROR(EPERM
));
759 return (dsl_deleg_access(zc
->zc_name
,
760 ZFS_DELEG_PERM_SHARE
, cr
));
762 #endif /* HAVE_SMB_SHARE */
765 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
767 #ifdef HAVE_SMB_SHARE
768 if (!INGLOBALZONE(curproc
))
769 return (SET_ERROR(EPERM
));
771 if (secpolicy_nfs(cr
) == 0) {
774 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
777 return (SET_ERROR(ENOTSUP
));
778 #endif /* HAVE_SMB_SHARE */
782 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
784 #ifdef HAVE_SMB_SHARE
785 if (!INGLOBALZONE(curproc
))
786 return (SET_ERROR(EPERM
));
788 if (secpolicy_smb(cr
) == 0) {
791 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
794 return (SET_ERROR(ENOTSUP
));
795 #endif /* HAVE_SMB_SHARE */
799 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
804 * Remove the @bla or /bla from the end of the name to get the parent.
806 (void) strncpy(parent
, datasetname
, parentsize
);
807 cp
= strrchr(parent
, '@');
811 cp
= strrchr(parent
, '/');
813 return (SET_ERROR(ENOENT
));
821 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
825 if ((error
= zfs_secpolicy_write_perms(name
,
826 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
829 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
834 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
836 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
840 * Destroying snapshots with delegated permissions requires
841 * descendant mount and destroy permissions.
845 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
848 nvpair_t
*pair
, *nextpair
;
851 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
852 return (SET_ERROR(EINVAL
));
853 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
855 nextpair
= nvlist_next_nvpair(snaps
, pair
);
856 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
857 if (error
== ENOENT
) {
859 * Ignore any snapshots that don't exist (we consider
860 * them "already destroyed"). Remove the name from the
861 * nvl here in case the snapshot is created between
862 * now and when we try to destroy it (in which case
863 * we don't want to destroy it since we haven't
864 * checked for permission).
866 fnvlist_remove_nvpair(snaps
, pair
);
877 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
879 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
882 if ((error
= zfs_secpolicy_write_perms(from
,
883 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
886 if ((error
= zfs_secpolicy_write_perms(from
,
887 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
890 if ((error
= zfs_get_parent(to
, parentname
,
891 sizeof (parentname
))) != 0)
894 if ((error
= zfs_secpolicy_write_perms(parentname
,
895 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
898 if ((error
= zfs_secpolicy_write_perms(parentname
,
899 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
907 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
909 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
914 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
917 dsl_dataset_t
*clone
;
920 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
921 ZFS_DELEG_PERM_PROMOTE
, cr
);
925 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
929 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
932 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
933 dsl_dataset_t
*origin
= NULL
;
937 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
938 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
940 dsl_dataset_rele(clone
, FTAG
);
941 dsl_pool_rele(dp
, FTAG
);
945 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
946 ZFS_DELEG_PERM_MOUNT
, cr
);
948 dsl_dataset_name(origin
, parentname
);
950 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
951 ZFS_DELEG_PERM_PROMOTE
, cr
);
953 dsl_dataset_rele(clone
, FTAG
);
954 dsl_dataset_rele(origin
, FTAG
);
956 dsl_pool_rele(dp
, FTAG
);
962 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
966 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
967 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
970 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
971 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
974 return (zfs_secpolicy_write_perms(zc
->zc_name
,
975 ZFS_DELEG_PERM_CREATE
, cr
));
980 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
982 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
986 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
988 return (zfs_secpolicy_write_perms(name
,
989 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
993 * Check for permission to create each snapshot in the nvlist.
997 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1003 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
1004 return (SET_ERROR(EINVAL
));
1005 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
1006 pair
= nvlist_next_nvpair(snaps
, pair
)) {
1007 char *name
= nvpair_name(pair
);
1008 char *atp
= strchr(name
, '@');
1011 error
= SET_ERROR(EINVAL
);
1015 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
1024 * Check for permission to create each snapshot in the nvlist.
1028 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1032 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
1033 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1034 char *name
= nvpair_name(pair
);
1035 char *hashp
= strchr(name
, '#');
1037 if (hashp
== NULL
) {
1038 error
= SET_ERROR(EINVAL
);
1042 error
= zfs_secpolicy_write_perms(name
,
1043 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1053 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1055 nvpair_t
*pair
, *nextpair
;
1058 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1060 char *name
= nvpair_name(pair
);
1061 char *hashp
= strchr(name
, '#');
1062 nextpair
= nvlist_next_nvpair(innvl
, pair
);
1064 if (hashp
== NULL
) {
1065 error
= SET_ERROR(EINVAL
);
1070 error
= zfs_secpolicy_write_perms(name
,
1071 ZFS_DELEG_PERM_DESTROY
, cr
);
1073 if (error
== ENOENT
) {
1075 * Ignore any filesystems that don't exist (we consider
1076 * their bookmarks "already destroyed"). Remove
1077 * the name from the nvl here in case the filesystem
1078 * is created between now and when we try to destroy
1079 * the bookmark (in which case we don't want to
1080 * destroy it since we haven't checked for permission).
1082 fnvlist_remove_nvpair(innvl
, pair
);
1094 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1097 * Even root must have a proper TSD so that we know what pool
1100 if (tsd_get(zfs_allow_log_key
) == NULL
)
1101 return (SET_ERROR(EPERM
));
1106 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1108 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1112 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1113 sizeof (parentname
))) != 0)
1116 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1117 (error
= zfs_secpolicy_write_perms(origin
,
1118 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1121 if ((error
= zfs_secpolicy_write_perms(parentname
,
1122 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1125 return (zfs_secpolicy_write_perms(parentname
,
1126 ZFS_DELEG_PERM_MOUNT
, cr
));
1130 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1131 * SYS_CONFIG privilege, which is not available in a local zone.
1135 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1137 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1138 return (SET_ERROR(EPERM
));
1144 * Policy for object to name lookups.
1148 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1152 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1155 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1160 * Policy for fault injection. Requires all privileges.
1164 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1166 return (secpolicy_zinject(cr
));
1171 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1173 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1175 if (prop
== ZPROP_INVAL
) {
1176 if (!zfs_prop_user(zc
->zc_value
))
1177 return (SET_ERROR(EINVAL
));
1178 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1179 ZFS_DELEG_PERM_USERPROP
, cr
));
1181 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1187 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1189 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1193 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1194 return (SET_ERROR(EINVAL
));
1196 if (zc
->zc_value
[0] == 0) {
1198 * They are asking about a posix uid/gid. If it's
1199 * themself, allow it.
1201 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1202 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
||
1203 zc
->zc_objset_type
== ZFS_PROP_USEROBJUSED
||
1204 zc
->zc_objset_type
== ZFS_PROP_USEROBJQUOTA
) {
1205 if (zc
->zc_guid
== crgetuid(cr
))
1207 } else if (zc
->zc_objset_type
== ZFS_PROP_GROUPUSED
||
1208 zc
->zc_objset_type
== ZFS_PROP_GROUPQUOTA
||
1209 zc
->zc_objset_type
== ZFS_PROP_GROUPOBJUSED
||
1210 zc
->zc_objset_type
== ZFS_PROP_GROUPOBJQUOTA
) {
1211 if (groupmember(zc
->zc_guid
, cr
))
1214 /* else is for project quota/used */
1217 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1218 userquota_perms
[zc
->zc_objset_type
], cr
));
1222 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1224 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1228 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1229 return (SET_ERROR(EINVAL
));
1231 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1232 userquota_perms
[zc
->zc_objset_type
], cr
));
1237 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1239 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1245 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1251 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1253 return (SET_ERROR(EINVAL
));
1255 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1256 pair
= nvlist_next_nvpair(holds
, pair
)) {
1257 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1258 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1261 error
= zfs_secpolicy_write_perms(fsname
,
1262 ZFS_DELEG_PERM_HOLD
, cr
);
1271 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1276 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1277 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1278 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1279 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1282 error
= zfs_secpolicy_write_perms(fsname
,
1283 ZFS_DELEG_PERM_RELEASE
, cr
);
1291 * Policy for allowing temporary snapshots to be taken or released
1294 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1297 * A temporary snapshot is the same as a snapshot,
1298 * hold, destroy and release all rolled into one.
1299 * Delegated diff alone is sufficient that we allow this.
1303 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1304 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1307 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1309 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1311 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1313 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1318 zfs_secpolicy_load_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1320 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1321 ZFS_DELEG_PERM_LOAD_KEY
, cr
));
1325 zfs_secpolicy_change_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1327 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1328 ZFS_DELEG_PERM_CHANGE_KEY
, cr
));
1332 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1335 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1339 nvlist_t
*list
= NULL
;
1342 * Read in and unpack the user-supplied nvlist.
1345 return (SET_ERROR(EINVAL
));
1347 packed
= vmem_alloc(size
, KM_SLEEP
);
1349 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1351 vmem_free(packed
, size
);
1352 return (SET_ERROR(EFAULT
));
1355 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1356 vmem_free(packed
, size
);
1360 vmem_free(packed
, size
);
1367 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1368 * Entries will be removed from the end of the nvlist, and one int32 entry
1369 * named "N_MORE_ERRORS" will be added indicating how many entries were
1373 nvlist_smush(nvlist_t
*errors
, size_t max
)
1377 size
= fnvlist_size(errors
);
1380 nvpair_t
*more_errors
;
1384 return (SET_ERROR(ENOMEM
));
1386 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1387 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1390 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1392 fnvlist_remove_nvpair(errors
, pair
);
1394 size
= fnvlist_size(errors
);
1395 } while (size
> max
);
1397 fnvlist_remove_nvpair(errors
, more_errors
);
1398 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1399 ASSERT3U(fnvlist_size(errors
), <=, max
);
1406 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1408 char *packed
= NULL
;
1412 size
= fnvlist_size(nvl
);
1414 if (size
> zc
->zc_nvlist_dst_size
) {
1415 error
= SET_ERROR(ENOMEM
);
1417 packed
= fnvlist_pack(nvl
, &size
);
1418 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1419 size
, zc
->zc_iflags
) != 0)
1420 error
= SET_ERROR(EFAULT
);
1421 fnvlist_pack_free(packed
, size
);
1424 zc
->zc_nvlist_dst_size
= size
;
1425 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1430 getzfsvfs_impl(objset_t
*os
, zfsvfs_t
**zfvp
)
1433 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1434 return (SET_ERROR(EINVAL
));
1437 mutex_enter(&os
->os_user_ptr_lock
);
1438 *zfvp
= dmu_objset_get_user(os
);
1439 /* bump s_active only when non-zero to prevent umount race */
1440 if (*zfvp
== NULL
|| (*zfvp
)->z_sb
== NULL
||
1441 !atomic_inc_not_zero(&((*zfvp
)->z_sb
->s_active
))) {
1442 error
= SET_ERROR(ESRCH
);
1444 mutex_exit(&os
->os_user_ptr_lock
);
1449 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1454 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1458 error
= getzfsvfs_impl(os
, zfvp
);
1459 dmu_objset_rele(os
, FTAG
);
1464 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1465 * case its z_sb will be NULL, and it will be opened as the owner.
1466 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1467 * which prevents all inode ops from running.
1470 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1474 if (getzfsvfs(name
, zfvp
) != 0)
1475 error
= zfsvfs_create(name
, B_FALSE
, zfvp
);
1477 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1479 if ((*zfvp
)->z_unmounted
) {
1481 * XXX we could probably try again, since the unmounting
1482 * thread should be just about to disassociate the
1483 * objset from the zfsvfs.
1485 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1486 return (SET_ERROR(EBUSY
));
1493 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1495 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1498 deactivate_super(zfsvfs
->z_sb
);
1500 dmu_objset_disown(zfsvfs
->z_os
, B_TRUE
, zfsvfs
);
1501 zfsvfs_free(zfsvfs
);
1506 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1509 nvlist_t
*config
, *props
= NULL
;
1510 nvlist_t
*rootprops
= NULL
;
1511 nvlist_t
*zplprops
= NULL
;
1512 dsl_crypto_params_t
*dcp
= NULL
;
1514 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1515 zc
->zc_iflags
, &config
)))
1518 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1519 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1520 zc
->zc_iflags
, &props
))) {
1521 nvlist_free(config
);
1526 nvlist_t
*nvl
= NULL
;
1527 nvlist_t
*hidden_args
= NULL
;
1528 uint64_t version
= SPA_VERSION
;
1530 (void) nvlist_lookup_uint64(props
,
1531 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1532 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1533 error
= SET_ERROR(EINVAL
);
1534 goto pool_props_bad
;
1536 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1538 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1540 nvlist_free(config
);
1544 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1547 (void) nvlist_lookup_nvlist(props
, ZPOOL_HIDDEN_ARGS
,
1549 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
,
1550 rootprops
, hidden_args
, &dcp
);
1552 nvlist_free(config
);
1556 (void) nvlist_remove_all(props
, ZPOOL_HIDDEN_ARGS
);
1558 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1559 error
= zfs_fill_zplprops_root(version
, rootprops
,
1562 goto pool_props_bad
;
1565 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
, dcp
);
1568 * Set the remaining root properties
1570 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1571 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1572 (void) spa_destroy(zc
->zc_name
);
1575 nvlist_free(rootprops
);
1576 nvlist_free(zplprops
);
1577 nvlist_free(config
);
1579 dsl_crypto_params_free(dcp
, !!error
);
1585 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1588 zfs_log_history(zc
);
1589 error
= spa_destroy(zc
->zc_name
);
1595 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1597 nvlist_t
*config
, *props
= NULL
;
1601 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1602 zc
->zc_iflags
, &config
)) != 0)
1605 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1606 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1607 zc
->zc_iflags
, &props
))) {
1608 nvlist_free(config
);
1612 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1613 guid
!= zc
->zc_guid
)
1614 error
= SET_ERROR(EINVAL
);
1616 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1618 if (zc
->zc_nvlist_dst
!= 0) {
1621 if ((err
= put_nvlist(zc
, config
)) != 0)
1625 nvlist_free(config
);
1632 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1635 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1636 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1638 zfs_log_history(zc
);
1639 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1645 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1650 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1651 return (SET_ERROR(EEXIST
));
1653 error
= put_nvlist(zc
, configs
);
1655 nvlist_free(configs
);
1662 * zc_name name of the pool
1665 * zc_cookie real errno
1666 * zc_nvlist_dst config nvlist
1667 * zc_nvlist_dst_size size of config nvlist
1670 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1676 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1677 sizeof (zc
->zc_value
));
1679 if (config
!= NULL
) {
1680 ret
= put_nvlist(zc
, config
);
1681 nvlist_free(config
);
1684 * The config may be present even if 'error' is non-zero.
1685 * In this case we return success, and preserve the real errno
1688 zc
->zc_cookie
= error
;
1697 * Try to import the given pool, returning pool stats as appropriate so that
1698 * user land knows which devices are available and overall pool health.
1701 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1703 nvlist_t
*tryconfig
, *config
= NULL
;
1706 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1707 zc
->zc_iflags
, &tryconfig
)) != 0)
1710 config
= spa_tryimport(tryconfig
);
1712 nvlist_free(tryconfig
);
1715 return (SET_ERROR(EINVAL
));
1717 error
= put_nvlist(zc
, config
);
1718 nvlist_free(config
);
1725 * zc_name name of the pool
1726 * zc_cookie scan func (pool_scan_func_t)
1727 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1730 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1735 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1738 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1739 return (SET_ERROR(EINVAL
));
1741 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1742 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1743 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1744 error
= spa_scan_stop(spa
);
1746 error
= spa_scan(spa
, zc
->zc_cookie
);
1748 spa_close(spa
, FTAG
);
1754 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1759 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1762 spa_close(spa
, FTAG
);
1768 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1773 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1776 if (zc
->zc_cookie
< spa_version(spa
) ||
1777 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1778 spa_close(spa
, FTAG
);
1779 return (SET_ERROR(EINVAL
));
1782 spa_upgrade(spa
, zc
->zc_cookie
);
1783 spa_close(spa
, FTAG
);
1789 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1796 if ((size
= zc
->zc_history_len
) == 0)
1797 return (SET_ERROR(EINVAL
));
1799 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1802 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1803 spa_close(spa
, FTAG
);
1804 return (SET_ERROR(ENOTSUP
));
1807 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1808 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1809 &zc
->zc_history_len
, hist_buf
)) == 0) {
1810 error
= ddi_copyout(hist_buf
,
1811 (void *)(uintptr_t)zc
->zc_history
,
1812 zc
->zc_history_len
, zc
->zc_iflags
);
1815 spa_close(spa
, FTAG
);
1816 vmem_free(hist_buf
, size
);
1821 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1826 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1828 error
= spa_change_guid(spa
);
1829 spa_close(spa
, FTAG
);
1835 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1837 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1842 * zc_name name of filesystem
1843 * zc_obj object to find
1846 * zc_value name of object
1849 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1854 /* XXX reading from objset not owned */
1855 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1858 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1859 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1860 return (SET_ERROR(EINVAL
));
1862 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1863 sizeof (zc
->zc_value
));
1864 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1871 * zc_name name of filesystem
1872 * zc_obj object to find
1875 * zc_stat stats on object
1876 * zc_value path to object
1879 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1884 /* XXX reading from objset not owned */
1885 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1888 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1889 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1890 return (SET_ERROR(EINVAL
));
1892 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1893 sizeof (zc
->zc_value
));
1894 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1900 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1906 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1910 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1911 zc
->zc_iflags
, &config
);
1913 error
= spa_vdev_add(spa
, config
);
1914 nvlist_free(config
);
1916 spa_close(spa
, FTAG
);
1922 * zc_name name of the pool
1923 * zc_nvlist_conf nvlist of devices to remove
1924 * zc_cookie to stop the remove?
1927 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1932 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1935 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1936 spa_close(spa
, FTAG
);
1941 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1945 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1947 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1949 switch (zc
->zc_cookie
) {
1950 case VDEV_STATE_ONLINE
:
1951 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1954 case VDEV_STATE_OFFLINE
:
1955 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1958 case VDEV_STATE_FAULTED
:
1959 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1960 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
&&
1961 zc
->zc_obj
!= VDEV_AUX_EXTERNAL_PERSIST
)
1962 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1964 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1967 case VDEV_STATE_DEGRADED
:
1968 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1969 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1970 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1972 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1976 error
= SET_ERROR(EINVAL
);
1978 zc
->zc_cookie
= newstate
;
1979 spa_close(spa
, FTAG
);
1984 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1987 int replacing
= zc
->zc_cookie
;
1991 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1994 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1995 zc
->zc_iflags
, &config
)) == 0) {
1996 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1997 nvlist_free(config
);
2000 spa_close(spa
, FTAG
);
2005 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
2010 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2013 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
2015 spa_close(spa
, FTAG
);
2020 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
2023 nvlist_t
*config
, *props
= NULL
;
2025 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
2027 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2030 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2031 zc
->zc_iflags
, &config
))) {
2032 spa_close(spa
, FTAG
);
2036 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
2037 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2038 zc
->zc_iflags
, &props
))) {
2039 spa_close(spa
, FTAG
);
2040 nvlist_free(config
);
2044 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
2046 spa_close(spa
, FTAG
);
2048 nvlist_free(config
);
2055 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
2058 char *path
= zc
->zc_value
;
2059 uint64_t guid
= zc
->zc_guid
;
2062 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2066 error
= spa_vdev_setpath(spa
, guid
, path
);
2067 spa_close(spa
, FTAG
);
2072 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
2075 char *fru
= zc
->zc_value
;
2076 uint64_t guid
= zc
->zc_guid
;
2079 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2083 error
= spa_vdev_setfru(spa
, guid
, fru
);
2084 spa_close(spa
, FTAG
);
2089 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2094 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2096 if (zc
->zc_nvlist_dst
!= 0 &&
2097 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2098 dmu_objset_stats(os
, nv
);
2100 * NB: zvol_get_stats() will read the objset contents,
2101 * which we aren't supposed to do with a
2102 * DS_MODE_USER hold, because it could be
2103 * inconsistent. So this is a bit of a workaround...
2104 * XXX reading with out owning
2106 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2107 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2108 error
= zvol_get_stats(os
, nv
);
2116 error
= put_nvlist(zc
, nv
);
2125 * zc_name name of filesystem
2126 * zc_nvlist_dst_size size of buffer for property nvlist
2129 * zc_objset_stats stats
2130 * zc_nvlist_dst property nvlist
2131 * zc_nvlist_dst_size size of property nvlist
2134 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2139 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2141 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2142 dmu_objset_rele(os
, FTAG
);
2150 * zc_name name of filesystem
2151 * zc_nvlist_dst_size size of buffer for property nvlist
2154 * zc_nvlist_dst received property nvlist
2155 * zc_nvlist_dst_size size of received property nvlist
2157 * Gets received properties (distinct from local properties on or after
2158 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2159 * local property values.
2162 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2168 * Without this check, we would return local property values if the
2169 * caller has not already received properties on or after
2170 * SPA_VERSION_RECVD_PROPS.
2172 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2173 return (SET_ERROR(ENOTSUP
));
2175 if (zc
->zc_nvlist_dst
!= 0 &&
2176 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2177 error
= put_nvlist(zc
, nv
);
2185 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2191 * zfs_get_zplprop() will either find a value or give us
2192 * the default value (if there is one).
2194 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2196 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2202 * zc_name name of filesystem
2203 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2206 * zc_nvlist_dst zpl property nvlist
2207 * zc_nvlist_dst_size size of zpl property nvlist
2210 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2215 /* XXX reading without owning */
2216 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2219 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2222 * NB: nvl_add_zplprop() will read the objset contents,
2223 * which we aren't supposed to do with a DS_MODE_USER
2224 * hold, because it could be inconsistent.
2226 if (zc
->zc_nvlist_dst
!= 0 &&
2227 !zc
->zc_objset_stats
.dds_inconsistent
&&
2228 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2231 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2232 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2233 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2234 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2235 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2236 err
= put_nvlist(zc
, nv
);
2239 err
= SET_ERROR(ENOENT
);
2241 dmu_objset_rele(os
, FTAG
);
2246 dataset_name_hidden(const char *name
)
2249 * Skip over datasets that are not visible in this zone,
2250 * internal datasets (which have a $ in their name), and
2251 * temporary datasets (which have a % in their name).
2253 if (strchr(name
, '$') != NULL
)
2255 if (strchr(name
, '%') != NULL
)
2257 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2264 * zc_name name of filesystem
2265 * zc_cookie zap cursor
2266 * zc_nvlist_dst_size size of buffer for property nvlist
2269 * zc_name name of next filesystem
2270 * zc_cookie zap cursor
2271 * zc_objset_stats stats
2272 * zc_nvlist_dst property nvlist
2273 * zc_nvlist_dst_size size of property nvlist
2276 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2281 size_t orig_len
= strlen(zc
->zc_name
);
2284 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2285 if (error
== ENOENT
)
2286 error
= SET_ERROR(ESRCH
);
2290 p
= strrchr(zc
->zc_name
, '/');
2291 if (p
== NULL
|| p
[1] != '\0')
2292 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2293 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2296 error
= dmu_dir_list_next(os
,
2297 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2298 NULL
, &zc
->zc_cookie
);
2299 if (error
== ENOENT
)
2300 error
= SET_ERROR(ESRCH
);
2301 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2302 dmu_objset_rele(os
, FTAG
);
2305 * If it's an internal dataset (ie. with a '$' in its name),
2306 * don't try to get stats for it, otherwise we'll return ENOENT.
2308 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2309 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2310 if (error
== ENOENT
) {
2311 /* We lost a race with destroy, get the next one. */
2312 zc
->zc_name
[orig_len
] = '\0';
2321 * zc_name name of filesystem
2322 * zc_cookie zap cursor
2323 * zc_nvlist_dst_size size of buffer for property nvlist
2326 * zc_name name of next snapshot
2327 * zc_objset_stats stats
2328 * zc_nvlist_dst property nvlist
2329 * zc_nvlist_dst_size size of property nvlist
2332 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2337 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2339 return (error
== ENOENT
? ESRCH
: error
);
2343 * A dataset name of maximum length cannot have any snapshots,
2344 * so exit immediately.
2346 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2347 ZFS_MAX_DATASET_NAME_LEN
) {
2348 dmu_objset_rele(os
, FTAG
);
2349 return (SET_ERROR(ESRCH
));
2352 error
= dmu_snapshot_list_next(os
,
2353 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2354 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2357 if (error
== 0 && !zc
->zc_simple
) {
2359 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2361 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2365 error
= dmu_objset_from_ds(ds
, &ossnap
);
2367 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2368 dsl_dataset_rele(ds
, FTAG
);
2370 } else if (error
== ENOENT
) {
2371 error
= SET_ERROR(ESRCH
);
2374 dmu_objset_rele(os
, FTAG
);
2375 /* if we failed, undo the @ that we tacked on to zc_name */
2377 *strchr(zc
->zc_name
, '@') = '\0';
2382 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2384 const char *propname
= nvpair_name(pair
);
2386 unsigned int vallen
;
2389 zfs_userquota_prop_t type
;
2395 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2397 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2398 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2400 return (SET_ERROR(EINVAL
));
2404 * A correctly constructed propname is encoded as
2405 * userquota@<rid>-<domain>.
2407 if ((dash
= strchr(propname
, '-')) == NULL
||
2408 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2410 return (SET_ERROR(EINVAL
));
2417 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2419 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2420 zfsvfs_rele(zfsvfs
, FTAG
);
2427 * If the named property is one that has a special function to set its value,
2428 * return 0 on success and a positive error code on failure; otherwise if it is
2429 * not one of the special properties handled by this function, return -1.
2431 * XXX: It would be better for callers of the property interface if we handled
2432 * these special cases in dsl_prop.c (in the dsl layer).
2435 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2438 const char *propname
= nvpair_name(pair
);
2439 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2440 uint64_t intval
= 0;
2441 char *strval
= NULL
;
2444 if (prop
== ZPROP_INVAL
) {
2445 if (zfs_prop_userquota(propname
))
2446 return (zfs_prop_set_userquota(dsname
, pair
));
2450 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2452 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2453 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2457 /* all special properties are numeric except for keylocation */
2458 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
) {
2459 strval
= fnvpair_value_string(pair
);
2461 intval
= fnvpair_value_uint64(pair
);
2465 case ZFS_PROP_QUOTA
:
2466 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2468 case ZFS_PROP_REFQUOTA
:
2469 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2471 case ZFS_PROP_FILESYSTEM_LIMIT
:
2472 case ZFS_PROP_SNAPSHOT_LIMIT
:
2473 if (intval
== UINT64_MAX
) {
2474 /* clearing the limit, just do it */
2477 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2480 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2481 * default path to set the value in the nvlist.
2486 case ZFS_PROP_KEYLOCATION
:
2487 err
= dsl_crypto_can_set_keylocation(dsname
, strval
);
2490 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2491 * default path to set the value in the nvlist.
2496 case ZFS_PROP_RESERVATION
:
2497 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2499 case ZFS_PROP_REFRESERVATION
:
2500 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2502 case ZFS_PROP_VOLSIZE
:
2503 err
= zvol_set_volsize(dsname
, intval
);
2505 case ZFS_PROP_SNAPDEV
:
2506 err
= zvol_set_snapdev(dsname
, source
, intval
);
2508 case ZFS_PROP_VOLMODE
:
2509 err
= zvol_set_volmode(dsname
, source
, intval
);
2511 case ZFS_PROP_VERSION
:
2515 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2518 err
= zfs_set_version(zfsvfs
, intval
);
2519 zfsvfs_rele(zfsvfs
, FTAG
);
2521 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2524 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2525 (void) strcpy(zc
->zc_name
, dsname
);
2526 (void) zfs_ioc_userspace_upgrade(zc
);
2527 (void) zfs_ioc_id_quota_upgrade(zc
);
2528 kmem_free(zc
, sizeof (zfs_cmd_t
));
2540 * This function is best effort. If it fails to set any of the given properties,
2541 * it continues to set as many as it can and returns the last error
2542 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2543 * with the list of names of all the properties that failed along with the
2544 * corresponding error numbers.
2546 * If every property is set successfully, zero is returned and errlist is not
2550 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2559 nvlist_t
*genericnvl
= fnvlist_alloc();
2560 nvlist_t
*retrynvl
= fnvlist_alloc();
2563 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2564 const char *propname
= nvpair_name(pair
);
2565 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2568 /* decode the property value */
2570 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2572 attrs
= fnvpair_value_nvlist(pair
);
2573 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2575 err
= SET_ERROR(EINVAL
);
2578 /* Validate value type */
2579 if (err
== 0 && source
== ZPROP_SRC_INHERITED
) {
2580 /* inherited properties are expected to be booleans */
2581 if (nvpair_type(propval
) != DATA_TYPE_BOOLEAN
)
2582 err
= SET_ERROR(EINVAL
);
2583 } else if (err
== 0 && prop
== ZPROP_INVAL
) {
2584 if (zfs_prop_user(propname
)) {
2585 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2586 err
= SET_ERROR(EINVAL
);
2587 } else if (zfs_prop_userquota(propname
)) {
2588 if (nvpair_type(propval
) !=
2589 DATA_TYPE_UINT64_ARRAY
)
2590 err
= SET_ERROR(EINVAL
);
2592 err
= SET_ERROR(EINVAL
);
2594 } else if (err
== 0) {
2595 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2596 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2597 err
= SET_ERROR(EINVAL
);
2598 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2601 intval
= fnvpair_value_uint64(propval
);
2603 switch (zfs_prop_get_type(prop
)) {
2604 case PROP_TYPE_NUMBER
:
2606 case PROP_TYPE_STRING
:
2607 err
= SET_ERROR(EINVAL
);
2609 case PROP_TYPE_INDEX
:
2610 if (zfs_prop_index_to_string(prop
,
2611 intval
, &unused
) != 0)
2612 err
= SET_ERROR(EINVAL
);
2616 "unknown property type");
2619 err
= SET_ERROR(EINVAL
);
2623 /* Validate permissions */
2625 err
= zfs_check_settable(dsname
, pair
, CRED());
2628 if (source
== ZPROP_SRC_INHERITED
)
2629 err
= -1; /* does not need special handling */
2631 err
= zfs_prop_set_special(dsname
, source
,
2635 * For better performance we build up a list of
2636 * properties to set in a single transaction.
2638 err
= nvlist_add_nvpair(genericnvl
, pair
);
2639 } else if (err
!= 0 && nvl
!= retrynvl
) {
2641 * This may be a spurious error caused by
2642 * receiving quota and reservation out of order.
2643 * Try again in a second pass.
2645 err
= nvlist_add_nvpair(retrynvl
, pair
);
2650 if (errlist
!= NULL
)
2651 fnvlist_add_int32(errlist
, propname
, err
);
2656 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2661 if (!nvlist_empty(genericnvl
) &&
2662 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2664 * If this fails, we still want to set as many properties as we
2665 * can, so try setting them individually.
2668 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2669 const char *propname
= nvpair_name(pair
);
2673 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2675 attrs
= fnvpair_value_nvlist(pair
);
2676 propval
= fnvlist_lookup_nvpair(attrs
,
2680 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2681 strval
= fnvpair_value_string(propval
);
2682 err
= dsl_prop_set_string(dsname
, propname
,
2684 } else if (nvpair_type(propval
) == DATA_TYPE_BOOLEAN
) {
2685 err
= dsl_prop_inherit(dsname
, propname
,
2688 intval
= fnvpair_value_uint64(propval
);
2689 err
= dsl_prop_set_int(dsname
, propname
, source
,
2694 if (errlist
!= NULL
) {
2695 fnvlist_add_int32(errlist
, propname
,
2702 nvlist_free(genericnvl
);
2703 nvlist_free(retrynvl
);
2709 * Check that all the properties are valid user properties.
2712 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2714 nvpair_t
*pair
= NULL
;
2717 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2718 const char *propname
= nvpair_name(pair
);
2720 if (!zfs_prop_user(propname
) ||
2721 nvpair_type(pair
) != DATA_TYPE_STRING
)
2722 return (SET_ERROR(EINVAL
));
2724 if ((error
= zfs_secpolicy_write_perms(fsname
,
2725 ZFS_DELEG_PERM_USERPROP
, CRED())))
2728 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2729 return (SET_ERROR(ENAMETOOLONG
));
2731 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2732 return (SET_ERROR(E2BIG
));
2738 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2742 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2745 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2746 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2749 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2754 clear_received_props(const char *dsname
, nvlist_t
*props
,
2758 nvlist_t
*cleared_props
= NULL
;
2759 props_skip(props
, skipped
, &cleared_props
);
2760 if (!nvlist_empty(cleared_props
)) {
2762 * Acts on local properties until the dataset has received
2763 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2765 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2766 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2767 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2769 nvlist_free(cleared_props
);
2775 * zc_name name of filesystem
2776 * zc_value name of property to set
2777 * zc_nvlist_src{_size} nvlist of properties to apply
2778 * zc_cookie received properties flag
2781 * zc_nvlist_dst{_size} error for each unapplied received property
2784 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2787 boolean_t received
= zc
->zc_cookie
;
2788 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2793 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2794 zc
->zc_iflags
, &nvl
)) != 0)
2798 nvlist_t
*origprops
;
2800 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2801 (void) clear_received_props(zc
->zc_name
,
2803 nvlist_free(origprops
);
2806 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2809 errors
= fnvlist_alloc();
2811 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2813 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2814 (void) put_nvlist(zc
, errors
);
2817 nvlist_free(errors
);
2824 * zc_name name of filesystem
2825 * zc_value name of property to inherit
2826 * zc_cookie revert to received value if TRUE
2831 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2833 const char *propname
= zc
->zc_value
;
2834 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2835 boolean_t received
= zc
->zc_cookie
;
2836 zprop_source_t source
= (received
2837 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2838 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2846 * Only check this in the non-received case. We want to allow
2847 * 'inherit -S' to revert non-inheritable properties like quota
2848 * and reservation to the received or default values even though
2849 * they are not considered inheritable.
2851 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2852 return (SET_ERROR(EINVAL
));
2855 if (prop
== ZPROP_INVAL
) {
2856 if (!zfs_prop_user(propname
))
2857 return (SET_ERROR(EINVAL
));
2859 type
= PROP_TYPE_STRING
;
2860 } else if (prop
== ZFS_PROP_VOLSIZE
|| prop
== ZFS_PROP_VERSION
) {
2861 return (SET_ERROR(EINVAL
));
2863 type
= zfs_prop_get_type(prop
);
2867 * zfs_prop_set_special() expects properties in the form of an
2868 * nvpair with type info.
2870 dummy
= fnvlist_alloc();
2873 case PROP_TYPE_STRING
:
2874 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2876 case PROP_TYPE_NUMBER
:
2877 case PROP_TYPE_INDEX
:
2878 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2881 err
= SET_ERROR(EINVAL
);
2885 pair
= nvlist_next_nvpair(dummy
, NULL
);
2887 err
= SET_ERROR(EINVAL
);
2889 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2890 if (err
== -1) /* property is not "special", needs handling */
2891 err
= dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
,
2901 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2908 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2909 zc
->zc_iflags
, &props
)))
2913 * If the only property is the configfile, then just do a spa_lookup()
2914 * to handle the faulted case.
2916 pair
= nvlist_next_nvpair(props
, NULL
);
2917 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2918 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2919 nvlist_next_nvpair(props
, pair
) == NULL
) {
2920 mutex_enter(&spa_namespace_lock
);
2921 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2922 spa_configfile_set(spa
, props
, B_FALSE
);
2923 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2925 mutex_exit(&spa_namespace_lock
);
2932 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2937 error
= spa_prop_set(spa
, props
);
2940 spa_close(spa
, FTAG
);
2946 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2950 nvlist_t
*nvp
= NULL
;
2952 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2954 * If the pool is faulted, there may be properties we can still
2955 * get (such as altroot and cachefile), so attempt to get them
2958 mutex_enter(&spa_namespace_lock
);
2959 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2960 error
= spa_prop_get(spa
, &nvp
);
2961 mutex_exit(&spa_namespace_lock
);
2963 error
= spa_prop_get(spa
, &nvp
);
2964 spa_close(spa
, FTAG
);
2967 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2968 error
= put_nvlist(zc
, nvp
);
2970 error
= SET_ERROR(EFAULT
);
2978 * zc_name name of filesystem
2979 * zc_nvlist_src{_size} nvlist of delegated permissions
2980 * zc_perm_action allow/unallow flag
2985 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2988 nvlist_t
*fsaclnv
= NULL
;
2990 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2991 zc
->zc_iflags
, &fsaclnv
)) != 0)
2995 * Verify nvlist is constructed correctly
2997 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2998 nvlist_free(fsaclnv
);
2999 return (SET_ERROR(EINVAL
));
3003 * If we don't have PRIV_SYS_MOUNT, then validate
3004 * that user is allowed to hand out each permission in
3008 error
= secpolicy_zfs(CRED());
3010 if (zc
->zc_perm_action
== B_FALSE
) {
3011 error
= dsl_deleg_can_allow(zc
->zc_name
,
3014 error
= dsl_deleg_can_unallow(zc
->zc_name
,
3020 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
3022 nvlist_free(fsaclnv
);
3028 * zc_name name of filesystem
3031 * zc_nvlist_src{_size} nvlist of delegated permissions
3034 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
3039 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
3040 error
= put_nvlist(zc
, nvp
);
3049 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
3051 zfs_creat_t
*zct
= arg
;
3053 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
3056 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
3060 * os parent objset pointer (NULL if root fs)
3061 * fuids_ok fuids allowed in this version of the spa?
3062 * sa_ok SAs allowed in this version of the spa?
3063 * createprops list of properties requested by creator
3066 * zplprops values for the zplprops we attach to the master node object
3067 * is_ci true if requested file system will be purely case-insensitive
3069 * Determine the settings for utf8only, normalization and
3070 * casesensitivity. Specific values may have been requested by the
3071 * creator and/or we can inherit values from the parent dataset. If
3072 * the file system is of too early a vintage, a creator can not
3073 * request settings for these properties, even if the requested
3074 * setting is the default value. We don't actually want to create dsl
3075 * properties for these, so remove them from the source nvlist after
3079 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
3080 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
3081 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3083 uint64_t sense
= ZFS_PROP_UNDEFINED
;
3084 uint64_t norm
= ZFS_PROP_UNDEFINED
;
3085 uint64_t u8
= ZFS_PROP_UNDEFINED
;
3088 ASSERT(zplprops
!= NULL
);
3090 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
3091 return (SET_ERROR(EINVAL
));
3094 * Pull out creator prop choices, if any.
3097 (void) nvlist_lookup_uint64(createprops
,
3098 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
3099 (void) nvlist_lookup_uint64(createprops
,
3100 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
3101 (void) nvlist_remove_all(createprops
,
3102 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3103 (void) nvlist_lookup_uint64(createprops
,
3104 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3105 (void) nvlist_remove_all(createprops
,
3106 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3107 (void) nvlist_lookup_uint64(createprops
,
3108 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3109 (void) nvlist_remove_all(createprops
,
3110 zfs_prop_to_name(ZFS_PROP_CASE
));
3114 * If the zpl version requested is whacky or the file system
3115 * or pool is version is too "young" to support normalization
3116 * and the creator tried to set a value for one of the props,
3119 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3120 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3121 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3122 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3123 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3124 sense
!= ZFS_PROP_UNDEFINED
)))
3125 return (SET_ERROR(ENOTSUP
));
3128 * Put the version in the zplprops
3130 VERIFY(nvlist_add_uint64(zplprops
,
3131 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3133 if (norm
== ZFS_PROP_UNDEFINED
&&
3134 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3136 VERIFY(nvlist_add_uint64(zplprops
,
3137 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3140 * If we're normalizing, names must always be valid UTF-8 strings.
3144 if (u8
== ZFS_PROP_UNDEFINED
&&
3145 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3147 VERIFY(nvlist_add_uint64(zplprops
,
3148 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3150 if (sense
== ZFS_PROP_UNDEFINED
&&
3151 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3153 VERIFY(nvlist_add_uint64(zplprops
,
3154 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3157 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3163 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3164 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3166 boolean_t fuids_ok
, sa_ok
;
3167 uint64_t zplver
= ZPL_VERSION
;
3168 objset_t
*os
= NULL
;
3169 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3175 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3176 cp
= strrchr(parentname
, '/');
3180 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3183 spa_vers
= spa_version(spa
);
3184 spa_close(spa
, FTAG
);
3186 zplver
= zfs_zpl_version_map(spa_vers
);
3187 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3188 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3191 * Open parent object set so we can inherit zplprop values.
3193 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3196 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3198 dmu_objset_rele(os
, FTAG
);
3203 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3204 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3208 uint64_t zplver
= ZPL_VERSION
;
3211 zplver
= zfs_zpl_version_map(spa_vers
);
3212 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3213 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3215 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3216 createprops
, zplprops
, is_ci
);
3222 * "type" -> dmu_objset_type_t (int32)
3223 * (optional) "props" -> { prop -> value }
3224 * (optional) "hidden_args" -> { "wkeydata" -> value }
3225 * raw uint8_t array of encryption wrapping key data (32 bytes)
3228 * outnvl: propname -> error code (int32)
3231 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3234 zfs_creat_t zct
= { 0 };
3235 nvlist_t
*nvprops
= NULL
;
3236 nvlist_t
*hidden_args
= NULL
;
3237 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3239 dmu_objset_type_t type
;
3240 boolean_t is_insensitive
= B_FALSE
;
3241 dsl_crypto_params_t
*dcp
= NULL
;
3243 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3244 return (SET_ERROR(EINVAL
));
3246 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3247 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
3251 cbfunc
= zfs_create_cb
;
3255 cbfunc
= zvol_create_cb
;
3262 if (strchr(fsname
, '@') ||
3263 strchr(fsname
, '%'))
3264 return (SET_ERROR(EINVAL
));
3266 zct
.zct_props
= nvprops
;
3269 return (SET_ERROR(EINVAL
));
3271 if (type
== DMU_OST_ZVOL
) {
3272 uint64_t volsize
, volblocksize
;
3274 if (nvprops
== NULL
)
3275 return (SET_ERROR(EINVAL
));
3276 if (nvlist_lookup_uint64(nvprops
,
3277 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3278 return (SET_ERROR(EINVAL
));
3280 if ((error
= nvlist_lookup_uint64(nvprops
,
3281 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3282 &volblocksize
)) != 0 && error
!= ENOENT
)
3283 return (SET_ERROR(EINVAL
));
3286 volblocksize
= zfs_prop_default_numeric(
3287 ZFS_PROP_VOLBLOCKSIZE
);
3289 if ((error
= zvol_check_volblocksize(fsname
,
3290 volblocksize
)) != 0 ||
3291 (error
= zvol_check_volsize(volsize
,
3292 volblocksize
)) != 0)
3294 } else if (type
== DMU_OST_ZFS
) {
3298 * We have to have normalization and
3299 * case-folding flags correct when we do the
3300 * file system creation, so go figure them out
3303 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3304 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3305 error
= zfs_fill_zplprops(fsname
, nvprops
,
3306 zct
.zct_zplprops
, &is_insensitive
);
3308 nvlist_free(zct
.zct_zplprops
);
3313 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, nvprops
,
3316 nvlist_free(zct
.zct_zplprops
);
3320 error
= dmu_objset_create(fsname
, type
,
3321 is_insensitive
? DS_FLAG_CI_DATASET
: 0, dcp
, cbfunc
, &zct
);
3323 nvlist_free(zct
.zct_zplprops
);
3324 dsl_crypto_params_free(dcp
, !!error
);
3327 * It would be nice to do this atomically.
3330 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3337 * Volumes will return EBUSY and cannot be destroyed
3338 * until all asynchronous minor handling has completed.
3339 * Wait for the spa_zvol_taskq to drain then retry.
3341 error2
= dsl_destroy_head(fsname
);
3342 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3343 error2
= spa_open(fsname
, &spa
, FTAG
);
3345 taskq_wait(spa
->spa_zvol_taskq
);
3346 spa_close(spa
, FTAG
);
3348 error2
= dsl_destroy_head(fsname
);
3357 * "origin" -> name of origin snapshot
3358 * (optional) "props" -> { prop -> value }
3359 * (optional) "hidden_args" -> { "wkeydata" -> value }
3360 * raw uint8_t array of encryption wrapping key data (32 bytes)
3364 * outnvl: propname -> error code (int32)
3367 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3370 nvlist_t
*nvprops
= NULL
;
3373 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3374 return (SET_ERROR(EINVAL
));
3375 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3377 if (strchr(fsname
, '@') ||
3378 strchr(fsname
, '%'))
3379 return (SET_ERROR(EINVAL
));
3381 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3382 return (SET_ERROR(EINVAL
));
3384 error
= dmu_objset_clone(fsname
, origin_name
);
3387 * It would be nice to do this atomically.
3390 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3393 (void) dsl_destroy_head(fsname
);
3400 * "snaps" -> { snapshot1, snapshot2 }
3401 * (optional) "props" -> { prop -> value (string) }
3404 * outnvl: snapshot -> error code (int32)
3407 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3410 nvlist_t
*props
= NULL
;
3414 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3415 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3418 if (!nvlist_empty(props
) &&
3419 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3420 return (SET_ERROR(ENOTSUP
));
3422 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3423 return (SET_ERROR(EINVAL
));
3424 poollen
= strlen(poolname
);
3425 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3426 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3427 const char *name
= nvpair_name(pair
);
3428 const char *cp
= strchr(name
, '@');
3431 * The snap name must contain an @, and the part after it must
3432 * contain only valid characters.
3435 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3436 return (SET_ERROR(EINVAL
));
3439 * The snap must be in the specified pool.
3441 if (strncmp(name
, poolname
, poollen
) != 0 ||
3442 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3443 return (SET_ERROR(EXDEV
));
3445 /* This must be the only snap of this fs. */
3446 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3447 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3448 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3450 return (SET_ERROR(EXDEV
));
3455 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3461 * innvl: "message" -> string
3465 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3473 * The poolname in the ioctl is not set, we get it from the TSD,
3474 * which was set at the end of the last successful ioctl that allows
3475 * logging. The secpolicy func already checked that it is set.
3476 * Only one log ioctl is allowed after each successful ioctl, so
3477 * we clear the TSD here.
3479 poolname
= tsd_get(zfs_allow_log_key
);
3480 if (poolname
== NULL
)
3481 return (SET_ERROR(EINVAL
));
3482 (void) tsd_set(zfs_allow_log_key
, NULL
);
3483 error
= spa_open(poolname
, &spa
, FTAG
);
3488 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3489 spa_close(spa
, FTAG
);
3490 return (SET_ERROR(EINVAL
));
3493 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3494 spa_close(spa
, FTAG
);
3495 return (SET_ERROR(ENOTSUP
));
3498 error
= spa_history_log(spa
, message
);
3499 spa_close(spa
, FTAG
);
3504 * The dp_config_rwlock must not be held when calling this, because the
3505 * unmount may need to write out data.
3507 * This function is best-effort. Callers must deal gracefully if it
3508 * remains mounted (or is remounted after this call).
3510 * Returns 0 if the argument is not a snapshot, or it is not currently a
3511 * filesystem, or we were able to unmount it. Returns error code otherwise.
3514 zfs_unmount_snap(const char *snapname
)
3516 if (strchr(snapname
, '@') == NULL
)
3519 (void) zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3524 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3526 zfs_unmount_snap(snapname
);
3531 * When a clone is destroyed, its origin may also need to be destroyed,
3532 * in which case it must be unmounted. This routine will do that unmount
3536 zfs_destroy_unmount_origin(const char *fsname
)
3542 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3545 ds
= dmu_objset_ds(os
);
3546 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3547 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3548 dsl_dataset_name(ds
->ds_prev
, originname
);
3549 dmu_objset_rele(os
, FTAG
);
3550 zfs_unmount_snap(originname
);
3552 dmu_objset_rele(os
, FTAG
);
3558 * "snaps" -> { snapshot1, snapshot2 }
3559 * (optional boolean) "defer"
3562 * outnvl: snapshot -> error code (int32)
3566 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3572 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3573 return (SET_ERROR(EINVAL
));
3574 defer
= nvlist_exists(innvl
, "defer");
3576 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3577 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3578 zfs_unmount_snap(nvpair_name(pair
));
3581 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3585 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3586 * All bookmarks must be in the same pool.
3589 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3592 * outnvl: bookmark -> error code (int32)
3597 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3599 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3600 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3604 * Verify the snapshot argument.
3606 if (nvpair_value_string(pair
, &snap_name
) != 0)
3607 return (SET_ERROR(EINVAL
));
3610 /* Verify that the keys (bookmarks) are unique */
3611 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3612 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3613 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3614 return (SET_ERROR(EINVAL
));
3618 return (dsl_bookmark_create(innvl
, outnvl
));
3623 * property 1, property 2, ...
3627 * bookmark name 1 -> { property 1, property 2, ... },
3628 * bookmark name 2 -> { property 1, property 2, ... }
3633 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3635 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3640 * bookmark name 1, bookmark name 2
3643 * outnvl: bookmark -> error code (int32)
3647 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3652 poollen
= strlen(poolname
);
3653 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3654 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3655 const char *name
= nvpair_name(pair
);
3656 const char *cp
= strchr(name
, '#');
3659 * The bookmark name must contain an #, and the part after it
3660 * must contain only valid characters.
3663 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3664 return (SET_ERROR(EINVAL
));
3667 * The bookmark must be in the specified pool.
3669 if (strncmp(name
, poolname
, poollen
) != 0 ||
3670 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3671 return (SET_ERROR(EXDEV
));
3674 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3679 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3683 uint64_t instrlimit
, memlimit
;
3684 boolean_t sync_flag
;
3685 nvpair_t
*nvarg
= NULL
;
3687 if (0 != nvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
, &program
)) {
3690 if (0 != nvlist_lookup_boolean_value(innvl
, ZCP_ARG_SYNC
, &sync_flag
)) {
3693 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3694 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3696 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3697 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3699 if (0 != nvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
, &nvarg
)) {
3703 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3705 if (memlimit
== 0 || memlimit
> zfs_lua_max_memlimit
)
3708 return (zcp_eval(poolname
, program
, sync_flag
, instrlimit
, memlimit
,
3714 * zc_name name of dataset to destroy
3715 * zc_objset_type type of objset
3716 * zc_defer_destroy mark for deferred destroy
3721 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3725 if (zc
->zc_objset_type
== DMU_OST_ZFS
)
3726 zfs_unmount_snap(zc
->zc_name
);
3728 if (strchr(zc
->zc_name
, '@')) {
3729 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3731 err
= dsl_destroy_head(zc
->zc_name
);
3732 if (err
== EEXIST
) {
3734 * It is possible that the given DS may have
3735 * hidden child (%recv) datasets - "leftovers"
3736 * resulting from the previously interrupted
3739 * 6 extra bytes for /%recv
3741 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3743 if (snprintf(namebuf
, sizeof (namebuf
), "%s/%s",
3744 zc
->zc_name
, recv_clone_name
) >=
3746 return (SET_ERROR(EINVAL
));
3749 * Try to remove the hidden child (%recv) and after
3750 * that try to remove the target dataset.
3751 * If the hidden child (%recv) does not exist
3752 * the original error (EEXIST) will be returned
3754 err
= dsl_destroy_head(namebuf
);
3756 err
= dsl_destroy_head(zc
->zc_name
);
3757 else if (err
== ENOENT
)
3758 err
= SET_ERROR(EEXIST
);
3766 * fsname is name of dataset to rollback (to most recent snapshot)
3768 * innvl may contain name of expected target snapshot
3770 * outnvl: "target" -> name of most recent snapshot
3775 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3779 char *target
= NULL
;
3782 (void) nvlist_lookup_string(innvl
, "target", &target
);
3783 if (target
!= NULL
) {
3784 const char *cp
= strchr(target
, '@');
3787 * The snap name must contain an @, and the part after it must
3788 * contain only valid characters.
3791 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3792 return (SET_ERROR(EINVAL
));
3795 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3798 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3799 error
= zfs_suspend_fs(zfsvfs
);
3803 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3805 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3806 error
= error
? error
: resume_err
;
3808 deactivate_super(zfsvfs
->z_sb
);
3809 } else if ((zv
= zvol_suspend(fsname
)) != NULL
) {
3810 error
= dsl_dataset_rollback(fsname
, target
, zvol_tag(zv
),
3814 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3820 recursive_unmount(const char *fsname
, void *arg
)
3822 const char *snapname
= arg
;
3825 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3826 zfs_unmount_snap(fullname
);
3834 * zc_name old name of dataset
3835 * zc_value new name of dataset
3836 * zc_cookie recursive flag (only valid for snapshots)
3841 zfs_ioc_rename(zfs_cmd_t
*zc
)
3843 boolean_t recursive
= zc
->zc_cookie
& 1;
3846 /* "zfs rename" from and to ...%recv datasets should both fail */
3847 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
3848 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3849 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
3850 dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3851 strchr(zc
->zc_name
, '%') || strchr(zc
->zc_value
, '%'))
3852 return (SET_ERROR(EINVAL
));
3854 at
= strchr(zc
->zc_name
, '@');
3856 /* snaps must be in same fs */
3859 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3860 return (SET_ERROR(EXDEV
));
3862 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3863 error
= dmu_objset_find(zc
->zc_name
,
3864 recursive_unmount
, at
+ 1,
3865 recursive
? DS_FIND_CHILDREN
: 0);
3871 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3872 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3877 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3882 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3884 const char *propname
= nvpair_name(pair
);
3885 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3886 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3890 if (prop
== ZPROP_INVAL
) {
3891 if (zfs_prop_user(propname
)) {
3892 if ((err
= zfs_secpolicy_write_perms(dsname
,
3893 ZFS_DELEG_PERM_USERPROP
, cr
)))
3898 if (!issnap
&& zfs_prop_userquota(propname
)) {
3899 const char *perm
= NULL
;
3900 const char *uq_prefix
=
3901 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3902 const char *gq_prefix
=
3903 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3904 const char *uiq_prefix
=
3905 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
];
3906 const char *giq_prefix
=
3907 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
];
3908 const char *pq_prefix
=
3909 zfs_userquota_prop_prefixes
[ZFS_PROP_PROJECTQUOTA
];
3910 const char *piq_prefix
= zfs_userquota_prop_prefixes
[\
3911 ZFS_PROP_PROJECTOBJQUOTA
];
3913 if (strncmp(propname
, uq_prefix
,
3914 strlen(uq_prefix
)) == 0) {
3915 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3916 } else if (strncmp(propname
, uiq_prefix
,
3917 strlen(uiq_prefix
)) == 0) {
3918 perm
= ZFS_DELEG_PERM_USEROBJQUOTA
;
3919 } else if (strncmp(propname
, gq_prefix
,
3920 strlen(gq_prefix
)) == 0) {
3921 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3922 } else if (strncmp(propname
, giq_prefix
,
3923 strlen(giq_prefix
)) == 0) {
3924 perm
= ZFS_DELEG_PERM_GROUPOBJQUOTA
;
3925 } else if (strncmp(propname
, pq_prefix
,
3926 strlen(pq_prefix
)) == 0) {
3927 perm
= ZFS_DELEG_PERM_PROJECTQUOTA
;
3928 } else if (strncmp(propname
, piq_prefix
,
3929 strlen(piq_prefix
)) == 0) {
3930 perm
= ZFS_DELEG_PERM_PROJECTOBJQUOTA
;
3932 /* {USER|GROUP|PROJECT}USED are read-only */
3933 return (SET_ERROR(EINVAL
));
3936 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3941 return (SET_ERROR(EINVAL
));
3945 return (SET_ERROR(EINVAL
));
3947 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3949 * dsl_prop_get_all_impl() returns properties in this
3953 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3954 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3959 * Check that this value is valid for this pool version
3962 case ZFS_PROP_COMPRESSION
:
3964 * If the user specified gzip compression, make sure
3965 * the SPA supports it. We ignore any errors here since
3966 * we'll catch them later.
3968 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3969 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3970 intval
<= ZIO_COMPRESS_GZIP_9
&&
3971 zfs_earlier_version(dsname
,
3972 SPA_VERSION_GZIP_COMPRESSION
)) {
3973 return (SET_ERROR(ENOTSUP
));
3976 if (intval
== ZIO_COMPRESS_ZLE
&&
3977 zfs_earlier_version(dsname
,
3978 SPA_VERSION_ZLE_COMPRESSION
))
3979 return (SET_ERROR(ENOTSUP
));
3981 if (intval
== ZIO_COMPRESS_LZ4
) {
3984 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3987 if (!spa_feature_is_enabled(spa
,
3988 SPA_FEATURE_LZ4_COMPRESS
)) {
3989 spa_close(spa
, FTAG
);
3990 return (SET_ERROR(ENOTSUP
));
3992 spa_close(spa
, FTAG
);
3996 * If this is a bootable dataset then
3997 * verify that the compression algorithm
3998 * is supported for booting. We must return
3999 * something other than ENOTSUP since it
4000 * implies a downrev pool version.
4002 if (zfs_is_bootfs(dsname
) &&
4003 !BOOTFS_COMPRESS_VALID(intval
)) {
4004 return (SET_ERROR(ERANGE
));
4009 case ZFS_PROP_COPIES
:
4010 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
4011 return (SET_ERROR(ENOTSUP
));
4014 case ZFS_PROP_VOLBLOCKSIZE
:
4015 case ZFS_PROP_RECORDSIZE
:
4016 /* Record sizes above 128k need the feature to be enabled */
4017 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4018 intval
> SPA_OLD_MAXBLOCKSIZE
) {
4022 * We don't allow setting the property above 1MB,
4023 * unless the tunable has been changed.
4025 if (intval
> zfs_max_recordsize
||
4026 intval
> SPA_MAXBLOCKSIZE
)
4027 return (SET_ERROR(ERANGE
));
4029 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4032 if (!spa_feature_is_enabled(spa
,
4033 SPA_FEATURE_LARGE_BLOCKS
)) {
4034 spa_close(spa
, FTAG
);
4035 return (SET_ERROR(ENOTSUP
));
4037 spa_close(spa
, FTAG
);
4041 case ZFS_PROP_DNODESIZE
:
4042 /* Dnode sizes above 512 need the feature to be enabled */
4043 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4044 intval
!= ZFS_DNSIZE_LEGACY
) {
4048 * If this is a bootable dataset then
4049 * we don't allow large (>512B) dnodes,
4050 * because GRUB doesn't support them.
4052 if (zfs_is_bootfs(dsname
) &&
4053 intval
!= ZFS_DNSIZE_LEGACY
) {
4054 return (SET_ERROR(EDOM
));
4057 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4060 if (!spa_feature_is_enabled(spa
,
4061 SPA_FEATURE_LARGE_DNODE
)) {
4062 spa_close(spa
, FTAG
);
4063 return (SET_ERROR(ENOTSUP
));
4065 spa_close(spa
, FTAG
);
4069 case ZFS_PROP_SHARESMB
:
4070 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
4071 return (SET_ERROR(ENOTSUP
));
4074 case ZFS_PROP_ACLINHERIT
:
4075 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4076 nvpair_value_uint64(pair
, &intval
) == 0) {
4077 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
4078 zfs_earlier_version(dsname
,
4079 SPA_VERSION_PASSTHROUGH_X
))
4080 return (SET_ERROR(ENOTSUP
));
4083 case ZFS_PROP_CHECKSUM
:
4084 case ZFS_PROP_DEDUP
:
4086 spa_feature_t feature
;
4091 /* dedup feature version checks */
4092 if (prop
== ZFS_PROP_DEDUP
&&
4093 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
4094 return (SET_ERROR(ENOTSUP
));
4096 if (nvpair_value_uint64(pair
, &intval
) != 0)
4097 return (SET_ERROR(EINVAL
));
4099 /* check prop value is enabled in features */
4100 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
4101 if (feature
== SPA_FEATURE_NONE
)
4104 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4107 * Salted checksums are not supported on root pools.
4109 if (spa_bootfs(spa
) != 0 &&
4110 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
4111 (zio_checksum_table
[intval
].ci_flags
&
4112 ZCHECKSUM_FLAG_SALTED
)) {
4113 spa_close(spa
, FTAG
);
4114 return (SET_ERROR(ERANGE
));
4116 if (!spa_feature_is_enabled(spa
, feature
)) {
4117 spa_close(spa
, FTAG
);
4118 return (SET_ERROR(ENOTSUP
));
4120 spa_close(spa
, FTAG
);
4128 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
4132 * Removes properties from the given props list that fail permission checks
4133 * needed to clear them and to restore them in case of a receive error. For each
4134 * property, make sure we have both set and inherit permissions.
4136 * Returns the first error encountered if any permission checks fail. If the
4137 * caller provides a non-NULL errlist, it also gives the complete list of names
4138 * of all the properties that failed a permission check along with the
4139 * corresponding error numbers. The caller is responsible for freeing the
4142 * If every property checks out successfully, zero is returned and the list
4143 * pointed at by errlist is NULL.
4146 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
4149 nvpair_t
*pair
, *next_pair
;
4156 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4158 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
4159 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
4160 pair
= nvlist_next_nvpair(props
, NULL
);
4161 while (pair
!= NULL
) {
4162 next_pair
= nvlist_next_nvpair(props
, pair
);
4164 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
4165 sizeof (zc
->zc_value
));
4166 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
4167 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
4168 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
4169 VERIFY(nvlist_add_int32(errors
,
4170 zc
->zc_value
, err
) == 0);
4174 kmem_free(zc
, sizeof (zfs_cmd_t
));
4176 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
4177 nvlist_free(errors
);
4180 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
4183 if (errlist
== NULL
)
4184 nvlist_free(errors
);
4192 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4194 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4195 /* dsl_prop_get_all_impl() format */
4197 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4198 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4202 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4204 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4205 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4209 if (nvpair_type(p1
) != nvpair_type(p2
))
4212 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4213 char *valstr1
, *valstr2
;
4215 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4216 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4217 return (strcmp(valstr1
, valstr2
) == 0);
4219 uint64_t intval1
, intval2
;
4221 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4222 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4223 return (intval1
== intval2
);
4228 * Remove properties from props if they are not going to change (as determined
4229 * by comparison with origprops). Remove them from origprops as well, since we
4230 * do not need to clear or restore properties that won't change.
4233 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4235 nvpair_t
*pair
, *next_pair
;
4237 if (origprops
== NULL
)
4238 return; /* all props need to be received */
4240 pair
= nvlist_next_nvpair(props
, NULL
);
4241 while (pair
!= NULL
) {
4242 const char *propname
= nvpair_name(pair
);
4245 next_pair
= nvlist_next_nvpair(props
, pair
);
4247 if ((nvlist_lookup_nvpair(origprops
, propname
,
4248 &match
) != 0) || !propval_equals(pair
, match
))
4249 goto next
; /* need to set received value */
4251 /* don't clear the existing received value */
4252 (void) nvlist_remove_nvpair(origprops
, match
);
4253 /* don't bother receiving the property */
4254 (void) nvlist_remove_nvpair(props
, pair
);
4261 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4262 * For example, refquota cannot be set until after the receipt of a dataset,
4263 * because in replication streams, an older/earlier snapshot may exceed the
4264 * refquota. We want to receive the older/earlier snapshot, but setting
4265 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4266 * the older/earlier snapshot from being received (with EDQUOT).
4268 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4270 * libzfs will need to be judicious handling errors encountered by props
4271 * extracted by this function.
4274 extract_delay_props(nvlist_t
*props
)
4276 nvlist_t
*delayprops
;
4277 nvpair_t
*nvp
, *tmp
;
4278 static const zfs_prop_t delayable
[] = {
4280 ZFS_PROP_KEYLOCATION
,
4285 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4287 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4288 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4290 * strcmp() is safe because zfs_prop_to_name() always returns
4293 for (i
= 0; delayable
[i
] != 0; i
++) {
4294 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4295 nvpair_name(nvp
)) == 0) {
4299 if (delayable
[i
] != 0) {
4300 tmp
= nvlist_prev_nvpair(props
, nvp
);
4301 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4302 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4307 if (nvlist_empty(delayprops
)) {
4308 nvlist_free(delayprops
);
4311 return (delayprops
);
4315 static boolean_t zfs_ioc_recv_inject_err
;
4319 * nvlist 'errors' is always allocated. It will contain descriptions of
4320 * encountered errors, if any. It's the callers responsibility to free.
4323 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
, nvlist_t
*recvprops
,
4324 nvlist_t
*localprops
, boolean_t force
, boolean_t resumable
, int input_fd
,
4325 dmu_replay_record_t
*begin_record
, int cleanup_fd
, uint64_t *read_bytes
,
4326 uint64_t *errflags
, uint64_t *action_handle
, nvlist_t
**errors
)
4328 dmu_recv_cookie_t drc
;
4330 int props_error
= 0;
4332 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4333 nvlist_t
*origprops
= NULL
; /* existing properties */
4334 nvlist_t
*origrecvd
= NULL
; /* existing received properties */
4335 boolean_t first_recvd_props
= B_FALSE
;
4340 *errors
= fnvlist_alloc();
4342 input_fp
= getf(input_fd
);
4343 if (input_fp
== NULL
)
4344 return (SET_ERROR(EBADF
));
4346 error
= dmu_recv_begin(tofs
, tosnap
,
4347 begin_record
, force
, resumable
, origin
, &drc
);
4352 * Set properties before we receive the stream so that they are applied
4353 * to the new data. Note that we must call dmu_recv_stream() if
4354 * dmu_recv_begin() succeeds.
4356 if (recvprops
!= NULL
&& !drc
.drc_newfs
) {
4357 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4358 SPA_VERSION_RECVD_PROPS
&&
4359 !dsl_prop_get_hasrecvd(tofs
))
4360 first_recvd_props
= B_TRUE
;
4363 * If new received properties are supplied, they are to
4364 * completely replace the existing received properties, so stash
4365 * away the existing ones.
4367 if (dsl_prop_get_received(tofs
, &origrecvd
) == 0) {
4368 nvlist_t
*errlist
= NULL
;
4370 * Don't bother writing a property if its value won't
4371 * change (and avoid the unnecessary security checks).
4373 * The first receive after SPA_VERSION_RECVD_PROPS is a
4374 * special case where we blow away all local properties
4377 if (!first_recvd_props
)
4378 props_reduce(recvprops
, origrecvd
);
4379 if (zfs_check_clearable(tofs
, origrecvd
, &errlist
) != 0)
4380 (void) nvlist_merge(*errors
, errlist
, 0);
4381 nvlist_free(errlist
);
4383 if (clear_received_props(tofs
, origrecvd
,
4384 first_recvd_props
? NULL
: recvprops
) != 0)
4385 *errflags
|= ZPROP_ERR_NOCLEAR
;
4387 *errflags
|= ZPROP_ERR_NOCLEAR
;
4392 * Stash away existing properties so we can restore them on error unless
4393 * we're doing the first receive after SPA_VERSION_RECVD_PROPS, in which
4394 * case "origrecvd" will take care of that.
4396 if (localprops
!= NULL
&& !drc
.drc_newfs
&& !first_recvd_props
) {
4398 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
4399 if (dsl_prop_get_all(os
, &origprops
) != 0) {
4400 *errflags
|= ZPROP_ERR_NOCLEAR
;
4402 dmu_objset_rele(os
, FTAG
);
4404 *errflags
|= ZPROP_ERR_NOCLEAR
;
4408 if (recvprops
!= NULL
) {
4409 props_error
= dsl_prop_set_hasrecvd(tofs
);
4411 if (props_error
== 0) {
4412 delayprops
= extract_delay_props(recvprops
);
4413 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4414 recvprops
, *errors
);
4418 if (localprops
!= NULL
) {
4419 nvlist_t
*oprops
= fnvlist_alloc();
4420 nvlist_t
*xprops
= fnvlist_alloc();
4421 nvpair_t
*nvp
= NULL
;
4423 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4424 if (nvpair_type(nvp
) == DATA_TYPE_BOOLEAN
) {
4426 const char *name
= nvpair_name(nvp
);
4427 zfs_prop_t prop
= zfs_name_to_prop(name
);
4428 if (prop
!= ZPROP_INVAL
) {
4429 if (!zfs_prop_inheritable(prop
))
4431 } else if (!zfs_prop_user(name
))
4433 fnvlist_add_boolean(xprops
, name
);
4435 /* -o property=value */
4436 fnvlist_add_nvpair(oprops
, nvp
);
4439 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4441 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
,
4444 nvlist_free(oprops
);
4445 nvlist_free(xprops
);
4448 off
= input_fp
->f_offset
;
4449 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4453 zfsvfs_t
*zfsvfs
= NULL
;
4454 zvol_state_t
*zv
= NULL
;
4456 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4461 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4462 error
= zfs_suspend_fs(zfsvfs
);
4464 * If the suspend fails, then the recv_end will
4465 * likely also fail, and clean up after itself.
4467 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4469 error
= zfs_resume_fs(zfsvfs
, ds
);
4470 error
= error
? error
: end_err
;
4471 deactivate_super(zfsvfs
->z_sb
);
4472 } else if ((zv
= zvol_suspend(tofs
)) != NULL
) {
4473 error
= dmu_recv_end(&drc
, zvol_tag(zv
));
4476 error
= dmu_recv_end(&drc
, NULL
);
4479 /* Set delayed properties now, after we're done receiving. */
4480 if (delayprops
!= NULL
&& error
== 0) {
4481 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4482 delayprops
, *errors
);
4486 if (delayprops
!= NULL
) {
4488 * Merge delayed props back in with initial props, in case
4489 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4490 * we have to make sure clear_received_props() includes
4491 * the delayed properties).
4493 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4494 * using ASSERT() will be just like a VERIFY.
4496 ASSERT(nvlist_merge(recvprops
, delayprops
, 0) == 0);
4497 nvlist_free(delayprops
);
4501 *read_bytes
= off
- input_fp
->f_offset
;
4502 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4503 input_fp
->f_offset
= off
;
4506 if (zfs_ioc_recv_inject_err
) {
4507 zfs_ioc_recv_inject_err
= B_FALSE
;
4513 * On error, restore the original props.
4515 if (error
!= 0 && recvprops
!= NULL
&& !drc
.drc_newfs
) {
4516 if (clear_received_props(tofs
, recvprops
, NULL
) != 0) {
4518 * We failed to clear the received properties.
4519 * Since we may have left a $recvd value on the
4520 * system, we can't clear the $hasrecvd flag.
4522 *errflags
|= ZPROP_ERR_NORESTORE
;
4523 } else if (first_recvd_props
) {
4524 dsl_prop_unset_hasrecvd(tofs
);
4527 if (origrecvd
== NULL
&& !drc
.drc_newfs
) {
4528 /* We failed to stash the original properties. */
4529 *errflags
|= ZPROP_ERR_NORESTORE
;
4533 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4534 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4535 * explicitly if we're restoring local properties cleared in the
4536 * first new-style receive.
4538 if (origrecvd
!= NULL
&&
4539 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4540 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4541 origrecvd
, NULL
) != 0) {
4543 * We stashed the original properties but failed to
4546 *errflags
|= ZPROP_ERR_NORESTORE
;
4549 if (error
!= 0 && localprops
!= NULL
&& !drc
.drc_newfs
&&
4550 !first_recvd_props
) {
4552 nvlist_t
*inheritprops
;
4555 if (origprops
== NULL
) {
4556 /* We failed to stash the original properties. */
4557 *errflags
|= ZPROP_ERR_NORESTORE
;
4561 /* Restore original props */
4562 setprops
= fnvlist_alloc();
4563 inheritprops
= fnvlist_alloc();
4565 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4566 const char *name
= nvpair_name(nvp
);
4570 if (!nvlist_exists(origprops
, name
)) {
4572 * Property was not present or was explicitly
4573 * inherited before the receive, restore this.
4575 fnvlist_add_boolean(inheritprops
, name
);
4578 attrs
= fnvlist_lookup_nvlist(origprops
, name
);
4579 source
= fnvlist_lookup_string(attrs
, ZPROP_SOURCE
);
4581 /* Skip received properties */
4582 if (strcmp(source
, ZPROP_SOURCE_VAL_RECVD
) == 0)
4585 if (strcmp(source
, tofs
) == 0) {
4586 /* Property was locally set */
4587 fnvlist_add_nvlist(setprops
, name
, attrs
);
4589 /* Property was implicitly inherited */
4590 fnvlist_add_boolean(inheritprops
, name
);
4594 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
, setprops
,
4596 *errflags
|= ZPROP_ERR_NORESTORE
;
4597 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
, inheritprops
,
4599 *errflags
|= ZPROP_ERR_NORESTORE
;
4601 nvlist_free(setprops
);
4602 nvlist_free(inheritprops
);
4606 nvlist_free(origrecvd
);
4607 nvlist_free(origprops
);
4610 error
= props_error
;
4617 * zc_name name of containing filesystem (unused)
4618 * zc_nvlist_src{_size} nvlist of properties to apply
4619 * zc_nvlist_conf{_size} nvlist of properties to exclude
4620 * (DATA_TYPE_BOOLEAN) and override (everything else)
4621 * zc_value name of snapshot to create
4622 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4623 * zc_cookie file descriptor to recv from
4624 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4625 * zc_guid force flag
4626 * zc_cleanup_fd cleanup-on-exit file descriptor
4627 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4630 * zc_cookie number of bytes read
4631 * zc_obj zprop_errflags_t
4632 * zc_action_handle handle for this guid/ds mapping
4633 * zc_nvlist_dst{_size} error for each unapplied received property
4636 zfs_ioc_recv(zfs_cmd_t
*zc
)
4638 dmu_replay_record_t begin_record
;
4639 nvlist_t
*errors
= NULL
;
4640 nvlist_t
*recvdprops
= NULL
;
4641 nvlist_t
*localprops
= NULL
;
4642 char *origin
= NULL
;
4644 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4647 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4648 strchr(zc
->zc_value
, '@') == NULL
||
4649 strchr(zc
->zc_value
, '%'))
4650 return (SET_ERROR(EINVAL
));
4652 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4653 tosnap
= strchr(tofs
, '@');
4656 if (zc
->zc_nvlist_src
!= 0 &&
4657 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4658 zc
->zc_iflags
, &recvdprops
)) != 0)
4661 if (zc
->zc_nvlist_conf
!= 0 &&
4662 (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
4663 zc
->zc_iflags
, &localprops
)) != 0)
4666 if (zc
->zc_string
[0])
4667 origin
= zc
->zc_string
;
4669 begin_record
.drr_type
= DRR_BEGIN
;
4670 begin_record
.drr_payloadlen
= 0;
4671 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4673 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvdprops
, localprops
,
4674 zc
->zc_guid
, B_FALSE
, zc
->zc_cookie
, &begin_record
,
4675 zc
->zc_cleanup_fd
, &zc
->zc_cookie
, &zc
->zc_obj
,
4676 &zc
->zc_action_handle
, &errors
);
4677 nvlist_free(recvdprops
);
4678 nvlist_free(localprops
);
4681 * Now that all props, initial and delayed, are set, report the prop
4682 * errors to the caller.
4684 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4685 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4686 put_nvlist(zc
, errors
) != 0)) {
4688 * Caller made zc->zc_nvlist_dst less than the minimum expected
4689 * size or supplied an invalid address.
4691 error
= SET_ERROR(EINVAL
);
4694 nvlist_free(errors
);
4701 * "snapname" -> full name of the snapshot to create
4702 * (optional) "props" -> received properties to set (nvlist)
4703 * (optional) "localprops" -> override and exclude properties (nvlist)
4704 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
4705 * "begin_record" -> non-byteswapped dmu_replay_record_t
4706 * "input_fd" -> file descriptor to read stream from (int32)
4707 * (optional) "force" -> force flag (value ignored)
4708 * (optional) "resumable" -> resumable flag (value ignored)
4709 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
4710 * (optional) "action_handle" -> handle for this guid/ds mapping
4714 * "read_bytes" -> number of bytes read
4715 * "error_flags" -> zprop_errflags_t
4716 * "action_handle" -> handle for this guid/ds mapping
4717 * "errors" -> error for each unapplied received property (nvlist)
4721 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4723 dmu_replay_record_t
*begin_record
;
4724 uint_t begin_record_size
;
4725 nvlist_t
*errors
= NULL
;
4726 nvlist_t
*recvprops
= NULL
;
4727 nvlist_t
*localprops
= NULL
;
4728 char *snapname
= NULL
;
4729 char *origin
= NULL
;
4731 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4733 boolean_t resumable
;
4734 uint64_t action_handle
= 0;
4735 uint64_t read_bytes
= 0;
4736 uint64_t errflags
= 0;
4738 int cleanup_fd
= -1;
4741 error
= nvlist_lookup_string(innvl
, "snapname", &snapname
);
4743 return (SET_ERROR(EINVAL
));
4745 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
4746 strchr(snapname
, '@') == NULL
||
4747 strchr(snapname
, '%'))
4748 return (SET_ERROR(EINVAL
));
4750 (void) strcpy(tofs
, snapname
);
4751 tosnap
= strchr(tofs
, '@');
4754 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
4755 if (error
&& error
!= ENOENT
)
4758 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
4759 (uchar_t
**)&begin_record
, &begin_record_size
);
4760 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
4761 return (SET_ERROR(EINVAL
));
4763 error
= nvlist_lookup_int32(innvl
, "input_fd", &input_fd
);
4765 return (SET_ERROR(EINVAL
));
4767 force
= nvlist_exists(innvl
, "force");
4768 resumable
= nvlist_exists(innvl
, "resumable");
4770 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
4771 if (error
&& error
!= ENOENT
)
4774 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
4775 if (error
&& error
!= ENOENT
)
4778 /* we still use "props" here for backwards compatibility */
4779 error
= nvlist_lookup_nvlist(innvl
, "props", &recvprops
);
4780 if (error
&& error
!= ENOENT
)
4783 error
= nvlist_lookup_nvlist(innvl
, "localprops", &localprops
);
4784 if (error
&& error
!= ENOENT
)
4787 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvprops
, localprops
,
4788 force
, resumable
, input_fd
, begin_record
, cleanup_fd
, &read_bytes
,
4789 &errflags
, &action_handle
, &errors
);
4791 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
4792 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
4793 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
4794 fnvlist_add_nvlist(outnvl
, "errors", errors
);
4796 nvlist_free(errors
);
4797 nvlist_free(recvprops
);
4798 nvlist_free(localprops
);
4805 * zc_name name of snapshot to send
4806 * zc_cookie file descriptor to send stream to
4807 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4808 * zc_sendobj objsetid of snapshot to send
4809 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4810 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4811 * output size in zc_objset_type.
4812 * zc_flags lzc_send_flags
4815 * zc_objset_type estimated size, if zc_guid is set
4817 * NOTE: This is no longer the preferred interface, any new functionality
4818 * should be added to zfs_ioc_send_new() instead.
4821 zfs_ioc_send(zfs_cmd_t
*zc
)
4825 boolean_t estimate
= (zc
->zc_guid
!= 0);
4826 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4827 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4828 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4829 boolean_t rawok
= (zc
->zc_flags
& 0x8);
4831 if (zc
->zc_obj
!= 0) {
4833 dsl_dataset_t
*tosnap
;
4835 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4839 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4841 dsl_pool_rele(dp
, FTAG
);
4845 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4847 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4848 dsl_dataset_rele(tosnap
, FTAG
);
4849 dsl_pool_rele(dp
, FTAG
);
4854 dsl_dataset_t
*tosnap
;
4855 dsl_dataset_t
*fromsnap
= NULL
;
4857 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4861 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
,
4864 dsl_pool_rele(dp
, FTAG
);
4868 if (zc
->zc_fromobj
!= 0) {
4869 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4872 dsl_dataset_rele(tosnap
, FTAG
);
4873 dsl_pool_rele(dp
, FTAG
);
4878 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
|| rawok
,
4879 &zc
->zc_objset_type
);
4881 if (fromsnap
!= NULL
)
4882 dsl_dataset_rele(fromsnap
, FTAG
);
4883 dsl_dataset_rele(tosnap
, FTAG
);
4884 dsl_pool_rele(dp
, FTAG
);
4886 file_t
*fp
= getf(zc
->zc_cookie
);
4888 return (SET_ERROR(EBADF
));
4891 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4892 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
, rawok
,
4893 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4895 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4897 releasef(zc
->zc_cookie
);
4904 * zc_name name of snapshot on which to report progress
4905 * zc_cookie file descriptor of send stream
4908 * zc_cookie number of bytes written in send stream thus far
4911 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4915 dmu_sendarg_t
*dsp
= NULL
;
4918 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4922 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4924 dsl_pool_rele(dp
, FTAG
);
4928 mutex_enter(&ds
->ds_sendstream_lock
);
4931 * Iterate over all the send streams currently active on this dataset.
4932 * If there's one which matches the specified file descriptor _and_ the
4933 * stream was started by the current process, return the progress of
4937 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4938 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4939 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4940 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4945 zc
->zc_cookie
= *(dsp
->dsa_off
);
4947 error
= SET_ERROR(ENOENT
);
4949 mutex_exit(&ds
->ds_sendstream_lock
);
4950 dsl_dataset_rele(ds
, FTAG
);
4951 dsl_pool_rele(dp
, FTAG
);
4956 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4960 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4961 &zc
->zc_inject_record
);
4964 zc
->zc_guid
= (uint64_t)id
;
4970 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4972 return (zio_clear_fault((int)zc
->zc_guid
));
4976 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4978 int id
= (int)zc
->zc_guid
;
4981 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4982 &zc
->zc_inject_record
);
4990 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4994 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4996 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4999 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5002 zc
->zc_nvlist_dst_size
= count
;
5004 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
5006 spa_close(spa
, FTAG
);
5012 zfs_ioc_clear(zfs_cmd_t
*zc
)
5019 * On zpool clear we also fix up missing slogs
5021 mutex_enter(&spa_namespace_lock
);
5022 spa
= spa_lookup(zc
->zc_name
);
5024 mutex_exit(&spa_namespace_lock
);
5025 return (SET_ERROR(EIO
));
5027 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
5028 /* we need to let spa_open/spa_load clear the chains */
5029 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
5031 spa
->spa_last_open_failed
= 0;
5032 mutex_exit(&spa_namespace_lock
);
5034 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
5035 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
5038 nvlist_t
*config
= NULL
;
5040 if (zc
->zc_nvlist_src
== 0)
5041 return (SET_ERROR(EINVAL
));
5043 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5044 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
5045 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
5047 if (config
!= NULL
) {
5050 if ((err
= put_nvlist(zc
, config
)) != 0)
5052 nvlist_free(config
);
5054 nvlist_free(policy
);
5061 spa_vdev_state_enter(spa
, SCL_NONE
);
5063 if (zc
->zc_guid
== 0) {
5066 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
5068 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
5069 spa_close(spa
, FTAG
);
5070 return (SET_ERROR(ENODEV
));
5074 vdev_clear(spa
, vd
);
5076 (void) spa_vdev_state_exit(spa
, spa_suspended(spa
) ?
5077 NULL
: spa
->spa_root_vdev
, 0);
5080 * Resume any suspended I/Os.
5082 if (zio_resume(spa
) != 0)
5083 error
= SET_ERROR(EIO
);
5085 spa_close(spa
, FTAG
);
5091 * Reopen all the vdevs associated with the pool.
5094 * "scrub_restart" -> when true and scrub is running, allow to restart
5095 * scrub as the side effect of the reopen (boolean).
5102 zfs_ioc_pool_reopen(const char *pool
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5106 boolean_t scrub_restart
= B_TRUE
;
5109 if (nvlist_lookup_boolean_value(innvl
, "scrub_restart",
5110 &scrub_restart
) != 0) {
5111 return (SET_ERROR(EINVAL
));
5115 error
= spa_open(pool
, &spa
, FTAG
);
5119 spa_vdev_state_enter(spa
, SCL_NONE
);
5122 * If the scrub_restart flag is B_FALSE and a scrub is already
5123 * in progress then set spa_scrub_reopen flag to B_TRUE so that
5124 * we don't restart the scrub as a side effect of the reopen.
5125 * Otherwise, let vdev_open() decided if a resilver is required.
5128 spa
->spa_scrub_reopen
= (!scrub_restart
&&
5129 dsl_scan_scrubbing(spa
->spa_dsl_pool
));
5130 vdev_reopen(spa
->spa_root_vdev
);
5131 spa
->spa_scrub_reopen
= B_FALSE
;
5133 (void) spa_vdev_state_exit(spa
, NULL
, 0);
5134 spa_close(spa
, FTAG
);
5140 * zc_name name of filesystem
5143 * zc_string name of conflicting snapshot, if there is one
5146 zfs_ioc_promote(zfs_cmd_t
*zc
)
5149 dsl_dataset_t
*ds
, *ods
;
5150 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
5154 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5155 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
5156 strchr(zc
->zc_name
, '%'))
5157 return (SET_ERROR(EINVAL
));
5159 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5163 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5165 dsl_pool_rele(dp
, FTAG
);
5169 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
5170 dsl_dataset_rele(ds
, FTAG
);
5171 dsl_pool_rele(dp
, FTAG
);
5172 return (SET_ERROR(EINVAL
));
5175 error
= dsl_dataset_hold_obj(dp
,
5176 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
5178 dsl_dataset_rele(ds
, FTAG
);
5179 dsl_pool_rele(dp
, FTAG
);
5183 dsl_dataset_name(ods
, origin
);
5184 dsl_dataset_rele(ods
, FTAG
);
5185 dsl_dataset_rele(ds
, FTAG
);
5186 dsl_pool_rele(dp
, FTAG
);
5189 * We don't need to unmount *all* the origin fs's snapshots, but
5192 cp
= strchr(origin
, '@');
5195 (void) dmu_objset_find(origin
,
5196 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
5197 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
5201 * Retrieve a single {user|group|project}{used|quota}@... property.
5204 * zc_name name of filesystem
5205 * zc_objset_type zfs_userquota_prop_t
5206 * zc_value domain name (eg. "S-1-234-567-89")
5207 * zc_guid RID/UID/GID
5210 * zc_cookie property value
5213 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
5218 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
5219 return (SET_ERROR(EINVAL
));
5221 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5225 error
= zfs_userspace_one(zfsvfs
,
5226 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
5227 zfsvfs_rele(zfsvfs
, FTAG
);
5234 * zc_name name of filesystem
5235 * zc_cookie zap cursor
5236 * zc_objset_type zfs_userquota_prop_t
5237 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
5240 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
5241 * zc_cookie zap cursor
5244 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
5247 int bufsize
= zc
->zc_nvlist_dst_size
;
5250 return (SET_ERROR(ENOMEM
));
5252 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5256 void *buf
= vmem_alloc(bufsize
, KM_SLEEP
);
5258 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
5259 buf
, &zc
->zc_nvlist_dst_size
);
5262 error
= xcopyout(buf
,
5263 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5264 zc
->zc_nvlist_dst_size
);
5266 vmem_free(buf
, bufsize
);
5267 zfsvfs_rele(zfsvfs
, FTAG
);
5274 * zc_name name of filesystem
5280 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
5286 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
5287 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
5289 * If userused is not enabled, it may be because the
5290 * objset needs to be closed & reopened (to grow the
5291 * objset_phys_t). Suspend/resume the fs will do that.
5293 dsl_dataset_t
*ds
, *newds
;
5295 ds
= dmu_objset_ds(zfsvfs
->z_os
);
5296 error
= zfs_suspend_fs(zfsvfs
);
5298 dmu_objset_refresh_ownership(ds
, &newds
,
5300 error
= zfs_resume_fs(zfsvfs
, newds
);
5304 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
5305 deactivate_super(zfsvfs
->z_sb
);
5307 /* XXX kind of reading contents without owning */
5308 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5312 error
= dmu_objset_userspace_upgrade(os
);
5313 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
5321 * zc_name name of filesystem
5327 zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
)
5332 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5336 if (dmu_objset_userobjspace_upgradable(os
) ||
5337 dmu_objset_projectquota_upgradable(os
)) {
5338 mutex_enter(&os
->os_upgrade_lock
);
5339 if (os
->os_upgrade_id
== 0) {
5340 /* clear potential error code and retry */
5341 os
->os_upgrade_status
= 0;
5342 mutex_exit(&os
->os_upgrade_lock
);
5344 dmu_objset_id_quota_upgrade(os
);
5346 mutex_exit(&os
->os_upgrade_lock
);
5349 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5351 taskq_wait_id(os
->os_spa
->spa_upgrade_taskq
, os
->os_upgrade_id
);
5352 error
= os
->os_upgrade_status
;
5354 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5357 dsl_dataset_rele_flags(dmu_objset_ds(os
), DS_HOLD_FLAG_DECRYPT
, FTAG
);
5363 zfs_ioc_share(zfs_cmd_t
*zc
)
5365 return (SET_ERROR(ENOSYS
));
5368 ace_t full_access
[] = {
5369 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
5374 * zc_name name of containing filesystem
5375 * zc_obj object # beyond which we want next in-use object #
5378 * zc_obj next in-use object #
5381 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
5383 objset_t
*os
= NULL
;
5386 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
5390 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
5392 dmu_objset_rele(os
, FTAG
);
5398 * zc_name name of filesystem
5399 * zc_value prefix name for snapshot
5400 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5403 * zc_value short name of new snapshot
5406 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5413 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5417 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5418 (u_longlong_t
)ddi_get_lbolt64());
5419 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5421 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5424 (void) strlcpy(zc
->zc_value
, snap_name
,
5425 sizeof (zc
->zc_value
));
5428 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5434 * zc_name name of "to" snapshot
5435 * zc_value name of "from" snapshot
5436 * zc_cookie file descriptor to write diff data on
5439 * dmu_diff_record_t's to the file descriptor
5442 zfs_ioc_diff(zfs_cmd_t
*zc
)
5448 fp
= getf(zc
->zc_cookie
);
5450 return (SET_ERROR(EBADF
));
5454 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5456 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5458 releasef(zc
->zc_cookie
);
5464 * Remove all ACL files in shares dir
5466 #ifdef HAVE_SMB_SHARE
5468 zfs_smb_acl_purge(znode_t
*dzp
)
5471 zap_attribute_t zap
;
5472 zfsvfs_t
*zfsvfs
= ZTOZSB(dzp
);
5475 for (zap_cursor_init(&zc
, zfsvfs
->z_os
, dzp
->z_id
);
5476 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5477 zap_cursor_advance(&zc
)) {
5478 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
5482 zap_cursor_fini(&zc
);
5485 #endif /* HAVE_SMB_SHARE */
5488 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5490 #ifdef HAVE_SMB_SHARE
5493 vnode_t
*resourcevp
= NULL
;
5502 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5503 NO_FOLLOW
, NULL
, &vp
)) != 0)
5506 /* Now make sure mntpnt and dataset are ZFS */
5508 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5509 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5510 zc
->zc_name
) != 0)) {
5512 return (SET_ERROR(EINVAL
));
5516 zfsvfs
= ZTOZSB(dzp
);
5520 * Create share dir if its missing.
5522 mutex_enter(&zfsvfs
->z_lock
);
5523 if (zfsvfs
->z_shares_dir
== 0) {
5526 tx
= dmu_tx_create(zfsvfs
->z_os
);
5527 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5529 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5530 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5534 error
= zfs_create_share_dir(zfsvfs
, tx
);
5538 mutex_exit(&zfsvfs
->z_lock
);
5544 mutex_exit(&zfsvfs
->z_lock
);
5546 ASSERT(zfsvfs
->z_shares_dir
);
5547 if ((error
= zfs_zget(zfsvfs
, zfsvfs
->z_shares_dir
, &sharedir
)) != 0) {
5553 switch (zc
->zc_cookie
) {
5554 case ZFS_SMB_ACL_ADD
:
5555 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5556 vattr
.va_mode
= S_IFREG
|0777;
5560 vsec
.vsa_mask
= VSA_ACE
;
5561 vsec
.vsa_aclentp
= &full_access
;
5562 vsec
.vsa_aclentsz
= sizeof (full_access
);
5563 vsec
.vsa_aclcnt
= 1;
5565 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
5566 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5568 VN_RELE(resourcevp
);
5571 case ZFS_SMB_ACL_REMOVE
:
5572 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5576 case ZFS_SMB_ACL_RENAME
:
5577 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5578 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5580 VN_RELE(ZTOV(sharedir
));
5584 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5585 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5588 VN_RELE(ZTOV(sharedir
));
5590 nvlist_free(nvlist
);
5593 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5595 nvlist_free(nvlist
);
5598 case ZFS_SMB_ACL_PURGE
:
5599 error
= zfs_smb_acl_purge(sharedir
);
5603 error
= SET_ERROR(EINVAL
);
5608 VN_RELE(ZTOV(sharedir
));
5614 return (SET_ERROR(ENOTSUP
));
5615 #endif /* HAVE_SMB_SHARE */
5620 * "holds" -> { snapname -> holdname (string), ... }
5621 * (optional) "cleanup_fd" -> fd (int32)
5625 * snapname -> error value (int32)
5631 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5635 int cleanup_fd
= -1;
5639 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5641 return (SET_ERROR(EINVAL
));
5643 /* make sure the user didn't pass us any invalid (empty) tags */
5644 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5645 pair
= nvlist_next_nvpair(holds
, pair
)) {
5648 error
= nvpair_value_string(pair
, &htag
);
5650 return (SET_ERROR(error
));
5652 if (strlen(htag
) == 0)
5653 return (SET_ERROR(EINVAL
));
5656 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5657 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5662 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5664 zfs_onexit_fd_rele(cleanup_fd
);
5669 * innvl is not used.
5672 * holdname -> time added (uint64 seconds since epoch)
5678 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5680 ASSERT3P(args
, ==, NULL
);
5681 return (dsl_dataset_get_holds(snapname
, outnvl
));
5686 * snapname -> { holdname, ... }
5691 * snapname -> error value (int32)
5697 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5699 return (dsl_dataset_user_release(holds
, errlist
));
5704 * zc_guid flags (ZEVENT_NONBLOCK)
5705 * zc_cleanup_fd zevent file descriptor
5708 * zc_nvlist_dst next nvlist event
5709 * zc_cookie dropped events since last get
5712 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5715 nvlist_t
*event
= NULL
;
5717 uint64_t dropped
= 0;
5720 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5725 error
= zfs_zevent_next(ze
, &event
,
5726 &zc
->zc_nvlist_dst_size
, &dropped
);
5727 if (event
!= NULL
) {
5728 zc
->zc_cookie
= dropped
;
5729 error
= put_nvlist(zc
, event
);
5733 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5736 if ((error
== 0) || (error
!= ENOENT
))
5739 error
= zfs_zevent_wait(ze
);
5744 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5751 * zc_cookie cleared events count
5754 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5758 zfs_zevent_drain_all(&count
);
5759 zc
->zc_cookie
= count
;
5766 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5767 * zc_cleanup zevent file descriptor
5770 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5776 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5780 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5781 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5788 * zc_name name of new filesystem or snapshot
5789 * zc_value full name of old snapshot
5792 * zc_cookie space in bytes
5793 * zc_objset_type compressed space in bytes
5794 * zc_perm_action uncompressed space in bytes
5797 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5801 dsl_dataset_t
*new, *old
;
5803 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5806 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5808 dsl_pool_rele(dp
, FTAG
);
5811 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5813 dsl_dataset_rele(new, FTAG
);
5814 dsl_pool_rele(dp
, FTAG
);
5818 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5819 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5820 dsl_dataset_rele(old
, FTAG
);
5821 dsl_dataset_rele(new, FTAG
);
5822 dsl_pool_rele(dp
, FTAG
);
5828 * "firstsnap" -> snapshot name
5832 * "used" -> space in bytes
5833 * "compressed" -> compressed space in bytes
5834 * "uncompressed" -> uncompressed space in bytes
5838 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5842 dsl_dataset_t
*new, *old
;
5844 uint64_t used
, comp
, uncomp
;
5846 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5847 return (SET_ERROR(EINVAL
));
5849 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5853 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5854 if (error
== 0 && !new->ds_is_snapshot
) {
5855 dsl_dataset_rele(new, FTAG
);
5856 error
= SET_ERROR(EINVAL
);
5859 dsl_pool_rele(dp
, FTAG
);
5862 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5863 if (error
== 0 && !old
->ds_is_snapshot
) {
5864 dsl_dataset_rele(old
, FTAG
);
5865 error
= SET_ERROR(EINVAL
);
5868 dsl_dataset_rele(new, FTAG
);
5869 dsl_pool_rele(dp
, FTAG
);
5873 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5874 dsl_dataset_rele(old
, FTAG
);
5875 dsl_dataset_rele(new, FTAG
);
5876 dsl_pool_rele(dp
, FTAG
);
5877 fnvlist_add_uint64(outnvl
, "used", used
);
5878 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5879 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5885 * "fd" -> file descriptor to write stream to (int32)
5886 * (optional) "fromsnap" -> full snap name to send an incremental from
5887 * (optional) "largeblockok" -> (value ignored)
5888 * indicates that blocks > 128KB are permitted
5889 * (optional) "embedok" -> (value ignored)
5890 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5891 * (optional) "compressok" -> (value ignored)
5892 * presence indicates compressed DRR_WRITE records are permitted
5893 * (optional) "rawok" -> (value ignored)
5894 * presence indicates raw encrypted records should be used.
5895 * (optional) "resume_object" and "resume_offset" -> (uint64)
5896 * if present, resume send stream from specified object and offset.
5903 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5907 char *fromname
= NULL
;
5910 boolean_t largeblockok
;
5912 boolean_t compressok
;
5914 uint64_t resumeobj
= 0;
5915 uint64_t resumeoff
= 0;
5917 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5919 return (SET_ERROR(EINVAL
));
5921 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5923 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5924 embedok
= nvlist_exists(innvl
, "embedok");
5925 compressok
= nvlist_exists(innvl
, "compressok");
5926 rawok
= nvlist_exists(innvl
, "rawok");
5928 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5929 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5931 if ((fp
= getf(fd
)) == NULL
)
5932 return (SET_ERROR(EBADF
));
5935 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5936 rawok
, fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5938 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5946 * Determine approximately how large a zfs send stream will be -- the number
5947 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5950 * (optional) "from" -> full snap or bookmark name to send an incremental
5952 * (optional) "largeblockok" -> (value ignored)
5953 * indicates that blocks > 128KB are permitted
5954 * (optional) "embedok" -> (value ignored)
5955 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5956 * (optional) "compressok" -> (value ignored)
5957 * presence indicates compressed DRR_WRITE records are permitted
5958 * (optional) "rawok" -> (value ignored)
5959 * presence indicates raw encrypted records should be used.
5963 * "space" -> bytes of space (uint64)
5967 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5970 dsl_dataset_t
*tosnap
;
5973 boolean_t compressok
;
5977 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5981 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5983 dsl_pool_rele(dp
, FTAG
);
5987 compressok
= nvlist_exists(innvl
, "compressok");
5988 rawok
= nvlist_exists(innvl
, "rawok");
5990 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5992 if (strchr(fromname
, '@') != NULL
) {
5994 * If from is a snapshot, hold it and use the more
5995 * efficient dmu_send_estimate to estimate send space
5996 * size using deadlists.
5998 dsl_dataset_t
*fromsnap
;
5999 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
6002 error
= dmu_send_estimate(tosnap
, fromsnap
,
6003 compressok
|| rawok
, &space
);
6004 dsl_dataset_rele(fromsnap
, FTAG
);
6005 } else if (strchr(fromname
, '#') != NULL
) {
6007 * If from is a bookmark, fetch the creation TXG of the
6008 * snapshot it was created from and use that to find
6009 * blocks that were born after it.
6011 zfs_bookmark_phys_t frombm
;
6013 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
6017 error
= dmu_send_estimate_from_txg(tosnap
,
6018 frombm
.zbm_creation_txg
, compressok
|| rawok
,
6022 * from is not properly formatted as a snapshot or
6025 error
= SET_ERROR(EINVAL
);
6030 * If estimating the size of a full send, use dmu_send_estimate.
6032 error
= dmu_send_estimate(tosnap
, NULL
, compressok
|| rawok
,
6036 fnvlist_add_uint64(outnvl
, "space", space
);
6039 dsl_dataset_rele(tosnap
, FTAG
);
6040 dsl_pool_rele(dp
, FTAG
);
6045 * Sync the currently open TXG to disk for the specified pool.
6046 * This is somewhat similar to 'zfs_sync()'.
6047 * For cases that do not result in error this ioctl will wait for
6048 * the currently open TXG to commit before returning back to the caller.
6051 * "force" -> when true, force uberblock update even if there is no dirty data.
6052 * In addition this will cause the vdev configuration to be written
6053 * out including updating the zpool cache file. (boolean_t)
6060 zfs_ioc_pool_sync(const char *pool
, nvlist_t
*innvl
, nvlist_t
*onvl
)
6063 boolean_t force
= B_FALSE
;
6066 if ((err
= spa_open(pool
, &spa
, FTAG
)) != 0)
6070 if (nvlist_lookup_boolean_value(innvl
, "force", &force
) != 0) {
6071 err
= SET_ERROR(EINVAL
);
6077 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_WRITER
);
6078 vdev_config_dirty(spa
->spa_root_vdev
);
6079 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6081 txg_wait_synced(spa_get_dsl(spa
), 0);
6083 spa_close(spa
, FTAG
);
6089 * Load a user's wrapping key into the kernel.
6091 * "hidden_args" -> { "wkeydata" -> value }
6092 * raw uint8_t array of encryption wrapping key data (32 bytes)
6093 * (optional) "noop" -> (value ignored)
6094 * presence indicated key should only be verified, not loaded
6099 zfs_ioc_load_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6102 dsl_crypto_params_t
*dcp
= NULL
;
6103 nvlist_t
*hidden_args
;
6104 boolean_t noop
= nvlist_exists(innvl
, "noop");
6106 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6107 ret
= SET_ERROR(EINVAL
);
6111 ret
= nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6113 ret
= SET_ERROR(EINVAL
);
6117 ret
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, NULL
,
6122 ret
= spa_keystore_load_wkey(dsname
, dcp
, noop
);
6126 dsl_crypto_params_free(dcp
, noop
);
6131 dsl_crypto_params_free(dcp
, B_TRUE
);
6136 * Unload a user's wrapping key from the kernel.
6137 * Both innvl and outnvl are unused.
6141 zfs_ioc_unload_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6145 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6146 ret
= (SET_ERROR(EINVAL
));
6150 ret
= spa_keystore_unload_wkey(dsname
);
6159 * Changes a user's wrapping key used to decrypt a dataset. The keyformat,
6160 * keylocation, pbkdf2salt, and pbkdf2iters properties can also be specified
6161 * here to change how the key is derived in userspace.
6164 * "hidden_args" (optional) -> { "wkeydata" -> value }
6165 * raw uint8_t array of new encryption wrapping key data (32 bytes)
6166 * "props" (optional) -> { prop -> value }
6173 zfs_ioc_change_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6176 uint64_t cmd
= DCP_CMD_NONE
;
6177 dsl_crypto_params_t
*dcp
= NULL
;
6178 nvlist_t
*args
= NULL
, *hidden_args
= NULL
;
6180 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6181 ret
= (SET_ERROR(EINVAL
));
6185 (void) nvlist_lookup_uint64(innvl
, "crypt_cmd", &cmd
);
6186 (void) nvlist_lookup_nvlist(innvl
, "props", &args
);
6187 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6189 ret
= dsl_crypto_params_create_nvlist(cmd
, args
, hidden_args
, &dcp
);
6193 ret
= spa_keystore_change_key(dsname
, dcp
);
6197 dsl_crypto_params_free(dcp
, B_FALSE
);
6202 dsl_crypto_params_free(dcp
, B_TRUE
);
6206 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
6209 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6210 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6211 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
6213 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6215 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6216 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6217 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6218 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6220 vec
->zvec_legacy_func
= func
;
6221 vec
->zvec_secpolicy
= secpolicy
;
6222 vec
->zvec_namecheck
= namecheck
;
6223 vec
->zvec_allow_log
= log_history
;
6224 vec
->zvec_pool_check
= pool_check
;
6228 * See the block comment at the beginning of this file for details on
6229 * each argument to this function.
6232 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
6233 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6234 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
6235 boolean_t allow_log
)
6237 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6239 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6240 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6241 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6242 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6244 /* if we are logging, the name must be valid */
6245 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
6247 vec
->zvec_name
= name
;
6248 vec
->zvec_func
= func
;
6249 vec
->zvec_secpolicy
= secpolicy
;
6250 vec
->zvec_namecheck
= namecheck
;
6251 vec
->zvec_pool_check
= pool_check
;
6252 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
6253 vec
->zvec_allow_log
= allow_log
;
6257 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6258 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
6259 zfs_ioc_poolcheck_t pool_check
)
6261 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6262 POOL_NAME
, log_history
, pool_check
);
6266 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6267 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
6269 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6270 DATASET_NAME
, B_FALSE
, pool_check
);
6274 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6276 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
6277 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6281 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6282 zfs_secpolicy_func_t
*secpolicy
)
6284 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6285 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6289 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
6290 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
6292 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6293 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6297 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6299 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
6300 zfs_secpolicy_read
);
6304 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6305 zfs_secpolicy_func_t
*secpolicy
)
6307 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6308 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6312 zfs_ioctl_init(void)
6314 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
6315 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
6316 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6318 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
6319 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
6320 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
6322 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
6323 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
6324 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6326 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
6327 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
6328 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6330 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
6331 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
6332 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6334 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
6335 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6336 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6338 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
6339 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6340 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6342 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
6343 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
6344 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6346 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
6347 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
6348 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6349 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
6350 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
6351 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6353 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
6354 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
6355 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6357 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
6358 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
6359 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
6361 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
6362 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
6363 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6365 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
6366 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
6367 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6369 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
6370 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
6372 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6374 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
6375 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
6376 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6377 zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY
,
6378 zfs_ioc_load_key
, zfs_secpolicy_load_key
,
6379 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
);
6380 zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY
,
6381 zfs_ioc_unload_key
, zfs_secpolicy_load_key
,
6382 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
);
6383 zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY
,
6384 zfs_ioc_change_key
, zfs_secpolicy_change_key
,
6385 DATASET_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
,
6388 zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC
,
6389 zfs_ioc_pool_sync
, zfs_secpolicy_none
, POOL_NAME
,
6390 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
6391 zfs_ioctl_register("reopen", ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
6392 zfs_secpolicy_config
, POOL_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
,
6395 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
6396 zfs_ioc_channel_program
, zfs_secpolicy_config
,
6397 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
6400 /* IOCTLS that use the legacy function signature */
6402 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
6403 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
6405 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
6406 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6407 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
6409 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
6410 zfs_ioc_pool_upgrade
);
6411 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
6413 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
6414 zfs_ioc_vdev_remove
);
6415 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
6416 zfs_ioc_vdev_set_state
);
6417 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
6418 zfs_ioc_vdev_attach
);
6419 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
6420 zfs_ioc_vdev_detach
);
6421 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
6422 zfs_ioc_vdev_setpath
);
6423 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
6424 zfs_ioc_vdev_setfru
);
6425 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
6426 zfs_ioc_pool_set_props
);
6427 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
6428 zfs_ioc_vdev_split
);
6429 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
6430 zfs_ioc_pool_reguid
);
6432 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
6433 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
6434 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
6435 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
6436 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
6437 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
6438 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
6439 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
6440 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
6441 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
6444 * pool destroy, and export don't log the history as part of
6445 * zfsdev_ioctl, but rather zfs_ioc_pool_export
6446 * does the logging of those commands.
6448 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
6449 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6450 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
6451 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6453 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
6454 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6455 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
6456 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6458 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
6459 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6460 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
6461 zfs_ioc_dsobj_to_dsname
,
6462 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6463 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
6464 zfs_ioc_pool_get_history
,
6465 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6467 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
6468 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6470 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
6471 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_READONLY
);
6473 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
6474 zfs_ioc_space_written
);
6475 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
6476 zfs_ioc_objset_recvd_props
);
6477 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
6479 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
6481 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
6482 zfs_ioc_objset_stats
);
6483 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
6484 zfs_ioc_objset_zplprops
);
6485 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
6486 zfs_ioc_dataset_list_next
);
6487 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
6488 zfs_ioc_snapshot_list_next
);
6489 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
6490 zfs_ioc_send_progress
);
6492 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
6493 zfs_ioc_diff
, zfs_secpolicy_diff
);
6494 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
6495 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
6496 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
6497 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
6498 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
6499 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
6500 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
6501 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
6502 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
6503 zfs_ioc_send
, zfs_secpolicy_send
);
6505 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
6506 zfs_secpolicy_none
);
6507 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
6508 zfs_secpolicy_destroy
);
6509 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
6510 zfs_secpolicy_rename
);
6511 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
6512 zfs_secpolicy_recv
);
6513 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
6514 zfs_secpolicy_promote
);
6515 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
6516 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
6517 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
6518 zfs_secpolicy_set_fsacl
);
6520 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
6521 zfs_secpolicy_share
, POOL_CHECK_NONE
);
6522 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
6523 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
6524 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
6525 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
6526 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6527 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
6528 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
6529 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6534 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
6535 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6536 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
6537 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6538 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
6539 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6543 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
6544 zfs_ioc_poolcheck_t check
)
6549 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
6551 if (check
& POOL_CHECK_NONE
)
6554 error
= spa_open(name
, &spa
, FTAG
);
6556 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
6557 error
= SET_ERROR(EAGAIN
);
6558 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
6559 error
= SET_ERROR(EROFS
);
6560 spa_close(spa
, FTAG
);
6566 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
6570 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6571 if (zs
->zs_minor
== minor
) {
6575 return (zs
->zs_onexit
);
6577 return (zs
->zs_zevent
);
6588 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
6592 ptr
= zfsdev_get_state_impl(minor
, which
);
6598 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
6600 zfsdev_state_t
*zs
, *fpd
;
6602 ASSERT(filp
!= NULL
);
6603 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
6605 fpd
= filp
->private_data
;
6607 return (SET_ERROR(EBADF
));
6609 mutex_enter(&zfsdev_state_lock
);
6611 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6613 if (zs
->zs_minor
== -1)
6617 *minorp
= fpd
->zs_minor
;
6618 mutex_exit(&zfsdev_state_lock
);
6623 mutex_exit(&zfsdev_state_lock
);
6625 return (SET_ERROR(EBADF
));
6629 * Find a free minor number. The zfsdev_state_list is expected to
6630 * be short since it is only a list of currently open file handles.
6633 zfsdev_minor_alloc(void)
6635 static minor_t last_minor
= 0;
6638 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6640 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6641 if (m
> ZFSDEV_MAX_MINOR
)
6643 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
6653 zfsdev_state_init(struct file
*filp
)
6655 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6657 boolean_t newzs
= B_FALSE
;
6659 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6661 minor
= zfsdev_minor_alloc();
6663 return (SET_ERROR(ENXIO
));
6665 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6666 if (zs
->zs_minor
== -1)
6672 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6677 filp
->private_data
= zs
;
6679 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
6680 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
6684 * In order to provide for lock-free concurrent read access
6685 * to the minor list in zfsdev_get_state_impl(), new entries
6686 * must be completely written before linking them into the
6687 * list whereas existing entries are already linked; the last
6688 * operation must be updating zs_minor (from -1 to the new
6692 zs
->zs_minor
= minor
;
6694 zsprev
->zs_next
= zs
;
6697 zs
->zs_minor
= minor
;
6704 zfsdev_state_destroy(struct file
*filp
)
6708 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6709 ASSERT(filp
->private_data
!= NULL
);
6711 zs
= filp
->private_data
;
6713 zfs_onexit_destroy(zs
->zs_onexit
);
6714 zfs_zevent_destroy(zs
->zs_zevent
);
6720 zfsdev_open(struct inode
*ino
, struct file
*filp
)
6724 mutex_enter(&zfsdev_state_lock
);
6725 error
= zfsdev_state_init(filp
);
6726 mutex_exit(&zfsdev_state_lock
);
6732 zfsdev_release(struct inode
*ino
, struct file
*filp
)
6736 mutex_enter(&zfsdev_state_lock
);
6737 error
= zfsdev_state_destroy(filp
);
6738 mutex_exit(&zfsdev_state_lock
);
6744 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6748 int error
, rc
, flag
= 0;
6749 const zfs_ioc_vec_t
*vec
;
6750 char *saved_poolname
= NULL
;
6751 nvlist_t
*innvl
= NULL
;
6752 fstrans_cookie_t cookie
;
6754 vecnum
= cmd
- ZFS_IOC_FIRST
;
6755 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6756 return (-SET_ERROR(EINVAL
));
6757 vec
= &zfs_ioc_vec
[vecnum
];
6760 * The registered ioctl list may be sparse, verify that either
6761 * a normal or legacy handler are registered.
6763 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
6764 return (-SET_ERROR(EINVAL
));
6766 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6768 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6770 error
= SET_ERROR(EFAULT
);
6774 zc
->zc_iflags
= flag
& FKIOCTL
;
6775 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
6777 * Make sure the user doesn't pass in an insane value for
6778 * zc_nvlist_src_size. We have to check, since we will end
6779 * up allocating that much memory inside of get_nvlist(). This
6780 * prevents a nefarious user from allocating tons of kernel
6783 * Also, we return EINVAL instead of ENOMEM here. The reason
6784 * being that returning ENOMEM from an ioctl() has a special
6785 * connotation; that the user's size value is too small and
6786 * needs to be expanded to hold the nvlist. See
6787 * zcmd_expand_dst_nvlist() for details.
6789 error
= SET_ERROR(EINVAL
); /* User's size too big */
6791 } else if (zc
->zc_nvlist_src_size
!= 0) {
6792 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6793 zc
->zc_iflags
, &innvl
);
6799 * Ensure that all pool/dataset names are valid before we pass down to
6802 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6803 switch (vec
->zvec_namecheck
) {
6805 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6806 error
= SET_ERROR(EINVAL
);
6808 error
= pool_status_check(zc
->zc_name
,
6809 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6813 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6814 error
= SET_ERROR(EINVAL
);
6816 error
= pool_status_check(zc
->zc_name
,
6817 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6826 cookie
= spl_fstrans_mark();
6827 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
6828 spl_fstrans_unmark(cookie
);
6834 /* legacy ioctls can modify zc_name */
6835 saved_poolname
= strdup(zc
->zc_name
);
6836 if (saved_poolname
== NULL
) {
6837 error
= SET_ERROR(ENOMEM
);
6840 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
6843 if (vec
->zvec_func
!= NULL
) {
6847 nvlist_t
*lognv
= NULL
;
6849 ASSERT(vec
->zvec_legacy_func
== NULL
);
6852 * Add the innvl to the lognv before calling the func,
6853 * in case the func changes the innvl.
6855 if (vec
->zvec_allow_log
) {
6856 lognv
= fnvlist_alloc();
6857 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6859 if (!nvlist_empty(innvl
)) {
6860 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6865 outnvl
= fnvlist_alloc();
6866 cookie
= spl_fstrans_mark();
6867 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6868 spl_fstrans_unmark(cookie
);
6871 * Some commands can partially execute, modify state, and still
6872 * return an error. In these cases, attempt to record what
6876 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
6877 vec
->zvec_allow_log
&&
6878 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6879 if (!nvlist_empty(outnvl
)) {
6880 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6884 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
6887 (void) spa_history_log_nvl(spa
, lognv
);
6888 spa_close(spa
, FTAG
);
6890 fnvlist_free(lognv
);
6892 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6894 if (vec
->zvec_smush_outnvlist
) {
6895 smusherror
= nvlist_smush(outnvl
,
6896 zc
->zc_nvlist_dst_size
);
6898 if (smusherror
== 0)
6899 puterror
= put_nvlist(zc
, outnvl
);
6905 nvlist_free(outnvl
);
6907 cookie
= spl_fstrans_mark();
6908 error
= vec
->zvec_legacy_func(zc
);
6909 spl_fstrans_unmark(cookie
);
6914 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6915 if (error
== 0 && rc
!= 0)
6916 error
= SET_ERROR(EFAULT
);
6917 if (error
== 0 && vec
->zvec_allow_log
) {
6918 char *s
= tsd_get(zfs_allow_log_key
);
6921 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6923 if (saved_poolname
!= NULL
)
6924 strfree(saved_poolname
);
6927 kmem_free(zc
, sizeof (zfs_cmd_t
));
6931 #ifdef CONFIG_COMPAT
6933 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6935 return (zfsdev_ioctl(filp
, cmd
, arg
));
6938 #define zfsdev_compat_ioctl NULL
6941 static const struct file_operations zfsdev_fops
= {
6942 .open
= zfsdev_open
,
6943 .release
= zfsdev_release
,
6944 .unlocked_ioctl
= zfsdev_ioctl
,
6945 .compat_ioctl
= zfsdev_compat_ioctl
,
6946 .owner
= THIS_MODULE
,
6949 static struct miscdevice zfs_misc
= {
6952 .fops
= &zfsdev_fops
,
6955 MODULE_ALIAS_MISCDEV(ZFS_MINOR
);
6956 MODULE_ALIAS("devname:zfs");
6963 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6964 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6965 zfsdev_state_list
->zs_minor
= -1;
6967 error
= misc_register(&zfs_misc
);
6968 if (error
== -EBUSY
) {
6970 * Fallback to dynamic minor allocation in the event of a
6971 * collision with a reserved minor in linux/miscdevice.h.
6972 * In this case the kernel modules must be manually loaded.
6974 printk(KERN_INFO
"ZFS: misc_register() with static minor %d "
6975 "failed %d, retrying with MISC_DYNAMIC_MINOR\n",
6978 zfs_misc
.minor
= MISC_DYNAMIC_MINOR
;
6979 error
= misc_register(&zfs_misc
);
6983 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
6991 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6993 misc_deregister(&zfs_misc
);
6994 mutex_destroy(&zfsdev_state_lock
);
6996 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6998 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7002 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7006 zfs_allow_log_destroy(void *arg
)
7008 char *poolname
= arg
;
7010 if (poolname
!= NULL
)
7015 #define ZFS_DEBUG_STR " (DEBUG mode)"
7017 #define ZFS_DEBUG_STR ""
7025 error
= -vn_set_pwd("/");
7028 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
7032 if ((error
= -zvol_init()) != 0)
7035 spa_init(FREAD
| FWRITE
);
7040 if ((error
= zfs_attach()) != 0)
7043 tsd_create(&zfs_fsyncer_key
, NULL
);
7044 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
7045 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
7047 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
7048 "ZFS pool version %s, ZFS filesystem version %s\n",
7049 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
7050 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
7051 #ifndef CONFIG_FS_POSIX_ACL
7052 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
7053 #endif /* CONFIG_FS_POSIX_ACL */
7061 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
7062 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
7063 ZFS_DEBUG_STR
, error
);
7076 tsd_destroy(&zfs_fsyncer_key
);
7077 tsd_destroy(&rrw_tsd_key
);
7078 tsd_destroy(&zfs_allow_log_key
);
7080 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
7081 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
7088 MODULE_DESCRIPTION("ZFS");
7089 MODULE_AUTHOR(ZFS_META_AUTHOR
);
7090 MODULE_LICENSE(ZFS_META_LICENSE
);
7091 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);
7092 #endif /* HAVE_SPL */