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>
147 #include <sys/file.h>
148 #include <sys/kmem.h>
149 #include <sys/cmn_err.h>
150 #include <sys/stat.h>
151 #include <sys/zfs_ioctl.h>
152 #include <sys/zfs_vfsops.h>
153 #include <sys/zfs_znode.h>
156 #include <sys/spa_impl.h>
157 #include <sys/vdev.h>
158 #include <sys/vdev_impl.h>
160 #include <sys/dsl_dir.h>
161 #include <sys/dsl_dataset.h>
162 #include <sys/dsl_prop.h>
163 #include <sys/dsl_deleg.h>
164 #include <sys/dmu_objset.h>
165 #include <sys/dmu_impl.h>
166 #include <sys/dmu_tx.h>
167 #include <sys/sunddi.h>
168 #include <sys/policy.h>
169 #include <sys/zone.h>
170 #include <sys/nvpair.h>
171 #include <sys/pathname.h>
173 #include <sys/fs/zfs.h>
174 #include <sys/zfs_ctldir.h>
175 #include <sys/zfs_dir.h>
176 #include <sys/zfs_onexit.h>
177 #include <sys/zvol.h>
178 #include <sys/dsl_scan.h>
179 #include <sys/fm/util.h>
180 #include <sys/dsl_crypt.h>
182 #include <sys/dmu_send.h>
183 #include <sys/dsl_destroy.h>
184 #include <sys/dsl_bookmark.h>
185 #include <sys/dsl_userhold.h>
186 #include <sys/zfeature.h>
188 #include <sys/zio_checksum.h>
189 #include <sys/vdev_removal.h>
191 #include <linux/miscdevice.h>
192 #include <linux/slab.h>
194 #include "zfs_namecheck.h"
195 #include "zfs_prop.h"
196 #include "zfs_deleg.h"
197 #include "zfs_comutil.h"
199 #include <sys/lua/lua.h>
200 #include <sys/lua/lauxlib.h>
203 * Limit maximum nvlist size. We don't want users passing in insane values
204 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
206 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
208 kmutex_t zfsdev_state_lock
;
209 zfsdev_state_t
*zfsdev_state_list
;
211 extern void zfs_init(void);
212 extern void zfs_fini(void);
214 uint_t zfs_fsyncer_key
;
215 extern uint_t rrw_tsd_key
;
216 static uint_t zfs_allow_log_key
;
218 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
219 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
220 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
226 } zfs_ioc_namecheck_t
;
229 POOL_CHECK_NONE
= 1 << 0,
230 POOL_CHECK_SUSPENDED
= 1 << 1,
231 POOL_CHECK_READONLY
= 1 << 2,
232 } zfs_ioc_poolcheck_t
;
234 typedef struct zfs_ioc_vec
{
235 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
236 zfs_ioc_func_t
*zvec_func
;
237 zfs_secpolicy_func_t
*zvec_secpolicy
;
238 zfs_ioc_namecheck_t zvec_namecheck
;
239 boolean_t zvec_allow_log
;
240 zfs_ioc_poolcheck_t zvec_pool_check
;
241 boolean_t zvec_smush_outnvlist
;
242 const char *zvec_name
;
245 /* This array is indexed by zfs_userquota_prop_t */
246 static const char *userquota_perms
[] = {
247 ZFS_DELEG_PERM_USERUSED
,
248 ZFS_DELEG_PERM_USERQUOTA
,
249 ZFS_DELEG_PERM_GROUPUSED
,
250 ZFS_DELEG_PERM_GROUPQUOTA
,
251 ZFS_DELEG_PERM_USEROBJUSED
,
252 ZFS_DELEG_PERM_USEROBJQUOTA
,
253 ZFS_DELEG_PERM_GROUPOBJUSED
,
254 ZFS_DELEG_PERM_GROUPOBJQUOTA
,
255 ZFS_DELEG_PERM_PROJECTUSED
,
256 ZFS_DELEG_PERM_PROJECTQUOTA
,
257 ZFS_DELEG_PERM_PROJECTOBJUSED
,
258 ZFS_DELEG_PERM_PROJECTOBJQUOTA
,
261 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
262 static int zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
);
263 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
265 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
267 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
269 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
270 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
273 history_str_free(char *buf
)
275 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
279 history_str_get(zfs_cmd_t
*zc
)
283 if (zc
->zc_history
== 0)
286 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
287 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
288 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
289 history_str_free(buf
);
293 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
299 * Check to see if the named dataset is currently defined as bootable
302 zfs_is_bootfs(const char *name
)
306 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
308 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
309 dmu_objset_rele(os
, FTAG
);
316 * Return non-zero if the spa version is less than requested version.
319 zfs_earlier_version(const char *name
, int version
)
323 if (spa_open(name
, &spa
, FTAG
) == 0) {
324 if (spa_version(spa
) < version
) {
325 spa_close(spa
, FTAG
);
328 spa_close(spa
, FTAG
);
334 * Return TRUE if the ZPL version is less than requested version.
337 zpl_earlier_version(const char *name
, int version
)
340 boolean_t rc
= B_TRUE
;
342 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
345 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
346 dmu_objset_rele(os
, FTAG
);
349 /* XXX reading from non-owned objset */
350 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
351 rc
= zplversion
< version
;
352 dmu_objset_rele(os
, FTAG
);
358 zfs_log_history(zfs_cmd_t
*zc
)
363 if ((buf
= history_str_get(zc
)) == NULL
)
366 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
367 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
368 (void) spa_history_log(spa
, buf
);
369 spa_close(spa
, FTAG
);
371 history_str_free(buf
);
375 * Policy for top-level read operations (list pools). Requires no privileges,
376 * and can be used in the local zone, as there is no associated dataset.
380 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
386 * Policy for dataset read operations (list children, get statistics). Requires
387 * no privileges, but must be visible in the local zone.
391 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
393 if (INGLOBALZONE(curproc
) ||
394 zone_dataset_visible(zc
->zc_name
, NULL
))
397 return (SET_ERROR(ENOENT
));
401 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
406 * The dataset must be visible by this zone -- check this first
407 * so they don't see EPERM on something they shouldn't know about.
409 if (!INGLOBALZONE(curproc
) &&
410 !zone_dataset_visible(dataset
, &writable
))
411 return (SET_ERROR(ENOENT
));
413 if (INGLOBALZONE(curproc
)) {
415 * If the fs is zoned, only root can access it from the
418 if (secpolicy_zfs(cr
) && zoned
)
419 return (SET_ERROR(EPERM
));
422 * If we are in a local zone, the 'zoned' property must be set.
425 return (SET_ERROR(EPERM
));
427 /* must be writable by this zone */
429 return (SET_ERROR(EPERM
));
435 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
439 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
440 return (SET_ERROR(ENOENT
));
442 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
446 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
450 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
451 return (SET_ERROR(ENOENT
));
453 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
457 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
458 const char *perm
, cred_t
*cr
)
462 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
464 error
= secpolicy_zfs(cr
);
466 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
472 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
479 * First do a quick check for root in the global zone, which
480 * is allowed to do all write_perms. This ensures that zfs_ioc_*
481 * will get to handle nonexistent datasets.
483 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
486 error
= dsl_pool_hold(name
, FTAG
, &dp
);
490 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
492 dsl_pool_rele(dp
, FTAG
);
496 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
498 dsl_dataset_rele(ds
, FTAG
);
499 dsl_pool_rele(dp
, FTAG
);
504 * Policy for setting the security label property.
506 * Returns 0 for success, non-zero for access and other errors.
509 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
512 char ds_hexsl
[MAXNAMELEN
];
513 bslabel_t ds_sl
, new_sl
;
514 boolean_t new_default
= FALSE
;
516 int needed_priv
= -1;
519 /* First get the existing dataset label. */
520 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
521 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
523 return (SET_ERROR(EPERM
));
525 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
528 /* The label must be translatable */
529 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
530 return (SET_ERROR(EINVAL
));
533 * In a non-global zone, disallow attempts to set a label that
534 * doesn't match that of the zone; otherwise no other checks
537 if (!INGLOBALZONE(curproc
)) {
538 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
539 return (SET_ERROR(EPERM
));
544 * For global-zone datasets (i.e., those whose zoned property is
545 * "off", verify that the specified new label is valid for the
548 if (dsl_prop_get_integer(name
,
549 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
550 return (SET_ERROR(EPERM
));
552 if (zfs_check_global_label(name
, strval
) != 0)
553 return (SET_ERROR(EPERM
));
557 * If the existing dataset label is nondefault, check if the
558 * dataset is mounted (label cannot be changed while mounted).
559 * Get the zfsvfs_t; if there isn't one, then the dataset isn't
560 * mounted (or isn't a dataset, doesn't exist, ...).
562 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
564 static char *setsl_tag
= "setsl_tag";
567 * Try to own the dataset; abort if there is any error,
568 * (e.g., already mounted, in use, or other error).
570 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
, B_TRUE
,
573 return (SET_ERROR(EPERM
));
575 dmu_objset_disown(os
, B_TRUE
, setsl_tag
);
578 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
582 if (hexstr_to_label(strval
, &new_sl
) != 0)
583 return (SET_ERROR(EPERM
));
585 if (blstrictdom(&ds_sl
, &new_sl
))
586 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
587 else if (blstrictdom(&new_sl
, &ds_sl
))
588 needed_priv
= PRIV_FILE_UPGRADE_SL
;
590 /* dataset currently has a default label */
592 needed_priv
= PRIV_FILE_UPGRADE_SL
;
596 if (needed_priv
!= -1)
597 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
600 return (SET_ERROR(ENOTSUP
));
601 #endif /* HAVE_MLSLABEL */
605 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
611 * Check permissions for special properties.
618 * Disallow setting of 'zoned' from within a local zone.
620 if (!INGLOBALZONE(curproc
))
621 return (SET_ERROR(EPERM
));
625 case ZFS_PROP_FILESYSTEM_LIMIT
:
626 case ZFS_PROP_SNAPSHOT_LIMIT
:
627 if (!INGLOBALZONE(curproc
)) {
629 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
631 * Unprivileged users are allowed to modify the
632 * limit on things *under* (ie. contained by)
633 * the thing they own.
635 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
637 return (SET_ERROR(EPERM
));
638 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
639 return (SET_ERROR(EPERM
));
643 case ZFS_PROP_MLSLABEL
:
644 if (!is_system_labeled())
645 return (SET_ERROR(EPERM
));
647 if (nvpair_value_string(propval
, &strval
) == 0) {
650 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
657 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
662 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
666 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
671 * permission to set permissions will be evaluated later in
672 * dsl_deleg_can_allow()
679 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
681 return (zfs_secpolicy_write_perms(zc
->zc_name
,
682 ZFS_DELEG_PERM_ROLLBACK
, cr
));
687 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
695 * Generate the current snapshot name from the given objsetid, then
696 * use that name for the secpolicy/zone checks.
698 cp
= strchr(zc
->zc_name
, '@');
700 return (SET_ERROR(EINVAL
));
701 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
705 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
707 dsl_pool_rele(dp
, FTAG
);
711 dsl_dataset_name(ds
, zc
->zc_name
);
713 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
714 ZFS_DELEG_PERM_SEND
, cr
);
715 dsl_dataset_rele(ds
, FTAG
);
716 dsl_pool_rele(dp
, FTAG
);
723 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
725 return (zfs_secpolicy_write_perms(zc
->zc_name
,
726 ZFS_DELEG_PERM_SEND
, cr
));
729 #ifdef HAVE_SMB_SHARE
732 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
737 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
738 NO_FOLLOW
, NULL
, &vp
)) != 0)
741 /* Now make sure mntpnt and dataset are ZFS */
743 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
744 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
745 zc
->zc_name
) != 0)) {
747 return (SET_ERROR(EPERM
));
751 return (dsl_deleg_access(zc
->zc_name
,
752 ZFS_DELEG_PERM_SHARE
, cr
));
754 #endif /* HAVE_SMB_SHARE */
757 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
759 #ifdef HAVE_SMB_SHARE
760 if (!INGLOBALZONE(curproc
))
761 return (SET_ERROR(EPERM
));
763 if (secpolicy_nfs(cr
) == 0) {
766 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
769 return (SET_ERROR(ENOTSUP
));
770 #endif /* HAVE_SMB_SHARE */
774 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
776 #ifdef HAVE_SMB_SHARE
777 if (!INGLOBALZONE(curproc
))
778 return (SET_ERROR(EPERM
));
780 if (secpolicy_smb(cr
) == 0) {
783 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
786 return (SET_ERROR(ENOTSUP
));
787 #endif /* HAVE_SMB_SHARE */
791 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
796 * Remove the @bla or /bla from the end of the name to get the parent.
798 (void) strncpy(parent
, datasetname
, parentsize
);
799 cp
= strrchr(parent
, '@');
803 cp
= strrchr(parent
, '/');
805 return (SET_ERROR(ENOENT
));
813 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
817 if ((error
= zfs_secpolicy_write_perms(name
,
818 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
821 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
826 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
828 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
832 * Destroying snapshots with delegated permissions requires
833 * descendant mount and destroy permissions.
837 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
840 nvpair_t
*pair
, *nextpair
;
843 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
844 return (SET_ERROR(EINVAL
));
845 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
847 nextpair
= nvlist_next_nvpair(snaps
, pair
);
848 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
849 if (error
== ENOENT
) {
851 * Ignore any snapshots that don't exist (we consider
852 * them "already destroyed"). Remove the name from the
853 * nvl here in case the snapshot is created between
854 * now and when we try to destroy it (in which case
855 * we don't want to destroy it since we haven't
856 * checked for permission).
858 fnvlist_remove_nvpair(snaps
, pair
);
869 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
871 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
874 if ((error
= zfs_secpolicy_write_perms(from
,
875 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
878 if ((error
= zfs_secpolicy_write_perms(from
,
879 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
882 if ((error
= zfs_get_parent(to
, parentname
,
883 sizeof (parentname
))) != 0)
886 if ((error
= zfs_secpolicy_write_perms(parentname
,
887 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
890 if ((error
= zfs_secpolicy_write_perms(parentname
,
891 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
899 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
901 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
906 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
909 dsl_dataset_t
*clone
;
912 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
913 ZFS_DELEG_PERM_PROMOTE
, cr
);
917 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
921 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
924 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
925 dsl_dataset_t
*origin
= NULL
;
929 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
930 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
932 dsl_dataset_rele(clone
, FTAG
);
933 dsl_pool_rele(dp
, FTAG
);
937 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
938 ZFS_DELEG_PERM_MOUNT
, cr
);
940 dsl_dataset_name(origin
, parentname
);
942 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
943 ZFS_DELEG_PERM_PROMOTE
, cr
);
945 dsl_dataset_rele(clone
, FTAG
);
946 dsl_dataset_rele(origin
, FTAG
);
948 dsl_pool_rele(dp
, FTAG
);
954 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
958 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
959 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
962 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
963 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
966 return (zfs_secpolicy_write_perms(zc
->zc_name
,
967 ZFS_DELEG_PERM_CREATE
, cr
));
972 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
974 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
978 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
980 return (zfs_secpolicy_write_perms(name
,
981 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
985 * Check for permission to create each snapshot in the nvlist.
989 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
995 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
996 return (SET_ERROR(EINVAL
));
997 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
998 pair
= nvlist_next_nvpair(snaps
, pair
)) {
999 char *name
= nvpair_name(pair
);
1000 char *atp
= strchr(name
, '@');
1003 error
= SET_ERROR(EINVAL
);
1007 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
1016 * Check for permission to create each snapshot in the nvlist.
1020 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1024 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
1025 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1026 char *name
= nvpair_name(pair
);
1027 char *hashp
= strchr(name
, '#');
1029 if (hashp
== NULL
) {
1030 error
= SET_ERROR(EINVAL
);
1034 error
= zfs_secpolicy_write_perms(name
,
1035 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1045 zfs_secpolicy_remap(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1047 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1048 ZFS_DELEG_PERM_REMAP
, 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
;
1513 char *spa_name
= zc
->zc_name
;
1515 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1516 zc
->zc_iflags
, &config
)))
1519 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1520 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1521 zc
->zc_iflags
, &props
))) {
1522 nvlist_free(config
);
1527 nvlist_t
*nvl
= NULL
;
1528 nvlist_t
*hidden_args
= NULL
;
1529 uint64_t version
= SPA_VERSION
;
1532 (void) nvlist_lookup_uint64(props
,
1533 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1534 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1535 error
= SET_ERROR(EINVAL
);
1536 goto pool_props_bad
;
1538 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1540 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1542 nvlist_free(config
);
1546 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1549 (void) nvlist_lookup_nvlist(props
, ZPOOL_HIDDEN_ARGS
,
1551 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
,
1552 rootprops
, hidden_args
, &dcp
);
1554 nvlist_free(config
);
1558 (void) nvlist_remove_all(props
, ZPOOL_HIDDEN_ARGS
);
1560 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1561 error
= zfs_fill_zplprops_root(version
, rootprops
,
1564 goto pool_props_bad
;
1566 if (nvlist_lookup_string(props
,
1567 zpool_prop_to_name(ZPOOL_PROP_TNAME
), &tname
) == 0)
1571 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
, dcp
);
1574 * Set the remaining root properties
1576 if (!error
&& (error
= zfs_set_prop_nvlist(spa_name
,
1577 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1578 (void) spa_destroy(spa_name
);
1581 nvlist_free(rootprops
);
1582 nvlist_free(zplprops
);
1583 nvlist_free(config
);
1585 dsl_crypto_params_free(dcp
, !!error
);
1591 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1594 zfs_log_history(zc
);
1595 error
= spa_destroy(zc
->zc_name
);
1601 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1603 nvlist_t
*config
, *props
= NULL
;
1607 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1608 zc
->zc_iflags
, &config
)) != 0)
1611 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1612 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1613 zc
->zc_iflags
, &props
))) {
1614 nvlist_free(config
);
1618 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1619 guid
!= zc
->zc_guid
)
1620 error
= SET_ERROR(EINVAL
);
1622 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1624 if (zc
->zc_nvlist_dst
!= 0) {
1627 if ((err
= put_nvlist(zc
, config
)) != 0)
1631 nvlist_free(config
);
1638 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1641 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1642 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1644 zfs_log_history(zc
);
1645 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1651 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1656 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1657 return (SET_ERROR(EEXIST
));
1659 error
= put_nvlist(zc
, configs
);
1661 nvlist_free(configs
);
1668 * zc_name name of the pool
1671 * zc_cookie real errno
1672 * zc_nvlist_dst config nvlist
1673 * zc_nvlist_dst_size size of config nvlist
1676 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1682 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1683 sizeof (zc
->zc_value
));
1685 if (config
!= NULL
) {
1686 ret
= put_nvlist(zc
, config
);
1687 nvlist_free(config
);
1690 * The config may be present even if 'error' is non-zero.
1691 * In this case we return success, and preserve the real errno
1694 zc
->zc_cookie
= error
;
1703 * Try to import the given pool, returning pool stats as appropriate so that
1704 * user land knows which devices are available and overall pool health.
1707 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1709 nvlist_t
*tryconfig
, *config
= NULL
;
1712 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1713 zc
->zc_iflags
, &tryconfig
)) != 0)
1716 config
= spa_tryimport(tryconfig
);
1718 nvlist_free(tryconfig
);
1721 return (SET_ERROR(EINVAL
));
1723 error
= put_nvlist(zc
, config
);
1724 nvlist_free(config
);
1731 * zc_name name of the pool
1732 * zc_cookie scan func (pool_scan_func_t)
1733 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1736 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1741 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1742 return (SET_ERROR(EINVAL
));
1744 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1747 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1748 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1749 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1750 error
= spa_scan_stop(spa
);
1752 error
= spa_scan(spa
, zc
->zc_cookie
);
1754 spa_close(spa
, FTAG
);
1760 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1765 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1768 spa_close(spa
, FTAG
);
1774 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1779 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1782 if (zc
->zc_cookie
< spa_version(spa
) ||
1783 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1784 spa_close(spa
, FTAG
);
1785 return (SET_ERROR(EINVAL
));
1788 spa_upgrade(spa
, zc
->zc_cookie
);
1789 spa_close(spa
, FTAG
);
1795 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1802 if ((size
= zc
->zc_history_len
) == 0)
1803 return (SET_ERROR(EINVAL
));
1805 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1808 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1809 spa_close(spa
, FTAG
);
1810 return (SET_ERROR(ENOTSUP
));
1813 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1814 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1815 &zc
->zc_history_len
, hist_buf
)) == 0) {
1816 error
= ddi_copyout(hist_buf
,
1817 (void *)(uintptr_t)zc
->zc_history
,
1818 zc
->zc_history_len
, zc
->zc_iflags
);
1821 spa_close(spa
, FTAG
);
1822 vmem_free(hist_buf
, size
);
1827 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1832 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1834 error
= spa_change_guid(spa
);
1835 spa_close(spa
, FTAG
);
1841 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1843 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1848 * zc_name name of filesystem
1849 * zc_obj object to find
1852 * zc_value name of object
1855 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1860 /* XXX reading from objset not owned */
1861 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1864 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1865 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1866 return (SET_ERROR(EINVAL
));
1868 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1869 sizeof (zc
->zc_value
));
1870 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1877 * zc_name name of filesystem
1878 * zc_obj object to find
1881 * zc_stat stats on object
1882 * zc_value path to object
1885 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1890 /* XXX reading from objset not owned */
1891 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1894 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1895 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1896 return (SET_ERROR(EINVAL
));
1898 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1899 sizeof (zc
->zc_value
));
1900 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1906 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1912 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1916 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1917 zc
->zc_iflags
, &config
);
1919 error
= spa_vdev_add(spa
, config
);
1920 nvlist_free(config
);
1922 spa_close(spa
, FTAG
);
1928 * zc_name name of the pool
1929 * zc_guid guid of vdev to remove
1930 * zc_cookie cancel removal
1933 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1938 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1941 if (zc
->zc_cookie
!= 0) {
1942 error
= spa_vdev_remove_cancel(spa
);
1944 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1946 spa_close(spa
, FTAG
);
1951 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1955 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1957 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1959 switch (zc
->zc_cookie
) {
1960 case VDEV_STATE_ONLINE
:
1961 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1964 case VDEV_STATE_OFFLINE
:
1965 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1968 case VDEV_STATE_FAULTED
:
1969 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1970 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
&&
1971 zc
->zc_obj
!= VDEV_AUX_EXTERNAL_PERSIST
)
1972 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1974 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1977 case VDEV_STATE_DEGRADED
:
1978 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1979 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1980 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1982 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1986 error
= SET_ERROR(EINVAL
);
1988 zc
->zc_cookie
= newstate
;
1989 spa_close(spa
, FTAG
);
1994 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1997 int replacing
= zc
->zc_cookie
;
2001 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2004 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2005 zc
->zc_iflags
, &config
)) == 0) {
2006 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
2007 nvlist_free(config
);
2010 spa_close(spa
, FTAG
);
2015 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
2020 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2023 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
2025 spa_close(spa
, FTAG
);
2030 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
2033 nvlist_t
*config
, *props
= NULL
;
2035 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
2037 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2040 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2041 zc
->zc_iflags
, &config
))) {
2042 spa_close(spa
, FTAG
);
2046 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
2047 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2048 zc
->zc_iflags
, &props
))) {
2049 spa_close(spa
, FTAG
);
2050 nvlist_free(config
);
2054 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
2056 spa_close(spa
, FTAG
);
2058 nvlist_free(config
);
2065 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
2068 char *path
= zc
->zc_value
;
2069 uint64_t guid
= zc
->zc_guid
;
2072 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2076 error
= spa_vdev_setpath(spa
, guid
, path
);
2077 spa_close(spa
, FTAG
);
2082 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
2085 char *fru
= zc
->zc_value
;
2086 uint64_t guid
= zc
->zc_guid
;
2089 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2093 error
= spa_vdev_setfru(spa
, guid
, fru
);
2094 spa_close(spa
, FTAG
);
2099 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2104 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2106 if (zc
->zc_nvlist_dst
!= 0 &&
2107 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2108 dmu_objset_stats(os
, nv
);
2110 * NB: zvol_get_stats() will read the objset contents,
2111 * which we aren't supposed to do with a
2112 * DS_MODE_USER hold, because it could be
2113 * inconsistent. So this is a bit of a workaround...
2114 * XXX reading with out owning
2116 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2117 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2118 error
= zvol_get_stats(os
, nv
);
2126 error
= put_nvlist(zc
, nv
);
2135 * zc_name name of filesystem
2136 * zc_nvlist_dst_size size of buffer for property nvlist
2139 * zc_objset_stats stats
2140 * zc_nvlist_dst property nvlist
2141 * zc_nvlist_dst_size size of property nvlist
2144 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2149 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2151 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2152 dmu_objset_rele(os
, FTAG
);
2160 * zc_name name of filesystem
2161 * zc_nvlist_dst_size size of buffer for property nvlist
2164 * zc_nvlist_dst received property nvlist
2165 * zc_nvlist_dst_size size of received property nvlist
2167 * Gets received properties (distinct from local properties on or after
2168 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2169 * local property values.
2172 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2178 * Without this check, we would return local property values if the
2179 * caller has not already received properties on or after
2180 * SPA_VERSION_RECVD_PROPS.
2182 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2183 return (SET_ERROR(ENOTSUP
));
2185 if (zc
->zc_nvlist_dst
!= 0 &&
2186 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2187 error
= put_nvlist(zc
, nv
);
2195 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2201 * zfs_get_zplprop() will either find a value or give us
2202 * the default value (if there is one).
2204 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2206 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2212 * zc_name name of filesystem
2213 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2216 * zc_nvlist_dst zpl property nvlist
2217 * zc_nvlist_dst_size size of zpl property nvlist
2220 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2225 /* XXX reading without owning */
2226 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2229 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2232 * NB: nvl_add_zplprop() will read the objset contents,
2233 * which we aren't supposed to do with a DS_MODE_USER
2234 * hold, because it could be inconsistent.
2236 if (zc
->zc_nvlist_dst
!= 0 &&
2237 !zc
->zc_objset_stats
.dds_inconsistent
&&
2238 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2241 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2242 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2243 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2244 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2245 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2246 err
= put_nvlist(zc
, nv
);
2249 err
= SET_ERROR(ENOENT
);
2251 dmu_objset_rele(os
, FTAG
);
2256 dataset_name_hidden(const char *name
)
2259 * Skip over datasets that are not visible in this zone,
2260 * internal datasets (which have a $ in their name), and
2261 * temporary datasets (which have a % in their name).
2263 if (strchr(name
, '$') != NULL
)
2265 if (strchr(name
, '%') != NULL
)
2267 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2274 * zc_name name of filesystem
2275 * zc_cookie zap cursor
2276 * zc_nvlist_dst_size size of buffer for property nvlist
2279 * zc_name name of next filesystem
2280 * zc_cookie zap cursor
2281 * zc_objset_stats stats
2282 * zc_nvlist_dst property nvlist
2283 * zc_nvlist_dst_size size of property nvlist
2286 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2291 size_t orig_len
= strlen(zc
->zc_name
);
2294 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2295 if (error
== ENOENT
)
2296 error
= SET_ERROR(ESRCH
);
2300 p
= strrchr(zc
->zc_name
, '/');
2301 if (p
== NULL
|| p
[1] != '\0')
2302 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2303 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2306 error
= dmu_dir_list_next(os
,
2307 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2308 NULL
, &zc
->zc_cookie
);
2309 if (error
== ENOENT
)
2310 error
= SET_ERROR(ESRCH
);
2311 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2312 dmu_objset_rele(os
, FTAG
);
2315 * If it's an internal dataset (ie. with a '$' in its name),
2316 * don't try to get stats for it, otherwise we'll return ENOENT.
2318 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2319 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2320 if (error
== ENOENT
) {
2321 /* We lost a race with destroy, get the next one. */
2322 zc
->zc_name
[orig_len
] = '\0';
2331 * zc_name name of filesystem
2332 * zc_cookie zap cursor
2333 * zc_nvlist_dst_size size of buffer for property nvlist
2336 * zc_name name of next snapshot
2337 * zc_objset_stats stats
2338 * zc_nvlist_dst property nvlist
2339 * zc_nvlist_dst_size size of property nvlist
2342 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2347 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2349 return (error
== ENOENT
? ESRCH
: error
);
2353 * A dataset name of maximum length cannot have any snapshots,
2354 * so exit immediately.
2356 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2357 ZFS_MAX_DATASET_NAME_LEN
) {
2358 dmu_objset_rele(os
, FTAG
);
2359 return (SET_ERROR(ESRCH
));
2362 error
= dmu_snapshot_list_next(os
,
2363 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2364 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2367 if (error
== 0 && !zc
->zc_simple
) {
2369 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2371 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2375 error
= dmu_objset_from_ds(ds
, &ossnap
);
2377 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2378 dsl_dataset_rele(ds
, FTAG
);
2380 } else if (error
== ENOENT
) {
2381 error
= SET_ERROR(ESRCH
);
2384 dmu_objset_rele(os
, FTAG
);
2385 /* if we failed, undo the @ that we tacked on to zc_name */
2387 *strchr(zc
->zc_name
, '@') = '\0';
2392 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2394 const char *propname
= nvpair_name(pair
);
2396 unsigned int vallen
;
2399 zfs_userquota_prop_t type
;
2405 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2407 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2408 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2410 return (SET_ERROR(EINVAL
));
2414 * A correctly constructed propname is encoded as
2415 * userquota@<rid>-<domain>.
2417 if ((dash
= strchr(propname
, '-')) == NULL
||
2418 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2420 return (SET_ERROR(EINVAL
));
2427 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2429 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2430 zfsvfs_rele(zfsvfs
, FTAG
);
2437 * If the named property is one that has a special function to set its value,
2438 * return 0 on success and a positive error code on failure; otherwise if it is
2439 * not one of the special properties handled by this function, return -1.
2441 * XXX: It would be better for callers of the property interface if we handled
2442 * these special cases in dsl_prop.c (in the dsl layer).
2445 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2448 const char *propname
= nvpair_name(pair
);
2449 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2450 uint64_t intval
= 0;
2451 char *strval
= NULL
;
2454 if (prop
== ZPROP_INVAL
) {
2455 if (zfs_prop_userquota(propname
))
2456 return (zfs_prop_set_userquota(dsname
, pair
));
2460 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2462 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2463 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2467 /* all special properties are numeric except for keylocation */
2468 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
) {
2469 strval
= fnvpair_value_string(pair
);
2471 intval
= fnvpair_value_uint64(pair
);
2475 case ZFS_PROP_QUOTA
:
2476 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2478 case ZFS_PROP_REFQUOTA
:
2479 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2481 case ZFS_PROP_FILESYSTEM_LIMIT
:
2482 case ZFS_PROP_SNAPSHOT_LIMIT
:
2483 if (intval
== UINT64_MAX
) {
2484 /* clearing the limit, just do it */
2487 err
= dsl_dir_activate_fs_ss_limit(dsname
);
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_KEYLOCATION
:
2497 err
= dsl_crypto_can_set_keylocation(dsname
, strval
);
2500 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2501 * default path to set the value in the nvlist.
2506 case ZFS_PROP_RESERVATION
:
2507 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2509 case ZFS_PROP_REFRESERVATION
:
2510 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2512 case ZFS_PROP_VOLSIZE
:
2513 err
= zvol_set_volsize(dsname
, intval
);
2515 case ZFS_PROP_SNAPDEV
:
2516 err
= zvol_set_snapdev(dsname
, source
, intval
);
2518 case ZFS_PROP_VOLMODE
:
2519 err
= zvol_set_volmode(dsname
, source
, intval
);
2521 case ZFS_PROP_VERSION
:
2525 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2528 err
= zfs_set_version(zfsvfs
, intval
);
2529 zfsvfs_rele(zfsvfs
, FTAG
);
2531 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2534 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2535 (void) strcpy(zc
->zc_name
, dsname
);
2536 (void) zfs_ioc_userspace_upgrade(zc
);
2537 (void) zfs_ioc_id_quota_upgrade(zc
);
2538 kmem_free(zc
, sizeof (zfs_cmd_t
));
2550 * This function is best effort. If it fails to set any of the given properties,
2551 * it continues to set as many as it can and returns the last error
2552 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2553 * with the list of names of all the properties that failed along with the
2554 * corresponding error numbers.
2556 * If every property is set successfully, zero is returned and errlist is not
2560 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2569 nvlist_t
*genericnvl
= fnvlist_alloc();
2570 nvlist_t
*retrynvl
= fnvlist_alloc();
2573 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2574 const char *propname
= nvpair_name(pair
);
2575 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2578 /* decode the property value */
2580 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2582 attrs
= fnvpair_value_nvlist(pair
);
2583 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2585 err
= SET_ERROR(EINVAL
);
2588 /* Validate value type */
2589 if (err
== 0 && source
== ZPROP_SRC_INHERITED
) {
2590 /* inherited properties are expected to be booleans */
2591 if (nvpair_type(propval
) != DATA_TYPE_BOOLEAN
)
2592 err
= SET_ERROR(EINVAL
);
2593 } else if (err
== 0 && prop
== ZPROP_INVAL
) {
2594 if (zfs_prop_user(propname
)) {
2595 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2596 err
= SET_ERROR(EINVAL
);
2597 } else if (zfs_prop_userquota(propname
)) {
2598 if (nvpair_type(propval
) !=
2599 DATA_TYPE_UINT64_ARRAY
)
2600 err
= SET_ERROR(EINVAL
);
2602 err
= SET_ERROR(EINVAL
);
2604 } else if (err
== 0) {
2605 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2606 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2607 err
= SET_ERROR(EINVAL
);
2608 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2611 intval
= fnvpair_value_uint64(propval
);
2613 switch (zfs_prop_get_type(prop
)) {
2614 case PROP_TYPE_NUMBER
:
2616 case PROP_TYPE_STRING
:
2617 err
= SET_ERROR(EINVAL
);
2619 case PROP_TYPE_INDEX
:
2620 if (zfs_prop_index_to_string(prop
,
2621 intval
, &unused
) != 0)
2622 err
= SET_ERROR(EINVAL
);
2626 "unknown property type");
2629 err
= SET_ERROR(EINVAL
);
2633 /* Validate permissions */
2635 err
= zfs_check_settable(dsname
, pair
, CRED());
2638 if (source
== ZPROP_SRC_INHERITED
)
2639 err
= -1; /* does not need special handling */
2641 err
= zfs_prop_set_special(dsname
, source
,
2645 * For better performance we build up a list of
2646 * properties to set in a single transaction.
2648 err
= nvlist_add_nvpair(genericnvl
, pair
);
2649 } else if (err
!= 0 && nvl
!= retrynvl
) {
2651 * This may be a spurious error caused by
2652 * receiving quota and reservation out of order.
2653 * Try again in a second pass.
2655 err
= nvlist_add_nvpair(retrynvl
, pair
);
2660 if (errlist
!= NULL
)
2661 fnvlist_add_int32(errlist
, propname
, err
);
2666 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2671 if (!nvlist_empty(genericnvl
) &&
2672 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2674 * If this fails, we still want to set as many properties as we
2675 * can, so try setting them individually.
2678 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2679 const char *propname
= nvpair_name(pair
);
2683 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2685 attrs
= fnvpair_value_nvlist(pair
);
2686 propval
= fnvlist_lookup_nvpair(attrs
,
2690 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2691 strval
= fnvpair_value_string(propval
);
2692 err
= dsl_prop_set_string(dsname
, propname
,
2694 } else if (nvpair_type(propval
) == DATA_TYPE_BOOLEAN
) {
2695 err
= dsl_prop_inherit(dsname
, propname
,
2698 intval
= fnvpair_value_uint64(propval
);
2699 err
= dsl_prop_set_int(dsname
, propname
, source
,
2704 if (errlist
!= NULL
) {
2705 fnvlist_add_int32(errlist
, propname
,
2712 nvlist_free(genericnvl
);
2713 nvlist_free(retrynvl
);
2719 * Check that all the properties are valid user properties.
2722 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2724 nvpair_t
*pair
= NULL
;
2727 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2728 const char *propname
= nvpair_name(pair
);
2730 if (!zfs_prop_user(propname
) ||
2731 nvpair_type(pair
) != DATA_TYPE_STRING
)
2732 return (SET_ERROR(EINVAL
));
2734 if ((error
= zfs_secpolicy_write_perms(fsname
,
2735 ZFS_DELEG_PERM_USERPROP
, CRED())))
2738 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2739 return (SET_ERROR(ENAMETOOLONG
));
2741 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2742 return (SET_ERROR(E2BIG
));
2748 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2752 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2755 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2756 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2759 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2764 clear_received_props(const char *dsname
, nvlist_t
*props
,
2768 nvlist_t
*cleared_props
= NULL
;
2769 props_skip(props
, skipped
, &cleared_props
);
2770 if (!nvlist_empty(cleared_props
)) {
2772 * Acts on local properties until the dataset has received
2773 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2775 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2776 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2777 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2779 nvlist_free(cleared_props
);
2785 * zc_name name of filesystem
2786 * zc_value name of property to set
2787 * zc_nvlist_src{_size} nvlist of properties to apply
2788 * zc_cookie received properties flag
2791 * zc_nvlist_dst{_size} error for each unapplied received property
2794 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2797 boolean_t received
= zc
->zc_cookie
;
2798 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2803 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2804 zc
->zc_iflags
, &nvl
)) != 0)
2808 nvlist_t
*origprops
;
2810 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2811 (void) clear_received_props(zc
->zc_name
,
2813 nvlist_free(origprops
);
2816 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2819 errors
= fnvlist_alloc();
2821 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2823 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2824 (void) put_nvlist(zc
, errors
);
2827 nvlist_free(errors
);
2834 * zc_name name of filesystem
2835 * zc_value name of property to inherit
2836 * zc_cookie revert to received value if TRUE
2841 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2843 const char *propname
= zc
->zc_value
;
2844 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2845 boolean_t received
= zc
->zc_cookie
;
2846 zprop_source_t source
= (received
2847 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2848 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2856 * Only check this in the non-received case. We want to allow
2857 * 'inherit -S' to revert non-inheritable properties like quota
2858 * and reservation to the received or default values even though
2859 * they are not considered inheritable.
2861 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2862 return (SET_ERROR(EINVAL
));
2865 if (prop
== ZPROP_INVAL
) {
2866 if (!zfs_prop_user(propname
))
2867 return (SET_ERROR(EINVAL
));
2869 type
= PROP_TYPE_STRING
;
2870 } else if (prop
== ZFS_PROP_VOLSIZE
|| prop
== ZFS_PROP_VERSION
) {
2871 return (SET_ERROR(EINVAL
));
2873 type
= zfs_prop_get_type(prop
);
2877 * zfs_prop_set_special() expects properties in the form of an
2878 * nvpair with type info.
2880 dummy
= fnvlist_alloc();
2883 case PROP_TYPE_STRING
:
2884 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2886 case PROP_TYPE_NUMBER
:
2887 case PROP_TYPE_INDEX
:
2888 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2891 err
= SET_ERROR(EINVAL
);
2895 pair
= nvlist_next_nvpair(dummy
, NULL
);
2897 err
= SET_ERROR(EINVAL
);
2899 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2900 if (err
== -1) /* property is not "special", needs handling */
2901 err
= dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
,
2911 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2918 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2919 zc
->zc_iflags
, &props
)))
2923 * If the only property is the configfile, then just do a spa_lookup()
2924 * to handle the faulted case.
2926 pair
= nvlist_next_nvpair(props
, NULL
);
2927 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2928 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2929 nvlist_next_nvpair(props
, pair
) == NULL
) {
2930 mutex_enter(&spa_namespace_lock
);
2931 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2932 spa_configfile_set(spa
, props
, B_FALSE
);
2933 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
);
2935 mutex_exit(&spa_namespace_lock
);
2942 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2947 error
= spa_prop_set(spa
, props
);
2950 spa_close(spa
, FTAG
);
2956 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2960 nvlist_t
*nvp
= NULL
;
2962 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2964 * If the pool is faulted, there may be properties we can still
2965 * get (such as altroot and cachefile), so attempt to get them
2968 mutex_enter(&spa_namespace_lock
);
2969 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2970 error
= spa_prop_get(spa
, &nvp
);
2971 mutex_exit(&spa_namespace_lock
);
2973 error
= spa_prop_get(spa
, &nvp
);
2974 spa_close(spa
, FTAG
);
2977 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2978 error
= put_nvlist(zc
, nvp
);
2980 error
= SET_ERROR(EFAULT
);
2988 * zc_name name of filesystem
2989 * zc_nvlist_src{_size} nvlist of delegated permissions
2990 * zc_perm_action allow/unallow flag
2995 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2998 nvlist_t
*fsaclnv
= NULL
;
3000 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3001 zc
->zc_iflags
, &fsaclnv
)) != 0)
3005 * Verify nvlist is constructed correctly
3007 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
3008 nvlist_free(fsaclnv
);
3009 return (SET_ERROR(EINVAL
));
3013 * If we don't have PRIV_SYS_MOUNT, then validate
3014 * that user is allowed to hand out each permission in
3018 error
= secpolicy_zfs(CRED());
3020 if (zc
->zc_perm_action
== B_FALSE
) {
3021 error
= dsl_deleg_can_allow(zc
->zc_name
,
3024 error
= dsl_deleg_can_unallow(zc
->zc_name
,
3030 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
3032 nvlist_free(fsaclnv
);
3038 * zc_name name of filesystem
3041 * zc_nvlist_src{_size} nvlist of delegated permissions
3044 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
3049 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
3050 error
= put_nvlist(zc
, nvp
);
3059 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
3061 zfs_creat_t
*zct
= arg
;
3063 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
3066 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
3070 * os parent objset pointer (NULL if root fs)
3071 * fuids_ok fuids allowed in this version of the spa?
3072 * sa_ok SAs allowed in this version of the spa?
3073 * createprops list of properties requested by creator
3076 * zplprops values for the zplprops we attach to the master node object
3077 * is_ci true if requested file system will be purely case-insensitive
3079 * Determine the settings for utf8only, normalization and
3080 * casesensitivity. Specific values may have been requested by the
3081 * creator and/or we can inherit values from the parent dataset. If
3082 * the file system is of too early a vintage, a creator can not
3083 * request settings for these properties, even if the requested
3084 * setting is the default value. We don't actually want to create dsl
3085 * properties for these, so remove them from the source nvlist after
3089 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
3090 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
3091 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3093 uint64_t sense
= ZFS_PROP_UNDEFINED
;
3094 uint64_t norm
= ZFS_PROP_UNDEFINED
;
3095 uint64_t u8
= ZFS_PROP_UNDEFINED
;
3098 ASSERT(zplprops
!= NULL
);
3100 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
3101 return (SET_ERROR(EINVAL
));
3104 * Pull out creator prop choices, if any.
3107 (void) nvlist_lookup_uint64(createprops
,
3108 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
3109 (void) nvlist_lookup_uint64(createprops
,
3110 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
3111 (void) nvlist_remove_all(createprops
,
3112 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3113 (void) nvlist_lookup_uint64(createprops
,
3114 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3115 (void) nvlist_remove_all(createprops
,
3116 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3117 (void) nvlist_lookup_uint64(createprops
,
3118 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3119 (void) nvlist_remove_all(createprops
,
3120 zfs_prop_to_name(ZFS_PROP_CASE
));
3124 * If the zpl version requested is whacky or the file system
3125 * or pool is version is too "young" to support normalization
3126 * and the creator tried to set a value for one of the props,
3129 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3130 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3131 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3132 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3133 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3134 sense
!= ZFS_PROP_UNDEFINED
)))
3135 return (SET_ERROR(ENOTSUP
));
3138 * Put the version in the zplprops
3140 VERIFY(nvlist_add_uint64(zplprops
,
3141 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3143 if (norm
== ZFS_PROP_UNDEFINED
&&
3144 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3146 VERIFY(nvlist_add_uint64(zplprops
,
3147 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3150 * If we're normalizing, names must always be valid UTF-8 strings.
3154 if (u8
== ZFS_PROP_UNDEFINED
&&
3155 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3157 VERIFY(nvlist_add_uint64(zplprops
,
3158 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3160 if (sense
== ZFS_PROP_UNDEFINED
&&
3161 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3163 VERIFY(nvlist_add_uint64(zplprops
,
3164 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3167 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3173 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3174 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3176 boolean_t fuids_ok
, sa_ok
;
3177 uint64_t zplver
= ZPL_VERSION
;
3178 objset_t
*os
= NULL
;
3179 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3185 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3186 cp
= strrchr(parentname
, '/');
3190 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3193 spa_vers
= spa_version(spa
);
3194 spa_close(spa
, FTAG
);
3196 zplver
= zfs_zpl_version_map(spa_vers
);
3197 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3198 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3201 * Open parent object set so we can inherit zplprop values.
3203 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3206 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3208 dmu_objset_rele(os
, FTAG
);
3213 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3214 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3218 uint64_t zplver
= ZPL_VERSION
;
3221 zplver
= zfs_zpl_version_map(spa_vers
);
3222 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3223 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3225 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3226 createprops
, zplprops
, is_ci
);
3232 * "type" -> dmu_objset_type_t (int32)
3233 * (optional) "props" -> { prop -> value }
3234 * (optional) "hidden_args" -> { "wkeydata" -> value }
3235 * raw uint8_t array of encryption wrapping key data (32 bytes)
3238 * outnvl: propname -> error code (int32)
3241 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3244 zfs_creat_t zct
= { 0 };
3245 nvlist_t
*nvprops
= NULL
;
3246 nvlist_t
*hidden_args
= NULL
;
3247 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3249 dmu_objset_type_t type
;
3250 boolean_t is_insensitive
= B_FALSE
;
3251 dsl_crypto_params_t
*dcp
= NULL
;
3253 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3254 return (SET_ERROR(EINVAL
));
3256 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3257 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
3261 cbfunc
= zfs_create_cb
;
3265 cbfunc
= zvol_create_cb
;
3272 if (strchr(fsname
, '@') ||
3273 strchr(fsname
, '%'))
3274 return (SET_ERROR(EINVAL
));
3276 zct
.zct_props
= nvprops
;
3279 return (SET_ERROR(EINVAL
));
3281 if (type
== DMU_OST_ZVOL
) {
3282 uint64_t volsize
, volblocksize
;
3284 if (nvprops
== NULL
)
3285 return (SET_ERROR(EINVAL
));
3286 if (nvlist_lookup_uint64(nvprops
,
3287 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3288 return (SET_ERROR(EINVAL
));
3290 if ((error
= nvlist_lookup_uint64(nvprops
,
3291 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3292 &volblocksize
)) != 0 && error
!= ENOENT
)
3293 return (SET_ERROR(EINVAL
));
3296 volblocksize
= zfs_prop_default_numeric(
3297 ZFS_PROP_VOLBLOCKSIZE
);
3299 if ((error
= zvol_check_volblocksize(fsname
,
3300 volblocksize
)) != 0 ||
3301 (error
= zvol_check_volsize(volsize
,
3302 volblocksize
)) != 0)
3304 } else if (type
== DMU_OST_ZFS
) {
3308 * We have to have normalization and
3309 * case-folding flags correct when we do the
3310 * file system creation, so go figure them out
3313 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3314 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3315 error
= zfs_fill_zplprops(fsname
, nvprops
,
3316 zct
.zct_zplprops
, &is_insensitive
);
3318 nvlist_free(zct
.zct_zplprops
);
3323 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, nvprops
,
3326 nvlist_free(zct
.zct_zplprops
);
3330 error
= dmu_objset_create(fsname
, type
,
3331 is_insensitive
? DS_FLAG_CI_DATASET
: 0, dcp
, cbfunc
, &zct
);
3333 nvlist_free(zct
.zct_zplprops
);
3334 dsl_crypto_params_free(dcp
, !!error
);
3337 * It would be nice to do this atomically.
3340 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3347 * Volumes will return EBUSY and cannot be destroyed
3348 * until all asynchronous minor handling has completed.
3349 * Wait for the spa_zvol_taskq to drain then retry.
3351 error2
= dsl_destroy_head(fsname
);
3352 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3353 error2
= spa_open(fsname
, &spa
, FTAG
);
3355 taskq_wait(spa
->spa_zvol_taskq
);
3356 spa_close(spa
, FTAG
);
3358 error2
= dsl_destroy_head(fsname
);
3367 * "origin" -> name of origin snapshot
3368 * (optional) "props" -> { prop -> value }
3369 * (optional) "hidden_args" -> { "wkeydata" -> value }
3370 * raw uint8_t array of encryption wrapping key data (32 bytes)
3374 * outnvl: propname -> error code (int32)
3377 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3380 nvlist_t
*nvprops
= NULL
;
3383 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3384 return (SET_ERROR(EINVAL
));
3385 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3387 if (strchr(fsname
, '@') ||
3388 strchr(fsname
, '%'))
3389 return (SET_ERROR(EINVAL
));
3391 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3392 return (SET_ERROR(EINVAL
));
3394 error
= dmu_objset_clone(fsname
, origin_name
);
3397 * It would be nice to do this atomically.
3400 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3403 (void) dsl_destroy_head(fsname
);
3410 zfs_ioc_remap(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3412 if (strchr(fsname
, '@') ||
3413 strchr(fsname
, '%'))
3414 return (SET_ERROR(EINVAL
));
3416 return (dmu_objset_remap_indirects(fsname
));
3421 * "snaps" -> { snapshot1, snapshot2 }
3422 * (optional) "props" -> { prop -> value (string) }
3425 * outnvl: snapshot -> error code (int32)
3428 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3431 nvlist_t
*props
= NULL
;
3435 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3436 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3439 if (!nvlist_empty(props
) &&
3440 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3441 return (SET_ERROR(ENOTSUP
));
3443 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3444 return (SET_ERROR(EINVAL
));
3445 poollen
= strlen(poolname
);
3446 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3447 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3448 const char *name
= nvpair_name(pair
);
3449 const char *cp
= strchr(name
, '@');
3452 * The snap name must contain an @, and the part after it must
3453 * contain only valid characters.
3456 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3457 return (SET_ERROR(EINVAL
));
3460 * The snap must be in the specified pool.
3462 if (strncmp(name
, poolname
, poollen
) != 0 ||
3463 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3464 return (SET_ERROR(EXDEV
));
3466 /* This must be the only snap of this fs. */
3467 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3468 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3469 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3471 return (SET_ERROR(EXDEV
));
3476 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3482 * innvl: "message" -> string
3486 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3494 * The poolname in the ioctl is not set, we get it from the TSD,
3495 * which was set at the end of the last successful ioctl that allows
3496 * logging. The secpolicy func already checked that it is set.
3497 * Only one log ioctl is allowed after each successful ioctl, so
3498 * we clear the TSD here.
3500 poolname
= tsd_get(zfs_allow_log_key
);
3501 if (poolname
== NULL
)
3502 return (SET_ERROR(EINVAL
));
3503 (void) tsd_set(zfs_allow_log_key
, NULL
);
3504 error
= spa_open(poolname
, &spa
, FTAG
);
3509 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3510 spa_close(spa
, FTAG
);
3511 return (SET_ERROR(EINVAL
));
3514 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3515 spa_close(spa
, FTAG
);
3516 return (SET_ERROR(ENOTSUP
));
3519 error
= spa_history_log(spa
, message
);
3520 spa_close(spa
, FTAG
);
3525 * The dp_config_rwlock must not be held when calling this, because the
3526 * unmount may need to write out data.
3528 * This function is best-effort. Callers must deal gracefully if it
3529 * remains mounted (or is remounted after this call).
3531 * Returns 0 if the argument is not a snapshot, or it is not currently a
3532 * filesystem, or we were able to unmount it. Returns error code otherwise.
3535 zfs_unmount_snap(const char *snapname
)
3537 if (strchr(snapname
, '@') == NULL
)
3540 (void) zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3545 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3547 zfs_unmount_snap(snapname
);
3552 * When a clone is destroyed, its origin may also need to be destroyed,
3553 * in which case it must be unmounted. This routine will do that unmount
3557 zfs_destroy_unmount_origin(const char *fsname
)
3563 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3566 ds
= dmu_objset_ds(os
);
3567 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3568 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3569 dsl_dataset_name(ds
->ds_prev
, originname
);
3570 dmu_objset_rele(os
, FTAG
);
3571 zfs_unmount_snap(originname
);
3573 dmu_objset_rele(os
, FTAG
);
3579 * "snaps" -> { snapshot1, snapshot2 }
3580 * (optional boolean) "defer"
3583 * outnvl: snapshot -> error code (int32)
3587 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3593 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3594 return (SET_ERROR(EINVAL
));
3595 defer
= nvlist_exists(innvl
, "defer");
3597 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3598 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3599 zfs_unmount_snap(nvpair_name(pair
));
3602 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3606 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3607 * All bookmarks must be in the same pool.
3610 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3613 * outnvl: bookmark -> error code (int32)
3618 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3620 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3621 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3625 * Verify the snapshot argument.
3627 if (nvpair_value_string(pair
, &snap_name
) != 0)
3628 return (SET_ERROR(EINVAL
));
3631 /* Verify that the keys (bookmarks) are unique */
3632 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3633 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3634 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3635 return (SET_ERROR(EINVAL
));
3639 return (dsl_bookmark_create(innvl
, outnvl
));
3644 * property 1, property 2, ...
3648 * bookmark name 1 -> { property 1, property 2, ... },
3649 * bookmark name 2 -> { property 1, property 2, ... }
3654 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3656 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3661 * bookmark name 1, bookmark name 2
3664 * outnvl: bookmark -> error code (int32)
3668 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3673 poollen
= strlen(poolname
);
3674 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3675 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3676 const char *name
= nvpair_name(pair
);
3677 const char *cp
= strchr(name
, '#');
3680 * The bookmark name must contain an #, and the part after it
3681 * must contain only valid characters.
3684 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3685 return (SET_ERROR(EINVAL
));
3688 * The bookmark must be in the specified pool.
3690 if (strncmp(name
, poolname
, poollen
) != 0 ||
3691 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3692 return (SET_ERROR(EXDEV
));
3695 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3700 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3704 uint64_t instrlimit
, memlimit
;
3705 boolean_t sync_flag
;
3706 nvpair_t
*nvarg
= NULL
;
3708 if (0 != nvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
, &program
)) {
3711 if (0 != nvlist_lookup_boolean_value(innvl
, ZCP_ARG_SYNC
, &sync_flag
)) {
3714 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3715 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3717 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3718 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3720 if (0 != nvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
, &nvarg
)) {
3724 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3726 if (memlimit
== 0 || memlimit
> zfs_lua_max_memlimit
)
3729 return (zcp_eval(poolname
, program
, sync_flag
, instrlimit
, memlimit
,
3739 zfs_ioc_pool_checkpoint(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3741 return (spa_checkpoint(poolname
));
3750 zfs_ioc_pool_discard_checkpoint(const char *poolname
, nvlist_t
*innvl
,
3753 return (spa_checkpoint_discard(poolname
));
3758 * zc_name name of dataset to destroy
3759 * zc_objset_type type of objset
3760 * zc_defer_destroy mark for deferred destroy
3765 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3769 if (zc
->zc_objset_type
== DMU_OST_ZFS
)
3770 zfs_unmount_snap(zc
->zc_name
);
3772 if (strchr(zc
->zc_name
, '@')) {
3773 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3775 err
= dsl_destroy_head(zc
->zc_name
);
3776 if (err
== EEXIST
) {
3778 * It is possible that the given DS may have
3779 * hidden child (%recv) datasets - "leftovers"
3780 * resulting from the previously interrupted
3783 * 6 extra bytes for /%recv
3785 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3787 if (snprintf(namebuf
, sizeof (namebuf
), "%s/%s",
3788 zc
->zc_name
, recv_clone_name
) >=
3790 return (SET_ERROR(EINVAL
));
3793 * Try to remove the hidden child (%recv) and after
3794 * that try to remove the target dataset.
3795 * If the hidden child (%recv) does not exist
3796 * the original error (EEXIST) will be returned
3798 err
= dsl_destroy_head(namebuf
);
3800 err
= dsl_destroy_head(zc
->zc_name
);
3801 else if (err
== ENOENT
)
3802 err
= SET_ERROR(EEXIST
);
3810 * fsname is name of dataset to rollback (to most recent snapshot)
3812 * innvl may contain name of expected target snapshot
3814 * outnvl: "target" -> name of most recent snapshot
3819 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3823 char *target
= NULL
;
3826 (void) nvlist_lookup_string(innvl
, "target", &target
);
3827 if (target
!= NULL
) {
3828 const char *cp
= strchr(target
, '@');
3831 * The snap name must contain an @, and the part after it must
3832 * contain only valid characters.
3835 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3836 return (SET_ERROR(EINVAL
));
3839 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3842 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3843 error
= zfs_suspend_fs(zfsvfs
);
3847 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3849 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3850 error
= error
? error
: resume_err
;
3852 deactivate_super(zfsvfs
->z_sb
);
3853 } else if ((zv
= zvol_suspend(fsname
)) != NULL
) {
3854 error
= dsl_dataset_rollback(fsname
, target
, zvol_tag(zv
),
3858 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3864 recursive_unmount(const char *fsname
, void *arg
)
3866 const char *snapname
= arg
;
3869 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3870 zfs_unmount_snap(fullname
);
3878 * zc_name old name of dataset
3879 * zc_value new name of dataset
3880 * zc_cookie recursive flag (only valid for snapshots)
3885 zfs_ioc_rename(zfs_cmd_t
*zc
)
3887 boolean_t recursive
= zc
->zc_cookie
& 1;
3890 /* "zfs rename" from and to ...%recv datasets should both fail */
3891 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
3892 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3893 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
3894 dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3895 strchr(zc
->zc_name
, '%') || strchr(zc
->zc_value
, '%'))
3896 return (SET_ERROR(EINVAL
));
3898 at
= strchr(zc
->zc_name
, '@');
3900 /* snaps must be in same fs */
3903 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3904 return (SET_ERROR(EXDEV
));
3906 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3907 error
= dmu_objset_find(zc
->zc_name
,
3908 recursive_unmount
, at
+ 1,
3909 recursive
? DS_FIND_CHILDREN
: 0);
3915 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3916 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3921 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3926 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3928 const char *propname
= nvpair_name(pair
);
3929 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3930 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3934 if (prop
== ZPROP_INVAL
) {
3935 if (zfs_prop_user(propname
)) {
3936 if ((err
= zfs_secpolicy_write_perms(dsname
,
3937 ZFS_DELEG_PERM_USERPROP
, cr
)))
3942 if (!issnap
&& zfs_prop_userquota(propname
)) {
3943 const char *perm
= NULL
;
3944 const char *uq_prefix
=
3945 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3946 const char *gq_prefix
=
3947 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3948 const char *uiq_prefix
=
3949 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
];
3950 const char *giq_prefix
=
3951 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
];
3952 const char *pq_prefix
=
3953 zfs_userquota_prop_prefixes
[ZFS_PROP_PROJECTQUOTA
];
3954 const char *piq_prefix
= zfs_userquota_prop_prefixes
[\
3955 ZFS_PROP_PROJECTOBJQUOTA
];
3957 if (strncmp(propname
, uq_prefix
,
3958 strlen(uq_prefix
)) == 0) {
3959 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3960 } else if (strncmp(propname
, uiq_prefix
,
3961 strlen(uiq_prefix
)) == 0) {
3962 perm
= ZFS_DELEG_PERM_USEROBJQUOTA
;
3963 } else if (strncmp(propname
, gq_prefix
,
3964 strlen(gq_prefix
)) == 0) {
3965 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3966 } else if (strncmp(propname
, giq_prefix
,
3967 strlen(giq_prefix
)) == 0) {
3968 perm
= ZFS_DELEG_PERM_GROUPOBJQUOTA
;
3969 } else if (strncmp(propname
, pq_prefix
,
3970 strlen(pq_prefix
)) == 0) {
3971 perm
= ZFS_DELEG_PERM_PROJECTQUOTA
;
3972 } else if (strncmp(propname
, piq_prefix
,
3973 strlen(piq_prefix
)) == 0) {
3974 perm
= ZFS_DELEG_PERM_PROJECTOBJQUOTA
;
3976 /* {USER|GROUP|PROJECT}USED are read-only */
3977 return (SET_ERROR(EINVAL
));
3980 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3985 return (SET_ERROR(EINVAL
));
3989 return (SET_ERROR(EINVAL
));
3991 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3993 * dsl_prop_get_all_impl() returns properties in this
3997 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3998 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4003 * Check that this value is valid for this pool version
4006 case ZFS_PROP_COMPRESSION
:
4008 * If the user specified gzip compression, make sure
4009 * the SPA supports it. We ignore any errors here since
4010 * we'll catch them later.
4012 if (nvpair_value_uint64(pair
, &intval
) == 0) {
4013 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
4014 intval
<= ZIO_COMPRESS_GZIP_9
&&
4015 zfs_earlier_version(dsname
,
4016 SPA_VERSION_GZIP_COMPRESSION
)) {
4017 return (SET_ERROR(ENOTSUP
));
4020 if (intval
== ZIO_COMPRESS_ZLE
&&
4021 zfs_earlier_version(dsname
,
4022 SPA_VERSION_ZLE_COMPRESSION
))
4023 return (SET_ERROR(ENOTSUP
));
4025 if (intval
== ZIO_COMPRESS_LZ4
) {
4028 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4031 if (!spa_feature_is_enabled(spa
,
4032 SPA_FEATURE_LZ4_COMPRESS
)) {
4033 spa_close(spa
, FTAG
);
4034 return (SET_ERROR(ENOTSUP
));
4036 spa_close(spa
, FTAG
);
4040 * If this is a bootable dataset then
4041 * verify that the compression algorithm
4042 * is supported for booting. We must return
4043 * something other than ENOTSUP since it
4044 * implies a downrev pool version.
4046 if (zfs_is_bootfs(dsname
) &&
4047 !BOOTFS_COMPRESS_VALID(intval
)) {
4048 return (SET_ERROR(ERANGE
));
4053 case ZFS_PROP_COPIES
:
4054 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
4055 return (SET_ERROR(ENOTSUP
));
4058 case ZFS_PROP_VOLBLOCKSIZE
:
4059 case ZFS_PROP_RECORDSIZE
:
4060 /* Record sizes above 128k need the feature to be enabled */
4061 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4062 intval
> SPA_OLD_MAXBLOCKSIZE
) {
4066 * We don't allow setting the property above 1MB,
4067 * unless the tunable has been changed.
4069 if (intval
> zfs_max_recordsize
||
4070 intval
> SPA_MAXBLOCKSIZE
)
4071 return (SET_ERROR(ERANGE
));
4073 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4076 if (!spa_feature_is_enabled(spa
,
4077 SPA_FEATURE_LARGE_BLOCKS
)) {
4078 spa_close(spa
, FTAG
);
4079 return (SET_ERROR(ENOTSUP
));
4081 spa_close(spa
, FTAG
);
4085 case ZFS_PROP_DNODESIZE
:
4086 /* Dnode sizes above 512 need the feature to be enabled */
4087 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4088 intval
!= ZFS_DNSIZE_LEGACY
) {
4092 * If this is a bootable dataset then
4093 * we don't allow large (>512B) dnodes,
4094 * because GRUB doesn't support them.
4096 if (zfs_is_bootfs(dsname
) &&
4097 intval
!= ZFS_DNSIZE_LEGACY
) {
4098 return (SET_ERROR(EDOM
));
4101 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4104 if (!spa_feature_is_enabled(spa
,
4105 SPA_FEATURE_LARGE_DNODE
)) {
4106 spa_close(spa
, FTAG
);
4107 return (SET_ERROR(ENOTSUP
));
4109 spa_close(spa
, FTAG
);
4113 case ZFS_PROP_SHARESMB
:
4114 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
4115 return (SET_ERROR(ENOTSUP
));
4118 case ZFS_PROP_ACLINHERIT
:
4119 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4120 nvpair_value_uint64(pair
, &intval
) == 0) {
4121 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
4122 zfs_earlier_version(dsname
,
4123 SPA_VERSION_PASSTHROUGH_X
))
4124 return (SET_ERROR(ENOTSUP
));
4127 case ZFS_PROP_CHECKSUM
:
4128 case ZFS_PROP_DEDUP
:
4130 spa_feature_t feature
;
4135 /* dedup feature version checks */
4136 if (prop
== ZFS_PROP_DEDUP
&&
4137 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
4138 return (SET_ERROR(ENOTSUP
));
4140 if (nvpair_value_uint64(pair
, &intval
) != 0)
4141 return (SET_ERROR(EINVAL
));
4143 /* check prop value is enabled in features */
4144 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
4145 if (feature
== SPA_FEATURE_NONE
)
4148 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4151 * Salted checksums are not supported on root pools.
4153 if (spa_bootfs(spa
) != 0 &&
4154 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
4155 (zio_checksum_table
[intval
].ci_flags
&
4156 ZCHECKSUM_FLAG_SALTED
)) {
4157 spa_close(spa
, FTAG
);
4158 return (SET_ERROR(ERANGE
));
4160 if (!spa_feature_is_enabled(spa
, feature
)) {
4161 spa_close(spa
, FTAG
);
4162 return (SET_ERROR(ENOTSUP
));
4164 spa_close(spa
, FTAG
);
4172 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
4176 * Removes properties from the given props list that fail permission checks
4177 * needed to clear them and to restore them in case of a receive error. For each
4178 * property, make sure we have both set and inherit permissions.
4180 * Returns the first error encountered if any permission checks fail. If the
4181 * caller provides a non-NULL errlist, it also gives the complete list of names
4182 * of all the properties that failed a permission check along with the
4183 * corresponding error numbers. The caller is responsible for freeing the
4186 * If every property checks out successfully, zero is returned and the list
4187 * pointed at by errlist is NULL.
4190 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
4193 nvpair_t
*pair
, *next_pair
;
4200 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4202 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
4203 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
4204 pair
= nvlist_next_nvpair(props
, NULL
);
4205 while (pair
!= NULL
) {
4206 next_pair
= nvlist_next_nvpair(props
, pair
);
4208 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
4209 sizeof (zc
->zc_value
));
4210 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
4211 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
4212 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
4213 VERIFY(nvlist_add_int32(errors
,
4214 zc
->zc_value
, err
) == 0);
4218 kmem_free(zc
, sizeof (zfs_cmd_t
));
4220 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
4221 nvlist_free(errors
);
4224 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
4227 if (errlist
== NULL
)
4228 nvlist_free(errors
);
4236 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4238 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4239 /* dsl_prop_get_all_impl() format */
4241 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4242 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4246 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4248 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4249 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4253 if (nvpair_type(p1
) != nvpair_type(p2
))
4256 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4257 char *valstr1
, *valstr2
;
4259 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4260 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4261 return (strcmp(valstr1
, valstr2
) == 0);
4263 uint64_t intval1
, intval2
;
4265 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4266 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4267 return (intval1
== intval2
);
4272 * Remove properties from props if they are not going to change (as determined
4273 * by comparison with origprops). Remove them from origprops as well, since we
4274 * do not need to clear or restore properties that won't change.
4277 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4279 nvpair_t
*pair
, *next_pair
;
4281 if (origprops
== NULL
)
4282 return; /* all props need to be received */
4284 pair
= nvlist_next_nvpair(props
, NULL
);
4285 while (pair
!= NULL
) {
4286 const char *propname
= nvpair_name(pair
);
4289 next_pair
= nvlist_next_nvpair(props
, pair
);
4291 if ((nvlist_lookup_nvpair(origprops
, propname
,
4292 &match
) != 0) || !propval_equals(pair
, match
))
4293 goto next
; /* need to set received value */
4295 /* don't clear the existing received value */
4296 (void) nvlist_remove_nvpair(origprops
, match
);
4297 /* don't bother receiving the property */
4298 (void) nvlist_remove_nvpair(props
, pair
);
4305 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4306 * For example, refquota cannot be set until after the receipt of a dataset,
4307 * because in replication streams, an older/earlier snapshot may exceed the
4308 * refquota. We want to receive the older/earlier snapshot, but setting
4309 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4310 * the older/earlier snapshot from being received (with EDQUOT).
4312 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4314 * libzfs will need to be judicious handling errors encountered by props
4315 * extracted by this function.
4318 extract_delay_props(nvlist_t
*props
)
4320 nvlist_t
*delayprops
;
4321 nvpair_t
*nvp
, *tmp
;
4322 static const zfs_prop_t delayable
[] = {
4324 ZFS_PROP_KEYLOCATION
,
4329 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4331 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4332 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4334 * strcmp() is safe because zfs_prop_to_name() always returns
4337 for (i
= 0; delayable
[i
] != 0; i
++) {
4338 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4339 nvpair_name(nvp
)) == 0) {
4343 if (delayable
[i
] != 0) {
4344 tmp
= nvlist_prev_nvpair(props
, nvp
);
4345 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4346 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4351 if (nvlist_empty(delayprops
)) {
4352 nvlist_free(delayprops
);
4355 return (delayprops
);
4359 static boolean_t zfs_ioc_recv_inject_err
;
4363 * nvlist 'errors' is always allocated. It will contain descriptions of
4364 * encountered errors, if any. It's the callers responsibility to free.
4367 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
, nvlist_t
*recvprops
,
4368 nvlist_t
*localprops
, boolean_t force
, boolean_t resumable
, int input_fd
,
4369 dmu_replay_record_t
*begin_record
, int cleanup_fd
, uint64_t *read_bytes
,
4370 uint64_t *errflags
, uint64_t *action_handle
, nvlist_t
**errors
)
4372 dmu_recv_cookie_t drc
;
4374 int props_error
= 0;
4376 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4377 nvlist_t
*origprops
= NULL
; /* existing properties */
4378 nvlist_t
*origrecvd
= NULL
; /* existing received properties */
4379 boolean_t first_recvd_props
= B_FALSE
;
4384 *errors
= fnvlist_alloc();
4386 input_fp
= getf(input_fd
);
4387 if (input_fp
== NULL
)
4388 return (SET_ERROR(EBADF
));
4390 error
= dmu_recv_begin(tofs
, tosnap
,
4391 begin_record
, force
, resumable
, origin
, &drc
);
4396 * Set properties before we receive the stream so that they are applied
4397 * to the new data. Note that we must call dmu_recv_stream() if
4398 * dmu_recv_begin() succeeds.
4400 if (recvprops
!= NULL
&& !drc
.drc_newfs
) {
4401 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4402 SPA_VERSION_RECVD_PROPS
&&
4403 !dsl_prop_get_hasrecvd(tofs
))
4404 first_recvd_props
= B_TRUE
;
4407 * If new received properties are supplied, they are to
4408 * completely replace the existing received properties, so stash
4409 * away the existing ones.
4411 if (dsl_prop_get_received(tofs
, &origrecvd
) == 0) {
4412 nvlist_t
*errlist
= NULL
;
4414 * Don't bother writing a property if its value won't
4415 * change (and avoid the unnecessary security checks).
4417 * The first receive after SPA_VERSION_RECVD_PROPS is a
4418 * special case where we blow away all local properties
4421 if (!first_recvd_props
)
4422 props_reduce(recvprops
, origrecvd
);
4423 if (zfs_check_clearable(tofs
, origrecvd
, &errlist
) != 0)
4424 (void) nvlist_merge(*errors
, errlist
, 0);
4425 nvlist_free(errlist
);
4427 if (clear_received_props(tofs
, origrecvd
,
4428 first_recvd_props
? NULL
: recvprops
) != 0)
4429 *errflags
|= ZPROP_ERR_NOCLEAR
;
4431 *errflags
|= ZPROP_ERR_NOCLEAR
;
4436 * Stash away existing properties so we can restore them on error unless
4437 * we're doing the first receive after SPA_VERSION_RECVD_PROPS, in which
4438 * case "origrecvd" will take care of that.
4440 if (localprops
!= NULL
&& !drc
.drc_newfs
&& !first_recvd_props
) {
4442 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
4443 if (dsl_prop_get_all(os
, &origprops
) != 0) {
4444 *errflags
|= ZPROP_ERR_NOCLEAR
;
4446 dmu_objset_rele(os
, FTAG
);
4448 *errflags
|= ZPROP_ERR_NOCLEAR
;
4452 if (recvprops
!= NULL
) {
4453 props_error
= dsl_prop_set_hasrecvd(tofs
);
4455 if (props_error
== 0) {
4456 delayprops
= extract_delay_props(recvprops
);
4457 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4458 recvprops
, *errors
);
4462 if (localprops
!= NULL
) {
4463 nvlist_t
*oprops
= fnvlist_alloc();
4464 nvlist_t
*xprops
= fnvlist_alloc();
4465 nvpair_t
*nvp
= NULL
;
4467 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4468 if (nvpair_type(nvp
) == DATA_TYPE_BOOLEAN
) {
4470 const char *name
= nvpair_name(nvp
);
4471 zfs_prop_t prop
= zfs_name_to_prop(name
);
4472 if (prop
!= ZPROP_INVAL
) {
4473 if (!zfs_prop_inheritable(prop
))
4475 } else if (!zfs_prop_user(name
))
4477 fnvlist_add_boolean(xprops
, name
);
4479 /* -o property=value */
4480 fnvlist_add_nvpair(oprops
, nvp
);
4483 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4485 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
,
4488 nvlist_free(oprops
);
4489 nvlist_free(xprops
);
4492 off
= input_fp
->f_offset
;
4493 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4497 zfsvfs_t
*zfsvfs
= NULL
;
4498 zvol_state_t
*zv
= NULL
;
4500 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4505 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4506 error
= zfs_suspend_fs(zfsvfs
);
4508 * If the suspend fails, then the recv_end will
4509 * likely also fail, and clean up after itself.
4511 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4513 error
= zfs_resume_fs(zfsvfs
, ds
);
4514 error
= error
? error
: end_err
;
4515 deactivate_super(zfsvfs
->z_sb
);
4516 } else if ((zv
= zvol_suspend(tofs
)) != NULL
) {
4517 error
= dmu_recv_end(&drc
, zvol_tag(zv
));
4520 error
= dmu_recv_end(&drc
, NULL
);
4523 /* Set delayed properties now, after we're done receiving. */
4524 if (delayprops
!= NULL
&& error
== 0) {
4525 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4526 delayprops
, *errors
);
4530 if (delayprops
!= NULL
) {
4532 * Merge delayed props back in with initial props, in case
4533 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4534 * we have to make sure clear_received_props() includes
4535 * the delayed properties).
4537 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4538 * using ASSERT() will be just like a VERIFY.
4540 ASSERT(nvlist_merge(recvprops
, delayprops
, 0) == 0);
4541 nvlist_free(delayprops
);
4545 *read_bytes
= off
- input_fp
->f_offset
;
4546 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4547 input_fp
->f_offset
= off
;
4550 if (zfs_ioc_recv_inject_err
) {
4551 zfs_ioc_recv_inject_err
= B_FALSE
;
4557 * On error, restore the original props.
4559 if (error
!= 0 && recvprops
!= NULL
&& !drc
.drc_newfs
) {
4560 if (clear_received_props(tofs
, recvprops
, NULL
) != 0) {
4562 * We failed to clear the received properties.
4563 * Since we may have left a $recvd value on the
4564 * system, we can't clear the $hasrecvd flag.
4566 *errflags
|= ZPROP_ERR_NORESTORE
;
4567 } else if (first_recvd_props
) {
4568 dsl_prop_unset_hasrecvd(tofs
);
4571 if (origrecvd
== NULL
&& !drc
.drc_newfs
) {
4572 /* We failed to stash the original properties. */
4573 *errflags
|= ZPROP_ERR_NORESTORE
;
4577 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4578 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4579 * explicitly if we're restoring local properties cleared in the
4580 * first new-style receive.
4582 if (origrecvd
!= NULL
&&
4583 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4584 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4585 origrecvd
, NULL
) != 0) {
4587 * We stashed the original properties but failed to
4590 *errflags
|= ZPROP_ERR_NORESTORE
;
4593 if (error
!= 0 && localprops
!= NULL
&& !drc
.drc_newfs
&&
4594 !first_recvd_props
) {
4596 nvlist_t
*inheritprops
;
4599 if (origprops
== NULL
) {
4600 /* We failed to stash the original properties. */
4601 *errflags
|= ZPROP_ERR_NORESTORE
;
4605 /* Restore original props */
4606 setprops
= fnvlist_alloc();
4607 inheritprops
= fnvlist_alloc();
4609 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4610 const char *name
= nvpair_name(nvp
);
4614 if (!nvlist_exists(origprops
, name
)) {
4616 * Property was not present or was explicitly
4617 * inherited before the receive, restore this.
4619 fnvlist_add_boolean(inheritprops
, name
);
4622 attrs
= fnvlist_lookup_nvlist(origprops
, name
);
4623 source
= fnvlist_lookup_string(attrs
, ZPROP_SOURCE
);
4625 /* Skip received properties */
4626 if (strcmp(source
, ZPROP_SOURCE_VAL_RECVD
) == 0)
4629 if (strcmp(source
, tofs
) == 0) {
4630 /* Property was locally set */
4631 fnvlist_add_nvlist(setprops
, name
, attrs
);
4633 /* Property was implicitly inherited */
4634 fnvlist_add_boolean(inheritprops
, name
);
4638 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
, setprops
,
4640 *errflags
|= ZPROP_ERR_NORESTORE
;
4641 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
, inheritprops
,
4643 *errflags
|= ZPROP_ERR_NORESTORE
;
4645 nvlist_free(setprops
);
4646 nvlist_free(inheritprops
);
4650 nvlist_free(origrecvd
);
4651 nvlist_free(origprops
);
4654 error
= props_error
;
4661 * zc_name name of containing filesystem (unused)
4662 * zc_nvlist_src{_size} nvlist of properties to apply
4663 * zc_nvlist_conf{_size} nvlist of properties to exclude
4664 * (DATA_TYPE_BOOLEAN) and override (everything else)
4665 * zc_value name of snapshot to create
4666 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4667 * zc_cookie file descriptor to recv from
4668 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4669 * zc_guid force flag
4670 * zc_cleanup_fd cleanup-on-exit file descriptor
4671 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4674 * zc_cookie number of bytes read
4675 * zc_obj zprop_errflags_t
4676 * zc_action_handle handle for this guid/ds mapping
4677 * zc_nvlist_dst{_size} error for each unapplied received property
4680 zfs_ioc_recv(zfs_cmd_t
*zc
)
4682 dmu_replay_record_t begin_record
;
4683 nvlist_t
*errors
= NULL
;
4684 nvlist_t
*recvdprops
= NULL
;
4685 nvlist_t
*localprops
= NULL
;
4686 char *origin
= NULL
;
4688 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4691 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4692 strchr(zc
->zc_value
, '@') == NULL
||
4693 strchr(zc
->zc_value
, '%'))
4694 return (SET_ERROR(EINVAL
));
4696 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4697 tosnap
= strchr(tofs
, '@');
4700 if (zc
->zc_nvlist_src
!= 0 &&
4701 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4702 zc
->zc_iflags
, &recvdprops
)) != 0)
4705 if (zc
->zc_nvlist_conf
!= 0 &&
4706 (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
4707 zc
->zc_iflags
, &localprops
)) != 0)
4710 if (zc
->zc_string
[0])
4711 origin
= zc
->zc_string
;
4713 begin_record
.drr_type
= DRR_BEGIN
;
4714 begin_record
.drr_payloadlen
= 0;
4715 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4717 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvdprops
, localprops
,
4718 zc
->zc_guid
, B_FALSE
, zc
->zc_cookie
, &begin_record
,
4719 zc
->zc_cleanup_fd
, &zc
->zc_cookie
, &zc
->zc_obj
,
4720 &zc
->zc_action_handle
, &errors
);
4721 nvlist_free(recvdprops
);
4722 nvlist_free(localprops
);
4725 * Now that all props, initial and delayed, are set, report the prop
4726 * errors to the caller.
4728 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4729 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4730 put_nvlist(zc
, errors
) != 0)) {
4732 * Caller made zc->zc_nvlist_dst less than the minimum expected
4733 * size or supplied an invalid address.
4735 error
= SET_ERROR(EINVAL
);
4738 nvlist_free(errors
);
4745 * "snapname" -> full name of the snapshot to create
4746 * (optional) "props" -> received properties to set (nvlist)
4747 * (optional) "localprops" -> override and exclude properties (nvlist)
4748 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
4749 * "begin_record" -> non-byteswapped dmu_replay_record_t
4750 * "input_fd" -> file descriptor to read stream from (int32)
4751 * (optional) "force" -> force flag (value ignored)
4752 * (optional) "resumable" -> resumable flag (value ignored)
4753 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
4754 * (optional) "action_handle" -> handle for this guid/ds mapping
4758 * "read_bytes" -> number of bytes read
4759 * "error_flags" -> zprop_errflags_t
4760 * "action_handle" -> handle for this guid/ds mapping
4761 * "errors" -> error for each unapplied received property (nvlist)
4765 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4767 dmu_replay_record_t
*begin_record
;
4768 uint_t begin_record_size
;
4769 nvlist_t
*errors
= NULL
;
4770 nvlist_t
*recvprops
= NULL
;
4771 nvlist_t
*localprops
= NULL
;
4772 char *snapname
= NULL
;
4773 char *origin
= NULL
;
4775 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4777 boolean_t resumable
;
4778 uint64_t action_handle
= 0;
4779 uint64_t read_bytes
= 0;
4780 uint64_t errflags
= 0;
4782 int cleanup_fd
= -1;
4785 error
= nvlist_lookup_string(innvl
, "snapname", &snapname
);
4787 return (SET_ERROR(EINVAL
));
4789 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
4790 strchr(snapname
, '@') == NULL
||
4791 strchr(snapname
, '%'))
4792 return (SET_ERROR(EINVAL
));
4794 (void) strcpy(tofs
, snapname
);
4795 tosnap
= strchr(tofs
, '@');
4798 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
4799 if (error
&& error
!= ENOENT
)
4802 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
4803 (uchar_t
**)&begin_record
, &begin_record_size
);
4804 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
4805 return (SET_ERROR(EINVAL
));
4807 error
= nvlist_lookup_int32(innvl
, "input_fd", &input_fd
);
4809 return (SET_ERROR(EINVAL
));
4811 force
= nvlist_exists(innvl
, "force");
4812 resumable
= nvlist_exists(innvl
, "resumable");
4814 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
4815 if (error
&& error
!= ENOENT
)
4818 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
4819 if (error
&& error
!= ENOENT
)
4822 /* we still use "props" here for backwards compatibility */
4823 error
= nvlist_lookup_nvlist(innvl
, "props", &recvprops
);
4824 if (error
&& error
!= ENOENT
)
4827 error
= nvlist_lookup_nvlist(innvl
, "localprops", &localprops
);
4828 if (error
&& error
!= ENOENT
)
4831 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvprops
, localprops
,
4832 force
, resumable
, input_fd
, begin_record
, cleanup_fd
, &read_bytes
,
4833 &errflags
, &action_handle
, &errors
);
4835 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
4836 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
4837 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
4838 fnvlist_add_nvlist(outnvl
, "errors", errors
);
4840 nvlist_free(errors
);
4841 nvlist_free(recvprops
);
4842 nvlist_free(localprops
);
4849 * zc_name name of snapshot to send
4850 * zc_cookie file descriptor to send stream to
4851 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4852 * zc_sendobj objsetid of snapshot to send
4853 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4854 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4855 * output size in zc_objset_type.
4856 * zc_flags lzc_send_flags
4859 * zc_objset_type estimated size, if zc_guid is set
4861 * NOTE: This is no longer the preferred interface, any new functionality
4862 * should be added to zfs_ioc_send_new() instead.
4865 zfs_ioc_send(zfs_cmd_t
*zc
)
4869 boolean_t estimate
= (zc
->zc_guid
!= 0);
4870 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4871 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4872 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4873 boolean_t rawok
= (zc
->zc_flags
& 0x8);
4875 if (zc
->zc_obj
!= 0) {
4877 dsl_dataset_t
*tosnap
;
4879 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4883 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4885 dsl_pool_rele(dp
, FTAG
);
4889 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4891 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4892 dsl_dataset_rele(tosnap
, FTAG
);
4893 dsl_pool_rele(dp
, FTAG
);
4898 dsl_dataset_t
*tosnap
;
4899 dsl_dataset_t
*fromsnap
= NULL
;
4901 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4905 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
,
4908 dsl_pool_rele(dp
, FTAG
);
4912 if (zc
->zc_fromobj
!= 0) {
4913 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4916 dsl_dataset_rele(tosnap
, FTAG
);
4917 dsl_pool_rele(dp
, FTAG
);
4922 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
|| rawok
,
4923 &zc
->zc_objset_type
);
4925 if (fromsnap
!= NULL
)
4926 dsl_dataset_rele(fromsnap
, FTAG
);
4927 dsl_dataset_rele(tosnap
, FTAG
);
4928 dsl_pool_rele(dp
, FTAG
);
4930 file_t
*fp
= getf(zc
->zc_cookie
);
4932 return (SET_ERROR(EBADF
));
4935 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4936 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
, rawok
,
4937 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4939 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4941 releasef(zc
->zc_cookie
);
4948 * zc_name name of snapshot on which to report progress
4949 * zc_cookie file descriptor of send stream
4952 * zc_cookie number of bytes written in send stream thus far
4955 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4959 dmu_sendarg_t
*dsp
= NULL
;
4962 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4966 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4968 dsl_pool_rele(dp
, FTAG
);
4972 mutex_enter(&ds
->ds_sendstream_lock
);
4975 * Iterate over all the send streams currently active on this dataset.
4976 * If there's one which matches the specified file descriptor _and_ the
4977 * stream was started by the current process, return the progress of
4981 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4982 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4983 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4984 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4989 zc
->zc_cookie
= *(dsp
->dsa_off
);
4991 error
= SET_ERROR(ENOENT
);
4993 mutex_exit(&ds
->ds_sendstream_lock
);
4994 dsl_dataset_rele(ds
, FTAG
);
4995 dsl_pool_rele(dp
, FTAG
);
5000 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
5004 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
5005 &zc
->zc_inject_record
);
5008 zc
->zc_guid
= (uint64_t)id
;
5014 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
5016 return (zio_clear_fault((int)zc
->zc_guid
));
5020 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
5022 int id
= (int)zc
->zc_guid
;
5025 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
5026 &zc
->zc_inject_record
);
5034 zfs_ioc_error_log(zfs_cmd_t
*zc
)
5038 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
5040 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
5043 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5046 zc
->zc_nvlist_dst_size
= count
;
5048 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
5050 spa_close(spa
, FTAG
);
5056 zfs_ioc_clear(zfs_cmd_t
*zc
)
5063 * On zpool clear we also fix up missing slogs
5065 mutex_enter(&spa_namespace_lock
);
5066 spa
= spa_lookup(zc
->zc_name
);
5068 mutex_exit(&spa_namespace_lock
);
5069 return (SET_ERROR(EIO
));
5071 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
5072 /* we need to let spa_open/spa_load clear the chains */
5073 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
5075 spa
->spa_last_open_failed
= 0;
5076 mutex_exit(&spa_namespace_lock
);
5078 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
5079 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
5082 nvlist_t
*config
= NULL
;
5084 if (zc
->zc_nvlist_src
== 0)
5085 return (SET_ERROR(EINVAL
));
5087 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5088 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
5089 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
5091 if (config
!= NULL
) {
5094 if ((err
= put_nvlist(zc
, config
)) != 0)
5096 nvlist_free(config
);
5098 nvlist_free(policy
);
5105 spa_vdev_state_enter(spa
, SCL_NONE
);
5107 if (zc
->zc_guid
== 0) {
5110 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
5112 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
5113 spa_close(spa
, FTAG
);
5114 return (SET_ERROR(ENODEV
));
5118 vdev_clear(spa
, vd
);
5120 (void) spa_vdev_state_exit(spa
, spa_suspended(spa
) ?
5121 NULL
: spa
->spa_root_vdev
, 0);
5124 * Resume any suspended I/Os.
5126 if (zio_resume(spa
) != 0)
5127 error
= SET_ERROR(EIO
);
5129 spa_close(spa
, FTAG
);
5135 * Reopen all the vdevs associated with the pool.
5138 * "scrub_restart" -> when true and scrub is running, allow to restart
5139 * scrub as the side effect of the reopen (boolean).
5146 zfs_ioc_pool_reopen(const char *pool
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5150 boolean_t scrub_restart
= B_TRUE
;
5153 if (nvlist_lookup_boolean_value(innvl
, "scrub_restart",
5154 &scrub_restart
) != 0) {
5155 return (SET_ERROR(EINVAL
));
5159 error
= spa_open(pool
, &spa
, FTAG
);
5163 spa_vdev_state_enter(spa
, SCL_NONE
);
5166 * If the scrub_restart flag is B_FALSE and a scrub is already
5167 * in progress then set spa_scrub_reopen flag to B_TRUE so that
5168 * we don't restart the scrub as a side effect of the reopen.
5169 * Otherwise, let vdev_open() decided if a resilver is required.
5172 spa
->spa_scrub_reopen
= (!scrub_restart
&&
5173 dsl_scan_scrubbing(spa
->spa_dsl_pool
));
5174 vdev_reopen(spa
->spa_root_vdev
);
5175 spa
->spa_scrub_reopen
= B_FALSE
;
5177 (void) spa_vdev_state_exit(spa
, NULL
, 0);
5178 spa_close(spa
, FTAG
);
5184 * zc_name name of filesystem
5187 * zc_string name of conflicting snapshot, if there is one
5190 zfs_ioc_promote(zfs_cmd_t
*zc
)
5193 dsl_dataset_t
*ds
, *ods
;
5194 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
5198 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5199 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
5200 strchr(zc
->zc_name
, '%'))
5201 return (SET_ERROR(EINVAL
));
5203 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5207 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5209 dsl_pool_rele(dp
, FTAG
);
5213 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
5214 dsl_dataset_rele(ds
, FTAG
);
5215 dsl_pool_rele(dp
, FTAG
);
5216 return (SET_ERROR(EINVAL
));
5219 error
= dsl_dataset_hold_obj(dp
,
5220 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
5222 dsl_dataset_rele(ds
, FTAG
);
5223 dsl_pool_rele(dp
, FTAG
);
5227 dsl_dataset_name(ods
, origin
);
5228 dsl_dataset_rele(ods
, FTAG
);
5229 dsl_dataset_rele(ds
, FTAG
);
5230 dsl_pool_rele(dp
, FTAG
);
5233 * We don't need to unmount *all* the origin fs's snapshots, but
5236 cp
= strchr(origin
, '@');
5239 (void) dmu_objset_find(origin
,
5240 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
5241 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
5245 * Retrieve a single {user|group|project}{used|quota}@... property.
5248 * zc_name name of filesystem
5249 * zc_objset_type zfs_userquota_prop_t
5250 * zc_value domain name (eg. "S-1-234-567-89")
5251 * zc_guid RID/UID/GID
5254 * zc_cookie property value
5257 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
5262 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
5263 return (SET_ERROR(EINVAL
));
5265 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5269 error
= zfs_userspace_one(zfsvfs
,
5270 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
5271 zfsvfs_rele(zfsvfs
, FTAG
);
5278 * zc_name name of filesystem
5279 * zc_cookie zap cursor
5280 * zc_objset_type zfs_userquota_prop_t
5281 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
5284 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
5285 * zc_cookie zap cursor
5288 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
5291 int bufsize
= zc
->zc_nvlist_dst_size
;
5294 return (SET_ERROR(ENOMEM
));
5296 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5300 void *buf
= vmem_alloc(bufsize
, KM_SLEEP
);
5302 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
5303 buf
, &zc
->zc_nvlist_dst_size
);
5306 error
= xcopyout(buf
,
5307 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5308 zc
->zc_nvlist_dst_size
);
5310 vmem_free(buf
, bufsize
);
5311 zfsvfs_rele(zfsvfs
, FTAG
);
5318 * zc_name name of filesystem
5324 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
5330 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
5331 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
5333 * If userused is not enabled, it may be because the
5334 * objset needs to be closed & reopened (to grow the
5335 * objset_phys_t). Suspend/resume the fs will do that.
5337 dsl_dataset_t
*ds
, *newds
;
5339 ds
= dmu_objset_ds(zfsvfs
->z_os
);
5340 error
= zfs_suspend_fs(zfsvfs
);
5342 dmu_objset_refresh_ownership(ds
, &newds
,
5344 error
= zfs_resume_fs(zfsvfs
, newds
);
5348 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
5349 deactivate_super(zfsvfs
->z_sb
);
5351 /* XXX kind of reading contents without owning */
5352 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5356 error
= dmu_objset_userspace_upgrade(os
);
5357 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
5365 * zc_name name of filesystem
5371 zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
)
5376 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5380 if (dmu_objset_userobjspace_upgradable(os
) ||
5381 dmu_objset_projectquota_upgradable(os
)) {
5382 mutex_enter(&os
->os_upgrade_lock
);
5383 if (os
->os_upgrade_id
== 0) {
5384 /* clear potential error code and retry */
5385 os
->os_upgrade_status
= 0;
5386 mutex_exit(&os
->os_upgrade_lock
);
5388 dmu_objset_id_quota_upgrade(os
);
5390 mutex_exit(&os
->os_upgrade_lock
);
5393 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5395 taskq_wait_id(os
->os_spa
->spa_upgrade_taskq
, os
->os_upgrade_id
);
5396 error
= os
->os_upgrade_status
;
5398 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5401 dsl_dataset_rele_flags(dmu_objset_ds(os
), DS_HOLD_FLAG_DECRYPT
, FTAG
);
5407 zfs_ioc_share(zfs_cmd_t
*zc
)
5409 return (SET_ERROR(ENOSYS
));
5412 ace_t full_access
[] = {
5413 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
5418 * zc_name name of containing filesystem
5419 * zc_obj object # beyond which we want next in-use object #
5422 * zc_obj next in-use object #
5425 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
5427 objset_t
*os
= NULL
;
5430 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
5434 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
5436 dmu_objset_rele(os
, FTAG
);
5442 * zc_name name of filesystem
5443 * zc_value prefix name for snapshot
5444 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5447 * zc_value short name of new snapshot
5450 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5457 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5461 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5462 (u_longlong_t
)ddi_get_lbolt64());
5463 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5465 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5468 (void) strlcpy(zc
->zc_value
, snap_name
,
5469 sizeof (zc
->zc_value
));
5472 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5478 * zc_name name of "to" snapshot
5479 * zc_value name of "from" snapshot
5480 * zc_cookie file descriptor to write diff data on
5483 * dmu_diff_record_t's to the file descriptor
5486 zfs_ioc_diff(zfs_cmd_t
*zc
)
5492 fp
= getf(zc
->zc_cookie
);
5494 return (SET_ERROR(EBADF
));
5498 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5500 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5502 releasef(zc
->zc_cookie
);
5508 * Remove all ACL files in shares dir
5510 #ifdef HAVE_SMB_SHARE
5512 zfs_smb_acl_purge(znode_t
*dzp
)
5515 zap_attribute_t zap
;
5516 zfsvfs_t
*zfsvfs
= ZTOZSB(dzp
);
5519 for (zap_cursor_init(&zc
, zfsvfs
->z_os
, dzp
->z_id
);
5520 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5521 zap_cursor_advance(&zc
)) {
5522 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
5526 zap_cursor_fini(&zc
);
5529 #endif /* HAVE_SMB_SHARE */
5532 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5534 #ifdef HAVE_SMB_SHARE
5537 vnode_t
*resourcevp
= NULL
;
5546 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5547 NO_FOLLOW
, NULL
, &vp
)) != 0)
5550 /* Now make sure mntpnt and dataset are ZFS */
5552 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5553 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5554 zc
->zc_name
) != 0)) {
5556 return (SET_ERROR(EINVAL
));
5560 zfsvfs
= ZTOZSB(dzp
);
5564 * Create share dir if its missing.
5566 mutex_enter(&zfsvfs
->z_lock
);
5567 if (zfsvfs
->z_shares_dir
== 0) {
5570 tx
= dmu_tx_create(zfsvfs
->z_os
);
5571 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5573 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5574 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5578 error
= zfs_create_share_dir(zfsvfs
, tx
);
5582 mutex_exit(&zfsvfs
->z_lock
);
5588 mutex_exit(&zfsvfs
->z_lock
);
5590 ASSERT(zfsvfs
->z_shares_dir
);
5591 if ((error
= zfs_zget(zfsvfs
, zfsvfs
->z_shares_dir
, &sharedir
)) != 0) {
5597 switch (zc
->zc_cookie
) {
5598 case ZFS_SMB_ACL_ADD
:
5599 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5600 vattr
.va_mode
= S_IFREG
|0777;
5604 vsec
.vsa_mask
= VSA_ACE
;
5605 vsec
.vsa_aclentp
= &full_access
;
5606 vsec
.vsa_aclentsz
= sizeof (full_access
);
5607 vsec
.vsa_aclcnt
= 1;
5609 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
5610 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5612 VN_RELE(resourcevp
);
5615 case ZFS_SMB_ACL_REMOVE
:
5616 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5620 case ZFS_SMB_ACL_RENAME
:
5621 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5622 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5624 VN_RELE(ZTOV(sharedir
));
5628 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5629 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5632 VN_RELE(ZTOV(sharedir
));
5634 nvlist_free(nvlist
);
5637 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5639 nvlist_free(nvlist
);
5642 case ZFS_SMB_ACL_PURGE
:
5643 error
= zfs_smb_acl_purge(sharedir
);
5647 error
= SET_ERROR(EINVAL
);
5652 VN_RELE(ZTOV(sharedir
));
5658 return (SET_ERROR(ENOTSUP
));
5659 #endif /* HAVE_SMB_SHARE */
5664 * "holds" -> { snapname -> holdname (string), ... }
5665 * (optional) "cleanup_fd" -> fd (int32)
5669 * snapname -> error value (int32)
5675 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5679 int cleanup_fd
= -1;
5683 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5685 return (SET_ERROR(EINVAL
));
5687 /* make sure the user didn't pass us any invalid (empty) tags */
5688 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5689 pair
= nvlist_next_nvpair(holds
, pair
)) {
5692 error
= nvpair_value_string(pair
, &htag
);
5694 return (SET_ERROR(error
));
5696 if (strlen(htag
) == 0)
5697 return (SET_ERROR(EINVAL
));
5700 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5701 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5706 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5708 zfs_onexit_fd_rele(cleanup_fd
);
5713 * innvl is not used.
5716 * holdname -> time added (uint64 seconds since epoch)
5722 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5724 ASSERT3P(args
, ==, NULL
);
5725 return (dsl_dataset_get_holds(snapname
, outnvl
));
5730 * snapname -> { holdname, ... }
5735 * snapname -> error value (int32)
5741 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5743 return (dsl_dataset_user_release(holds
, errlist
));
5748 * zc_guid flags (ZEVENT_NONBLOCK)
5749 * zc_cleanup_fd zevent file descriptor
5752 * zc_nvlist_dst next nvlist event
5753 * zc_cookie dropped events since last get
5756 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5759 nvlist_t
*event
= NULL
;
5761 uint64_t dropped
= 0;
5764 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5769 error
= zfs_zevent_next(ze
, &event
,
5770 &zc
->zc_nvlist_dst_size
, &dropped
);
5771 if (event
!= NULL
) {
5772 zc
->zc_cookie
= dropped
;
5773 error
= put_nvlist(zc
, event
);
5777 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5780 if ((error
== 0) || (error
!= ENOENT
))
5783 error
= zfs_zevent_wait(ze
);
5788 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5795 * zc_cookie cleared events count
5798 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5802 zfs_zevent_drain_all(&count
);
5803 zc
->zc_cookie
= count
;
5810 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5811 * zc_cleanup zevent file descriptor
5814 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5820 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5824 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5825 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5832 * zc_name name of new filesystem or snapshot
5833 * zc_value full name of old snapshot
5836 * zc_cookie space in bytes
5837 * zc_objset_type compressed space in bytes
5838 * zc_perm_action uncompressed space in bytes
5841 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5845 dsl_dataset_t
*new, *old
;
5847 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5850 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5852 dsl_pool_rele(dp
, FTAG
);
5855 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5857 dsl_dataset_rele(new, FTAG
);
5858 dsl_pool_rele(dp
, FTAG
);
5862 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5863 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5864 dsl_dataset_rele(old
, FTAG
);
5865 dsl_dataset_rele(new, FTAG
);
5866 dsl_pool_rele(dp
, FTAG
);
5872 * "firstsnap" -> snapshot name
5876 * "used" -> space in bytes
5877 * "compressed" -> compressed space in bytes
5878 * "uncompressed" -> uncompressed space in bytes
5882 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5886 dsl_dataset_t
*new, *old
;
5888 uint64_t used
, comp
, uncomp
;
5890 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5891 return (SET_ERROR(EINVAL
));
5893 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5897 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5898 if (error
== 0 && !new->ds_is_snapshot
) {
5899 dsl_dataset_rele(new, FTAG
);
5900 error
= SET_ERROR(EINVAL
);
5903 dsl_pool_rele(dp
, FTAG
);
5906 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5907 if (error
== 0 && !old
->ds_is_snapshot
) {
5908 dsl_dataset_rele(old
, FTAG
);
5909 error
= SET_ERROR(EINVAL
);
5912 dsl_dataset_rele(new, FTAG
);
5913 dsl_pool_rele(dp
, FTAG
);
5917 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5918 dsl_dataset_rele(old
, FTAG
);
5919 dsl_dataset_rele(new, FTAG
);
5920 dsl_pool_rele(dp
, FTAG
);
5921 fnvlist_add_uint64(outnvl
, "used", used
);
5922 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5923 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5929 * "fd" -> file descriptor to write stream to (int32)
5930 * (optional) "fromsnap" -> full snap name to send an incremental from
5931 * (optional) "largeblockok" -> (value ignored)
5932 * indicates that blocks > 128KB are permitted
5933 * (optional) "embedok" -> (value ignored)
5934 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5935 * (optional) "compressok" -> (value ignored)
5936 * presence indicates compressed DRR_WRITE records are permitted
5937 * (optional) "rawok" -> (value ignored)
5938 * presence indicates raw encrypted records should be used.
5939 * (optional) "resume_object" and "resume_offset" -> (uint64)
5940 * if present, resume send stream from specified object and offset.
5947 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5951 char *fromname
= NULL
;
5954 boolean_t largeblockok
;
5956 boolean_t compressok
;
5958 uint64_t resumeobj
= 0;
5959 uint64_t resumeoff
= 0;
5961 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5963 return (SET_ERROR(EINVAL
));
5965 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5967 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5968 embedok
= nvlist_exists(innvl
, "embedok");
5969 compressok
= nvlist_exists(innvl
, "compressok");
5970 rawok
= nvlist_exists(innvl
, "rawok");
5972 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5973 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5975 if ((fp
= getf(fd
)) == NULL
)
5976 return (SET_ERROR(EBADF
));
5979 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5980 rawok
, fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5982 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5990 * Determine approximately how large a zfs send stream will be -- the number
5991 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5994 * (optional) "from" -> full snap or bookmark name to send an incremental
5996 * (optional) "largeblockok" -> (value ignored)
5997 * indicates that blocks > 128KB are permitted
5998 * (optional) "embedok" -> (value ignored)
5999 * presence indicates DRR_WRITE_EMBEDDED records are permitted
6000 * (optional) "compressok" -> (value ignored)
6001 * presence indicates compressed DRR_WRITE records are permitted
6002 * (optional) "rawok" -> (value ignored)
6003 * presence indicates raw encrypted records should be used.
6007 * "space" -> bytes of space (uint64)
6011 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6014 dsl_dataset_t
*tosnap
;
6017 boolean_t compressok
;
6021 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
6025 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
6027 dsl_pool_rele(dp
, FTAG
);
6031 compressok
= nvlist_exists(innvl
, "compressok");
6032 rawok
= nvlist_exists(innvl
, "rawok");
6034 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
6036 if (strchr(fromname
, '@') != NULL
) {
6038 * If from is a snapshot, hold it and use the more
6039 * efficient dmu_send_estimate to estimate send space
6040 * size using deadlists.
6042 dsl_dataset_t
*fromsnap
;
6043 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
6046 error
= dmu_send_estimate(tosnap
, fromsnap
,
6047 compressok
|| rawok
, &space
);
6048 dsl_dataset_rele(fromsnap
, FTAG
);
6049 } else if (strchr(fromname
, '#') != NULL
) {
6051 * If from is a bookmark, fetch the creation TXG of the
6052 * snapshot it was created from and use that to find
6053 * blocks that were born after it.
6055 zfs_bookmark_phys_t frombm
;
6057 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
6061 error
= dmu_send_estimate_from_txg(tosnap
,
6062 frombm
.zbm_creation_txg
, compressok
|| rawok
,
6066 * from is not properly formatted as a snapshot or
6069 error
= SET_ERROR(EINVAL
);
6074 * If estimating the size of a full send, use dmu_send_estimate.
6076 error
= dmu_send_estimate(tosnap
, NULL
, compressok
|| rawok
,
6080 fnvlist_add_uint64(outnvl
, "space", space
);
6083 dsl_dataset_rele(tosnap
, FTAG
);
6084 dsl_pool_rele(dp
, FTAG
);
6089 * Sync the currently open TXG to disk for the specified pool.
6090 * This is somewhat similar to 'zfs_sync()'.
6091 * For cases that do not result in error this ioctl will wait for
6092 * the currently open TXG to commit before returning back to the caller.
6095 * "force" -> when true, force uberblock update even if there is no dirty data.
6096 * In addition this will cause the vdev configuration to be written
6097 * out including updating the zpool cache file. (boolean_t)
6104 zfs_ioc_pool_sync(const char *pool
, nvlist_t
*innvl
, nvlist_t
*onvl
)
6107 boolean_t force
= B_FALSE
;
6110 if ((err
= spa_open(pool
, &spa
, FTAG
)) != 0)
6114 if (nvlist_lookup_boolean_value(innvl
, "force", &force
) != 0) {
6115 err
= SET_ERROR(EINVAL
);
6121 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_WRITER
);
6122 vdev_config_dirty(spa
->spa_root_vdev
);
6123 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6125 txg_wait_synced(spa_get_dsl(spa
), 0);
6127 spa_close(spa
, FTAG
);
6133 * Load a user's wrapping key into the kernel.
6135 * "hidden_args" -> { "wkeydata" -> value }
6136 * raw uint8_t array of encryption wrapping key data (32 bytes)
6137 * (optional) "noop" -> (value ignored)
6138 * presence indicated key should only be verified, not loaded
6143 zfs_ioc_load_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6146 dsl_crypto_params_t
*dcp
= NULL
;
6147 nvlist_t
*hidden_args
;
6148 boolean_t noop
= nvlist_exists(innvl
, "noop");
6150 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6151 ret
= SET_ERROR(EINVAL
);
6155 ret
= nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6157 ret
= SET_ERROR(EINVAL
);
6161 ret
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, NULL
,
6166 ret
= spa_keystore_load_wkey(dsname
, dcp
, noop
);
6170 dsl_crypto_params_free(dcp
, noop
);
6175 dsl_crypto_params_free(dcp
, B_TRUE
);
6180 * Unload a user's wrapping key from the kernel.
6181 * Both innvl and outnvl are unused.
6185 zfs_ioc_unload_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6189 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6190 ret
= (SET_ERROR(EINVAL
));
6194 ret
= spa_keystore_unload_wkey(dsname
);
6203 * Changes a user's wrapping key used to decrypt a dataset. The keyformat,
6204 * keylocation, pbkdf2salt, and pbkdf2iters properties can also be specified
6205 * here to change how the key is derived in userspace.
6208 * "hidden_args" (optional) -> { "wkeydata" -> value }
6209 * raw uint8_t array of new encryption wrapping key data (32 bytes)
6210 * "props" (optional) -> { prop -> value }
6217 zfs_ioc_change_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6220 uint64_t cmd
= DCP_CMD_NONE
;
6221 dsl_crypto_params_t
*dcp
= NULL
;
6222 nvlist_t
*args
= NULL
, *hidden_args
= NULL
;
6224 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6225 ret
= (SET_ERROR(EINVAL
));
6229 (void) nvlist_lookup_uint64(innvl
, "crypt_cmd", &cmd
);
6230 (void) nvlist_lookup_nvlist(innvl
, "props", &args
);
6231 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6233 ret
= dsl_crypto_params_create_nvlist(cmd
, args
, hidden_args
, &dcp
);
6237 ret
= spa_keystore_change_key(dsname
, dcp
);
6241 dsl_crypto_params_free(dcp
, B_FALSE
);
6246 dsl_crypto_params_free(dcp
, B_TRUE
);
6250 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
6253 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6254 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6255 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
6257 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6259 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6260 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6261 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6262 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6264 vec
->zvec_legacy_func
= func
;
6265 vec
->zvec_secpolicy
= secpolicy
;
6266 vec
->zvec_namecheck
= namecheck
;
6267 vec
->zvec_allow_log
= log_history
;
6268 vec
->zvec_pool_check
= pool_check
;
6272 * See the block comment at the beginning of this file for details on
6273 * each argument to this function.
6276 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
6277 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6278 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
6279 boolean_t allow_log
)
6281 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6283 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6284 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6285 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6286 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6288 /* if we are logging, the name must be valid */
6289 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
6291 vec
->zvec_name
= name
;
6292 vec
->zvec_func
= func
;
6293 vec
->zvec_secpolicy
= secpolicy
;
6294 vec
->zvec_namecheck
= namecheck
;
6295 vec
->zvec_pool_check
= pool_check
;
6296 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
6297 vec
->zvec_allow_log
= allow_log
;
6301 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6302 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
6303 zfs_ioc_poolcheck_t pool_check
)
6305 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6306 POOL_NAME
, log_history
, pool_check
);
6310 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6311 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
6313 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6314 DATASET_NAME
, B_FALSE
, pool_check
);
6318 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6320 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
6321 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6325 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6326 zfs_secpolicy_func_t
*secpolicy
)
6328 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6329 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6333 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
6334 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
6336 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6337 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6341 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6343 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
6344 zfs_secpolicy_read
);
6348 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6349 zfs_secpolicy_func_t
*secpolicy
)
6351 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6352 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6356 zfs_ioctl_init(void)
6358 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
6359 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
6360 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6362 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
6363 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
6364 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
6366 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
6367 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
6368 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6370 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
6371 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
6372 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6374 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
6375 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
6376 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6378 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
6379 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6380 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6382 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
6383 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6384 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6386 zfs_ioctl_register("remap", ZFS_IOC_REMAP
,
6387 zfs_ioc_remap
, zfs_secpolicy_remap
, DATASET_NAME
,
6388 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
6390 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
6391 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
6392 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6394 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
6395 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
6396 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6397 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
6398 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
6399 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6401 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
6402 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
6403 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6405 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
6406 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
6407 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
6409 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
6410 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
6411 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6413 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
6414 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
6415 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
6417 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
6418 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
6420 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6422 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
6423 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
6424 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6425 zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY
,
6426 zfs_ioc_load_key
, zfs_secpolicy_load_key
,
6427 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
);
6428 zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY
,
6429 zfs_ioc_unload_key
, zfs_secpolicy_load_key
,
6430 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
);
6431 zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY
,
6432 zfs_ioc_change_key
, zfs_secpolicy_change_key
,
6433 DATASET_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
,
6436 zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC
,
6437 zfs_ioc_pool_sync
, zfs_secpolicy_none
, POOL_NAME
,
6438 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
6439 zfs_ioctl_register("reopen", ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
6440 zfs_secpolicy_config
, POOL_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
,
6443 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
6444 zfs_ioc_channel_program
, zfs_secpolicy_config
,
6445 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
6448 zfs_ioctl_register("zpool_checkpoint", ZFS_IOC_POOL_CHECKPOINT
,
6449 zfs_ioc_pool_checkpoint
, zfs_secpolicy_config
, POOL_NAME
,
6450 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6452 zfs_ioctl_register("zpool_discard_checkpoint",
6453 ZFS_IOC_POOL_DISCARD_CHECKPOINT
, zfs_ioc_pool_discard_checkpoint
,
6454 zfs_secpolicy_config
, POOL_NAME
,
6455 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
6457 /* IOCTLS that use the legacy function signature */
6459 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
6460 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
6462 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
6463 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6464 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
6466 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
6467 zfs_ioc_pool_upgrade
);
6468 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
6470 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
6471 zfs_ioc_vdev_remove
);
6472 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
6473 zfs_ioc_vdev_set_state
);
6474 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
6475 zfs_ioc_vdev_attach
);
6476 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
6477 zfs_ioc_vdev_detach
);
6478 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
6479 zfs_ioc_vdev_setpath
);
6480 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
6481 zfs_ioc_vdev_setfru
);
6482 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
6483 zfs_ioc_pool_set_props
);
6484 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
6485 zfs_ioc_vdev_split
);
6486 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
6487 zfs_ioc_pool_reguid
);
6489 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
6490 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
6491 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
6492 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
6493 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
6494 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
6495 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
6496 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
6497 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
6498 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
6501 * pool destroy, and export don't log the history as part of
6502 * zfsdev_ioctl, but rather zfs_ioc_pool_export
6503 * does the logging of those commands.
6505 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
6506 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6507 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
6508 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6510 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
6511 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6512 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
6513 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6515 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
6516 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6517 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
6518 zfs_ioc_dsobj_to_dsname
,
6519 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6520 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
6521 zfs_ioc_pool_get_history
,
6522 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6524 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
6525 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6527 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
6528 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_READONLY
);
6530 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
6531 zfs_ioc_space_written
);
6532 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
6533 zfs_ioc_objset_recvd_props
);
6534 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
6536 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
6538 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
6539 zfs_ioc_objset_stats
);
6540 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
6541 zfs_ioc_objset_zplprops
);
6542 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
6543 zfs_ioc_dataset_list_next
);
6544 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
6545 zfs_ioc_snapshot_list_next
);
6546 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
6547 zfs_ioc_send_progress
);
6549 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
6550 zfs_ioc_diff
, zfs_secpolicy_diff
);
6551 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
6552 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
6553 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
6554 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
6555 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
6556 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
6557 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
6558 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
6559 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
6560 zfs_ioc_send
, zfs_secpolicy_send
);
6562 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
6563 zfs_secpolicy_none
);
6564 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
6565 zfs_secpolicy_destroy
);
6566 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
6567 zfs_secpolicy_rename
);
6568 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
6569 zfs_secpolicy_recv
);
6570 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
6571 zfs_secpolicy_promote
);
6572 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
6573 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
6574 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
6575 zfs_secpolicy_set_fsacl
);
6577 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
6578 zfs_secpolicy_share
, POOL_CHECK_NONE
);
6579 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
6580 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
6581 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
6582 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
6583 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6584 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
6585 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
6586 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6591 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
6592 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6593 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
6594 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6595 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
6596 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6600 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
6601 zfs_ioc_poolcheck_t check
)
6606 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
6608 if (check
& POOL_CHECK_NONE
)
6611 error
= spa_open(name
, &spa
, FTAG
);
6613 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
6614 error
= SET_ERROR(EAGAIN
);
6615 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
6616 error
= SET_ERROR(EROFS
);
6617 spa_close(spa
, FTAG
);
6623 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
6627 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6628 if (zs
->zs_minor
== minor
) {
6632 return (zs
->zs_onexit
);
6634 return (zs
->zs_zevent
);
6645 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
6649 ptr
= zfsdev_get_state_impl(minor
, which
);
6655 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
6657 zfsdev_state_t
*zs
, *fpd
;
6659 ASSERT(filp
!= NULL
);
6660 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
6662 fpd
= filp
->private_data
;
6664 return (SET_ERROR(EBADF
));
6666 mutex_enter(&zfsdev_state_lock
);
6668 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6670 if (zs
->zs_minor
== -1)
6674 *minorp
= fpd
->zs_minor
;
6675 mutex_exit(&zfsdev_state_lock
);
6680 mutex_exit(&zfsdev_state_lock
);
6682 return (SET_ERROR(EBADF
));
6686 * Find a free minor number. The zfsdev_state_list is expected to
6687 * be short since it is only a list of currently open file handles.
6690 zfsdev_minor_alloc(void)
6692 static minor_t last_minor
= 0;
6695 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6697 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6698 if (m
> ZFSDEV_MAX_MINOR
)
6700 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
6710 zfsdev_state_init(struct file
*filp
)
6712 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6714 boolean_t newzs
= B_FALSE
;
6716 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6718 minor
= zfsdev_minor_alloc();
6720 return (SET_ERROR(ENXIO
));
6722 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6723 if (zs
->zs_minor
== -1)
6729 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6734 filp
->private_data
= zs
;
6736 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
6737 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
6741 * In order to provide for lock-free concurrent read access
6742 * to the minor list in zfsdev_get_state_impl(), new entries
6743 * must be completely written before linking them into the
6744 * list whereas existing entries are already linked; the last
6745 * operation must be updating zs_minor (from -1 to the new
6749 zs
->zs_minor
= minor
;
6751 zsprev
->zs_next
= zs
;
6754 zs
->zs_minor
= minor
;
6761 zfsdev_state_destroy(struct file
*filp
)
6765 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6766 ASSERT(filp
->private_data
!= NULL
);
6768 zs
= filp
->private_data
;
6770 zfs_onexit_destroy(zs
->zs_onexit
);
6771 zfs_zevent_destroy(zs
->zs_zevent
);
6777 zfsdev_open(struct inode
*ino
, struct file
*filp
)
6781 mutex_enter(&zfsdev_state_lock
);
6782 error
= zfsdev_state_init(filp
);
6783 mutex_exit(&zfsdev_state_lock
);
6789 zfsdev_release(struct inode
*ino
, struct file
*filp
)
6793 mutex_enter(&zfsdev_state_lock
);
6794 error
= zfsdev_state_destroy(filp
);
6795 mutex_exit(&zfsdev_state_lock
);
6801 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6805 int error
, rc
, flag
= 0;
6806 const zfs_ioc_vec_t
*vec
;
6807 char *saved_poolname
= NULL
;
6808 nvlist_t
*innvl
= NULL
;
6809 fstrans_cookie_t cookie
;
6811 vecnum
= cmd
- ZFS_IOC_FIRST
;
6812 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6813 return (-SET_ERROR(EINVAL
));
6814 vec
= &zfs_ioc_vec
[vecnum
];
6817 * The registered ioctl list may be sparse, verify that either
6818 * a normal or legacy handler are registered.
6820 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
6821 return (-SET_ERROR(EINVAL
));
6823 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6825 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6827 error
= SET_ERROR(EFAULT
);
6831 zc
->zc_iflags
= flag
& FKIOCTL
;
6832 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
6834 * Make sure the user doesn't pass in an insane value for
6835 * zc_nvlist_src_size. We have to check, since we will end
6836 * up allocating that much memory inside of get_nvlist(). This
6837 * prevents a nefarious user from allocating tons of kernel
6840 * Also, we return EINVAL instead of ENOMEM here. The reason
6841 * being that returning ENOMEM from an ioctl() has a special
6842 * connotation; that the user's size value is too small and
6843 * needs to be expanded to hold the nvlist. See
6844 * zcmd_expand_dst_nvlist() for details.
6846 error
= SET_ERROR(EINVAL
); /* User's size too big */
6848 } else if (zc
->zc_nvlist_src_size
!= 0) {
6849 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6850 zc
->zc_iflags
, &innvl
);
6856 * Ensure that all pool/dataset names are valid before we pass down to
6859 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6860 switch (vec
->zvec_namecheck
) {
6862 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6863 error
= SET_ERROR(EINVAL
);
6865 error
= pool_status_check(zc
->zc_name
,
6866 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6870 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6871 error
= SET_ERROR(EINVAL
);
6873 error
= pool_status_check(zc
->zc_name
,
6874 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6883 cookie
= spl_fstrans_mark();
6884 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
6885 spl_fstrans_unmark(cookie
);
6891 /* legacy ioctls can modify zc_name */
6892 saved_poolname
= strdup(zc
->zc_name
);
6893 if (saved_poolname
== NULL
) {
6894 error
= SET_ERROR(ENOMEM
);
6897 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
6900 if (vec
->zvec_func
!= NULL
) {
6904 nvlist_t
*lognv
= NULL
;
6906 ASSERT(vec
->zvec_legacy_func
== NULL
);
6909 * Add the innvl to the lognv before calling the func,
6910 * in case the func changes the innvl.
6912 if (vec
->zvec_allow_log
) {
6913 lognv
= fnvlist_alloc();
6914 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6916 if (!nvlist_empty(innvl
)) {
6917 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6922 outnvl
= fnvlist_alloc();
6923 cookie
= spl_fstrans_mark();
6924 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6925 spl_fstrans_unmark(cookie
);
6928 * Some commands can partially execute, modify state, and still
6929 * return an error. In these cases, attempt to record what
6933 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
6934 vec
->zvec_allow_log
&&
6935 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6936 if (!nvlist_empty(outnvl
)) {
6937 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6941 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
6944 (void) spa_history_log_nvl(spa
, lognv
);
6945 spa_close(spa
, FTAG
);
6947 fnvlist_free(lognv
);
6949 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6951 if (vec
->zvec_smush_outnvlist
) {
6952 smusherror
= nvlist_smush(outnvl
,
6953 zc
->zc_nvlist_dst_size
);
6955 if (smusherror
== 0)
6956 puterror
= put_nvlist(zc
, outnvl
);
6962 nvlist_free(outnvl
);
6964 cookie
= spl_fstrans_mark();
6965 error
= vec
->zvec_legacy_func(zc
);
6966 spl_fstrans_unmark(cookie
);
6971 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6972 if (error
== 0 && rc
!= 0)
6973 error
= SET_ERROR(EFAULT
);
6974 if (error
== 0 && vec
->zvec_allow_log
) {
6975 char *s
= tsd_get(zfs_allow_log_key
);
6978 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6980 if (saved_poolname
!= NULL
)
6981 strfree(saved_poolname
);
6984 kmem_free(zc
, sizeof (zfs_cmd_t
));
6988 #ifdef CONFIG_COMPAT
6990 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6992 return (zfsdev_ioctl(filp
, cmd
, arg
));
6995 #define zfsdev_compat_ioctl NULL
6998 static const struct file_operations zfsdev_fops
= {
6999 .open
= zfsdev_open
,
7000 .release
= zfsdev_release
,
7001 .unlocked_ioctl
= zfsdev_ioctl
,
7002 .compat_ioctl
= zfsdev_compat_ioctl
,
7003 .owner
= THIS_MODULE
,
7006 static struct miscdevice zfs_misc
= {
7009 .fops
= &zfsdev_fops
,
7012 MODULE_ALIAS_MISCDEV(ZFS_MINOR
);
7013 MODULE_ALIAS("devname:zfs");
7020 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
7021 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
7022 zfsdev_state_list
->zs_minor
= -1;
7024 error
= misc_register(&zfs_misc
);
7025 if (error
== -EBUSY
) {
7027 * Fallback to dynamic minor allocation in the event of a
7028 * collision with a reserved minor in linux/miscdevice.h.
7029 * In this case the kernel modules must be manually loaded.
7031 printk(KERN_INFO
"ZFS: misc_register() with static minor %d "
7032 "failed %d, retrying with MISC_DYNAMIC_MINOR\n",
7035 zfs_misc
.minor
= MISC_DYNAMIC_MINOR
;
7036 error
= misc_register(&zfs_misc
);
7040 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
7048 zfsdev_state_t
*zs
, *zsprev
= NULL
;
7050 misc_deregister(&zfs_misc
);
7051 mutex_destroy(&zfsdev_state_lock
);
7053 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
7055 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7059 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7063 zfs_allow_log_destroy(void *arg
)
7065 char *poolname
= arg
;
7067 if (poolname
!= NULL
)
7072 #define ZFS_DEBUG_STR " (DEBUG mode)"
7074 #define ZFS_DEBUG_STR ""
7082 error
= -vn_set_pwd("/");
7085 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
7089 if ((error
= -zvol_init()) != 0)
7092 spa_init(FREAD
| FWRITE
);
7097 if ((error
= zfs_attach()) != 0)
7100 tsd_create(&zfs_fsyncer_key
, NULL
);
7101 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
7102 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
7104 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
7105 "ZFS pool version %s, ZFS filesystem version %s\n",
7106 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
7107 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
7108 #ifndef CONFIG_FS_POSIX_ACL
7109 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
7110 #endif /* CONFIG_FS_POSIX_ACL */
7118 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
7119 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
7120 ZFS_DEBUG_STR
, error
);
7133 tsd_destroy(&zfs_fsyncer_key
);
7134 tsd_destroy(&rrw_tsd_key
);
7135 tsd_destroy(&zfs_allow_log_key
);
7137 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
7138 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
7141 #if defined(_KERNEL)
7145 MODULE_DESCRIPTION("ZFS");
7146 MODULE_AUTHOR(ZFS_META_AUTHOR
);
7147 MODULE_LICENSE(ZFS_META_LICENSE
);
7148 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);