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, 2018 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) 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
37 * Copyright 2017 RackTop Systems.
38 * Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
39 * Copyright (c) 2019 Datto Inc.
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 * We want newer versions of libzfs and libzfs_core to run against
67 * existing zfs kernel modules (i.e. a deferred reboot after an update).
68 * Therefore the ioctl numbers cannot change from release to release.
70 * zfs_secpolicy_func_t *secpolicy
71 * This function will be called before the zfs_ioc_func_t, to
72 * determine if this operation is permitted. It should return EPERM
73 * on failure, and 0 on success. Checks include determining if the
74 * dataset is visible in this zone, and if the user has either all
75 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
76 * to do this operation on this dataset with "zfs allow".
78 * zfs_ioc_namecheck_t namecheck
79 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
80 * name, a dataset name, or nothing. If the name is not well-formed,
81 * the ioctl will fail and the callback will not be called.
82 * Therefore, the callback can assume that the name is well-formed
83 * (e.g. is null-terminated, doesn't have more than one '@' character,
84 * doesn't have invalid characters).
86 * zfs_ioc_poolcheck_t pool_check
87 * This specifies requirements on the pool state. If the pool does
88 * not meet them (is suspended or is readonly), the ioctl will fail
89 * and the callback will not be called. If any checks are specified
90 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
91 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
92 * POOL_CHECK_READONLY).
94 * zfs_ioc_key_t *nvl_keys
95 * The list of expected/allowable innvl input keys. This list is used
96 * to validate the nvlist input to the ioctl.
98 * boolean_t smush_outnvlist
99 * If smush_outnvlist is true, then the output is presumed to be a
100 * list of errors, and it will be "smushed" down to fit into the
101 * caller's buffer, by removing some entries and replacing them with a
102 * single "N_MORE_ERRORS" entry indicating how many were removed. See
103 * nvlist_smush() for details. If smush_outnvlist is false, and the
104 * outnvlist does not fit into the userland-provided buffer, then the
105 * ioctl will fail with ENOMEM.
107 * zfs_ioc_func_t *func
108 * The callback function that will perform the operation.
110 * The callback should return 0 on success, or an error number on
111 * failure. If the function fails, the userland ioctl will return -1,
112 * and errno will be set to the callback's return value. The callback
113 * will be called with the following arguments:
116 * The name of the pool or dataset to operate on, from
117 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
118 * expected type (pool, dataset, or none).
121 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
122 * NULL if no input nvlist was provided. Changes to this nvlist are
123 * ignored. If the input nvlist could not be deserialized, the
124 * ioctl will fail and the callback will not be called.
127 * The output nvlist, initially empty. The callback can fill it in,
128 * and it will be returned to userland by serializing it into
129 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
130 * fails (e.g. because the caller didn't supply a large enough
131 * buffer), then the overall ioctl will fail. See the
132 * 'smush_nvlist' argument above for additional behaviors.
134 * There are two typical uses of the output nvlist:
135 * - To return state, e.g. property values. In this case,
136 * smush_outnvlist should be false. If the buffer was not large
137 * enough, the caller will reallocate a larger buffer and try
140 * - To return multiple errors from an ioctl which makes on-disk
141 * changes. In this case, smush_outnvlist should be true.
142 * Ioctls which make on-disk modifications should generally not
143 * use the outnvl if they succeed, because the caller can not
144 * distinguish between the operation failing, and
145 * deserialization failing.
147 * IOCTL Interface Errors
149 * The following ioctl input errors can be returned:
150 * ZFS_ERR_IOC_CMD_UNAVAIL the ioctl number is not supported by kernel
151 * ZFS_ERR_IOC_ARG_UNAVAIL an input argument is not supported by kernel
152 * ZFS_ERR_IOC_ARG_REQUIRED a required input argument is missing
153 * ZFS_ERR_IOC_ARG_BADTYPE an input argument has an invalid type
156 #include <sys/types.h>
157 #include <sys/param.h>
158 #include <sys/errno.h>
160 #include <sys/file.h>
161 #include <sys/kmem.h>
162 #include <sys/cmn_err.h>
163 #include <sys/stat.h>
164 #include <sys/zfs_ioctl.h>
165 #include <sys/zfs_vfsops.h>
166 #include <sys/zfs_znode.h>
169 #include <sys/spa_impl.h>
170 #include <sys/vdev.h>
171 #include <sys/vdev_impl.h>
173 #include <sys/dsl_dir.h>
174 #include <sys/dsl_dataset.h>
175 #include <sys/dsl_prop.h>
176 #include <sys/dsl_deleg.h>
177 #include <sys/dmu_objset.h>
178 #include <sys/dmu_impl.h>
179 #include <sys/dmu_tx.h>
180 #include <sys/sunddi.h>
181 #include <sys/policy.h>
182 #include <sys/zone.h>
183 #include <sys/nvpair.h>
184 #include <sys/pathname.h>
186 #include <sys/fs/zfs.h>
187 #include <sys/zfs_ctldir.h>
188 #include <sys/zfs_dir.h>
189 #include <sys/zfs_onexit.h>
190 #include <sys/zvol.h>
191 #include <sys/dsl_scan.h>
192 #include <sys/fm/util.h>
193 #include <sys/dsl_crypt.h>
195 #include <sys/dmu_recv.h>
196 #include <sys/dmu_send.h>
197 #include <sys/dsl_destroy.h>
198 #include <sys/dsl_bookmark.h>
199 #include <sys/dsl_userhold.h>
200 #include <sys/zfeature.h>
202 #include <sys/zio_checksum.h>
203 #include <sys/vdev_removal.h>
204 #include <sys/zfs_sysfs.h>
205 #include <sys/vdev_impl.h>
206 #include <sys/vdev_initialize.h>
207 #include <sys/vdev_trim.h>
209 #include <linux/miscdevice.h>
210 #include <linux/slab.h>
212 #include "zfs_namecheck.h"
213 #include "zfs_prop.h"
214 #include "zfs_deleg.h"
215 #include "zfs_comutil.h"
217 #include <sys/lua/lua.h>
218 #include <sys/lua/lauxlib.h>
221 * Limit maximum nvlist size. We don't want users passing in insane values
222 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
224 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
226 kmutex_t zfsdev_state_lock
;
227 zfsdev_state_t
*zfsdev_state_list
;
229 extern void zfs_init(void);
230 extern void zfs_fini(void);
232 uint_t zfs_fsyncer_key
;
233 extern uint_t rrw_tsd_key
;
234 static uint_t zfs_allow_log_key
;
236 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
237 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
238 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
241 * IOC Keys are used to document and validate user->kernel interface inputs.
242 * See zfs_keys_recv_new for an example declaration. Any key name that is not
243 * listed will be rejected as input.
245 * The keyname 'optional' is always allowed, and must be an nvlist if present.
246 * Arguments which older kernels can safely ignore can be placed under the
249 * When adding new keys to an existing ioc for new functionality, consider:
250 * - adding an entry into zfs_sysfs.c zfs_features[] list
251 * - updating the libzfs_input_check.c test utility
253 * Note: in the ZK_WILDCARDLIST case, the name serves as documentation
254 * for the expected name (bookmark, snapshot, property, etc) but there
255 * is no validation in the preflight zfs_check_input_nvpairs() check.
258 ZK_OPTIONAL
= 1 << 0, /* pair is optional */
259 ZK_WILDCARDLIST
= 1 << 1, /* one or more unspecified key names */
262 /* DATA_TYPE_ANY is used when zkey_type can vary. */
263 #define DATA_TYPE_ANY DATA_TYPE_UNKNOWN
265 typedef struct zfs_ioc_key
{
266 const char *zkey_name
;
267 data_type_t zkey_type
;
268 ioc_key_flag_t zkey_flags
;
275 } zfs_ioc_namecheck_t
;
278 POOL_CHECK_NONE
= 1 << 0,
279 POOL_CHECK_SUSPENDED
= 1 << 1,
280 POOL_CHECK_READONLY
= 1 << 2,
281 } zfs_ioc_poolcheck_t
;
283 typedef struct zfs_ioc_vec
{
284 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
285 zfs_ioc_func_t
*zvec_func
;
286 zfs_secpolicy_func_t
*zvec_secpolicy
;
287 zfs_ioc_namecheck_t zvec_namecheck
;
288 boolean_t zvec_allow_log
;
289 zfs_ioc_poolcheck_t zvec_pool_check
;
290 boolean_t zvec_smush_outnvlist
;
291 const char *zvec_name
;
292 const zfs_ioc_key_t
*zvec_nvl_keys
;
293 size_t zvec_nvl_key_count
;
296 /* This array is indexed by zfs_userquota_prop_t */
297 static const char *userquota_perms
[] = {
298 ZFS_DELEG_PERM_USERUSED
,
299 ZFS_DELEG_PERM_USERQUOTA
,
300 ZFS_DELEG_PERM_GROUPUSED
,
301 ZFS_DELEG_PERM_GROUPQUOTA
,
302 ZFS_DELEG_PERM_USEROBJUSED
,
303 ZFS_DELEG_PERM_USEROBJQUOTA
,
304 ZFS_DELEG_PERM_GROUPOBJUSED
,
305 ZFS_DELEG_PERM_GROUPOBJQUOTA
,
306 ZFS_DELEG_PERM_PROJECTUSED
,
307 ZFS_DELEG_PERM_PROJECTQUOTA
,
308 ZFS_DELEG_PERM_PROJECTOBJUSED
,
309 ZFS_DELEG_PERM_PROJECTOBJQUOTA
,
312 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
313 static int zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
);
314 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
316 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
318 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
320 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
321 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
324 history_str_free(char *buf
)
326 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
330 history_str_get(zfs_cmd_t
*zc
)
334 if (zc
->zc_history
== 0)
337 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
338 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
339 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
340 history_str_free(buf
);
344 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
350 * Check to see if the named dataset is currently defined as bootable
353 zfs_is_bootfs(const char *name
)
357 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
359 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
360 dmu_objset_rele(os
, FTAG
);
367 * Return non-zero if the spa version is less than requested version.
370 zfs_earlier_version(const char *name
, int version
)
374 if (spa_open(name
, &spa
, FTAG
) == 0) {
375 if (spa_version(spa
) < version
) {
376 spa_close(spa
, FTAG
);
379 spa_close(spa
, FTAG
);
385 * Return TRUE if the ZPL version is less than requested version.
388 zpl_earlier_version(const char *name
, int version
)
391 boolean_t rc
= B_TRUE
;
393 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
396 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
397 dmu_objset_rele(os
, FTAG
);
400 /* XXX reading from non-owned objset */
401 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
402 rc
= zplversion
< version
;
403 dmu_objset_rele(os
, FTAG
);
409 zfs_log_history(zfs_cmd_t
*zc
)
414 if ((buf
= history_str_get(zc
)) == NULL
)
417 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
418 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
419 (void) spa_history_log(spa
, buf
);
420 spa_close(spa
, FTAG
);
422 history_str_free(buf
);
426 * Policy for top-level read operations (list pools). Requires no privileges,
427 * and can be used in the local zone, as there is no associated dataset.
431 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
437 * Policy for dataset read operations (list children, get statistics). Requires
438 * no privileges, but must be visible in the local zone.
442 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
444 if (INGLOBALZONE(curproc
) ||
445 zone_dataset_visible(zc
->zc_name
, NULL
))
448 return (SET_ERROR(ENOENT
));
452 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
457 * The dataset must be visible by this zone -- check this first
458 * so they don't see EPERM on something they shouldn't know about.
460 if (!INGLOBALZONE(curproc
) &&
461 !zone_dataset_visible(dataset
, &writable
))
462 return (SET_ERROR(ENOENT
));
464 if (INGLOBALZONE(curproc
)) {
466 * If the fs is zoned, only root can access it from the
469 if (secpolicy_zfs(cr
) && zoned
)
470 return (SET_ERROR(EPERM
));
473 * If we are in a local zone, the 'zoned' property must be set.
476 return (SET_ERROR(EPERM
));
478 /* must be writable by this zone */
480 return (SET_ERROR(EPERM
));
486 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
490 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
491 return (SET_ERROR(ENOENT
));
493 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
497 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
501 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
502 return (SET_ERROR(ENOENT
));
504 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
508 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
509 const char *perm
, cred_t
*cr
)
513 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
515 error
= secpolicy_zfs(cr
);
517 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
523 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
530 * First do a quick check for root in the global zone, which
531 * is allowed to do all write_perms. This ensures that zfs_ioc_*
532 * will get to handle nonexistent datasets.
534 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
537 error
= dsl_pool_hold(name
, FTAG
, &dp
);
541 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
543 dsl_pool_rele(dp
, FTAG
);
547 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
549 dsl_dataset_rele(ds
, FTAG
);
550 dsl_pool_rele(dp
, FTAG
);
555 * Policy for setting the security label property.
557 * Returns 0 for success, non-zero for access and other errors.
560 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
563 char ds_hexsl
[MAXNAMELEN
];
564 bslabel_t ds_sl
, new_sl
;
565 boolean_t new_default
= FALSE
;
567 int needed_priv
= -1;
570 /* First get the existing dataset label. */
571 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
572 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
574 return (SET_ERROR(EPERM
));
576 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
579 /* The label must be translatable */
580 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
581 return (SET_ERROR(EINVAL
));
584 * In a non-global zone, disallow attempts to set a label that
585 * doesn't match that of the zone; otherwise no other checks
588 if (!INGLOBALZONE(curproc
)) {
589 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
590 return (SET_ERROR(EPERM
));
595 * For global-zone datasets (i.e., those whose zoned property is
596 * "off", verify that the specified new label is valid for the
599 if (dsl_prop_get_integer(name
,
600 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
601 return (SET_ERROR(EPERM
));
603 if (zfs_check_global_label(name
, strval
) != 0)
604 return (SET_ERROR(EPERM
));
608 * If the existing dataset label is nondefault, check if the
609 * dataset is mounted (label cannot be changed while mounted).
610 * Get the zfsvfs_t; if there isn't one, then the dataset isn't
611 * mounted (or isn't a dataset, doesn't exist, ...).
613 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
615 static char *setsl_tag
= "setsl_tag";
618 * Try to own the dataset; abort if there is any error,
619 * (e.g., already mounted, in use, or other error).
621 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
, B_TRUE
,
624 return (SET_ERROR(EPERM
));
626 dmu_objset_disown(os
, B_TRUE
, setsl_tag
);
629 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
633 if (hexstr_to_label(strval
, &new_sl
) != 0)
634 return (SET_ERROR(EPERM
));
636 if (blstrictdom(&ds_sl
, &new_sl
))
637 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
638 else if (blstrictdom(&new_sl
, &ds_sl
))
639 needed_priv
= PRIV_FILE_UPGRADE_SL
;
641 /* dataset currently has a default label */
643 needed_priv
= PRIV_FILE_UPGRADE_SL
;
647 if (needed_priv
!= -1)
648 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
651 return (SET_ERROR(ENOTSUP
));
652 #endif /* HAVE_MLSLABEL */
656 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
662 * Check permissions for special properties.
669 * Disallow setting of 'zoned' from within a local zone.
671 if (!INGLOBALZONE(curproc
))
672 return (SET_ERROR(EPERM
));
676 case ZFS_PROP_FILESYSTEM_LIMIT
:
677 case ZFS_PROP_SNAPSHOT_LIMIT
:
678 if (!INGLOBALZONE(curproc
)) {
680 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
682 * Unprivileged users are allowed to modify the
683 * limit on things *under* (ie. contained by)
684 * the thing they own.
686 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
688 return (SET_ERROR(EPERM
));
689 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
690 return (SET_ERROR(EPERM
));
694 case ZFS_PROP_MLSLABEL
:
695 if (!is_system_labeled())
696 return (SET_ERROR(EPERM
));
698 if (nvpair_value_string(propval
, &strval
) == 0) {
701 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
708 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
713 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
717 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
722 * permission to set permissions will be evaluated later in
723 * dsl_deleg_can_allow()
730 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
732 return (zfs_secpolicy_write_perms(zc
->zc_name
,
733 ZFS_DELEG_PERM_ROLLBACK
, cr
));
738 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
746 * Generate the current snapshot name from the given objsetid, then
747 * use that name for the secpolicy/zone checks.
749 cp
= strchr(zc
->zc_name
, '@');
751 return (SET_ERROR(EINVAL
));
752 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
756 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
758 dsl_pool_rele(dp
, FTAG
);
762 dsl_dataset_name(ds
, zc
->zc_name
);
764 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
765 ZFS_DELEG_PERM_SEND
, cr
);
766 dsl_dataset_rele(ds
, FTAG
);
767 dsl_pool_rele(dp
, FTAG
);
774 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
776 return (zfs_secpolicy_write_perms(zc
->zc_name
,
777 ZFS_DELEG_PERM_SEND
, cr
));
781 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
783 return (SET_ERROR(ENOTSUP
));
787 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
789 return (SET_ERROR(ENOTSUP
));
793 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
798 * Remove the @bla or /bla from the end of the name to get the parent.
800 (void) strncpy(parent
, datasetname
, parentsize
);
801 cp
= strrchr(parent
, '@');
805 cp
= strrchr(parent
, '/');
807 return (SET_ERROR(ENOENT
));
815 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
819 if ((error
= zfs_secpolicy_write_perms(name
,
820 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
823 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
828 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
830 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
834 * Destroying snapshots with delegated permissions requires
835 * descendant mount and destroy permissions.
839 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
842 nvpair_t
*pair
, *nextpair
;
845 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
847 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
849 nextpair
= nvlist_next_nvpair(snaps
, pair
);
850 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
851 if (error
== ENOENT
) {
853 * Ignore any snapshots that don't exist (we consider
854 * them "already destroyed"). Remove the name from the
855 * nvl here in case the snapshot is created between
856 * now and when we try to destroy it (in which case
857 * we don't want to destroy it since we haven't
858 * checked for permission).
860 fnvlist_remove_nvpair(snaps
, pair
);
871 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
873 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
876 if ((error
= zfs_secpolicy_write_perms(from
,
877 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
880 if ((error
= zfs_secpolicy_write_perms(from
,
881 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
884 if ((error
= zfs_get_parent(to
, parentname
,
885 sizeof (parentname
))) != 0)
888 if ((error
= zfs_secpolicy_write_perms(parentname
,
889 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
892 if ((error
= zfs_secpolicy_write_perms(parentname
,
893 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
901 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
903 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
908 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
911 dsl_dataset_t
*clone
;
914 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
915 ZFS_DELEG_PERM_PROMOTE
, cr
);
919 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
923 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
926 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
927 dsl_dataset_t
*origin
= NULL
;
931 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
932 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
934 dsl_dataset_rele(clone
, FTAG
);
935 dsl_pool_rele(dp
, FTAG
);
939 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
940 ZFS_DELEG_PERM_MOUNT
, cr
);
942 dsl_dataset_name(origin
, parentname
);
944 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
945 ZFS_DELEG_PERM_PROMOTE
, cr
);
947 dsl_dataset_rele(clone
, FTAG
);
948 dsl_dataset_rele(origin
, FTAG
);
950 dsl_pool_rele(dp
, FTAG
);
956 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
960 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
961 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
964 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
965 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
968 return (zfs_secpolicy_write_perms(zc
->zc_name
,
969 ZFS_DELEG_PERM_CREATE
, cr
));
974 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
976 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
980 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
982 return (zfs_secpolicy_write_perms(name
,
983 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
987 * Check for permission to create each snapshot in the nvlist.
991 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
997 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
999 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
1000 pair
= nvlist_next_nvpair(snaps
, pair
)) {
1001 char *name
= nvpair_name(pair
);
1002 char *atp
= strchr(name
, '@');
1005 error
= SET_ERROR(EINVAL
);
1009 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
1018 * Check for permission to create each bookmark in the nvlist.
1022 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1026 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
1027 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1028 char *name
= nvpair_name(pair
);
1029 char *hashp
= strchr(name
, '#');
1031 if (hashp
== NULL
) {
1032 error
= SET_ERROR(EINVAL
);
1036 error
= zfs_secpolicy_write_perms(name
,
1037 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1047 zfs_secpolicy_remap(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1049 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1050 ZFS_DELEG_PERM_REMAP
, cr
));
1055 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1057 nvpair_t
*pair
, *nextpair
;
1060 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1062 char *name
= nvpair_name(pair
);
1063 char *hashp
= strchr(name
, '#');
1064 nextpair
= nvlist_next_nvpair(innvl
, pair
);
1066 if (hashp
== NULL
) {
1067 error
= SET_ERROR(EINVAL
);
1072 error
= zfs_secpolicy_write_perms(name
,
1073 ZFS_DELEG_PERM_DESTROY
, cr
);
1075 if (error
== ENOENT
) {
1077 * Ignore any filesystems that don't exist (we consider
1078 * their bookmarks "already destroyed"). Remove
1079 * the name from the nvl here in case the filesystem
1080 * is created between now and when we try to destroy
1081 * the bookmark (in which case we don't want to
1082 * destroy it since we haven't checked for permission).
1084 fnvlist_remove_nvpair(innvl
, pair
);
1096 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1099 * Even root must have a proper TSD so that we know what pool
1102 if (tsd_get(zfs_allow_log_key
) == NULL
)
1103 return (SET_ERROR(EPERM
));
1108 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1110 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1114 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1115 sizeof (parentname
))) != 0)
1118 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1119 (error
= zfs_secpolicy_write_perms(origin
,
1120 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1123 if ((error
= zfs_secpolicy_write_perms(parentname
,
1124 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1127 return (zfs_secpolicy_write_perms(parentname
,
1128 ZFS_DELEG_PERM_MOUNT
, cr
));
1132 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1133 * SYS_CONFIG privilege, which is not available in a local zone.
1137 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1139 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1140 return (SET_ERROR(EPERM
));
1146 * Policy for object to name lookups.
1150 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1154 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1157 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1162 * Policy for fault injection. Requires all privileges.
1166 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1168 return (secpolicy_zinject(cr
));
1173 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1175 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1177 if (prop
== ZPROP_INVAL
) {
1178 if (!zfs_prop_user(zc
->zc_value
))
1179 return (SET_ERROR(EINVAL
));
1180 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1181 ZFS_DELEG_PERM_USERPROP
, cr
));
1183 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1189 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1191 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1195 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1196 return (SET_ERROR(EINVAL
));
1198 if (zc
->zc_value
[0] == 0) {
1200 * They are asking about a posix uid/gid. If it's
1201 * themself, allow it.
1203 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1204 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
||
1205 zc
->zc_objset_type
== ZFS_PROP_USEROBJUSED
||
1206 zc
->zc_objset_type
== ZFS_PROP_USEROBJQUOTA
) {
1207 if (zc
->zc_guid
== crgetuid(cr
))
1209 } else if (zc
->zc_objset_type
== ZFS_PROP_GROUPUSED
||
1210 zc
->zc_objset_type
== ZFS_PROP_GROUPQUOTA
||
1211 zc
->zc_objset_type
== ZFS_PROP_GROUPOBJUSED
||
1212 zc
->zc_objset_type
== ZFS_PROP_GROUPOBJQUOTA
) {
1213 if (groupmember(zc
->zc_guid
, cr
))
1216 /* else is for project quota/used */
1219 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1220 userquota_perms
[zc
->zc_objset_type
], cr
));
1224 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1226 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1230 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1231 return (SET_ERROR(EINVAL
));
1233 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1234 userquota_perms
[zc
->zc_objset_type
], cr
));
1239 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1241 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1247 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1253 holds
= fnvlist_lookup_nvlist(innvl
, "holds");
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 if (innvl
!= NULL
) {
1311 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1313 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1315 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1321 zfs_secpolicy_load_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1323 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1324 ZFS_DELEG_PERM_LOAD_KEY
, cr
));
1328 zfs_secpolicy_change_key(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1330 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1331 ZFS_DELEG_PERM_CHANGE_KEY
, cr
));
1335 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1338 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1342 nvlist_t
*list
= NULL
;
1345 * Read in and unpack the user-supplied nvlist.
1348 return (SET_ERROR(EINVAL
));
1350 packed
= vmem_alloc(size
, KM_SLEEP
);
1352 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1354 vmem_free(packed
, size
);
1355 return (SET_ERROR(EFAULT
));
1358 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1359 vmem_free(packed
, size
);
1363 vmem_free(packed
, size
);
1370 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1371 * Entries will be removed from the end of the nvlist, and one int32 entry
1372 * named "N_MORE_ERRORS" will be added indicating how many entries were
1376 nvlist_smush(nvlist_t
*errors
, size_t max
)
1380 size
= fnvlist_size(errors
);
1383 nvpair_t
*more_errors
;
1387 return (SET_ERROR(ENOMEM
));
1389 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1390 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1393 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1395 fnvlist_remove_nvpair(errors
, pair
);
1397 size
= fnvlist_size(errors
);
1398 } while (size
> max
);
1400 fnvlist_remove_nvpair(errors
, more_errors
);
1401 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1402 ASSERT3U(fnvlist_size(errors
), <=, max
);
1409 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1411 char *packed
= NULL
;
1415 size
= fnvlist_size(nvl
);
1417 if (size
> zc
->zc_nvlist_dst_size
) {
1418 error
= SET_ERROR(ENOMEM
);
1420 packed
= fnvlist_pack(nvl
, &size
);
1421 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1422 size
, zc
->zc_iflags
) != 0)
1423 error
= SET_ERROR(EFAULT
);
1424 fnvlist_pack_free(packed
, size
);
1427 zc
->zc_nvlist_dst_size
= size
;
1428 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1433 getzfsvfs_impl(objset_t
*os
, zfsvfs_t
**zfvp
)
1436 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1437 return (SET_ERROR(EINVAL
));
1440 mutex_enter(&os
->os_user_ptr_lock
);
1441 *zfvp
= dmu_objset_get_user(os
);
1442 /* bump s_active only when non-zero to prevent umount race */
1443 if (*zfvp
== NULL
|| (*zfvp
)->z_sb
== NULL
||
1444 !atomic_inc_not_zero(&((*zfvp
)->z_sb
->s_active
))) {
1445 error
= SET_ERROR(ESRCH
);
1447 mutex_exit(&os
->os_user_ptr_lock
);
1452 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1457 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1461 error
= getzfsvfs_impl(os
, zfvp
);
1462 dmu_objset_rele(os
, FTAG
);
1467 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1468 * case its z_sb will be NULL, and it will be opened as the owner.
1469 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1470 * which prevents all inode ops from running.
1473 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1477 if (getzfsvfs(name
, zfvp
) != 0)
1478 error
= zfsvfs_create(name
, B_FALSE
, zfvp
);
1480 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1482 if ((*zfvp
)->z_unmounted
) {
1484 * XXX we could probably try again, since the unmounting
1485 * thread should be just about to disassociate the
1486 * objset from the zfsvfs.
1488 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1489 return (SET_ERROR(EBUSY
));
1496 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1498 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1501 deactivate_super(zfsvfs
->z_sb
);
1503 dmu_objset_disown(zfsvfs
->z_os
, B_TRUE
, zfsvfs
);
1504 zfsvfs_free(zfsvfs
);
1509 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1512 nvlist_t
*config
, *props
= NULL
;
1513 nvlist_t
*rootprops
= NULL
;
1514 nvlist_t
*zplprops
= NULL
;
1515 dsl_crypto_params_t
*dcp
= NULL
;
1516 char *spa_name
= zc
->zc_name
;
1518 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1519 zc
->zc_iflags
, &config
)))
1522 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1523 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1524 zc
->zc_iflags
, &props
))) {
1525 nvlist_free(config
);
1530 nvlist_t
*nvl
= NULL
;
1531 nvlist_t
*hidden_args
= NULL
;
1532 uint64_t version
= SPA_VERSION
;
1535 (void) nvlist_lookup_uint64(props
,
1536 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1537 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1538 error
= SET_ERROR(EINVAL
);
1539 goto pool_props_bad
;
1541 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1543 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1545 nvlist_free(config
);
1549 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1552 (void) nvlist_lookup_nvlist(props
, ZPOOL_HIDDEN_ARGS
,
1554 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
,
1555 rootprops
, hidden_args
, &dcp
);
1557 nvlist_free(config
);
1561 (void) nvlist_remove_all(props
, ZPOOL_HIDDEN_ARGS
);
1563 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1564 error
= zfs_fill_zplprops_root(version
, rootprops
,
1567 goto pool_props_bad
;
1569 if (nvlist_lookup_string(props
,
1570 zpool_prop_to_name(ZPOOL_PROP_TNAME
), &tname
) == 0)
1574 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
, dcp
);
1577 * Set the remaining root properties
1579 if (!error
&& (error
= zfs_set_prop_nvlist(spa_name
,
1580 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1581 (void) spa_destroy(spa_name
);
1584 nvlist_free(rootprops
);
1585 nvlist_free(zplprops
);
1586 nvlist_free(config
);
1588 dsl_crypto_params_free(dcp
, !!error
);
1594 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1597 zfs_log_history(zc
);
1598 error
= spa_destroy(zc
->zc_name
);
1604 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1606 nvlist_t
*config
, *props
= NULL
;
1610 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1611 zc
->zc_iflags
, &config
)) != 0)
1614 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1615 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1616 zc
->zc_iflags
, &props
))) {
1617 nvlist_free(config
);
1621 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1622 guid
!= zc
->zc_guid
)
1623 error
= SET_ERROR(EINVAL
);
1625 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1627 if (zc
->zc_nvlist_dst
!= 0) {
1630 if ((err
= put_nvlist(zc
, config
)) != 0)
1634 nvlist_free(config
);
1641 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1644 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1645 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1647 zfs_log_history(zc
);
1648 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1654 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1659 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1660 return (SET_ERROR(EEXIST
));
1662 error
= put_nvlist(zc
, configs
);
1664 nvlist_free(configs
);
1671 * zc_name name of the pool
1674 * zc_cookie real errno
1675 * zc_nvlist_dst config nvlist
1676 * zc_nvlist_dst_size size of config nvlist
1679 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1685 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1686 sizeof (zc
->zc_value
));
1688 if (config
!= NULL
) {
1689 ret
= put_nvlist(zc
, config
);
1690 nvlist_free(config
);
1693 * The config may be present even if 'error' is non-zero.
1694 * In this case we return success, and preserve the real errno
1697 zc
->zc_cookie
= error
;
1706 * Try to import the given pool, returning pool stats as appropriate so that
1707 * user land knows which devices are available and overall pool health.
1710 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1712 nvlist_t
*tryconfig
, *config
= NULL
;
1715 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1716 zc
->zc_iflags
, &tryconfig
)) != 0)
1719 config
= spa_tryimport(tryconfig
);
1721 nvlist_free(tryconfig
);
1724 return (SET_ERROR(EINVAL
));
1726 error
= put_nvlist(zc
, config
);
1727 nvlist_free(config
);
1734 * zc_name name of the pool
1735 * zc_cookie scan func (pool_scan_func_t)
1736 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1739 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1744 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1745 return (SET_ERROR(EINVAL
));
1747 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1750 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1751 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1752 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1753 error
= spa_scan_stop(spa
);
1755 error
= spa_scan(spa
, zc
->zc_cookie
);
1757 spa_close(spa
, FTAG
);
1763 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1768 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1771 spa_close(spa
, FTAG
);
1777 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1782 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1785 if (zc
->zc_cookie
< spa_version(spa
) ||
1786 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1787 spa_close(spa
, FTAG
);
1788 return (SET_ERROR(EINVAL
));
1791 spa_upgrade(spa
, zc
->zc_cookie
);
1792 spa_close(spa
, FTAG
);
1798 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1805 if ((size
= zc
->zc_history_len
) == 0)
1806 return (SET_ERROR(EINVAL
));
1808 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1811 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1812 spa_close(spa
, FTAG
);
1813 return (SET_ERROR(ENOTSUP
));
1816 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1817 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1818 &zc
->zc_history_len
, hist_buf
)) == 0) {
1819 error
= ddi_copyout(hist_buf
,
1820 (void *)(uintptr_t)zc
->zc_history
,
1821 zc
->zc_history_len
, zc
->zc_iflags
);
1824 spa_close(spa
, FTAG
);
1825 vmem_free(hist_buf
, size
);
1830 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1835 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1837 error
= spa_change_guid(spa
);
1838 spa_close(spa
, FTAG
);
1844 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1846 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1851 * zc_name name of filesystem
1852 * zc_obj object to find
1855 * zc_value name of object
1858 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1863 /* XXX reading from objset not owned */
1864 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1867 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1868 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1869 return (SET_ERROR(EINVAL
));
1871 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1872 sizeof (zc
->zc_value
));
1873 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1880 * zc_name name of filesystem
1881 * zc_obj object to find
1884 * zc_stat stats on object
1885 * zc_value path to object
1888 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1893 /* XXX reading from objset not owned */
1894 if ((error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
,
1897 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1898 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1899 return (SET_ERROR(EINVAL
));
1901 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1902 sizeof (zc
->zc_value
));
1903 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
1909 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1915 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1919 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1920 zc
->zc_iflags
, &config
);
1922 error
= spa_vdev_add(spa
, config
);
1923 nvlist_free(config
);
1925 spa_close(spa
, FTAG
);
1931 * zc_name name of the pool
1932 * zc_guid guid of vdev to remove
1933 * zc_cookie cancel removal
1936 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1941 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1944 if (zc
->zc_cookie
!= 0) {
1945 error
= spa_vdev_remove_cancel(spa
);
1947 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1949 spa_close(spa
, FTAG
);
1954 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1958 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1960 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1962 switch (zc
->zc_cookie
) {
1963 case VDEV_STATE_ONLINE
:
1964 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1967 case VDEV_STATE_OFFLINE
:
1968 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1971 case VDEV_STATE_FAULTED
:
1972 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1973 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
&&
1974 zc
->zc_obj
!= VDEV_AUX_EXTERNAL_PERSIST
)
1975 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1977 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1980 case VDEV_STATE_DEGRADED
:
1981 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1982 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1983 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1985 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1989 error
= SET_ERROR(EINVAL
);
1991 zc
->zc_cookie
= newstate
;
1992 spa_close(spa
, FTAG
);
1997 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
2000 int replacing
= zc
->zc_cookie
;
2004 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2007 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2008 zc
->zc_iflags
, &config
)) == 0) {
2009 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
2010 nvlist_free(config
);
2013 spa_close(spa
, FTAG
);
2018 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
2023 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2026 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
2028 spa_close(spa
, FTAG
);
2033 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
2036 nvlist_t
*config
, *props
= NULL
;
2038 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
2040 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
2043 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
2044 zc
->zc_iflags
, &config
))) {
2045 spa_close(spa
, FTAG
);
2049 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
2050 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2051 zc
->zc_iflags
, &props
))) {
2052 spa_close(spa
, FTAG
);
2053 nvlist_free(config
);
2057 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
2059 spa_close(spa
, FTAG
);
2061 nvlist_free(config
);
2068 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
2071 char *path
= zc
->zc_value
;
2072 uint64_t guid
= zc
->zc_guid
;
2075 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2079 error
= spa_vdev_setpath(spa
, guid
, path
);
2080 spa_close(spa
, FTAG
);
2085 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
2088 char *fru
= zc
->zc_value
;
2089 uint64_t guid
= zc
->zc_guid
;
2092 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2096 error
= spa_vdev_setfru(spa
, guid
, fru
);
2097 spa_close(spa
, FTAG
);
2102 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2107 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2109 if (zc
->zc_nvlist_dst
!= 0 &&
2110 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2111 dmu_objset_stats(os
, nv
);
2113 * NB: zvol_get_stats() will read the objset contents,
2114 * which we aren't supposed to do with a
2115 * DS_MODE_USER hold, because it could be
2116 * inconsistent. So this is a bit of a workaround...
2117 * XXX reading with out owning
2119 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2120 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2121 error
= zvol_get_stats(os
, nv
);
2129 error
= put_nvlist(zc
, nv
);
2138 * zc_name name of filesystem
2139 * zc_nvlist_dst_size size of buffer for property nvlist
2142 * zc_objset_stats stats
2143 * zc_nvlist_dst property nvlist
2144 * zc_nvlist_dst_size size of property nvlist
2147 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2152 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2154 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2155 dmu_objset_rele(os
, FTAG
);
2163 * zc_name name of filesystem
2164 * zc_nvlist_dst_size size of buffer for property nvlist
2167 * zc_nvlist_dst received property nvlist
2168 * zc_nvlist_dst_size size of received property nvlist
2170 * Gets received properties (distinct from local properties on or after
2171 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2172 * local property values.
2175 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2181 * Without this check, we would return local property values if the
2182 * caller has not already received properties on or after
2183 * SPA_VERSION_RECVD_PROPS.
2185 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2186 return (SET_ERROR(ENOTSUP
));
2188 if (zc
->zc_nvlist_dst
!= 0 &&
2189 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2190 error
= put_nvlist(zc
, nv
);
2198 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2204 * zfs_get_zplprop() will either find a value or give us
2205 * the default value (if there is one).
2207 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2209 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2215 * zc_name name of filesystem
2216 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2219 * zc_nvlist_dst zpl property nvlist
2220 * zc_nvlist_dst_size size of zpl property nvlist
2223 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2228 /* XXX reading without owning */
2229 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2232 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2235 * NB: nvl_add_zplprop() will read the objset contents,
2236 * which we aren't supposed to do with a DS_MODE_USER
2237 * hold, because it could be inconsistent.
2239 if (zc
->zc_nvlist_dst
!= 0 &&
2240 !zc
->zc_objset_stats
.dds_inconsistent
&&
2241 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2244 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2245 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2246 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2247 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2248 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2249 err
= put_nvlist(zc
, nv
);
2252 err
= SET_ERROR(ENOENT
);
2254 dmu_objset_rele(os
, FTAG
);
2260 * zc_name name of filesystem
2261 * zc_cookie zap cursor
2262 * zc_nvlist_dst_size size of buffer for property nvlist
2265 * zc_name name of next filesystem
2266 * zc_cookie zap cursor
2267 * zc_objset_stats stats
2268 * zc_nvlist_dst property nvlist
2269 * zc_nvlist_dst_size size of property nvlist
2272 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2277 size_t orig_len
= strlen(zc
->zc_name
);
2280 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2281 if (error
== ENOENT
)
2282 error
= SET_ERROR(ESRCH
);
2286 p
= strrchr(zc
->zc_name
, '/');
2287 if (p
== NULL
|| p
[1] != '\0')
2288 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2289 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2292 error
= dmu_dir_list_next(os
,
2293 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2294 NULL
, &zc
->zc_cookie
);
2295 if (error
== ENOENT
)
2296 error
= SET_ERROR(ESRCH
);
2297 } while (error
== 0 && zfs_dataset_name_hidden(zc
->zc_name
));
2298 dmu_objset_rele(os
, FTAG
);
2301 * If it's an internal dataset (ie. with a '$' in its name),
2302 * don't try to get stats for it, otherwise we'll return ENOENT.
2304 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2305 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2306 if (error
== ENOENT
) {
2307 /* We lost a race with destroy, get the next one. */
2308 zc
->zc_name
[orig_len
] = '\0';
2317 * zc_name name of filesystem
2318 * zc_cookie zap cursor
2319 * zc_nvlist_src iteration range nvlist
2320 * zc_nvlist_src_size size of iteration range nvlist
2323 * zc_name name of next snapshot
2324 * zc_objset_stats stats
2325 * zc_nvlist_dst property nvlist
2326 * zc_nvlist_dst_size size of property nvlist
2329 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2332 objset_t
*os
, *ossnap
;
2334 uint64_t min_txg
= 0, max_txg
= 0;
2336 if (zc
->zc_nvlist_src_size
!= 0) {
2337 nvlist_t
*props
= NULL
;
2338 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2339 zc
->zc_iflags
, &props
);
2342 (void) nvlist_lookup_uint64(props
, SNAP_ITER_MIN_TXG
,
2344 (void) nvlist_lookup_uint64(props
, SNAP_ITER_MAX_TXG
,
2349 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2351 return (error
== ENOENT
? ESRCH
: error
);
2355 * A dataset name of maximum length cannot have any snapshots,
2356 * so exit immediately.
2358 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2359 ZFS_MAX_DATASET_NAME_LEN
) {
2360 dmu_objset_rele(os
, FTAG
);
2361 return (SET_ERROR(ESRCH
));
2364 while (error
== 0) {
2365 if (issig(JUSTLOOKING
) && issig(FORREAL
)) {
2366 error
= SET_ERROR(EINTR
);
2370 error
= dmu_snapshot_list_next(os
,
2371 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2372 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
,
2373 &zc
->zc_cookie
, NULL
);
2374 if (error
== ENOENT
) {
2375 error
= SET_ERROR(ESRCH
);
2377 } else if (error
!= 0) {
2381 error
= dsl_dataset_hold_obj(dmu_objset_pool(os
), zc
->zc_obj
,
2386 if ((min_txg
!= 0 && dsl_get_creationtxg(ds
) < min_txg
) ||
2387 (max_txg
!= 0 && dsl_get_creationtxg(ds
) > max_txg
)) {
2388 dsl_dataset_rele(ds
, FTAG
);
2389 /* undo snapshot name append */
2390 *(strchr(zc
->zc_name
, '@') + 1) = '\0';
2395 if (zc
->zc_simple
) {
2396 dsl_dataset_rele(ds
, FTAG
);
2400 if ((error
= dmu_objset_from_ds(ds
, &ossnap
)) != 0) {
2401 dsl_dataset_rele(ds
, FTAG
);
2404 if ((error
= zfs_ioc_objset_stats_impl(zc
, ossnap
)) != 0) {
2405 dsl_dataset_rele(ds
, FTAG
);
2408 dsl_dataset_rele(ds
, FTAG
);
2412 dmu_objset_rele(os
, FTAG
);
2413 /* if we failed, undo the @ that we tacked on to zc_name */
2415 *strchr(zc
->zc_name
, '@') = '\0';
2420 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2422 const char *propname
= nvpair_name(pair
);
2424 unsigned int vallen
;
2427 zfs_userquota_prop_t type
;
2433 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2435 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2436 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2438 return (SET_ERROR(EINVAL
));
2442 * A correctly constructed propname is encoded as
2443 * userquota@<rid>-<domain>.
2445 if ((dash
= strchr(propname
, '-')) == NULL
||
2446 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2448 return (SET_ERROR(EINVAL
));
2455 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2457 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2458 zfsvfs_rele(zfsvfs
, FTAG
);
2465 * If the named property is one that has a special function to set its value,
2466 * return 0 on success and a positive error code on failure; otherwise if it is
2467 * not one of the special properties handled by this function, return -1.
2469 * XXX: It would be better for callers of the property interface if we handled
2470 * these special cases in dsl_prop.c (in the dsl layer).
2473 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2476 const char *propname
= nvpair_name(pair
);
2477 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2478 uint64_t intval
= 0;
2479 char *strval
= NULL
;
2482 if (prop
== ZPROP_INVAL
) {
2483 if (zfs_prop_userquota(propname
))
2484 return (zfs_prop_set_userquota(dsname
, pair
));
2488 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2490 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2491 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2495 /* all special properties are numeric except for keylocation */
2496 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
) {
2497 strval
= fnvpair_value_string(pair
);
2499 intval
= fnvpair_value_uint64(pair
);
2503 case ZFS_PROP_QUOTA
:
2504 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2506 case ZFS_PROP_REFQUOTA
:
2507 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2509 case ZFS_PROP_FILESYSTEM_LIMIT
:
2510 case ZFS_PROP_SNAPSHOT_LIMIT
:
2511 if (intval
== UINT64_MAX
) {
2512 /* clearing the limit, just do it */
2515 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2518 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2519 * default path to set the value in the nvlist.
2524 case ZFS_PROP_KEYLOCATION
:
2525 err
= dsl_crypto_can_set_keylocation(dsname
, strval
);
2528 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2529 * default path to set the value in the nvlist.
2534 case ZFS_PROP_RESERVATION
:
2535 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2537 case ZFS_PROP_REFRESERVATION
:
2538 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2540 case ZFS_PROP_VOLSIZE
:
2541 err
= zvol_set_volsize(dsname
, intval
);
2543 case ZFS_PROP_SNAPDEV
:
2544 err
= zvol_set_snapdev(dsname
, source
, intval
);
2546 case ZFS_PROP_VOLMODE
:
2547 err
= zvol_set_volmode(dsname
, source
, intval
);
2549 case ZFS_PROP_VERSION
:
2553 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2556 err
= zfs_set_version(zfsvfs
, intval
);
2557 zfsvfs_rele(zfsvfs
, FTAG
);
2559 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2562 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2563 (void) strcpy(zc
->zc_name
, dsname
);
2564 (void) zfs_ioc_userspace_upgrade(zc
);
2565 (void) zfs_ioc_id_quota_upgrade(zc
);
2566 kmem_free(zc
, sizeof (zfs_cmd_t
));
2578 * This function is best effort. If it fails to set any of the given properties,
2579 * it continues to set as many as it can and returns the last error
2580 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2581 * with the list of names of all the properties that failed along with the
2582 * corresponding error numbers.
2584 * If every property is set successfully, zero is returned and errlist is not
2588 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2597 nvlist_t
*genericnvl
= fnvlist_alloc();
2598 nvlist_t
*retrynvl
= fnvlist_alloc();
2601 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2602 const char *propname
= nvpair_name(pair
);
2603 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2606 /* decode the property value */
2608 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2610 attrs
= fnvpair_value_nvlist(pair
);
2611 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2613 err
= SET_ERROR(EINVAL
);
2616 /* Validate value type */
2617 if (err
== 0 && source
== ZPROP_SRC_INHERITED
) {
2618 /* inherited properties are expected to be booleans */
2619 if (nvpair_type(propval
) != DATA_TYPE_BOOLEAN
)
2620 err
= SET_ERROR(EINVAL
);
2621 } else if (err
== 0 && prop
== ZPROP_INVAL
) {
2622 if (zfs_prop_user(propname
)) {
2623 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2624 err
= SET_ERROR(EINVAL
);
2625 } else if (zfs_prop_userquota(propname
)) {
2626 if (nvpair_type(propval
) !=
2627 DATA_TYPE_UINT64_ARRAY
)
2628 err
= SET_ERROR(EINVAL
);
2630 err
= SET_ERROR(EINVAL
);
2632 } else if (err
== 0) {
2633 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2634 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2635 err
= SET_ERROR(EINVAL
);
2636 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2639 intval
= fnvpair_value_uint64(propval
);
2641 switch (zfs_prop_get_type(prop
)) {
2642 case PROP_TYPE_NUMBER
:
2644 case PROP_TYPE_STRING
:
2645 err
= SET_ERROR(EINVAL
);
2647 case PROP_TYPE_INDEX
:
2648 if (zfs_prop_index_to_string(prop
,
2649 intval
, &unused
) != 0)
2650 err
= SET_ERROR(EINVAL
);
2654 "unknown property type");
2657 err
= SET_ERROR(EINVAL
);
2661 /* Validate permissions */
2663 err
= zfs_check_settable(dsname
, pair
, CRED());
2666 if (source
== ZPROP_SRC_INHERITED
)
2667 err
= -1; /* does not need special handling */
2669 err
= zfs_prop_set_special(dsname
, source
,
2673 * For better performance we build up a list of
2674 * properties to set in a single transaction.
2676 err
= nvlist_add_nvpair(genericnvl
, pair
);
2677 } else if (err
!= 0 && nvl
!= retrynvl
) {
2679 * This may be a spurious error caused by
2680 * receiving quota and reservation out of order.
2681 * Try again in a second pass.
2683 err
= nvlist_add_nvpair(retrynvl
, pair
);
2688 if (errlist
!= NULL
)
2689 fnvlist_add_int32(errlist
, propname
, err
);
2694 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2699 if (!nvlist_empty(genericnvl
) &&
2700 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2702 * If this fails, we still want to set as many properties as we
2703 * can, so try setting them individually.
2706 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2707 const char *propname
= nvpair_name(pair
);
2711 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2713 attrs
= fnvpair_value_nvlist(pair
);
2714 propval
= fnvlist_lookup_nvpair(attrs
,
2718 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2719 strval
= fnvpair_value_string(propval
);
2720 err
= dsl_prop_set_string(dsname
, propname
,
2722 } else if (nvpair_type(propval
) == DATA_TYPE_BOOLEAN
) {
2723 err
= dsl_prop_inherit(dsname
, propname
,
2726 intval
= fnvpair_value_uint64(propval
);
2727 err
= dsl_prop_set_int(dsname
, propname
, source
,
2732 if (errlist
!= NULL
) {
2733 fnvlist_add_int32(errlist
, propname
,
2740 nvlist_free(genericnvl
);
2741 nvlist_free(retrynvl
);
2747 * Check that all the properties are valid user properties.
2750 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2752 nvpair_t
*pair
= NULL
;
2755 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2756 const char *propname
= nvpair_name(pair
);
2758 if (!zfs_prop_user(propname
) ||
2759 nvpair_type(pair
) != DATA_TYPE_STRING
)
2760 return (SET_ERROR(EINVAL
));
2762 if ((error
= zfs_secpolicy_write_perms(fsname
,
2763 ZFS_DELEG_PERM_USERPROP
, CRED())))
2766 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2767 return (SET_ERROR(ENAMETOOLONG
));
2769 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2770 return (SET_ERROR(E2BIG
));
2776 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2780 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2783 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2784 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2787 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2792 clear_received_props(const char *dsname
, nvlist_t
*props
,
2796 nvlist_t
*cleared_props
= NULL
;
2797 props_skip(props
, skipped
, &cleared_props
);
2798 if (!nvlist_empty(cleared_props
)) {
2800 * Acts on local properties until the dataset has received
2801 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2803 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2804 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2805 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2807 nvlist_free(cleared_props
);
2813 * zc_name name of filesystem
2814 * zc_value name of property to set
2815 * zc_nvlist_src{_size} nvlist of properties to apply
2816 * zc_cookie received properties flag
2819 * zc_nvlist_dst{_size} error for each unapplied received property
2822 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2825 boolean_t received
= zc
->zc_cookie
;
2826 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2831 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2832 zc
->zc_iflags
, &nvl
)) != 0)
2836 nvlist_t
*origprops
;
2838 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2839 (void) clear_received_props(zc
->zc_name
,
2841 nvlist_free(origprops
);
2844 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2847 errors
= fnvlist_alloc();
2849 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2851 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2852 (void) put_nvlist(zc
, errors
);
2855 nvlist_free(errors
);
2862 * zc_name name of filesystem
2863 * zc_value name of property to inherit
2864 * zc_cookie revert to received value if TRUE
2869 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2871 const char *propname
= zc
->zc_value
;
2872 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2873 boolean_t received
= zc
->zc_cookie
;
2874 zprop_source_t source
= (received
2875 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2876 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2884 * Only check this in the non-received case. We want to allow
2885 * 'inherit -S' to revert non-inheritable properties like quota
2886 * and reservation to the received or default values even though
2887 * they are not considered inheritable.
2889 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2890 return (SET_ERROR(EINVAL
));
2893 if (prop
== ZPROP_INVAL
) {
2894 if (!zfs_prop_user(propname
))
2895 return (SET_ERROR(EINVAL
));
2897 type
= PROP_TYPE_STRING
;
2898 } else if (prop
== ZFS_PROP_VOLSIZE
|| prop
== ZFS_PROP_VERSION
) {
2899 return (SET_ERROR(EINVAL
));
2901 type
= zfs_prop_get_type(prop
);
2905 * zfs_prop_set_special() expects properties in the form of an
2906 * nvpair with type info.
2908 dummy
= fnvlist_alloc();
2911 case PROP_TYPE_STRING
:
2912 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2914 case PROP_TYPE_NUMBER
:
2915 case PROP_TYPE_INDEX
:
2916 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2919 err
= SET_ERROR(EINVAL
);
2923 pair
= nvlist_next_nvpair(dummy
, NULL
);
2925 err
= SET_ERROR(EINVAL
);
2927 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2928 if (err
== -1) /* property is not "special", needs handling */
2929 err
= dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
,
2939 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2946 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2947 zc
->zc_iflags
, &props
)))
2951 * If the only property is the configfile, then just do a spa_lookup()
2952 * to handle the faulted case.
2954 pair
= nvlist_next_nvpair(props
, NULL
);
2955 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2956 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2957 nvlist_next_nvpair(props
, pair
) == NULL
) {
2958 mutex_enter(&spa_namespace_lock
);
2959 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2960 spa_configfile_set(spa
, props
, B_FALSE
);
2961 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
);
2963 mutex_exit(&spa_namespace_lock
);
2970 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2975 error
= spa_prop_set(spa
, props
);
2978 spa_close(spa
, FTAG
);
2984 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2988 nvlist_t
*nvp
= NULL
;
2990 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2992 * If the pool is faulted, there may be properties we can still
2993 * get (such as altroot and cachefile), so attempt to get them
2996 mutex_enter(&spa_namespace_lock
);
2997 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2998 error
= spa_prop_get(spa
, &nvp
);
2999 mutex_exit(&spa_namespace_lock
);
3001 error
= spa_prop_get(spa
, &nvp
);
3002 spa_close(spa
, FTAG
);
3005 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
3006 error
= put_nvlist(zc
, nvp
);
3008 error
= SET_ERROR(EFAULT
);
3016 * zc_name name of filesystem
3017 * zc_nvlist_src{_size} nvlist of delegated permissions
3018 * zc_perm_action allow/unallow flag
3023 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
3026 nvlist_t
*fsaclnv
= NULL
;
3028 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
3029 zc
->zc_iflags
, &fsaclnv
)) != 0)
3033 * Verify nvlist is constructed correctly
3035 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
3036 nvlist_free(fsaclnv
);
3037 return (SET_ERROR(EINVAL
));
3041 * If we don't have PRIV_SYS_MOUNT, then validate
3042 * that user is allowed to hand out each permission in
3046 error
= secpolicy_zfs(CRED());
3048 if (zc
->zc_perm_action
== B_FALSE
) {
3049 error
= dsl_deleg_can_allow(zc
->zc_name
,
3052 error
= dsl_deleg_can_unallow(zc
->zc_name
,
3058 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
3060 nvlist_free(fsaclnv
);
3066 * zc_name name of filesystem
3069 * zc_nvlist_src{_size} nvlist of delegated permissions
3072 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
3077 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
3078 error
= put_nvlist(zc
, nvp
);
3087 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
3089 zfs_creat_t
*zct
= arg
;
3091 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
3094 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
3098 * os parent objset pointer (NULL if root fs)
3099 * fuids_ok fuids allowed in this version of the spa?
3100 * sa_ok SAs allowed in this version of the spa?
3101 * createprops list of properties requested by creator
3104 * zplprops values for the zplprops we attach to the master node object
3105 * is_ci true if requested file system will be purely case-insensitive
3107 * Determine the settings for utf8only, normalization and
3108 * casesensitivity. Specific values may have been requested by the
3109 * creator and/or we can inherit values from the parent dataset. If
3110 * the file system is of too early a vintage, a creator can not
3111 * request settings for these properties, even if the requested
3112 * setting is the default value. We don't actually want to create dsl
3113 * properties for these, so remove them from the source nvlist after
3117 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
3118 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
3119 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3121 uint64_t sense
= ZFS_PROP_UNDEFINED
;
3122 uint64_t norm
= ZFS_PROP_UNDEFINED
;
3123 uint64_t u8
= ZFS_PROP_UNDEFINED
;
3126 ASSERT(zplprops
!= NULL
);
3128 /* parent dataset must be a filesystem */
3129 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
3130 return (SET_ERROR(ZFS_ERR_WRONG_PARENT
));
3133 * Pull out creator prop choices, if any.
3136 (void) nvlist_lookup_uint64(createprops
,
3137 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
3138 (void) nvlist_lookup_uint64(createprops
,
3139 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
3140 (void) nvlist_remove_all(createprops
,
3141 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3142 (void) nvlist_lookup_uint64(createprops
,
3143 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3144 (void) nvlist_remove_all(createprops
,
3145 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3146 (void) nvlist_lookup_uint64(createprops
,
3147 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3148 (void) nvlist_remove_all(createprops
,
3149 zfs_prop_to_name(ZFS_PROP_CASE
));
3153 * If the zpl version requested is whacky or the file system
3154 * or pool is version is too "young" to support normalization
3155 * and the creator tried to set a value for one of the props,
3158 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3159 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3160 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3161 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3162 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3163 sense
!= ZFS_PROP_UNDEFINED
)))
3164 return (SET_ERROR(ENOTSUP
));
3167 * Put the version in the zplprops
3169 VERIFY(nvlist_add_uint64(zplprops
,
3170 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3172 if (norm
== ZFS_PROP_UNDEFINED
&&
3173 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3175 VERIFY(nvlist_add_uint64(zplprops
,
3176 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3179 * If we're normalizing, names must always be valid UTF-8 strings.
3183 if (u8
== ZFS_PROP_UNDEFINED
&&
3184 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3186 VERIFY(nvlist_add_uint64(zplprops
,
3187 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3189 if (sense
== ZFS_PROP_UNDEFINED
&&
3190 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3192 VERIFY(nvlist_add_uint64(zplprops
,
3193 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3196 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3202 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3203 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3205 boolean_t fuids_ok
, sa_ok
;
3206 uint64_t zplver
= ZPL_VERSION
;
3207 objset_t
*os
= NULL
;
3208 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3213 zfs_get_parent(dataset
, parentname
, sizeof (parentname
));
3215 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3218 spa_vers
= spa_version(spa
);
3219 spa_close(spa
, FTAG
);
3221 zplver
= zfs_zpl_version_map(spa_vers
);
3222 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3223 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3226 * Open parent object set so we can inherit zplprop values.
3228 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3231 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3233 dmu_objset_rele(os
, FTAG
);
3238 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3239 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3243 uint64_t zplver
= ZPL_VERSION
;
3246 zplver
= zfs_zpl_version_map(spa_vers
);
3247 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3248 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3250 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3251 createprops
, zplprops
, is_ci
);
3257 * "type" -> dmu_objset_type_t (int32)
3258 * (optional) "props" -> { prop -> value }
3259 * (optional) "hidden_args" -> { "wkeydata" -> value }
3260 * raw uint8_t array of encryption wrapping key data (32 bytes)
3263 * outnvl: propname -> error code (int32)
3266 static const zfs_ioc_key_t zfs_keys_create
[] = {
3267 {"type", DATA_TYPE_INT32
, 0},
3268 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3269 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3273 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3276 zfs_creat_t zct
= { 0 };
3277 nvlist_t
*nvprops
= NULL
;
3278 nvlist_t
*hidden_args
= NULL
;
3279 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3280 dmu_objset_type_t type
;
3281 boolean_t is_insensitive
= B_FALSE
;
3282 dsl_crypto_params_t
*dcp
= NULL
;
3284 type
= (dmu_objset_type_t
)fnvlist_lookup_int32(innvl
, "type");
3285 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3286 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
3290 cbfunc
= zfs_create_cb
;
3294 cbfunc
= zvol_create_cb
;
3301 if (strchr(fsname
, '@') ||
3302 strchr(fsname
, '%'))
3303 return (SET_ERROR(EINVAL
));
3305 zct
.zct_props
= nvprops
;
3308 return (SET_ERROR(EINVAL
));
3310 if (type
== DMU_OST_ZVOL
) {
3311 uint64_t volsize
, volblocksize
;
3313 if (nvprops
== NULL
)
3314 return (SET_ERROR(EINVAL
));
3315 if (nvlist_lookup_uint64(nvprops
,
3316 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3317 return (SET_ERROR(EINVAL
));
3319 if ((error
= nvlist_lookup_uint64(nvprops
,
3320 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3321 &volblocksize
)) != 0 && error
!= ENOENT
)
3322 return (SET_ERROR(EINVAL
));
3325 volblocksize
= zfs_prop_default_numeric(
3326 ZFS_PROP_VOLBLOCKSIZE
);
3328 if ((error
= zvol_check_volblocksize(fsname
,
3329 volblocksize
)) != 0 ||
3330 (error
= zvol_check_volsize(volsize
,
3331 volblocksize
)) != 0)
3333 } else if (type
== DMU_OST_ZFS
) {
3337 * We have to have normalization and
3338 * case-folding flags correct when we do the
3339 * file system creation, so go figure them out
3342 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3343 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3344 error
= zfs_fill_zplprops(fsname
, nvprops
,
3345 zct
.zct_zplprops
, &is_insensitive
);
3347 nvlist_free(zct
.zct_zplprops
);
3352 error
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, nvprops
,
3355 nvlist_free(zct
.zct_zplprops
);
3359 error
= dmu_objset_create(fsname
, type
,
3360 is_insensitive
? DS_FLAG_CI_DATASET
: 0, dcp
, cbfunc
, &zct
);
3362 nvlist_free(zct
.zct_zplprops
);
3363 dsl_crypto_params_free(dcp
, !!error
);
3366 * It would be nice to do this atomically.
3369 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3376 * Volumes will return EBUSY and cannot be destroyed
3377 * until all asynchronous minor handling has completed.
3378 * Wait for the spa_zvol_taskq to drain then retry.
3380 error2
= dsl_destroy_head(fsname
);
3381 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3382 error2
= spa_open(fsname
, &spa
, FTAG
);
3384 taskq_wait(spa
->spa_zvol_taskq
);
3385 spa_close(spa
, FTAG
);
3387 error2
= dsl_destroy_head(fsname
);
3396 * "origin" -> name of origin snapshot
3397 * (optional) "props" -> { prop -> value }
3398 * (optional) "hidden_args" -> { "wkeydata" -> value }
3399 * raw uint8_t array of encryption wrapping key data (32 bytes)
3403 * outnvl: propname -> error code (int32)
3405 static const zfs_ioc_key_t zfs_keys_clone
[] = {
3406 {"origin", DATA_TYPE_STRING
, 0},
3407 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3408 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3412 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3415 nvlist_t
*nvprops
= NULL
;
3418 origin_name
= fnvlist_lookup_string(innvl
, "origin");
3419 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3421 if (strchr(fsname
, '@') ||
3422 strchr(fsname
, '%'))
3423 return (SET_ERROR(EINVAL
));
3425 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3426 return (SET_ERROR(EINVAL
));
3428 error
= dmu_objset_clone(fsname
, origin_name
);
3431 * It would be nice to do this atomically.
3434 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3437 (void) dsl_destroy_head(fsname
);
3442 static const zfs_ioc_key_t zfs_keys_remap
[] = {
3448 zfs_ioc_remap(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3450 if (strchr(fsname
, '@') ||
3451 strchr(fsname
, '%'))
3452 return (SET_ERROR(EINVAL
));
3454 return (dmu_objset_remap_indirects(fsname
));
3459 * "snaps" -> { snapshot1, snapshot2 }
3460 * (optional) "props" -> { prop -> value (string) }
3463 * outnvl: snapshot -> error code (int32)
3465 static const zfs_ioc_key_t zfs_keys_snapshot
[] = {
3466 {"snaps", DATA_TYPE_NVLIST
, 0},
3467 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
3471 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3474 nvlist_t
*props
= NULL
;
3478 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3479 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3482 if (!nvlist_empty(props
) &&
3483 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3484 return (SET_ERROR(ENOTSUP
));
3486 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
3487 poollen
= strlen(poolname
);
3488 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3489 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3490 const char *name
= nvpair_name(pair
);
3491 const char *cp
= strchr(name
, '@');
3494 * The snap name must contain an @, and the part after it must
3495 * contain only valid characters.
3498 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3499 return (SET_ERROR(EINVAL
));
3502 * The snap must be in the specified pool.
3504 if (strncmp(name
, poolname
, poollen
) != 0 ||
3505 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3506 return (SET_ERROR(EXDEV
));
3508 /* This must be the only snap of this fs. */
3509 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3510 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3511 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3513 return (SET_ERROR(EXDEV
));
3518 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3524 * innvl: "message" -> string
3526 static const zfs_ioc_key_t zfs_keys_log_history
[] = {
3527 {"message", DATA_TYPE_STRING
, 0},
3532 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3540 * The poolname in the ioctl is not set, we get it from the TSD,
3541 * which was set at the end of the last successful ioctl that allows
3542 * logging. The secpolicy func already checked that it is set.
3543 * Only one log ioctl is allowed after each successful ioctl, so
3544 * we clear the TSD here.
3546 poolname
= tsd_get(zfs_allow_log_key
);
3547 if (poolname
== NULL
)
3548 return (SET_ERROR(EINVAL
));
3549 (void) tsd_set(zfs_allow_log_key
, NULL
);
3550 error
= spa_open(poolname
, &spa
, FTAG
);
3555 message
= fnvlist_lookup_string(innvl
, "message");
3557 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3558 spa_close(spa
, FTAG
);
3559 return (SET_ERROR(ENOTSUP
));
3562 error
= spa_history_log(spa
, message
);
3563 spa_close(spa
, FTAG
);
3568 * The dp_config_rwlock must not be held when calling this, because the
3569 * unmount may need to write out data.
3571 * This function is best-effort. Callers must deal gracefully if it
3572 * remains mounted (or is remounted after this call).
3574 * Returns 0 if the argument is not a snapshot, or it is not currently a
3575 * filesystem, or we were able to unmount it. Returns error code otherwise.
3578 zfs_unmount_snap(const char *snapname
)
3580 if (strchr(snapname
, '@') == NULL
)
3583 (void) zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3588 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3590 zfs_unmount_snap(snapname
);
3595 * When a clone is destroyed, its origin may also need to be destroyed,
3596 * in which case it must be unmounted. This routine will do that unmount
3600 zfs_destroy_unmount_origin(const char *fsname
)
3606 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3609 ds
= dmu_objset_ds(os
);
3610 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3611 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3612 dsl_dataset_name(ds
->ds_prev
, originname
);
3613 dmu_objset_rele(os
, FTAG
);
3614 zfs_unmount_snap(originname
);
3616 dmu_objset_rele(os
, FTAG
);
3622 * "snaps" -> { snapshot1, snapshot2 }
3623 * (optional boolean) "defer"
3626 * outnvl: snapshot -> error code (int32)
3628 static const zfs_ioc_key_t zfs_keys_destroy_snaps
[] = {
3629 {"snaps", DATA_TYPE_NVLIST
, 0},
3630 {"defer", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
3635 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3641 snaps
= fnvlist_lookup_nvlist(innvl
, "snaps");
3642 defer
= nvlist_exists(innvl
, "defer");
3644 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3645 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3646 zfs_unmount_snap(nvpair_name(pair
));
3649 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3653 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3654 * All bookmarks must be in the same pool.
3657 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3660 * outnvl: bookmark -> error code (int32)
3663 static const zfs_ioc_key_t zfs_keys_bookmark
[] = {
3664 {"<bookmark>...", DATA_TYPE_STRING
, ZK_WILDCARDLIST
},
3669 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3671 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3672 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3676 * Verify the snapshot argument.
3678 if (nvpair_value_string(pair
, &snap_name
) != 0)
3679 return (SET_ERROR(EINVAL
));
3682 /* Verify that the keys (bookmarks) are unique */
3683 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3684 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3685 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3686 return (SET_ERROR(EINVAL
));
3690 return (dsl_bookmark_create(innvl
, outnvl
));
3695 * property 1, property 2, ...
3699 * bookmark name 1 -> { property 1, property 2, ... },
3700 * bookmark name 2 -> { property 1, property 2, ... }
3704 static const zfs_ioc_key_t zfs_keys_get_bookmarks
[] = {
3705 {"<property>...", DATA_TYPE_BOOLEAN
, ZK_WILDCARDLIST
| ZK_OPTIONAL
},
3709 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3711 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3716 * bookmark name 1, bookmark name 2
3719 * outnvl: bookmark -> error code (int32)
3722 static const zfs_ioc_key_t zfs_keys_destroy_bookmarks
[] = {
3723 {"<bookmark>...", DATA_TYPE_BOOLEAN
, ZK_WILDCARDLIST
},
3727 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3732 poollen
= strlen(poolname
);
3733 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3734 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3735 const char *name
= nvpair_name(pair
);
3736 const char *cp
= strchr(name
, '#');
3739 * The bookmark name must contain an #, and the part after it
3740 * must contain only valid characters.
3743 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3744 return (SET_ERROR(EINVAL
));
3747 * The bookmark must be in the specified pool.
3749 if (strncmp(name
, poolname
, poollen
) != 0 ||
3750 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3751 return (SET_ERROR(EXDEV
));
3754 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3758 static const zfs_ioc_key_t zfs_keys_channel_program
[] = {
3759 {"program", DATA_TYPE_STRING
, 0},
3760 {"arg", DATA_TYPE_ANY
, 0},
3761 {"sync", DATA_TYPE_BOOLEAN_VALUE
, ZK_OPTIONAL
},
3762 {"instrlimit", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
3763 {"memlimit", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
3767 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3771 uint64_t instrlimit
, memlimit
;
3772 boolean_t sync_flag
;
3773 nvpair_t
*nvarg
= NULL
;
3775 program
= fnvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
);
3776 if (0 != nvlist_lookup_boolean_value(innvl
, ZCP_ARG_SYNC
, &sync_flag
)) {
3779 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3780 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3782 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3783 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3785 nvarg
= fnvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
);
3787 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3789 if (memlimit
== 0 || memlimit
> zfs_lua_max_memlimit
)
3792 return (zcp_eval(poolname
, program
, sync_flag
, instrlimit
, memlimit
,
3800 static const zfs_ioc_key_t zfs_keys_pool_checkpoint
[] = {
3806 zfs_ioc_pool_checkpoint(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3808 return (spa_checkpoint(poolname
));
3815 static const zfs_ioc_key_t zfs_keys_pool_discard_checkpoint
[] = {
3821 zfs_ioc_pool_discard_checkpoint(const char *poolname
, nvlist_t
*innvl
,
3824 return (spa_checkpoint_discard(poolname
));
3829 * zc_name name of dataset to destroy
3830 * zc_defer_destroy mark for deferred destroy
3835 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3838 dmu_objset_type_t ost
;
3841 err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
3844 ost
= dmu_objset_type(os
);
3845 dmu_objset_rele(os
, FTAG
);
3847 if (ost
== DMU_OST_ZFS
)
3848 zfs_unmount_snap(zc
->zc_name
);
3850 if (strchr(zc
->zc_name
, '@')) {
3851 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3853 err
= dsl_destroy_head(zc
->zc_name
);
3854 if (err
== EEXIST
) {
3856 * It is possible that the given DS may have
3857 * hidden child (%recv) datasets - "leftovers"
3858 * resulting from the previously interrupted
3861 * 6 extra bytes for /%recv
3863 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3865 if (snprintf(namebuf
, sizeof (namebuf
), "%s/%s",
3866 zc
->zc_name
, recv_clone_name
) >=
3868 return (SET_ERROR(EINVAL
));
3871 * Try to remove the hidden child (%recv) and after
3872 * that try to remove the target dataset.
3873 * If the hidden child (%recv) does not exist
3874 * the original error (EEXIST) will be returned
3876 err
= dsl_destroy_head(namebuf
);
3878 err
= dsl_destroy_head(zc
->zc_name
);
3879 else if (err
== ENOENT
)
3880 err
= SET_ERROR(EEXIST
);
3889 * "initialize_command" -> POOL_INITIALIZE_{CANCEL|START|SUSPEND} (uint64)
3890 * "initialize_vdevs": { -> guids to initialize (nvlist)
3891 * "vdev_path_1": vdev_guid_1, (uint64),
3892 * "vdev_path_2": vdev_guid_2, (uint64),
3898 * "initialize_vdevs": { -> initialization errors (nvlist)
3899 * "vdev_path_1": errno, see function body for possible errnos (uint64)
3900 * "vdev_path_2": errno, ... (uint64)
3905 * EINVAL is returned for an unknown commands or if any of the provided vdev
3906 * guids have be specified with a type other than uint64.
3908 static const zfs_ioc_key_t zfs_keys_pool_initialize
[] = {
3909 {ZPOOL_INITIALIZE_COMMAND
, DATA_TYPE_UINT64
, 0},
3910 {ZPOOL_INITIALIZE_VDEVS
, DATA_TYPE_NVLIST
, 0}
3914 zfs_ioc_pool_initialize(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3917 if (nvlist_lookup_uint64(innvl
, ZPOOL_INITIALIZE_COMMAND
,
3919 return (SET_ERROR(EINVAL
));
3922 if (!(cmd_type
== POOL_INITIALIZE_CANCEL
||
3923 cmd_type
== POOL_INITIALIZE_START
||
3924 cmd_type
== POOL_INITIALIZE_SUSPEND
)) {
3925 return (SET_ERROR(EINVAL
));
3928 nvlist_t
*vdev_guids
;
3929 if (nvlist_lookup_nvlist(innvl
, ZPOOL_INITIALIZE_VDEVS
,
3930 &vdev_guids
) != 0) {
3931 return (SET_ERROR(EINVAL
));
3934 for (nvpair_t
*pair
= nvlist_next_nvpair(vdev_guids
, NULL
);
3935 pair
!= NULL
; pair
= nvlist_next_nvpair(vdev_guids
, pair
)) {
3937 if (nvpair_value_uint64(pair
, &vdev_guid
) != 0) {
3938 return (SET_ERROR(EINVAL
));
3943 int error
= spa_open(poolname
, &spa
, FTAG
);
3947 nvlist_t
*vdev_errlist
= fnvlist_alloc();
3948 int total_errors
= spa_vdev_initialize(spa
, vdev_guids
, cmd_type
,
3951 if (fnvlist_size(vdev_errlist
) > 0) {
3952 fnvlist_add_nvlist(outnvl
, ZPOOL_INITIALIZE_VDEVS
,
3955 fnvlist_free(vdev_errlist
);
3957 spa_close(spa
, FTAG
);
3958 return (total_errors
> 0 ? EINVAL
: 0);
3963 * "trim_command" -> POOL_TRIM_{CANCEL|START|SUSPEND} (uint64)
3964 * "trim_vdevs": { -> guids to TRIM (nvlist)
3965 * "vdev_path_1": vdev_guid_1, (uint64),
3966 * "vdev_path_2": vdev_guid_2, (uint64),
3969 * "trim_rate" -> Target TRIM rate in bytes/sec.
3970 * "trim_secure" -> Set to request a secure TRIM.
3974 * "trim_vdevs": { -> TRIM errors (nvlist)
3975 * "vdev_path_1": errno, see function body for possible errnos (uint64)
3976 * "vdev_path_2": errno, ... (uint64)
3981 * EINVAL is returned for an unknown commands or if any of the provided vdev
3982 * guids have be specified with a type other than uint64.
3984 static const zfs_ioc_key_t zfs_keys_pool_trim
[] = {
3985 {ZPOOL_TRIM_COMMAND
, DATA_TYPE_UINT64
, 0},
3986 {ZPOOL_TRIM_VDEVS
, DATA_TYPE_NVLIST
, 0},
3987 {ZPOOL_TRIM_RATE
, DATA_TYPE_UINT64
, ZK_OPTIONAL
},
3988 {ZPOOL_TRIM_SECURE
, DATA_TYPE_BOOLEAN_VALUE
, ZK_OPTIONAL
},
3992 zfs_ioc_pool_trim(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3995 if (nvlist_lookup_uint64(innvl
, ZPOOL_TRIM_COMMAND
, &cmd_type
) != 0)
3996 return (SET_ERROR(EINVAL
));
3998 if (!(cmd_type
== POOL_TRIM_CANCEL
||
3999 cmd_type
== POOL_TRIM_START
||
4000 cmd_type
== POOL_TRIM_SUSPEND
)) {
4001 return (SET_ERROR(EINVAL
));
4004 nvlist_t
*vdev_guids
;
4005 if (nvlist_lookup_nvlist(innvl
, ZPOOL_TRIM_VDEVS
, &vdev_guids
) != 0)
4006 return (SET_ERROR(EINVAL
));
4008 for (nvpair_t
*pair
= nvlist_next_nvpair(vdev_guids
, NULL
);
4009 pair
!= NULL
; pair
= nvlist_next_nvpair(vdev_guids
, pair
)) {
4011 if (nvpair_value_uint64(pair
, &vdev_guid
) != 0) {
4012 return (SET_ERROR(EINVAL
));
4016 /* Optional, defaults to maximum rate when not provided */
4018 if (nvlist_lookup_uint64(innvl
, ZPOOL_TRIM_RATE
, &rate
) != 0)
4021 /* Optional, defaults to standard TRIM when not provided */
4023 if (nvlist_lookup_boolean_value(innvl
, ZPOOL_TRIM_SECURE
,
4029 int error
= spa_open(poolname
, &spa
, FTAG
);
4033 nvlist_t
*vdev_errlist
= fnvlist_alloc();
4034 int total_errors
= spa_vdev_trim(spa
, vdev_guids
, cmd_type
,
4035 rate
, !!zfs_trim_metaslab_skip
, secure
, vdev_errlist
);
4037 if (fnvlist_size(vdev_errlist
) > 0)
4038 fnvlist_add_nvlist(outnvl
, ZPOOL_TRIM_VDEVS
, vdev_errlist
);
4040 fnvlist_free(vdev_errlist
);
4042 spa_close(spa
, FTAG
);
4043 return (total_errors
> 0 ? EINVAL
: 0);
4047 * fsname is name of dataset to rollback (to most recent snapshot)
4049 * innvl may contain name of expected target snapshot
4051 * outnvl: "target" -> name of most recent snapshot
4054 static const zfs_ioc_key_t zfs_keys_rollback
[] = {
4055 {"target", DATA_TYPE_STRING
, ZK_OPTIONAL
},
4060 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4064 char *target
= NULL
;
4067 (void) nvlist_lookup_string(innvl
, "target", &target
);
4068 if (target
!= NULL
) {
4069 const char *cp
= strchr(target
, '@');
4072 * The snap name must contain an @, and the part after it must
4073 * contain only valid characters.
4076 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
4077 return (SET_ERROR(EINVAL
));
4080 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
4083 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4084 error
= zfs_suspend_fs(zfsvfs
);
4088 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
4090 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
4091 error
= error
? error
: resume_err
;
4093 deactivate_super(zfsvfs
->z_sb
);
4094 } else if ((zv
= zvol_suspend(fsname
)) != NULL
) {
4095 error
= dsl_dataset_rollback(fsname
, target
, zvol_tag(zv
),
4099 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
4105 recursive_unmount(const char *fsname
, void *arg
)
4107 const char *snapname
= arg
;
4110 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
4111 zfs_unmount_snap(fullname
);
4119 * zc_name old name of dataset
4120 * zc_value new name of dataset
4121 * zc_cookie recursive flag (only valid for snapshots)
4126 zfs_ioc_rename(zfs_cmd_t
*zc
)
4129 dmu_objset_type_t ost
;
4130 boolean_t recursive
= zc
->zc_cookie
& 1;
4134 /* "zfs rename" from and to ...%recv datasets should both fail */
4135 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
4136 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
4137 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
4138 dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4139 strchr(zc
->zc_name
, '%') || strchr(zc
->zc_value
, '%'))
4140 return (SET_ERROR(EINVAL
));
4142 err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4145 ost
= dmu_objset_type(os
);
4146 dmu_objset_rele(os
, FTAG
);
4148 at
= strchr(zc
->zc_name
, '@');
4150 /* snaps must be in same fs */
4153 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
4154 return (SET_ERROR(EXDEV
));
4156 if (ost
== DMU_OST_ZFS
) {
4157 error
= dmu_objset_find(zc
->zc_name
,
4158 recursive_unmount
, at
+ 1,
4159 recursive
? DS_FIND_CHILDREN
: 0);
4165 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
4166 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
4171 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
4176 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
4178 const char *propname
= nvpair_name(pair
);
4179 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
4180 zfs_prop_t prop
= zfs_name_to_prop(propname
);
4184 if (prop
== ZPROP_INVAL
) {
4185 if (zfs_prop_user(propname
)) {
4186 if ((err
= zfs_secpolicy_write_perms(dsname
,
4187 ZFS_DELEG_PERM_USERPROP
, cr
)))
4192 if (!issnap
&& zfs_prop_userquota(propname
)) {
4193 const char *perm
= NULL
;
4194 const char *uq_prefix
=
4195 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
4196 const char *gq_prefix
=
4197 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
4198 const char *uiq_prefix
=
4199 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
];
4200 const char *giq_prefix
=
4201 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
];
4202 const char *pq_prefix
=
4203 zfs_userquota_prop_prefixes
[ZFS_PROP_PROJECTQUOTA
];
4204 const char *piq_prefix
= zfs_userquota_prop_prefixes
[\
4205 ZFS_PROP_PROJECTOBJQUOTA
];
4207 if (strncmp(propname
, uq_prefix
,
4208 strlen(uq_prefix
)) == 0) {
4209 perm
= ZFS_DELEG_PERM_USERQUOTA
;
4210 } else if (strncmp(propname
, uiq_prefix
,
4211 strlen(uiq_prefix
)) == 0) {
4212 perm
= ZFS_DELEG_PERM_USEROBJQUOTA
;
4213 } else if (strncmp(propname
, gq_prefix
,
4214 strlen(gq_prefix
)) == 0) {
4215 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
4216 } else if (strncmp(propname
, giq_prefix
,
4217 strlen(giq_prefix
)) == 0) {
4218 perm
= ZFS_DELEG_PERM_GROUPOBJQUOTA
;
4219 } else if (strncmp(propname
, pq_prefix
,
4220 strlen(pq_prefix
)) == 0) {
4221 perm
= ZFS_DELEG_PERM_PROJECTQUOTA
;
4222 } else if (strncmp(propname
, piq_prefix
,
4223 strlen(piq_prefix
)) == 0) {
4224 perm
= ZFS_DELEG_PERM_PROJECTOBJQUOTA
;
4226 /* {USER|GROUP|PROJECT}USED are read-only */
4227 return (SET_ERROR(EINVAL
));
4230 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
4235 return (SET_ERROR(EINVAL
));
4239 return (SET_ERROR(EINVAL
));
4241 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
4243 * dsl_prop_get_all_impl() returns properties in this
4247 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
4248 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4253 * Check that this value is valid for this pool version
4256 case ZFS_PROP_COMPRESSION
:
4258 * If the user specified gzip compression, make sure
4259 * the SPA supports it. We ignore any errors here since
4260 * we'll catch them later.
4262 if (nvpair_value_uint64(pair
, &intval
) == 0) {
4263 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
4264 intval
<= ZIO_COMPRESS_GZIP_9
&&
4265 zfs_earlier_version(dsname
,
4266 SPA_VERSION_GZIP_COMPRESSION
)) {
4267 return (SET_ERROR(ENOTSUP
));
4270 if (intval
== ZIO_COMPRESS_ZLE
&&
4271 zfs_earlier_version(dsname
,
4272 SPA_VERSION_ZLE_COMPRESSION
))
4273 return (SET_ERROR(ENOTSUP
));
4275 if (intval
== ZIO_COMPRESS_LZ4
) {
4278 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4281 if (!spa_feature_is_enabled(spa
,
4282 SPA_FEATURE_LZ4_COMPRESS
)) {
4283 spa_close(spa
, FTAG
);
4284 return (SET_ERROR(ENOTSUP
));
4286 spa_close(spa
, FTAG
);
4290 * If this is a bootable dataset then
4291 * verify that the compression algorithm
4292 * is supported for booting. We must return
4293 * something other than ENOTSUP since it
4294 * implies a downrev pool version.
4296 if (zfs_is_bootfs(dsname
) &&
4297 !BOOTFS_COMPRESS_VALID(intval
)) {
4298 return (SET_ERROR(ERANGE
));
4303 case ZFS_PROP_COPIES
:
4304 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
4305 return (SET_ERROR(ENOTSUP
));
4308 case ZFS_PROP_VOLBLOCKSIZE
:
4309 case ZFS_PROP_RECORDSIZE
:
4310 /* Record sizes above 128k need the feature to be enabled */
4311 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4312 intval
> SPA_OLD_MAXBLOCKSIZE
) {
4316 * We don't allow setting the property above 1MB,
4317 * unless the tunable has been changed.
4319 if (intval
> zfs_max_recordsize
||
4320 intval
> SPA_MAXBLOCKSIZE
)
4321 return (SET_ERROR(ERANGE
));
4323 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4326 if (!spa_feature_is_enabled(spa
,
4327 SPA_FEATURE_LARGE_BLOCKS
)) {
4328 spa_close(spa
, FTAG
);
4329 return (SET_ERROR(ENOTSUP
));
4331 spa_close(spa
, FTAG
);
4335 case ZFS_PROP_DNODESIZE
:
4336 /* Dnode sizes above 512 need the feature to be enabled */
4337 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
4338 intval
!= ZFS_DNSIZE_LEGACY
) {
4342 * If this is a bootable dataset then
4343 * we don't allow large (>512B) dnodes,
4344 * because GRUB doesn't support them.
4346 if (zfs_is_bootfs(dsname
) &&
4347 intval
!= ZFS_DNSIZE_LEGACY
) {
4348 return (SET_ERROR(EDOM
));
4351 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4354 if (!spa_feature_is_enabled(spa
,
4355 SPA_FEATURE_LARGE_DNODE
)) {
4356 spa_close(spa
, FTAG
);
4357 return (SET_ERROR(ENOTSUP
));
4359 spa_close(spa
, FTAG
);
4363 case ZFS_PROP_SPECIAL_SMALL_BLOCKS
:
4365 * This property could require the allocation classes
4366 * feature to be active for setting, however we allow
4367 * it so that tests of settable properties succeed.
4368 * The CLI will issue a warning in this case.
4372 case ZFS_PROP_SHARESMB
:
4373 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
4374 return (SET_ERROR(ENOTSUP
));
4377 case ZFS_PROP_ACLINHERIT
:
4378 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4379 nvpair_value_uint64(pair
, &intval
) == 0) {
4380 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
4381 zfs_earlier_version(dsname
,
4382 SPA_VERSION_PASSTHROUGH_X
))
4383 return (SET_ERROR(ENOTSUP
));
4386 case ZFS_PROP_CHECKSUM
:
4387 case ZFS_PROP_DEDUP
:
4389 spa_feature_t feature
;
4393 /* dedup feature version checks */
4394 if (prop
== ZFS_PROP_DEDUP
&&
4395 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
4396 return (SET_ERROR(ENOTSUP
));
4398 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
4399 nvpair_value_uint64(pair
, &intval
) == 0) {
4400 /* check prop value is enabled in features */
4401 feature
= zio_checksum_to_feature(
4402 intval
& ZIO_CHECKSUM_MASK
);
4403 if (feature
== SPA_FEATURE_NONE
)
4406 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
4409 if (!spa_feature_is_enabled(spa
, feature
)) {
4410 spa_close(spa
, FTAG
);
4411 return (SET_ERROR(ENOTSUP
));
4413 spa_close(spa
, FTAG
);
4422 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
4426 * Removes properties from the given props list that fail permission checks
4427 * needed to clear them and to restore them in case of a receive error. For each
4428 * property, make sure we have both set and inherit permissions.
4430 * Returns the first error encountered if any permission checks fail. If the
4431 * caller provides a non-NULL errlist, it also gives the complete list of names
4432 * of all the properties that failed a permission check along with the
4433 * corresponding error numbers. The caller is responsible for freeing the
4436 * If every property checks out successfully, zero is returned and the list
4437 * pointed at by errlist is NULL.
4440 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
4443 nvpair_t
*pair
, *next_pair
;
4450 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4452 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
4453 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
4454 pair
= nvlist_next_nvpair(props
, NULL
);
4455 while (pair
!= NULL
) {
4456 next_pair
= nvlist_next_nvpair(props
, pair
);
4458 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
4459 sizeof (zc
->zc_value
));
4460 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
4461 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
4462 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
4463 VERIFY(nvlist_add_int32(errors
,
4464 zc
->zc_value
, err
) == 0);
4468 kmem_free(zc
, sizeof (zfs_cmd_t
));
4470 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
4471 nvlist_free(errors
);
4474 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
4477 if (errlist
== NULL
)
4478 nvlist_free(errors
);
4486 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4488 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4489 /* dsl_prop_get_all_impl() format */
4491 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4492 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4496 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4498 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4499 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4503 if (nvpair_type(p1
) != nvpair_type(p2
))
4506 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4507 char *valstr1
, *valstr2
;
4509 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4510 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4511 return (strcmp(valstr1
, valstr2
) == 0);
4513 uint64_t intval1
, intval2
;
4515 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4516 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4517 return (intval1
== intval2
);
4522 * Remove properties from props if they are not going to change (as determined
4523 * by comparison with origprops). Remove them from origprops as well, since we
4524 * do not need to clear or restore properties that won't change.
4527 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4529 nvpair_t
*pair
, *next_pair
;
4531 if (origprops
== NULL
)
4532 return; /* all props need to be received */
4534 pair
= nvlist_next_nvpair(props
, NULL
);
4535 while (pair
!= NULL
) {
4536 const char *propname
= nvpair_name(pair
);
4539 next_pair
= nvlist_next_nvpair(props
, pair
);
4541 if ((nvlist_lookup_nvpair(origprops
, propname
,
4542 &match
) != 0) || !propval_equals(pair
, match
))
4543 goto next
; /* need to set received value */
4545 /* don't clear the existing received value */
4546 (void) nvlist_remove_nvpair(origprops
, match
);
4547 /* don't bother receiving the property */
4548 (void) nvlist_remove_nvpair(props
, pair
);
4555 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4556 * For example, refquota cannot be set until after the receipt of a dataset,
4557 * because in replication streams, an older/earlier snapshot may exceed the
4558 * refquota. We want to receive the older/earlier snapshot, but setting
4559 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4560 * the older/earlier snapshot from being received (with EDQUOT).
4562 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4564 * libzfs will need to be judicious handling errors encountered by props
4565 * extracted by this function.
4568 extract_delay_props(nvlist_t
*props
)
4570 nvlist_t
*delayprops
;
4571 nvpair_t
*nvp
, *tmp
;
4572 static const zfs_prop_t delayable
[] = {
4574 ZFS_PROP_KEYLOCATION
,
4579 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4581 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4582 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4584 * strcmp() is safe because zfs_prop_to_name() always returns
4587 for (i
= 0; delayable
[i
] != 0; i
++) {
4588 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4589 nvpair_name(nvp
)) == 0) {
4593 if (delayable
[i
] != 0) {
4594 tmp
= nvlist_prev_nvpair(props
, nvp
);
4595 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4596 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4601 if (nvlist_empty(delayprops
)) {
4602 nvlist_free(delayprops
);
4605 return (delayprops
);
4609 static boolean_t zfs_ioc_recv_inject_err
;
4613 * nvlist 'errors' is always allocated. It will contain descriptions of
4614 * encountered errors, if any. It's the callers responsibility to free.
4617 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
, nvlist_t
*recvprops
,
4618 nvlist_t
*localprops
, nvlist_t
*hidden_args
, boolean_t force
,
4619 boolean_t resumable
, int input_fd
, dmu_replay_record_t
*begin_record
,
4620 int cleanup_fd
, uint64_t *read_bytes
, uint64_t *errflags
,
4621 uint64_t *action_handle
, nvlist_t
**errors
)
4623 dmu_recv_cookie_t drc
;
4625 int props_error
= 0;
4627 nvlist_t
*local_delayprops
= NULL
;
4628 nvlist_t
*recv_delayprops
= NULL
;
4629 nvlist_t
*origprops
= NULL
; /* existing properties */
4630 nvlist_t
*origrecvd
= NULL
; /* existing received properties */
4631 boolean_t first_recvd_props
= B_FALSE
;
4636 *errors
= fnvlist_alloc();
4638 input_fp
= getf(input_fd
);
4639 if (input_fp
== NULL
)
4640 return (SET_ERROR(EBADF
));
4642 error
= dmu_recv_begin(tofs
, tosnap
, begin_record
, force
,
4643 resumable
, localprops
, hidden_args
, origin
, &drc
);
4648 * Set properties before we receive the stream so that they are applied
4649 * to the new data. Note that we must call dmu_recv_stream() if
4650 * dmu_recv_begin() succeeds.
4652 if (recvprops
!= NULL
&& !drc
.drc_newfs
) {
4653 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4654 SPA_VERSION_RECVD_PROPS
&&
4655 !dsl_prop_get_hasrecvd(tofs
))
4656 first_recvd_props
= B_TRUE
;
4659 * If new received properties are supplied, they are to
4660 * completely replace the existing received properties,
4661 * so stash away the existing ones.
4663 if (dsl_prop_get_received(tofs
, &origrecvd
) == 0) {
4664 nvlist_t
*errlist
= NULL
;
4666 * Don't bother writing a property if its value won't
4667 * change (and avoid the unnecessary security checks).
4669 * The first receive after SPA_VERSION_RECVD_PROPS is a
4670 * special case where we blow away all local properties
4673 if (!first_recvd_props
)
4674 props_reduce(recvprops
, origrecvd
);
4675 if (zfs_check_clearable(tofs
, origrecvd
, &errlist
) != 0)
4676 (void) nvlist_merge(*errors
, errlist
, 0);
4677 nvlist_free(errlist
);
4679 if (clear_received_props(tofs
, origrecvd
,
4680 first_recvd_props
? NULL
: recvprops
) != 0)
4681 *errflags
|= ZPROP_ERR_NOCLEAR
;
4683 *errflags
|= ZPROP_ERR_NOCLEAR
;
4688 * Stash away existing properties so we can restore them on error unless
4689 * we're doing the first receive after SPA_VERSION_RECVD_PROPS, in which
4690 * case "origrecvd" will take care of that.
4692 if (localprops
!= NULL
&& !drc
.drc_newfs
&& !first_recvd_props
) {
4694 if (dmu_objset_hold(tofs
, FTAG
, &os
) == 0) {
4695 if (dsl_prop_get_all(os
, &origprops
) != 0) {
4696 *errflags
|= ZPROP_ERR_NOCLEAR
;
4698 dmu_objset_rele(os
, FTAG
);
4700 *errflags
|= ZPROP_ERR_NOCLEAR
;
4704 if (recvprops
!= NULL
) {
4705 props_error
= dsl_prop_set_hasrecvd(tofs
);
4707 if (props_error
== 0) {
4708 recv_delayprops
= extract_delay_props(recvprops
);
4709 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4710 recvprops
, *errors
);
4714 if (localprops
!= NULL
) {
4715 nvlist_t
*oprops
= fnvlist_alloc();
4716 nvlist_t
*xprops
= fnvlist_alloc();
4717 nvpair_t
*nvp
= NULL
;
4719 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4720 if (nvpair_type(nvp
) == DATA_TYPE_BOOLEAN
) {
4722 const char *name
= nvpair_name(nvp
);
4723 zfs_prop_t prop
= zfs_name_to_prop(name
);
4724 if (prop
!= ZPROP_INVAL
) {
4725 if (!zfs_prop_inheritable(prop
))
4727 } else if (!zfs_prop_user(name
))
4729 fnvlist_add_boolean(xprops
, name
);
4731 /* -o property=value */
4732 fnvlist_add_nvpair(oprops
, nvp
);
4736 local_delayprops
= extract_delay_props(oprops
);
4737 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4739 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
,
4742 nvlist_free(oprops
);
4743 nvlist_free(xprops
);
4746 off
= input_fp
->f_offset
;
4747 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4751 zfsvfs_t
*zfsvfs
= NULL
;
4752 zvol_state_t
*zv
= NULL
;
4754 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4759 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4760 error
= zfs_suspend_fs(zfsvfs
);
4762 * If the suspend fails, then the recv_end will
4763 * likely also fail, and clean up after itself.
4765 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4767 error
= zfs_resume_fs(zfsvfs
, ds
);
4768 error
= error
? error
: end_err
;
4769 deactivate_super(zfsvfs
->z_sb
);
4770 } else if ((zv
= zvol_suspend(tofs
)) != NULL
) {
4771 error
= dmu_recv_end(&drc
, zvol_tag(zv
));
4774 error
= dmu_recv_end(&drc
, NULL
);
4777 /* Set delayed properties now, after we're done receiving. */
4778 if (recv_delayprops
!= NULL
&& error
== 0) {
4779 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4780 recv_delayprops
, *errors
);
4782 if (local_delayprops
!= NULL
&& error
== 0) {
4783 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
,
4784 local_delayprops
, *errors
);
4789 * Merge delayed props back in with initial props, in case
4790 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4791 * we have to make sure clear_received_props() includes
4792 * the delayed properties).
4794 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4795 * using ASSERT() will be just like a VERIFY.
4797 if (recv_delayprops
!= NULL
) {
4798 ASSERT(nvlist_merge(recvprops
, recv_delayprops
, 0) == 0);
4799 nvlist_free(recv_delayprops
);
4801 if (local_delayprops
!= NULL
) {
4802 ASSERT(nvlist_merge(localprops
, local_delayprops
, 0) == 0);
4803 nvlist_free(local_delayprops
);
4806 *read_bytes
= off
- input_fp
->f_offset
;
4807 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4808 input_fp
->f_offset
= off
;
4811 if (zfs_ioc_recv_inject_err
) {
4812 zfs_ioc_recv_inject_err
= B_FALSE
;
4818 * On error, restore the original props.
4820 if (error
!= 0 && recvprops
!= NULL
&& !drc
.drc_newfs
) {
4821 if (clear_received_props(tofs
, recvprops
, NULL
) != 0) {
4823 * We failed to clear the received properties.
4824 * Since we may have left a $recvd value on the
4825 * system, we can't clear the $hasrecvd flag.
4827 *errflags
|= ZPROP_ERR_NORESTORE
;
4828 } else if (first_recvd_props
) {
4829 dsl_prop_unset_hasrecvd(tofs
);
4832 if (origrecvd
== NULL
&& !drc
.drc_newfs
) {
4833 /* We failed to stash the original properties. */
4834 *errflags
|= ZPROP_ERR_NORESTORE
;
4838 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4839 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4840 * explicitly if we're restoring local properties cleared in the
4841 * first new-style receive.
4843 if (origrecvd
!= NULL
&&
4844 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4845 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4846 origrecvd
, NULL
) != 0) {
4848 * We stashed the original properties but failed to
4851 *errflags
|= ZPROP_ERR_NORESTORE
;
4854 if (error
!= 0 && localprops
!= NULL
&& !drc
.drc_newfs
&&
4855 !first_recvd_props
) {
4857 nvlist_t
*inheritprops
;
4860 if (origprops
== NULL
) {
4861 /* We failed to stash the original properties. */
4862 *errflags
|= ZPROP_ERR_NORESTORE
;
4866 /* Restore original props */
4867 setprops
= fnvlist_alloc();
4868 inheritprops
= fnvlist_alloc();
4870 while ((nvp
= nvlist_next_nvpair(localprops
, nvp
)) != NULL
) {
4871 const char *name
= nvpair_name(nvp
);
4875 if (!nvlist_exists(origprops
, name
)) {
4877 * Property was not present or was explicitly
4878 * inherited before the receive, restore this.
4880 fnvlist_add_boolean(inheritprops
, name
);
4883 attrs
= fnvlist_lookup_nvlist(origprops
, name
);
4884 source
= fnvlist_lookup_string(attrs
, ZPROP_SOURCE
);
4886 /* Skip received properties */
4887 if (strcmp(source
, ZPROP_SOURCE_VAL_RECVD
) == 0)
4890 if (strcmp(source
, tofs
) == 0) {
4891 /* Property was locally set */
4892 fnvlist_add_nvlist(setprops
, name
, attrs
);
4894 /* Property was implicitly inherited */
4895 fnvlist_add_boolean(inheritprops
, name
);
4899 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_LOCAL
, setprops
,
4901 *errflags
|= ZPROP_ERR_NORESTORE
;
4902 if (zfs_set_prop_nvlist(tofs
, ZPROP_SRC_INHERITED
, inheritprops
,
4904 *errflags
|= ZPROP_ERR_NORESTORE
;
4906 nvlist_free(setprops
);
4907 nvlist_free(inheritprops
);
4911 nvlist_free(origrecvd
);
4912 nvlist_free(origprops
);
4915 error
= props_error
;
4922 * zc_name name of containing filesystem (unused)
4923 * zc_nvlist_src{_size} nvlist of properties to apply
4924 * zc_nvlist_conf{_size} nvlist of properties to exclude
4925 * (DATA_TYPE_BOOLEAN) and override (everything else)
4926 * zc_value name of snapshot to create
4927 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4928 * zc_cookie file descriptor to recv from
4929 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4930 * zc_guid force flag
4931 * zc_cleanup_fd cleanup-on-exit file descriptor
4932 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4935 * zc_cookie number of bytes read
4936 * zc_obj zprop_errflags_t
4937 * zc_action_handle handle for this guid/ds mapping
4938 * zc_nvlist_dst{_size} error for each unapplied received property
4941 zfs_ioc_recv(zfs_cmd_t
*zc
)
4943 dmu_replay_record_t begin_record
;
4944 nvlist_t
*errors
= NULL
;
4945 nvlist_t
*recvdprops
= NULL
;
4946 nvlist_t
*localprops
= NULL
;
4947 char *origin
= NULL
;
4949 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4952 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4953 strchr(zc
->zc_value
, '@') == NULL
||
4954 strchr(zc
->zc_value
, '%'))
4955 return (SET_ERROR(EINVAL
));
4957 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4958 tosnap
= strchr(tofs
, '@');
4961 if (zc
->zc_nvlist_src
!= 0 &&
4962 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4963 zc
->zc_iflags
, &recvdprops
)) != 0)
4966 if (zc
->zc_nvlist_conf
!= 0 &&
4967 (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
4968 zc
->zc_iflags
, &localprops
)) != 0)
4971 if (zc
->zc_string
[0])
4972 origin
= zc
->zc_string
;
4974 begin_record
.drr_type
= DRR_BEGIN
;
4975 begin_record
.drr_payloadlen
= 0;
4976 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4978 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvdprops
, localprops
,
4979 NULL
, zc
->zc_guid
, B_FALSE
, zc
->zc_cookie
, &begin_record
,
4980 zc
->zc_cleanup_fd
, &zc
->zc_cookie
, &zc
->zc_obj
,
4981 &zc
->zc_action_handle
, &errors
);
4982 nvlist_free(recvdprops
);
4983 nvlist_free(localprops
);
4986 * Now that all props, initial and delayed, are set, report the prop
4987 * errors to the caller.
4989 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4990 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4991 put_nvlist(zc
, errors
) != 0)) {
4993 * Caller made zc->zc_nvlist_dst less than the minimum expected
4994 * size or supplied an invalid address.
4996 error
= SET_ERROR(EINVAL
);
4999 nvlist_free(errors
);
5006 * "snapname" -> full name of the snapshot to create
5007 * (optional) "props" -> received properties to set (nvlist)
5008 * (optional) "localprops" -> override and exclude properties (nvlist)
5009 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
5010 * "begin_record" -> non-byteswapped dmu_replay_record_t
5011 * "input_fd" -> file descriptor to read stream from (int32)
5012 * (optional) "force" -> force flag (value ignored)
5013 * (optional) "resumable" -> resumable flag (value ignored)
5014 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
5015 * (optional) "action_handle" -> handle for this guid/ds mapping
5016 * (optional) "hidden_args" -> { "wkeydata" -> value }
5020 * "read_bytes" -> number of bytes read
5021 * "error_flags" -> zprop_errflags_t
5022 * "action_handle" -> handle for this guid/ds mapping
5023 * "errors" -> error for each unapplied received property (nvlist)
5026 static const zfs_ioc_key_t zfs_keys_recv_new
[] = {
5027 {"snapname", DATA_TYPE_STRING
, 0},
5028 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
5029 {"localprops", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
5030 {"origin", DATA_TYPE_STRING
, ZK_OPTIONAL
},
5031 {"begin_record", DATA_TYPE_BYTE_ARRAY
, 0},
5032 {"input_fd", DATA_TYPE_INT32
, 0},
5033 {"force", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
5034 {"resumable", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
5035 {"cleanup_fd", DATA_TYPE_INT32
, ZK_OPTIONAL
},
5036 {"action_handle", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
5037 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
5041 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5043 dmu_replay_record_t
*begin_record
;
5044 uint_t begin_record_size
;
5045 nvlist_t
*errors
= NULL
;
5046 nvlist_t
*recvprops
= NULL
;
5047 nvlist_t
*localprops
= NULL
;
5048 nvlist_t
*hidden_args
= NULL
;
5050 char *origin
= NULL
;
5052 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
5054 boolean_t resumable
;
5055 uint64_t action_handle
= 0;
5056 uint64_t read_bytes
= 0;
5057 uint64_t errflags
= 0;
5059 int cleanup_fd
= -1;
5062 snapname
= fnvlist_lookup_string(innvl
, "snapname");
5064 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
5065 strchr(snapname
, '@') == NULL
||
5066 strchr(snapname
, '%'))
5067 return (SET_ERROR(EINVAL
));
5069 (void) strcpy(tofs
, snapname
);
5070 tosnap
= strchr(tofs
, '@');
5073 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
5074 if (error
&& error
!= ENOENT
)
5077 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
5078 (uchar_t
**)&begin_record
, &begin_record_size
);
5079 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
5080 return (SET_ERROR(EINVAL
));
5082 input_fd
= fnvlist_lookup_int32(innvl
, "input_fd");
5084 force
= nvlist_exists(innvl
, "force");
5085 resumable
= nvlist_exists(innvl
, "resumable");
5087 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
5088 if (error
&& error
!= ENOENT
)
5091 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
5092 if (error
&& error
!= ENOENT
)
5095 /* we still use "props" here for backwards compatibility */
5096 error
= nvlist_lookup_nvlist(innvl
, "props", &recvprops
);
5097 if (error
&& error
!= ENOENT
)
5100 error
= nvlist_lookup_nvlist(innvl
, "localprops", &localprops
);
5101 if (error
&& error
!= ENOENT
)
5104 error
= nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
5105 if (error
&& error
!= ENOENT
)
5108 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, recvprops
, localprops
,
5109 hidden_args
, force
, resumable
, input_fd
, begin_record
, cleanup_fd
,
5110 &read_bytes
, &errflags
, &action_handle
, &errors
);
5112 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
5113 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
5114 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
5115 fnvlist_add_nvlist(outnvl
, "errors", errors
);
5117 nvlist_free(errors
);
5118 nvlist_free(recvprops
);
5119 nvlist_free(localprops
);
5126 * zc_name name of snapshot to send
5127 * zc_cookie file descriptor to send stream to
5128 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
5129 * zc_sendobj objsetid of snapshot to send
5130 * zc_fromobj objsetid of incremental fromsnap (may be zero)
5131 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
5132 * output size in zc_objset_type.
5133 * zc_flags lzc_send_flags
5136 * zc_objset_type estimated size, if zc_guid is set
5138 * NOTE: This is no longer the preferred interface, any new functionality
5139 * should be added to zfs_ioc_send_new() instead.
5142 zfs_ioc_send(zfs_cmd_t
*zc
)
5146 boolean_t estimate
= (zc
->zc_guid
!= 0);
5147 boolean_t embedok
= (zc
->zc_flags
& 0x1);
5148 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
5149 boolean_t compressok
= (zc
->zc_flags
& 0x4);
5150 boolean_t rawok
= (zc
->zc_flags
& 0x8);
5152 if (zc
->zc_obj
!= 0) {
5154 dsl_dataset_t
*tosnap
;
5156 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5160 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
5162 dsl_pool_rele(dp
, FTAG
);
5166 if (dsl_dir_is_clone(tosnap
->ds_dir
))
5168 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
5169 dsl_dataset_rele(tosnap
, FTAG
);
5170 dsl_pool_rele(dp
, FTAG
);
5175 dsl_dataset_t
*tosnap
;
5176 dsl_dataset_t
*fromsnap
= NULL
;
5178 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5182 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
,
5185 dsl_pool_rele(dp
, FTAG
);
5189 if (zc
->zc_fromobj
!= 0) {
5190 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
5193 dsl_dataset_rele(tosnap
, FTAG
);
5194 dsl_pool_rele(dp
, FTAG
);
5199 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
|| rawok
,
5200 &zc
->zc_objset_type
);
5202 if (fromsnap
!= NULL
)
5203 dsl_dataset_rele(fromsnap
, FTAG
);
5204 dsl_dataset_rele(tosnap
, FTAG
);
5205 dsl_pool_rele(dp
, FTAG
);
5207 file_t
*fp
= getf(zc
->zc_cookie
);
5209 return (SET_ERROR(EBADF
));
5212 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
5213 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
, rawok
,
5214 zc
->zc_cookie
, fp
->f_vnode
, &off
);
5216 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5218 releasef(zc
->zc_cookie
);
5225 * zc_name name of snapshot on which to report progress
5226 * zc_cookie file descriptor of send stream
5229 * zc_cookie number of bytes written in send stream thus far
5232 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
5236 dmu_sendarg_t
*dsp
= NULL
;
5239 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5243 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5245 dsl_pool_rele(dp
, FTAG
);
5249 mutex_enter(&ds
->ds_sendstream_lock
);
5252 * Iterate over all the send streams currently active on this dataset.
5253 * If there's one which matches the specified file descriptor _and_ the
5254 * stream was started by the current process, return the progress of
5258 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
5259 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
5260 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
5261 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
5266 zc
->zc_cookie
= *(dsp
->dsa_off
);
5268 error
= SET_ERROR(ENOENT
);
5270 mutex_exit(&ds
->ds_sendstream_lock
);
5271 dsl_dataset_rele(ds
, FTAG
);
5272 dsl_pool_rele(dp
, FTAG
);
5277 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
5281 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
5282 &zc
->zc_inject_record
);
5285 zc
->zc_guid
= (uint64_t)id
;
5291 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
5293 return (zio_clear_fault((int)zc
->zc_guid
));
5297 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
5299 int id
= (int)zc
->zc_guid
;
5302 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
5303 &zc
->zc_inject_record
);
5311 zfs_ioc_error_log(zfs_cmd_t
*zc
)
5315 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
5317 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
5320 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5323 zc
->zc_nvlist_dst_size
= count
;
5325 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
5327 spa_close(spa
, FTAG
);
5333 zfs_ioc_clear(zfs_cmd_t
*zc
)
5340 * On zpool clear we also fix up missing slogs
5342 mutex_enter(&spa_namespace_lock
);
5343 spa
= spa_lookup(zc
->zc_name
);
5345 mutex_exit(&spa_namespace_lock
);
5346 return (SET_ERROR(EIO
));
5348 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
5349 /* we need to let spa_open/spa_load clear the chains */
5350 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
5352 spa
->spa_last_open_failed
= 0;
5353 mutex_exit(&spa_namespace_lock
);
5355 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
5356 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
5359 nvlist_t
*config
= NULL
;
5361 if (zc
->zc_nvlist_src
== 0)
5362 return (SET_ERROR(EINVAL
));
5364 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5365 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
5366 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
5368 if (config
!= NULL
) {
5371 if ((err
= put_nvlist(zc
, config
)) != 0)
5373 nvlist_free(config
);
5375 nvlist_free(policy
);
5383 * If multihost is enabled, resuming I/O is unsafe as another
5384 * host may have imported the pool.
5386 if (spa_multihost(spa
) && spa_suspended(spa
))
5387 return (SET_ERROR(EINVAL
));
5389 spa_vdev_state_enter(spa
, SCL_NONE
);
5391 if (zc
->zc_guid
== 0) {
5394 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
5396 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
5397 spa_close(spa
, FTAG
);
5398 return (SET_ERROR(ENODEV
));
5402 vdev_clear(spa
, vd
);
5404 (void) spa_vdev_state_exit(spa
, spa_suspended(spa
) ?
5405 NULL
: spa
->spa_root_vdev
, 0);
5408 * Resume any suspended I/Os.
5410 if (zio_resume(spa
) != 0)
5411 error
= SET_ERROR(EIO
);
5413 spa_close(spa
, FTAG
);
5419 * Reopen all the vdevs associated with the pool.
5422 * "scrub_restart" -> when true and scrub is running, allow to restart
5423 * scrub as the side effect of the reopen (boolean).
5428 static const zfs_ioc_key_t zfs_keys_pool_reopen
[] = {
5429 {"scrub_restart", DATA_TYPE_BOOLEAN_VALUE
, 0},
5434 zfs_ioc_pool_reopen(const char *pool
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5438 boolean_t scrub_restart
= B_TRUE
;
5441 scrub_restart
= fnvlist_lookup_boolean_value(innvl
,
5445 error
= spa_open(pool
, &spa
, FTAG
);
5449 spa_vdev_state_enter(spa
, SCL_NONE
);
5452 * If the scrub_restart flag is B_FALSE and a scrub is already
5453 * in progress then set spa_scrub_reopen flag to B_TRUE so that
5454 * we don't restart the scrub as a side effect of the reopen.
5455 * Otherwise, let vdev_open() decided if a resilver is required.
5458 spa
->spa_scrub_reopen
= (!scrub_restart
&&
5459 dsl_scan_scrubbing(spa
->spa_dsl_pool
));
5460 vdev_reopen(spa
->spa_root_vdev
);
5461 spa
->spa_scrub_reopen
= B_FALSE
;
5463 (void) spa_vdev_state_exit(spa
, NULL
, 0);
5464 spa_close(spa
, FTAG
);
5470 * zc_name name of filesystem
5473 * zc_string name of conflicting snapshot, if there is one
5476 zfs_ioc_promote(zfs_cmd_t
*zc
)
5479 dsl_dataset_t
*ds
, *ods
;
5480 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
5484 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5485 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
5486 strchr(zc
->zc_name
, '%'))
5487 return (SET_ERROR(EINVAL
));
5489 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5493 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
5495 dsl_pool_rele(dp
, FTAG
);
5499 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
5500 dsl_dataset_rele(ds
, FTAG
);
5501 dsl_pool_rele(dp
, FTAG
);
5502 return (SET_ERROR(EINVAL
));
5505 error
= dsl_dataset_hold_obj(dp
,
5506 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
5508 dsl_dataset_rele(ds
, FTAG
);
5509 dsl_pool_rele(dp
, FTAG
);
5513 dsl_dataset_name(ods
, origin
);
5514 dsl_dataset_rele(ods
, FTAG
);
5515 dsl_dataset_rele(ds
, FTAG
);
5516 dsl_pool_rele(dp
, FTAG
);
5519 * We don't need to unmount *all* the origin fs's snapshots, but
5522 cp
= strchr(origin
, '@');
5525 (void) dmu_objset_find(origin
,
5526 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
5527 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
5531 * Retrieve a single {user|group|project}{used|quota}@... property.
5534 * zc_name name of filesystem
5535 * zc_objset_type zfs_userquota_prop_t
5536 * zc_value domain name (eg. "S-1-234-567-89")
5537 * zc_guid RID/UID/GID
5540 * zc_cookie property value
5543 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
5548 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
5549 return (SET_ERROR(EINVAL
));
5551 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5555 error
= zfs_userspace_one(zfsvfs
,
5556 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
5557 zfsvfs_rele(zfsvfs
, FTAG
);
5564 * zc_name name of filesystem
5565 * zc_cookie zap cursor
5566 * zc_objset_type zfs_userquota_prop_t
5567 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
5570 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
5571 * zc_cookie zap cursor
5574 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
5577 int bufsize
= zc
->zc_nvlist_dst_size
;
5580 return (SET_ERROR(ENOMEM
));
5582 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
5586 void *buf
= vmem_alloc(bufsize
, KM_SLEEP
);
5588 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
5589 buf
, &zc
->zc_nvlist_dst_size
);
5592 error
= xcopyout(buf
,
5593 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
5594 zc
->zc_nvlist_dst_size
);
5596 vmem_free(buf
, bufsize
);
5597 zfsvfs_rele(zfsvfs
, FTAG
);
5604 * zc_name name of filesystem
5610 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
5616 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
5617 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
5619 * If userused is not enabled, it may be because the
5620 * objset needs to be closed & reopened (to grow the
5621 * objset_phys_t). Suspend/resume the fs will do that.
5623 dsl_dataset_t
*ds
, *newds
;
5625 ds
= dmu_objset_ds(zfsvfs
->z_os
);
5626 error
= zfs_suspend_fs(zfsvfs
);
5628 dmu_objset_refresh_ownership(ds
, &newds
,
5630 error
= zfs_resume_fs(zfsvfs
, newds
);
5634 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
5635 deactivate_super(zfsvfs
->z_sb
);
5637 /* XXX kind of reading contents without owning */
5638 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5642 error
= dmu_objset_userspace_upgrade(os
);
5643 dmu_objset_rele_flags(os
, B_TRUE
, FTAG
);
5651 * zc_name name of filesystem
5657 zfs_ioc_id_quota_upgrade(zfs_cmd_t
*zc
)
5662 error
= dmu_objset_hold_flags(zc
->zc_name
, B_TRUE
, FTAG
, &os
);
5666 if (dmu_objset_userobjspace_upgradable(os
) ||
5667 dmu_objset_projectquota_upgradable(os
)) {
5668 mutex_enter(&os
->os_upgrade_lock
);
5669 if (os
->os_upgrade_id
== 0) {
5670 /* clear potential error code and retry */
5671 os
->os_upgrade_status
= 0;
5672 mutex_exit(&os
->os_upgrade_lock
);
5674 dmu_objset_id_quota_upgrade(os
);
5676 mutex_exit(&os
->os_upgrade_lock
);
5679 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5681 taskq_wait_id(os
->os_spa
->spa_upgrade_taskq
, os
->os_upgrade_id
);
5682 error
= os
->os_upgrade_status
;
5684 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
5687 dsl_dataset_rele_flags(dmu_objset_ds(os
), DS_HOLD_FLAG_DECRYPT
, FTAG
);
5693 zfs_ioc_share(zfs_cmd_t
*zc
)
5695 return (SET_ERROR(ENOSYS
));
5698 ace_t full_access
[] = {
5699 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
5704 * zc_name name of containing filesystem
5705 * zc_obj object # beyond which we want next in-use object #
5708 * zc_obj next in-use object #
5711 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
5713 objset_t
*os
= NULL
;
5716 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
5720 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
5722 dmu_objset_rele(os
, FTAG
);
5728 * zc_name name of filesystem
5729 * zc_value prefix name for snapshot
5730 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5733 * zc_value short name of new snapshot
5736 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5743 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5747 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5748 (u_longlong_t
)ddi_get_lbolt64());
5749 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5751 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5754 (void) strlcpy(zc
->zc_value
, snap_name
,
5755 sizeof (zc
->zc_value
));
5758 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5764 * zc_name name of "to" snapshot
5765 * zc_value name of "from" snapshot
5766 * zc_cookie file descriptor to write diff data on
5769 * dmu_diff_record_t's to the file descriptor
5772 zfs_ioc_diff(zfs_cmd_t
*zc
)
5778 fp
= getf(zc
->zc_cookie
);
5780 return (SET_ERROR(EBADF
));
5784 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5786 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5788 releasef(zc
->zc_cookie
);
5794 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5796 return (SET_ERROR(ENOTSUP
));
5801 * "holds" -> { snapname -> holdname (string), ... }
5802 * (optional) "cleanup_fd" -> fd (int32)
5806 * snapname -> error value (int32)
5810 static const zfs_ioc_key_t zfs_keys_hold
[] = {
5811 {"holds", DATA_TYPE_NVLIST
, 0},
5812 {"cleanup_fd", DATA_TYPE_INT32
, ZK_OPTIONAL
},
5817 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5821 int cleanup_fd
= -1;
5825 holds
= fnvlist_lookup_nvlist(args
, "holds");
5827 /* make sure the user didn't pass us any invalid (empty) tags */
5828 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5829 pair
= nvlist_next_nvpair(holds
, pair
)) {
5832 error
= nvpair_value_string(pair
, &htag
);
5834 return (SET_ERROR(error
));
5836 if (strlen(htag
) == 0)
5837 return (SET_ERROR(EINVAL
));
5840 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5841 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5846 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5848 zfs_onexit_fd_rele(cleanup_fd
);
5853 * innvl is not used.
5856 * holdname -> time added (uint64 seconds since epoch)
5860 static const zfs_ioc_key_t zfs_keys_get_holds
[] = {
5866 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5868 return (dsl_dataset_get_holds(snapname
, outnvl
));
5873 * snapname -> { holdname, ... }
5878 * snapname -> error value (int32)
5882 static const zfs_ioc_key_t zfs_keys_release
[] = {
5883 {"<snapname>...", DATA_TYPE_NVLIST
, ZK_WILDCARDLIST
},
5888 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5890 return (dsl_dataset_user_release(holds
, errlist
));
5895 * zc_guid flags (ZEVENT_NONBLOCK)
5896 * zc_cleanup_fd zevent file descriptor
5899 * zc_nvlist_dst next nvlist event
5900 * zc_cookie dropped events since last get
5903 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5906 nvlist_t
*event
= NULL
;
5908 uint64_t dropped
= 0;
5911 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5916 error
= zfs_zevent_next(ze
, &event
,
5917 &zc
->zc_nvlist_dst_size
, &dropped
);
5918 if (event
!= NULL
) {
5919 zc
->zc_cookie
= dropped
;
5920 error
= put_nvlist(zc
, event
);
5924 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5927 if ((error
== 0) || (error
!= ENOENT
))
5930 error
= zfs_zevent_wait(ze
);
5935 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5942 * zc_cookie cleared events count
5945 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5949 zfs_zevent_drain_all(&count
);
5950 zc
->zc_cookie
= count
;
5957 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5958 * zc_cleanup zevent file descriptor
5961 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5967 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5971 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5972 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5979 * zc_name name of new filesystem or snapshot
5980 * zc_value full name of old snapshot
5983 * zc_cookie space in bytes
5984 * zc_objset_type compressed space in bytes
5985 * zc_perm_action uncompressed space in bytes
5988 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5992 dsl_dataset_t
*new, *old
;
5994 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5997 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5999 dsl_pool_rele(dp
, FTAG
);
6002 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
6004 dsl_dataset_rele(new, FTAG
);
6005 dsl_pool_rele(dp
, FTAG
);
6009 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
6010 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
6011 dsl_dataset_rele(old
, FTAG
);
6012 dsl_dataset_rele(new, FTAG
);
6013 dsl_pool_rele(dp
, FTAG
);
6019 * "firstsnap" -> snapshot name
6023 * "used" -> space in bytes
6024 * "compressed" -> compressed space in bytes
6025 * "uncompressed" -> uncompressed space in bytes
6028 static const zfs_ioc_key_t zfs_keys_space_snaps
[] = {
6029 {"firstsnap", DATA_TYPE_STRING
, 0},
6033 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6037 dsl_dataset_t
*new, *old
;
6039 uint64_t used
, comp
, uncomp
;
6041 firstsnap
= fnvlist_lookup_string(innvl
, "firstsnap");
6043 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
6047 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
6048 if (error
== 0 && !new->ds_is_snapshot
) {
6049 dsl_dataset_rele(new, FTAG
);
6050 error
= SET_ERROR(EINVAL
);
6053 dsl_pool_rele(dp
, FTAG
);
6056 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
6057 if (error
== 0 && !old
->ds_is_snapshot
) {
6058 dsl_dataset_rele(old
, FTAG
);
6059 error
= SET_ERROR(EINVAL
);
6062 dsl_dataset_rele(new, FTAG
);
6063 dsl_pool_rele(dp
, FTAG
);
6067 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
6068 dsl_dataset_rele(old
, FTAG
);
6069 dsl_dataset_rele(new, FTAG
);
6070 dsl_pool_rele(dp
, FTAG
);
6071 fnvlist_add_uint64(outnvl
, "used", used
);
6072 fnvlist_add_uint64(outnvl
, "compressed", comp
);
6073 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
6079 * "fd" -> file descriptor to write stream to (int32)
6080 * (optional) "fromsnap" -> full snap name to send an incremental from
6081 * (optional) "largeblockok" -> (value ignored)
6082 * indicates that blocks > 128KB are permitted
6083 * (optional) "embedok" -> (value ignored)
6084 * presence indicates DRR_WRITE_EMBEDDED records are permitted
6085 * (optional) "compressok" -> (value ignored)
6086 * presence indicates compressed DRR_WRITE records are permitted
6087 * (optional) "rawok" -> (value ignored)
6088 * presence indicates raw encrypted records should be used.
6089 * (optional) "resume_object" and "resume_offset" -> (uint64)
6090 * if present, resume send stream from specified object and offset.
6095 static const zfs_ioc_key_t zfs_keys_send_new
[] = {
6096 {"fd", DATA_TYPE_INT32
, 0},
6097 {"fromsnap", DATA_TYPE_STRING
, ZK_OPTIONAL
},
6098 {"largeblockok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6099 {"embedok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6100 {"compressok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6101 {"rawok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6102 {"resume_object", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
6103 {"resume_offset", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
6108 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6112 char *fromname
= NULL
;
6115 boolean_t largeblockok
;
6117 boolean_t compressok
;
6119 uint64_t resumeobj
= 0;
6120 uint64_t resumeoff
= 0;
6122 fd
= fnvlist_lookup_int32(innvl
, "fd");
6124 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
6126 largeblockok
= nvlist_exists(innvl
, "largeblockok");
6127 embedok
= nvlist_exists(innvl
, "embedok");
6128 compressok
= nvlist_exists(innvl
, "compressok");
6129 rawok
= nvlist_exists(innvl
, "rawok");
6131 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
6132 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
6134 if ((fp
= getf(fd
)) == NULL
)
6135 return (SET_ERROR(EBADF
));
6138 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
6139 rawok
, fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
6141 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
6149 * Determine approximately how large a zfs send stream will be -- the number
6150 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
6153 * (optional) "from" -> full snap or bookmark name to send an incremental
6155 * (optional) "largeblockok" -> (value ignored)
6156 * indicates that blocks > 128KB are permitted
6157 * (optional) "embedok" -> (value ignored)
6158 * presence indicates DRR_WRITE_EMBEDDED records are permitted
6159 * (optional) "compressok" -> (value ignored)
6160 * presence indicates compressed DRR_WRITE records are permitted
6161 * (optional) "rawok" -> (value ignored)
6162 * presence indicates raw encrypted records should be used.
6166 * "space" -> bytes of space (uint64)
6169 static const zfs_ioc_key_t zfs_keys_send_space
[] = {
6170 {"from", DATA_TYPE_STRING
, ZK_OPTIONAL
},
6171 {"fromsnap", DATA_TYPE_STRING
, ZK_OPTIONAL
},
6172 {"largeblockok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6173 {"embedok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6174 {"compressok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6175 {"rawok", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6179 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6182 dsl_dataset_t
*tosnap
;
6185 boolean_t compressok
;
6189 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
6193 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
6195 dsl_pool_rele(dp
, FTAG
);
6199 compressok
= nvlist_exists(innvl
, "compressok");
6200 rawok
= nvlist_exists(innvl
, "rawok");
6202 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
6204 if (strchr(fromname
, '@') != NULL
) {
6206 * If from is a snapshot, hold it and use the more
6207 * efficient dmu_send_estimate to estimate send space
6208 * size using deadlists.
6210 dsl_dataset_t
*fromsnap
;
6211 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
6214 error
= dmu_send_estimate(tosnap
, fromsnap
,
6215 compressok
|| rawok
, &space
);
6216 dsl_dataset_rele(fromsnap
, FTAG
);
6217 } else if (strchr(fromname
, '#') != NULL
) {
6219 * If from is a bookmark, fetch the creation TXG of the
6220 * snapshot it was created from and use that to find
6221 * blocks that were born after it.
6223 zfs_bookmark_phys_t frombm
;
6225 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
6229 error
= dmu_send_estimate_from_txg(tosnap
,
6230 frombm
.zbm_creation_txg
, compressok
|| rawok
,
6234 * from is not properly formatted as a snapshot or
6237 error
= SET_ERROR(EINVAL
);
6242 * If estimating the size of a full send, use dmu_send_estimate.
6244 error
= dmu_send_estimate(tosnap
, NULL
, compressok
|| rawok
,
6248 fnvlist_add_uint64(outnvl
, "space", space
);
6251 dsl_dataset_rele(tosnap
, FTAG
);
6252 dsl_pool_rele(dp
, FTAG
);
6257 * Sync the currently open TXG to disk for the specified pool.
6258 * This is somewhat similar to 'zfs_sync()'.
6259 * For cases that do not result in error this ioctl will wait for
6260 * the currently open TXG to commit before returning back to the caller.
6263 * "force" -> when true, force uberblock update even if there is no dirty data.
6264 * In addition this will cause the vdev configuration to be written
6265 * out including updating the zpool cache file. (boolean_t)
6270 static const zfs_ioc_key_t zfs_keys_pool_sync
[] = {
6271 {"force", DATA_TYPE_BOOLEAN_VALUE
, 0},
6276 zfs_ioc_pool_sync(const char *pool
, nvlist_t
*innvl
, nvlist_t
*onvl
)
6279 boolean_t force
= B_FALSE
;
6282 if ((err
= spa_open(pool
, &spa
, FTAG
)) != 0)
6286 force
= fnvlist_lookup_boolean_value(innvl
, "force");
6289 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_WRITER
);
6290 vdev_config_dirty(spa
->spa_root_vdev
);
6291 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6293 txg_wait_synced(spa_get_dsl(spa
), 0);
6295 spa_close(spa
, FTAG
);
6301 * Load a user's wrapping key into the kernel.
6303 * "hidden_args" -> { "wkeydata" -> value }
6304 * raw uint8_t array of encryption wrapping key data (32 bytes)
6305 * (optional) "noop" -> (value ignored)
6306 * presence indicated key should only be verified, not loaded
6309 static const zfs_ioc_key_t zfs_keys_load_key
[] = {
6310 {"hidden_args", DATA_TYPE_NVLIST
, 0},
6311 {"noop", DATA_TYPE_BOOLEAN
, ZK_OPTIONAL
},
6316 zfs_ioc_load_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6319 dsl_crypto_params_t
*dcp
= NULL
;
6320 nvlist_t
*hidden_args
;
6321 boolean_t noop
= nvlist_exists(innvl
, "noop");
6323 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6324 ret
= SET_ERROR(EINVAL
);
6328 hidden_args
= fnvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
);
6330 ret
= dsl_crypto_params_create_nvlist(DCP_CMD_NONE
, NULL
,
6335 ret
= spa_keystore_load_wkey(dsname
, dcp
, noop
);
6339 dsl_crypto_params_free(dcp
, noop
);
6344 dsl_crypto_params_free(dcp
, B_TRUE
);
6349 * Unload a user's wrapping key from the kernel.
6350 * Both innvl and outnvl are unused.
6352 static const zfs_ioc_key_t zfs_keys_unload_key
[] = {
6358 zfs_ioc_unload_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6362 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6363 ret
= (SET_ERROR(EINVAL
));
6367 ret
= spa_keystore_unload_wkey(dsname
);
6376 * Changes a user's wrapping key used to decrypt a dataset. The keyformat,
6377 * keylocation, pbkdf2salt, and pbkdf2iters properties can also be specified
6378 * here to change how the key is derived in userspace.
6381 * "hidden_args" (optional) -> { "wkeydata" -> value }
6382 * raw uint8_t array of new encryption wrapping key data (32 bytes)
6383 * "props" (optional) -> { prop -> value }
6388 static const zfs_ioc_key_t zfs_keys_change_key
[] = {
6389 {"crypt_cmd", DATA_TYPE_UINT64
, ZK_OPTIONAL
},
6390 {"hidden_args", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
6391 {"props", DATA_TYPE_NVLIST
, ZK_OPTIONAL
},
6396 zfs_ioc_change_key(const char *dsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
6399 uint64_t cmd
= DCP_CMD_NONE
;
6400 dsl_crypto_params_t
*dcp
= NULL
;
6401 nvlist_t
*args
= NULL
, *hidden_args
= NULL
;
6403 if (strchr(dsname
, '@') != NULL
|| strchr(dsname
, '%') != NULL
) {
6404 ret
= (SET_ERROR(EINVAL
));
6408 (void) nvlist_lookup_uint64(innvl
, "crypt_cmd", &cmd
);
6409 (void) nvlist_lookup_nvlist(innvl
, "props", &args
);
6410 (void) nvlist_lookup_nvlist(innvl
, ZPOOL_HIDDEN_ARGS
, &hidden_args
);
6412 ret
= dsl_crypto_params_create_nvlist(cmd
, args
, hidden_args
, &dcp
);
6416 ret
= spa_keystore_change_key(dsname
, dcp
);
6420 dsl_crypto_params_free(dcp
, B_FALSE
);
6425 dsl_crypto_params_free(dcp
, B_TRUE
);
6429 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
6432 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6433 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6434 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
6436 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6438 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6439 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6440 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6441 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6443 vec
->zvec_legacy_func
= func
;
6444 vec
->zvec_secpolicy
= secpolicy
;
6445 vec
->zvec_namecheck
= namecheck
;
6446 vec
->zvec_allow_log
= log_history
;
6447 vec
->zvec_pool_check
= pool_check
;
6451 * See the block comment at the beginning of this file for details on
6452 * each argument to this function.
6455 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
6456 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
6457 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
6458 boolean_t allow_log
, const zfs_ioc_key_t
*nvl_keys
, size_t num_keys
)
6460 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
6462 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
6463 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
6464 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
6465 ASSERT3P(vec
->zvec_func
, ==, NULL
);
6467 /* if we are logging, the name must be valid */
6468 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
6470 vec
->zvec_name
= name
;
6471 vec
->zvec_func
= func
;
6472 vec
->zvec_secpolicy
= secpolicy
;
6473 vec
->zvec_namecheck
= namecheck
;
6474 vec
->zvec_pool_check
= pool_check
;
6475 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
6476 vec
->zvec_allow_log
= allow_log
;
6477 vec
->zvec_nvl_keys
= nvl_keys
;
6478 vec
->zvec_nvl_key_count
= num_keys
;
6482 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6483 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
6484 zfs_ioc_poolcheck_t pool_check
)
6486 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6487 POOL_NAME
, log_history
, pool_check
);
6491 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6492 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
6494 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6495 DATASET_NAME
, B_FALSE
, pool_check
);
6499 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6501 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
6502 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6506 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6507 zfs_secpolicy_func_t
*secpolicy
)
6509 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6510 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6514 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
6515 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
6517 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6518 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6522 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
6524 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
6525 zfs_secpolicy_read
);
6529 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
6530 zfs_secpolicy_func_t
*secpolicy
)
6532 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
6533 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6537 zfs_ioctl_init(void)
6539 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
6540 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
6541 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6542 zfs_keys_snapshot
, ARRAY_SIZE(zfs_keys_snapshot
));
6544 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
6545 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
6546 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
,
6547 zfs_keys_log_history
, ARRAY_SIZE(zfs_keys_log_history
));
6549 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
6550 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
6551 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6552 zfs_keys_space_snaps
, ARRAY_SIZE(zfs_keys_space_snaps
));
6554 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
6555 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
6556 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6557 zfs_keys_send_new
, ARRAY_SIZE(zfs_keys_send_new
));
6559 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
6560 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
6561 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6562 zfs_keys_send_space
, ARRAY_SIZE(zfs_keys_send_space
));
6564 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
6565 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6566 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6567 zfs_keys_create
, ARRAY_SIZE(zfs_keys_create
));
6569 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
6570 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
6571 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6572 zfs_keys_clone
, ARRAY_SIZE(zfs_keys_clone
));
6574 zfs_ioctl_register("remap", ZFS_IOC_REMAP
,
6575 zfs_ioc_remap
, zfs_secpolicy_remap
, DATASET_NAME
,
6576 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
,
6577 zfs_keys_remap
, ARRAY_SIZE(zfs_keys_remap
));
6579 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
6580 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
6581 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6582 zfs_keys_destroy_snaps
, ARRAY_SIZE(zfs_keys_destroy_snaps
));
6584 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
6585 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
6586 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6587 zfs_keys_hold
, ARRAY_SIZE(zfs_keys_hold
));
6588 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
6589 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
6590 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6591 zfs_keys_release
, ARRAY_SIZE(zfs_keys_release
));
6593 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
6594 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
6595 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6596 zfs_keys_get_holds
, ARRAY_SIZE(zfs_keys_get_holds
));
6598 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
6599 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
6600 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
,
6601 zfs_keys_rollback
, ARRAY_SIZE(zfs_keys_rollback
));
6603 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
6604 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
6605 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6606 zfs_keys_bookmark
, ARRAY_SIZE(zfs_keys_bookmark
));
6608 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
6609 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
6610 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
,
6611 zfs_keys_get_bookmarks
, ARRAY_SIZE(zfs_keys_get_bookmarks
));
6613 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
6614 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
6616 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6617 zfs_keys_destroy_bookmarks
,
6618 ARRAY_SIZE(zfs_keys_destroy_bookmarks
));
6620 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
6621 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
6622 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6623 zfs_keys_recv_new
, ARRAY_SIZE(zfs_keys_recv_new
));
6624 zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY
,
6625 zfs_ioc_load_key
, zfs_secpolicy_load_key
,
6626 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
,
6627 zfs_keys_load_key
, ARRAY_SIZE(zfs_keys_load_key
));
6628 zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY
,
6629 zfs_ioc_unload_key
, zfs_secpolicy_load_key
,
6630 DATASET_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
, B_TRUE
,
6631 zfs_keys_unload_key
, ARRAY_SIZE(zfs_keys_unload_key
));
6632 zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY
,
6633 zfs_ioc_change_key
, zfs_secpolicy_change_key
,
6634 DATASET_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
,
6635 B_TRUE
, B_TRUE
, zfs_keys_change_key
,
6636 ARRAY_SIZE(zfs_keys_change_key
));
6638 zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC
,
6639 zfs_ioc_pool_sync
, zfs_secpolicy_none
, POOL_NAME
,
6640 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
,
6641 zfs_keys_pool_sync
, ARRAY_SIZE(zfs_keys_pool_sync
));
6642 zfs_ioctl_register("reopen", ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
6643 zfs_secpolicy_config
, POOL_NAME
, POOL_CHECK_SUSPENDED
, B_TRUE
,
6644 B_TRUE
, zfs_keys_pool_reopen
, ARRAY_SIZE(zfs_keys_pool_reopen
));
6646 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
6647 zfs_ioc_channel_program
, zfs_secpolicy_config
,
6648 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
6649 B_TRUE
, zfs_keys_channel_program
,
6650 ARRAY_SIZE(zfs_keys_channel_program
));
6652 zfs_ioctl_register("zpool_checkpoint", ZFS_IOC_POOL_CHECKPOINT
,
6653 zfs_ioc_pool_checkpoint
, zfs_secpolicy_config
, POOL_NAME
,
6654 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6655 zfs_keys_pool_checkpoint
, ARRAY_SIZE(zfs_keys_pool_checkpoint
));
6657 zfs_ioctl_register("zpool_discard_checkpoint",
6658 ZFS_IOC_POOL_DISCARD_CHECKPOINT
, zfs_ioc_pool_discard_checkpoint
,
6659 zfs_secpolicy_config
, POOL_NAME
,
6660 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6661 zfs_keys_pool_discard_checkpoint
,
6662 ARRAY_SIZE(zfs_keys_pool_discard_checkpoint
));
6664 zfs_ioctl_register("initialize", ZFS_IOC_POOL_INITIALIZE
,
6665 zfs_ioc_pool_initialize
, zfs_secpolicy_config
, POOL_NAME
,
6666 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6667 zfs_keys_pool_initialize
, ARRAY_SIZE(zfs_keys_pool_initialize
));
6669 zfs_ioctl_register("trim", ZFS_IOC_POOL_TRIM
,
6670 zfs_ioc_pool_trim
, zfs_secpolicy_config
, POOL_NAME
,
6671 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
,
6672 zfs_keys_pool_trim
, ARRAY_SIZE(zfs_keys_pool_trim
));
6674 /* IOCTLS that use the legacy function signature */
6676 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
6677 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
6679 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
6680 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6681 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
6683 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
6684 zfs_ioc_pool_upgrade
);
6685 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
6687 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
6688 zfs_ioc_vdev_remove
);
6689 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
6690 zfs_ioc_vdev_set_state
);
6691 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
6692 zfs_ioc_vdev_attach
);
6693 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
6694 zfs_ioc_vdev_detach
);
6695 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
6696 zfs_ioc_vdev_setpath
);
6697 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
6698 zfs_ioc_vdev_setfru
);
6699 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
6700 zfs_ioc_pool_set_props
);
6701 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
6702 zfs_ioc_vdev_split
);
6703 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
6704 zfs_ioc_pool_reguid
);
6706 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
6707 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
6708 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
6709 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
6710 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
6711 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
6712 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
6713 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
6714 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
6715 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
6718 * pool destroy, and export don't log the history as part of
6719 * zfsdev_ioctl, but rather zfs_ioc_pool_export
6720 * does the logging of those commands.
6722 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
6723 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6724 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
6725 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6727 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
6728 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6729 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
6730 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
6732 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
6733 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6734 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
6735 zfs_ioc_dsobj_to_dsname
,
6736 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6737 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
6738 zfs_ioc_pool_get_history
,
6739 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
6741 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
6742 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
6744 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
6745 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_READONLY
);
6747 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
6748 zfs_ioc_space_written
);
6749 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
6750 zfs_ioc_objset_recvd_props
);
6751 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
6753 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
6755 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
6756 zfs_ioc_objset_stats
);
6757 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
6758 zfs_ioc_objset_zplprops
);
6759 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
6760 zfs_ioc_dataset_list_next
);
6761 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
6762 zfs_ioc_snapshot_list_next
);
6763 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
6764 zfs_ioc_send_progress
);
6766 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
6767 zfs_ioc_diff
, zfs_secpolicy_diff
);
6768 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
6769 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
6770 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
6771 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
6772 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
6773 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
6774 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
6775 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
6776 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
6777 zfs_ioc_send
, zfs_secpolicy_send
);
6779 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
6780 zfs_secpolicy_none
);
6781 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
6782 zfs_secpolicy_destroy
);
6783 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
6784 zfs_secpolicy_rename
);
6785 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
6786 zfs_secpolicy_recv
);
6787 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
6788 zfs_secpolicy_promote
);
6789 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
6790 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
6791 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
6792 zfs_secpolicy_set_fsacl
);
6794 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
6795 zfs_secpolicy_share
, POOL_CHECK_NONE
);
6796 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
6797 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
6798 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
6799 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
6800 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6801 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
6802 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
6803 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
6808 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
6809 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6810 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
6811 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6812 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
6813 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
6817 * Verify that for non-legacy ioctls the input nvlist
6818 * pairs match against the expected input.
6820 * Possible errors are:
6821 * ZFS_ERR_IOC_ARG_UNAVAIL An unrecognized nvpair was encountered
6822 * ZFS_ERR_IOC_ARG_REQUIRED A required nvpair is missing
6823 * ZFS_ERR_IOC_ARG_BADTYPE Invalid type for nvpair
6826 zfs_check_input_nvpairs(nvlist_t
*innvl
, const zfs_ioc_vec_t
*vec
)
6828 const zfs_ioc_key_t
*nvl_keys
= vec
->zvec_nvl_keys
;
6829 boolean_t required_keys_found
= B_FALSE
;
6832 * examine each input pair
6834 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
6835 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
6836 char *name
= nvpair_name(pair
);
6837 data_type_t type
= nvpair_type(pair
);
6838 boolean_t identified
= B_FALSE
;
6841 * check pair against the documented names and type
6843 for (int k
= 0; k
< vec
->zvec_nvl_key_count
; k
++) {
6844 /* if not a wild card name, check for an exact match */
6845 if ((nvl_keys
[k
].zkey_flags
& ZK_WILDCARDLIST
) == 0 &&
6846 strcmp(nvl_keys
[k
].zkey_name
, name
) != 0)
6849 identified
= B_TRUE
;
6851 if (nvl_keys
[k
].zkey_type
!= DATA_TYPE_ANY
&&
6852 nvl_keys
[k
].zkey_type
!= type
) {
6853 return (SET_ERROR(ZFS_ERR_IOC_ARG_BADTYPE
));
6856 if (nvl_keys
[k
].zkey_flags
& ZK_OPTIONAL
)
6859 required_keys_found
= B_TRUE
;
6863 /* allow an 'optional' key, everything else is invalid */
6865 (strcmp(name
, "optional") != 0 ||
6866 type
!= DATA_TYPE_NVLIST
)) {
6867 return (SET_ERROR(ZFS_ERR_IOC_ARG_UNAVAIL
));
6871 /* verify that all required keys were found */
6872 for (int k
= 0; k
< vec
->zvec_nvl_key_count
; k
++) {
6873 if (nvl_keys
[k
].zkey_flags
& ZK_OPTIONAL
)
6876 if (nvl_keys
[k
].zkey_flags
& ZK_WILDCARDLIST
) {
6877 /* at least one non-optionial key is expected here */
6878 if (!required_keys_found
)
6879 return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED
));
6883 if (!nvlist_exists(innvl
, nvl_keys
[k
].zkey_name
))
6884 return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED
));
6891 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
6892 zfs_ioc_poolcheck_t check
)
6897 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
6899 if (check
& POOL_CHECK_NONE
)
6902 error
= spa_open(name
, &spa
, FTAG
);
6904 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
6905 error
= SET_ERROR(EAGAIN
);
6906 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
6907 error
= SET_ERROR(EROFS
);
6908 spa_close(spa
, FTAG
);
6914 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
6918 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6919 if (zs
->zs_minor
== minor
) {
6923 return (zs
->zs_onexit
);
6925 return (zs
->zs_zevent
);
6936 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
6940 ptr
= zfsdev_get_state_impl(minor
, which
);
6946 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
6948 zfsdev_state_t
*zs
, *fpd
;
6950 ASSERT(filp
!= NULL
);
6951 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
6953 fpd
= filp
->private_data
;
6955 return (SET_ERROR(EBADF
));
6957 mutex_enter(&zfsdev_state_lock
);
6959 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6961 if (zs
->zs_minor
== -1)
6965 *minorp
= fpd
->zs_minor
;
6966 mutex_exit(&zfsdev_state_lock
);
6971 mutex_exit(&zfsdev_state_lock
);
6973 return (SET_ERROR(EBADF
));
6977 * Find a free minor number. The zfsdev_state_list is expected to
6978 * be short since it is only a list of currently open file handles.
6981 zfsdev_minor_alloc(void)
6983 static minor_t last_minor
= 0;
6986 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6988 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6989 if (m
> ZFSDEV_MAX_MINOR
)
6991 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
7001 zfsdev_state_init(struct file
*filp
)
7003 zfsdev_state_t
*zs
, *zsprev
= NULL
;
7005 boolean_t newzs
= B_FALSE
;
7007 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
7009 minor
= zfsdev_minor_alloc();
7011 return (SET_ERROR(ENXIO
));
7013 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
7014 if (zs
->zs_minor
== -1)
7020 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
7025 filp
->private_data
= zs
;
7027 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
7028 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
7032 * In order to provide for lock-free concurrent read access
7033 * to the minor list in zfsdev_get_state_impl(), new entries
7034 * must be completely written before linking them into the
7035 * list whereas existing entries are already linked; the last
7036 * operation must be updating zs_minor (from -1 to the new
7040 zs
->zs_minor
= minor
;
7042 zsprev
->zs_next
= zs
;
7045 zs
->zs_minor
= minor
;
7052 zfsdev_state_destroy(struct file
*filp
)
7056 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
7057 ASSERT(filp
->private_data
!= NULL
);
7059 zs
= filp
->private_data
;
7061 zfs_onexit_destroy(zs
->zs_onexit
);
7062 zfs_zevent_destroy(zs
->zs_zevent
);
7068 zfsdev_open(struct inode
*ino
, struct file
*filp
)
7072 mutex_enter(&zfsdev_state_lock
);
7073 error
= zfsdev_state_init(filp
);
7074 mutex_exit(&zfsdev_state_lock
);
7080 zfsdev_release(struct inode
*ino
, struct file
*filp
)
7084 mutex_enter(&zfsdev_state_lock
);
7085 error
= zfsdev_state_destroy(filp
);
7086 mutex_exit(&zfsdev_state_lock
);
7092 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
7096 int error
, rc
, flag
= 0;
7097 const zfs_ioc_vec_t
*vec
;
7098 char *saved_poolname
= NULL
;
7099 nvlist_t
*innvl
= NULL
;
7100 fstrans_cookie_t cookie
;
7102 vecnum
= cmd
- ZFS_IOC_FIRST
;
7103 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
7104 return (-SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL
));
7105 vec
= &zfs_ioc_vec
[vecnum
];
7108 * The registered ioctl list may be sparse, verify that either
7109 * a normal or legacy handler are registered.
7111 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
7112 return (-SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL
));
7114 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
7116 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
7118 error
= SET_ERROR(EFAULT
);
7122 zc
->zc_iflags
= flag
& FKIOCTL
;
7123 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
7125 * Make sure the user doesn't pass in an insane value for
7126 * zc_nvlist_src_size. We have to check, since we will end
7127 * up allocating that much memory inside of get_nvlist(). This
7128 * prevents a nefarious user from allocating tons of kernel
7131 * Also, we return EINVAL instead of ENOMEM here. The reason
7132 * being that returning ENOMEM from an ioctl() has a special
7133 * connotation; that the user's size value is too small and
7134 * needs to be expanded to hold the nvlist. See
7135 * zcmd_expand_dst_nvlist() for details.
7137 error
= SET_ERROR(EINVAL
); /* User's size too big */
7139 } else if (zc
->zc_nvlist_src_size
!= 0) {
7140 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
7141 zc
->zc_iflags
, &innvl
);
7147 * Ensure that all pool/dataset names are valid before we pass down to
7150 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
7151 switch (vec
->zvec_namecheck
) {
7153 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
7154 error
= SET_ERROR(EINVAL
);
7156 error
= pool_status_check(zc
->zc_name
,
7157 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
7161 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
7162 error
= SET_ERROR(EINVAL
);
7164 error
= pool_status_check(zc
->zc_name
,
7165 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
7173 * Ensure that all input pairs are valid before we pass them down
7174 * to the lower layers.
7176 * The vectored functions can use fnvlist_lookup_{type} for any
7177 * required pairs since zfs_check_input_nvpairs() confirmed that
7178 * they exist and are of the correct type.
7180 if (error
== 0 && vec
->zvec_func
!= NULL
) {
7181 error
= zfs_check_input_nvpairs(innvl
, vec
);
7187 cookie
= spl_fstrans_mark();
7188 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
7189 spl_fstrans_unmark(cookie
);
7195 /* legacy ioctls can modify zc_name */
7196 saved_poolname
= strdup(zc
->zc_name
);
7197 if (saved_poolname
== NULL
) {
7198 error
= SET_ERROR(ENOMEM
);
7201 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
7204 if (vec
->zvec_func
!= NULL
) {
7208 nvlist_t
*lognv
= NULL
;
7210 ASSERT(vec
->zvec_legacy_func
== NULL
);
7213 * Add the innvl to the lognv before calling the func,
7214 * in case the func changes the innvl.
7216 if (vec
->zvec_allow_log
) {
7217 lognv
= fnvlist_alloc();
7218 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
7220 if (!nvlist_empty(innvl
)) {
7221 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
7226 outnvl
= fnvlist_alloc();
7227 cookie
= spl_fstrans_mark();
7228 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
7229 spl_fstrans_unmark(cookie
);
7232 * Some commands can partially execute, modify state, and still
7233 * return an error. In these cases, attempt to record what
7237 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
7238 vec
->zvec_allow_log
&&
7239 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
7240 if (!nvlist_empty(outnvl
)) {
7241 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
7245 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
7248 (void) spa_history_log_nvl(spa
, lognv
);
7249 spa_close(spa
, FTAG
);
7251 fnvlist_free(lognv
);
7253 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
7255 if (vec
->zvec_smush_outnvlist
) {
7256 smusherror
= nvlist_smush(outnvl
,
7257 zc
->zc_nvlist_dst_size
);
7259 if (smusherror
== 0)
7260 puterror
= put_nvlist(zc
, outnvl
);
7266 nvlist_free(outnvl
);
7268 cookie
= spl_fstrans_mark();
7269 error
= vec
->zvec_legacy_func(zc
);
7270 spl_fstrans_unmark(cookie
);
7275 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
7276 if (error
== 0 && rc
!= 0)
7277 error
= SET_ERROR(EFAULT
);
7278 if (error
== 0 && vec
->zvec_allow_log
) {
7279 char *s
= tsd_get(zfs_allow_log_key
);
7282 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
7284 if (saved_poolname
!= NULL
)
7285 strfree(saved_poolname
);
7288 kmem_free(zc
, sizeof (zfs_cmd_t
));
7292 #ifdef CONFIG_COMPAT
7294 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
7296 return (zfsdev_ioctl(filp
, cmd
, arg
));
7299 #define zfsdev_compat_ioctl NULL
7302 static const struct file_operations zfsdev_fops
= {
7303 .open
= zfsdev_open
,
7304 .release
= zfsdev_release
,
7305 .unlocked_ioctl
= zfsdev_ioctl
,
7306 .compat_ioctl
= zfsdev_compat_ioctl
,
7307 .owner
= THIS_MODULE
,
7310 static struct miscdevice zfs_misc
= {
7311 .minor
= ZFS_DEVICE_MINOR
,
7313 .fops
= &zfsdev_fops
,
7316 MODULE_ALIAS_MISCDEV(ZFS_DEVICE_MINOR
);
7317 MODULE_ALIAS("devname:zfs");
7324 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
7325 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
7326 zfsdev_state_list
->zs_minor
= -1;
7328 error
= misc_register(&zfs_misc
);
7329 if (error
== -EBUSY
) {
7331 * Fallback to dynamic minor allocation in the event of a
7332 * collision with a reserved minor in linux/miscdevice.h.
7333 * In this case the kernel modules must be manually loaded.
7335 printk(KERN_INFO
"ZFS: misc_register() with static minor %d "
7336 "failed %d, retrying with MISC_DYNAMIC_MINOR\n",
7337 ZFS_DEVICE_MINOR
, error
);
7339 zfs_misc
.minor
= MISC_DYNAMIC_MINOR
;
7340 error
= misc_register(&zfs_misc
);
7344 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
7352 zfsdev_state_t
*zs
, *zsprev
= NULL
;
7354 misc_deregister(&zfs_misc
);
7355 mutex_destroy(&zfsdev_state_lock
);
7357 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
7359 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7363 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
7367 zfs_allow_log_destroy(void *arg
)
7369 char *poolname
= arg
;
7371 if (poolname
!= NULL
)
7376 #define ZFS_DEBUG_STR " (DEBUG mode)"
7378 #define ZFS_DEBUG_STR ""
7386 error
= -vn_set_pwd("/");
7389 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
7393 if ((error
= -zvol_init()) != 0)
7396 spa_init(FREAD
| FWRITE
);
7402 if ((error
= zfs_attach()) != 0)
7405 tsd_create(&zfs_fsyncer_key
, NULL
);
7406 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
7407 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
7409 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
7410 "ZFS pool version %s, ZFS filesystem version %s\n",
7411 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
7412 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
7413 #ifndef CONFIG_FS_POSIX_ACL
7414 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
7415 #endif /* CONFIG_FS_POSIX_ACL */
7424 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
7425 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
7426 ZFS_DEBUG_STR
, error
);
7440 tsd_destroy(&zfs_fsyncer_key
);
7441 tsd_destroy(&rrw_tsd_key
);
7442 tsd_destroy(&zfs_allow_log_key
);
7444 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
7445 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
7448 #if defined(_KERNEL)
7452 MODULE_DESCRIPTION("ZFS");
7453 MODULE_AUTHOR(ZFS_META_AUTHOR
);
7454 MODULE_LICENSE(ZFS_META_LICENSE
);
7455 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);