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
,
249 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
250 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
252 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
254 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
256 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
257 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
260 history_str_free(char *buf
)
262 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
266 history_str_get(zfs_cmd_t
*zc
)
270 if (zc
->zc_history
== 0)
273 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
274 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
275 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
276 history_str_free(buf
);
280 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
286 * Check to see if the named dataset is currently defined as bootable
289 zfs_is_bootfs(const char *name
)
293 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
295 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
296 dmu_objset_rele(os
, FTAG
);
303 * Return non-zero if the spa version is less than requested version.
306 zfs_earlier_version(const char *name
, int version
)
310 if (spa_open(name
, &spa
, FTAG
) == 0) {
311 if (spa_version(spa
) < version
) {
312 spa_close(spa
, FTAG
);
315 spa_close(spa
, FTAG
);
321 * Return TRUE if the ZPL version is less than requested version.
324 zpl_earlier_version(const char *name
, int version
)
327 boolean_t rc
= B_TRUE
;
329 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
332 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
333 dmu_objset_rele(os
, FTAG
);
336 /* XXX reading from non-owned objset */
337 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
338 rc
= zplversion
< version
;
339 dmu_objset_rele(os
, FTAG
);
345 zfs_log_history(zfs_cmd_t
*zc
)
350 if ((buf
= history_str_get(zc
)) == NULL
)
353 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
354 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
355 (void) spa_history_log(spa
, buf
);
356 spa_close(spa
, FTAG
);
358 history_str_free(buf
);
362 * Policy for top-level read operations (list pools). Requires no privileges,
363 * and can be used in the local zone, as there is no associated dataset.
367 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
373 * Policy for dataset read operations (list children, get statistics). Requires
374 * no privileges, but must be visible in the local zone.
378 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
380 if (INGLOBALZONE(curproc
) ||
381 zone_dataset_visible(zc
->zc_name
, NULL
))
384 return (SET_ERROR(ENOENT
));
388 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
393 * The dataset must be visible by this zone -- check this first
394 * so they don't see EPERM on something they shouldn't know about.
396 if (!INGLOBALZONE(curproc
) &&
397 !zone_dataset_visible(dataset
, &writable
))
398 return (SET_ERROR(ENOENT
));
400 if (INGLOBALZONE(curproc
)) {
402 * If the fs is zoned, only root can access it from the
405 if (secpolicy_zfs(cr
) && zoned
)
406 return (SET_ERROR(EPERM
));
409 * If we are in a local zone, the 'zoned' property must be set.
412 return (SET_ERROR(EPERM
));
414 /* must be writable by this zone */
416 return (SET_ERROR(EPERM
));
422 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
426 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
427 return (SET_ERROR(ENOENT
));
429 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
433 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
437 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
438 return (SET_ERROR(ENOENT
));
440 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
444 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
445 const char *perm
, cred_t
*cr
)
449 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
451 error
= secpolicy_zfs(cr
);
453 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
459 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
465 error
= dsl_pool_hold(name
, FTAG
, &dp
);
469 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
471 dsl_pool_rele(dp
, FTAG
);
475 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
477 dsl_dataset_rele(ds
, FTAG
);
478 dsl_pool_rele(dp
, FTAG
);
483 * Policy for setting the security label property.
485 * Returns 0 for success, non-zero for access and other errors.
488 zfs_set_slabel_policy(const char *name
, char *strval
, cred_t
*cr
)
491 char ds_hexsl
[MAXNAMELEN
];
492 bslabel_t ds_sl
, new_sl
;
493 boolean_t new_default
= FALSE
;
495 int needed_priv
= -1;
498 /* First get the existing dataset label. */
499 error
= dsl_prop_get(name
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
500 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
502 return (SET_ERROR(EPERM
));
504 if (strcasecmp(strval
, ZFS_MLSLABEL_DEFAULT
) == 0)
507 /* The label must be translatable */
508 if (!new_default
&& (hexstr_to_label(strval
, &new_sl
) != 0))
509 return (SET_ERROR(EINVAL
));
512 * In a non-global zone, disallow attempts to set a label that
513 * doesn't match that of the zone; otherwise no other checks
516 if (!INGLOBALZONE(curproc
)) {
517 if (new_default
|| !blequal(&new_sl
, CR_SL(CRED())))
518 return (SET_ERROR(EPERM
));
523 * For global-zone datasets (i.e., those whose zoned property is
524 * "off", verify that the specified new label is valid for the
527 if (dsl_prop_get_integer(name
,
528 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
529 return (SET_ERROR(EPERM
));
531 if (zfs_check_global_label(name
, strval
) != 0)
532 return (SET_ERROR(EPERM
));
536 * If the existing dataset label is nondefault, check if the
537 * dataset is mounted (label cannot be changed while mounted).
538 * Get the zfs_sb_t; if there isn't one, then the dataset isn't
539 * mounted (or isn't a dataset, doesn't exist, ...).
541 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) != 0) {
543 static char *setsl_tag
= "setsl_tag";
546 * Try to own the dataset; abort if there is any error,
547 * (e.g., already mounted, in use, or other error).
549 error
= dmu_objset_own(name
, DMU_OST_ZFS
, B_TRUE
,
552 return (SET_ERROR(EPERM
));
554 dmu_objset_disown(os
, setsl_tag
);
557 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
561 if (hexstr_to_label(strval
, &new_sl
) != 0)
562 return (SET_ERROR(EPERM
));
564 if (blstrictdom(&ds_sl
, &new_sl
))
565 needed_priv
= PRIV_FILE_DOWNGRADE_SL
;
566 else if (blstrictdom(&new_sl
, &ds_sl
))
567 needed_priv
= PRIV_FILE_UPGRADE_SL
;
569 /* dataset currently has a default label */
571 needed_priv
= PRIV_FILE_UPGRADE_SL
;
575 if (needed_priv
!= -1)
576 return (PRIV_POLICY(cr
, needed_priv
, B_FALSE
, EPERM
, NULL
));
580 #endif /* HAVE_MLSLABEL */
584 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
590 * Check permissions for special properties.
597 * Disallow setting of 'zoned' from within a local zone.
599 if (!INGLOBALZONE(curproc
))
600 return (SET_ERROR(EPERM
));
604 case ZFS_PROP_FILESYSTEM_LIMIT
:
605 case ZFS_PROP_SNAPSHOT_LIMIT
:
606 if (!INGLOBALZONE(curproc
)) {
608 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
610 * Unprivileged users are allowed to modify the
611 * limit on things *under* (ie. contained by)
612 * the thing they own.
614 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
616 return (SET_ERROR(EPERM
));
617 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
618 return (SET_ERROR(EPERM
));
622 case ZFS_PROP_MLSLABEL
:
623 if (!is_system_labeled())
624 return (SET_ERROR(EPERM
));
626 if (nvpair_value_string(propval
, &strval
) == 0) {
629 err
= zfs_set_slabel_policy(dsname
, strval
, CRED());
636 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
641 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
645 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
650 * permission to set permissions will be evaluated later in
651 * dsl_deleg_can_allow()
658 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
660 return (zfs_secpolicy_write_perms(zc
->zc_name
,
661 ZFS_DELEG_PERM_ROLLBACK
, cr
));
666 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
674 * Generate the current snapshot name from the given objsetid, then
675 * use that name for the secpolicy/zone checks.
677 cp
= strchr(zc
->zc_name
, '@');
679 return (SET_ERROR(EINVAL
));
680 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
684 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
686 dsl_pool_rele(dp
, FTAG
);
690 dsl_dataset_name(ds
, zc
->zc_name
);
692 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
693 ZFS_DELEG_PERM_SEND
, cr
);
694 dsl_dataset_rele(ds
, FTAG
);
695 dsl_pool_rele(dp
, FTAG
);
702 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
704 return (zfs_secpolicy_write_perms(zc
->zc_name
,
705 ZFS_DELEG_PERM_SEND
, cr
));
708 #ifdef HAVE_SMB_SHARE
711 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
716 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
717 NO_FOLLOW
, NULL
, &vp
)) != 0)
720 /* Now make sure mntpnt and dataset are ZFS */
722 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
723 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
724 zc
->zc_name
) != 0)) {
726 return (SET_ERROR(EPERM
));
730 return (dsl_deleg_access(zc
->zc_name
,
731 ZFS_DELEG_PERM_SHARE
, cr
));
733 #endif /* HAVE_SMB_SHARE */
736 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
738 #ifdef HAVE_SMB_SHARE
739 if (!INGLOBALZONE(curproc
))
740 return (SET_ERROR(EPERM
));
742 if (secpolicy_nfs(cr
) == 0) {
745 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
748 return (SET_ERROR(ENOTSUP
));
749 #endif /* HAVE_SMB_SHARE */
753 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
755 #ifdef HAVE_SMB_SHARE
756 if (!INGLOBALZONE(curproc
))
757 return (SET_ERROR(EPERM
));
759 if (secpolicy_smb(cr
) == 0) {
762 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
765 return (SET_ERROR(ENOTSUP
));
766 #endif /* HAVE_SMB_SHARE */
770 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
775 * Remove the @bla or /bla from the end of the name to get the parent.
777 (void) strncpy(parent
, datasetname
, parentsize
);
778 cp
= strrchr(parent
, '@');
782 cp
= strrchr(parent
, '/');
784 return (SET_ERROR(ENOENT
));
792 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
796 if ((error
= zfs_secpolicy_write_perms(name
,
797 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
800 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
805 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
807 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
811 * Destroying snapshots with delegated permissions requires
812 * descendant mount and destroy permissions.
816 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
819 nvpair_t
*pair
, *nextpair
;
822 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
823 return (SET_ERROR(EINVAL
));
824 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
826 nextpair
= nvlist_next_nvpair(snaps
, pair
);
827 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
828 if (error
== ENOENT
) {
830 * Ignore any snapshots that don't exist (we consider
831 * them "already destroyed"). Remove the name from the
832 * nvl here in case the snapshot is created between
833 * now and when we try to destroy it (in which case
834 * we don't want to destroy it since we haven't
835 * checked for permission).
837 fnvlist_remove_nvpair(snaps
, pair
);
848 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
850 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
853 if ((error
= zfs_secpolicy_write_perms(from
,
854 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
857 if ((error
= zfs_secpolicy_write_perms(from
,
858 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
861 if ((error
= zfs_get_parent(to
, parentname
,
862 sizeof (parentname
))) != 0)
865 if ((error
= zfs_secpolicy_write_perms(parentname
,
866 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
869 if ((error
= zfs_secpolicy_write_perms(parentname
,
870 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
878 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
880 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
885 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
888 dsl_dataset_t
*clone
;
891 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
892 ZFS_DELEG_PERM_PROMOTE
, cr
);
896 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
900 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
903 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
904 dsl_dataset_t
*origin
= NULL
;
908 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
909 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
911 dsl_dataset_rele(clone
, FTAG
);
912 dsl_pool_rele(dp
, FTAG
);
916 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
917 ZFS_DELEG_PERM_MOUNT
, cr
);
919 dsl_dataset_name(origin
, parentname
);
921 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
922 ZFS_DELEG_PERM_PROMOTE
, cr
);
924 dsl_dataset_rele(clone
, FTAG
);
925 dsl_dataset_rele(origin
, FTAG
);
927 dsl_pool_rele(dp
, FTAG
);
933 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
937 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
938 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
941 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
942 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
945 return (zfs_secpolicy_write_perms(zc
->zc_name
,
946 ZFS_DELEG_PERM_CREATE
, cr
));
951 zfs_secpolicy_recv_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
953 return (zfs_secpolicy_recv(zc
, innvl
, cr
));
957 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
959 return (zfs_secpolicy_write_perms(name
,
960 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
964 * Check for permission to create each snapshot in the nvlist.
968 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
974 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
975 return (SET_ERROR(EINVAL
));
976 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
977 pair
= nvlist_next_nvpair(snaps
, pair
)) {
978 char *name
= nvpair_name(pair
);
979 char *atp
= strchr(name
, '@');
982 error
= SET_ERROR(EINVAL
);
986 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
995 * Check for permission to create each snapshot in the nvlist.
999 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1004 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
1005 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
1006 char *name
= nvpair_name(pair
);
1007 char *hashp
= strchr(name
, '#');
1009 if (hashp
== NULL
) {
1010 error
= SET_ERROR(EINVAL
);
1014 error
= zfs_secpolicy_write_perms(name
,
1015 ZFS_DELEG_PERM_BOOKMARK
, cr
);
1025 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1027 nvpair_t
*pair
, *nextpair
;
1030 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1032 char *name
= nvpair_name(pair
);
1033 char *hashp
= strchr(name
, '#');
1034 nextpair
= nvlist_next_nvpair(innvl
, pair
);
1036 if (hashp
== NULL
) {
1037 error
= SET_ERROR(EINVAL
);
1042 error
= zfs_secpolicy_write_perms(name
,
1043 ZFS_DELEG_PERM_DESTROY
, cr
);
1045 if (error
== ENOENT
) {
1047 * Ignore any filesystems that don't exist (we consider
1048 * their bookmarks "already destroyed"). Remove
1049 * the name from the nvl here in case the filesystem
1050 * is created between now and when we try to destroy
1051 * the bookmark (in which case we don't want to
1052 * destroy it since we haven't checked for permission).
1054 fnvlist_remove_nvpair(innvl
, pair
);
1066 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1069 * Even root must have a proper TSD so that we know what pool
1072 if (tsd_get(zfs_allow_log_key
) == NULL
)
1073 return (SET_ERROR(EPERM
));
1078 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1080 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1084 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1085 sizeof (parentname
))) != 0)
1088 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1089 (error
= zfs_secpolicy_write_perms(origin
,
1090 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1093 if ((error
= zfs_secpolicy_write_perms(parentname
,
1094 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1097 return (zfs_secpolicy_write_perms(parentname
,
1098 ZFS_DELEG_PERM_MOUNT
, cr
));
1102 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1103 * SYS_CONFIG privilege, which is not available in a local zone.
1107 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1109 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1110 return (SET_ERROR(EPERM
));
1116 * Policy for object to name lookups.
1120 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1124 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1127 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1132 * Policy for fault injection. Requires all privileges.
1136 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1138 return (secpolicy_zinject(cr
));
1143 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1145 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1147 if (prop
== ZPROP_INVAL
) {
1148 if (!zfs_prop_user(zc
->zc_value
))
1149 return (SET_ERROR(EINVAL
));
1150 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1151 ZFS_DELEG_PERM_USERPROP
, cr
));
1153 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1159 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1161 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1165 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1166 return (SET_ERROR(EINVAL
));
1168 if (zc
->zc_value
[0] == 0) {
1170 * They are asking about a posix uid/gid. If it's
1171 * themself, allow it.
1173 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1174 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
1175 if (zc
->zc_guid
== crgetuid(cr
))
1178 if (groupmember(zc
->zc_guid
, cr
))
1183 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1184 userquota_perms
[zc
->zc_objset_type
], cr
));
1188 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1190 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1194 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1195 return (SET_ERROR(EINVAL
));
1197 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1198 userquota_perms
[zc
->zc_objset_type
], cr
));
1203 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1205 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1211 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1217 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1219 return (SET_ERROR(EINVAL
));
1221 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1222 pair
= nvlist_next_nvpair(holds
, pair
)) {
1223 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1224 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1227 error
= zfs_secpolicy_write_perms(fsname
,
1228 ZFS_DELEG_PERM_HOLD
, cr
);
1237 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1242 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1243 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1244 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1245 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1248 error
= zfs_secpolicy_write_perms(fsname
,
1249 ZFS_DELEG_PERM_RELEASE
, cr
);
1257 * Policy for allowing temporary snapshots to be taken or released
1260 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1263 * A temporary snapshot is the same as a snapshot,
1264 * hold, destroy and release all rolled into one.
1265 * Delegated diff alone is sufficient that we allow this.
1269 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1270 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1273 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1275 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1277 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1279 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1284 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1287 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1291 nvlist_t
*list
= NULL
;
1294 * Read in and unpack the user-supplied nvlist.
1297 return (SET_ERROR(EINVAL
));
1299 packed
= vmem_alloc(size
, KM_SLEEP
);
1301 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1303 vmem_free(packed
, size
);
1304 return (SET_ERROR(EFAULT
));
1307 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1308 vmem_free(packed
, size
);
1312 vmem_free(packed
, size
);
1319 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1320 * Entries will be removed from the end of the nvlist, and one int32 entry
1321 * named "N_MORE_ERRORS" will be added indicating how many entries were
1325 nvlist_smush(nvlist_t
*errors
, size_t max
)
1329 size
= fnvlist_size(errors
);
1332 nvpair_t
*more_errors
;
1336 return (SET_ERROR(ENOMEM
));
1338 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1339 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1342 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1344 fnvlist_remove_nvpair(errors
, pair
);
1346 size
= fnvlist_size(errors
);
1347 } while (size
> max
);
1349 fnvlist_remove_nvpair(errors
, more_errors
);
1350 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1351 ASSERT3U(fnvlist_size(errors
), <=, max
);
1358 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1360 char *packed
= NULL
;
1364 size
= fnvlist_size(nvl
);
1366 if (size
> zc
->zc_nvlist_dst_size
) {
1367 error
= SET_ERROR(ENOMEM
);
1369 packed
= fnvlist_pack(nvl
, &size
);
1370 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1371 size
, zc
->zc_iflags
) != 0)
1372 error
= SET_ERROR(EFAULT
);
1373 fnvlist_pack_free(packed
, size
);
1376 zc
->zc_nvlist_dst_size
= size
;
1377 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1382 get_zfs_sb(const char *dsname
, zfs_sb_t
**zsbp
)
1387 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1390 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1391 dmu_objset_rele(os
, FTAG
);
1392 return (SET_ERROR(EINVAL
));
1395 mutex_enter(&os
->os_user_ptr_lock
);
1396 *zsbp
= dmu_objset_get_user(os
);
1397 /* bump s_active only when non-zero to prevent umount race */
1398 if (*zsbp
== NULL
|| (*zsbp
)->z_sb
== NULL
||
1399 !atomic_inc_not_zero(&((*zsbp
)->z_sb
->s_active
))) {
1400 error
= SET_ERROR(ESRCH
);
1402 mutex_exit(&os
->os_user_ptr_lock
);
1403 dmu_objset_rele(os
, FTAG
);
1408 * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
1409 * case its z_sb will be NULL, and it will be opened as the owner.
1410 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1411 * which prevents all inode ops from running.
1414 zfs_sb_hold(const char *name
, void *tag
, zfs_sb_t
**zsbp
, boolean_t writer
)
1418 if (get_zfs_sb(name
, zsbp
) != 0)
1419 error
= zfs_sb_create(name
, NULL
, zsbp
);
1421 rrm_enter(&(*zsbp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1423 if ((*zsbp
)->z_unmounted
) {
1425 * XXX we could probably try again, since the unmounting
1426 * thread should be just about to disassociate the
1427 * objset from the zsb.
1429 rrm_exit(&(*zsbp
)->z_teardown_lock
, tag
);
1430 return (SET_ERROR(EBUSY
));
1437 zfs_sb_rele(zfs_sb_t
*zsb
, void *tag
)
1439 rrm_exit(&zsb
->z_teardown_lock
, tag
);
1442 deactivate_super(zsb
->z_sb
);
1444 dmu_objset_disown(zsb
->z_os
, zsb
);
1450 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1453 nvlist_t
*config
, *props
= NULL
;
1454 nvlist_t
*rootprops
= NULL
;
1455 nvlist_t
*zplprops
= NULL
;
1457 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1458 zc
->zc_iflags
, &config
)))
1461 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1462 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1463 zc
->zc_iflags
, &props
))) {
1464 nvlist_free(config
);
1469 nvlist_t
*nvl
= NULL
;
1470 uint64_t version
= SPA_VERSION
;
1472 (void) nvlist_lookup_uint64(props
,
1473 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1474 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1475 error
= SET_ERROR(EINVAL
);
1476 goto pool_props_bad
;
1478 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1480 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1482 nvlist_free(config
);
1486 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1488 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1489 error
= zfs_fill_zplprops_root(version
, rootprops
,
1492 goto pool_props_bad
;
1495 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1498 * Set the remaining root properties
1500 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1501 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1502 (void) spa_destroy(zc
->zc_name
);
1505 nvlist_free(rootprops
);
1506 nvlist_free(zplprops
);
1507 nvlist_free(config
);
1514 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1517 zfs_log_history(zc
);
1518 error
= spa_destroy(zc
->zc_name
);
1524 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1526 nvlist_t
*config
, *props
= NULL
;
1530 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1531 zc
->zc_iflags
, &config
)) != 0)
1534 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1535 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1536 zc
->zc_iflags
, &props
))) {
1537 nvlist_free(config
);
1541 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1542 guid
!= zc
->zc_guid
)
1543 error
= SET_ERROR(EINVAL
);
1545 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1547 if (zc
->zc_nvlist_dst
!= 0) {
1550 if ((err
= put_nvlist(zc
, config
)) != 0)
1554 nvlist_free(config
);
1561 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1564 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1565 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1567 zfs_log_history(zc
);
1568 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1574 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1579 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1580 return (SET_ERROR(EEXIST
));
1582 error
= put_nvlist(zc
, configs
);
1584 nvlist_free(configs
);
1591 * zc_name name of the pool
1594 * zc_cookie real errno
1595 * zc_nvlist_dst config nvlist
1596 * zc_nvlist_dst_size size of config nvlist
1599 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1605 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1606 sizeof (zc
->zc_value
));
1608 if (config
!= NULL
) {
1609 ret
= put_nvlist(zc
, config
);
1610 nvlist_free(config
);
1613 * The config may be present even if 'error' is non-zero.
1614 * In this case we return success, and preserve the real errno
1617 zc
->zc_cookie
= error
;
1626 * Try to import the given pool, returning pool stats as appropriate so that
1627 * user land knows which devices are available and overall pool health.
1630 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1632 nvlist_t
*tryconfig
, *config
;
1635 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1636 zc
->zc_iflags
, &tryconfig
)) != 0)
1639 config
= spa_tryimport(tryconfig
);
1641 nvlist_free(tryconfig
);
1644 return (SET_ERROR(EINVAL
));
1646 error
= put_nvlist(zc
, config
);
1647 nvlist_free(config
);
1654 * zc_name name of the pool
1655 * zc_cookie scan func (pool_scan_func_t)
1658 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1663 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1666 if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1667 error
= spa_scan_stop(spa
);
1669 error
= spa_scan(spa
, zc
->zc_cookie
);
1671 spa_close(spa
, FTAG
);
1677 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1682 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1685 spa_close(spa
, FTAG
);
1691 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1696 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1699 if (zc
->zc_cookie
< spa_version(spa
) ||
1700 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1701 spa_close(spa
, FTAG
);
1702 return (SET_ERROR(EINVAL
));
1705 spa_upgrade(spa
, zc
->zc_cookie
);
1706 spa_close(spa
, FTAG
);
1712 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1719 if ((size
= zc
->zc_history_len
) == 0)
1720 return (SET_ERROR(EINVAL
));
1722 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1725 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1726 spa_close(spa
, FTAG
);
1727 return (SET_ERROR(ENOTSUP
));
1730 hist_buf
= vmem_alloc(size
, KM_SLEEP
);
1731 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1732 &zc
->zc_history_len
, hist_buf
)) == 0) {
1733 error
= ddi_copyout(hist_buf
,
1734 (void *)(uintptr_t)zc
->zc_history
,
1735 zc
->zc_history_len
, zc
->zc_iflags
);
1738 spa_close(spa
, FTAG
);
1739 vmem_free(hist_buf
, size
);
1744 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1749 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1751 error
= spa_change_guid(spa
);
1752 spa_close(spa
, FTAG
);
1758 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1760 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1765 * zc_name name of filesystem
1766 * zc_obj object to find
1769 * zc_value name of object
1772 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1777 /* XXX reading from objset not owned */
1778 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1780 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1781 dmu_objset_rele(os
, FTAG
);
1782 return (SET_ERROR(EINVAL
));
1784 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1785 sizeof (zc
->zc_value
));
1786 dmu_objset_rele(os
, FTAG
);
1793 * zc_name name of filesystem
1794 * zc_obj object to find
1797 * zc_stat stats on object
1798 * zc_value path to object
1801 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1806 /* XXX reading from objset not owned */
1807 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1809 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1810 dmu_objset_rele(os
, FTAG
);
1811 return (SET_ERROR(EINVAL
));
1813 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1814 sizeof (zc
->zc_value
));
1815 dmu_objset_rele(os
, FTAG
);
1821 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1827 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1831 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1832 zc
->zc_iflags
, &config
);
1834 error
= spa_vdev_add(spa
, config
);
1835 nvlist_free(config
);
1837 spa_close(spa
, FTAG
);
1843 * zc_name name of the pool
1844 * zc_nvlist_conf nvlist of devices to remove
1845 * zc_cookie to stop the remove?
1848 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1853 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1856 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1857 spa_close(spa
, FTAG
);
1862 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1866 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1868 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1870 switch (zc
->zc_cookie
) {
1871 case VDEV_STATE_ONLINE
:
1872 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1875 case VDEV_STATE_OFFLINE
:
1876 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1879 case VDEV_STATE_FAULTED
:
1880 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1881 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1882 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1884 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1887 case VDEV_STATE_DEGRADED
:
1888 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1889 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1890 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1892 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1896 error
= SET_ERROR(EINVAL
);
1898 zc
->zc_cookie
= newstate
;
1899 spa_close(spa
, FTAG
);
1904 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1907 int replacing
= zc
->zc_cookie
;
1911 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1914 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1915 zc
->zc_iflags
, &config
)) == 0) {
1916 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1917 nvlist_free(config
);
1920 spa_close(spa
, FTAG
);
1925 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1930 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1933 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1935 spa_close(spa
, FTAG
);
1940 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1943 nvlist_t
*config
, *props
= NULL
;
1945 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1947 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1950 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1951 zc
->zc_iflags
, &config
))) {
1952 spa_close(spa
, FTAG
);
1956 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1957 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1958 zc
->zc_iflags
, &props
))) {
1959 spa_close(spa
, FTAG
);
1960 nvlist_free(config
);
1964 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1966 spa_close(spa
, FTAG
);
1968 nvlist_free(config
);
1975 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1978 char *path
= zc
->zc_value
;
1979 uint64_t guid
= zc
->zc_guid
;
1982 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1986 error
= spa_vdev_setpath(spa
, guid
, path
);
1987 spa_close(spa
, FTAG
);
1992 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1995 char *fru
= zc
->zc_value
;
1996 uint64_t guid
= zc
->zc_guid
;
1999 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
2003 error
= spa_vdev_setfru(spa
, guid
, fru
);
2004 spa_close(spa
, FTAG
);
2009 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
2014 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2016 if (zc
->zc_nvlist_dst
!= 0 &&
2017 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
2018 dmu_objset_stats(os
, nv
);
2020 * NB: zvol_get_stats() will read the objset contents,
2021 * which we aren't supposed to do with a
2022 * DS_MODE_USER hold, because it could be
2023 * inconsistent. So this is a bit of a workaround...
2024 * XXX reading with out owning
2026 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
2027 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
2028 error
= zvol_get_stats(os
, nv
);
2034 error
= put_nvlist(zc
, nv
);
2043 * zc_name name of filesystem
2044 * zc_nvlist_dst_size size of buffer for property nvlist
2047 * zc_objset_stats stats
2048 * zc_nvlist_dst property nvlist
2049 * zc_nvlist_dst_size size of property nvlist
2052 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2057 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2059 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2060 dmu_objset_rele(os
, FTAG
);
2068 * zc_name name of filesystem
2069 * zc_nvlist_dst_size size of buffer for property nvlist
2072 * zc_nvlist_dst received property nvlist
2073 * zc_nvlist_dst_size size of received property nvlist
2075 * Gets received properties (distinct from local properties on or after
2076 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2077 * local property values.
2080 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2086 * Without this check, we would return local property values if the
2087 * caller has not already received properties on or after
2088 * SPA_VERSION_RECVD_PROPS.
2090 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2091 return (SET_ERROR(ENOTSUP
));
2093 if (zc
->zc_nvlist_dst
!= 0 &&
2094 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2095 error
= put_nvlist(zc
, nv
);
2103 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2109 * zfs_get_zplprop() will either find a value or give us
2110 * the default value (if there is one).
2112 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2114 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2120 * zc_name name of filesystem
2121 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2124 * zc_nvlist_dst zpl property nvlist
2125 * zc_nvlist_dst_size size of zpl property nvlist
2128 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2133 /* XXX reading without owning */
2134 if ((err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)))
2137 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2140 * NB: nvl_add_zplprop() will read the objset contents,
2141 * which we aren't supposed to do with a DS_MODE_USER
2142 * hold, because it could be inconsistent.
2144 if (zc
->zc_nvlist_dst
!= 0 &&
2145 !zc
->zc_objset_stats
.dds_inconsistent
&&
2146 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2149 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2150 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2151 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2152 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2153 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2154 err
= put_nvlist(zc
, nv
);
2157 err
= SET_ERROR(ENOENT
);
2159 dmu_objset_rele(os
, FTAG
);
2164 dataset_name_hidden(const char *name
)
2167 * Skip over datasets that are not visible in this zone,
2168 * internal datasets (which have a $ in their name), and
2169 * temporary datasets (which have a % in their name).
2171 if (strchr(name
, '$') != NULL
)
2173 if (strchr(name
, '%') != NULL
)
2175 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2182 * zc_name name of filesystem
2183 * zc_cookie zap cursor
2184 * zc_nvlist_dst_size size of buffer for property nvlist
2187 * zc_name name of next filesystem
2188 * zc_cookie zap cursor
2189 * zc_objset_stats stats
2190 * zc_nvlist_dst property nvlist
2191 * zc_nvlist_dst_size size of property nvlist
2194 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2199 size_t orig_len
= strlen(zc
->zc_name
);
2202 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))) {
2203 if (error
== ENOENT
)
2204 error
= SET_ERROR(ESRCH
);
2208 p
= strrchr(zc
->zc_name
, '/');
2209 if (p
== NULL
|| p
[1] != '\0')
2210 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2211 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2214 error
= dmu_dir_list_next(os
,
2215 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2216 NULL
, &zc
->zc_cookie
);
2217 if (error
== ENOENT
)
2218 error
= SET_ERROR(ESRCH
);
2219 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2220 dmu_objset_rele(os
, FTAG
);
2223 * If it's an internal dataset (ie. with a '$' in its name),
2224 * don't try to get stats for it, otherwise we'll return ENOENT.
2226 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2227 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2228 if (error
== ENOENT
) {
2229 /* We lost a race with destroy, get the next one. */
2230 zc
->zc_name
[orig_len
] = '\0';
2239 * zc_name name of filesystem
2240 * zc_cookie zap cursor
2241 * zc_nvlist_dst_size size of buffer for property nvlist
2244 * zc_name name of next snapshot
2245 * zc_objset_stats stats
2246 * zc_nvlist_dst property nvlist
2247 * zc_nvlist_dst_size size of property nvlist
2250 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2255 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2257 return (error
== ENOENT
? ESRCH
: error
);
2261 * A dataset name of maximum length cannot have any snapshots,
2262 * so exit immediately.
2264 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2265 ZFS_MAX_DATASET_NAME_LEN
) {
2266 dmu_objset_rele(os
, FTAG
);
2267 return (SET_ERROR(ESRCH
));
2270 error
= dmu_snapshot_list_next(os
,
2271 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2272 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2275 if (error
== 0 && !zc
->zc_simple
) {
2277 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2279 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2283 error
= dmu_objset_from_ds(ds
, &ossnap
);
2285 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2286 dsl_dataset_rele(ds
, FTAG
);
2288 } else if (error
== ENOENT
) {
2289 error
= SET_ERROR(ESRCH
);
2292 dmu_objset_rele(os
, FTAG
);
2293 /* if we failed, undo the @ that we tacked on to zc_name */
2295 *strchr(zc
->zc_name
, '@') = '\0';
2300 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2302 const char *propname
= nvpair_name(pair
);
2304 unsigned int vallen
;
2307 zfs_userquota_prop_t type
;
2313 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2315 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2316 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2318 return (SET_ERROR(EINVAL
));
2322 * A correctly constructed propname is encoded as
2323 * userquota@<rid>-<domain>.
2325 if ((dash
= strchr(propname
, '-')) == NULL
||
2326 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2328 return (SET_ERROR(EINVAL
));
2335 err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_FALSE
);
2337 err
= zfs_set_userquota(zsb
, type
, domain
, rid
, quota
);
2338 zfs_sb_rele(zsb
, FTAG
);
2345 * If the named property is one that has a special function to set its value,
2346 * return 0 on success and a positive error code on failure; otherwise if it is
2347 * not one of the special properties handled by this function, return -1.
2349 * XXX: It would be better for callers of the property interface if we handled
2350 * these special cases in dsl_prop.c (in the dsl layer).
2353 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2356 const char *propname
= nvpair_name(pair
);
2357 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2361 if (prop
== ZPROP_INVAL
) {
2362 if (zfs_prop_userquota(propname
))
2363 return (zfs_prop_set_userquota(dsname
, pair
));
2367 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2369 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2370 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2374 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2377 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2380 case ZFS_PROP_QUOTA
:
2381 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2383 case ZFS_PROP_REFQUOTA
:
2384 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2386 case ZFS_PROP_FILESYSTEM_LIMIT
:
2387 case ZFS_PROP_SNAPSHOT_LIMIT
:
2388 if (intval
== UINT64_MAX
) {
2389 /* clearing the limit, just do it */
2392 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2395 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2396 * default path to set the value in the nvlist.
2401 case ZFS_PROP_RESERVATION
:
2402 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2404 case ZFS_PROP_REFRESERVATION
:
2405 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2407 case ZFS_PROP_VOLSIZE
:
2408 err
= zvol_set_volsize(dsname
, intval
);
2410 case ZFS_PROP_SNAPDEV
:
2411 err
= zvol_set_snapdev(dsname
, source
, intval
);
2413 case ZFS_PROP_VERSION
:
2417 if ((err
= zfs_sb_hold(dsname
, FTAG
, &zsb
, B_TRUE
)) != 0)
2420 err
= zfs_set_version(zsb
, intval
);
2421 zfs_sb_rele(zsb
, FTAG
);
2423 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2426 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2427 (void) strcpy(zc
->zc_name
, dsname
);
2428 (void) zfs_ioc_userspace_upgrade(zc
);
2429 kmem_free(zc
, sizeof (zfs_cmd_t
));
2441 * This function is best effort. If it fails to set any of the given properties,
2442 * it continues to set as many as it can and returns the last error
2443 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2444 * with the list of names of all the properties that failed along with the
2445 * corresponding error numbers.
2447 * If every property is set successfully, zero is returned and errlist is not
2451 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2460 nvlist_t
*genericnvl
= fnvlist_alloc();
2461 nvlist_t
*retrynvl
= fnvlist_alloc();
2464 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2465 const char *propname
= nvpair_name(pair
);
2466 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2469 /* decode the property value */
2471 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2473 attrs
= fnvpair_value_nvlist(pair
);
2474 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2476 err
= SET_ERROR(EINVAL
);
2479 /* Validate value type */
2480 if (err
== 0 && prop
== ZPROP_INVAL
) {
2481 if (zfs_prop_user(propname
)) {
2482 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2483 err
= SET_ERROR(EINVAL
);
2484 } else if (zfs_prop_userquota(propname
)) {
2485 if (nvpair_type(propval
) !=
2486 DATA_TYPE_UINT64_ARRAY
)
2487 err
= SET_ERROR(EINVAL
);
2489 err
= SET_ERROR(EINVAL
);
2491 } else if (err
== 0) {
2492 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2493 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2494 err
= SET_ERROR(EINVAL
);
2495 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2498 intval
= fnvpair_value_uint64(propval
);
2500 switch (zfs_prop_get_type(prop
)) {
2501 case PROP_TYPE_NUMBER
:
2503 case PROP_TYPE_STRING
:
2504 err
= SET_ERROR(EINVAL
);
2506 case PROP_TYPE_INDEX
:
2507 if (zfs_prop_index_to_string(prop
,
2508 intval
, &unused
) != 0)
2509 err
= SET_ERROR(EINVAL
);
2513 "unknown property type");
2516 err
= SET_ERROR(EINVAL
);
2520 /* Validate permissions */
2522 err
= zfs_check_settable(dsname
, pair
, CRED());
2525 err
= zfs_prop_set_special(dsname
, source
, pair
);
2528 * For better performance we build up a list of
2529 * properties to set in a single transaction.
2531 err
= nvlist_add_nvpair(genericnvl
, pair
);
2532 } else if (err
!= 0 && nvl
!= retrynvl
) {
2534 * This may be a spurious error caused by
2535 * receiving quota and reservation out of order.
2536 * Try again in a second pass.
2538 err
= nvlist_add_nvpair(retrynvl
, pair
);
2543 if (errlist
!= NULL
)
2544 fnvlist_add_int32(errlist
, propname
, err
);
2549 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2554 if (!nvlist_empty(genericnvl
) &&
2555 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2557 * If this fails, we still want to set as many properties as we
2558 * can, so try setting them individually.
2561 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2562 const char *propname
= nvpair_name(pair
);
2566 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2568 attrs
= fnvpair_value_nvlist(pair
);
2569 propval
= fnvlist_lookup_nvpair(attrs
,
2573 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2574 strval
= fnvpair_value_string(propval
);
2575 err
= dsl_prop_set_string(dsname
, propname
,
2578 intval
= fnvpair_value_uint64(propval
);
2579 err
= dsl_prop_set_int(dsname
, propname
, source
,
2584 if (errlist
!= NULL
) {
2585 fnvlist_add_int32(errlist
, propname
,
2592 nvlist_free(genericnvl
);
2593 nvlist_free(retrynvl
);
2599 * Check that all the properties are valid user properties.
2602 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2604 nvpair_t
*pair
= NULL
;
2607 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2608 const char *propname
= nvpair_name(pair
);
2610 if (!zfs_prop_user(propname
) ||
2611 nvpair_type(pair
) != DATA_TYPE_STRING
)
2612 return (SET_ERROR(EINVAL
));
2614 if ((error
= zfs_secpolicy_write_perms(fsname
,
2615 ZFS_DELEG_PERM_USERPROP
, CRED())))
2618 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2619 return (SET_ERROR(ENAMETOOLONG
));
2621 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2622 return (SET_ERROR(E2BIG
));
2628 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2632 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2635 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2636 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2639 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2644 clear_received_props(const char *dsname
, nvlist_t
*props
,
2648 nvlist_t
*cleared_props
= NULL
;
2649 props_skip(props
, skipped
, &cleared_props
);
2650 if (!nvlist_empty(cleared_props
)) {
2652 * Acts on local properties until the dataset has received
2653 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2655 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2656 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2657 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2659 nvlist_free(cleared_props
);
2665 * zc_name name of filesystem
2666 * zc_value name of property to set
2667 * zc_nvlist_src{_size} nvlist of properties to apply
2668 * zc_cookie received properties flag
2671 * zc_nvlist_dst{_size} error for each unapplied received property
2674 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2677 boolean_t received
= zc
->zc_cookie
;
2678 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2683 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2684 zc
->zc_iflags
, &nvl
)) != 0)
2688 nvlist_t
*origprops
;
2690 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2691 (void) clear_received_props(zc
->zc_name
,
2693 nvlist_free(origprops
);
2696 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2699 errors
= fnvlist_alloc();
2701 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2703 if (zc
->zc_nvlist_dst
!= 0 && errors
!= NULL
) {
2704 (void) put_nvlist(zc
, errors
);
2707 nvlist_free(errors
);
2714 * zc_name name of filesystem
2715 * zc_value name of property to inherit
2716 * zc_cookie revert to received value if TRUE
2721 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2723 const char *propname
= zc
->zc_value
;
2724 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2725 boolean_t received
= zc
->zc_cookie
;
2726 zprop_source_t source
= (received
2727 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2728 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2737 * zfs_prop_set_special() expects properties in the form of an
2738 * nvpair with type info.
2740 if (prop
== ZPROP_INVAL
) {
2741 if (!zfs_prop_user(propname
))
2742 return (SET_ERROR(EINVAL
));
2744 type
= PROP_TYPE_STRING
;
2745 } else if (prop
== ZFS_PROP_VOLSIZE
||
2746 prop
== ZFS_PROP_VERSION
) {
2747 return (SET_ERROR(EINVAL
));
2749 type
= zfs_prop_get_type(prop
);
2752 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2755 case PROP_TYPE_STRING
:
2756 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2758 case PROP_TYPE_NUMBER
:
2759 case PROP_TYPE_INDEX
:
2760 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2764 return (SET_ERROR(EINVAL
));
2767 pair
= nvlist_next_nvpair(dummy
, NULL
);
2768 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2771 return (err
); /* special property already handled */
2774 * Only check this in the non-received case. We want to allow
2775 * 'inherit -S' to revert non-inheritable properties like quota
2776 * and reservation to the received or default values even though
2777 * they are not considered inheritable.
2779 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2780 return (SET_ERROR(EINVAL
));
2783 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2784 return (dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
, source
));
2788 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2795 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2796 zc
->zc_iflags
, &props
)))
2800 * If the only property is the configfile, then just do a spa_lookup()
2801 * to handle the faulted case.
2803 pair
= nvlist_next_nvpair(props
, NULL
);
2804 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2805 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2806 nvlist_next_nvpair(props
, pair
) == NULL
) {
2807 mutex_enter(&spa_namespace_lock
);
2808 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2809 spa_configfile_set(spa
, props
, B_FALSE
);
2810 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2812 mutex_exit(&spa_namespace_lock
);
2819 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2824 error
= spa_prop_set(spa
, props
);
2827 spa_close(spa
, FTAG
);
2833 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2837 nvlist_t
*nvp
= NULL
;
2839 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2841 * If the pool is faulted, there may be properties we can still
2842 * get (such as altroot and cachefile), so attempt to get them
2845 mutex_enter(&spa_namespace_lock
);
2846 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2847 error
= spa_prop_get(spa
, &nvp
);
2848 mutex_exit(&spa_namespace_lock
);
2850 error
= spa_prop_get(spa
, &nvp
);
2851 spa_close(spa
, FTAG
);
2854 if (error
== 0 && zc
->zc_nvlist_dst
!= 0)
2855 error
= put_nvlist(zc
, nvp
);
2857 error
= SET_ERROR(EFAULT
);
2865 * zc_name name of filesystem
2866 * zc_nvlist_src{_size} nvlist of delegated permissions
2867 * zc_perm_action allow/unallow flag
2872 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2875 nvlist_t
*fsaclnv
= NULL
;
2877 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2878 zc
->zc_iflags
, &fsaclnv
)) != 0)
2882 * Verify nvlist is constructed correctly
2884 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2885 nvlist_free(fsaclnv
);
2886 return (SET_ERROR(EINVAL
));
2890 * If we don't have PRIV_SYS_MOUNT, then validate
2891 * that user is allowed to hand out each permission in
2895 error
= secpolicy_zfs(CRED());
2897 if (zc
->zc_perm_action
== B_FALSE
) {
2898 error
= dsl_deleg_can_allow(zc
->zc_name
,
2901 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2907 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2909 nvlist_free(fsaclnv
);
2915 * zc_name name of filesystem
2918 * zc_nvlist_src{_size} nvlist of delegated permissions
2921 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2926 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2927 error
= put_nvlist(zc
, nvp
);
2936 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2938 zfs_creat_t
*zct
= arg
;
2940 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2943 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2947 * os parent objset pointer (NULL if root fs)
2948 * fuids_ok fuids allowed in this version of the spa?
2949 * sa_ok SAs allowed in this version of the spa?
2950 * createprops list of properties requested by creator
2953 * zplprops values for the zplprops we attach to the master node object
2954 * is_ci true if requested file system will be purely case-insensitive
2956 * Determine the settings for utf8only, normalization and
2957 * casesensitivity. Specific values may have been requested by the
2958 * creator and/or we can inherit values from the parent dataset. If
2959 * the file system is of too early a vintage, a creator can not
2960 * request settings for these properties, even if the requested
2961 * setting is the default value. We don't actually want to create dsl
2962 * properties for these, so remove them from the source nvlist after
2966 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2967 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2968 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2970 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2971 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2972 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2975 ASSERT(zplprops
!= NULL
);
2978 * Pull out creator prop choices, if any.
2981 (void) nvlist_lookup_uint64(createprops
,
2982 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2983 (void) nvlist_lookup_uint64(createprops
,
2984 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2985 (void) nvlist_remove_all(createprops
,
2986 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2987 (void) nvlist_lookup_uint64(createprops
,
2988 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2989 (void) nvlist_remove_all(createprops
,
2990 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2991 (void) nvlist_lookup_uint64(createprops
,
2992 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2993 (void) nvlist_remove_all(createprops
,
2994 zfs_prop_to_name(ZFS_PROP_CASE
));
2998 * If the zpl version requested is whacky or the file system
2999 * or pool is version is too "young" to support normalization
3000 * and the creator tried to set a value for one of the props,
3003 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
3004 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
3005 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
3006 (zplver
< ZPL_VERSION_NORMALIZATION
&&
3007 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
3008 sense
!= ZFS_PROP_UNDEFINED
)))
3009 return (SET_ERROR(ENOTSUP
));
3012 * Put the version in the zplprops
3014 VERIFY(nvlist_add_uint64(zplprops
,
3015 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
3017 if (norm
== ZFS_PROP_UNDEFINED
&&
3018 (error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
)) != 0)
3020 VERIFY(nvlist_add_uint64(zplprops
,
3021 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
3024 * If we're normalizing, names must always be valid UTF-8 strings.
3028 if (u8
== ZFS_PROP_UNDEFINED
&&
3029 (error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
)) != 0)
3031 VERIFY(nvlist_add_uint64(zplprops
,
3032 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
3034 if (sense
== ZFS_PROP_UNDEFINED
&&
3035 (error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
)) != 0)
3037 VERIFY(nvlist_add_uint64(zplprops
,
3038 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3041 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3047 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3048 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3050 boolean_t fuids_ok
, sa_ok
;
3051 uint64_t zplver
= ZPL_VERSION
;
3052 objset_t
*os
= NULL
;
3053 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3059 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3060 cp
= strrchr(parentname
, '/');
3064 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3067 spa_vers
= spa_version(spa
);
3068 spa_close(spa
, FTAG
);
3070 zplver
= zfs_zpl_version_map(spa_vers
);
3071 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3072 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3075 * Open parent object set so we can inherit zplprop values.
3077 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3080 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3082 dmu_objset_rele(os
, FTAG
);
3087 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3088 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3092 uint64_t zplver
= ZPL_VERSION
;
3095 zplver
= zfs_zpl_version_map(spa_vers
);
3096 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3097 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3099 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3100 createprops
, zplprops
, is_ci
);
3106 * "type" -> dmu_objset_type_t (int32)
3107 * (optional) "props" -> { prop -> value }
3110 * outnvl: propname -> error code (int32)
3113 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3116 zfs_creat_t zct
= { 0 };
3117 nvlist_t
*nvprops
= NULL
;
3118 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3120 dmu_objset_type_t type
;
3121 boolean_t is_insensitive
= B_FALSE
;
3123 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3124 return (SET_ERROR(EINVAL
));
3126 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3130 cbfunc
= zfs_create_cb
;
3134 cbfunc
= zvol_create_cb
;
3141 if (strchr(fsname
, '@') ||
3142 strchr(fsname
, '%'))
3143 return (SET_ERROR(EINVAL
));
3145 zct
.zct_props
= nvprops
;
3148 return (SET_ERROR(EINVAL
));
3150 if (type
== DMU_OST_ZVOL
) {
3151 uint64_t volsize
, volblocksize
;
3153 if (nvprops
== NULL
)
3154 return (SET_ERROR(EINVAL
));
3155 if (nvlist_lookup_uint64(nvprops
,
3156 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3157 return (SET_ERROR(EINVAL
));
3159 if ((error
= nvlist_lookup_uint64(nvprops
,
3160 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3161 &volblocksize
)) != 0 && error
!= ENOENT
)
3162 return (SET_ERROR(EINVAL
));
3165 volblocksize
= zfs_prop_default_numeric(
3166 ZFS_PROP_VOLBLOCKSIZE
);
3168 if ((error
= zvol_check_volblocksize(fsname
,
3169 volblocksize
)) != 0 ||
3170 (error
= zvol_check_volsize(volsize
,
3171 volblocksize
)) != 0)
3173 } else if (type
== DMU_OST_ZFS
) {
3177 * We have to have normalization and
3178 * case-folding flags correct when we do the
3179 * file system creation, so go figure them out
3182 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3183 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3184 error
= zfs_fill_zplprops(fsname
, nvprops
,
3185 zct
.zct_zplprops
, &is_insensitive
);
3187 nvlist_free(zct
.zct_zplprops
);
3192 error
= dmu_objset_create(fsname
, type
,
3193 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3194 nvlist_free(zct
.zct_zplprops
);
3197 * It would be nice to do this atomically.
3200 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3207 * Volumes will return EBUSY and cannot be destroyed
3208 * until all asynchronous minor handling has completed.
3209 * Wait for the spa_zvol_taskq to drain then retry.
3211 error2
= dsl_destroy_head(fsname
);
3212 while ((error2
== EBUSY
) && (type
== DMU_OST_ZVOL
)) {
3213 error2
= spa_open(fsname
, &spa
, FTAG
);
3215 taskq_wait(spa
->spa_zvol_taskq
);
3216 spa_close(spa
, FTAG
);
3218 error2
= dsl_destroy_head(fsname
);
3227 * "origin" -> name of origin snapshot
3228 * (optional) "props" -> { prop -> value }
3232 * outnvl: propname -> error code (int32)
3235 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3238 nvlist_t
*nvprops
= NULL
;
3241 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3242 return (SET_ERROR(EINVAL
));
3243 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3245 if (strchr(fsname
, '@') ||
3246 strchr(fsname
, '%'))
3247 return (SET_ERROR(EINVAL
));
3249 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3250 return (SET_ERROR(EINVAL
));
3251 error
= dmu_objset_clone(fsname
, origin_name
);
3256 * It would be nice to do this atomically.
3259 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3262 (void) dsl_destroy_head(fsname
);
3269 * "snaps" -> { snapshot1, snapshot2 }
3270 * (optional) "props" -> { prop -> value (string) }
3273 * outnvl: snapshot -> error code (int32)
3276 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3279 nvlist_t
*props
= NULL
;
3281 nvpair_t
*pair
, *pair2
;
3283 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3284 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3287 if (!nvlist_empty(props
) &&
3288 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3289 return (SET_ERROR(ENOTSUP
));
3291 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3292 return (SET_ERROR(EINVAL
));
3293 poollen
= strlen(poolname
);
3294 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3295 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3296 const char *name
= nvpair_name(pair
);
3297 const char *cp
= strchr(name
, '@');
3300 * The snap name must contain an @, and the part after it must
3301 * contain only valid characters.
3304 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3305 return (SET_ERROR(EINVAL
));
3308 * The snap must be in the specified pool.
3310 if (strncmp(name
, poolname
, poollen
) != 0 ||
3311 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3312 return (SET_ERROR(EXDEV
));
3314 /* This must be the only snap of this fs. */
3315 for (pair2
= nvlist_next_nvpair(snaps
, pair
);
3316 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3317 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3319 return (SET_ERROR(EXDEV
));
3324 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3330 * innvl: "message" -> string
3334 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3342 * The poolname in the ioctl is not set, we get it from the TSD,
3343 * which was set at the end of the last successful ioctl that allows
3344 * logging. The secpolicy func already checked that it is set.
3345 * Only one log ioctl is allowed after each successful ioctl, so
3346 * we clear the TSD here.
3348 poolname
= tsd_get(zfs_allow_log_key
);
3349 if (poolname
== NULL
)
3350 return (SET_ERROR(EINVAL
));
3351 (void) tsd_set(zfs_allow_log_key
, NULL
);
3352 error
= spa_open(poolname
, &spa
, FTAG
);
3357 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3358 spa_close(spa
, FTAG
);
3359 return (SET_ERROR(EINVAL
));
3362 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3363 spa_close(spa
, FTAG
);
3364 return (SET_ERROR(ENOTSUP
));
3367 error
= spa_history_log(spa
, message
);
3368 spa_close(spa
, FTAG
);
3373 * The dp_config_rwlock must not be held when calling this, because the
3374 * unmount may need to write out data.
3376 * This function is best-effort. Callers must deal gracefully if it
3377 * remains mounted (or is remounted after this call).
3379 * Returns 0 if the argument is not a snapshot, or it is not currently a
3380 * filesystem, or we were able to unmount it. Returns error code otherwise.
3383 zfs_unmount_snap(const char *snapname
)
3387 if (strchr(snapname
, '@') == NULL
)
3390 err
= zfsctl_snapshot_unmount((char *)snapname
, MNT_FORCE
);
3391 if (err
!= 0 && err
!= ENOENT
)
3392 return (SET_ERROR(err
));
3399 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3401 return (zfs_unmount_snap(snapname
));
3405 * When a clone is destroyed, its origin may also need to be destroyed,
3406 * in which case it must be unmounted. This routine will do that unmount
3410 zfs_destroy_unmount_origin(const char *fsname
)
3416 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3419 ds
= dmu_objset_ds(os
);
3420 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3421 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3422 dsl_dataset_name(ds
->ds_prev
, originname
);
3423 dmu_objset_rele(os
, FTAG
);
3424 (void) zfs_unmount_snap(originname
);
3426 dmu_objset_rele(os
, FTAG
);
3432 * "snaps" -> { snapshot1, snapshot2 }
3433 * (optional boolean) "defer"
3436 * outnvl: snapshot -> error code (int32)
3440 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3446 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3447 return (SET_ERROR(EINVAL
));
3448 defer
= nvlist_exists(innvl
, "defer");
3450 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3451 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3452 (void) zfs_unmount_snap(nvpair_name(pair
));
3455 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3459 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3460 * All bookmarks must be in the same pool.
3463 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3466 * outnvl: bookmark -> error code (int32)
3471 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3473 nvpair_t
*pair
, *pair2
;
3475 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
3476 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3480 * Verify the snapshot argument.
3482 if (nvpair_value_string(pair
, &snap_name
) != 0)
3483 return (SET_ERROR(EINVAL
));
3486 /* Verify that the keys (bookmarks) are unique */
3487 for (pair2
= nvlist_next_nvpair(innvl
, pair
);
3488 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3489 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3490 return (SET_ERROR(EINVAL
));
3494 return (dsl_bookmark_create(innvl
, outnvl
));
3499 * property 1, property 2, ...
3503 * bookmark name 1 -> { property 1, property 2, ... },
3504 * bookmark name 2 -> { property 1, property 2, ... }
3509 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3511 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3516 * bookmark name 1, bookmark name 2
3519 * outnvl: bookmark -> error code (int32)
3523 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3529 poollen
= strlen(poolname
);
3530 for (pair
= nvlist_next_nvpair(innvl
, NULL
);
3531 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3532 const char *name
= nvpair_name(pair
);
3533 const char *cp
= strchr(name
, '#');
3536 * The bookmark name must contain an #, and the part after it
3537 * must contain only valid characters.
3540 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3541 return (SET_ERROR(EINVAL
));
3544 * The bookmark must be in the specified pool.
3546 if (strncmp(name
, poolname
, poollen
) != 0 ||
3547 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3548 return (SET_ERROR(EXDEV
));
3551 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3557 * zc_name name of dataset to destroy
3558 * zc_objset_type type of objset
3559 * zc_defer_destroy mark for deferred destroy
3564 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3568 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3569 err
= zfs_unmount_snap(zc
->zc_name
);
3574 if (strchr(zc
->zc_name
, '@')) {
3575 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3577 err
= dsl_destroy_head(zc
->zc_name
);
3578 if (err
== EEXIST
) {
3580 * It is possible that the given DS may have
3581 * hidden child (%recv) datasets - "leftovers"
3582 * resulting from the previously interrupted
3585 * 6 extra bytes for /%recv
3587 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
3589 (void) snprintf(namebuf
, sizeof (namebuf
),
3590 "%s/%s", zc
->zc_name
, recv_clone_name
);
3593 * Try to remove the hidden child (%recv) and after
3594 * that try to remove the target dataset.
3595 * If the hidden child (%recv) does not exist
3596 * the original error (EEXIST) will be returned
3598 err
= dsl_destroy_head(namebuf
);
3600 err
= dsl_destroy_head(zc
->zc_name
);
3601 else if (err
== ENOENT
)
3610 * fsname is name of dataset to rollback (to most recent snapshot)
3612 * innvl is not used.
3614 * outnvl: "target" -> name of most recent snapshot
3619 zfs_ioc_rollback(const char *fsname
, nvlist_t
*args
, nvlist_t
*outnvl
)
3624 if (get_zfs_sb(fsname
, &zsb
) == 0) {
3625 error
= zfs_suspend_fs(zsb
);
3629 error
= dsl_dataset_rollback(fsname
, zsb
, outnvl
);
3630 resume_err
= zfs_resume_fs(zsb
, fsname
);
3631 error
= error
? error
: resume_err
;
3633 deactivate_super(zsb
->z_sb
);
3635 error
= dsl_dataset_rollback(fsname
, NULL
, outnvl
);
3641 recursive_unmount(const char *fsname
, void *arg
)
3643 const char *snapname
= arg
;
3647 fullname
= kmem_asprintf("%s@%s", fsname
, snapname
);
3648 error
= zfs_unmount_snap(fullname
);
3656 * zc_name old name of dataset
3657 * zc_value new name of dataset
3658 * zc_cookie recursive flag (only valid for snapshots)
3663 zfs_ioc_rename(zfs_cmd_t
*zc
)
3665 boolean_t recursive
= zc
->zc_cookie
& 1;
3668 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3669 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3670 strchr(zc
->zc_value
, '%'))
3671 return (SET_ERROR(EINVAL
));
3673 at
= strchr(zc
->zc_name
, '@');
3675 /* snaps must be in same fs */
3678 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3679 return (SET_ERROR(EXDEV
));
3681 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3682 error
= dmu_objset_find(zc
->zc_name
,
3683 recursive_unmount
, at
+ 1,
3684 recursive
? DS_FIND_CHILDREN
: 0);
3690 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3691 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3696 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3701 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3703 const char *propname
= nvpair_name(pair
);
3704 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3705 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3709 if (prop
== ZPROP_INVAL
) {
3710 if (zfs_prop_user(propname
)) {
3711 if ((err
= zfs_secpolicy_write_perms(dsname
,
3712 ZFS_DELEG_PERM_USERPROP
, cr
)))
3717 if (!issnap
&& zfs_prop_userquota(propname
)) {
3718 const char *perm
= NULL
;
3719 const char *uq_prefix
=
3720 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3721 const char *gq_prefix
=
3722 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3724 if (strncmp(propname
, uq_prefix
,
3725 strlen(uq_prefix
)) == 0) {
3726 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3727 } else if (strncmp(propname
, gq_prefix
,
3728 strlen(gq_prefix
)) == 0) {
3729 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3731 /* USERUSED and GROUPUSED are read-only */
3732 return (SET_ERROR(EINVAL
));
3735 if ((err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
)))
3740 return (SET_ERROR(EINVAL
));
3744 return (SET_ERROR(EINVAL
));
3746 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3748 * dsl_prop_get_all_impl() returns properties in this
3752 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3753 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3758 * Check that this value is valid for this pool version
3761 case ZFS_PROP_COMPRESSION
:
3763 * If the user specified gzip compression, make sure
3764 * the SPA supports it. We ignore any errors here since
3765 * we'll catch them later.
3767 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3768 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3769 intval
<= ZIO_COMPRESS_GZIP_9
&&
3770 zfs_earlier_version(dsname
,
3771 SPA_VERSION_GZIP_COMPRESSION
)) {
3772 return (SET_ERROR(ENOTSUP
));
3775 if (intval
== ZIO_COMPRESS_ZLE
&&
3776 zfs_earlier_version(dsname
,
3777 SPA_VERSION_ZLE_COMPRESSION
))
3778 return (SET_ERROR(ENOTSUP
));
3780 if (intval
== ZIO_COMPRESS_LZ4
) {
3783 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3786 if (!spa_feature_is_enabled(spa
,
3787 SPA_FEATURE_LZ4_COMPRESS
)) {
3788 spa_close(spa
, FTAG
);
3789 return (SET_ERROR(ENOTSUP
));
3791 spa_close(spa
, FTAG
);
3795 * If this is a bootable dataset then
3796 * verify that the compression algorithm
3797 * is supported for booting. We must return
3798 * something other than ENOTSUP since it
3799 * implies a downrev pool version.
3801 if (zfs_is_bootfs(dsname
) &&
3802 !BOOTFS_COMPRESS_VALID(intval
)) {
3803 return (SET_ERROR(ERANGE
));
3808 case ZFS_PROP_COPIES
:
3809 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3810 return (SET_ERROR(ENOTSUP
));
3813 case ZFS_PROP_VOLBLOCKSIZE
:
3814 case ZFS_PROP_RECORDSIZE
:
3815 /* Record sizes above 128k need the feature to be enabled */
3816 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3817 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3821 * If this is a bootable dataset then
3822 * we don't allow large (>128K) blocks,
3823 * because GRUB doesn't support them.
3825 if (zfs_is_bootfs(dsname
) &&
3826 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3827 return (SET_ERROR(ERANGE
));
3831 * We don't allow setting the property above 1MB,
3832 * unless the tunable has been changed.
3834 if (intval
> zfs_max_recordsize
||
3835 intval
> SPA_MAXBLOCKSIZE
)
3836 return (SET_ERROR(ERANGE
));
3838 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3841 if (!spa_feature_is_enabled(spa
,
3842 SPA_FEATURE_LARGE_BLOCKS
)) {
3843 spa_close(spa
, FTAG
);
3844 return (SET_ERROR(ENOTSUP
));
3846 spa_close(spa
, FTAG
);
3850 case ZFS_PROP_DNODESIZE
:
3851 /* Dnode sizes above 512 need the feature to be enabled */
3852 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3853 intval
!= ZFS_DNSIZE_LEGACY
) {
3857 * If this is a bootable dataset then
3858 * we don't allow large (>512B) dnodes,
3859 * because GRUB doesn't support them.
3861 if (zfs_is_bootfs(dsname
) &&
3862 intval
!= ZFS_DNSIZE_LEGACY
) {
3863 return (SET_ERROR(EDOM
));
3866 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3869 if (!spa_feature_is_enabled(spa
,
3870 SPA_FEATURE_LARGE_DNODE
)) {
3871 spa_close(spa
, FTAG
);
3872 return (SET_ERROR(ENOTSUP
));
3874 spa_close(spa
, FTAG
);
3878 case ZFS_PROP_SHARESMB
:
3879 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3880 return (SET_ERROR(ENOTSUP
));
3883 case ZFS_PROP_ACLINHERIT
:
3884 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3885 nvpair_value_uint64(pair
, &intval
) == 0) {
3886 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3887 zfs_earlier_version(dsname
,
3888 SPA_VERSION_PASSTHROUGH_X
))
3889 return (SET_ERROR(ENOTSUP
));
3892 case ZFS_PROP_CHECKSUM
:
3893 case ZFS_PROP_DEDUP
:
3895 spa_feature_t feature
;
3900 /* dedup feature version checks */
3901 if (prop
== ZFS_PROP_DEDUP
&&
3902 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3903 return (SET_ERROR(ENOTSUP
));
3905 if (nvpair_value_uint64(pair
, &intval
) != 0)
3906 return (SET_ERROR(EINVAL
));
3908 /* check prop value is enabled in features */
3909 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
3910 if (feature
== SPA_FEATURE_NONE
)
3913 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3916 * Salted checksums are not supported on root pools.
3918 if (spa_bootfs(spa
) != 0 &&
3919 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
3920 (zio_checksum_table
[intval
].ci_flags
&
3921 ZCHECKSUM_FLAG_SALTED
)) {
3922 spa_close(spa
, FTAG
);
3923 return (SET_ERROR(ERANGE
));
3925 if (!spa_feature_is_enabled(spa
, feature
)) {
3926 spa_close(spa
, FTAG
);
3927 return (SET_ERROR(ENOTSUP
));
3929 spa_close(spa
, FTAG
);
3937 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3941 * Removes properties from the given props list that fail permission checks
3942 * needed to clear them and to restore them in case of a receive error. For each
3943 * property, make sure we have both set and inherit permissions.
3945 * Returns the first error encountered if any permission checks fail. If the
3946 * caller provides a non-NULL errlist, it also gives the complete list of names
3947 * of all the properties that failed a permission check along with the
3948 * corresponding error numbers. The caller is responsible for freeing the
3951 * If every property checks out successfully, zero is returned and the list
3952 * pointed at by errlist is NULL.
3955 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3958 nvpair_t
*pair
, *next_pair
;
3965 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3967 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
3968 (void) strlcpy(zc
->zc_name
, dataset
, sizeof (zc
->zc_name
));
3969 pair
= nvlist_next_nvpair(props
, NULL
);
3970 while (pair
!= NULL
) {
3971 next_pair
= nvlist_next_nvpair(props
, pair
);
3973 (void) strlcpy(zc
->zc_value
, nvpair_name(pair
),
3974 sizeof (zc
->zc_value
));
3975 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3976 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
3977 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3978 VERIFY(nvlist_add_int32(errors
,
3979 zc
->zc_value
, err
) == 0);
3983 kmem_free(zc
, sizeof (zfs_cmd_t
));
3985 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3986 nvlist_free(errors
);
3989 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3992 if (errlist
== NULL
)
3993 nvlist_free(errors
);
4001 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
4003 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
4004 /* dsl_prop_get_all_impl() format */
4006 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
4007 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4011 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
4013 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
4014 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4018 if (nvpair_type(p1
) != nvpair_type(p2
))
4021 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4022 char *valstr1
, *valstr2
;
4024 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4025 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4026 return (strcmp(valstr1
, valstr2
) == 0);
4028 uint64_t intval1
, intval2
;
4030 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4031 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4032 return (intval1
== intval2
);
4037 * Remove properties from props if they are not going to change (as determined
4038 * by comparison with origprops). Remove them from origprops as well, since we
4039 * do not need to clear or restore properties that won't change.
4042 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4044 nvpair_t
*pair
, *next_pair
;
4046 if (origprops
== NULL
)
4047 return; /* all props need to be received */
4049 pair
= nvlist_next_nvpair(props
, NULL
);
4050 while (pair
!= NULL
) {
4051 const char *propname
= nvpair_name(pair
);
4054 next_pair
= nvlist_next_nvpair(props
, pair
);
4056 if ((nvlist_lookup_nvpair(origprops
, propname
,
4057 &match
) != 0) || !propval_equals(pair
, match
))
4058 goto next
; /* need to set received value */
4060 /* don't clear the existing received value */
4061 (void) nvlist_remove_nvpair(origprops
, match
);
4062 /* don't bother receiving the property */
4063 (void) nvlist_remove_nvpair(props
, pair
);
4070 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4071 * For example, refquota cannot be set until after the receipt of a dataset,
4072 * because in replication streams, an older/earlier snapshot may exceed the
4073 * refquota. We want to receive the older/earlier snapshot, but setting
4074 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4075 * the older/earlier snapshot from being received (with EDQUOT).
4077 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4079 * libzfs will need to be judicious handling errors encountered by props
4080 * extracted by this function.
4083 extract_delay_props(nvlist_t
*props
)
4085 nvlist_t
*delayprops
;
4086 nvpair_t
*nvp
, *tmp
;
4087 static const zfs_prop_t delayable
[] = { ZFS_PROP_REFQUOTA
, 0 };
4090 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4092 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4093 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4095 * strcmp() is safe because zfs_prop_to_name() always returns
4098 for (i
= 0; delayable
[i
] != 0; i
++) {
4099 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4100 nvpair_name(nvp
)) == 0) {
4104 if (delayable
[i
] != 0) {
4105 tmp
= nvlist_prev_nvpair(props
, nvp
);
4106 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4107 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4112 if (nvlist_empty(delayprops
)) {
4113 nvlist_free(delayprops
);
4116 return (delayprops
);
4120 static boolean_t zfs_ioc_recv_inject_err
;
4124 * nvlist 'errors' is always allocated. It will contain descriptions of
4125 * encountered errors, if any. It's the callers responsibility to free.
4128 zfs_ioc_recv_impl(char *tofs
, char *tosnap
, char *origin
,
4129 nvlist_t
*props
, boolean_t force
, boolean_t resumable
, int input_fd
,
4130 dmu_replay_record_t
*begin_record
, int cleanup_fd
, uint64_t *read_bytes
,
4131 uint64_t *errflags
, uint64_t *action_handle
, nvlist_t
**errors
)
4133 dmu_recv_cookie_t drc
;
4135 int props_error
= 0;
4137 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4138 nvlist_t
*origprops
= NULL
; /* existing properties */
4139 boolean_t first_recvd_props
= B_FALSE
;
4144 *errors
= fnvlist_alloc();
4146 input_fp
= getf(input_fd
);
4147 if (input_fp
== NULL
)
4148 return (SET_ERROR(EBADF
));
4150 error
= dmu_recv_begin(tofs
, tosnap
,
4151 begin_record
, force
, resumable
, origin
, &drc
);
4156 * Set properties before we receive the stream so that they are applied
4157 * to the new data. Note that we must call dmu_recv_stream() if
4158 * dmu_recv_begin() succeeds.
4160 if (props
!= NULL
&& !drc
.drc_newfs
) {
4161 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4162 SPA_VERSION_RECVD_PROPS
&&
4163 !dsl_prop_get_hasrecvd(tofs
))
4164 first_recvd_props
= B_TRUE
;
4167 * If new received properties are supplied, they are to
4168 * completely replace the existing received properties, so stash
4169 * away the existing ones.
4171 if (dsl_prop_get_received(tofs
, &origprops
) == 0) {
4172 nvlist_t
*errlist
= NULL
;
4174 * Don't bother writing a property if its value won't
4175 * change (and avoid the unnecessary security checks).
4177 * The first receive after SPA_VERSION_RECVD_PROPS is a
4178 * special case where we blow away all local properties
4181 if (!first_recvd_props
)
4182 props_reduce(props
, origprops
);
4183 if (zfs_check_clearable(tofs
, origprops
, &errlist
) != 0)
4184 (void) nvlist_merge(*errors
, errlist
, 0);
4185 nvlist_free(errlist
);
4187 if (clear_received_props(tofs
, origprops
,
4188 first_recvd_props
? NULL
: props
) != 0)
4189 *errflags
|= ZPROP_ERR_NOCLEAR
;
4191 *errflags
|= ZPROP_ERR_NOCLEAR
;
4195 if (props
!= NULL
) {
4196 props_error
= dsl_prop_set_hasrecvd(tofs
);
4198 if (props_error
== 0) {
4199 delayprops
= extract_delay_props(props
);
4200 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4205 off
= input_fp
->f_offset
;
4206 error
= dmu_recv_stream(&drc
, input_fp
->f_vnode
, &off
, cleanup_fd
,
4210 zfs_sb_t
*zsb
= NULL
;
4212 if (get_zfs_sb(tofs
, &zsb
) == 0) {
4216 error
= zfs_suspend_fs(zsb
);
4218 * If the suspend fails, then the recv_end will
4219 * likely also fail, and clean up after itself.
4221 end_err
= dmu_recv_end(&drc
, zsb
);
4223 error
= zfs_resume_fs(zsb
, tofs
);
4224 error
= error
? error
: end_err
;
4225 deactivate_super(zsb
->z_sb
);
4227 error
= dmu_recv_end(&drc
, NULL
);
4230 /* Set delayed properties now, after we're done receiving. */
4231 if (delayprops
!= NULL
&& error
== 0) {
4232 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4233 delayprops
, *errors
);
4237 if (delayprops
!= NULL
) {
4239 * Merge delayed props back in with initial props, in case
4240 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4241 * we have to make sure clear_received_props() includes
4242 * the delayed properties).
4244 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4245 * using ASSERT() will be just like a VERIFY.
4247 ASSERT(nvlist_merge(props
, delayprops
, 0) == 0);
4248 nvlist_free(delayprops
);
4252 *read_bytes
= off
- input_fp
->f_offset
;
4253 if (VOP_SEEK(input_fp
->f_vnode
, input_fp
->f_offset
, &off
, NULL
) == 0)
4254 input_fp
->f_offset
= off
;
4257 if (zfs_ioc_recv_inject_err
) {
4258 zfs_ioc_recv_inject_err
= B_FALSE
;
4264 * On error, restore the original props.
4266 if (error
!= 0 && props
!= NULL
&& !drc
.drc_newfs
) {
4267 if (clear_received_props(tofs
, props
, NULL
) != 0) {
4269 * We failed to clear the received properties.
4270 * Since we may have left a $recvd value on the
4271 * system, we can't clear the $hasrecvd flag.
4273 *errflags
|= ZPROP_ERR_NORESTORE
;
4274 } else if (first_recvd_props
) {
4275 dsl_prop_unset_hasrecvd(tofs
);
4278 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4279 /* We failed to stash the original properties. */
4280 *errflags
|= ZPROP_ERR_NORESTORE
;
4284 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4285 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4286 * explictly if we're restoring local properties cleared in the
4287 * first new-style receive.
4289 if (origprops
!= NULL
&&
4290 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4291 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4292 origprops
, NULL
) != 0) {
4294 * We stashed the original properties but failed to
4297 *errflags
|= ZPROP_ERR_NORESTORE
;
4302 nvlist_free(origprops
);
4305 error
= props_error
;
4312 * zc_name name of containing filesystem (unused)
4313 * zc_nvlist_src{_size} nvlist of properties to apply
4314 * zc_value name of snapshot to create
4315 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4316 * zc_cookie file descriptor to recv from
4317 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4318 * zc_guid force flag
4319 * zc_cleanup_fd cleanup-on-exit file descriptor
4320 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4323 * zc_cookie number of bytes read
4324 * zc_obj zprop_errflags_t
4325 * zc_action_handle handle for this guid/ds mapping
4326 * zc_nvlist_dst{_size} error for each unapplied received property
4329 zfs_ioc_recv(zfs_cmd_t
*zc
)
4331 dmu_replay_record_t begin_record
;
4332 nvlist_t
*errors
= NULL
;
4333 nvlist_t
*props
= NULL
;
4334 char *origin
= NULL
;
4336 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4339 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4340 strchr(zc
->zc_value
, '@') == NULL
||
4341 strchr(zc
->zc_value
, '%'))
4342 return (SET_ERROR(EINVAL
));
4344 (void) strlcpy(tofs
, zc
->zc_value
, sizeof (tofs
));
4345 tosnap
= strchr(tofs
, '@');
4348 if (zc
->zc_nvlist_src
!= 0 &&
4349 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4350 zc
->zc_iflags
, &props
)) != 0)
4353 if (zc
->zc_string
[0])
4354 origin
= zc
->zc_string
;
4356 begin_record
.drr_type
= DRR_BEGIN
;
4357 begin_record
.drr_payloadlen
= 0;
4358 begin_record
.drr_u
.drr_begin
= zc
->zc_begin_record
;
4360 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, props
, zc
->zc_guid
,
4361 B_FALSE
, zc
->zc_cookie
, &begin_record
, zc
->zc_cleanup_fd
,
4362 &zc
->zc_cookie
, &zc
->zc_obj
, &zc
->zc_action_handle
, &errors
);
4366 * Now that all props, initial and delayed, are set, report the prop
4367 * errors to the caller.
4369 if (zc
->zc_nvlist_dst_size
!= 0 && errors
!= NULL
&&
4370 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4371 put_nvlist(zc
, errors
) != 0)) {
4373 * Caller made zc->zc_nvlist_dst less than the minimum expected
4374 * size or supplied an invalid address.
4376 error
= SET_ERROR(EINVAL
);
4379 nvlist_free(errors
);
4386 * "snapname" -> full name of the snapshot to create
4387 * (optional) "props" -> properties to set (nvlist)
4388 * (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
4389 * "begin_record" -> non-byteswapped dmu_replay_record_t
4390 * "input_fd" -> file descriptor to read stream from (int32)
4391 * (optional) "force" -> force flag (value ignored)
4392 * (optional) "resumable" -> resumable flag (value ignored)
4393 * (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
4394 * (optional) "action_handle" -> handle for this guid/ds mapping
4398 * "read_bytes" -> number of bytes read
4399 * "error_flags" -> zprop_errflags_t
4400 * "action_handle" -> handle for this guid/ds mapping
4401 * "errors" -> error for each unapplied received property (nvlist)
4405 zfs_ioc_recv_new(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
4407 dmu_replay_record_t
*begin_record
;
4408 uint_t begin_record_size
;
4409 nvlist_t
*errors
= NULL
;
4410 nvlist_t
*props
= NULL
;
4411 char *snapname
= NULL
;
4412 char *origin
= NULL
;
4414 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4416 boolean_t resumable
;
4417 uint64_t action_handle
= 0;
4418 uint64_t read_bytes
= 0;
4419 uint64_t errflags
= 0;
4421 int cleanup_fd
= -1;
4424 error
= nvlist_lookup_string(innvl
, "snapname", &snapname
);
4426 return (SET_ERROR(EINVAL
));
4428 if (dataset_namecheck(snapname
, NULL
, NULL
) != 0 ||
4429 strchr(snapname
, '@') == NULL
||
4430 strchr(snapname
, '%'))
4431 return (SET_ERROR(EINVAL
));
4433 (void) strcpy(tofs
, snapname
);
4434 tosnap
= strchr(tofs
, '@');
4437 error
= nvlist_lookup_string(innvl
, "origin", &origin
);
4438 if (error
&& error
!= ENOENT
)
4441 error
= nvlist_lookup_byte_array(innvl
, "begin_record",
4442 (uchar_t
**) &begin_record
, &begin_record_size
);
4443 if (error
!= 0 || begin_record_size
!= sizeof (*begin_record
))
4444 return (SET_ERROR(EINVAL
));
4446 error
= nvlist_lookup_int32(innvl
, "input_fd", &input_fd
);
4448 return (SET_ERROR(EINVAL
));
4450 force
= nvlist_exists(innvl
, "force");
4451 resumable
= nvlist_exists(innvl
, "resumable");
4453 error
= nvlist_lookup_int32(innvl
, "cleanup_fd", &cleanup_fd
);
4454 if (error
&& error
!= ENOENT
)
4457 error
= nvlist_lookup_uint64(innvl
, "action_handle", &action_handle
);
4458 if (error
&& error
!= ENOENT
)
4461 error
= nvlist_lookup_nvlist(innvl
, "props", &props
);
4462 if (error
&& error
!= ENOENT
)
4465 error
= zfs_ioc_recv_impl(tofs
, tosnap
, origin
, props
, force
,
4466 resumable
, input_fd
, begin_record
, cleanup_fd
, &read_bytes
,
4467 &errflags
, &action_handle
, &errors
);
4469 fnvlist_add_uint64(outnvl
, "read_bytes", read_bytes
);
4470 fnvlist_add_uint64(outnvl
, "error_flags", errflags
);
4471 fnvlist_add_uint64(outnvl
, "action_handle", action_handle
);
4472 fnvlist_add_nvlist(outnvl
, "errors", errors
);
4474 nvlist_free(errors
);
4482 * zc_name name of snapshot to send
4483 * zc_cookie file descriptor to send stream to
4484 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4485 * zc_sendobj objsetid of snapshot to send
4486 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4487 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4488 * output size in zc_objset_type.
4489 * zc_flags lzc_send_flags
4492 * zc_objset_type estimated size, if zc_guid is set
4495 zfs_ioc_send(zfs_cmd_t
*zc
)
4499 boolean_t estimate
= (zc
->zc_guid
!= 0);
4500 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4501 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4502 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4504 if (zc
->zc_obj
!= 0) {
4506 dsl_dataset_t
*tosnap
;
4508 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4512 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4514 dsl_pool_rele(dp
, FTAG
);
4518 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4520 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4521 dsl_dataset_rele(tosnap
, FTAG
);
4522 dsl_pool_rele(dp
, FTAG
);
4527 dsl_dataset_t
*tosnap
;
4528 dsl_dataset_t
*fromsnap
= NULL
;
4530 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4534 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4536 dsl_pool_rele(dp
, FTAG
);
4540 if (zc
->zc_fromobj
!= 0) {
4541 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4544 dsl_dataset_rele(tosnap
, FTAG
);
4545 dsl_pool_rele(dp
, FTAG
);
4550 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
4551 &zc
->zc_objset_type
);
4553 if (fromsnap
!= NULL
)
4554 dsl_dataset_rele(fromsnap
, FTAG
);
4555 dsl_dataset_rele(tosnap
, FTAG
);
4556 dsl_pool_rele(dp
, FTAG
);
4558 file_t
*fp
= getf(zc
->zc_cookie
);
4560 return (SET_ERROR(EBADF
));
4563 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4564 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
,
4565 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4567 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4569 releasef(zc
->zc_cookie
);
4576 * zc_name name of snapshot on which to report progress
4577 * zc_cookie file descriptor of send stream
4580 * zc_cookie number of bytes written in send stream thus far
4583 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4587 dmu_sendarg_t
*dsp
= NULL
;
4590 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4594 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4596 dsl_pool_rele(dp
, FTAG
);
4600 mutex_enter(&ds
->ds_sendstream_lock
);
4603 * Iterate over all the send streams currently active on this dataset.
4604 * If there's one which matches the specified file descriptor _and_ the
4605 * stream was started by the current process, return the progress of
4609 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4610 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4611 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4612 dsp
->dsa_proc
->group_leader
== curproc
->group_leader
)
4617 zc
->zc_cookie
= *(dsp
->dsa_off
);
4619 error
= SET_ERROR(ENOENT
);
4621 mutex_exit(&ds
->ds_sendstream_lock
);
4622 dsl_dataset_rele(ds
, FTAG
);
4623 dsl_pool_rele(dp
, FTAG
);
4628 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4632 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4633 &zc
->zc_inject_record
);
4636 zc
->zc_guid
= (uint64_t)id
;
4642 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4644 return (zio_clear_fault((int)zc
->zc_guid
));
4648 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4650 int id
= (int)zc
->zc_guid
;
4653 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4654 &zc
->zc_inject_record
);
4662 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4666 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4668 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4671 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4674 zc
->zc_nvlist_dst_size
= count
;
4676 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4678 spa_close(spa
, FTAG
);
4684 zfs_ioc_clear(zfs_cmd_t
*zc
)
4691 * On zpool clear we also fix up missing slogs
4693 mutex_enter(&spa_namespace_lock
);
4694 spa
= spa_lookup(zc
->zc_name
);
4696 mutex_exit(&spa_namespace_lock
);
4697 return (SET_ERROR(EIO
));
4699 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4700 /* we need to let spa_open/spa_load clear the chains */
4701 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4703 spa
->spa_last_open_failed
= 0;
4704 mutex_exit(&spa_namespace_lock
);
4706 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4707 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4710 nvlist_t
*config
= NULL
;
4712 if (zc
->zc_nvlist_src
== 0)
4713 return (SET_ERROR(EINVAL
));
4715 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4716 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4717 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4719 if (config
!= NULL
) {
4722 if ((err
= put_nvlist(zc
, config
)) != 0)
4724 nvlist_free(config
);
4726 nvlist_free(policy
);
4733 spa_vdev_state_enter(spa
, SCL_NONE
);
4735 if (zc
->zc_guid
== 0) {
4738 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4740 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4741 spa_close(spa
, FTAG
);
4742 return (SET_ERROR(ENODEV
));
4746 vdev_clear(spa
, vd
);
4748 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4751 * Resume any suspended I/Os.
4753 if (zio_resume(spa
) != 0)
4754 error
= SET_ERROR(EIO
);
4756 spa_close(spa
, FTAG
);
4762 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4767 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4771 spa_vdev_state_enter(spa
, SCL_NONE
);
4774 * If a resilver is already in progress then set the
4775 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4776 * the scan as a side effect of the reopen. Otherwise, let
4777 * vdev_open() decided if a resilver is required.
4779 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4780 vdev_reopen(spa
->spa_root_vdev
);
4781 spa
->spa_scrub_reopen
= B_FALSE
;
4783 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4784 spa_close(spa
, FTAG
);
4789 * zc_name name of filesystem
4790 * zc_value name of origin snapshot
4793 * zc_string name of conflicting snapshot, if there is one
4796 zfs_ioc_promote(zfs_cmd_t
*zc
)
4801 * We don't need to unmount *all* the origin fs's snapshots, but
4804 cp
= strchr(zc
->zc_value
, '@');
4807 (void) dmu_objset_find(zc
->zc_value
,
4808 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
4809 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4813 * Retrieve a single {user|group}{used|quota}@... property.
4816 * zc_name name of filesystem
4817 * zc_objset_type zfs_userquota_prop_t
4818 * zc_value domain name (eg. "S-1-234-567-89")
4819 * zc_guid RID/UID/GID
4822 * zc_cookie property value
4825 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4830 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4831 return (SET_ERROR(EINVAL
));
4833 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4837 error
= zfs_userspace_one(zsb
,
4838 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4839 zfs_sb_rele(zsb
, FTAG
);
4846 * zc_name name of filesystem
4847 * zc_cookie zap cursor
4848 * zc_objset_type zfs_userquota_prop_t
4849 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4852 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4853 * zc_cookie zap cursor
4856 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4859 int bufsize
= zc
->zc_nvlist_dst_size
;
4864 return (SET_ERROR(ENOMEM
));
4866 error
= zfs_sb_hold(zc
->zc_name
, FTAG
, &zsb
, B_FALSE
);
4870 buf
= vmem_alloc(bufsize
, KM_SLEEP
);
4872 error
= zfs_userspace_many(zsb
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4873 buf
, &zc
->zc_nvlist_dst_size
);
4876 error
= xcopyout(buf
,
4877 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4878 zc
->zc_nvlist_dst_size
);
4880 vmem_free(buf
, bufsize
);
4881 zfs_sb_rele(zsb
, FTAG
);
4888 * zc_name name of filesystem
4894 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4900 if (get_zfs_sb(zc
->zc_name
, &zsb
) == 0) {
4901 if (!dmu_objset_userused_enabled(zsb
->z_os
)) {
4903 * If userused is not enabled, it may be because the
4904 * objset needs to be closed & reopened (to grow the
4905 * objset_phys_t). Suspend/resume the fs will do that.
4907 error
= zfs_suspend_fs(zsb
);
4909 dmu_objset_refresh_ownership(zsb
->z_os
,
4911 error
= zfs_resume_fs(zsb
, zc
->zc_name
);
4915 error
= dmu_objset_userspace_upgrade(zsb
->z_os
);
4916 deactivate_super(zsb
->z_sb
);
4918 /* XXX kind of reading contents without owning */
4919 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4923 error
= dmu_objset_userspace_upgrade(os
);
4924 dmu_objset_rele(os
, FTAG
);
4931 zfs_ioc_share(zfs_cmd_t
*zc
)
4933 return (SET_ERROR(ENOSYS
));
4936 ace_t full_access
[] = {
4937 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4942 * zc_name name of containing filesystem
4943 * zc_obj object # beyond which we want next in-use object #
4946 * zc_obj next in-use object #
4949 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4951 objset_t
*os
= NULL
;
4954 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4958 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
, 0);
4960 dmu_objset_rele(os
, FTAG
);
4966 * zc_name name of filesystem
4967 * zc_value prefix name for snapshot
4968 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4971 * zc_value short name of new snapshot
4974 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
4981 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
4985 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
4986 (u_longlong_t
)ddi_get_lbolt64());
4987 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
4989 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
4992 (void) strlcpy(zc
->zc_value
, snap_name
,
4993 sizeof (zc
->zc_value
));
4996 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5002 * zc_name name of "to" snapshot
5003 * zc_value name of "from" snapshot
5004 * zc_cookie file descriptor to write diff data on
5007 * dmu_diff_record_t's to the file descriptor
5010 zfs_ioc_diff(zfs_cmd_t
*zc
)
5016 fp
= getf(zc
->zc_cookie
);
5018 return (SET_ERROR(EBADF
));
5022 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5024 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5026 releasef(zc
->zc_cookie
);
5032 * Remove all ACL files in shares dir
5034 #ifdef HAVE_SMB_SHARE
5036 zfs_smb_acl_purge(znode_t
*dzp
)
5039 zap_attribute_t zap
;
5040 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
5043 for (zap_cursor_init(&zc
, zsb
->z_os
, dzp
->z_id
);
5044 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5045 zap_cursor_advance(&zc
)) {
5046 if ((error
= VOP_REMOVE(ZTOV(dzp
), zap
.za_name
, kcred
,
5050 zap_cursor_fini(&zc
);
5053 #endif /* HAVE_SMB_SHARE */
5056 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5058 #ifdef HAVE_SMB_SHARE
5061 vnode_t
*resourcevp
= NULL
;
5070 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5071 NO_FOLLOW
, NULL
, &vp
)) != 0)
5074 /* Now make sure mntpnt and dataset are ZFS */
5076 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5077 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5078 zc
->zc_name
) != 0)) {
5080 return (SET_ERROR(EINVAL
));
5088 * Create share dir if its missing.
5090 mutex_enter(&zsb
->z_lock
);
5091 if (zsb
->z_shares_dir
== 0) {
5094 tx
= dmu_tx_create(zsb
->z_os
);
5095 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5097 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5098 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5102 error
= zfs_create_share_dir(zsb
, tx
);
5106 mutex_exit(&zsb
->z_lock
);
5112 mutex_exit(&zsb
->z_lock
);
5114 ASSERT(zsb
->z_shares_dir
);
5115 if ((error
= zfs_zget(zsb
, zsb
->z_shares_dir
, &sharedir
)) != 0) {
5121 switch (zc
->zc_cookie
) {
5122 case ZFS_SMB_ACL_ADD
:
5123 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5124 vattr
.va_mode
= S_IFREG
|0777;
5128 vsec
.vsa_mask
= VSA_ACE
;
5129 vsec
.vsa_aclentp
= &full_access
;
5130 vsec
.vsa_aclentsz
= sizeof (full_access
);
5131 vsec
.vsa_aclcnt
= 1;
5133 error
= VOP_CREATE(ZTOV(sharedir
), zc
->zc_string
,
5134 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5136 VN_RELE(resourcevp
);
5139 case ZFS_SMB_ACL_REMOVE
:
5140 error
= VOP_REMOVE(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5144 case ZFS_SMB_ACL_RENAME
:
5145 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5146 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5148 VN_RELE(ZTOV(sharedir
));
5152 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5153 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5156 VN_RELE(ZTOV(sharedir
));
5158 nvlist_free(nvlist
);
5161 error
= VOP_RENAME(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5163 nvlist_free(nvlist
);
5166 case ZFS_SMB_ACL_PURGE
:
5167 error
= zfs_smb_acl_purge(sharedir
);
5171 error
= SET_ERROR(EINVAL
);
5176 VN_RELE(ZTOV(sharedir
));
5182 return (SET_ERROR(ENOTSUP
));
5183 #endif /* HAVE_SMB_SHARE */
5188 * "holds" -> { snapname -> holdname (string), ... }
5189 * (optional) "cleanup_fd" -> fd (int32)
5193 * snapname -> error value (int32)
5199 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5203 int cleanup_fd
= -1;
5207 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5209 return (SET_ERROR(EINVAL
));
5211 /* make sure the user didn't pass us any invalid (empty) tags */
5212 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5213 pair
= nvlist_next_nvpair(holds
, pair
)) {
5216 error
= nvpair_value_string(pair
, &htag
);
5218 return (SET_ERROR(error
));
5220 if (strlen(htag
) == 0)
5221 return (SET_ERROR(EINVAL
));
5224 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5225 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5230 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5232 zfs_onexit_fd_rele(cleanup_fd
);
5237 * innvl is not used.
5240 * holdname -> time added (uint64 seconds since epoch)
5246 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5248 return (dsl_dataset_get_holds(snapname
, outnvl
));
5253 * snapname -> { holdname, ... }
5258 * snapname -> error value (int32)
5264 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5266 return (dsl_dataset_user_release(holds
, errlist
));
5271 * zc_guid flags (ZEVENT_NONBLOCK)
5272 * zc_cleanup_fd zevent file descriptor
5275 * zc_nvlist_dst next nvlist event
5276 * zc_cookie dropped events since last get
5279 zfs_ioc_events_next(zfs_cmd_t
*zc
)
5282 nvlist_t
*event
= NULL
;
5284 uint64_t dropped
= 0;
5287 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5292 error
= zfs_zevent_next(ze
, &event
,
5293 &zc
->zc_nvlist_dst_size
, &dropped
);
5294 if (event
!= NULL
) {
5295 zc
->zc_cookie
= dropped
;
5296 error
= put_nvlist(zc
, event
);
5300 if (zc
->zc_guid
& ZEVENT_NONBLOCK
)
5303 if ((error
== 0) || (error
!= ENOENT
))
5306 error
= zfs_zevent_wait(ze
);
5311 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5318 * zc_cookie cleared events count
5321 zfs_ioc_events_clear(zfs_cmd_t
*zc
)
5325 zfs_zevent_drain_all(&count
);
5326 zc
->zc_cookie
= count
;
5333 * zc_guid eid | ZEVENT_SEEK_START | ZEVENT_SEEK_END
5334 * zc_cleanup zevent file descriptor
5337 zfs_ioc_events_seek(zfs_cmd_t
*zc
)
5343 error
= zfs_zevent_fd_hold(zc
->zc_cleanup_fd
, &minor
, &ze
);
5347 error
= zfs_zevent_seek(ze
, zc
->zc_guid
);
5348 zfs_zevent_fd_rele(zc
->zc_cleanup_fd
);
5355 * zc_name name of new filesystem or snapshot
5356 * zc_value full name of old snapshot
5359 * zc_cookie space in bytes
5360 * zc_objset_type compressed space in bytes
5361 * zc_perm_action uncompressed space in bytes
5364 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5368 dsl_dataset_t
*new, *old
;
5370 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5373 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5375 dsl_pool_rele(dp
, FTAG
);
5378 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5380 dsl_dataset_rele(new, FTAG
);
5381 dsl_pool_rele(dp
, FTAG
);
5385 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5386 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5387 dsl_dataset_rele(old
, FTAG
);
5388 dsl_dataset_rele(new, FTAG
);
5389 dsl_pool_rele(dp
, FTAG
);
5395 * "firstsnap" -> snapshot name
5399 * "used" -> space in bytes
5400 * "compressed" -> compressed space in bytes
5401 * "uncompressed" -> uncompressed space in bytes
5405 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5409 dsl_dataset_t
*new, *old
;
5411 uint64_t used
, comp
, uncomp
;
5413 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5414 return (SET_ERROR(EINVAL
));
5416 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5420 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5421 if (error
== 0 && !new->ds_is_snapshot
) {
5422 dsl_dataset_rele(new, FTAG
);
5423 error
= SET_ERROR(EINVAL
);
5426 dsl_pool_rele(dp
, FTAG
);
5429 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5430 if (error
== 0 && !old
->ds_is_snapshot
) {
5431 dsl_dataset_rele(old
, FTAG
);
5432 error
= SET_ERROR(EINVAL
);
5435 dsl_dataset_rele(new, FTAG
);
5436 dsl_pool_rele(dp
, FTAG
);
5440 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5441 dsl_dataset_rele(old
, FTAG
);
5442 dsl_dataset_rele(new, FTAG
);
5443 dsl_pool_rele(dp
, FTAG
);
5444 fnvlist_add_uint64(outnvl
, "used", used
);
5445 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5446 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5452 * "fd" -> file descriptor to write stream to (int32)
5453 * (optional) "fromsnap" -> full snap name to send an incremental from
5454 * (optional) "largeblockok" -> (value ignored)
5455 * indicates that blocks > 128KB are permitted
5456 * (optional) "embedok" -> (value ignored)
5457 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5458 * (optional) "compressok" -> (value ignored)
5459 * presence indicates compressed DRR_WRITE records are permitted
5460 * (optional) "resume_object" and "resume_offset" -> (uint64)
5461 * if present, resume send stream from specified object and offset.
5468 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5472 char *fromname
= NULL
;
5475 boolean_t largeblockok
;
5477 boolean_t compressok
;
5478 uint64_t resumeobj
= 0;
5479 uint64_t resumeoff
= 0;
5481 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5483 return (SET_ERROR(EINVAL
));
5485 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5487 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5488 embedok
= nvlist_exists(innvl
, "embedok");
5489 compressok
= nvlist_exists(innvl
, "compressok");
5491 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5492 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5494 if ((fp
= getf(fd
)) == NULL
)
5495 return (SET_ERROR(EBADF
));
5498 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5499 fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5501 if (VOP_SEEK(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5509 * Determine approximately how large a zfs send stream will be -- the number
5510 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5513 * (optional) "from" -> full snap or bookmark name to send an incremental
5515 * (optional) "largeblockok" -> (value ignored)
5516 * indicates that blocks > 128KB are permitted
5517 * (optional) "embedok" -> (value ignored)
5518 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5519 * (optional) "compressok" -> (value ignored)
5520 * presence indicates compressed DRR_WRITE records are permitted
5524 * "space" -> bytes of space (uint64)
5528 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5531 dsl_dataset_t
*tosnap
;
5534 /* LINTED E_FUNC_SET_NOT_USED */
5535 boolean_t largeblockok
;
5536 /* LINTED E_FUNC_SET_NOT_USED */
5538 boolean_t compressok
;
5541 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5545 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5547 dsl_pool_rele(dp
, FTAG
);
5551 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5552 embedok
= nvlist_exists(innvl
, "embedok");
5553 compressok
= nvlist_exists(innvl
, "compressok");
5555 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5557 if (strchr(fromname
, '@') != NULL
) {
5559 * If from is a snapshot, hold it and use the more
5560 * efficient dmu_send_estimate to estimate send space
5561 * size using deadlists.
5563 dsl_dataset_t
*fromsnap
;
5564 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5567 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
5569 dsl_dataset_rele(fromsnap
, FTAG
);
5570 } else if (strchr(fromname
, '#') != NULL
) {
5572 * If from is a bookmark, fetch the creation TXG of the
5573 * snapshot it was created from and use that to find
5574 * blocks that were born after it.
5576 zfs_bookmark_phys_t frombm
;
5578 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
5582 error
= dmu_send_estimate_from_txg(tosnap
,
5583 frombm
.zbm_creation_txg
, compressok
, &space
);
5586 * from is not properly formatted as a snapshot or
5589 error
= SET_ERROR(EINVAL
);
5593 // If estimating the size of a full send, use dmu_send_estimate
5594 error
= dmu_send_estimate(tosnap
, NULL
, compressok
, &space
);
5597 fnvlist_add_uint64(outnvl
, "space", space
);
5600 dsl_dataset_rele(tosnap
, FTAG
);
5601 dsl_pool_rele(dp
, FTAG
);
5605 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5608 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5609 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5610 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5612 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5614 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5615 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5616 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5617 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5619 vec
->zvec_legacy_func
= func
;
5620 vec
->zvec_secpolicy
= secpolicy
;
5621 vec
->zvec_namecheck
= namecheck
;
5622 vec
->zvec_allow_log
= log_history
;
5623 vec
->zvec_pool_check
= pool_check
;
5627 * See the block comment at the beginning of this file for details on
5628 * each argument to this function.
5631 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5632 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5633 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5634 boolean_t allow_log
)
5636 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5638 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5639 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5640 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5641 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5643 /* if we are logging, the name must be valid */
5644 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5646 vec
->zvec_name
= name
;
5647 vec
->zvec_func
= func
;
5648 vec
->zvec_secpolicy
= secpolicy
;
5649 vec
->zvec_namecheck
= namecheck
;
5650 vec
->zvec_pool_check
= pool_check
;
5651 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5652 vec
->zvec_allow_log
= allow_log
;
5656 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5657 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5658 zfs_ioc_poolcheck_t pool_check
)
5660 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5661 POOL_NAME
, log_history
, pool_check
);
5665 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5666 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5668 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5669 DATASET_NAME
, B_FALSE
, pool_check
);
5673 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5675 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5676 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5680 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5681 zfs_secpolicy_func_t
*secpolicy
)
5683 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5684 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5688 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5689 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5691 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5692 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5696 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5698 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5699 zfs_secpolicy_read
);
5703 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5704 zfs_secpolicy_func_t
*secpolicy
)
5706 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5707 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5711 zfs_ioctl_init(void)
5713 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5714 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5715 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5717 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5718 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5719 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5721 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5722 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5723 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5725 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5726 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5727 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5729 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5730 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5731 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5733 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5734 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5735 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5737 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5738 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5739 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5741 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5742 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5743 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5745 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
5746 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
5747 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5748 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
5749 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
5750 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5752 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
5753 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
5754 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5756 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
5757 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
5758 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
5760 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
5761 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
5762 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5764 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
5765 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
5766 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5768 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
5769 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
5771 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5773 zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW
,
5774 zfs_ioc_recv_new
, zfs_secpolicy_recv_new
, DATASET_NAME
,
5775 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5777 /* IOCTLS that use the legacy function signature */
5779 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5780 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5782 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5783 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5784 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5786 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5787 zfs_ioc_pool_upgrade
);
5788 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5790 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5791 zfs_ioc_vdev_remove
);
5792 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5793 zfs_ioc_vdev_set_state
);
5794 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5795 zfs_ioc_vdev_attach
);
5796 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5797 zfs_ioc_vdev_detach
);
5798 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5799 zfs_ioc_vdev_setpath
);
5800 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5801 zfs_ioc_vdev_setfru
);
5802 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5803 zfs_ioc_pool_set_props
);
5804 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5805 zfs_ioc_vdev_split
);
5806 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5807 zfs_ioc_pool_reguid
);
5809 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5810 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5811 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5812 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5813 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5814 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5815 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5816 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5817 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5818 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5821 * pool destroy, and export don't log the history as part of
5822 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5823 * does the logging of those commands.
5825 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5826 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5827 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5828 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5830 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5831 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5832 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5833 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5835 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5836 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5837 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5838 zfs_ioc_dsobj_to_dsname
,
5839 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5840 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5841 zfs_ioc_pool_get_history
,
5842 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5844 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5845 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5847 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5848 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5849 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5850 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5852 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5853 zfs_ioc_space_written
);
5854 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5855 zfs_ioc_objset_recvd_props
);
5856 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5858 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5860 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5861 zfs_ioc_objset_stats
);
5862 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5863 zfs_ioc_objset_zplprops
);
5864 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5865 zfs_ioc_dataset_list_next
);
5866 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5867 zfs_ioc_snapshot_list_next
);
5868 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5869 zfs_ioc_send_progress
);
5871 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5872 zfs_ioc_diff
, zfs_secpolicy_diff
);
5873 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5874 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5875 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5876 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5877 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5878 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5879 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5880 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5881 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5882 zfs_ioc_send
, zfs_secpolicy_send
);
5884 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5885 zfs_secpolicy_none
);
5886 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5887 zfs_secpolicy_destroy
);
5888 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5889 zfs_secpolicy_rename
);
5890 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5891 zfs_secpolicy_recv
);
5892 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5893 zfs_secpolicy_promote
);
5894 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5895 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5896 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5897 zfs_secpolicy_set_fsacl
);
5899 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5900 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5901 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5902 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5903 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5904 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5905 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5906 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5907 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5908 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5913 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT
, zfs_ioc_events_next
,
5914 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5915 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR
, zfs_ioc_events_clear
,
5916 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5917 zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_SEEK
, zfs_ioc_events_seek
,
5918 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5922 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5923 zfs_ioc_poolcheck_t check
)
5928 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5930 if (check
& POOL_CHECK_NONE
)
5933 error
= spa_open(name
, &spa
, FTAG
);
5935 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5936 error
= SET_ERROR(EAGAIN
);
5937 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5938 error
= SET_ERROR(EROFS
);
5939 spa_close(spa
, FTAG
);
5945 zfsdev_get_state_impl(minor_t minor
, enum zfsdev_state_type which
)
5949 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
5950 if (zs
->zs_minor
== minor
) {
5954 return (zs
->zs_onexit
);
5956 return (zs
->zs_zevent
);
5967 zfsdev_get_state(minor_t minor
, enum zfsdev_state_type which
)
5971 ptr
= zfsdev_get_state_impl(minor
, which
);
5977 zfsdev_getminor(struct file
*filp
, minor_t
*minorp
)
5979 zfsdev_state_t
*zs
, *fpd
;
5981 ASSERT(filp
!= NULL
);
5982 ASSERT(!MUTEX_HELD(&zfsdev_state_lock
));
5984 fpd
= filp
->private_data
;
5988 mutex_enter(&zfsdev_state_lock
);
5990 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
5992 if (zs
->zs_minor
== -1)
5996 *minorp
= fpd
->zs_minor
;
5997 mutex_exit(&zfsdev_state_lock
);
6002 mutex_exit(&zfsdev_state_lock
);
6008 * Find a free minor number. The zfsdev_state_list is expected to
6009 * be short since it is only a list of currently open file handles.
6012 zfsdev_minor_alloc(void)
6014 static minor_t last_minor
= 0;
6017 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6019 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
6020 if (m
> ZFSDEV_MAX_MINOR
)
6022 if (zfsdev_get_state_impl(m
, ZST_ALL
) == NULL
) {
6032 zfsdev_state_init(struct file
*filp
)
6034 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6036 boolean_t newzs
= B_FALSE
;
6038 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6040 minor
= zfsdev_minor_alloc();
6042 return (SET_ERROR(ENXIO
));
6044 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6045 if (zs
->zs_minor
== -1)
6051 zs
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6056 filp
->private_data
= zs
;
6058 zfs_onexit_init((zfs_onexit_t
**)&zs
->zs_onexit
);
6059 zfs_zevent_init((zfs_zevent_t
**)&zs
->zs_zevent
);
6063 * In order to provide for lock-free concurrent read access
6064 * to the minor list in zfsdev_get_state_impl(), new entries
6065 * must be completely written before linking them into the
6066 * list whereas existing entries are already linked; the last
6067 * operation must be updating zs_minor (from -1 to the new
6071 zs
->zs_minor
= minor
;
6073 zsprev
->zs_next
= zs
;
6076 zs
->zs_minor
= minor
;
6083 zfsdev_state_destroy(struct file
*filp
)
6087 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
6088 ASSERT(filp
->private_data
!= NULL
);
6090 zs
= filp
->private_data
;
6092 zfs_onexit_destroy(zs
->zs_onexit
);
6093 zfs_zevent_destroy(zs
->zs_zevent
);
6099 zfsdev_open(struct inode
*ino
, struct file
*filp
)
6103 mutex_enter(&zfsdev_state_lock
);
6104 error
= zfsdev_state_init(filp
);
6105 mutex_exit(&zfsdev_state_lock
);
6111 zfsdev_release(struct inode
*ino
, struct file
*filp
)
6115 mutex_enter(&zfsdev_state_lock
);
6116 error
= zfsdev_state_destroy(filp
);
6117 mutex_exit(&zfsdev_state_lock
);
6123 zfsdev_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6127 int error
, rc
, flag
= 0;
6128 const zfs_ioc_vec_t
*vec
;
6129 char *saved_poolname
= NULL
;
6130 nvlist_t
*innvl
= NULL
;
6131 fstrans_cookie_t cookie
;
6133 vecnum
= cmd
- ZFS_IOC_FIRST
;
6134 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6135 return (-SET_ERROR(EINVAL
));
6136 vec
= &zfs_ioc_vec
[vecnum
];
6139 * The registered ioctl list may be sparse, verify that either
6140 * a normal or legacy handler are registered.
6142 if (vec
->zvec_func
== NULL
&& vec
->zvec_legacy_func
== NULL
)
6143 return (-SET_ERROR(EINVAL
));
6145 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6147 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6149 error
= SET_ERROR(EFAULT
);
6153 zc
->zc_iflags
= flag
& FKIOCTL
;
6154 if (zc
->zc_nvlist_src_size
> MAX_NVLIST_SRC_SIZE
) {
6156 * Make sure the user doesn't pass in an insane value for
6157 * zc_nvlist_src_size. We have to check, since we will end
6158 * up allocating that much memory inside of get_nvlist(). This
6159 * prevents a nefarious user from allocating tons of kernel
6162 * Also, we return EINVAL instead of ENOMEM here. The reason
6163 * being that returning ENOMEM from an ioctl() has a special
6164 * connotation; that the user's size value is too small and
6165 * needs to be expanded to hold the nvlist. See
6166 * zcmd_expand_dst_nvlist() for details.
6168 error
= SET_ERROR(EINVAL
); /* User's size too big */
6170 } else if (zc
->zc_nvlist_src_size
!= 0) {
6171 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6172 zc
->zc_iflags
, &innvl
);
6178 * Ensure that all pool/dataset names are valid before we pass down to
6181 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6182 switch (vec
->zvec_namecheck
) {
6184 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6185 error
= SET_ERROR(EINVAL
);
6187 error
= pool_status_check(zc
->zc_name
,
6188 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6192 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6193 error
= SET_ERROR(EINVAL
);
6195 error
= pool_status_check(zc
->zc_name
,
6196 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6204 if (error
== 0 && !(flag
& FKIOCTL
)) {
6205 cookie
= spl_fstrans_mark();
6206 error
= vec
->zvec_secpolicy(zc
, innvl
, CRED());
6207 spl_fstrans_unmark(cookie
);
6213 /* legacy ioctls can modify zc_name */
6214 saved_poolname
= strdup(zc
->zc_name
);
6215 if (saved_poolname
== NULL
) {
6216 error
= SET_ERROR(ENOMEM
);
6219 saved_poolname
[strcspn(saved_poolname
, "/@#")] = '\0';
6222 if (vec
->zvec_func
!= NULL
) {
6226 nvlist_t
*lognv
= NULL
;
6228 ASSERT(vec
->zvec_legacy_func
== NULL
);
6231 * Add the innvl to the lognv before calling the func,
6232 * in case the func changes the innvl.
6234 if (vec
->zvec_allow_log
) {
6235 lognv
= fnvlist_alloc();
6236 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6238 if (!nvlist_empty(innvl
)) {
6239 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6244 outnvl
= fnvlist_alloc();
6245 cookie
= spl_fstrans_mark();
6246 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6247 spl_fstrans_unmark(cookie
);
6249 if (error
== 0 && vec
->zvec_allow_log
&&
6250 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6251 if (!nvlist_empty(outnvl
)) {
6252 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6255 (void) spa_history_log_nvl(spa
, lognv
);
6256 spa_close(spa
, FTAG
);
6258 fnvlist_free(lognv
);
6260 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6262 if (vec
->zvec_smush_outnvlist
) {
6263 smusherror
= nvlist_smush(outnvl
,
6264 zc
->zc_nvlist_dst_size
);
6266 if (smusherror
== 0)
6267 puterror
= put_nvlist(zc
, outnvl
);
6273 nvlist_free(outnvl
);
6275 cookie
= spl_fstrans_mark();
6276 error
= vec
->zvec_legacy_func(zc
);
6277 spl_fstrans_unmark(cookie
);
6282 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6283 if (error
== 0 && rc
!= 0)
6284 error
= SET_ERROR(EFAULT
);
6285 if (error
== 0 && vec
->zvec_allow_log
) {
6286 char *s
= tsd_get(zfs_allow_log_key
);
6289 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6291 if (saved_poolname
!= NULL
)
6292 strfree(saved_poolname
);
6295 kmem_free(zc
, sizeof (zfs_cmd_t
));
6299 #ifdef CONFIG_COMPAT
6301 zfsdev_compat_ioctl(struct file
*filp
, unsigned cmd
, unsigned long arg
)
6303 return (zfsdev_ioctl(filp
, cmd
, arg
));
6306 #define zfsdev_compat_ioctl NULL
6309 static const struct file_operations zfsdev_fops
= {
6310 .open
= zfsdev_open
,
6311 .release
= zfsdev_release
,
6312 .unlocked_ioctl
= zfsdev_ioctl
,
6313 .compat_ioctl
= zfsdev_compat_ioctl
,
6314 .owner
= THIS_MODULE
,
6317 static struct miscdevice zfs_misc
= {
6318 .minor
= MISC_DYNAMIC_MINOR
,
6320 .fops
= &zfsdev_fops
,
6328 mutex_init(&zfsdev_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6329 zfsdev_state_list
= kmem_zalloc(sizeof (zfsdev_state_t
), KM_SLEEP
);
6330 zfsdev_state_list
->zs_minor
= -1;
6332 error
= misc_register(&zfs_misc
);
6334 printk(KERN_INFO
"ZFS: misc_register() failed %d\n", error
);
6344 zfsdev_state_t
*zs
, *zsprev
= NULL
;
6346 misc_deregister(&zfs_misc
);
6347 mutex_destroy(&zfsdev_state_lock
);
6349 for (zs
= zfsdev_state_list
; zs
!= NULL
; zs
= zs
->zs_next
) {
6351 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
6355 kmem_free(zsprev
, sizeof (zfsdev_state_t
));
6359 zfs_allow_log_destroy(void *arg
)
6361 char *poolname
= arg
;
6363 if (poolname
!= NULL
)
6368 #define ZFS_DEBUG_STR " (DEBUG mode)"
6370 #define ZFS_DEBUG_STR ""
6378 error
= -vn_set_pwd("/");
6381 "ZFS: Warning unable to set pwd to '/': %d\n", error
);
6385 if ((error
= -zvol_init()) != 0)
6388 spa_init(FREAD
| FWRITE
);
6393 if ((error
= zfs_attach()) != 0)
6396 tsd_create(&zfs_fsyncer_key
, NULL
);
6397 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
6398 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
6400 printk(KERN_NOTICE
"ZFS: Loaded module v%s-%s%s, "
6401 "ZFS pool version %s, ZFS filesystem version %s\n",
6402 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
,
6403 SPA_VERSION_STRING
, ZPL_VERSION_STRING
);
6404 #ifndef CONFIG_FS_POSIX_ACL
6405 printk(KERN_NOTICE
"ZFS: Posix ACLs disabled by kernel\n");
6406 #endif /* CONFIG_FS_POSIX_ACL */
6414 printk(KERN_NOTICE
"ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
6415 ", rc = %d\n", ZFS_META_VERSION
, ZFS_META_RELEASE
,
6416 ZFS_DEBUG_STR
, error
);
6429 tsd_destroy(&zfs_fsyncer_key
);
6430 tsd_destroy(&rrw_tsd_key
);
6431 tsd_destroy(&zfs_allow_log_key
);
6433 printk(KERN_NOTICE
"ZFS: Unloaded module v%s-%s%s\n",
6434 ZFS_META_VERSION
, ZFS_META_RELEASE
, ZFS_DEBUG_STR
);
6441 MODULE_DESCRIPTION("ZFS");
6442 MODULE_AUTHOR(ZFS_META_AUTHOR
);
6443 MODULE_LICENSE(ZFS_META_LICENSE
);
6444 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);
6445 #endif /* HAVE_SPL */