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) 2012, Joyent, Inc. All rights reserved.
28 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
29 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
30 * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
31 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
32 * Copyright (c) 2013 Steven Hartland. All rights reserved.
33 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
39 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
40 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
42 * There are two ways that we handle ioctls: the legacy way where almost
43 * all of the logic is in the ioctl callback, and the new way where most
44 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
46 * Non-legacy ioctls should be registered by calling
47 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
48 * from userland by lzc_ioctl().
50 * The registration arguments are as follows:
53 * The name of the ioctl. This is used for history logging. If the
54 * ioctl returns successfully (the callback returns 0), and allow_log
55 * is true, then a history log entry will be recorded with the input &
56 * output nvlists. The log entry can be printed with "zpool history -i".
59 * The ioctl request number, which userland will pass to ioctl(2).
60 * The ioctl numbers can change from release to release, because
61 * the caller (libzfs) must be matched to the kernel.
63 * zfs_secpolicy_func_t *secpolicy
64 * This function will be called before the zfs_ioc_func_t, to
65 * determine if this operation is permitted. It should return EPERM
66 * on failure, and 0 on success. Checks include determining if the
67 * dataset is visible in this zone, and if the user has either all
68 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
69 * to do this operation on this dataset with "zfs allow".
71 * zfs_ioc_namecheck_t namecheck
72 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
73 * name, a dataset name, or nothing. If the name is not well-formed,
74 * the ioctl will fail and the callback will not be called.
75 * Therefore, the callback can assume that the name is well-formed
76 * (e.g. is null-terminated, doesn't have more than one '@' character,
77 * doesn't have invalid characters).
79 * zfs_ioc_poolcheck_t pool_check
80 * This specifies requirements on the pool state. If the pool does
81 * not meet them (is suspended or is readonly), the ioctl will fail
82 * and the callback will not be called. If any checks are specified
83 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
84 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
85 * POOL_CHECK_READONLY).
87 * boolean_t smush_outnvlist
88 * If smush_outnvlist is true, then the output is presumed to be a
89 * list of errors, and it will be "smushed" down to fit into the
90 * caller's buffer, by removing some entries and replacing them with a
91 * single "N_MORE_ERRORS" entry indicating how many were removed. See
92 * nvlist_smush() for details. If smush_outnvlist is false, and the
93 * outnvlist does not fit into the userland-provided buffer, then the
94 * ioctl will fail with ENOMEM.
96 * zfs_ioc_func_t *func
97 * The callback function that will perform the operation.
99 * The callback should return 0 on success, or an error number on
100 * failure. If the function fails, the userland ioctl will return -1,
101 * and errno will be set to the callback's return value. The callback
102 * will be called with the following arguments:
105 * The name of the pool or dataset to operate on, from
106 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
107 * expected type (pool, dataset, or none).
110 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
111 * NULL if no input nvlist was provided. Changes to this nvlist are
112 * ignored. If the input nvlist could not be deserialized, the
113 * ioctl will fail and the callback will not be called.
116 * The output nvlist, initially empty. The callback can fill it in,
117 * and it will be returned to userland by serializing it into
118 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
119 * fails (e.g. because the caller didn't supply a large enough
120 * buffer), then the overall ioctl will fail. See the
121 * 'smush_nvlist' argument above for additional behaviors.
123 * There are two typical uses of the output nvlist:
124 * - To return state, e.g. property values. In this case,
125 * smush_outnvlist should be false. If the buffer was not large
126 * enough, the caller will reallocate a larger buffer and try
129 * - To return multiple errors from an ioctl which makes on-disk
130 * changes. In this case, smush_outnvlist should be true.
131 * Ioctls which make on-disk modifications should generally not
132 * use the outnvl if they succeed, because the caller can not
133 * distinguish between the operation failing, and
134 * deserialization failing.
137 #include <sys/types.h>
138 #include <sys/param.h>
139 #include <sys/errno.h>
142 #include <sys/modctl.h>
143 #include <sys/open.h>
144 #include <sys/file.h>
145 #include <sys/kmem.h>
146 #include <sys/conf.h>
147 #include <sys/cmn_err.h>
148 #include <sys/stat.h>
149 #include <sys/zfs_ioctl.h>
150 #include <sys/zfs_vfsops.h>
151 #include <sys/zfs_znode.h>
154 #include <sys/spa_impl.h>
155 #include <sys/vdev.h>
156 #include <sys/priv_impl.h>
158 #include <sys/dsl_dir.h>
159 #include <sys/dsl_dataset.h>
160 #include <sys/dsl_prop.h>
161 #include <sys/dsl_deleg.h>
162 #include <sys/dmu_objset.h>
163 #include <sys/dmu_impl.h>
164 #include <sys/dmu_tx.h>
166 #include <sys/sunddi.h>
167 #include <sys/sunldi.h>
168 #include <sys/policy.h>
169 #include <sys/zone.h>
170 #include <sys/nvpair.h>
171 #include <sys/pathname.h>
172 #include <sys/mount.h>
174 #include <sys/fs/zfs.h>
175 #include <sys/zfs_ctldir.h>
176 #include <sys/zfs_dir.h>
177 #include <sys/zfs_onexit.h>
178 #include <sys/zvol.h>
179 #include <sys/dsl_scan.h>
180 #include <sharefs/share.h>
181 #include <sys/fm/util.h>
183 #include <sys/dmu_send.h>
184 #include <sys/dsl_destroy.h>
185 #include <sys/dsl_bookmark.h>
186 #include <sys/dsl_userhold.h>
187 #include <sys/zfeature.h>
188 #include <sys/zio_checksum.h>
190 #include <linux/miscdevice.h>
191 #include <linux/slab.h>
193 #include "zfs_namecheck.h"
194 #include "zfs_prop.h"
195 #include "zfs_deleg.h"
196 #include "zfs_comutil.h"
199 * Limit maximum nvlist size. We don't want users passing in insane values
200 * for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
202 #define MAX_NVLIST_SRC_SIZE KMALLOC_MAX_SIZE
204 kmutex_t zfsdev_state_lock
;
205 zfsdev_state_t
*zfsdev_state_list
;
207 extern void zfs_init(void);
208 extern void zfs_fini(void);
210 uint_t zfs_fsyncer_key
;
211 extern uint_t rrw_tsd_key
;
212 static uint_t zfs_allow_log_key
;
214 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
215 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
216 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
222 } zfs_ioc_namecheck_t
;
225 POOL_CHECK_NONE
= 1 << 0,
226 POOL_CHECK_SUSPENDED
= 1 << 1,
227 POOL_CHECK_READONLY
= 1 << 2,
228 } zfs_ioc_poolcheck_t
;
230 typedef struct zfs_ioc_vec
{
231 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
232 zfs_ioc_func_t
*zvec_func
;
233 zfs_secpolicy_func_t
*zvec_secpolicy
;
234 zfs_ioc_namecheck_t zvec_namecheck
;
235 boolean_t zvec_allow_log
;
236 zfs_ioc_poolcheck_t zvec_pool_check
;
237 boolean_t zvec_smush_outnvlist
;
238 const char *zvec_name
;
241 /* This array is indexed by zfs_userquota_prop_t */
242 static const char *userquota_perms
[] = {
243 ZFS_DELEG_PERM_USERUSED
,
244 ZFS_DELEG_PERM_USERQUOTA
,
245 ZFS_DELEG_PERM_GROUPUSED
,
246 ZFS_DELEG_PERM_GROUPQUOTA
,
247 ZFS_DELEG_PERM_USEROBJUSED
,
248 ZFS_DELEG_PERM_USEROBJQUOTA
,
249 ZFS_DELEG_PERM_GROUPOBJUSED
,
250 ZFS_DELEG_PERM_GROUPOBJQUOTA
,
253 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
254 static int zfs_ioc_userobjspace_upgrade(zfs_cmd_t
*zc
);
255 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
257 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
259 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
261 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
262 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
265 history_str_free(char *buf
)
267 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
271 history_str_get(zfs_cmd_t
*zc
)
275 if (zc
->zc_history
== 0)
278 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
279 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
280 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
281 history_str_free(buf
);
285 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
291 * Check to see if the named dataset is currently defined as bootable
294 zfs_is_bootfs(const char *name
)
298 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
300 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
301 dmu_objset_rele(os
, FTAG
);
308 * Return non-zero if the spa version is less than requested version.
311 zfs_earlier_version(const char *name
, int version
)
315 if (spa_open(name
, &spa
, FTAG
) == 0) {
316 if (spa_version(spa
) < version
) {
317 spa_close(spa
, FTAG
);
320 spa_close(spa
, FTAG
);
326 * Return TRUE if the ZPL version is less than requested version.
329 zpl_earlier_version(const char *name
, int version
)
332 boolean_t rc
= B_TRUE
;
334 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
337 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
338 dmu_objset_rele(os
, FTAG
);
341 /* XXX reading from non-owned objset */
342 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
343 rc
= zplversion
< version
;
344 dmu_objset_rele(os
, FTAG
);
350 zfs_log_history(zfs_cmd_t
*zc
)
355 if ((buf
= history_str_get(zc
)) == NULL
)
358 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
359 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
360 (void) spa_history_log(spa
, buf
);
361 spa_close(spa
, FTAG
);
363 history_str_free(buf
);
367 * Policy for top-level read operations (list pools). Requires no privileges,
368 * and can be used in the local zone, as there is no associated dataset.
372 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
378 * Policy for dataset read operations (list children, get statistics). Requires
379 * no privileges, but must be visible in the local zone.
383 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
385 if (INGLOBALZONE(curproc
) ||
386 zone_dataset_visible(zc
->zc_name
, NULL
))
389 return (SET_ERROR(ENOENT
));
393 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
398 * The dataset must be visible by this zone -- check this first
399 * so they don't see EPERM on something they shouldn't know about.
401 if (!INGLOBALZONE(curproc
) &&
402 !zone_dataset_visible(dataset
, &writable
))
403 return (SET_ERROR(ENOENT
));
405 if (INGLOBALZONE(curproc
)) {
407 * If the fs is zoned, only root can access it from the
410 if (secpolicy_zfs(cr
) && zoned
)
411 return (SET_ERROR(EPERM
));
414 * If we are in a local zone, the 'zoned' property must be set.
417 return (SET_ERROR(EPERM
));
419 /* must be writable by this zone */
421 return (SET_ERROR(EPERM
));
427 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
431 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
432 return (SET_ERROR(ENOENT
));
434 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
438 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
442 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
443 return (SET_ERROR(ENOENT
));
445 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
449 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
450 const char *perm
, cred_t
*cr
)
454 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
456 error
= secpolicy_zfs(cr
);
458 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
464 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
470 error
= dsl_pool_hold(name
, FTAG
, &dp
);
474 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
476 dsl_pool_rele(dp
, FTAG
);
480 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
482 dsl_dataset_rele(ds
, FTAG
);
483 dsl_pool_rele(dp
, FTAG
);
488 * Policy for setting the security label property.
490 * Returns 0 for success, non-zero for access and other errors.
493 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
496 char ds_hexsl
[MAXNAMELEN
];
497 bslabel_t ds_sl
, new_sl
;
498 boolean_t new_default
= FALSE
;
500 int needed_priv
= -1;
503 /* First get the existing dataset label. */
504 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
505 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
507 return (SET_ERROR(EPERM
));
509 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
512 /* The label must be translatable */
513 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
514 return (SET_ERROR(EINVAL
));
517 * In a non-global zone, disallow attempts to set a label that
518 * doesn't match that of the zone; otherwise no other checks
521 if (!INGLOBALZONE(curproc
)) {
522 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
523 return (SET_ERROR(EPERM
));
528 * For global-zone datasets (i.e., those whose zoned property is
529 * "off", verify that the specified new label is valid for the
532 if (dsl_prop_get_integer(name
,
533 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
534 return (SET_ERROR(EPERM
));
536 if (zfs_check_global_label(name
, strval
) != 0)
537 return (SET_ERROR(EPERM
));
541 * If the existing dataset label is nondefault, check if the
542 * dataset is mounted (label cannot be changed while mounted).
543 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
544 * mounted (or isn't a dataset, doesn't exist, ...).
546 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
548 static char *setsl_tag
= "setsl_tag";
551 * Try to own the dataset; abort if there is any error,
552 * (e.g., already mounted, in use, or other error).
554 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
,
557 return (SET_ERROR(EPERM
));
559 dmu_objset_disown(os
, setsl_tag
);
562 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
566 if (hexstr_to_label(strval
, &new_sl
) != 0)
567 return (SET_ERROR(EPERM
));
569 if (blstrictdom(&ds_sl
, &new_sl
))
570 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
571 else if (blstrictdom(&new_sl
, &ds_sl
))
572 needed_priv
= PRIV_FILE_UPGRADE_SL
;
574 /* dataset currently has a default label */
576 needed_priv
= PRIV_FILE_UPGRADE_SL
;
580 if (needed_priv
!= -1)
581 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
585 #endif /* HAVE_MLSLABEL */
589 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
595 * Check permissions for special properties.
602 * Disallow setting of 'zoned' from within a local zone.
604 if (!INGLOBALZONE(curproc
))
605 return (SET_ERROR(EPERM
));
609 case ZFS_PROP_FILESYSTEM_LIMIT
:
610 case ZFS_PROP_SNAPSHOT_LIMIT
:
611 if (!INGLOBALZONE(curproc
)) {
613 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
615 * Unprivileged users are allowed to modify the
616 * limit on things *under* (ie. contained by)
617 * the thing they own.
619 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
621 return (SET_ERROR(EPERM
));
622 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
623 return (SET_ERROR(EPERM
));
627 case ZFS_PROP_MLSLABEL
:
628 if (!is_system_labeled())
629 return (SET_ERROR(EPERM
));
631 if (nvpair_value_string(propval
, &strval
) == 0) {
634 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
641 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
646 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
650 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
655 * permission to set permissions will be evaluated later in
656 * dsl_deleg_can_allow()
663 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
665 return (zfs_secpolicy_write_perms(zc
->zc_name
,
666 ZFS_DELEG_PERM_ROLLBACK
, cr
));
671 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
679 * Generate the current snapshot name from the given objsetid, then
680 * use that name for the secpolicy/zone checks.
682 cp
= strchr(zc
->zc_name
, '@');
684 return (SET_ERROR(EINVAL
));
685 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
689 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
691 dsl_pool_rele(dp
, FTAG
);
695 dsl_dataset_name(ds
, zc
->zc_name
);
697 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
698 ZFS_DELEG_PERM_SEND
, cr
);
699 dsl_dataset_rele(ds
, FTAG
);
700 dsl_pool_rele(dp
, FTAG
);
707 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
709 return (zfs_secpolicy_write_perms(zc
->zc_name
,
710 ZFS_DELEG_PERM_SEND
, cr
));
713 #ifdef HAVE_SMB_SHARE
716 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
721 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
722 NO_FOLLOW
, NULL
, &vp
)) != 0)
725 /* Now make sure mntpnt and dataset are ZFS */
727 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
728 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
729 zc
->zc_name
) != 0)) {
731 return (SET_ERROR(EPERM
));
735 return (dsl_deleg_access(zc
->zc_name
,
736 ZFS_DELEG_PERM_SHARE
, cr
));
738 #endif /* HAVE_SMB_SHARE */
741 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
743 #ifdef HAVE_SMB_SHARE
744 if (!INGLOBALZONE(curproc
))
745 return (SET_ERROR(EPERM
));
747 if (secpolicy_nfs(cr
) == 0) {
750 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
753 return (SET_ERROR(ENOTSUP
));
754 #endif /* HAVE_SMB_SHARE */
758 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
760 #ifdef HAVE_SMB_SHARE
761 if (!INGLOBALZONE(curproc
))
762 return (SET_ERROR(EPERM
));
764 if (secpolicy_smb(cr
) == 0) {
767 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
770 return (SET_ERROR(ENOTSUP
));
771 #endif /* HAVE_SMB_SHARE */
775 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
780 * Remove the @bla or /bla from the end of the name to get the parent.
782 (void) strncpy(parent
, datasetname
, parentsize
);
783 cp
= strrchr(parent
, '@');
787 cp
= strrchr(parent
, '/');
789 return (SET_ERROR(ENOENT
));
797 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
801 if ((error
= zfs_secpolicy_write_perms(name
,
802 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
805 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
810 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
812 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
816 * Destroying snapshots with delegated permissions requires
817 * descendant mount and destroy permissions.
821 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
824 nvpair_t
*pair
, *nextpair
;
827 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
828 return (SET_ERROR(EINVAL
));
829 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
831 nextpair
= nvlist_next_nvpair(snaps
, pair
);
832 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
833 if (error
== ENOENT
) {
835 * Ignore any snapshots that don't exist (we consider
836 * them "already destroyed"). Remove the name from the
837 * nvl here in case the snapshot is created between
838 * now and when we try to destroy it (in which case
839 * we don't want to destroy it since we haven't
840 * checked for permission).
842 fnvlist_remove_nvpair(snaps
, pair
);
853 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
855 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
858 if ((error
= zfs_secpolicy_write_perms(from
,
859 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
862 if ((error
= zfs_secpolicy_write_perms(from
,
863 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
866 if ((error
= zfs_get_parent(to
, parentname
,
867 sizeof (parentname
))) != 0)
870 if ((error
= zfs_secpolicy_write_perms(parentname
,
871 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
874 if ((error
= zfs_secpolicy_write_perms(parentname
,
875 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
883 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
885 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
890 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
893 dsl_dataset_t
*clone
;
896 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
897 ZFS_DELEG_PERM_PROMOTE
, cr
);
901 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
905 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
908 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
909 dsl_dataset_t
*origin
= NULL
;
913 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
914 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
916 dsl_dataset_rele(clone
, FTAG
);
917 dsl_pool_rele(dp
, FTAG
);
921 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
922 ZFS_DELEG_PERM_MOUNT
, cr
);
924 dsl_dataset_name(origin
, parentname
);
926 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
927 ZFS_DELEG_PERM_PROMOTE
, cr
);
929 dsl_dataset_rele(clone
, FTAG
);
930 dsl_dataset_rele(origin
, FTAG
);
932 dsl_pool_rele(dp
, FTAG
);
938 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
942 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
943 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
946 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
947 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
950 return (zfs_secpolicy_write_perms(zc
->zc_name
,
951 ZFS_DELEG_PERM_CREATE
, cr
));
956 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
958 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
962 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
964 return (zfs_secpolicy_write_perms(name
,
965 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
969 * Check for permission to create each snapshot in the nvlist.
973 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
979 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
980 return (SET_ERROR(EINVAL
));
981 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
982 pair
= nvlist_next_nvpair(snaps
, pair
)) {
983 char *name
= nvpair_name(pair
);
984 char *atp
= strchr(name
, '@');
987 error
= SET_ERROR(EINVAL
);
991 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
1000 * Check for permission to create each snapshot in the nvlist.
1004 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1009 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
1010 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1011 char *name
= nvpair_name(pair
);
1012 char *hashp
= strchr(name
, '#');
1014 if (hashp
== NULL
) {
1015 error
= SET_ERROR(EINVAL
);
1019 error
= zfs_secpolicy_write_perms(name
,
1020 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1030 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1032 nvpair_t
*pair
, *nextpair
;
1035 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1037 char *name
= nvpair_name(pair
);
1038 char *hashp
= strchr(name
, '#');
1039 nextpair
= nvlist_next_nvpair(innvl
, pair
);
1041 if (hashp
== NULL
) {
1042 error
= SET_ERROR(EINVAL
);
1047 error
= zfs_secpolicy_write_perms(name
,
1048 ZFS_DELEG_PERM_DESTROY
, cr
);
1050 if (error
== ENOENT
) {
1052 * Ignore any filesystems that don't exist (we consider
1053 * their bookmarks "already destroyed"). Remove
1054 * the name from the nvl here in case the filesystem
1055 * is created between now and when we try to destroy
1056 * the bookmark (in which case we don't want to
1057 * destroy it since we haven't checked for permission).
1059 fnvlist_remove_nvpair(innvl
, pair
);
1071 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1074 * Even root must have a proper TSD so that we know what pool
1077 if (tsd_get(zfs_allow_log_key
) == NULL
)
1078 return (SET_ERROR(EPERM
));
1083 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1085 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1089 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1090 sizeof (parentname
))) != 0)
1093 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1094 (error
= zfs_secpolicy_write_perms(origin
,
1095 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1098 if ((error
= zfs_secpolicy_write_perms(parentname
,
1099 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1102 return (zfs_secpolicy_write_perms(parentname
,
1103 ZFS_DELEG_PERM_MOUNT
, cr
));
1107 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1108 * SYS_CONFIG privilege, which is not available in a local zone.
1112 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1114 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1115 return (SET_ERROR(EPERM
));
1121 * Policy for object to name lookups.
1125 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1129 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1132 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1137 * Policy for fault injection. Requires all privileges.
1141 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1143 return (secpolicy_zinject(cr
));
1148 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1150 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1152 if (prop
== ZPROP_INVAL
) {
1153 if (!zfs_prop_user(zc
->zc_value
))
1154 return (SET_ERROR(EINVAL
));
1155 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1156 ZFS_DELEG_PERM_USERPROP
, cr
));
1158 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1164 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1166 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1170 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1171 return (SET_ERROR(EINVAL
));
1173 if (zc
->zc_value
[0] == 0) {
1175 * They are asking about a posix uid/gid. If it's
1176 * themself, allow it.
1178 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1179 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
||
1180 zc
->zc_objset_type
== ZFS_PROP_USEROBJUSED
||
1181 zc
->zc_objset_type
== ZFS_PROP_USEROBJQUOTA
) {
1182 if (zc
->zc_guid
== crgetuid(cr
))
1185 if (groupmember(zc
->zc_guid
, cr
))
1190 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1191 userquota_perms
[zc
->zc_objset_type
], cr
));
1195 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1197 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1201 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1202 return (SET_ERROR(EINVAL
));
1204 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1205 userquota_perms
[zc
->zc_objset_type
], cr
));
1210 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1212 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1218 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1224 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1226 return (SET_ERROR(EINVAL
));
1228 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1229 pair
= nvlist_next_nvpair(holds
, pair
)) {
1230 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1231 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1234 error
= zfs_secpolicy_write_perms(fsname
,
1235 ZFS_DELEG_PERM_HOLD
, cr
);
1244 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1249 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1250 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1251 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1252 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1255 error
= zfs_secpolicy_write_perms(fsname
,
1256 ZFS_DELEG_PERM_RELEASE
, cr
);
1264 * Policy for allowing temporary snapshots to be taken or released
1267 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1270 * A temporary snapshot is the same as a snapshot,
1271 * hold, destroy and release all rolled into one.
1272 * Delegated diff alone is sufficient that we allow this.
1276 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1277 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1280 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1282 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1284 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1286 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1291 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1294 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1298 nvlist_t
*list
= NULL
;
1301 * Read in and unpack the user-supplied nvlist.
1304 return (SET_ERROR(EINVAL
));
1306 packed
= vmem_alloc(size
, KM_SLEEP
);
1308 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1310 vmem_free(packed
, size
);
1311 return (SET_ERROR(EFAULT
));
1314 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1315 vmem_free(packed
, size
);
1319 vmem_free(packed
, size
);
1326 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1327 * Entries will be removed from the end of the nvlist, and one int32 entry
1328 * named "N_MORE_ERRORS" will be added indicating how many entries were
1332 nvlist_smush(nvlist_t
*errors
, size_t max
)
1336 size
= fnvlist_size(errors
);
1339 nvpair_t
*more_errors
;
1343 return (SET_ERROR(ENOMEM
));
1345 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1346 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1349 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1351 fnvlist_remove_nvpair(errors
, pair
);
1353 size
= fnvlist_size(errors
);
1354 } while (size
> max
);
1356 fnvlist_remove_nvpair(errors
, more_errors
);
1357 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1358 ASSERT3U(fnvlist_size(errors
), <=, max
);
1365 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1367 char *packed
= NULL
;
1371 size
= fnvlist_size(nvl
);
1373 if (size
> zc
->zc_nvlist_dst_size
) {
1374 error
= SET_ERROR(ENOMEM
);
1376 packed
= fnvlist_pack(nvl
, &size
);
1377 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1378 size
, zc
->zc_iflags
) != 0)
1379 error
= SET_ERROR(EFAULT
);
1380 fnvlist_pack_free(packed
, size
);
1383 zc
->zc_nvlist_dst_size
= size
;
1384 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1389 get_zfs_sb(const char *dsname
, zfs_sb_t
**zsbp
)
1394 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1397 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1398 dmu_objset_rele(os
, FTAG
);
1399 return (SET_ERROR(EINVAL
));
1402 mutex_enter(&os
->os_user_ptr_lock
);
1403 *zsbp
= dmu_objset_get_user(os
);
1404 /* bump s_active only when non-zero to prevent umount race */
1405 if (*zsbp
== NULL
|| (*zsbp
)->z_sb
== NULL
||
1406 !atomic_inc_not_zero(&((*zsbp
)->z_sb
->s_active
))) {
1407 error
= SET_ERROR(ESRCH
);
1409 mutex_exit(&os
->os_user_ptr_lock
);
1410 dmu_objset_rele(os
, FTAG
);
1415 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1416 * case its z_sb will be NULL, and it will be opened as the owner.
1417 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1418 * which prevents all inode ops from running.
1421 zfs_sb_hold(const char *name
, void *tag
, zfs_sb_t
**zsbp
, boolean_t writer
)
1425 if (get_zfs_sb(name
, zsbp
) != 0)
1426 error
= zfs_sb_create(name
, NULL
, zsbp
);
1428 rrm_enter(&(*zsbp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1430 if ((*zsbp
)->z_unmounted
) {
1432 * XXX we could probably try again, since the unmounting
1433 * thread should be just about to disassociate the
1434 * objset from the zsb.
1436 rrm_exit(&(*zsbp
)->z_teardown_lock
, tag
);
1437 return (SET_ERROR(EBUSY
));
1444 zfs_sb_rele(zfs_sb_t
*zsb
, void *tag
)
1446 rrm_exit(&zsb
->z_teardown_lock
, tag
);
1449 deactivate_super(zsb
->z_sb
);
1451 dmu_objset_disown(zsb
->z_os
, zsb
);
1457 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1460 nvlist_t
*config
, *props
= NULL
;
1461 nvlist_t
*rootprops
= NULL
;
1462 nvlist_t
*zplprops
= NULL
;
1464 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1465 zc
->zc_iflags
, &config
)))
1468 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1469 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1470 zc
->zc_iflags
, &props
))) {
1471 nvlist_free(config
);
1476 nvlist_t
*nvl
= NULL
;
1477 uint64_t version
= SPA_VERSION
;
1479 (void) nvlist_lookup_uint64(props
,
1480 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1481 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1482 error
= SET_ERROR(EINVAL
);
1483 goto pool_props_bad
;
1485 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1487 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1489 nvlist_free(config
);
1493 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1495 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1496 error
= zfs_fill_zplprops_root(version
, rootprops
,
1499 goto pool_props_bad
;
1502 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1505 * Set the remaining root properties
1507 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1508 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1509 (void) spa_destroy(zc
->zc_name
);
1512 nvlist_free(rootprops
);
1513 nvlist_free(zplprops
);
1514 nvlist_free(config
);
1521 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1524 zfs_log_history(zc
);
1525 error
= spa_destroy(zc
->zc_name
);
1531 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1533 nvlist_t
*config
, *props
= NULL
;
1537 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1538 zc
->zc_iflags
, &config
)) != 0)
1541 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1542 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1543 zc
->zc_iflags
, &props
))) {
1544 nvlist_free(config
);
1548 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1549 guid
!= zc
->zc_guid
)
1550 error
= SET_ERROR(EINVAL
);
1552 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1554 if (zc
->zc_nvlist_dst
!= 0) {
1557 if ((err
= put_nvlist(zc
, config
)) != 0)
1561 nvlist_free(config
);
1568 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1571 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1572 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1574 zfs_log_history(zc
);
1575 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1581 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1586 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1587 return (SET_ERROR(EEXIST
));
1589 error
= put_nvlist(zc
, configs
);
1591 nvlist_free(configs
);
1598 * zc_name name of the pool
1601 * zc_cookie real errno
1602 * zc_nvlist_dst config nvlist
1603 * zc_nvlist_dst_size size of config nvlist
1606 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1612 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1613 sizeof (zc
->zc_value
));
1615 if (config
!= NULL
) {
1616 ret
= put_nvlist(zc
, config
);
1617 nvlist_free(config
);
1620 * The config may be present even if 'error' is non-zero.
1621 * In this case we return success, and preserve the real errno
1624 zc
->zc_cookie
= error
;
1633 * Try to import the given pool, returning pool stats as appropriate so that
1634 * user land knows which devices are available and overall pool health.
1637 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1639 nvlist_t
*tryconfig
, *config
;
1642 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1643 zc
->zc_iflags
, &tryconfig
)) != 0)
1646 config
= spa_tryimport(tryconfig
);
1648 nvlist_free(tryconfig
);
1651 return (SET_ERROR(EINVAL
));
1653 error
= put_nvlist(zc
, config
);
1654 nvlist_free(config
);
1661 * zc_name name of the pool
1662 * zc_cookie scan func (pool_scan_func_t)
1665 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1670 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1673 if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1674 error
= spa_scan_stop(spa
);
1676 error
= spa_scan(spa
, zc
->zc_cookie
);
1678 spa_close(spa
, FTAG
);
1684 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1689 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1692 spa_close(spa
, FTAG
);
1698 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1703 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1706 if (zc
->zc_cookie
< spa_version(spa
) ||
1707 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1708 spa_close(spa
, FTAG
);
1709 return (SET_ERROR(EINVAL
));
1712 spa_upgrade(spa
, zc
->zc_cookie
);
1713 spa_close(spa
, FTAG
);
1719 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1726 if ((size
= zc
->zc_history_len
) == 0)
1727 return (SET_ERROR(EINVAL
));
1729 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1732 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1733 spa_close(spa
, FTAG
);
1734 return (SET_ERROR(ENOTSUP
));
1737 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1738 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1739 &zc
->zc_history_len
, hist_buf
)) == 0) {
1740 error
= ddi_copyout(hist_buf
,
1741 (void *)(uintptr_t)zc
->zc_history
,
1742 zc
->zc_history_len
, zc
->zc_iflags
);
1745 spa_close(spa
, FTAG
);
1746 vmem_free(hist_buf
, size
);
1751 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1756 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1758 error
= spa_change_guid(spa
);
1759 spa_close(spa
, FTAG
);
1765 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1767 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1772 * zc_name name of filesystem
1773 * zc_obj object to find
1776 * zc_value name of object
1779 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1784 /* XXX reading from objset not owned */
1785 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1787 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1788 dmu_objset_rele(os
, FTAG
);
1789 return (SET_ERROR(EINVAL
));
1791 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1792 sizeof (zc
->zc_value
));
1793 dmu_objset_rele(os
, FTAG
);
1800 * zc_name name of filesystem
1801 * zc_obj object to find
1804 * zc_stat stats on object
1805 * zc_value path to object
1808 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1813 /* XXX reading from objset not owned */
1814 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1816 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1817 dmu_objset_rele(os
, FTAG
);
1818 return (SET_ERROR(EINVAL
));
1820 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1821 sizeof (zc
->zc_value
));
1822 dmu_objset_rele(os
, FTAG
);
1828 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1834 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1838 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1839 zc
->zc_iflags
, &config
);
1841 error
= spa_vdev_add(spa
, config
);
1842 nvlist_free(config
);
1844 spa_close(spa
, FTAG
);
1850 * zc_name name of the pool
1851 * zc_nvlist_conf nvlist of devices to remove
1852 * zc_cookie to stop the remove?
1855 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1860 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1863 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1864 spa_close(spa
, FTAG
);
1869 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1873 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1875 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1877 switch (zc
->zc_cookie
) {
1878 case VDEV_STATE_ONLINE
:
1879 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1882 case VDEV_STATE_OFFLINE
:
1883 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1886 case VDEV_STATE_FAULTED
:
1887 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1888 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1889 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1891 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1894 case VDEV_STATE_DEGRADED
:
1895 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1896 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1897 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1899 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1903 error
= SET_ERROR(EINVAL
);
1905 zc
->zc_cookie
= newstate
;
1906 spa_close(spa
, FTAG
);
1911 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1914 int replacing
= zc
->zc_cookie
;
1918 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1921 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1922 zc
->zc_iflags
, &config
)) == 0) {
1923 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1924 nvlist_free(config
);
1927 spa_close(spa
, FTAG
);
1932 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1937 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1940 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1942 spa_close(spa
, FTAG
);
1947 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1950 nvlist_t
*config
, *props
= NULL
;
1952 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1954 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1957 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1958 zc
->zc_iflags
, &config
))) {
1959 spa_close(spa
, FTAG
);
1963 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1964 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1965 zc
->zc_iflags
, &props
))) {
1966 spa_close(spa
, FTAG
);
1967 nvlist_free(config
);
1971 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1973 spa_close(spa
, FTAG
);
1975 nvlist_free(config
);
1982 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1985 char *path
= zc
->zc_value
;
1986 uint64_t guid
= zc
->zc_guid
;
1989 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1993 error
= spa_vdev_setpath(spa
, guid
, path
);
1994 spa_close(spa
, FTAG
);
1999 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
2002 char *fru
= zc
->zc_value
;
2003 uint64_t guid
= zc
->zc_guid
;
2006 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2010 error
= spa_vdev_setfru(spa
, guid
, fru
);
2011 spa_close(spa
, FTAG
);
2016 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2021 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2023 if (zc
->zc_nvlist_dst
!= 0 &&
2024 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2025 dmu_objset_stats(os
, nv
);
2027 * NB: zvol_get_stats() will read the objset contents,
2028 * which we aren't supposed to do with a
2029 * DS_MODE_USER hold, because it could be
2030 * inconsistent. So this is a bit of a workaround...
2031 * XXX reading with out owning
2033 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2034 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2035 error
= zvol_get_stats(os
, nv
);
2043 error
= put_nvlist(zc
, nv
);
2052 * zc_name name of filesystem
2053 * zc_nvlist_dst_size size of buffer for property nvlist
2056 * zc_objset_stats stats
2057 * zc_nvlist_dst property nvlist
2058 * zc_nvlist_dst_size size of property nvlist
2061 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2066 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2068 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2069 dmu_objset_rele(os
, FTAG
);
2077 * zc_name name of filesystem
2078 * zc_nvlist_dst_size size of buffer for property nvlist
2081 * zc_nvlist_dst received property nvlist
2082 * zc_nvlist_dst_size size of received property nvlist
2084 * Gets received properties (distinct from local properties on or after
2085 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2086 * local property values.
2089 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2095 * Without this check, we would return local property values if the
2096 * caller has not already received properties on or after
2097 * SPA_VERSION_RECVD_PROPS.
2099 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2100 return (SET_ERROR(ENOTSUP
));
2102 if (zc
->zc_nvlist_dst
!= 0 &&
2103 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2104 error
= put_nvlist(zc
, nv
);
2112 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2118 * zfs_get_zplprop() will either find a value or give us
2119 * the default value (if there is one).
2121 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2123 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2129 * zc_name name of filesystem
2130 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2133 * zc_nvlist_dst zpl property nvlist
2134 * zc_nvlist_dst_size size of zpl property nvlist
2137 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2142 /* XXX reading without owning */
2143 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2146 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2149 * NB: nvl_add_zplprop() will read the objset contents,
2150 * which we aren't supposed to do with a DS_MODE_USER
2151 * hold, because it could be inconsistent.
2153 if (zc
->zc_nvlist_dst
!= 0 &&
2154 !zc
->zc_objset_stats
.dds_inconsistent
&&
2155 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2158 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2159 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2160 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2161 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2162 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2163 err
= put_nvlist(zc
, nv
);
2166 err
= SET_ERROR(ENOENT
);
2168 dmu_objset_rele(os
, FTAG
);
2173 dataset_name_hidden(const char *name
)
2176 * Skip over datasets that are not visible in this zone,
2177 * internal datasets (which have a $ in their name), and
2178 * temporary datasets (which have a % in their name).
2180 if (strchr(name
, '$') != NULL
)
2182 if (strchr(name
, '%') != NULL
)
2184 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2191 * zc_name name of filesystem
2192 * zc_cookie zap cursor
2193 * zc_nvlist_dst_size size of buffer for property nvlist
2196 * zc_name name of next filesystem
2197 * zc_cookie zap cursor
2198 * zc_objset_stats stats
2199 * zc_nvlist_dst property nvlist
2200 * zc_nvlist_dst_size size of property nvlist
2203 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2208 size_t orig_len
= strlen(zc
->zc_name
);
2211 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2212 if (error
== ENOENT
)
2213 error
= SET_ERROR(ESRCH
);
2217 p
= strrchr(zc
->zc_name
, '/');
2218 if (p
== NULL
|| p
[1] != '\0')
2219 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2220 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2223 error
= dmu_dir_list_next(os
,
2224 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2225 NULL
, &zc
->zc_cookie
);
2226 if (error
== ENOENT
)
2227 error
= SET_ERROR(ESRCH
);
2228 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2229 dmu_objset_rele(os
, FTAG
);
2232 * If it's an internal dataset (ie. with a '$' in its name),
2233 * don't try to get stats for it, otherwise we'll return ENOENT.
2235 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2236 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2237 if (error
== ENOENT
) {
2238 /* We lost a race with destroy, get the next one. */
2239 zc
->zc_name
[orig_len
] = '\0';
2248 * zc_name name of filesystem
2249 * zc_cookie zap cursor
2250 * zc_nvlist_dst_size size of buffer for property nvlist
2253 * zc_name name of next snapshot
2254 * zc_objset_stats stats
2255 * zc_nvlist_dst property nvlist
2256 * zc_nvlist_dst_size size of property nvlist
2259 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2264 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2266 return (error
== ENOENT
? ESRCH
: error
);
2270 * A dataset name of maximum length cannot have any snapshots,
2271 * so exit immediately.
2273 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2274 ZFS_MAX_DATASET_NAME_LEN
) {
2275 dmu_objset_rele(os
, FTAG
);
2276 return (SET_ERROR(ESRCH
));
2279 error
= dmu_snapshot_list_next(os
,
2280 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2281 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2284 if (error
== 0 && !zc
->zc_simple
) {
2286 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2288 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2292 error
= dmu_objset_from_ds(ds
, &ossnap
);
2294 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2295 dsl_dataset_rele(ds
, FTAG
);
2297 } else if (error
== ENOENT
) {
2298 error
= SET_ERROR(ESRCH
);
2301 dmu_objset_rele(os
, FTAG
);
2302 /* if we failed, undo the @ that we tacked on to zc_name */
2304 *strchr(zc
->zc_name
, '@') = '\0';
2309 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2311 const char *propname
= nvpair_name(pair
);
2313 unsigned int vallen
;
2316 zfs_userquota_prop_t type
;
2322 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2324 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2325 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2327 return (SET_ERROR(EINVAL
));
2331 * A correctly constructed propname is encoded as
2332 * userquota@<rid>-<domain>.
2334 if ((dash
= strchr(propname
, '-')) == NULL
||
2335 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2337 return (SET_ERROR(EINVAL
));
2344 err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
2346 err
= zfs_set_userquota(zsb
, type
, domain
, rid
, quota
);
2347 zfs_sb_rele(zsb
, FTAG
);
2354 * If the named property is one that has a special function to set its value,
2355 * return 0 on success and a positive error code on failure; otherwise if it is
2356 * not one of the special properties handled by this function, return -1.
2358 * XXX: It would be better for callers of the property interface if we handled
2359 * these special cases in dsl_prop.c (in the dsl layer).
2362 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2365 const char *propname
= nvpair_name(pair
);
2366 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2370 if (prop
== ZPROP_INVAL
) {
2371 if (zfs_prop_userquota(propname
))
2372 return (zfs_prop_set_userquota(dsname
, pair
));
2376 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2378 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2379 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2383 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2386 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2389 case ZFS_PROP_QUOTA
:
2390 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2392 case ZFS_PROP_REFQUOTA
:
2393 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2395 case ZFS_PROP_FILESYSTEM_LIMIT
:
2396 case ZFS_PROP_SNAPSHOT_LIMIT
:
2397 if (intval
== UINT64_MAX
) {
2398 /* clearing the limit, just do it */
2401 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2404 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2405 * default path to set the value in the nvlist.
2410 case ZFS_PROP_RESERVATION
:
2411 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2413 case ZFS_PROP_REFRESERVATION
:
2414 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2416 case ZFS_PROP_VOLSIZE
:
2417 err
= zvol_set_volsize(dsname
, intval
);
2419 case ZFS_PROP_SNAPDEV
:
2420 err
= zvol_set_snapdev(dsname
, source
, intval
);
2422 case ZFS_PROP_VERSION
:
2426 if ((err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_TRUE
)) != 0)
2429 err
= zfs_set_version(zsb
, intval
);
2430 zfs_sb_rele(zsb
, FTAG
);
2432 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2435 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2436 (void) strcpy(zc
->zc_name
, dsname
);
2437 (void) zfs_ioc_userspace_upgrade(zc
);
2438 (void) zfs_ioc_userobjspace_upgrade(zc
);
2439 kmem_free(zc
, sizeof (zfs_cmd_t
));
2451 * This function is best effort. If it fails to set any of the given properties,
2452 * it continues to set as many as it can and returns the last error
2453 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2454 * with the list of names of all the properties that failed along with the
2455 * corresponding error numbers.
2457 * If every property is set successfully, zero is returned and errlist is not
2461 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2470 nvlist_t
*genericnvl
= fnvlist_alloc();
2471 nvlist_t
*retrynvl
= fnvlist_alloc();
2474 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2475 const char *propname
= nvpair_name(pair
);
2476 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2479 /* decode the property value */
2481 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2483 attrs
= fnvpair_value_nvlist(pair
);
2484 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2486 err
= SET_ERROR(EINVAL
);
2489 /* Validate value type */
2490 if (err
== 0 && prop
== ZPROP_INVAL
) {
2491 if (zfs_prop_user(propname
)) {
2492 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2493 err
= SET_ERROR(EINVAL
);
2494 } else if (zfs_prop_userquota(propname
)) {
2495 if (nvpair_type(propval
) !=
2496 DATA_TYPE_UINT64_ARRAY
)
2497 err
= SET_ERROR(EINVAL
);
2499 err
= SET_ERROR(EINVAL
);
2501 } else if (err
== 0) {
2502 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2503 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2504 err
= SET_ERROR(EINVAL
);
2505 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2508 intval
= fnvpair_value_uint64(propval
);
2510 switch (zfs_prop_get_type(prop
)) {
2511 case PROP_TYPE_NUMBER
:
2513 case PROP_TYPE_STRING
:
2514 err
= SET_ERROR(EINVAL
);
2516 case PROP_TYPE_INDEX
:
2517 if (zfs_prop_index_to_string(prop
,
2518 intval
, &unused
) != 0)
2519 err
= SET_ERROR(EINVAL
);
2523 "unknown property type");
2526 err
= SET_ERROR(EINVAL
);
2530 /* Validate permissions */
2532 err
= zfs_check_settable(dsname
, pair
, CRED());
2535 err
= zfs_prop_set_special(dsname
, source
, pair
);
2538 * For better performance we build up a list of
2539 * properties to set in a single transaction.
2541 err
= nvlist_add_nvpair(genericnvl
, pair
);
2542 } else if (err
!= 0 && nvl
!= retrynvl
) {
2544 * This may be a spurious error caused by
2545 * receiving quota and reservation out of order.
2546 * Try again in a second pass.
2548 err
= nvlist_add_nvpair(retrynvl
, pair
);
2553 if (errlist
!= NULL
)
2554 fnvlist_add_int32(errlist
, propname
, err
);
2559 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2564 if (!nvlist_empty(genericnvl
) &&
2565 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2567 * If this fails, we still want to set as many properties as we
2568 * can, so try setting them individually.
2571 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2572 const char *propname
= nvpair_name(pair
);
2576 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2578 attrs
= fnvpair_value_nvlist(pair
);
2579 propval
= fnvlist_lookup_nvpair(attrs
,
2583 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2584 strval
= fnvpair_value_string(propval
);
2585 err
= dsl_prop_set_string(dsname
, propname
,
2588 intval
= fnvpair_value_uint64(propval
);
2589 err
= dsl_prop_set_int(dsname
, propname
, source
,
2594 if (errlist
!= NULL
) {
2595 fnvlist_add_int32(errlist
, propname
,
2602 nvlist_free(genericnvl
);
2603 nvlist_free(retrynvl
);
2609 * Check that all the properties are valid user properties.
2612 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2614 nvpair_t
*pair
= NULL
;
2617 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2618 const char *propname
= nvpair_name(pair
);
2620 if (!zfs_prop_user(propname
) ||
2621 nvpair_type(pair
) != DATA_TYPE_STRING
)
2622 return (SET_ERROR(EINVAL
));
2624 if ((error
= zfs_secpolicy_write_perms(fsname
,
2625 ZFS_DELEG_PERM_USERPROP
, CRED())))
2628 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2629 return (SET_ERROR(ENAMETOOLONG
));
2631 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2632 return (SET_ERROR(E2BIG
));
2638 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2642 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2645 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2646 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2649 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2654 clear_received_props(const char *dsname
, nvlist_t
*props
,
2658 nvlist_t
*cleared_props
= NULL
;
2659 props_skip(props
, skipped
, &cleared_props
);
2660 if (!nvlist_empty(cleared_props
)) {
2662 * Acts on local properties until the dataset has received
2663 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2665 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2666 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2667 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2669 nvlist_free(cleared_props
);
2675 * zc_name name of filesystem
2676 * zc_value name of property to set
2677 * zc_nvlist_src{_size} nvlist of properties to apply
2678 * zc_cookie received properties flag
2681 * zc_nvlist_dst{_size} error for each unapplied received property
2684 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2687 boolean_t received
= zc
->zc_cookie
;
2688 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2693 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2694 zc
->zc_iflags
, &nvl
)) != 0)
2698 nvlist_t
*origprops
;
2700 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2701 (void) clear_received_props(zc
->zc_name
,
2703 nvlist_free(origprops
);
2706 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2709 errors
= fnvlist_alloc();
2711 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2713 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2714 (void) put_nvlist(zc
, errors
);
2717 nvlist_free(errors
);
2724 * zc_name name of filesystem
2725 * zc_value name of property to inherit
2726 * zc_cookie revert to received value if TRUE
2731 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2733 const char *propname
= zc
->zc_value
;
2734 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2735 boolean_t received
= zc
->zc_cookie
;
2736 zprop_source_t source
= (received
2737 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2738 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2747 * zfs_prop_set_special() expects properties in the form of an
2748 * nvpair with type info.
2750 if (prop
== ZPROP_INVAL
) {
2751 if (!zfs_prop_user(propname
))
2752 return (SET_ERROR(EINVAL
));
2754 type
= PROP_TYPE_STRING
;
2755 } else if (prop
== ZFS_PROP_VOLSIZE
||
2756 prop
== ZFS_PROP_VERSION
) {
2757 return (SET_ERROR(EINVAL
));
2759 type
= zfs_prop_get_type(prop
);
2762 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2765 case PROP_TYPE_STRING
:
2766 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2768 case PROP_TYPE_NUMBER
:
2769 case PROP_TYPE_INDEX
:
2770 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2774 return (SET_ERROR(EINVAL
));
2777 pair
= nvlist_next_nvpair(dummy
, NULL
);
2780 return (SET_ERROR(EINVAL
));
2782 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2785 return (err
); /* special property already handled */
2788 * Only check this in the non-received case. We want to allow
2789 * 'inherit -S' to revert non-inheritable properties like quota
2790 * and reservation to the received or default values even though
2791 * they are not considered inheritable.
2793 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2794 return (SET_ERROR(EINVAL
));
2797 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2798 return (dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
, source
));
2802 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2809 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2810 zc
->zc_iflags
, &props
)))
2814 * If the only property is the configfile, then just do a spa_lookup()
2815 * to handle the faulted case.
2817 pair
= nvlist_next_nvpair(props
, NULL
);
2818 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2819 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2820 nvlist_next_nvpair(props
, pair
) == NULL
) {
2821 mutex_enter(&spa_namespace_lock
);
2822 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2823 spa_configfile_set(spa
, props
, B_FALSE
);
2824 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2826 mutex_exit(&spa_namespace_lock
);
2833 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2838 error
= spa_prop_set(spa
, props
);
2841 spa_close(spa
, FTAG
);
2847 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2851 nvlist_t
*nvp
= NULL
;
2853 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2855 * If the pool is faulted, there may be properties we can still
2856 * get (such as altroot and cachefile), so attempt to get them
2859 mutex_enter(&spa_namespace_lock
);
2860 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2861 error
= spa_prop_get(spa
, &nvp
);
2862 mutex_exit(&spa_namespace_lock
);
2864 error
= spa_prop_get(spa
, &nvp
);
2865 spa_close(spa
, FTAG
);
2868 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2869 error
= put_nvlist(zc
, nvp
);
2871 error
= SET_ERROR(EFAULT
);
2879 * zc_name name of filesystem
2880 * zc_nvlist_src{_size} nvlist of delegated permissions
2881 * zc_perm_action allow/unallow flag
2886 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2889 nvlist_t
*fsaclnv
= NULL
;
2891 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2892 zc
->zc_iflags
, &fsaclnv
)) != 0)
2896 * Verify nvlist is constructed correctly
2898 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2899 nvlist_free(fsaclnv
);
2900 return (SET_ERROR(EINVAL
));
2904 * If we don't have PRIV_SYS_MOUNT, then validate
2905 * that user is allowed to hand out each permission in
2909 error
= secpolicy_zfs(CRED());
2911 if (zc
->zc_perm_action
== B_FALSE
) {
2912 error
= dsl_deleg_can_allow(zc
->zc_name
,
2915 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2921 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2923 nvlist_free(fsaclnv
);
2929 * zc_name name of filesystem
2932 * zc_nvlist_src{_size} nvlist of delegated permissions
2935 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2940 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2941 error
= put_nvlist(zc
, nvp
);
2950 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2952 zfs_creat_t
*zct
= arg
;
2954 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2957 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2961 * os parent objset pointer (NULL if root fs)
2962 * fuids_ok fuids allowed in this version of the spa?
2963 * sa_ok SAs allowed in this version of the spa?
2964 * createprops list of properties requested by creator
2967 * zplprops values for the zplprops we attach to the master node object
2968 * is_ci true if requested file system will be purely case-insensitive
2970 * Determine the settings for utf8only, normalization and
2971 * casesensitivity. Specific values may have been requested by the
2972 * creator and/or we can inherit values from the parent dataset. If
2973 * the file system is of too early a vintage, a creator can not
2974 * request settings for these properties, even if the requested
2975 * setting is the default value. We don't actually want to create dsl
2976 * properties for these, so remove them from the source nvlist after
2980 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2981 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2982 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2984 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2985 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2986 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2989 ASSERT(zplprops
!= NULL
);
2992 * Pull out creator prop choices, if any.
2995 (void) nvlist_lookup_uint64(createprops
,
2996 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2997 (void) nvlist_lookup_uint64(createprops
,
2998 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2999 (void) nvlist_remove_all(createprops
,
3000 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
3001 (void) nvlist_lookup_uint64(createprops
,
3002 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
3003 (void) nvlist_remove_all(createprops
,
3004 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
3005 (void) nvlist_lookup_uint64(createprops
,
3006 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
3007 (void) nvlist_remove_all(createprops
,
3008 zfs_prop_to_name(ZFS_PROP_CASE
));
3012 * If the zpl version requested is whacky or the file system
3013 * or pool is version is too "young" to support normalization
3014 * and the creator tried to set a value for one of the props,
3017 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3018 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3019 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3020 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3021 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3022 sense
!= ZFS_PROP_UNDEFINED
)))
3023 return (SET_ERROR(ENOTSUP
));
3026 * Put the version in the zplprops
3028 VERIFY(nvlist_add_uint64(zplprops
,
3029 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3031 if (norm
== ZFS_PROP_UNDEFINED
&&
3032 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3034 VERIFY(nvlist_add_uint64(zplprops
,
3035 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3038 * If we're normalizing, names must always be valid UTF-8 strings.
3042 if (u8
== ZFS_PROP_UNDEFINED
&&
3043 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3045 VERIFY(nvlist_add_uint64(zplprops
,
3046 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3048 if (sense
== ZFS_PROP_UNDEFINED
&&
3049 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3051 VERIFY(nvlist_add_uint64(zplprops
,
3052 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3055 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3061 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3062 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3064 boolean_t fuids_ok
, sa_ok
;
3065 uint64_t zplver
= ZPL_VERSION
;
3066 objset_t
*os
= NULL
;
3067 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3073 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3074 cp
= strrchr(parentname
, '/');
3078 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3081 spa_vers
= spa_version(spa
);
3082 spa_close(spa
, FTAG
);
3084 zplver
= zfs_zpl_version_map(spa_vers
);
3085 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3086 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3089 * Open parent object set so we can inherit zplprop values.
3091 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3094 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3096 dmu_objset_rele(os
, FTAG
);
3101 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3102 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3106 uint64_t zplver
= ZPL_VERSION
;
3109 zplver
= zfs_zpl_version_map(spa_vers
);
3110 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3111 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3113 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3114 createprops
, zplprops
, is_ci
);
3120 * "type" -> dmu_objset_type_t (int32)
3121 * (optional) "props" -> { prop -> value }
3124 * outnvl: propname -> error code (int32)
3127 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3130 zfs_creat_t zct
= { 0 };
3131 nvlist_t
*nvprops
= NULL
;
3132 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3134 dmu_objset_type_t type
;
3135 boolean_t is_insensitive
= B_FALSE
;
3137 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3138 return (SET_ERROR(EINVAL
));
3140 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3144 cbfunc
= zfs_create_cb
;
3148 cbfunc
= zvol_create_cb
;
3155 if (strchr(fsname
, '@') ||
3156 strchr(fsname
, '%'))
3157 return (SET_ERROR(EINVAL
));
3159 zct
.zct_props
= nvprops
;
3162 return (SET_ERROR(EINVAL
));
3164 if (type
== DMU_OST_ZVOL
) {
3165 uint64_t volsize
, volblocksize
;
3167 if (nvprops
== NULL
)
3168 return (SET_ERROR(EINVAL
));
3169 if (nvlist_lookup_uint64(nvprops
,
3170 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3171 return (SET_ERROR(EINVAL
));
3173 if ((error
= nvlist_lookup_uint64(nvprops
,
3174 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3175 &volblocksize
)) != 0 && error
!= ENOENT
)
3176 return (SET_ERROR(EINVAL
));
3179 volblocksize
= zfs_prop_default_numeric(
3180 ZFS_PROP_VOLBLOCKSIZE
);
3182 if ((error
= zvol_check_volblocksize(fsname
,
3183 volblocksize
)) != 0 ||
3184 (error
= zvol_check_volsize(volsize
,
3185 volblocksize
)) != 0)
3187 } else if (type
== DMU_OST_ZFS
) {
3191 * We have to have normalization and
3192 * case-folding flags correct when we do the
3193 * file system creation, so go figure them out
3196 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3197 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3198 error
= zfs_fill_zplprops(fsname
, nvprops
,
3199 zct
.zct_zplprops
, &is_insensitive
);
3201 nvlist_free(zct
.zct_zplprops
);
3206 error
= dmu_objset_create(fsname
, type
,
3207 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3208 nvlist_free(zct
.zct_zplprops
);
3211 * It would be nice to do this atomically.
3214 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3221 * Volumes will return EBUSY and cannot be destroyed
3222 * until all asynchronous minor handling has completed.
3223 * Wait for the spa_zvol_taskq to drain then retry.
3225 error2
= dsl_destroy_head(fsname
);
3226 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3227 error2
= spa_open(fsname
, &spa
, FTAG
);
3229 taskq_wait(spa
->spa_zvol_taskq
);
3230 spa_close(spa
, FTAG
);
3232 error2
= dsl_destroy_head(fsname
);
3241 * "origin" -> name of origin snapshot
3242 * (optional) "props" -> { prop -> value }
3246 * outnvl: propname -> error code (int32)
3249 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3252 nvlist_t
*nvprops
= NULL
;
3255 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3256 return (SET_ERROR(EINVAL
));
3257 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3259 if (strchr(fsname
, '@') ||
3260 strchr(fsname
, '%'))
3261 return (SET_ERROR(EINVAL
));
3263 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3264 return (SET_ERROR(EINVAL
));
3265 error
= dmu_objset_clone(fsname
, origin_name
);
3270 * It would be nice to do this atomically.
3273 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3276 (void) dsl_destroy_head(fsname
);
3283 * "snaps" -> { snapshot1, snapshot2 }
3284 * (optional) "props" -> { prop -> value (string) }
3287 * outnvl: snapshot -> error code (int32)
3290 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3293 nvlist_t
*props
= NULL
;
3295 nvpair_t
*pair
, *pair2
;
3297 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3298 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3301 if (!nvlist_empty(props
) &&
3302 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3303 return (SET_ERROR(ENOTSUP
));
3305 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3306 return (SET_ERROR(EINVAL
));
3307 poollen
= strlen(poolname
);
3308 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3309 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3310 const char *name
= nvpair_name(pair
);
3311 const char *cp
= strchr(name
, '@');
3314 * The snap name must contain an @, and the part after it must
3315 * contain only valid characters.
3318 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3319 return (SET_ERROR(EINVAL
));
3322 * The snap must be in the specified pool.
3324 if (strncmp(name
, poolname
, poollen
) != 0 ||
3325 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3326 return (SET_ERROR(EXDEV
));
3328 /* This must be the only snap of this fs. */
3329 for (pair2
= nvlist_next_nvpair(snaps
, pair
);
3330 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3331 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3333 return (SET_ERROR(EXDEV
));
3338 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3344 * innvl: "message" -> string
3348 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3356 * The poolname in the ioctl is not set, we get it from the TSD,
3357 * which was set at the end of the last successful ioctl that allows
3358 * logging. The secpolicy func already checked that it is set.
3359 * Only one log ioctl is allowed after each successful ioctl, so
3360 * we clear the TSD here.
3362 poolname
= tsd_get(zfs_allow_log_key
);
3363 if (poolname
== NULL
)
3364 return (SET_ERROR(EINVAL
));
3365 (void) tsd_set(zfs_allow_log_key
, NULL
);
3366 error
= spa_open(poolname
, &spa
, FTAG
);
3371 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3372 spa_close(spa
, FTAG
);
3373 return (SET_ERROR(EINVAL
));
3376 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3377 spa_close(spa
, FTAG
);
3378 return (SET_ERROR(ENOTSUP
));
3381 error
= spa_history_log(spa
, message
);
3382 spa_close(spa
, FTAG
);
3387 * The dp_config_rwlock must not be held when calling this, because the
3388 * unmount may need to write out data.
3390 * This function is best-effort. Callers must deal gracefully if it
3391 * remains mounted (or is remounted after this call).
3393 * Returns 0 if the argument is not a snapshot, or it is not currently a
3394 * filesystem, or we were able to unmount it. Returns error code otherwise.
3397 zfs_unmount_snap(const char *snapname
)
3401 if (strchr(snapname
, '@') == NULL
)
3404 err
= zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3405 if (err
!= 0 && err
!= ENOENT
)
3406 return (SET_ERROR(err
));
3413 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3415 return (zfs_unmount_snap(snapname
));
3419 * When a clone is destroyed, its origin may also need to be destroyed,
3420 * in which case it must be unmounted. This routine will do that unmount
3424 zfs_destroy_unmount_origin(const char *fsname
)
3430 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3433 ds
= dmu_objset_ds(os
);
3434 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3435 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3436 dsl_dataset_name(ds
->ds_prev
, originname
);
3437 dmu_objset_rele(os
, FTAG
);
3438 (void) zfs_unmount_snap(originname
);
3440 dmu_objset_rele(os
, FTAG
);
3446 * "snaps" -> { snapshot1, snapshot2 }
3447 * (optional boolean) "defer"
3450 * outnvl: snapshot -> error code (int32)
3454 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3460 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3461 return (SET_ERROR(EINVAL
));
3462 defer
= nvlist_exists(innvl
, "defer");
3464 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3465 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3466 (void) zfs_unmount_snap(nvpair_name(pair
));
3469 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3473 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3474 * All bookmarks must be in the same pool.
3477 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3480 * outnvl: bookmark -> error code (int32)
3485 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3487 nvpair_t
*pair
, *pair2
;
3489 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
3490 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3494 * Verify the snapshot argument.
3496 if (nvpair_value_string(pair
, &snap_name
) != 0)
3497 return (SET_ERROR(EINVAL
));
3500 /* Verify that the keys (bookmarks) are unique */
3501 for (pair2
= nvlist_next_nvpair(innvl
, pair
);
3502 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3503 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3504 return (SET_ERROR(EINVAL
));
3508 return (dsl_bookmark_create(innvl
, outnvl
));
3513 * property 1, property 2, ...
3517 * bookmark name 1 -> { property 1, property 2, ... },
3518 * bookmark name 2 -> { property 1, property 2, ... }
3523 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3525 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3530 * bookmark name 1, bookmark name 2
3533 * outnvl: bookmark -> error code (int32)
3537 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3543 poollen
= strlen(poolname
);
3544 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
3545 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3546 const char *name
= nvpair_name(pair
);
3547 const char *cp
= strchr(name
, '#');
3550 * The bookmark name must contain an #, and the part after it
3551 * must contain only valid characters.
3554 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3555 return (SET_ERROR(EINVAL
));
3558 * The bookmark must be in the specified pool.
3560 if (strncmp(name
, poolname
, poollen
) != 0 ||
3561 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3562 return (SET_ERROR(EXDEV
));
3565 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3571 * zc_name name of dataset to destroy
3572 * zc_objset_type type of objset
3573 * zc_defer_destroy mark for deferred destroy
3578 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3582 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3583 err
= zfs_unmount_snap(zc
->zc_name
);
3588 if (strchr(zc
->zc_name
, '@')) {
3589 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3591 err
= dsl_destroy_head(zc
->zc_name
);
3592 if (err
== EEXIST
) {
3594 * It is possible that the given DS may have
3595 * hidden child (%recv) datasets - "leftovers"
3596 * resulting from the previously interrupted
3599 * 6 extra bytes for /%recv
3601 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3603 (void) snprintf(namebuf
, sizeof (namebuf
),
3604 "%s/%s", zc
->zc_name
, recv_clone_name
);
3607 * Try to remove the hidden child (%recv) and after
3608 * that try to remove the target dataset.
3609 * If the hidden child (%recv) does not exist
3610 * the original error (EEXIST) will be returned
3612 err
= dsl_destroy_head(namebuf
);
3614 err
= dsl_destroy_head(zc
->zc_name
);
3615 else if (err
== ENOENT
)
3624 * fsname is name of dataset to rollback (to most recent snapshot)
3626 * innvl is not used.
3628 * outnvl: "target" -> name of most recent snapshot
3633 zfs_ioc_rollback(const char *fsname
, nvlist_t
*args
, nvlist_t
*outnvl
)
3638 if (get_zfs_sb(fsname
, &zsb
) == 0) {
3639 error
= zfs_suspend_fs(zsb
);
3643 error
= dsl_dataset_rollback(fsname
, zsb
, outnvl
);
3644 resume_err
= zfs_resume_fs(zsb
, fsname
);
3645 error
= error
? error
: resume_err
;
3647 deactivate_super(zsb
->z_sb
);
3649 error
= dsl_dataset_rollback(fsname
, NULL
, outnvl
);
3655 recursive_unmount(const char *fsname
, void *arg
)
3657 const char *snapname
= arg
;
3661 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3662 error
= zfs_unmount_snap(fullname
);
3670 * zc_name old name of dataset
3671 * zc_value new name of dataset
3672 * zc_cookie recursive flag (only valid for snapshots)
3677 zfs_ioc_rename(zfs_cmd_t
*zc
)
3679 boolean_t recursive
= zc
->zc_cookie
& 1;
3682 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3683 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3684 strchr(zc
->zc_value
, '%'))
3685 return (SET_ERROR(EINVAL
));
3687 at
= strchr(zc
->zc_name
, '@');
3689 /* snaps must be in same fs */
3692 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3693 return (SET_ERROR(EXDEV
));
3695 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3696 error
= dmu_objset_find(zc
->zc_name
,
3697 recursive_unmount
, at
+ 1,
3698 recursive
? DS_FIND_CHILDREN
: 0);
3704 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3705 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3710 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3715 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3717 const char *propname
= nvpair_name(pair
);
3718 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3719 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3723 if (prop
== ZPROP_INVAL
) {
3724 if (zfs_prop_user(propname
)) {
3725 if ((err
= zfs_secpolicy_write_perms(dsname
,
3726 ZFS_DELEG_PERM_USERPROP
, cr
)))
3731 if (!issnap
&& zfs_prop_userquota(propname
)) {
3732 const char *perm
= NULL
;
3733 const char *uq_prefix
=
3734 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3735 const char *gq_prefix
=
3736 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3737 const char *uiq_prefix
=
3738 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
];
3739 const char *giq_prefix
=
3740 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
];
3742 if (strncmp(propname
, uq_prefix
,
3743 strlen(uq_prefix
)) == 0) {
3744 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3745 } else if (strncmp(propname
, uiq_prefix
,
3746 strlen(uiq_prefix
)) == 0) {
3747 perm
= ZFS_DELEG_PERM_USEROBJQUOTA
;
3748 } else if (strncmp(propname
, gq_prefix
,
3749 strlen(gq_prefix
)) == 0) {
3750 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3751 } else if (strncmp(propname
, giq_prefix
,
3752 strlen(giq_prefix
)) == 0) {
3753 perm
= ZFS_DELEG_PERM_GROUPOBJQUOTA
;
3755 /* USERUSED and GROUPUSED are read-only */
3756 return (SET_ERROR(EINVAL
));
3759 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3764 return (SET_ERROR(EINVAL
));
3768 return (SET_ERROR(EINVAL
));
3770 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3772 * dsl_prop_get_all_impl() returns properties in this
3776 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3777 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3782 * Check that this value is valid for this pool version
3785 case ZFS_PROP_COMPRESSION
:
3787 * If the user specified gzip compression, make sure
3788 * the SPA supports it. We ignore any errors here since
3789 * we'll catch them later.
3791 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3792 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3793 intval
<= ZIO_COMPRESS_GZIP_9
&&
3794 zfs_earlier_version(dsname
,
3795 SPA_VERSION_GZIP_COMPRESSION
)) {
3796 return (SET_ERROR(ENOTSUP
));
3799 if (intval
== ZIO_COMPRESS_ZLE
&&
3800 zfs_earlier_version(dsname
,
3801 SPA_VERSION_ZLE_COMPRESSION
))
3802 return (SET_ERROR(ENOTSUP
));
3804 if (intval
== ZIO_COMPRESS_LZ4
) {
3807 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3810 if (!spa_feature_is_enabled(spa
,
3811 SPA_FEATURE_LZ4_COMPRESS
)) {
3812 spa_close(spa
, FTAG
);
3813 return (SET_ERROR(ENOTSUP
));
3815 spa_close(spa
, FTAG
);
3819 * If this is a bootable dataset then
3820 * verify that the compression algorithm
3821 * is supported for booting. We must return
3822 * something other than ENOTSUP since it
3823 * implies a downrev pool version.
3825 if (zfs_is_bootfs(dsname
) &&
3826 !BOOTFS_COMPRESS_VALID(intval
)) {
3827 return (SET_ERROR(ERANGE
));
3832 case ZFS_PROP_COPIES
:
3833 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3834 return (SET_ERROR(ENOTSUP
));
3837 case ZFS_PROP_VOLBLOCKSIZE
:
3838 case ZFS_PROP_RECORDSIZE
:
3839 /* Record sizes above 128k need the feature to be enabled */
3840 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3841 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3845 * If this is a bootable dataset then
3846 * we don't allow large (>128K) blocks,
3847 * because GRUB doesn't support them.
3849 if (zfs_is_bootfs(dsname
) &&
3850 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3851 return (SET_ERROR(ERANGE
));
3855 * We don't allow setting the property above 1MB,
3856 * unless the tunable has been changed.
3858 if (intval
> zfs_max_recordsize
||
3859 intval
> SPA_MAXBLOCKSIZE
)
3860 return (SET_ERROR(ERANGE
));
3862 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3865 if (!spa_feature_is_enabled(spa
,
3866 SPA_FEATURE_LARGE_BLOCKS
)) {
3867 spa_close(spa
, FTAG
);
3868 return (SET_ERROR(ENOTSUP
));
3870 spa_close(spa
, FTAG
);
3874 case ZFS_PROP_DNODESIZE
:
3875 /* Dnode sizes above 512 need the feature to be enabled */
3876 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3877 intval
!= ZFS_DNSIZE_LEGACY
) {
3881 * If this is a bootable dataset then
3882 * we don't allow large (>512B) dnodes,
3883 * because GRUB doesn't support them.
3885 if (zfs_is_bootfs(dsname
) &&
3886 intval
!= ZFS_DNSIZE_LEGACY
) {
3887 return (SET_ERROR(EDOM
));
3890 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3893 if (!spa_feature_is_enabled(spa
,
3894 SPA_FEATURE_LARGE_DNODE
)) {
3895 spa_close(spa
, FTAG
);
3896 return (SET_ERROR(ENOTSUP
));
3898 spa_close(spa
, FTAG
);
3902 case ZFS_PROP_SHARESMB
:
3903 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3904 return (SET_ERROR(ENOTSUP
));
3907 case ZFS_PROP_ACLINHERIT
:
3908 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3909 nvpair_value_uint64(pair
, &intval
) == 0) {
3910 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3911 zfs_earlier_version(dsname
,
3912 SPA_VERSION_PASSTHROUGH_X
))
3913 return (SET_ERROR(ENOTSUP
));
3916 case ZFS_PROP_CHECKSUM
:
3917 case ZFS_PROP_DEDUP
:
3919 spa_feature_t feature
;
3924 /* dedup feature version checks */
3925 if (prop
== ZFS_PROP_DEDUP
&&
3926 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3927 return (SET_ERROR(ENOTSUP
));
3929 if (nvpair_value_uint64(pair
, &intval
) != 0)
3930 return (SET_ERROR(EINVAL
));
3932 /* check prop value is enabled in features */
3933 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
3934 if (feature
== SPA_FEATURE_NONE
)
3937 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3940 * Salted checksums are not supported on root pools.
3942 if (spa_bootfs(spa
) != 0 &&
3943 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
3944 (zio_checksum_table
[intval
].ci_flags
&
3945 ZCHECKSUM_FLAG_SALTED
)) {
3946 spa_close(spa
, FTAG
);
3947 return (SET_ERROR(ERANGE
));
3949 if (!spa_feature_is_enabled(spa
, feature
)) {
3950 spa_close(spa
, FTAG
);
3951 return (SET_ERROR(ENOTSUP
));
3953 spa_close(spa
, FTAG
);
3961 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3965 * Removes properties from the given props list that fail permission checks
3966 * needed to clear them and to restore them in case of a receive error. For each
3967 * property, make sure we have both set and inherit permissions.
3969 * Returns the first error encountered if any permission checks fail. If the
3970 * caller provides a non-NULL errlist, it also gives the complete list of names
3971 * of all the properties that failed a permission check along with the
3972 * corresponding error numbers. The caller is responsible for freeing the
3975 * If every property checks out successfully, zero is returned and the list
3976 * pointed at by errlist is NULL.
3979 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3982 nvpair_t
*pair
, *next_pair
;
3989 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3991 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
3992 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
3993 pair
= nvlist_next_nvpair(props
, NULL
);
3994 while (pair
!= NULL
) {
3995 next_pair
= nvlist_next_nvpair(props
, pair
);
3997 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
3998 sizeof (zc
->zc_value
));
3999 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
4000 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
4001 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
4002 VERIFY(nvlist_add_int32(errors
,
4003 zc
->zc_value
, err
) == 0);
4007 kmem_free(zc
, sizeof (zfs_cmd_t
));
4009 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
4010 nvlist_free(errors
);
4013 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
4016 if (errlist
== NULL
)
4017 nvlist_free(errors
);
4025 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4027 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4028 /* dsl_prop_get_all_impl() format */
4030 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4031 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4035 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4037 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4038 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4042 if (nvpair_type(p1
) != nvpair_type(p2
))
4045 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4046 char *valstr1
, *valstr2
;
4048 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4049 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4050 return (strcmp(valstr1
, valstr2
) == 0);
4052 uint64_t intval1
, intval2
;
4054 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4055 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4056 return (intval1
== intval2
);
4061 * Remove properties from props if they are not going to change (as determined
4062 * by comparison with origprops). Remove them from origprops as well, since we
4063 * do not need to clear or restore properties that won't change.
4066 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4068 nvpair_t
*pair
, *next_pair
;
4070 if (origprops
== NULL
)
4071 return; /* all props need to be received */
4073 pair
= nvlist_next_nvpair(props
, NULL
);
4074 while (pair
!= NULL
) {
4075 const char *propname
= nvpair_name(pair
);
4078 next_pair
= nvlist_next_nvpair(props
, pair
);
4080 if ((nvlist_lookup_nvpair(origprops
, propname
,
4081 &match
) != 0) || !propval_equals(pair
, match
))
4082 goto next
; /* need to set received value */
4084 /* don't clear the existing received value */
4085 (void) nvlist_remove_nvpair(origprops
, match
);
4086 /* don't bother receiving the property */
4087 (void) nvlist_remove_nvpair(props
, pair
);
4094 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4095 * For example, refquota cannot be set until after the receipt of a dataset,
4096 * because in replication streams, an older/earlier snapshot may exceed the
4097 * refquota. We want to receive the older/earlier snapshot, but setting
4098 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4099 * the older/earlier snapshot from being received (with EDQUOT).
4101 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4103 * libzfs will need to be judicious handling errors encountered by props
4104 * extracted by this function.
4107 extract_delay_props(nvlist_t
*props
)
4109 nvlist_t
*delayprops
;
4110 nvpair_t
*nvp
, *tmp
;
4111 static const zfs_prop_t delayable
[] = { ZFS_PROP_REFQUOTA
, 0 };
4114 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4116 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4117 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4119 * strcmp() is safe because zfs_prop_to_name() always returns
4122 for (i
= 0; delayable
[i
] != 0; i
++) {
4123 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4124 nvpair_name(nvp
)) == 0) {
4128 if (delayable
[i
] != 0) {
4129 tmp
= nvlist_prev_nvpair(props
, nvp
);
4130 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4131 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4136 if (nvlist_empty(delayprops
)) {
4137 nvlist_free(delayprops
);
4140 return (delayprops
);
4144 static boolean_t zfs_ioc_recv_inject_err
;
4148 * nvlist 'errors' is always allocated. It will contain descriptions of
4149 * encountered errors, if any. It's the callers responsibility to free.
4152 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
,
4153 nvlist_t
*props
, boolean_t force
, boolean_t resumable
, int input_fd
,
4154 dmu_replay_record_t
*begin_record
, int cleanup_fd
, uint64_t *read_bytes
,
4155 uint64_t *errflags
, uint64_t *action_handle
, nvlist_t
**errors
)
4157 dmu_recv_cookie_t drc
;
4159 int props_error
= 0;
4161 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4162 nvlist_t
*origprops
= NULL
; /* existing properties */
4163 boolean_t first_recvd_props
= B_FALSE
;
4168 *errors
= fnvlist_alloc();
4170 input_fp
= getf(input_fd
);
4171 if (input_fp
== NULL
)
4172 return (SET_ERROR(EBADF
));
4174 error
= dmu_recv_begin(tofs
, tosnap
,
4175 begin_record
, force
, resumable
, origin
, &drc
);
4180 * Set properties before we receive the stream so that they are applied
4181 * to the new data. Note that we must call dmu_recv_stream() if
4182 * dmu_recv_begin() succeeds.
4184 if (props
!= NULL
&& !drc
.drc_newfs
) {
4185 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4186 SPA_VERSION_RECVD_PROPS
&&
4187 !dsl_prop_get_hasrecvd(tofs
))
4188 first_recvd_props
= B_TRUE
;
4191 * If new received properties are supplied, they are to
4192 * completely replace the existing received properties, so stash
4193 * away the existing ones.
4195 if (dsl_prop_get_received(tofs
, &origprops
) == 0) {
4196 nvlist_t
*errlist
= NULL
;
4198 * Don't bother writing a property if its value won't
4199 * change (and avoid the unnecessary security checks).
4201 * The first receive after SPA_VERSION_RECVD_PROPS is a
4202 * special case where we blow away all local properties
4205 if (!first_recvd_props
)
4206 props_reduce(props
, origprops
);
4207 if (zfs_check_clearable(tofs
, origprops
, &errlist
) != 0)
4208 (void) nvlist_merge(*errors
, errlist
, 0);
4209 nvlist_free(errlist
);
4211 if (clear_received_props(tofs
, origprops
,
4212 first_recvd_props
? NULL
: props
) != 0)
4213 *errflags
|= ZPROP_ERR_NOCLEAR
;
4215 *errflags
|= ZPROP_ERR_NOCLEAR
;
4219 if (props
!= NULL
) {
4220 props_error
= dsl_prop_set_hasrecvd(tofs
);
4222 if (props_error
== 0) {
4223 delayprops
= extract_delay_props(props
);
4224 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4229 off
= input_fp
->f_offset
;
4230 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4234 zfs_sb_t
*zsb
= NULL
;
4236 if (get_zfs_sb(tofs
, &zsb
) == 0) {
4240 error
= zfs_suspend_fs(zsb
);
4242 * If the suspend fails, then the recv_end will
4243 * likely also fail, and clean up after itself.
4245 end_err
= dmu_recv_end(&drc
, zsb
);
4247 error
= zfs_resume_fs(zsb
, tofs
);
4248 error
= error
? error
: end_err
;
4249 deactivate_super(zsb
->z_sb
);
4251 error
= dmu_recv_end(&drc
, NULL
);
4254 /* Set delayed properties now, after we're done receiving. */
4255 if (delayprops
!= NULL
&& error
== 0) {
4256 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4257 delayprops
, *errors
);
4261 if (delayprops
!= NULL
) {
4263 * Merge delayed props back in with initial props, in case
4264 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4265 * we have to make sure clear_received_props() includes
4266 * the delayed properties).
4268 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4269 * using ASSERT() will be just like a VERIFY.
4271 ASSERT(nvlist_merge(props
, delayprops
, 0) == 0);
4272 nvlist_free(delayprops
);
4276 *read_bytes
= off
- input_fp
->f_offset
;
4277 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4278 input_fp
->f_offset
= off
;
4281 if (zfs_ioc_recv_inject_err
) {
4282 zfs_ioc_recv_inject_err
= B_FALSE
;
4288 * On error, restore the original props.
4290 if (error
!= 0 && props
!= NULL
&& !drc
.drc_newfs
) {
4291 if (clear_received_props(tofs
, props
, NULL
) != 0) {
4293 * We failed to clear the received properties.
4294 * Since we may have left a $recvd value on the
4295 * system, we can't clear the $hasrecvd flag.
4297 *errflags
|= ZPROP_ERR_NORESTORE
;
4298 } else if (first_recvd_props
) {
4299 dsl_prop_unset_hasrecvd(tofs
);
4302 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4303 /* We failed to stash the original properties. */
4304 *errflags
|= ZPROP_ERR_NORESTORE
;
4308 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4309 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4310 * explictly if we're restoring local properties cleared in the
4311 * first new-style receive.
4313 if (origprops
!= NULL
&&
4314 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4315 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4316 origprops
, NULL
) != 0) {
4318 * We stashed the original properties but failed to
4321 *errflags
|= ZPROP_ERR_NORESTORE
;
4326 nvlist_free(origprops
);
4329 error
= props_error
;
4336 * zc_name name of containing filesystem (unused)
4337 * zc_nvlist_src{_size} nvlist of properties to apply
4338 * zc_value name of snapshot to create
4339 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4340 * zc_cookie file descriptor to recv from
4341 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4342 * zc_guid force flag
4343 * zc_cleanup_fd cleanup-on-exit file descriptor
4344 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4347 * zc_cookie number of bytes read
4348 * zc_obj zprop_errflags_t
4349 * zc_action_handle handle for this guid/ds mapping
4350 * zc_nvlist_dst{_size} error for each unapplied received property
4353 zfs_ioc_recv(zfs_cmd_t
*zc
)
4355 dmu_replay_record_t begin_record
;
4356 nvlist_t
*errors
= NULL
;
4357 nvlist_t
*props
= NULL
;
4358 char *origin
= NULL
;
4360 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4363 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4364 strchr(zc
->zc_value
, '@') == NULL
||
4365 strchr(zc
->zc_value
, '%'))
4366 return (SET_ERROR(EINVAL
));
4368 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4369 tosnap
= strchr(tofs
, '@');
4372 if (zc
->zc_nvlist_src
!= 0 &&
4373 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4374 zc
->zc_iflags
, &props
)) != 0)
4377 if (zc
->zc_string
[0])
4378 origin
= zc
->zc_string
;
4380 begin_record
.drr_type
= DRR_BEGIN
;
4381 begin_record
.drr_payloadlen
= 0;
4382 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4384 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, props
, zc
->zc_guid
,
4385 B_FALSE
, zc
->zc_cookie
, &begin_record
, zc
->zc_cleanup_fd
,
4386 &zc
->zc_cookie
, &zc
->zc_obj
, &zc
->zc_action_handle
, &errors
);
4390 * Now that all props, initial and delayed, are set, report the prop
4391 * errors to the caller.
4393 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4394 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4395 put_nvlist(zc
, errors
) != 0)) {
4397 * Caller made zc->zc_nvlist_dst less than the minimum expected
4398 * size or supplied an invalid address.
4400 error
= SET_ERROR(EINVAL
);
4403 nvlist_free(errors
);
4410 * "snapname" -> full name of the snapshot to create
4411 * (optional) "props" -> properties to set (nvlist)
4412 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
4413 * "begin_record" -> non-byteswapped dmu_replay_record_t
4414 * "input_fd" -> file descriptor to read stream from (int32)
4415 * (optional) "force" -> force flag (value ignored)
4416 * (optional) "resumable" -> resumable flag (value ignored)
4417 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
4418 * (optional) "action_handle" -> handle for this guid/ds mapping
4422 * "read_bytes" -> number of bytes read
4423 * "error_flags" -> zprop_errflags_t
4424 * "action_handle" -> handle for this guid/ds mapping
4425 * "errors" -> error for each unapplied received property (nvlist)
4429 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4431 dmu_replay_record_t
*begin_record
;
4432 uint_t begin_record_size
;
4433 nvlist_t
*errors
= NULL
;
4434 nvlist_t
*props
= NULL
;
4435 char *snapname
= NULL
;
4436 char *origin
= NULL
;
4438 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4440 boolean_t resumable
;
4441 uint64_t action_handle
= 0;
4442 uint64_t read_bytes
= 0;
4443 uint64_t errflags
= 0;
4445 int cleanup_fd
= -1;
4448 error
= nvlist_lookup_string(innvl
, "snapname", &snapname
);
4450 return (SET_ERROR(EINVAL
));
4452 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
4453 strchr(snapname
, '@') == NULL
||
4454 strchr(snapname
, '%'))
4455 return (SET_ERROR(EINVAL
));
4457 (void) strcpy(tofs
, snapname
);
4458 tosnap
= strchr(tofs
, '@');
4461 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
4462 if (error
&& error
!= ENOENT
)
4465 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
4466 (uchar_t
**)&begin_record
, &begin_record_size
);
4467 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
4468 return (SET_ERROR(EINVAL
));
4470 error
= nvlist_lookup_int32(innvl
, "input_fd", &input_fd
);
4472 return (SET_ERROR(EINVAL
));
4474 force
= nvlist_exists(innvl
, "force");
4475 resumable
= nvlist_exists(innvl
, "resumable");
4477 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
4478 if (error
&& error
!= ENOENT
)
4481 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
4482 if (error
&& error
!= ENOENT
)
4485 error
= nvlist_lookup_nvlist(innvl
, "props", &props
);
4486 if (error
&& error
!= ENOENT
)
4489 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, props
, force
,
4490 resumable
, input_fd
, begin_record
, cleanup_fd
, &read_bytes
,
4491 &errflags
, &action_handle
, &errors
);
4493 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
4494 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
4495 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
4496 fnvlist_add_nvlist(outnvl
, "errors", errors
);
4498 nvlist_free(errors
);
4506 * zc_name name of snapshot to send
4507 * zc_cookie file descriptor to send stream to
4508 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4509 * zc_sendobj objsetid of snapshot to send
4510 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4511 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4512 * output size in zc_objset_type.
4513 * zc_flags lzc_send_flags
4516 * zc_objset_type estimated size, if zc_guid is set
4519 zfs_ioc_send(zfs_cmd_t
*zc
)
4523 boolean_t estimate
= (zc
->zc_guid
!= 0);
4524 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4525 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4526 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4528 if (zc
->zc_obj
!= 0) {
4530 dsl_dataset_t
*tosnap
;
4532 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4536 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4538 dsl_pool_rele(dp
, FTAG
);
4542 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4544 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4545 dsl_dataset_rele(tosnap
, FTAG
);
4546 dsl_pool_rele(dp
, FTAG
);
4551 dsl_dataset_t
*tosnap
;
4552 dsl_dataset_t
*fromsnap
= NULL
;
4554 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4558 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4560 dsl_pool_rele(dp
, FTAG
);
4564 if (zc
->zc_fromobj
!= 0) {
4565 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4568 dsl_dataset_rele(tosnap
, FTAG
);
4569 dsl_pool_rele(dp
, FTAG
);
4574 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
4575 &zc
->zc_objset_type
);
4577 if (fromsnap
!= NULL
)
4578 dsl_dataset_rele(fromsnap
, FTAG
);
4579 dsl_dataset_rele(tosnap
, FTAG
);
4580 dsl_pool_rele(dp
, FTAG
);
4582 file_t
*fp
= getf(zc
->zc_cookie
);
4584 return (SET_ERROR(EBADF
));
4587 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4588 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
,
4589 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4591 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4593 releasef(zc
->zc_cookie
);
4600 * zc_name name of snapshot on which to report progress
4601 * zc_cookie file descriptor of send stream
4604 * zc_cookie number of bytes written in send stream thus far
4607 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4611 dmu_sendarg_t
*dsp
= NULL
;
4614 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4618 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4620 dsl_pool_rele(dp
, FTAG
);
4624 mutex_enter(&ds
->ds_sendstream_lock
);
4627 * Iterate over all the send streams currently active on this dataset.
4628 * If there's one which matches the specified file descriptor _and_ the
4629 * stream was started by the current process, return the progress of
4633 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4634 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4635 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4636 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4641 zc
->zc_cookie
= *(dsp
->dsa_off
);
4643 error
= SET_ERROR(ENOENT
);
4645 mutex_exit(&ds
->ds_sendstream_lock
);
4646 dsl_dataset_rele(ds
, FTAG
);
4647 dsl_pool_rele(dp
, FTAG
);
4652 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4656 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4657 &zc
->zc_inject_record
);
4660 zc
->zc_guid
= (uint64_t)id
;
4666 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4668 return (zio_clear_fault((int)zc
->zc_guid
));
4672 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4674 int id
= (int)zc
->zc_guid
;
4677 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4678 &zc
->zc_inject_record
);
4686 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4690 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4692 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4695 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4698 zc
->zc_nvlist_dst_size
= count
;
4700 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4702 spa_close(spa
, FTAG
);
4708 zfs_ioc_clear(zfs_cmd_t
*zc
)
4715 * On zpool clear we also fix up missing slogs
4717 mutex_enter(&spa_namespace_lock
);
4718 spa
= spa_lookup(zc
->zc_name
);
4720 mutex_exit(&spa_namespace_lock
);
4721 return (SET_ERROR(EIO
));
4723 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4724 /* we need to let spa_open/spa_load clear the chains */
4725 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4727 spa
->spa_last_open_failed
= 0;
4728 mutex_exit(&spa_namespace_lock
);
4730 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4731 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4734 nvlist_t
*config
= NULL
;
4736 if (zc
->zc_nvlist_src
== 0)
4737 return (SET_ERROR(EINVAL
));
4739 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4740 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4741 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4743 if (config
!= NULL
) {
4746 if ((err
= put_nvlist(zc
, config
)) != 0)
4748 nvlist_free(config
);
4750 nvlist_free(policy
);
4757 spa_vdev_state_enter(spa
, SCL_NONE
);
4759 if (zc
->zc_guid
== 0) {
4762 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4764 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4765 spa_close(spa
, FTAG
);
4766 return (SET_ERROR(ENODEV
));
4770 vdev_clear(spa
, vd
);
4772 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4775 * Resume any suspended I/Os.
4777 if (zio_resume(spa
) != 0)
4778 error
= SET_ERROR(EIO
);
4780 spa_close(spa
, FTAG
);
4786 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4791 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4795 spa_vdev_state_enter(spa
, SCL_NONE
);
4798 * If a resilver is already in progress then set the
4799 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4800 * the scan as a side effect of the reopen. Otherwise, let
4801 * vdev_open() decided if a resilver is required.
4803 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4804 vdev_reopen(spa
->spa_root_vdev
);
4805 spa
->spa_scrub_reopen
= B_FALSE
;
4807 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4808 spa_close(spa
, FTAG
);
4813 * zc_name name of filesystem
4814 * zc_value name of origin snapshot
4817 * zc_string name of conflicting snapshot, if there is one
4820 zfs_ioc_promote(zfs_cmd_t
*zc
)
4825 * We don't need to unmount *all* the origin fs's snapshots, but
4828 cp
= strchr(zc
->zc_value
, '@');
4831 (void) dmu_objset_find(zc
->zc_value
,
4832 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
4833 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4837 * Retrieve a single {user|group}{used|quota}@... property.
4840 * zc_name name of filesystem
4841 * zc_objset_type zfs_userquota_prop_t
4842 * zc_value domain name (eg. "S-1-234-567-89")
4843 * zc_guid RID/UID/GID
4846 * zc_cookie property value
4849 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4854 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4855 return (SET_ERROR(EINVAL
));
4857 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4861 error
= zfs_userspace_one(zsb
,
4862 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4863 zfs_sb_rele(zsb
, FTAG
);
4870 * zc_name name of filesystem
4871 * zc_cookie zap cursor
4872 * zc_objset_type zfs_userquota_prop_t
4873 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4876 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4877 * zc_cookie zap cursor
4880 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4883 int bufsize
= zc
->zc_nvlist_dst_size
;
4888 return (SET_ERROR(ENOMEM
));
4890 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4894 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
4896 error
= zfs_userspace_many(zsb
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4897 buf
, &zc
->zc_nvlist_dst_size
);
4900 error
= xcopyout(buf
,
4901 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4902 zc
->zc_nvlist_dst_size
);
4904 vmem_free(buf
, bufsize
);
4905 zfs_sb_rele(zsb
, FTAG
);
4912 * zc_name name of filesystem
4918 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4924 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
4925 if (!dmu_objset_userused_enabled(zsb
->z_os
)) {
4927 * If userused is not enabled, it may be because the
4928 * objset needs to be closed & reopened (to grow the
4929 * objset_phys_t). Suspend/resume the fs will do that.
4931 error
= zfs_suspend_fs(zsb
);
4933 dmu_objset_refresh_ownership(zsb
->z_os
,
4935 error
= zfs_resume_fs(zsb
, zc
->zc_name
);
4939 error
= dmu_objset_userspace_upgrade(zsb
->z_os
);
4940 deactivate_super(zsb
->z_sb
);
4942 /* XXX kind of reading contents without owning */
4943 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4947 error
= dmu_objset_userspace_upgrade(os
);
4948 dmu_objset_rele(os
, FTAG
);
4956 * zc_name name of filesystem
4962 zfs_ioc_userobjspace_upgrade(zfs_cmd_t
*zc
)
4967 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4971 dsl_dataset_long_hold(dmu_objset_ds(os
), FTAG
);
4972 dsl_pool_rele(dmu_objset_pool(os
), FTAG
);
4974 if (dmu_objset_userobjspace_upgradable(os
)) {
4975 mutex_enter(&os
->os_upgrade_lock
);
4976 if (os
->os_upgrade_id
== 0) {
4977 /* clear potential error code and retry */
4978 os
->os_upgrade_status
= 0;
4979 mutex_exit(&os
->os_upgrade_lock
);
4981 dmu_objset_userobjspace_upgrade(os
);
4983 mutex_exit(&os
->os_upgrade_lock
);
4986 taskq_wait_id(os
->os_spa
->spa_upgrade_taskq
, os
->os_upgrade_id
);
4987 error
= os
->os_upgrade_status
;
4990 dsl_dataset_long_rele(dmu_objset_ds(os
), FTAG
);
4991 dsl_dataset_rele(dmu_objset_ds(os
), FTAG
);
4997 zfs_ioc_share(zfs_cmd_t
*zc
)
4999 return (SET_ERROR(ENOSYS
));
5002 ace_t full_access
[] = {
5003 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
5008 * zc_name name of containing filesystem
5009 * zc_obj object # beyond which we want next in-use object #
5012 * zc_obj next in-use object #
5015 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
5017 objset_t
*os
= NULL
;
5020 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
5024 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
5026 dmu_objset_rele(os
, FTAG
);
5032 * zc_name name of filesystem
5033 * zc_value prefix name for snapshot
5034 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5037 * zc_value short name of new snapshot
5040 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5047 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5051 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5052 (u_longlong_t
)ddi_get_lbolt64());
5053 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5055 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5058 (void) strlcpy(zc
->zc_value
, snap_name
,
5059 sizeof (zc
->zc_value
));
5062 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5068 * zc_name name of "to" snapshot
5069 * zc_value name of "from" snapshot
5070 * zc_cookie file descriptor to write diff data on
5073 * dmu_diff_record_t's to the file descriptor
5076 zfs_ioc_diff(zfs_cmd_t
*zc
)
5082 fp
= getf(zc
->zc_cookie
);
5084 return (SET_ERROR(EBADF
));
5088 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5090 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5092 releasef(zc
->zc_cookie
);
5098 * Remove all ACL files in shares dir
5100 #ifdef HAVE_SMB_SHARE
5102 zfs_smb_acl_purge(znode_t
*dzp
)
5105 zap_attribute_t zap
;
5106 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
5109 for (zap_cursor_init(&zc
, zsb
->z_os
, dzp
->z_id
);
5110 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5111 zap_cursor_advance(&zc
)) {
5112 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
5116 zap_cursor_fini(&zc
);
5119 #endif /* HAVE_SMB_SHARE */
5122 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5124 #ifdef HAVE_SMB_SHARE
5127 vnode_t
*resourcevp
= NULL
;
5136 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5137 NO_FOLLOW
, NULL
, &vp
)) != 0)
5140 /* Now make sure mntpnt and dataset are ZFS */
5142 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5143 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5144 zc
->zc_name
) != 0)) {
5146 return (SET_ERROR(EINVAL
));
5154 * Create share dir if its missing.
5156 mutex_enter(&zsb
->z_lock
);
5157 if (zsb
->z_shares_dir
== 0) {
5160 tx
= dmu_tx_create(zsb
->z_os
);
5161 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5163 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5164 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5168 error
= zfs_create_share_dir(zsb
, tx
);
5172 mutex_exit(&zsb
->z_lock
);
5178 mutex_exit(&zsb
->z_lock
);
5180 ASSERT(zsb
->z_shares_dir
);
5181 if ((error
= zfs_zget(zsb
, zsb
->z_shares_dir
, &sharedir
)) != 0) {
5187 switch (zc
->zc_cookie
) {
5188 case ZFS_SMB_ACL_ADD
:
5189 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5190 vattr
.va_mode
= S_IFREG
|0777;
5194 vsec
.vsa_mask
= VSA_ACE
;
5195 vsec
.vsa_aclentp
= &full_access
;
5196 vsec
.vsa_aclentsz
= sizeof (full_access
);
5197 vsec
.vsa_aclcnt
= 1;
5199 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
5200 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5202 VN_RELE(resourcevp
);
5205 case ZFS_SMB_ACL_REMOVE
:
5206 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5210 case ZFS_SMB_ACL_RENAME
:
5211 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5212 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5214 VN_RELE(ZTOV(sharedir
));
5218 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5219 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5222 VN_RELE(ZTOV(sharedir
));
5224 nvlist_free(nvlist
);
5227 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5229 nvlist_free(nvlist
);
5232 case ZFS_SMB_ACL_PURGE
:
5233 error
= zfs_smb_acl_purge(sharedir
);
5237 error
= SET_ERROR(EINVAL
);
5242 VN_RELE(ZTOV(sharedir
));
5248 return (SET_ERROR(ENOTSUP
));
5249 #endif /* HAVE_SMB_SHARE */
5254 * "holds" -> { snapname -> holdname (string), ... }
5255 * (optional) "cleanup_fd" -> fd (int32)
5259 * snapname -> error value (int32)
5265 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5269 int cleanup_fd
= -1;
5273 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5275 return (SET_ERROR(EINVAL
));
5277 /* make sure the user didn't pass us any invalid (empty) tags */
5278 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5279 pair
= nvlist_next_nvpair(holds
, pair
)) {
5282 error
= nvpair_value_string(pair
, &htag
);
5284 return (SET_ERROR(error
));
5286 if (strlen(htag
) == 0)
5287 return (SET_ERROR(EINVAL
));
5290 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5291 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5296 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5298 zfs_onexit_fd_rele(cleanup_fd
);
5303 * innvl is not used.
5306 * holdname -> time added (uint64 seconds since epoch)
5312 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5314 return (dsl_dataset_get_holds(snapname
, outnvl
));
5319 * snapname -> { holdname, ... }
5324 * snapname -> error value (int32)
5330 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5332 return (dsl_dataset_user_release(holds
, errlist
));
5337 * zc_guid flags (ZEVENT_NONBLOCK)
5338 * zc_cleanup_fd zevent file descriptor
5341 * zc_nvlist_dst next nvlist event
5342 * zc_cookie dropped events since last get
5345 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5348 nvlist_t
*event
= NULL
;
5350 uint64_t dropped
= 0;
5353 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5358 error
= zfs_zevent_next(ze
, &event
,
5359 &zc
->zc_nvlist_dst_size
, &dropped
);
5360 if (event
!= NULL
) {
5361 zc
->zc_cookie
= dropped
;
5362 error
= put_nvlist(zc
, event
);
5366 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5369 if ((error
== 0) || (error
!= ENOENT
))
5372 error
= zfs_zevent_wait(ze
);
5377 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5384 * zc_cookie cleared events count
5387 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5391 zfs_zevent_drain_all(&count
);
5392 zc
->zc_cookie
= count
;
5399 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5400 * zc_cleanup zevent file descriptor
5403 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5409 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5413 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5414 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5421 * zc_name name of new filesystem or snapshot
5422 * zc_value full name of old snapshot
5425 * zc_cookie space in bytes
5426 * zc_objset_type compressed space in bytes
5427 * zc_perm_action uncompressed space in bytes
5430 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5434 dsl_dataset_t
*new, *old
;
5436 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5439 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5441 dsl_pool_rele(dp
, FTAG
);
5444 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5446 dsl_dataset_rele(new, FTAG
);
5447 dsl_pool_rele(dp
, FTAG
);
5451 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5452 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5453 dsl_dataset_rele(old
, FTAG
);
5454 dsl_dataset_rele(new, FTAG
);
5455 dsl_pool_rele(dp
, FTAG
);
5461 * "firstsnap" -> snapshot name
5465 * "used" -> space in bytes
5466 * "compressed" -> compressed space in bytes
5467 * "uncompressed" -> uncompressed space in bytes
5471 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5475 dsl_dataset_t
*new, *old
;
5477 uint64_t used
, comp
, uncomp
;
5479 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5480 return (SET_ERROR(EINVAL
));
5482 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5486 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5487 if (error
== 0 && !new->ds_is_snapshot
) {
5488 dsl_dataset_rele(new, FTAG
);
5489 error
= SET_ERROR(EINVAL
);
5492 dsl_pool_rele(dp
, FTAG
);
5495 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5496 if (error
== 0 && !old
->ds_is_snapshot
) {
5497 dsl_dataset_rele(old
, FTAG
);
5498 error
= SET_ERROR(EINVAL
);
5501 dsl_dataset_rele(new, FTAG
);
5502 dsl_pool_rele(dp
, FTAG
);
5506 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5507 dsl_dataset_rele(old
, FTAG
);
5508 dsl_dataset_rele(new, FTAG
);
5509 dsl_pool_rele(dp
, FTAG
);
5510 fnvlist_add_uint64(outnvl
, "used", used
);
5511 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5512 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5518 * "fd" -> file descriptor to write stream to (int32)
5519 * (optional) "fromsnap" -> full snap name to send an incremental from
5520 * (optional) "largeblockok" -> (value ignored)
5521 * indicates that blocks > 128KB are permitted
5522 * (optional) "embedok" -> (value ignored)
5523 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5524 * (optional) "compressok" -> (value ignored)
5525 * presence indicates compressed DRR_WRITE records are permitted
5526 * (optional) "resume_object" and "resume_offset" -> (uint64)
5527 * if present, resume send stream from specified object and offset.
5534 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5538 char *fromname
= NULL
;
5541 boolean_t largeblockok
;
5543 boolean_t compressok
;
5544 uint64_t resumeobj
= 0;
5545 uint64_t resumeoff
= 0;
5547 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5549 return (SET_ERROR(EINVAL
));
5551 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5553 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5554 embedok
= nvlist_exists(innvl
, "embedok");
5555 compressok
= nvlist_exists(innvl
, "compressok");
5557 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5558 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5560 if ((fp
= getf(fd
)) == NULL
)
5561 return (SET_ERROR(EBADF
));
5564 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5565 fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5567 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5575 * Determine approximately how large a zfs send stream will be -- the number
5576 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5579 * (optional) "from" -> full snap or bookmark name to send an incremental
5581 * (optional) "largeblockok" -> (value ignored)
5582 * indicates that blocks > 128KB are permitted
5583 * (optional) "embedok" -> (value ignored)
5584 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5585 * (optional) "compressok" -> (value ignored)
5586 * presence indicates compressed DRR_WRITE records are permitted
5590 * "space" -> bytes of space (uint64)
5594 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5597 dsl_dataset_t
*tosnap
;
5600 /* LINTED E_FUNC_SET_NOT_USED */
5601 boolean_t largeblockok
;
5602 /* LINTED E_FUNC_SET_NOT_USED */
5604 boolean_t compressok
;
5607 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5611 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5613 dsl_pool_rele(dp
, FTAG
);
5617 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5618 embedok
= nvlist_exists(innvl
, "embedok");
5619 compressok
= nvlist_exists(innvl
, "compressok");
5621 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5623 if (strchr(fromname
, '@') != NULL
) {
5625 * If from is a snapshot, hold it and use the more
5626 * efficient dmu_send_estimate to estimate send space
5627 * size using deadlists.
5629 dsl_dataset_t
*fromsnap
;
5630 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5633 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
5635 dsl_dataset_rele(fromsnap
, FTAG
);
5636 } else if (strchr(fromname
, '#') != NULL
) {
5638 * If from is a bookmark, fetch the creation TXG of the
5639 * snapshot it was created from and use that to find
5640 * blocks that were born after it.
5642 zfs_bookmark_phys_t frombm
;
5644 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
5648 error
= dmu_send_estimate_from_txg(tosnap
,
5649 frombm
.zbm_creation_txg
, compressok
, &space
);
5652 * from is not properly formatted as a snapshot or
5655 error
= SET_ERROR(EINVAL
);
5659 // If estimating the size of a full send, use dmu_send_estimate
5660 error
= dmu_send_estimate(tosnap
, NULL
, compressok
, &space
);
5663 fnvlist_add_uint64(outnvl
, "space", space
);
5666 dsl_dataset_rele(tosnap
, FTAG
);
5667 dsl_pool_rele(dp
, FTAG
);
5671 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5674 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5675 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5676 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5678 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5680 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5681 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5682 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5683 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5685 vec
->zvec_legacy_func
= func
;
5686 vec
->zvec_secpolicy
= secpolicy
;
5687 vec
->zvec_namecheck
= namecheck
;
5688 vec
->zvec_allow_log
= log_history
;
5689 vec
->zvec_pool_check
= pool_check
;
5693 * See the block comment at the beginning of this file for details on
5694 * each argument to this function.
5697 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5698 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5699 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5700 boolean_t allow_log
)
5702 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5704 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5705 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5706 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5707 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5709 /* if we are logging, the name must be valid */
5710 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5712 vec
->zvec_name
= name
;
5713 vec
->zvec_func
= func
;
5714 vec
->zvec_secpolicy
= secpolicy
;
5715 vec
->zvec_namecheck
= namecheck
;
5716 vec
->zvec_pool_check
= pool_check
;
5717 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5718 vec
->zvec_allow_log
= allow_log
;
5722 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5723 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5724 zfs_ioc_poolcheck_t pool_check
)
5726 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5727 POOL_NAME
, log_history
, pool_check
);
5731 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5732 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5734 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5735 DATASET_NAME
, B_FALSE
, pool_check
);
5739 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5741 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5742 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5746 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5747 zfs_secpolicy_func_t
*secpolicy
)
5749 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5750 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5754 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5755 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5757 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5758 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5762 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5764 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5765 zfs_secpolicy_read
);
5769 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5770 zfs_secpolicy_func_t
*secpolicy
)
5772 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5773 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5777 zfs_ioctl_init(void)
5779 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5780 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5781 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5783 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5784 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5785 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5787 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5788 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5789 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5791 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5792 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5793 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5795 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5796 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5797 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5799 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5800 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5801 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5803 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5804 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5805 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5807 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5808 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5809 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5811 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
5812 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
5813 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5814 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
5815 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
5816 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5818 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
5819 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
5820 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5822 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
5823 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
5824 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
5826 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
5827 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
5828 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5830 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
5831 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
5832 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5834 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
5835 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
5837 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5839 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
5840 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
5841 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5843 /* IOCTLS that use the legacy function signature */
5845 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5846 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5848 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5849 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5850 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5852 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5853 zfs_ioc_pool_upgrade
);
5854 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5856 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5857 zfs_ioc_vdev_remove
);
5858 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5859 zfs_ioc_vdev_set_state
);
5860 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5861 zfs_ioc_vdev_attach
);
5862 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5863 zfs_ioc_vdev_detach
);
5864 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5865 zfs_ioc_vdev_setpath
);
5866 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5867 zfs_ioc_vdev_setfru
);
5868 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5869 zfs_ioc_pool_set_props
);
5870 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5871 zfs_ioc_vdev_split
);
5872 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5873 zfs_ioc_pool_reguid
);
5875 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5876 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5877 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5878 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5879 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5880 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5881 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5882 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5883 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5884 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5887 * pool destroy, and export don't log the history as part of
5888 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5889 * does the logging of those commands.
5891 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5892 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5893 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5894 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5896 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5897 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5898 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5899 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5901 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5902 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5903 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5904 zfs_ioc_dsobj_to_dsname
,
5905 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5906 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5907 zfs_ioc_pool_get_history
,
5908 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5910 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5911 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5913 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5914 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5915 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5916 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5918 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5919 zfs_ioc_space_written
);
5920 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5921 zfs_ioc_objset_recvd_props
);
5922 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5924 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5926 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5927 zfs_ioc_objset_stats
);
5928 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5929 zfs_ioc_objset_zplprops
);
5930 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5931 zfs_ioc_dataset_list_next
);
5932 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5933 zfs_ioc_snapshot_list_next
);
5934 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5935 zfs_ioc_send_progress
);
5937 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5938 zfs_ioc_diff
, zfs_secpolicy_diff
);
5939 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5940 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5941 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5942 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5943 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5944 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5945 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5946 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5947 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5948 zfs_ioc_send
, zfs_secpolicy_send
);
5950 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5951 zfs_secpolicy_none
);
5952 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5953 zfs_secpolicy_destroy
);
5954 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5955 zfs_secpolicy_rename
);
5956 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5957 zfs_secpolicy_recv
);
5958 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5959 zfs_secpolicy_promote
);
5960 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5961 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5962 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5963 zfs_secpolicy_set_fsacl
);
5965 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5966 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5967 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5968 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5969 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5970 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5971 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5972 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5973 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5974 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5979 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
5980 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5981 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
5982 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5983 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
5984 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5988 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5989 zfs_ioc_poolcheck_t check
)
5994 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5996 if (check
& POOL_CHECK_NONE
)
5999 error
= spa_open(name
, &spa
, FTAG
);
6001 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
6002 error
= SET_ERROR(EAGAIN
);
6003 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
6004 error
= SET_ERROR(EROFS
);
6005 spa_close(spa
, FTAG
);
6011 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
6015 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6016 if (zs
->zs_minor
== minor
) {
6020 return (zs
->zs_onexit
);
6022 return (zs
->zs_zevent
);
6033 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
6037 ptr
= zfsdev_get_state_impl(minor
, which
);
6043 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
6045 zfsdev_state_t
*zs
, *fpd
;
6047 ASSERT(filp
!= NULL
);
6048 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
6050 fpd
= filp
->private_data
;
6054 mutex_enter(&zfsdev_state_lock
);
6056 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6058 if (zs
->zs_minor
== -1)
6062 *minorp
= fpd
->zs_minor
;
6063 mutex_exit(&zfsdev_state_lock
);
6068 mutex_exit(&zfsdev_state_lock
);
6074 * Find a free minor number. The zfsdev_state_list is expected to
6075 * be short since it is only a list of currently open file handles.
6078 zfsdev_minor_alloc(void)
6080 static minor_t last_minor
= 0;
6083 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6085 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6086 if (m
> ZFSDEV_MAX_MINOR
)
6088 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
6098 zfsdev_state_init(struct file
*filp
)
6100 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6102 boolean_t newzs
= B_FALSE
;
6104 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6106 minor
= zfsdev_minor_alloc();
6108 return (SET_ERROR(ENXIO
));
6110 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6111 if (zs
->zs_minor
== -1)
6117 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6122 filp
->private_data
= zs
;
6124 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
6125 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
6129 * In order to provide for lock-free concurrent read access
6130 * to the minor list in zfsdev_get_state_impl(), new entries
6131 * must be completely written before linking them into the
6132 * list whereas existing entries are already linked; the last
6133 * operation must be updating zs_minor (from -1 to the new
6137 zs
->zs_minor
= minor
;
6139 zsprev
->zs_next
= zs
;
6142 zs
->zs_minor
= minor
;
6149 zfsdev_state_destroy(struct file
*filp
)
6153 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6154 ASSERT(filp
->private_data
!= NULL
);
6156 zs
= filp
->private_data
;
6158 zfs_onexit_destroy(zs
->zs_onexit
);
6159 zfs_zevent_destroy(zs
->zs_zevent
);
6165 zfsdev_open(struct inode
*ino
, struct file
*filp
)
6169 mutex_enter(&zfsdev_state_lock
);
6170 error
= zfsdev_state_init(filp
);
6171 mutex_exit(&zfsdev_state_lock
);
6177 zfsdev_release(struct inode
*ino
, struct file
*filp
)
6181 mutex_enter(&zfsdev_state_lock
);
6182 error
= zfsdev_state_destroy(filp
);
6183 mutex_exit(&zfsdev_state_lock
);
6189 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6193 int error
, rc
, flag
= 0;
6194 const zfs_ioc_vec_t
*vec
;
6195 char *saved_poolname
= NULL
;
6196 nvlist_t
*innvl
= NULL
;
6197 fstrans_cookie_t cookie
;
6199 vecnum
= cmd
- ZFS_IOC_FIRST
;
6200 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6201 return (-SET_ERROR(EINVAL
));
6202 vec
= &zfs_ioc_vec
[vecnum
];
6205 * The registered ioctl list may be sparse, verify that either
6206 * a normal or legacy handler are registered.
6208 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
6209 return (-SET_ERROR(EINVAL
));
6211 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6213 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6215 error
= SET_ERROR(EFAULT
);
6219 zc
->zc_iflags
= flag
& FKIOCTL
;
6220 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
6222 * Make sure the user doesn't pass in an insane value for
6223 * zc_nvlist_src_size. We have to check, since we will end
6224 * up allocating that much memory inside of get_nvlist(). This
6225 * prevents a nefarious user from allocating tons of kernel
6228 * Also, we return EINVAL instead of ENOMEM here. The reason
6229 * being that returning ENOMEM from an ioctl() has a special
6230 * connotation; that the user's size value is too small and
6231 * needs to be expanded to hold the nvlist. See
6232 * zcmd_expand_dst_nvlist() for details.
6234 error
= SET_ERROR(EINVAL
); /* User's size too big */
6236 } else if (zc
->zc_nvlist_src_size
!= 0) {
6237 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6238 zc
->zc_iflags
, &innvl
);
6244 * Ensure that all pool/dataset names are valid before we pass down to
6247 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6248 switch (vec
->zvec_namecheck
) {
6250 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6251 error
= SET_ERROR(EINVAL
);
6253 error
= pool_status_check(zc
->zc_name
,
6254 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6258 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6259 error
= SET_ERROR(EINVAL
);
6261 error
= pool_status_check(zc
->zc_name
,
6262 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6270 if (error
== 0 && !(flag
& FKIOCTL
)) {
6271 cookie
= spl_fstrans_mark();
6272 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
6273 spl_fstrans_unmark(cookie
);
6279 /* legacy ioctls can modify zc_name */
6280 saved_poolname
= strdup(zc
->zc_name
);
6281 if (saved_poolname
== NULL
) {
6282 error
= SET_ERROR(ENOMEM
);
6285 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
6288 if (vec
->zvec_func
!= NULL
) {
6292 nvlist_t
*lognv
= NULL
;
6294 ASSERT(vec
->zvec_legacy_func
== NULL
);
6297 * Add the innvl to the lognv before calling the func,
6298 * in case the func changes the innvl.
6300 if (vec
->zvec_allow_log
) {
6301 lognv
= fnvlist_alloc();
6302 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6304 if (!nvlist_empty(innvl
)) {
6305 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6310 outnvl
= fnvlist_alloc();
6311 cookie
= spl_fstrans_mark();
6312 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6313 spl_fstrans_unmark(cookie
);
6315 if (error
== 0 && vec
->zvec_allow_log
&&
6316 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6317 if (!nvlist_empty(outnvl
)) {
6318 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6321 (void) spa_history_log_nvl(spa
, lognv
);
6322 spa_close(spa
, FTAG
);
6324 fnvlist_free(lognv
);
6326 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6328 if (vec
->zvec_smush_outnvlist
) {
6329 smusherror
= nvlist_smush(outnvl
,
6330 zc
->zc_nvlist_dst_size
);
6332 if (smusherror
== 0)
6333 puterror
= put_nvlist(zc
, outnvl
);
6339 nvlist_free(outnvl
);
6341 cookie
= spl_fstrans_mark();
6342 error
= vec
->zvec_legacy_func(zc
);
6343 spl_fstrans_unmark(cookie
);
6348 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6349 if (error
== 0 && rc
!= 0)
6350 error
= SET_ERROR(EFAULT
);
6351 if (error
== 0 && vec
->zvec_allow_log
) {
6352 char *s
= tsd_get(zfs_allow_log_key
);
6355 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6357 if (saved_poolname
!= NULL
)
6358 strfree(saved_poolname
);
6361 kmem_free(zc
, sizeof (zfs_cmd_t
));
6365 #ifdef CONFIG_COMPAT
6367 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6369 return (zfsdev_ioctl(filp
, cmd
, arg
));
6372 #define zfsdev_compat_ioctl NULL
6375 static const struct file_operations zfsdev_fops
= {
6376 .open
= zfsdev_open
,
6377 .release
= zfsdev_release
,
6378 .unlocked_ioctl
= zfsdev_ioctl
,
6379 .compat_ioctl
= zfsdev_compat_ioctl
,
6380 .owner
= THIS_MODULE
,
6383 static struct miscdevice zfs_misc
= {
6384 .minor
= MISC_DYNAMIC_MINOR
,
6386 .fops
= &zfsdev_fops
,
6394 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6395 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6396 zfsdev_state_list
->zs_minor
= -1;
6398 error
= misc_register(&zfs_misc
);
6400 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
6410 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6412 misc_deregister(&zfs_misc
);
6413 mutex_destroy(&zfsdev_state_lock
);
6415 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6417 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
6421 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
6425 zfs_allow_log_destroy(void *arg
)
6427 char *poolname
= arg
;
6429 if (poolname
!= NULL
)
6434 #define ZFS_DEBUG_STR " (DEBUG mode)"
6436 #define ZFS_DEBUG_STR ""
6444 error
= -vn_set_pwd("/");
6447 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
6451 if ((error
= -zvol_init()) != 0)
6454 spa_init(FREAD
| FWRITE
);
6459 if ((error
= zfs_attach()) != 0)
6462 tsd_create(&zfs_fsyncer_key
, NULL
);
6463 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
6464 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
6466 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
6467 "ZFS pool version %s, ZFS filesystem version %s\n",
6468 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
6469 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
6470 #ifndef CONFIG_FS_POSIX_ACL
6471 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
6472 #endif /* CONFIG_FS_POSIX_ACL */
6480 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
6481 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
6482 ZFS_DEBUG_STR
, error
);
6495 tsd_destroy(&zfs_fsyncer_key
);
6496 tsd_destroy(&rrw_tsd_key
);
6497 tsd_destroy(&zfs_allow_log_key
);
6499 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
6500 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
6507 MODULE_DESCRIPTION("ZFS");
6508 MODULE_AUTHOR(ZFS_META_AUTHOR
);
6509 MODULE_LICENSE(ZFS_META_LICENSE
);
6510 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);
6511 #endif /* HAVE_SPL */