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 * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
25 * Portions Copyright 2011 Martin Matuska
26 * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
27 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
29 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
30 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
31 * Copyright (c) 2013 Steven Hartland. All rights reserved.
32 * Copyright (c) 2014 Integros [integros.com]
33 * Copyright 2016 Toomas Soome <tsoome@me.com>
34 * Copyright 2017 RackTop Systems.
40 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
41 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
43 * There are two ways that we handle ioctls: the legacy way where almost
44 * all of the logic is in the ioctl callback, and the new way where most
45 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
47 * Non-legacy ioctls should be registered by calling
48 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
49 * from userland by lzc_ioctl().
51 * The registration arguments are as follows:
54 * The name of the ioctl. This is used for history logging. If the
55 * ioctl returns successfully (the callback returns 0), and allow_log
56 * is true, then a history log entry will be recorded with the input &
57 * output nvlists. The log entry can be printed with "zpool history -i".
60 * The ioctl request number, which userland will pass to ioctl(2).
61 * The ioctl numbers can change from release to release, because
62 * the caller (libzfs) must be matched to the kernel.
64 * zfs_secpolicy_func_t *secpolicy
65 * This function will be called before the zfs_ioc_func_t, to
66 * determine if this operation is permitted. It should return EPERM
67 * on failure, and 0 on success. Checks include determining if the
68 * dataset is visible in this zone, and if the user has either all
69 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
70 * to do this operation on this dataset with "zfs allow".
72 * zfs_ioc_namecheck_t namecheck
73 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
74 * name, a dataset name, or nothing. If the name is not well-formed,
75 * the ioctl will fail and the callback will not be called.
76 * Therefore, the callback can assume that the name is well-formed
77 * (e.g. is null-terminated, doesn't have more than one '@' character,
78 * doesn't have invalid characters).
80 * zfs_ioc_poolcheck_t pool_check
81 * This specifies requirements on the pool state. If the pool does
82 * not meet them (is suspended or is readonly), the ioctl will fail
83 * and the callback will not be called. If any checks are specified
84 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
85 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
86 * POOL_CHECK_READONLY).
88 * boolean_t smush_outnvlist
89 * If smush_outnvlist is true, then the output is presumed to be a
90 * list of errors, and it will be "smushed" down to fit into the
91 * caller's buffer, by removing some entries and replacing them with a
92 * single "N_MORE_ERRORS" entry indicating how many were removed. See
93 * nvlist_smush() for details. If smush_outnvlist is false, and the
94 * outnvlist does not fit into the userland-provided buffer, then the
95 * ioctl will fail with ENOMEM.
97 * zfs_ioc_func_t *func
98 * The callback function that will perform the operation.
100 * The callback should return 0 on success, or an error number on
101 * failure. If the function fails, the userland ioctl will return -1,
102 * and errno will be set to the callback's return value. The callback
103 * will be called with the following arguments:
106 * The name of the pool or dataset to operate on, from
107 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
108 * expected type (pool, dataset, or none).
111 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
112 * NULL if no input nvlist was provided. Changes to this nvlist are
113 * ignored. If the input nvlist could not be deserialized, the
114 * ioctl will fail and the callback will not be called.
117 * The output nvlist, initially empty. The callback can fill it in,
118 * and it will be returned to userland by serializing it into
119 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
120 * fails (e.g. because the caller didn't supply a large enough
121 * buffer), then the overall ioctl will fail. See the
122 * 'smush_nvlist' argument above for additional behaviors.
124 * There are two typical uses of the output nvlist:
125 * - To return state, e.g. property values. In this case,
126 * smush_outnvlist should be false. If the buffer was not large
127 * enough, the caller will reallocate a larger buffer and try
130 * - To return multiple errors from an ioctl which makes on-disk
131 * changes. In this case, smush_outnvlist should be true.
132 * Ioctls which make on-disk modifications should generally not
133 * use the outnvl if they succeed, because the caller can not
134 * distinguish between the operation failing, and
135 * deserialization failing.
138 #include <sys/types.h>
139 #include <sys/param.h>
140 #include <sys/errno.h>
143 #include <sys/modctl.h>
144 #include <sys/open.h>
145 #include <sys/file.h>
146 #include <sys/kmem.h>
147 #include <sys/conf.h>
148 #include <sys/cmn_err.h>
149 #include <sys/stat.h>
150 #include <sys/zfs_ioctl.h>
151 #include <sys/zfs_vfsops.h>
152 #include <sys/zfs_znode.h>
155 #include <sys/spa_impl.h>
156 #include <sys/vdev.h>
157 #include <sys/priv_impl.h>
159 #include <sys/dsl_dir.h>
160 #include <sys/dsl_dataset.h>
161 #include <sys/dsl_prop.h>
162 #include <sys/dsl_deleg.h>
163 #include <sys/dmu_objset.h>
164 #include <sys/dmu_impl.h>
165 #include <sys/dmu_tx.h>
167 #include <sys/sunddi.h>
168 #include <sys/sunldi.h>
169 #include <sys/policy.h>
170 #include <sys/zone.h>
171 #include <sys/nvpair.h>
172 #include <sys/pathname.h>
173 #include <sys/mount.h>
175 #include <sys/fs/zfs.h>
176 #include <sys/zfs_ctldir.h>
177 #include <sys/zfs_dir.h>
178 #include <sys/zfs_onexit.h>
179 #include <sys/zvol.h>
180 #include <sys/dsl_scan.h>
181 #include <sharefs/share.h>
182 #include <sys/dmu_objset.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>
189 #include <sys/zio_checksum.h>
191 #include "zfs_namecheck.h"
192 #include "zfs_prop.h"
193 #include "zfs_deleg.h"
194 #include "zfs_comutil.h"
199 extern struct modlfs zfs_modlfs
;
201 extern void zfs_init(void);
202 extern void zfs_fini(void);
204 ldi_ident_t zfs_li
= NULL
;
207 uint_t zfs_fsyncer_key
;
208 extern uint_t rrw_tsd_key
;
209 static uint_t zfs_allow_log_key
;
211 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
212 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
213 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
219 } zfs_ioc_namecheck_t
;
222 POOL_CHECK_NONE
= 1 << 0,
223 POOL_CHECK_SUSPENDED
= 1 << 1,
224 POOL_CHECK_READONLY
= 1 << 2,
225 } zfs_ioc_poolcheck_t
;
227 typedef struct zfs_ioc_vec
{
228 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
229 zfs_ioc_func_t
*zvec_func
;
230 zfs_secpolicy_func_t
*zvec_secpolicy
;
231 zfs_ioc_namecheck_t zvec_namecheck
;
232 boolean_t zvec_allow_log
;
233 zfs_ioc_poolcheck_t zvec_pool_check
;
234 boolean_t zvec_smush_outnvlist
;
235 const char *zvec_name
;
238 /* This array is indexed by zfs_userquota_prop_t */
239 static const char *userquota_perms
[] = {
240 ZFS_DELEG_PERM_USERUSED
,
241 ZFS_DELEG_PERM_USERQUOTA
,
242 ZFS_DELEG_PERM_GROUPUSED
,
243 ZFS_DELEG_PERM_GROUPQUOTA
,
246 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
247 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
249 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
251 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
253 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
254 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
256 static int zfs_prop_activate_feature(spa_t
*spa
, spa_feature_t feature
);
258 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
260 __dprintf(const char *file
, const char *func
, int line
, const char *fmt
, ...)
267 * Get rid of annoying "../common/" prefix to filename.
269 newfile
= strrchr(file
, '/');
270 if (newfile
!= NULL
) {
271 newfile
= newfile
+ 1; /* Get rid of leading / */
277 (void) vsnprintf(buf
, sizeof (buf
), fmt
, adx
);
281 * To get this data, use the zfs-dprintf probe as so:
282 * dtrace -q -n 'zfs-dprintf \
283 * /stringof(arg0) == "dbuf.c"/ \
284 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
286 * arg1 = function name
290 DTRACE_PROBE4(zfs__dprintf
,
291 char *, newfile
, char *, func
, int, line
, char *, buf
);
295 history_str_free(char *buf
)
297 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
301 history_str_get(zfs_cmd_t
*zc
)
305 if (zc
->zc_history
== (uintptr_t)NULL
)
308 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
309 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
310 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
311 history_str_free(buf
);
315 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
321 * Check to see if the named dataset is currently defined as bootable
324 zfs_is_bootfs(const char *name
)
328 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
330 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
331 dmu_objset_rele(os
, FTAG
);
338 * Return non-zero if the spa version is less than requested version.
341 zfs_earlier_version(const char *name
, int version
)
345 if (spa_open(name
, &spa
, FTAG
) == 0) {
346 if (spa_version(spa
) < version
) {
347 spa_close(spa
, FTAG
);
350 spa_close(spa
, FTAG
);
356 * Return TRUE if the ZPL version is less than requested version.
359 zpl_earlier_version(const char *name
, int version
)
362 boolean_t rc
= B_TRUE
;
364 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
367 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
368 dmu_objset_rele(os
, FTAG
);
371 /* XXX reading from non-owned objset */
372 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
373 rc
= zplversion
< version
;
374 dmu_objset_rele(os
, FTAG
);
380 zfs_log_history(zfs_cmd_t
*zc
)
385 if ((buf
= history_str_get(zc
)) == NULL
)
388 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
389 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
390 (void) spa_history_log(spa
, buf
);
391 spa_close(spa
, FTAG
);
393 history_str_free(buf
);
397 * Policy for top-level read operations (list pools). Requires no privileges,
398 * and can be used in the local zone, as there is no associated dataset.
402 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
408 * Policy for dataset read operations (list children, get statistics). Requires
409 * no privileges, but must be visible in the local zone.
413 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
415 if (INGLOBALZONE(curproc
) ||
416 zone_dataset_visible(zc
->zc_name
, NULL
))
419 return (SET_ERROR(ENOENT
));
423 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
428 * The dataset must be visible by this zone -- check this first
429 * so they don't see EPERM on something they shouldn't know about.
431 if (!INGLOBALZONE(curproc
) &&
432 !zone_dataset_visible(dataset
, &writable
))
433 return (SET_ERROR(ENOENT
));
435 if (INGLOBALZONE(curproc
)) {
437 * If the fs is zoned, only root can access it from the
440 if (secpolicy_zfs(cr
) && zoned
)
441 return (SET_ERROR(EPERM
));
444 * If we are in a local zone, the 'zoned' property must be set.
447 return (SET_ERROR(EPERM
));
449 /* must be writable by this zone */
451 return (SET_ERROR(EPERM
));
457 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
461 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
462 return (SET_ERROR(ENOENT
));
464 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
468 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
472 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
473 return (SET_ERROR(ENOENT
));
475 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
479 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
480 const char *perm
, cred_t
*cr
)
484 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
486 error
= secpolicy_zfs(cr
);
488 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
494 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
501 * First do a quick check for root in the global zone, which
502 * is allowed to do all write_perms. This ensures that zfs_ioc_*
503 * will get to handle nonexistent datasets.
505 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
508 error
= dsl_pool_hold(name
, FTAG
, &dp
);
512 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
514 dsl_pool_rele(dp
, FTAG
);
518 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
520 dsl_dataset_rele(ds
, FTAG
);
521 dsl_pool_rele(dp
, FTAG
);
526 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
532 * Check permissions for special properties.
537 * Disallow setting of 'zoned' from within a local zone.
539 if (!INGLOBALZONE(curproc
))
540 return (SET_ERROR(EPERM
));
544 case ZFS_PROP_FILESYSTEM_LIMIT
:
545 case ZFS_PROP_SNAPSHOT_LIMIT
:
546 if (!INGLOBALZONE(curproc
)) {
548 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
550 * Unprivileged users are allowed to modify the
551 * limit on things *under* (ie. contained by)
552 * the thing they own.
554 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
556 return (SET_ERROR(EPERM
));
557 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
558 return (SET_ERROR(EPERM
));
563 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
568 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
572 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
577 * permission to set permissions will be evaluated later in
578 * dsl_deleg_can_allow()
585 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
587 return (zfs_secpolicy_write_perms(zc
->zc_name
,
588 ZFS_DELEG_PERM_ROLLBACK
, cr
));
593 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
601 * Generate the current snapshot name from the given objsetid, then
602 * use that name for the secpolicy/zone checks.
604 cp
= strchr(zc
->zc_name
, '@');
606 return (SET_ERROR(EINVAL
));
607 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
611 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
613 dsl_pool_rele(dp
, FTAG
);
617 dsl_dataset_name(ds
, zc
->zc_name
);
619 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
620 ZFS_DELEG_PERM_SEND
, cr
);
621 dsl_dataset_rele(ds
, FTAG
);
622 dsl_pool_rele(dp
, FTAG
);
629 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
631 return (zfs_secpolicy_write_perms(zc
->zc_name
,
632 ZFS_DELEG_PERM_SEND
, cr
));
637 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
642 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
643 NO_FOLLOW
, NULL
, &vp
)) != 0)
646 /* Now make sure mntpnt and dataset are ZFS */
648 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
649 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
650 zc
->zc_name
) != 0)) {
652 return (SET_ERROR(EPERM
));
656 return (dsl_deleg_access(zc
->zc_name
,
657 ZFS_DELEG_PERM_SHARE
, cr
));
661 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
663 if (!INGLOBALZONE(curproc
))
664 return (SET_ERROR(EPERM
));
666 if (secpolicy_nfs(cr
) == 0) {
669 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
674 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
676 if (!INGLOBALZONE(curproc
))
677 return (SET_ERROR(EPERM
));
679 if (secpolicy_smb(cr
) == 0) {
682 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
687 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
692 * Remove the @bla or /bla from the end of the name to get the parent.
694 (void) strncpy(parent
, datasetname
, parentsize
);
695 cp
= strrchr(parent
, '@');
699 cp
= strrchr(parent
, '/');
701 return (SET_ERROR(ENOENT
));
709 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
713 if ((error
= zfs_secpolicy_write_perms(name
,
714 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
717 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
722 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
724 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
728 * Destroying snapshots with delegated permissions requires
729 * descendant mount and destroy permissions.
733 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
736 nvpair_t
*pair
, *nextpair
;
739 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
740 return (SET_ERROR(EINVAL
));
741 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
743 nextpair
= nvlist_next_nvpair(snaps
, pair
);
744 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
745 if (error
== ENOENT
) {
747 * Ignore any snapshots that don't exist (we consider
748 * them "already destroyed"). Remove the name from the
749 * nvl here in case the snapshot is created between
750 * now and when we try to destroy it (in which case
751 * we don't want to destroy it since we haven't
752 * checked for permission).
754 fnvlist_remove_nvpair(snaps
, pair
);
765 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
767 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
770 if ((error
= zfs_secpolicy_write_perms(from
,
771 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
774 if ((error
= zfs_secpolicy_write_perms(from
,
775 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
778 if ((error
= zfs_get_parent(to
, parentname
,
779 sizeof (parentname
))) != 0)
782 if ((error
= zfs_secpolicy_write_perms(parentname
,
783 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
786 if ((error
= zfs_secpolicy_write_perms(parentname
,
787 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
795 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
797 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
802 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
805 dsl_dataset_t
*clone
;
808 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
809 ZFS_DELEG_PERM_PROMOTE
, cr
);
813 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
817 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
820 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
821 dsl_dataset_t
*origin
= NULL
;
825 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
826 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
828 dsl_dataset_rele(clone
, FTAG
);
829 dsl_pool_rele(dp
, FTAG
);
833 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
834 ZFS_DELEG_PERM_MOUNT
, cr
);
836 dsl_dataset_name(origin
, parentname
);
838 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
839 ZFS_DELEG_PERM_PROMOTE
, cr
);
841 dsl_dataset_rele(clone
, FTAG
);
842 dsl_dataset_rele(origin
, FTAG
);
844 dsl_pool_rele(dp
, FTAG
);
850 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
854 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
855 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
858 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
859 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
862 return (zfs_secpolicy_write_perms(zc
->zc_name
,
863 ZFS_DELEG_PERM_CREATE
, cr
));
867 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
869 return (zfs_secpolicy_write_perms(name
,
870 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
874 * Check for permission to create each snapshot in the nvlist.
878 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
884 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
885 return (SET_ERROR(EINVAL
));
886 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
887 pair
= nvlist_next_nvpair(snaps
, pair
)) {
888 char *name
= nvpair_name(pair
);
889 char *atp
= strchr(name
, '@');
892 error
= SET_ERROR(EINVAL
);
896 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
905 * Check for permission to create each snapshot in the nvlist.
909 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
913 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
914 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
915 char *name
= nvpair_name(pair
);
916 char *hashp
= strchr(name
, '#');
919 error
= SET_ERROR(EINVAL
);
923 error
= zfs_secpolicy_write_perms(name
,
924 ZFS_DELEG_PERM_BOOKMARK
, cr
);
934 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
936 nvpair_t
*pair
, *nextpair
;
939 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
941 char *name
= nvpair_name(pair
);
942 char *hashp
= strchr(name
, '#');
943 nextpair
= nvlist_next_nvpair(innvl
, pair
);
946 error
= SET_ERROR(EINVAL
);
951 error
= zfs_secpolicy_write_perms(name
,
952 ZFS_DELEG_PERM_DESTROY
, cr
);
954 if (error
== ENOENT
) {
956 * Ignore any filesystems that don't exist (we consider
957 * their bookmarks "already destroyed"). Remove
958 * the name from the nvl here in case the filesystem
959 * is created between now and when we try to destroy
960 * the bookmark (in which case we don't want to
961 * destroy it since we haven't checked for permission).
963 fnvlist_remove_nvpair(innvl
, pair
);
975 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
978 * Even root must have a proper TSD so that we know what pool
981 if (tsd_get(zfs_allow_log_key
) == NULL
)
982 return (SET_ERROR(EPERM
));
987 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
989 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
993 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
994 sizeof (parentname
))) != 0)
997 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
998 (error
= zfs_secpolicy_write_perms(origin
,
999 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1002 if ((error
= zfs_secpolicy_write_perms(parentname
,
1003 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1006 return (zfs_secpolicy_write_perms(parentname
,
1007 ZFS_DELEG_PERM_MOUNT
, cr
));
1011 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1012 * SYS_CONFIG privilege, which is not available in a local zone.
1016 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1018 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1019 return (SET_ERROR(EPERM
));
1025 * Policy for object to name lookups.
1029 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1033 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1036 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1041 * Policy for fault injection. Requires all privileges.
1045 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1047 return (secpolicy_zinject(cr
));
1052 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1054 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1056 if (prop
== ZPROP_INVAL
) {
1057 if (!zfs_prop_user(zc
->zc_value
))
1058 return (SET_ERROR(EINVAL
));
1059 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1060 ZFS_DELEG_PERM_USERPROP
, cr
));
1062 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1068 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1070 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1074 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1075 return (SET_ERROR(EINVAL
));
1077 if (zc
->zc_value
[0] == 0) {
1079 * They are asking about a posix uid/gid. If it's
1080 * themself, allow it.
1082 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1083 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
1084 if (zc
->zc_guid
== crgetuid(cr
))
1087 if (groupmember(zc
->zc_guid
, cr
))
1092 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1093 userquota_perms
[zc
->zc_objset_type
], cr
));
1097 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1099 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1103 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1104 return (SET_ERROR(EINVAL
));
1106 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1107 userquota_perms
[zc
->zc_objset_type
], cr
));
1112 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1114 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1120 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1126 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1128 return (SET_ERROR(EINVAL
));
1130 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1131 pair
= nvlist_next_nvpair(holds
, pair
)) {
1132 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1133 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1136 error
= zfs_secpolicy_write_perms(fsname
,
1137 ZFS_DELEG_PERM_HOLD
, cr
);
1146 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1151 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1152 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1153 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1154 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1157 error
= zfs_secpolicy_write_perms(fsname
,
1158 ZFS_DELEG_PERM_RELEASE
, cr
);
1166 * Policy for allowing temporary snapshots to be taken or released
1169 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1172 * A temporary snapshot is the same as a snapshot,
1173 * hold, destroy and release all rolled into one.
1174 * Delegated diff alone is sufficient that we allow this.
1178 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1179 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1182 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1184 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1186 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1188 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1193 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1196 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1200 nvlist_t
*list
= NULL
;
1203 * Read in and unpack the user-supplied nvlist.
1206 return (SET_ERROR(EINVAL
));
1208 packed
= kmem_alloc(size
, KM_SLEEP
);
1210 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1212 kmem_free(packed
, size
);
1213 return (SET_ERROR(EFAULT
));
1216 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1217 kmem_free(packed
, size
);
1221 kmem_free(packed
, size
);
1228 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1229 * Entries will be removed from the end of the nvlist, and one int32 entry
1230 * named "N_MORE_ERRORS" will be added indicating how many entries were
1234 nvlist_smush(nvlist_t
*errors
, size_t max
)
1238 size
= fnvlist_size(errors
);
1241 nvpair_t
*more_errors
;
1245 return (SET_ERROR(ENOMEM
));
1247 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1248 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1251 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1253 fnvlist_remove_nvpair(errors
, pair
);
1255 size
= fnvlist_size(errors
);
1256 } while (size
> max
);
1258 fnvlist_remove_nvpair(errors
, more_errors
);
1259 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1260 ASSERT3U(fnvlist_size(errors
), <=, max
);
1267 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1269 char *packed
= NULL
;
1273 size
= fnvlist_size(nvl
);
1275 if (size
> zc
->zc_nvlist_dst_size
) {
1276 error
= SET_ERROR(ENOMEM
);
1278 packed
= fnvlist_pack(nvl
, &size
);
1279 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1280 size
, zc
->zc_iflags
) != 0)
1281 error
= SET_ERROR(EFAULT
);
1282 fnvlist_pack_free(packed
, size
);
1285 zc
->zc_nvlist_dst_size
= size
;
1286 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1291 getzfsvfs_impl(objset_t
*os
, zfsvfs_t
**zfvp
)
1294 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1295 return (SET_ERROR(EINVAL
));
1298 mutex_enter(&os
->os_user_ptr_lock
);
1299 *zfvp
= dmu_objset_get_user(os
);
1301 VFS_HOLD((*zfvp
)->z_vfs
);
1303 error
= SET_ERROR(ESRCH
);
1305 mutex_exit(&os
->os_user_ptr_lock
);
1310 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1315 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1319 error
= getzfsvfs_impl(os
, zfvp
);
1320 dmu_objset_rele(os
, FTAG
);
1325 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1326 * case its z_vfs will be NULL, and it will be opened as the owner.
1327 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1328 * which prevents all vnode ops from running.
1331 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1335 if (getzfsvfs(name
, zfvp
) != 0)
1336 error
= zfsvfs_create(name
, zfvp
);
1338 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1340 if ((*zfvp
)->z_unmounted
) {
1342 * XXX we could probably try again, since the unmounting
1343 * thread should be just about to disassociate the
1344 * objset from the zfsvfs.
1346 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1347 return (SET_ERROR(EBUSY
));
1354 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1356 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1358 if (zfsvfs
->z_vfs
) {
1359 VFS_RELE(zfsvfs
->z_vfs
);
1361 dmu_objset_disown(zfsvfs
->z_os
, zfsvfs
);
1362 zfsvfs_free(zfsvfs
);
1367 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1370 nvlist_t
*config
, *props
= NULL
;
1371 nvlist_t
*rootprops
= NULL
;
1372 nvlist_t
*zplprops
= NULL
;
1374 if (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1375 zc
->zc_iflags
, &config
))
1378 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1379 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1380 zc
->zc_iflags
, &props
))) {
1381 nvlist_free(config
);
1386 nvlist_t
*nvl
= NULL
;
1387 uint64_t version
= SPA_VERSION
;
1389 (void) nvlist_lookup_uint64(props
,
1390 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1391 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1392 error
= SET_ERROR(EINVAL
);
1393 goto pool_props_bad
;
1395 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1397 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1399 nvlist_free(config
);
1403 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1405 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1406 error
= zfs_fill_zplprops_root(version
, rootprops
,
1409 goto pool_props_bad
;
1412 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1415 * Set the remaining root properties
1417 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1418 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1419 (void) spa_destroy(zc
->zc_name
);
1422 nvlist_free(rootprops
);
1423 nvlist_free(zplprops
);
1424 nvlist_free(config
);
1431 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1434 zfs_log_history(zc
);
1435 error
= spa_destroy(zc
->zc_name
);
1437 zvol_remove_minors(zc
->zc_name
);
1442 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1444 nvlist_t
*config
, *props
= NULL
;
1448 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1449 zc
->zc_iflags
, &config
)) != 0)
1452 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1453 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1454 zc
->zc_iflags
, &props
))) {
1455 nvlist_free(config
);
1459 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1460 guid
!= zc
->zc_guid
)
1461 error
= SET_ERROR(EINVAL
);
1463 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1465 if (zc
->zc_nvlist_dst
!= 0) {
1468 if ((err
= put_nvlist(zc
, config
)) != 0)
1472 nvlist_free(config
);
1480 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1483 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1484 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1486 zfs_log_history(zc
);
1487 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1489 zvol_remove_minors(zc
->zc_name
);
1494 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1499 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1500 return (SET_ERROR(EEXIST
));
1502 error
= put_nvlist(zc
, configs
);
1504 nvlist_free(configs
);
1511 * zc_name name of the pool
1514 * zc_cookie real errno
1515 * zc_nvlist_dst config nvlist
1516 * zc_nvlist_dst_size size of config nvlist
1519 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1525 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1526 sizeof (zc
->zc_value
));
1528 if (config
!= NULL
) {
1529 ret
= put_nvlist(zc
, config
);
1530 nvlist_free(config
);
1533 * The config may be present even if 'error' is non-zero.
1534 * In this case we return success, and preserve the real errno
1537 zc
->zc_cookie
= error
;
1546 * Try to import the given pool, returning pool stats as appropriate so that
1547 * user land knows which devices are available and overall pool health.
1550 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1552 nvlist_t
*tryconfig
, *config
;
1555 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1556 zc
->zc_iflags
, &tryconfig
)) != 0)
1559 config
= spa_tryimport(tryconfig
);
1561 nvlist_free(tryconfig
);
1564 return (SET_ERROR(EINVAL
));
1566 error
= put_nvlist(zc
, config
);
1567 nvlist_free(config
);
1574 * zc_name name of the pool
1575 * zc_cookie scan func (pool_scan_func_t)
1578 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1583 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1586 if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1587 error
= spa_scan_stop(spa
);
1589 error
= spa_scan(spa
, zc
->zc_cookie
);
1591 spa_close(spa
, FTAG
);
1597 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1602 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1605 spa_close(spa
, FTAG
);
1611 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1616 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1619 if (zc
->zc_cookie
< spa_version(spa
) ||
1620 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1621 spa_close(spa
, FTAG
);
1622 return (SET_ERROR(EINVAL
));
1625 spa_upgrade(spa
, zc
->zc_cookie
);
1626 spa_close(spa
, FTAG
);
1632 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1639 if ((size
= zc
->zc_history_len
) == 0)
1640 return (SET_ERROR(EINVAL
));
1642 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1645 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1646 spa_close(spa
, FTAG
);
1647 return (SET_ERROR(ENOTSUP
));
1650 hist_buf
= kmem_alloc(size
, KM_SLEEP
);
1651 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1652 &zc
->zc_history_len
, hist_buf
)) == 0) {
1653 error
= ddi_copyout(hist_buf
,
1654 (void *)(uintptr_t)zc
->zc_history
,
1655 zc
->zc_history_len
, zc
->zc_iflags
);
1658 spa_close(spa
, FTAG
);
1659 kmem_free(hist_buf
, size
);
1664 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1669 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1671 error
= spa_change_guid(spa
);
1672 spa_close(spa
, FTAG
);
1678 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1680 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1685 * zc_name name of filesystem
1686 * zc_obj object to find
1689 * zc_value name of object
1692 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1697 /* XXX reading from objset not owned */
1698 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1700 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1701 dmu_objset_rele(os
, FTAG
);
1702 return (SET_ERROR(EINVAL
));
1704 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1705 sizeof (zc
->zc_value
));
1706 dmu_objset_rele(os
, FTAG
);
1713 * zc_name name of filesystem
1714 * zc_obj object to find
1717 * zc_stat stats on object
1718 * zc_value path to object
1721 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1726 /* XXX reading from objset not owned */
1727 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1729 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1730 dmu_objset_rele(os
, FTAG
);
1731 return (SET_ERROR(EINVAL
));
1733 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1734 sizeof (zc
->zc_value
));
1735 dmu_objset_rele(os
, FTAG
);
1741 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1745 nvlist_t
*config
, **l2cache
, **spares
;
1746 uint_t nl2cache
= 0, nspares
= 0;
1748 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1752 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1753 zc
->zc_iflags
, &config
);
1754 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_L2CACHE
,
1755 &l2cache
, &nl2cache
);
1757 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_SPARES
,
1761 * A root pool with concatenated devices is not supported.
1762 * Thus, can not add a device to a root pool.
1764 * Intent log device can not be added to a rootpool because
1765 * during mountroot, zil is replayed, a seperated log device
1766 * can not be accessed during the mountroot time.
1768 * l2cache and spare devices are ok to be added to a rootpool.
1770 if (spa_bootfs(spa
) != 0 && nl2cache
== 0 && nspares
== 0) {
1771 nvlist_free(config
);
1772 spa_close(spa
, FTAG
);
1773 return (SET_ERROR(EDOM
));
1777 error
= spa_vdev_add(spa
, config
);
1778 nvlist_free(config
);
1780 spa_close(spa
, FTAG
);
1786 * zc_name name of the pool
1787 * zc_nvlist_conf nvlist of devices to remove
1788 * zc_cookie to stop the remove?
1791 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1796 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1799 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1800 spa_close(spa
, FTAG
);
1805 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1809 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1811 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1813 switch (zc
->zc_cookie
) {
1814 case VDEV_STATE_ONLINE
:
1815 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1818 case VDEV_STATE_OFFLINE
:
1819 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1822 case VDEV_STATE_FAULTED
:
1823 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1824 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1825 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1827 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1830 case VDEV_STATE_DEGRADED
:
1831 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1832 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1833 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1835 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1839 error
= SET_ERROR(EINVAL
);
1841 zc
->zc_cookie
= newstate
;
1842 spa_close(spa
, FTAG
);
1847 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1850 int replacing
= zc
->zc_cookie
;
1854 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1857 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1858 zc
->zc_iflags
, &config
)) == 0) {
1859 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1860 nvlist_free(config
);
1863 spa_close(spa
, FTAG
);
1868 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1873 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1876 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1878 spa_close(spa
, FTAG
);
1883 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1886 nvlist_t
*config
, *props
= NULL
;
1888 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1890 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1893 if (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1894 zc
->zc_iflags
, &config
)) {
1895 spa_close(spa
, FTAG
);
1899 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1900 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1901 zc
->zc_iflags
, &props
))) {
1902 spa_close(spa
, FTAG
);
1903 nvlist_free(config
);
1907 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1909 spa_close(spa
, FTAG
);
1911 nvlist_free(config
);
1918 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1921 char *path
= zc
->zc_value
;
1922 uint64_t guid
= zc
->zc_guid
;
1925 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1929 error
= spa_vdev_setpath(spa
, guid
, path
);
1930 spa_close(spa
, FTAG
);
1935 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1938 char *fru
= zc
->zc_value
;
1939 uint64_t guid
= zc
->zc_guid
;
1942 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1946 error
= spa_vdev_setfru(spa
, guid
, fru
);
1947 spa_close(spa
, FTAG
);
1952 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
1957 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1959 if (zc
->zc_nvlist_dst
!= 0 &&
1960 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
1961 dmu_objset_stats(os
, nv
);
1963 * NB: zvol_get_stats() will read the objset contents,
1964 * which we aren't supposed to do with a
1965 * DS_MODE_USER hold, because it could be
1966 * inconsistent. So this is a bit of a workaround...
1967 * XXX reading with out owning
1969 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
1970 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
1971 error
= zvol_get_stats(os
, nv
);
1976 error
= put_nvlist(zc
, nv
);
1985 * zc_name name of filesystem
1986 * zc_nvlist_dst_size size of buffer for property nvlist
1989 * zc_objset_stats stats
1990 * zc_nvlist_dst property nvlist
1991 * zc_nvlist_dst_size size of property nvlist
1994 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
1999 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2001 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2002 dmu_objset_rele(os
, FTAG
);
2010 * zc_name name of filesystem
2011 * zc_nvlist_dst_size size of buffer for property nvlist
2014 * zc_nvlist_dst received property nvlist
2015 * zc_nvlist_dst_size size of received property nvlist
2017 * Gets received properties (distinct from local properties on or after
2018 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2019 * local property values.
2022 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2028 * Without this check, we would return local property values if the
2029 * caller has not already received properties on or after
2030 * SPA_VERSION_RECVD_PROPS.
2032 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2033 return (SET_ERROR(ENOTSUP
));
2035 if (zc
->zc_nvlist_dst
!= 0 &&
2036 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2037 error
= put_nvlist(zc
, nv
);
2045 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2051 * zfs_get_zplprop() will either find a value or give us
2052 * the default value (if there is one).
2054 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2056 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2062 * zc_name name of filesystem
2063 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2066 * zc_nvlist_dst zpl property nvlist
2067 * zc_nvlist_dst_size size of zpl property nvlist
2070 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2075 /* XXX reading without owning */
2076 if (err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))
2079 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2082 * NB: nvl_add_zplprop() will read the objset contents,
2083 * which we aren't supposed to do with a DS_MODE_USER
2084 * hold, because it could be inconsistent.
2086 if (zc
->zc_nvlist_dst
!= (uintptr_t)NULL
&&
2087 !zc
->zc_objset_stats
.dds_inconsistent
&&
2088 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2091 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2092 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2093 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2094 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2095 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2096 err
= put_nvlist(zc
, nv
);
2099 err
= SET_ERROR(ENOENT
);
2101 dmu_objset_rele(os
, FTAG
);
2106 dataset_name_hidden(const char *name
)
2109 * Skip over datasets that are not visible in this zone,
2110 * internal datasets (which have a $ in their name), and
2111 * temporary datasets (which have a % in their name).
2113 if (strchr(name
, '$') != NULL
)
2115 if (strchr(name
, '%') != NULL
)
2117 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2124 * zc_name name of filesystem
2125 * zc_cookie zap cursor
2126 * zc_nvlist_dst_size size of buffer for property nvlist
2129 * zc_name name of next filesystem
2130 * zc_cookie zap cursor
2131 * zc_objset_stats stats
2132 * zc_nvlist_dst property nvlist
2133 * zc_nvlist_dst_size size of property nvlist
2136 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2141 size_t orig_len
= strlen(zc
->zc_name
);
2144 if (error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) {
2145 if (error
== ENOENT
)
2146 error
= SET_ERROR(ESRCH
);
2150 p
= strrchr(zc
->zc_name
, '/');
2151 if (p
== NULL
|| p
[1] != '\0')
2152 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2153 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2156 error
= dmu_dir_list_next(os
,
2157 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2158 NULL
, &zc
->zc_cookie
);
2159 if (error
== ENOENT
)
2160 error
= SET_ERROR(ESRCH
);
2161 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2162 dmu_objset_rele(os
, FTAG
);
2165 * If it's an internal dataset (ie. with a '$' in its name),
2166 * don't try to get stats for it, otherwise we'll return ENOENT.
2168 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2169 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2170 if (error
== ENOENT
) {
2171 /* We lost a race with destroy, get the next one. */
2172 zc
->zc_name
[orig_len
] = '\0';
2181 * zc_name name of filesystem
2182 * zc_cookie zap cursor
2183 * zc_nvlist_dst_size size of buffer for property nvlist
2184 * zc_simple when set, only name is requested
2187 * zc_name name of next snapshot
2188 * zc_objset_stats stats
2189 * zc_nvlist_dst property nvlist
2190 * zc_nvlist_dst_size size of property nvlist
2193 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2198 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2200 return (error
== ENOENT
? ESRCH
: error
);
2204 * A dataset name of maximum length cannot have any snapshots,
2205 * so exit immediately.
2207 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2208 ZFS_MAX_DATASET_NAME_LEN
) {
2209 dmu_objset_rele(os
, FTAG
);
2210 return (SET_ERROR(ESRCH
));
2213 error
= dmu_snapshot_list_next(os
,
2214 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2215 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2218 if (error
== 0 && !zc
->zc_simple
) {
2220 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2222 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2226 error
= dmu_objset_from_ds(ds
, &ossnap
);
2228 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2229 dsl_dataset_rele(ds
, FTAG
);
2231 } else if (error
== ENOENT
) {
2232 error
= SET_ERROR(ESRCH
);
2235 dmu_objset_rele(os
, FTAG
);
2236 /* if we failed, undo the @ that we tacked on to zc_name */
2238 *strchr(zc
->zc_name
, '@') = '\0';
2243 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2245 const char *propname
= nvpair_name(pair
);
2247 unsigned int vallen
;
2250 zfs_userquota_prop_t type
;
2256 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2258 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2259 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2261 return (SET_ERROR(EINVAL
));
2265 * A correctly constructed propname is encoded as
2266 * userquota@<rid>-<domain>.
2268 if ((dash
= strchr(propname
, '-')) == NULL
||
2269 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2271 return (SET_ERROR(EINVAL
));
2278 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2280 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2281 zfsvfs_rele(zfsvfs
, FTAG
);
2288 * If the named property is one that has a special function to set its value,
2289 * return 0 on success and a positive error code on failure; otherwise if it is
2290 * not one of the special properties handled by this function, return -1.
2292 * XXX: It would be better for callers of the property interface if we handled
2293 * these special cases in dsl_prop.c (in the dsl layer).
2296 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2299 const char *propname
= nvpair_name(pair
);
2300 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2304 if (prop
== ZPROP_INVAL
) {
2305 if (zfs_prop_userquota(propname
))
2306 return (zfs_prop_set_userquota(dsname
, pair
));
2310 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2312 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2313 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2317 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2320 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2323 case ZFS_PROP_QUOTA
:
2324 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2326 case ZFS_PROP_REFQUOTA
:
2327 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2329 case ZFS_PROP_FILESYSTEM_LIMIT
:
2330 case ZFS_PROP_SNAPSHOT_LIMIT
:
2331 if (intval
== UINT64_MAX
) {
2332 /* clearing the limit, just do it */
2335 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2338 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2339 * default path to set the value in the nvlist.
2344 case ZFS_PROP_RESERVATION
:
2345 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2347 case ZFS_PROP_REFRESERVATION
:
2348 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2350 case ZFS_PROP_VOLSIZE
:
2351 err
= zvol_set_volsize(dsname
, intval
);
2353 case ZFS_PROP_VERSION
:
2357 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2360 err
= zfs_set_version(zfsvfs
, intval
);
2361 zfsvfs_rele(zfsvfs
, FTAG
);
2363 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2366 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2367 (void) strcpy(zc
->zc_name
, dsname
);
2368 (void) zfs_ioc_userspace_upgrade(zc
);
2369 kmem_free(zc
, sizeof (zfs_cmd_t
));
2381 * This function is best effort. If it fails to set any of the given properties,
2382 * it continues to set as many as it can and returns the last error
2383 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2384 * with the list of names of all the properties that failed along with the
2385 * corresponding error numbers.
2387 * If every property is set successfully, zero is returned and errlist is not
2391 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2399 nvlist_t
*genericnvl
= fnvlist_alloc();
2400 nvlist_t
*retrynvl
= fnvlist_alloc();
2404 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2405 const char *propname
= nvpair_name(pair
);
2406 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2409 /* decode the property value */
2411 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2413 attrs
= fnvpair_value_nvlist(pair
);
2414 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2416 err
= SET_ERROR(EINVAL
);
2419 /* Validate value type */
2420 if (err
== 0 && prop
== ZPROP_INVAL
) {
2421 if (zfs_prop_user(propname
)) {
2422 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2423 err
= SET_ERROR(EINVAL
);
2424 } else if (zfs_prop_userquota(propname
)) {
2425 if (nvpair_type(propval
) !=
2426 DATA_TYPE_UINT64_ARRAY
)
2427 err
= SET_ERROR(EINVAL
);
2429 err
= SET_ERROR(EINVAL
);
2431 } else if (err
== 0) {
2432 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2433 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2434 err
= SET_ERROR(EINVAL
);
2435 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2438 intval
= fnvpair_value_uint64(propval
);
2440 switch (zfs_prop_get_type(prop
)) {
2441 case PROP_TYPE_NUMBER
:
2443 case PROP_TYPE_STRING
:
2444 err
= SET_ERROR(EINVAL
);
2446 case PROP_TYPE_INDEX
:
2447 if (zfs_prop_index_to_string(prop
,
2448 intval
, &unused
) != 0)
2449 err
= SET_ERROR(EINVAL
);
2453 "unknown property type");
2456 err
= SET_ERROR(EINVAL
);
2460 /* Validate permissions */
2462 err
= zfs_check_settable(dsname
, pair
, CRED());
2465 err
= zfs_prop_set_special(dsname
, source
, pair
);
2468 * For better performance we build up a list of
2469 * properties to set in a single transaction.
2471 err
= nvlist_add_nvpair(genericnvl
, pair
);
2472 } else if (err
!= 0 && nvl
!= retrynvl
) {
2474 * This may be a spurious error caused by
2475 * receiving quota and reservation out of order.
2476 * Try again in a second pass.
2478 err
= nvlist_add_nvpair(retrynvl
, pair
);
2483 if (errlist
!= NULL
)
2484 fnvlist_add_int32(errlist
, propname
, err
);
2489 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2494 if (!nvlist_empty(genericnvl
) &&
2495 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2497 * If this fails, we still want to set as many properties as we
2498 * can, so try setting them individually.
2501 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2502 const char *propname
= nvpair_name(pair
);
2506 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2508 attrs
= fnvpair_value_nvlist(pair
);
2509 propval
= fnvlist_lookup_nvpair(attrs
,
2513 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2514 strval
= fnvpair_value_string(propval
);
2515 err
= dsl_prop_set_string(dsname
, propname
,
2518 intval
= fnvpair_value_uint64(propval
);
2519 err
= dsl_prop_set_int(dsname
, propname
, source
,
2524 if (errlist
!= NULL
) {
2525 fnvlist_add_int32(errlist
, propname
,
2532 nvlist_free(genericnvl
);
2533 nvlist_free(retrynvl
);
2539 * Check that all the properties are valid user properties.
2542 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2544 nvpair_t
*pair
= NULL
;
2547 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2548 const char *propname
= nvpair_name(pair
);
2550 if (!zfs_prop_user(propname
) ||
2551 nvpair_type(pair
) != DATA_TYPE_STRING
)
2552 return (SET_ERROR(EINVAL
));
2554 if (error
= zfs_secpolicy_write_perms(fsname
,
2555 ZFS_DELEG_PERM_USERPROP
, CRED()))
2558 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2559 return (SET_ERROR(ENAMETOOLONG
));
2561 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2568 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2572 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2575 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2576 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2579 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2584 clear_received_props(const char *dsname
, nvlist_t
*props
,
2588 nvlist_t
*cleared_props
= NULL
;
2589 props_skip(props
, skipped
, &cleared_props
);
2590 if (!nvlist_empty(cleared_props
)) {
2592 * Acts on local properties until the dataset has received
2593 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2595 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2596 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2597 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2599 nvlist_free(cleared_props
);
2605 * zc_name name of filesystem
2606 * zc_value name of property to set
2607 * zc_nvlist_src{_size} nvlist of properties to apply
2608 * zc_cookie received properties flag
2611 * zc_nvlist_dst{_size} error for each unapplied received property
2614 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2617 boolean_t received
= zc
->zc_cookie
;
2618 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2623 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2624 zc
->zc_iflags
, &nvl
)) != 0)
2628 nvlist_t
*origprops
;
2630 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2631 (void) clear_received_props(zc
->zc_name
,
2633 nvlist_free(origprops
);
2636 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2639 errors
= fnvlist_alloc();
2641 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2643 if (zc
->zc_nvlist_dst
!= (uintptr_t)NULL
&& errors
!= NULL
) {
2644 (void) put_nvlist(zc
, errors
);
2647 nvlist_free(errors
);
2654 * zc_name name of filesystem
2655 * zc_value name of property to inherit
2656 * zc_cookie revert to received value if TRUE
2661 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2663 const char *propname
= zc
->zc_value
;
2664 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2665 boolean_t received
= zc
->zc_cookie
;
2666 zprop_source_t source
= (received
2667 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2668 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2677 * zfs_prop_set_special() expects properties in the form of an
2678 * nvpair with type info.
2680 if (prop
== ZPROP_INVAL
) {
2681 if (!zfs_prop_user(propname
))
2682 return (SET_ERROR(EINVAL
));
2684 type
= PROP_TYPE_STRING
;
2685 } else if (prop
== ZFS_PROP_VOLSIZE
||
2686 prop
== ZFS_PROP_VERSION
) {
2687 return (SET_ERROR(EINVAL
));
2689 type
= zfs_prop_get_type(prop
);
2692 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2695 case PROP_TYPE_STRING
:
2696 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2698 case PROP_TYPE_NUMBER
:
2699 case PROP_TYPE_INDEX
:
2700 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2704 return (SET_ERROR(EINVAL
));
2707 pair
= nvlist_next_nvpair(dummy
, NULL
);
2708 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2711 return (err
); /* special property already handled */
2714 * Only check this in the non-received case. We want to allow
2715 * 'inherit -S' to revert non-inheritable properties like quota
2716 * and reservation to the received or default values even though
2717 * they are not considered inheritable.
2719 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2720 return (SET_ERROR(EINVAL
));
2723 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2724 return (dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
, source
));
2728 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2735 if (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2736 zc
->zc_iflags
, &props
))
2740 * If the only property is the configfile, then just do a spa_lookup()
2741 * to handle the faulted case.
2743 pair
= nvlist_next_nvpair(props
, NULL
);
2744 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2745 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2746 nvlist_next_nvpair(props
, pair
) == NULL
) {
2747 mutex_enter(&spa_namespace_lock
);
2748 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2749 spa_configfile_set(spa
, props
, B_FALSE
);
2750 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2752 mutex_exit(&spa_namespace_lock
);
2759 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2764 error
= spa_prop_set(spa
, props
);
2767 spa_close(spa
, FTAG
);
2773 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2777 nvlist_t
*nvp
= NULL
;
2779 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2781 * If the pool is faulted, there may be properties we can still
2782 * get (such as altroot and cachefile), so attempt to get them
2785 mutex_enter(&spa_namespace_lock
);
2786 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2787 error
= spa_prop_get(spa
, &nvp
);
2788 mutex_exit(&spa_namespace_lock
);
2790 error
= spa_prop_get(spa
, &nvp
);
2791 spa_close(spa
, FTAG
);
2794 if (error
== 0 && zc
->zc_nvlist_dst
!= (uintptr_t)NULL
)
2795 error
= put_nvlist(zc
, nvp
);
2797 error
= SET_ERROR(EFAULT
);
2805 * zc_name name of filesystem
2806 * zc_nvlist_src{_size} nvlist of delegated permissions
2807 * zc_perm_action allow/unallow flag
2812 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2815 nvlist_t
*fsaclnv
= NULL
;
2817 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2818 zc
->zc_iflags
, &fsaclnv
)) != 0)
2822 * Verify nvlist is constructed correctly
2824 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2825 nvlist_free(fsaclnv
);
2826 return (SET_ERROR(EINVAL
));
2830 * If we don't have PRIV_SYS_MOUNT, then validate
2831 * that user is allowed to hand out each permission in
2835 error
= secpolicy_zfs(CRED());
2837 if (zc
->zc_perm_action
== B_FALSE
) {
2838 error
= dsl_deleg_can_allow(zc
->zc_name
,
2841 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2847 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2849 nvlist_free(fsaclnv
);
2855 * zc_name name of filesystem
2858 * zc_nvlist_src{_size} nvlist of delegated permissions
2861 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2866 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2867 error
= put_nvlist(zc
, nvp
);
2875 * Search the vfs list for a specified resource. Returns a pointer to it
2876 * or NULL if no suitable entry is found. The caller of this routine
2877 * is responsible for releasing the returned vfs pointer.
2880 zfs_get_vfs(const char *resource
)
2883 struct vfs
*vfs_found
= NULL
;
2885 vfs_list_read_lock();
2888 if (strcmp(refstr_value(vfsp
->vfs_resource
), resource
) == 0) {
2893 vfsp
= vfsp
->vfs_next
;
2894 } while (vfsp
!= rootvfs
);
2901 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2903 zfs_creat_t
*zct
= arg
;
2905 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2908 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2912 * os parent objset pointer (NULL if root fs)
2913 * fuids_ok fuids allowed in this version of the spa?
2914 * sa_ok SAs allowed in this version of the spa?
2915 * createprops list of properties requested by creator
2918 * zplprops values for the zplprops we attach to the master node object
2919 * is_ci true if requested file system will be purely case-insensitive
2921 * Determine the settings for utf8only, normalization and
2922 * casesensitivity. Specific values may have been requested by the
2923 * creator and/or we can inherit values from the parent dataset. If
2924 * the file system is of too early a vintage, a creator can not
2925 * request settings for these properties, even if the requested
2926 * setting is the default value. We don't actually want to create dsl
2927 * properties for these, so remove them from the source nvlist after
2931 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2932 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2933 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2935 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2936 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2937 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2939 ASSERT(zplprops
!= NULL
);
2941 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
2942 return (SET_ERROR(EINVAL
));
2945 * Pull out creator prop choices, if any.
2948 (void) nvlist_lookup_uint64(createprops
,
2949 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2950 (void) nvlist_lookup_uint64(createprops
,
2951 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2952 (void) nvlist_remove_all(createprops
,
2953 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2954 (void) nvlist_lookup_uint64(createprops
,
2955 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2956 (void) nvlist_remove_all(createprops
,
2957 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2958 (void) nvlist_lookup_uint64(createprops
,
2959 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2960 (void) nvlist_remove_all(createprops
,
2961 zfs_prop_to_name(ZFS_PROP_CASE
));
2965 * If the zpl version requested is whacky or the file system
2966 * or pool is version is too "young" to support normalization
2967 * and the creator tried to set a value for one of the props,
2970 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
2971 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
2972 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
2973 (zplver
< ZPL_VERSION_NORMALIZATION
&&
2974 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
2975 sense
!= ZFS_PROP_UNDEFINED
)))
2976 return (SET_ERROR(ENOTSUP
));
2979 * Put the version in the zplprops
2981 VERIFY(nvlist_add_uint64(zplprops
,
2982 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
2984 if (norm
== ZFS_PROP_UNDEFINED
)
2985 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
) == 0);
2986 VERIFY(nvlist_add_uint64(zplprops
,
2987 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
2990 * If we're normalizing, names must always be valid UTF-8 strings.
2994 if (u8
== ZFS_PROP_UNDEFINED
)
2995 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
) == 0);
2996 VERIFY(nvlist_add_uint64(zplprops
,
2997 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
2999 if (sense
== ZFS_PROP_UNDEFINED
)
3000 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
) == 0);
3001 VERIFY(nvlist_add_uint64(zplprops
,
3002 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3005 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3011 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3012 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3014 boolean_t fuids_ok
, sa_ok
;
3015 uint64_t zplver
= ZPL_VERSION
;
3016 objset_t
*os
= NULL
;
3017 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3023 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3024 cp
= strrchr(parentname
, '/');
3028 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3031 spa_vers
= spa_version(spa
);
3032 spa_close(spa
, FTAG
);
3034 zplver
= zfs_zpl_version_map(spa_vers
);
3035 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3036 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3039 * Open parent object set so we can inherit zplprop values.
3041 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3044 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3046 dmu_objset_rele(os
, FTAG
);
3051 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3052 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3056 uint64_t zplver
= ZPL_VERSION
;
3059 zplver
= zfs_zpl_version_map(spa_vers
);
3060 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3061 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3063 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3064 createprops
, zplprops
, is_ci
);
3070 * "type" -> dmu_objset_type_t (int32)
3071 * (optional) "props" -> { prop -> value }
3074 * outnvl: propname -> error code (int32)
3077 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3080 zfs_creat_t zct
= { 0 };
3081 nvlist_t
*nvprops
= NULL
;
3082 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3084 dmu_objset_type_t type
;
3085 boolean_t is_insensitive
= B_FALSE
;
3087 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3088 return (SET_ERROR(EINVAL
));
3090 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3094 cbfunc
= zfs_create_cb
;
3098 cbfunc
= zvol_create_cb
;
3105 if (strchr(fsname
, '@') ||
3106 strchr(fsname
, '%'))
3107 return (SET_ERROR(EINVAL
));
3109 zct
.zct_props
= nvprops
;
3112 return (SET_ERROR(EINVAL
));
3114 if (type
== DMU_OST_ZVOL
) {
3115 uint64_t volsize
, volblocksize
;
3117 if (nvprops
== NULL
)
3118 return (SET_ERROR(EINVAL
));
3119 if (nvlist_lookup_uint64(nvprops
,
3120 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3121 return (SET_ERROR(EINVAL
));
3123 if ((error
= nvlist_lookup_uint64(nvprops
,
3124 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3125 &volblocksize
)) != 0 && error
!= ENOENT
)
3126 return (SET_ERROR(EINVAL
));
3129 volblocksize
= zfs_prop_default_numeric(
3130 ZFS_PROP_VOLBLOCKSIZE
);
3132 if ((error
= zvol_check_volblocksize(
3133 volblocksize
)) != 0 ||
3134 (error
= zvol_check_volsize(volsize
,
3135 volblocksize
)) != 0)
3137 } else if (type
== DMU_OST_ZFS
) {
3141 * We have to have normalization and
3142 * case-folding flags correct when we do the
3143 * file system creation, so go figure them out
3146 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3147 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3148 error
= zfs_fill_zplprops(fsname
, nvprops
,
3149 zct
.zct_zplprops
, &is_insensitive
);
3151 nvlist_free(zct
.zct_zplprops
);
3156 error
= dmu_objset_create(fsname
, type
,
3157 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3158 nvlist_free(zct
.zct_zplprops
);
3161 * It would be nice to do this atomically.
3164 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3167 (void) dsl_destroy_head(fsname
);
3174 * "origin" -> name of origin snapshot
3175 * (optional) "props" -> { prop -> value }
3178 * outnvl: propname -> error code (int32)
3181 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3184 nvlist_t
*nvprops
= NULL
;
3187 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3188 return (SET_ERROR(EINVAL
));
3189 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3191 if (strchr(fsname
, '@') ||
3192 strchr(fsname
, '%'))
3193 return (SET_ERROR(EINVAL
));
3195 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3196 return (SET_ERROR(EINVAL
));
3197 error
= dmu_objset_clone(fsname
, origin_name
);
3202 * It would be nice to do this atomically.
3205 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3208 (void) dsl_destroy_head(fsname
);
3215 * "snaps" -> { snapshot1, snapshot2 }
3216 * (optional) "props" -> { prop -> value (string) }
3219 * outnvl: snapshot -> error code (int32)
3222 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3225 nvlist_t
*props
= NULL
;
3229 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3230 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3233 if (!nvlist_empty(props
) &&
3234 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3235 return (SET_ERROR(ENOTSUP
));
3237 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3238 return (SET_ERROR(EINVAL
));
3239 poollen
= strlen(poolname
);
3240 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3241 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3242 const char *name
= nvpair_name(pair
);
3243 const char *cp
= strchr(name
, '@');
3246 * The snap name must contain an @, and the part after it must
3247 * contain only valid characters.
3250 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3251 return (SET_ERROR(EINVAL
));
3254 * The snap must be in the specified pool.
3256 if (strncmp(name
, poolname
, poollen
) != 0 ||
3257 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3258 return (SET_ERROR(EXDEV
));
3260 /* This must be the only snap of this fs. */
3261 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3262 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3263 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3265 return (SET_ERROR(EXDEV
));
3270 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3275 * innvl: "message" -> string
3279 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3287 * The poolname in the ioctl is not set, we get it from the TSD,
3288 * which was set at the end of the last successful ioctl that allows
3289 * logging. The secpolicy func already checked that it is set.
3290 * Only one log ioctl is allowed after each successful ioctl, so
3291 * we clear the TSD here.
3293 poolname
= tsd_get(zfs_allow_log_key
);
3294 (void) tsd_set(zfs_allow_log_key
, NULL
);
3295 error
= spa_open(poolname
, &spa
, FTAG
);
3300 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3301 spa_close(spa
, FTAG
);
3302 return (SET_ERROR(EINVAL
));
3305 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3306 spa_close(spa
, FTAG
);
3307 return (SET_ERROR(ENOTSUP
));
3310 error
= spa_history_log(spa
, message
);
3311 spa_close(spa
, FTAG
);
3316 * The dp_config_rwlock must not be held when calling this, because the
3317 * unmount may need to write out data.
3319 * This function is best-effort. Callers must deal gracefully if it
3320 * remains mounted (or is remounted after this call).
3322 * Returns 0 if the argument is not a snapshot, or it is not currently a
3323 * filesystem, or we were able to unmount it. Returns error code otherwise.
3326 zfs_unmount_snap(const char *snapname
)
3332 if (strchr(snapname
, '@') == NULL
)
3335 vfsp
= zfs_get_vfs(snapname
);
3339 zfsvfs
= vfsp
->vfs_data
;
3340 ASSERT(!dsl_pool_config_held(dmu_objset_pool(zfsvfs
->z_os
)));
3342 err
= vn_vfswlock(vfsp
->vfs_vnodecovered
);
3345 return (SET_ERROR(err
));
3348 * Always force the unmount for snapshots.
3350 (void) dounmount(vfsp
, MS_FORCE
, kcred
);
3356 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3358 return (zfs_unmount_snap(snapname
));
3362 * When a clone is destroyed, its origin may also need to be destroyed,
3363 * in which case it must be unmounted. This routine will do that unmount
3367 zfs_destroy_unmount_origin(const char *fsname
)
3373 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3376 ds
= dmu_objset_ds(os
);
3377 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3378 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3379 dsl_dataset_name(ds
->ds_prev
, originname
);
3380 dmu_objset_rele(os
, FTAG
);
3381 (void) zfs_unmount_snap(originname
);
3383 dmu_objset_rele(os
, FTAG
);
3389 * "snaps" -> { snapshot1, snapshot2 }
3390 * (optional boolean) "defer"
3393 * outnvl: snapshot -> error code (int32)
3398 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3404 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3405 return (SET_ERROR(EINVAL
));
3406 defer
= nvlist_exists(innvl
, "defer");
3408 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3409 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3410 (void) zfs_unmount_snap(nvpair_name(pair
));
3413 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3417 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3418 * All bookmarks must be in the same pool.
3421 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3424 * outnvl: bookmark -> error code (int32)
3429 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3431 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3432 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3436 * Verify the snapshot argument.
3438 if (nvpair_value_string(pair
, &snap_name
) != 0)
3439 return (SET_ERROR(EINVAL
));
3442 /* Verify that the keys (bookmarks) are unique */
3443 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3444 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3445 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3446 return (SET_ERROR(EINVAL
));
3450 return (dsl_bookmark_create(innvl
, outnvl
));
3455 * property 1, property 2, ...
3459 * bookmark name 1 -> { property 1, property 2, ... },
3460 * bookmark name 2 -> { property 1, property 2, ... }
3465 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3467 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3472 * bookmark name 1, bookmark name 2
3475 * outnvl: bookmark -> error code (int32)
3479 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3484 poollen
= strlen(poolname
);
3485 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3486 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3487 const char *name
= nvpair_name(pair
);
3488 const char *cp
= strchr(name
, '#');
3491 * The bookmark name must contain an #, and the part after it
3492 * must contain only valid characters.
3495 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3496 return (SET_ERROR(EINVAL
));
3499 * The bookmark must be in the specified pool.
3501 if (strncmp(name
, poolname
, poollen
) != 0 ||
3502 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3503 return (SET_ERROR(EXDEV
));
3506 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3511 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3515 uint64_t instrlimit
, memlimit
;
3516 nvpair_t
*nvarg
= NULL
;
3518 if (0 != nvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
, &program
)) {
3521 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3522 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3524 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3525 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3527 if (0 != nvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
, &nvarg
)) {
3531 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3533 if (memlimit
== 0 || memlimit
> ZCP_MAX_MEMLIMIT
)
3536 return (zcp_eval(poolname
, program
, instrlimit
, memlimit
,
3542 * zc_name name of dataset to destroy
3543 * zc_objset_type type of objset
3544 * zc_defer_destroy mark for deferred destroy
3549 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3553 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3554 err
= zfs_unmount_snap(zc
->zc_name
);
3559 if (strchr(zc
->zc_name
, '@'))
3560 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3562 err
= dsl_destroy_head(zc
->zc_name
);
3563 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3564 (void) zvol_remove_minor(zc
->zc_name
);
3569 * fsname is name of dataset to rollback (to most recent snapshot)
3571 * innvl may contain name of expected target snapshot
3573 * outnvl: "target" -> name of most recent snapshot
3578 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3581 char *target
= NULL
;
3584 (void) nvlist_lookup_string(innvl
, "target", &target
);
3585 if (target
!= NULL
) {
3586 int fslen
= strlen(fsname
);
3588 if (strncmp(fsname
, target
, fslen
) != 0)
3589 return (SET_ERROR(EINVAL
));
3590 if (target
[fslen
] != '@')
3591 return (SET_ERROR(EINVAL
));
3594 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3597 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3598 error
= zfs_suspend_fs(zfsvfs
);
3602 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3604 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3605 error
= error
? error
: resume_err
;
3607 VFS_RELE(zfsvfs
->z_vfs
);
3609 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3615 recursive_unmount(const char *fsname
, void *arg
)
3617 const char *snapname
= arg
;
3618 char fullname
[ZFS_MAX_DATASET_NAME_LEN
];
3620 (void) snprintf(fullname
, sizeof (fullname
), "%s@%s", fsname
, snapname
);
3621 return (zfs_unmount_snap(fullname
));
3626 * zc_name old name of dataset
3627 * zc_value new name of dataset
3628 * zc_cookie recursive flag (only valid for snapshots)
3633 zfs_ioc_rename(zfs_cmd_t
*zc
)
3635 boolean_t recursive
= zc
->zc_cookie
& 1;
3638 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3639 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3640 strchr(zc
->zc_value
, '%'))
3641 return (SET_ERROR(EINVAL
));
3643 at
= strchr(zc
->zc_name
, '@');
3645 /* snaps must be in same fs */
3648 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3649 return (SET_ERROR(EXDEV
));
3651 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3652 error
= dmu_objset_find(zc
->zc_name
,
3653 recursive_unmount
, at
+ 1,
3654 recursive
? DS_FIND_CHILDREN
: 0);
3660 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3661 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3666 if (zc
->zc_objset_type
== DMU_OST_ZVOL
)
3667 (void) zvol_remove_minor(zc
->zc_name
);
3668 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3673 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3675 const char *propname
= nvpair_name(pair
);
3676 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3677 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3681 if (prop
== ZPROP_INVAL
) {
3682 if (zfs_prop_user(propname
)) {
3683 if (err
= zfs_secpolicy_write_perms(dsname
,
3684 ZFS_DELEG_PERM_USERPROP
, cr
))
3689 if (!issnap
&& zfs_prop_userquota(propname
)) {
3690 const char *perm
= NULL
;
3691 const char *uq_prefix
=
3692 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3693 const char *gq_prefix
=
3694 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3696 if (strncmp(propname
, uq_prefix
,
3697 strlen(uq_prefix
)) == 0) {
3698 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3699 } else if (strncmp(propname
, gq_prefix
,
3700 strlen(gq_prefix
)) == 0) {
3701 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3703 /* USERUSED and GROUPUSED are read-only */
3704 return (SET_ERROR(EINVAL
));
3707 if (err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
))
3712 return (SET_ERROR(EINVAL
));
3716 return (SET_ERROR(EINVAL
));
3718 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3720 * dsl_prop_get_all_impl() returns properties in this
3724 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3725 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3730 * Check that this value is valid for this pool version
3733 case ZFS_PROP_COMPRESSION
:
3735 * If the user specified gzip compression, make sure
3736 * the SPA supports it. We ignore any errors here since
3737 * we'll catch them later.
3739 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3740 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3741 intval
<= ZIO_COMPRESS_GZIP_9
&&
3742 zfs_earlier_version(dsname
,
3743 SPA_VERSION_GZIP_COMPRESSION
)) {
3744 return (SET_ERROR(ENOTSUP
));
3747 if (intval
== ZIO_COMPRESS_ZLE
&&
3748 zfs_earlier_version(dsname
,
3749 SPA_VERSION_ZLE_COMPRESSION
))
3750 return (SET_ERROR(ENOTSUP
));
3752 if (intval
== ZIO_COMPRESS_LZ4
) {
3755 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3758 if (!spa_feature_is_enabled(spa
,
3759 SPA_FEATURE_LZ4_COMPRESS
)) {
3760 spa_close(spa
, FTAG
);
3761 return (SET_ERROR(ENOTSUP
));
3763 spa_close(spa
, FTAG
);
3767 * If this is a bootable dataset then
3768 * verify that the compression algorithm
3769 * is supported for booting. We must return
3770 * something other than ENOTSUP since it
3771 * implies a downrev pool version.
3773 if (zfs_is_bootfs(dsname
) &&
3774 !BOOTFS_COMPRESS_VALID(intval
)) {
3775 return (SET_ERROR(ERANGE
));
3780 case ZFS_PROP_COPIES
:
3781 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3782 return (SET_ERROR(ENOTSUP
));
3785 case ZFS_PROP_RECORDSIZE
:
3786 /* Record sizes above 128k need the feature to be enabled */
3787 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3788 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3792 * We don't allow setting the property above 1MB,
3793 * unless the tunable has been changed.
3795 if (intval
> zfs_max_recordsize
||
3796 intval
> SPA_MAXBLOCKSIZE
)
3797 return (SET_ERROR(ERANGE
));
3799 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3802 if (!spa_feature_is_enabled(spa
,
3803 SPA_FEATURE_LARGE_BLOCKS
)) {
3804 spa_close(spa
, FTAG
);
3805 return (SET_ERROR(ENOTSUP
));
3807 spa_close(spa
, FTAG
);
3811 case ZFS_PROP_SHARESMB
:
3812 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3813 return (SET_ERROR(ENOTSUP
));
3816 case ZFS_PROP_ACLINHERIT
:
3817 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3818 nvpair_value_uint64(pair
, &intval
) == 0) {
3819 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3820 zfs_earlier_version(dsname
,
3821 SPA_VERSION_PASSTHROUGH_X
))
3822 return (SET_ERROR(ENOTSUP
));
3826 case ZFS_PROP_CHECKSUM
:
3827 case ZFS_PROP_DEDUP
:
3829 spa_feature_t feature
;
3832 /* dedup feature version checks */
3833 if (prop
== ZFS_PROP_DEDUP
&&
3834 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3835 return (SET_ERROR(ENOTSUP
));
3837 if (nvpair_value_uint64(pair
, &intval
) != 0)
3838 return (SET_ERROR(EINVAL
));
3840 /* check prop value is enabled in features */
3841 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
3842 if (feature
== SPA_FEATURE_NONE
)
3845 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3848 * Salted checksums are not supported on root pools.
3850 if (spa_bootfs(spa
) != 0 &&
3851 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
3852 (zio_checksum_table
[intval
].ci_flags
&
3853 ZCHECKSUM_FLAG_SALTED
)) {
3854 spa_close(spa
, FTAG
);
3855 return (SET_ERROR(ERANGE
));
3857 if (!spa_feature_is_enabled(spa
, feature
)) {
3858 spa_close(spa
, FTAG
);
3859 return (SET_ERROR(ENOTSUP
));
3861 spa_close(spa
, FTAG
);
3866 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3870 * Checks for a race condition to make sure we don't increment a feature flag
3874 zfs_prop_activate_feature_check(void *arg
, dmu_tx_t
*tx
)
3876 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3877 spa_feature_t
*featurep
= arg
;
3879 if (!spa_feature_is_active(spa
, *featurep
))
3882 return (SET_ERROR(EBUSY
));
3886 * The callback invoked on feature activation in the sync task caused by
3887 * zfs_prop_activate_feature.
3890 zfs_prop_activate_feature_sync(void *arg
, dmu_tx_t
*tx
)
3892 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3893 spa_feature_t
*featurep
= arg
;
3895 spa_feature_incr(spa
, *featurep
, tx
);
3899 * Activates a feature on a pool in response to a property setting. This
3900 * creates a new sync task which modifies the pool to reflect the feature
3904 zfs_prop_activate_feature(spa_t
*spa
, spa_feature_t feature
)
3908 /* EBUSY here indicates that the feature is already active */
3909 err
= dsl_sync_task(spa_name(spa
),
3910 zfs_prop_activate_feature_check
, zfs_prop_activate_feature_sync
,
3911 &feature
, 2, ZFS_SPACE_CHECK_RESERVED
);
3913 if (err
!= 0 && err
!= EBUSY
)
3920 * Removes properties from the given props list that fail permission checks
3921 * needed to clear them and to restore them in case of a receive error. For each
3922 * property, make sure we have both set and inherit permissions.
3924 * Returns the first error encountered if any permission checks fail. If the
3925 * caller provides a non-NULL errlist, it also gives the complete list of names
3926 * of all the properties that failed a permission check along with the
3927 * corresponding error numbers. The caller is responsible for freeing the
3930 * If every property checks out successfully, zero is returned and the list
3931 * pointed at by errlist is NULL.
3934 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3937 nvpair_t
*pair
, *next_pair
;
3944 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3946 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
3947 (void) strcpy(zc
->zc_name
, dataset
);
3948 pair
= nvlist_next_nvpair(props
, NULL
);
3949 while (pair
!= NULL
) {
3950 next_pair
= nvlist_next_nvpair(props
, pair
);
3952 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3953 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3954 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
3955 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3956 VERIFY(nvlist_add_int32(errors
,
3957 zc
->zc_value
, err
) == 0);
3961 kmem_free(zc
, sizeof (zfs_cmd_t
));
3963 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3964 nvlist_free(errors
);
3967 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3970 if (errlist
== NULL
)
3971 nvlist_free(errors
);
3979 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3981 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3982 /* dsl_prop_get_all_impl() format */
3984 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3985 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3989 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3991 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3992 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3996 if (nvpair_type(p1
) != nvpair_type(p2
))
3999 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4000 char *valstr1
, *valstr2
;
4002 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4003 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4004 return (strcmp(valstr1
, valstr2
) == 0);
4006 uint64_t intval1
, intval2
;
4008 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4009 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4010 return (intval1
== intval2
);
4015 * Remove properties from props if they are not going to change (as determined
4016 * by comparison with origprops). Remove them from origprops as well, since we
4017 * do not need to clear or restore properties that won't change.
4020 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4022 nvpair_t
*pair
, *next_pair
;
4024 if (origprops
== NULL
)
4025 return; /* all props need to be received */
4027 pair
= nvlist_next_nvpair(props
, NULL
);
4028 while (pair
!= NULL
) {
4029 const char *propname
= nvpair_name(pair
);
4032 next_pair
= nvlist_next_nvpair(props
, pair
);
4034 if ((nvlist_lookup_nvpair(origprops
, propname
,
4035 &match
) != 0) || !propval_equals(pair
, match
))
4036 goto next
; /* need to set received value */
4038 /* don't clear the existing received value */
4039 (void) nvlist_remove_nvpair(origprops
, match
);
4040 /* don't bother receiving the property */
4041 (void) nvlist_remove_nvpair(props
, pair
);
4048 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4049 * For example, refquota cannot be set until after the receipt of a dataset,
4050 * because in replication streams, an older/earlier snapshot may exceed the
4051 * refquota. We want to receive the older/earlier snapshot, but setting
4052 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4053 * the older/earlier snapshot from being received (with EDQUOT).
4055 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4057 * libzfs will need to be judicious handling errors encountered by props
4058 * extracted by this function.
4061 extract_delay_props(nvlist_t
*props
)
4063 nvlist_t
*delayprops
;
4064 nvpair_t
*nvp
, *tmp
;
4065 static const zfs_prop_t delayable
[] = { ZFS_PROP_REFQUOTA
, 0 };
4068 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4070 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4071 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4073 * strcmp() is safe because zfs_prop_to_name() always returns
4076 for (i
= 0; delayable
[i
] != 0; i
++) {
4077 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4078 nvpair_name(nvp
)) == 0) {
4082 if (delayable
[i
] != 0) {
4083 tmp
= nvlist_prev_nvpair(props
, nvp
);
4084 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4085 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4090 if (nvlist_empty(delayprops
)) {
4091 nvlist_free(delayprops
);
4094 return (delayprops
);
4098 static boolean_t zfs_ioc_recv_inject_err
;
4103 * zc_name name of containing filesystem
4104 * zc_nvlist_src{_size} nvlist of properties to apply
4105 * zc_value name of snapshot to create
4106 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4107 * zc_cookie file descriptor to recv from
4108 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4109 * zc_guid force flag
4110 * zc_cleanup_fd cleanup-on-exit file descriptor
4111 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4112 * zc_resumable if data is incomplete assume sender will resume
4115 * zc_cookie number of bytes read
4116 * zc_nvlist_dst{_size} error for each unapplied received property
4117 * zc_obj zprop_errflags_t
4118 * zc_action_handle handle for this guid/ds mapping
4121 zfs_ioc_recv(zfs_cmd_t
*zc
)
4124 dmu_recv_cookie_t drc
;
4125 boolean_t force
= (boolean_t
)zc
->zc_guid
;
4128 int props_error
= 0;
4131 nvlist_t
*props
= NULL
; /* sent properties */
4132 nvlist_t
*origprops
= NULL
; /* existing properties */
4133 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4134 char *origin
= NULL
;
4136 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4137 boolean_t first_recvd_props
= B_FALSE
;
4139 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4140 strchr(zc
->zc_value
, '@') == NULL
||
4141 strchr(zc
->zc_value
, '%'))
4142 return (SET_ERROR(EINVAL
));
4144 (void) strcpy(tofs
, zc
->zc_value
);
4145 tosnap
= strchr(tofs
, '@');
4148 if (zc
->zc_nvlist_src
!= (uintptr_t)NULL
&&
4149 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4150 zc
->zc_iflags
, &props
)) != 0)
4157 return (SET_ERROR(EBADF
));
4160 errors
= fnvlist_alloc();
4162 if (zc
->zc_string
[0])
4163 origin
= zc
->zc_string
;
4165 error
= dmu_recv_begin(tofs
, tosnap
,
4166 &zc
->zc_begin_record
, force
, zc
->zc_resumable
, origin
, &drc
);
4171 * Set properties before we receive the stream so that they are applied
4172 * to the new data. Note that we must call dmu_recv_stream() if
4173 * dmu_recv_begin() succeeds.
4175 if (props
!= NULL
&& !drc
.drc_newfs
) {
4176 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4177 SPA_VERSION_RECVD_PROPS
&&
4178 !dsl_prop_get_hasrecvd(tofs
))
4179 first_recvd_props
= B_TRUE
;
4182 * If new received properties are supplied, they are to
4183 * completely replace the existing received properties, so stash
4184 * away the existing ones.
4186 if (dsl_prop_get_received(tofs
, &origprops
) == 0) {
4187 nvlist_t
*errlist
= NULL
;
4189 * Don't bother writing a property if its value won't
4190 * change (and avoid the unnecessary security checks).
4192 * The first receive after SPA_VERSION_RECVD_PROPS is a
4193 * special case where we blow away all local properties
4196 if (!first_recvd_props
)
4197 props_reduce(props
, origprops
);
4198 if (zfs_check_clearable(tofs
, origprops
, &errlist
) != 0)
4199 (void) nvlist_merge(errors
, errlist
, 0);
4200 nvlist_free(errlist
);
4202 if (clear_received_props(tofs
, origprops
,
4203 first_recvd_props
? NULL
: props
) != 0)
4204 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4206 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4210 if (props
!= NULL
) {
4211 props_error
= dsl_prop_set_hasrecvd(tofs
);
4213 if (props_error
== 0) {
4214 delayprops
= extract_delay_props(props
);
4215 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4221 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
4222 &zc
->zc_action_handle
);
4225 zfsvfs_t
*zfsvfs
= NULL
;
4227 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4232 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4233 error
= zfs_suspend_fs(zfsvfs
);
4235 * If the suspend fails, then the recv_end will
4236 * likely also fail, and clean up after itself.
4238 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4240 error
= zfs_resume_fs(zfsvfs
, ds
);
4241 error
= error
? error
: end_err
;
4242 VFS_RELE(zfsvfs
->z_vfs
);
4244 error
= dmu_recv_end(&drc
, NULL
);
4247 /* Set delayed properties now, after we're done receiving. */
4248 if (delayprops
!= NULL
&& error
== 0) {
4249 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4250 delayprops
, errors
);
4254 if (delayprops
!= NULL
) {
4256 * Merge delayed props back in with initial props, in case
4257 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4258 * we have to make sure clear_received_props() includes
4259 * the delayed properties).
4261 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4262 * using ASSERT() will be just like a VERIFY.
4264 ASSERT(nvlist_merge(props
, delayprops
, 0) == 0);
4265 nvlist_free(delayprops
);
4269 * Now that all props, initial and delayed, are set, report the prop
4270 * errors to the caller.
4272 if (zc
->zc_nvlist_dst_size
!= 0 &&
4273 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4274 put_nvlist(zc
, errors
) != 0)) {
4276 * Caller made zc->zc_nvlist_dst less than the minimum expected
4277 * size or supplied an invalid address.
4279 props_error
= SET_ERROR(EINVAL
);
4282 zc
->zc_cookie
= off
- fp
->f_offset
;
4283 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4287 if (zfs_ioc_recv_inject_err
) {
4288 zfs_ioc_recv_inject_err
= B_FALSE
;
4293 * On error, restore the original props.
4295 if (error
!= 0 && props
!= NULL
&& !drc
.drc_newfs
) {
4296 if (clear_received_props(tofs
, props
, NULL
) != 0) {
4298 * We failed to clear the received properties.
4299 * Since we may have left a $recvd value on the
4300 * system, we can't clear the $hasrecvd flag.
4302 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4303 } else if (first_recvd_props
) {
4304 dsl_prop_unset_hasrecvd(tofs
);
4307 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4308 /* We failed to stash the original properties. */
4309 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4313 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4314 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4315 * explictly if we're restoring local properties cleared in the
4316 * first new-style receive.
4318 if (origprops
!= NULL
&&
4319 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4320 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4321 origprops
, NULL
) != 0) {
4323 * We stashed the original properties but failed to
4326 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4331 nvlist_free(origprops
);
4332 nvlist_free(errors
);
4336 error
= props_error
;
4343 * zc_name name of snapshot to send
4344 * zc_cookie file descriptor to send stream to
4345 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4346 * zc_sendobj objsetid of snapshot to send
4347 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4348 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4349 * output size in zc_objset_type.
4350 * zc_flags lzc_send_flags
4353 * zc_objset_type estimated size, if zc_guid is set
4356 zfs_ioc_send(zfs_cmd_t
*zc
)
4360 boolean_t estimate
= (zc
->zc_guid
!= 0);
4361 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4362 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4363 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4365 if (zc
->zc_obj
!= 0) {
4367 dsl_dataset_t
*tosnap
;
4369 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4373 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4375 dsl_pool_rele(dp
, FTAG
);
4379 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4381 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4382 dsl_dataset_rele(tosnap
, FTAG
);
4383 dsl_pool_rele(dp
, FTAG
);
4388 dsl_dataset_t
*tosnap
;
4389 dsl_dataset_t
*fromsnap
= NULL
;
4391 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4395 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4397 dsl_pool_rele(dp
, FTAG
);
4401 if (zc
->zc_fromobj
!= 0) {
4402 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4405 dsl_dataset_rele(tosnap
, FTAG
);
4406 dsl_pool_rele(dp
, FTAG
);
4411 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
4412 &zc
->zc_objset_type
);
4414 if (fromsnap
!= NULL
)
4415 dsl_dataset_rele(fromsnap
, FTAG
);
4416 dsl_dataset_rele(tosnap
, FTAG
);
4417 dsl_pool_rele(dp
, FTAG
);
4419 file_t
*fp
= getf(zc
->zc_cookie
);
4421 return (SET_ERROR(EBADF
));
4424 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4425 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
,
4426 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4428 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4430 releasef(zc
->zc_cookie
);
4437 * zc_name name of snapshot on which to report progress
4438 * zc_cookie file descriptor of send stream
4441 * zc_cookie number of bytes written in send stream thus far
4444 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4448 dmu_sendarg_t
*dsp
= NULL
;
4451 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4455 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4457 dsl_pool_rele(dp
, FTAG
);
4461 mutex_enter(&ds
->ds_sendstream_lock
);
4464 * Iterate over all the send streams currently active on this dataset.
4465 * If there's one which matches the specified file descriptor _and_ the
4466 * stream was started by the current process, return the progress of
4469 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4470 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4471 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4472 dsp
->dsa_proc
== curproc
)
4477 zc
->zc_cookie
= *(dsp
->dsa_off
);
4479 error
= SET_ERROR(ENOENT
);
4481 mutex_exit(&ds
->ds_sendstream_lock
);
4482 dsl_dataset_rele(ds
, FTAG
);
4483 dsl_pool_rele(dp
, FTAG
);
4488 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4492 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4493 &zc
->zc_inject_record
);
4496 zc
->zc_guid
= (uint64_t)id
;
4502 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4504 return (zio_clear_fault((int)zc
->zc_guid
));
4508 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4510 int id
= (int)zc
->zc_guid
;
4513 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4514 &zc
->zc_inject_record
);
4522 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4526 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4528 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4531 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4534 zc
->zc_nvlist_dst_size
= count
;
4536 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4538 spa_close(spa
, FTAG
);
4544 zfs_ioc_clear(zfs_cmd_t
*zc
)
4551 * On zpool clear we also fix up missing slogs
4553 mutex_enter(&spa_namespace_lock
);
4554 spa
= spa_lookup(zc
->zc_name
);
4556 mutex_exit(&spa_namespace_lock
);
4557 return (SET_ERROR(EIO
));
4559 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4560 /* we need to let spa_open/spa_load clear the chains */
4561 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4563 spa
->spa_last_open_failed
= 0;
4564 mutex_exit(&spa_namespace_lock
);
4566 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4567 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4570 nvlist_t
*config
= NULL
;
4572 if (zc
->zc_nvlist_src
== (uintptr_t)NULL
)
4573 return (SET_ERROR(EINVAL
));
4575 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4576 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4577 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4579 if (config
!= NULL
) {
4582 if ((err
= put_nvlist(zc
, config
)) != 0)
4584 nvlist_free(config
);
4586 nvlist_free(policy
);
4593 spa_vdev_state_enter(spa
, SCL_NONE
);
4595 if (zc
->zc_guid
== 0) {
4598 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4600 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4601 spa_close(spa
, FTAG
);
4602 return (SET_ERROR(ENODEV
));
4606 vdev_clear(spa
, vd
);
4608 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4611 * Resume any suspended I/Os.
4613 if (zio_resume(spa
) != 0)
4614 error
= SET_ERROR(EIO
);
4616 spa_close(spa
, FTAG
);
4622 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4627 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4631 spa_vdev_state_enter(spa
, SCL_NONE
);
4634 * If a resilver is already in progress then set the
4635 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4636 * the scan as a side effect of the reopen. Otherwise, let
4637 * vdev_open() decided if a resilver is required.
4639 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4640 vdev_reopen(spa
->spa_root_vdev
);
4641 spa
->spa_scrub_reopen
= B_FALSE
;
4643 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4644 spa_close(spa
, FTAG
);
4649 * zc_name name of filesystem
4652 * zc_string name of conflicting snapshot, if there is one
4655 zfs_ioc_promote(zfs_cmd_t
*zc
)
4658 dsl_dataset_t
*ds
, *ods
;
4659 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
4663 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4667 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4669 dsl_pool_rele(dp
, FTAG
);
4673 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
4674 dsl_dataset_rele(ds
, FTAG
);
4675 dsl_pool_rele(dp
, FTAG
);
4676 return (SET_ERROR(EINVAL
));
4679 error
= dsl_dataset_hold_obj(dp
,
4680 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
4682 dsl_dataset_rele(ds
, FTAG
);
4683 dsl_pool_rele(dp
, FTAG
);
4687 dsl_dataset_name(ods
, origin
);
4688 dsl_dataset_rele(ods
, FTAG
);
4689 dsl_dataset_rele(ds
, FTAG
);
4690 dsl_pool_rele(dp
, FTAG
);
4693 * We don't need to unmount *all* the origin fs's snapshots, but
4696 cp
= strchr(origin
, '@');
4699 (void) dmu_objset_find(origin
,
4700 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
4701 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4705 * Retrieve a single {user|group}{used|quota}@... property.
4708 * zc_name name of filesystem
4709 * zc_objset_type zfs_userquota_prop_t
4710 * zc_value domain name (eg. "S-1-234-567-89")
4711 * zc_guid RID/UID/GID
4714 * zc_cookie property value
4717 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4722 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4723 return (SET_ERROR(EINVAL
));
4725 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
4729 error
= zfs_userspace_one(zfsvfs
,
4730 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4731 zfsvfs_rele(zfsvfs
, FTAG
);
4738 * zc_name name of filesystem
4739 * zc_cookie zap cursor
4740 * zc_objset_type zfs_userquota_prop_t
4741 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4744 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4745 * zc_cookie zap cursor
4748 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4751 int bufsize
= zc
->zc_nvlist_dst_size
;
4754 return (SET_ERROR(ENOMEM
));
4756 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
4760 void *buf
= kmem_alloc(bufsize
, KM_SLEEP
);
4762 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4763 buf
, &zc
->zc_nvlist_dst_size
);
4766 error
= xcopyout(buf
,
4767 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4768 zc
->zc_nvlist_dst_size
);
4770 kmem_free(buf
, bufsize
);
4771 zfsvfs_rele(zfsvfs
, FTAG
);
4778 * zc_name name of filesystem
4784 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4790 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
4791 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
4793 * If userused is not enabled, it may be because the
4794 * objset needs to be closed & reopened (to grow the
4795 * objset_phys_t). Suspend/resume the fs will do that.
4799 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4800 error
= zfs_suspend_fs(zfsvfs
);
4802 dmu_objset_refresh_ownership(zfsvfs
->z_os
,
4804 error
= zfs_resume_fs(zfsvfs
, ds
);
4808 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
4809 VFS_RELE(zfsvfs
->z_vfs
);
4811 /* XXX kind of reading contents without owning */
4812 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4816 error
= dmu_objset_userspace_upgrade(os
);
4817 dmu_objset_rele(os
, FTAG
);
4824 * We don't want to have a hard dependency
4825 * against some special symbols in sharefs
4826 * nfs, and smbsrv. Determine them if needed when
4827 * the first file system is shared.
4828 * Neither sharefs, nfs or smbsrv are unloadable modules.
4830 int (*znfsexport_fs
)(void *arg
);
4831 int (*zshare_fs
)(enum sharefs_sys_op
, share_t
*, uint32_t);
4832 int (*zsmbexport_fs
)(void *arg
, boolean_t add_share
);
4834 int zfs_nfsshare_inited
;
4835 int zfs_smbshare_inited
;
4837 ddi_modhandle_t nfs_mod
;
4838 ddi_modhandle_t sharefs_mod
;
4839 ddi_modhandle_t smbsrv_mod
;
4840 kmutex_t zfs_share_lock
;
4847 ASSERT(MUTEX_HELD(&zfs_share_lock
));
4848 /* Both NFS and SMB shares also require sharetab support. */
4849 if (sharefs_mod
== NULL
&& ((sharefs_mod
=
4850 ddi_modopen("fs/sharefs",
4851 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4852 return (SET_ERROR(ENOSYS
));
4854 if (zshare_fs
== NULL
&& ((zshare_fs
=
4855 (int (*)(enum sharefs_sys_op
, share_t
*, uint32_t))
4856 ddi_modsym(sharefs_mod
, "sharefs_impl", &error
)) == NULL
)) {
4857 return (SET_ERROR(ENOSYS
));
4863 zfs_ioc_share(zfs_cmd_t
*zc
)
4868 switch (zc
->zc_share
.z_sharetype
) {
4870 case ZFS_UNSHARE_NFS
:
4871 if (zfs_nfsshare_inited
== 0) {
4872 mutex_enter(&zfs_share_lock
);
4873 if (nfs_mod
== NULL
&& ((nfs_mod
= ddi_modopen("fs/nfs",
4874 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4875 mutex_exit(&zfs_share_lock
);
4876 return (SET_ERROR(ENOSYS
));
4878 if (znfsexport_fs
== NULL
&&
4879 ((znfsexport_fs
= (int (*)(void *))
4881 "nfs_export", &error
)) == NULL
)) {
4882 mutex_exit(&zfs_share_lock
);
4883 return (SET_ERROR(ENOSYS
));
4885 error
= zfs_init_sharefs();
4887 mutex_exit(&zfs_share_lock
);
4888 return (SET_ERROR(ENOSYS
));
4890 zfs_nfsshare_inited
= 1;
4891 mutex_exit(&zfs_share_lock
);
4895 case ZFS_UNSHARE_SMB
:
4896 if (zfs_smbshare_inited
== 0) {
4897 mutex_enter(&zfs_share_lock
);
4898 if (smbsrv_mod
== NULL
&& ((smbsrv_mod
=
4899 ddi_modopen("drv/smbsrv",
4900 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4901 mutex_exit(&zfs_share_lock
);
4902 return (SET_ERROR(ENOSYS
));
4904 if (zsmbexport_fs
== NULL
&& ((zsmbexport_fs
=
4905 (int (*)(void *, boolean_t
))ddi_modsym(smbsrv_mod
,
4906 "smb_server_share", &error
)) == NULL
)) {
4907 mutex_exit(&zfs_share_lock
);
4908 return (SET_ERROR(ENOSYS
));
4910 error
= zfs_init_sharefs();
4912 mutex_exit(&zfs_share_lock
);
4913 return (SET_ERROR(ENOSYS
));
4915 zfs_smbshare_inited
= 1;
4916 mutex_exit(&zfs_share_lock
);
4920 return (SET_ERROR(EINVAL
));
4923 switch (zc
->zc_share
.z_sharetype
) {
4925 case ZFS_UNSHARE_NFS
:
4927 znfsexport_fs((void *)
4928 (uintptr_t)zc
->zc_share
.z_exportdata
))
4932 case ZFS_UNSHARE_SMB
:
4933 if (error
= zsmbexport_fs((void *)
4934 (uintptr_t)zc
->zc_share
.z_exportdata
,
4935 zc
->zc_share
.z_sharetype
== ZFS_SHARE_SMB
?
4942 opcode
= (zc
->zc_share
.z_sharetype
== ZFS_SHARE_NFS
||
4943 zc
->zc_share
.z_sharetype
== ZFS_SHARE_SMB
) ?
4944 SHAREFS_ADD
: SHAREFS_REMOVE
;
4947 * Add or remove share from sharetab
4949 error
= zshare_fs(opcode
,
4950 (void *)(uintptr_t)zc
->zc_share
.z_sharedata
,
4951 zc
->zc_share
.z_sharemax
);
4957 ace_t full_access
[] = {
4958 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4963 * zc_name name of containing filesystem
4964 * zc_obj object # beyond which we want next in-use object #
4967 * zc_obj next in-use object #
4970 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4972 objset_t
*os
= NULL
;
4975 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4979 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4980 dsl_dataset_phys(os
->os_dsl_dataset
)->ds_prev_snap_txg
);
4982 dmu_objset_rele(os
, FTAG
);
4988 * zc_name name of filesystem
4989 * zc_value prefix name for snapshot
4990 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4993 * zc_value short name of new snapshot
4996 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5003 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5007 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5008 (u_longlong_t
)ddi_get_lbolt64());
5009 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5011 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5014 (void) strcpy(zc
->zc_value
, snap_name
);
5017 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5023 * zc_name name of "to" snapshot
5024 * zc_value name of "from" snapshot
5025 * zc_cookie file descriptor to write diff data on
5028 * dmu_diff_record_t's to the file descriptor
5031 zfs_ioc_diff(zfs_cmd_t
*zc
)
5037 fp
= getf(zc
->zc_cookie
);
5039 return (SET_ERROR(EBADF
));
5043 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5045 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5047 releasef(zc
->zc_cookie
);
5053 * Remove all ACL files in shares dir
5056 zfs_smb_acl_purge(znode_t
*dzp
)
5059 zap_attribute_t zap
;
5060 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
5063 for (zap_cursor_init(&zc
, zfsvfs
->z_os
, dzp
->z_id
);
5064 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5065 zap_cursor_advance(&zc
)) {
5066 if ((error
= fop_remove(ZTOV(dzp
), zap
.za_name
, kcred
,
5070 zap_cursor_fini(&zc
);
5075 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5079 vnode_t
*resourcevp
= NULL
;
5088 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5089 NO_FOLLOW
, NULL
, &vp
)) != 0)
5092 /* Now make sure mntpnt and dataset are ZFS */
5094 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5095 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5096 zc
->zc_name
) != 0)) {
5098 return (SET_ERROR(EINVAL
));
5102 zfsvfs
= dzp
->z_zfsvfs
;
5106 * Create share dir if its missing.
5108 mutex_enter(&zfsvfs
->z_lock
);
5109 if (zfsvfs
->z_shares_dir
== 0) {
5112 tx
= dmu_tx_create(zfsvfs
->z_os
);
5113 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5115 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5116 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5120 error
= zfs_create_share_dir(zfsvfs
, tx
);
5124 mutex_exit(&zfsvfs
->z_lock
);
5130 mutex_exit(&zfsvfs
->z_lock
);
5132 ASSERT(zfsvfs
->z_shares_dir
);
5133 if ((error
= zfs_zget(zfsvfs
, zfsvfs
->z_shares_dir
, &sharedir
)) != 0) {
5139 switch (zc
->zc_cookie
) {
5140 case ZFS_SMB_ACL_ADD
:
5141 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5142 vattr
.va_type
= VREG
;
5143 vattr
.va_mode
= S_IFREG
|0777;
5147 vsec
.vsa_mask
= VSA_ACE
;
5148 vsec
.vsa_aclentp
= &full_access
;
5149 vsec
.vsa_aclentsz
= sizeof (full_access
);
5150 vsec
.vsa_aclcnt
= 1;
5152 error
= fop_create(ZTOV(sharedir
), zc
->zc_string
,
5153 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5155 VN_RELE(resourcevp
);
5158 case ZFS_SMB_ACL_REMOVE
:
5159 error
= fop_remove(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5163 case ZFS_SMB_ACL_RENAME
:
5164 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5165 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5167 VN_RELE(ZTOV(sharedir
));
5171 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5172 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5175 VN_RELE(ZTOV(sharedir
));
5177 nvlist_free(nvlist
);
5180 error
= fop_rename(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5182 nvlist_free(nvlist
);
5185 case ZFS_SMB_ACL_PURGE
:
5186 error
= zfs_smb_acl_purge(sharedir
);
5190 error
= SET_ERROR(EINVAL
);
5195 VN_RELE(ZTOV(sharedir
));
5204 * "holds" -> { snapname -> holdname (string), ... }
5205 * (optional) "cleanup_fd" -> fd (int32)
5209 * snapname -> error value (int32)
5215 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5219 int cleanup_fd
= -1;
5223 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5225 return (SET_ERROR(EINVAL
));
5227 /* make sure the user didn't pass us any invalid (empty) tags */
5228 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5229 pair
= nvlist_next_nvpair(holds
, pair
)) {
5232 error
= nvpair_value_string(pair
, &htag
);
5234 return (SET_ERROR(error
));
5236 if (strlen(htag
) == 0)
5237 return (SET_ERROR(EINVAL
));
5240 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5241 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5246 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5248 zfs_onexit_fd_rele(cleanup_fd
);
5253 * innvl is not used.
5256 * holdname -> time added (uint64 seconds since epoch)
5262 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5264 return (dsl_dataset_get_holds(snapname
, outnvl
));
5269 * snapname -> { holdname, ... }
5274 * snapname -> error value (int32)
5280 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5282 return (dsl_dataset_user_release(holds
, errlist
));
5287 * zc_name name of new filesystem or snapshot
5288 * zc_value full name of old snapshot
5291 * zc_cookie space in bytes
5292 * zc_objset_type compressed space in bytes
5293 * zc_perm_action uncompressed space in bytes
5296 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5300 dsl_dataset_t
*new, *old
;
5302 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5305 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5307 dsl_pool_rele(dp
, FTAG
);
5310 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5312 dsl_dataset_rele(new, FTAG
);
5313 dsl_pool_rele(dp
, FTAG
);
5317 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5318 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5319 dsl_dataset_rele(old
, FTAG
);
5320 dsl_dataset_rele(new, FTAG
);
5321 dsl_pool_rele(dp
, FTAG
);
5327 * "firstsnap" -> snapshot name
5331 * "used" -> space in bytes
5332 * "compressed" -> compressed space in bytes
5333 * "uncompressed" -> uncompressed space in bytes
5337 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5341 dsl_dataset_t
*new, *old
;
5343 uint64_t used
, comp
, uncomp
;
5345 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5346 return (SET_ERROR(EINVAL
));
5348 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5352 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5353 if (error
== 0 && !new->ds_is_snapshot
) {
5354 dsl_dataset_rele(new, FTAG
);
5355 error
= SET_ERROR(EINVAL
);
5358 dsl_pool_rele(dp
, FTAG
);
5361 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5362 if (error
== 0 && !old
->ds_is_snapshot
) {
5363 dsl_dataset_rele(old
, FTAG
);
5364 error
= SET_ERROR(EINVAL
);
5367 dsl_dataset_rele(new, FTAG
);
5368 dsl_pool_rele(dp
, FTAG
);
5372 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5373 dsl_dataset_rele(old
, FTAG
);
5374 dsl_dataset_rele(new, FTAG
);
5375 dsl_pool_rele(dp
, FTAG
);
5376 fnvlist_add_uint64(outnvl
, "used", used
);
5377 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5378 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5384 * "fd" -> file descriptor to write stream to (int32)
5385 * (optional) "fromsnap" -> full snap name to send an incremental from
5386 * (optional) "largeblockok" -> (value ignored)
5387 * indicates that blocks > 128KB are permitted
5388 * (optional) "embedok" -> (value ignored)
5389 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5390 * (optional) "compressok" -> (value ignored)
5391 * presence indicates compressed DRR_WRITE records are permitted
5392 * (optional) "resume_object" and "resume_offset" -> (uint64)
5393 * if present, resume send stream from specified object and offset.
5400 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5404 char *fromname
= NULL
;
5406 boolean_t largeblockok
;
5408 boolean_t compressok
;
5409 uint64_t resumeobj
= 0;
5410 uint64_t resumeoff
= 0;
5412 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5414 return (SET_ERROR(EINVAL
));
5416 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5418 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5419 embedok
= nvlist_exists(innvl
, "embedok");
5420 compressok
= nvlist_exists(innvl
, "compressok");
5422 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5423 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5425 file_t
*fp
= getf(fd
);
5427 return (SET_ERROR(EBADF
));
5430 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5431 fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5433 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5440 * Determine approximately how large a zfs send stream will be -- the number
5441 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5444 * (optional) "from" -> full snap or bookmark name to send an incremental
5446 * (optional) "largeblockok" -> (value ignored)
5447 * indicates that blocks > 128KB are permitted
5448 * (optional) "embedok" -> (value ignored)
5449 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5450 * (optional) "compressok" -> (value ignored)
5451 * presence indicates compressed DRR_WRITE records are permitted
5455 * "space" -> bytes of space (uint64)
5459 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5462 dsl_dataset_t
*tosnap
;
5465 /* LINTED E_FUNC_SET_NOT_USED */
5466 boolean_t largeblockok
;
5467 /* LINTED E_FUNC_SET_NOT_USED */
5469 boolean_t compressok
;
5472 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5476 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5478 dsl_pool_rele(dp
, FTAG
);
5482 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5483 embedok
= nvlist_exists(innvl
, "embedok");
5484 compressok
= nvlist_exists(innvl
, "compressok");
5486 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5488 if (strchr(fromname
, '@') != NULL
) {
5490 * If from is a snapshot, hold it and use the more
5491 * efficient dmu_send_estimate to estimate send space
5492 * size using deadlists.
5494 dsl_dataset_t
*fromsnap
;
5495 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5498 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
5500 dsl_dataset_rele(fromsnap
, FTAG
);
5501 } else if (strchr(fromname
, '#') != NULL
) {
5503 * If from is a bookmark, fetch the creation TXG of the
5504 * snapshot it was created from and use that to find
5505 * blocks that were born after it.
5507 zfs_bookmark_phys_t frombm
;
5509 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
5513 error
= dmu_send_estimate_from_txg(tosnap
,
5514 frombm
.zbm_creation_txg
, compressok
, &space
);
5517 * from is not properly formatted as a snapshot or
5520 error
= SET_ERROR(EINVAL
);
5524 // If estimating the size of a full send, use dmu_send_estimate
5525 error
= dmu_send_estimate(tosnap
, NULL
, compressok
, &space
);
5528 fnvlist_add_uint64(outnvl
, "space", space
);
5531 dsl_dataset_rele(tosnap
, FTAG
);
5532 dsl_pool_rele(dp
, FTAG
);
5536 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5539 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5540 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5541 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5543 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5545 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5546 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5547 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5548 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5550 vec
->zvec_legacy_func
= func
;
5551 vec
->zvec_secpolicy
= secpolicy
;
5552 vec
->zvec_namecheck
= namecheck
;
5553 vec
->zvec_allow_log
= log_history
;
5554 vec
->zvec_pool_check
= pool_check
;
5558 * See the block comment at the beginning of this file for details on
5559 * each argument to this function.
5562 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5563 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5564 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5565 boolean_t allow_log
)
5567 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5569 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5570 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5571 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5572 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5574 /* if we are logging, the name must be valid */
5575 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5577 vec
->zvec_name
= name
;
5578 vec
->zvec_func
= func
;
5579 vec
->zvec_secpolicy
= secpolicy
;
5580 vec
->zvec_namecheck
= namecheck
;
5581 vec
->zvec_pool_check
= pool_check
;
5582 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5583 vec
->zvec_allow_log
= allow_log
;
5587 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5588 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5589 zfs_ioc_poolcheck_t pool_check
)
5591 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5592 POOL_NAME
, log_history
, pool_check
);
5596 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5597 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5599 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5600 DATASET_NAME
, B_FALSE
, pool_check
);
5604 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5606 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5607 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5611 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5612 zfs_secpolicy_func_t
*secpolicy
)
5614 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5615 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5619 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5620 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5622 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5623 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5627 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5629 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5630 zfs_secpolicy_read
);
5634 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5635 zfs_secpolicy_func_t
*secpolicy
)
5637 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5638 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5642 zfs_ioctl_init(void)
5644 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5645 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5646 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5648 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5649 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5650 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5652 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5653 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5654 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5656 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5657 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5658 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5660 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5661 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5662 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5664 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5665 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5666 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5668 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5669 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5670 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5672 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5673 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5674 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5676 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
5677 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
5678 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5679 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
5680 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
5681 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5683 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
5684 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
5685 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5687 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
5688 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
5689 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
5691 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
5692 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
5693 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5695 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
5696 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
5697 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5699 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
5700 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
5702 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5704 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
5705 zfs_ioc_channel_program
, zfs_secpolicy_config
,
5706 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
5709 /* IOCTLS that use the legacy function signature */
5711 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5712 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5714 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5715 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5716 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5718 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5719 zfs_ioc_pool_upgrade
);
5720 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5722 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5723 zfs_ioc_vdev_remove
);
5724 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5725 zfs_ioc_vdev_set_state
);
5726 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5727 zfs_ioc_vdev_attach
);
5728 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5729 zfs_ioc_vdev_detach
);
5730 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5731 zfs_ioc_vdev_setpath
);
5732 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5733 zfs_ioc_vdev_setfru
);
5734 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5735 zfs_ioc_pool_set_props
);
5736 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5737 zfs_ioc_vdev_split
);
5738 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5739 zfs_ioc_pool_reguid
);
5741 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5742 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5743 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5744 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5745 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5746 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5747 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5748 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5749 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5750 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5753 * pool destroy, and export don't log the history as part of
5754 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5755 * does the logging of those commands.
5757 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5758 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5759 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5760 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5762 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5763 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5764 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5765 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5767 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5768 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5769 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5770 zfs_ioc_dsobj_to_dsname
,
5771 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5772 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5773 zfs_ioc_pool_get_history
,
5774 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5776 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5777 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5779 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5780 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5781 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5782 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5784 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5785 zfs_ioc_space_written
);
5786 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5787 zfs_ioc_objset_recvd_props
);
5788 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5790 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5792 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5793 zfs_ioc_objset_stats
);
5794 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5795 zfs_ioc_objset_zplprops
);
5796 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5797 zfs_ioc_dataset_list_next
);
5798 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5799 zfs_ioc_snapshot_list_next
);
5800 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5801 zfs_ioc_send_progress
);
5803 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5804 zfs_ioc_diff
, zfs_secpolicy_diff
);
5805 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5806 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5807 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5808 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5809 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5810 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5811 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5812 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5813 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5814 zfs_ioc_send
, zfs_secpolicy_send
);
5816 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5817 zfs_secpolicy_none
);
5818 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5819 zfs_secpolicy_destroy
);
5820 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5821 zfs_secpolicy_rename
);
5822 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5823 zfs_secpolicy_recv
);
5824 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5825 zfs_secpolicy_promote
);
5826 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5827 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5828 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5829 zfs_secpolicy_set_fsacl
);
5831 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5832 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5833 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5834 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5835 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5836 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5837 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5838 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5839 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5840 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5844 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5845 zfs_ioc_poolcheck_t check
)
5850 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5852 if (check
& POOL_CHECK_NONE
)
5855 error
= spa_open(name
, &spa
, FTAG
);
5857 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5858 error
= SET_ERROR(EAGAIN
);
5859 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5860 error
= SET_ERROR(EROFS
);
5861 spa_close(spa
, FTAG
);
5867 * Find a free minor number.
5870 zfsdev_minor_alloc(void)
5872 static minor_t last_minor
;
5875 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5877 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5878 if (m
> ZFSDEV_MAX_MINOR
)
5880 if (ddi_get_soft_state(zfsdev_state
, m
) == NULL
) {
5890 zfs_ctldev_init(dev_t
*devp
)
5893 zfs_soft_state_t
*zs
;
5895 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5896 ASSERT(getminor(*devp
) == 0);
5898 minor
= zfsdev_minor_alloc();
5900 return (SET_ERROR(ENXIO
));
5902 if (ddi_soft_state_zalloc(zfsdev_state
, minor
) != DDI_SUCCESS
)
5903 return (SET_ERROR(EAGAIN
));
5905 *devp
= makedevice(getemajor(*devp
), minor
);
5907 zs
= ddi_get_soft_state(zfsdev_state
, minor
);
5908 zs
->zss_type
= ZSST_CTLDEV
;
5909 zfs_onexit_init((zfs_onexit_t
**)&zs
->zss_data
);
5915 zfs_ctldev_destroy(zfs_onexit_t
*zo
, minor_t minor
)
5917 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5919 zfs_onexit_destroy(zo
);
5920 ddi_soft_state_free(zfsdev_state
, minor
);
5924 zfsdev_get_soft_state(minor_t minor
, enum zfs_soft_state_type which
)
5926 zfs_soft_state_t
*zp
;
5928 zp
= ddi_get_soft_state(zfsdev_state
, minor
);
5929 if (zp
== NULL
|| zp
->zss_type
!= which
)
5932 return (zp
->zss_data
);
5936 zfsdev_open(dev_t
*devp
, int flag
, int otyp
, cred_t
*cr
)
5940 if (getminor(*devp
) != 0)
5941 return (zvol_open(devp
, flag
, otyp
, cr
));
5943 /* This is the control device. Allocate a new minor if requested. */
5945 mutex_enter(&zfsdev_state_lock
);
5946 error
= zfs_ctldev_init(devp
);
5947 mutex_exit(&zfsdev_state_lock
);
5954 zfsdev_close(dev_t dev
, int flag
, int otyp
, cred_t
*cr
)
5957 minor_t minor
= getminor(dev
);
5962 mutex_enter(&zfsdev_state_lock
);
5963 zo
= zfsdev_get_soft_state(minor
, ZSST_CTLDEV
);
5965 mutex_exit(&zfsdev_state_lock
);
5966 return (zvol_close(dev
, flag
, otyp
, cr
));
5968 zfs_ctldev_destroy(zo
, minor
);
5969 mutex_exit(&zfsdev_state_lock
);
5975 zfsdev_ioctl(dev_t dev
, int cmd
, intptr_t arg
, int flag
, cred_t
*cr
, int *rvalp
)
5980 minor_t minor
= getminor(dev
);
5981 const zfs_ioc_vec_t
*vec
;
5982 char *saved_poolname
= NULL
;
5983 nvlist_t
*innvl
= NULL
;
5986 zfsdev_get_soft_state(minor
, ZSST_CTLDEV
) == NULL
)
5987 return (zvol_ioctl(dev
, cmd
, arg
, flag
, cr
, rvalp
));
5989 vecnum
= cmd
- ZFS_IOC_FIRST
;
5990 ASSERT3U(getmajor(dev
), ==, ddi_driver_major(zfs_dip
));
5992 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
5993 return (SET_ERROR(EINVAL
));
5994 vec
= &zfs_ioc_vec
[vecnum
];
5996 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
5998 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6000 error
= SET_ERROR(EFAULT
);
6004 zc
->zc_iflags
= flag
& FKIOCTL
;
6005 if (zc
->zc_nvlist_src_size
!= 0) {
6006 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6007 zc
->zc_iflags
, &innvl
);
6013 * Ensure that all pool/dataset names are valid before we pass down to
6016 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6017 switch (vec
->zvec_namecheck
) {
6019 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6020 error
= SET_ERROR(EINVAL
);
6022 error
= pool_status_check(zc
->zc_name
,
6023 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6027 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6028 error
= SET_ERROR(EINVAL
);
6030 error
= pool_status_check(zc
->zc_name
,
6031 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6040 error
= vec
->zvec_secpolicy(zc
, innvl
, cr
);
6045 /* legacy ioctls can modify zc_name */
6046 len
= strcspn(zc
->zc_name
, "/@#") + 1;
6047 saved_poolname
= kmem_alloc(len
, KM_SLEEP
);
6048 (void) strlcpy(saved_poolname
, zc
->zc_name
, len
);
6050 if (vec
->zvec_func
!= NULL
) {
6054 nvlist_t
*lognv
= NULL
;
6056 ASSERT(vec
->zvec_legacy_func
== NULL
);
6059 * Add the innvl to the lognv before calling the func,
6060 * in case the func changes the innvl.
6062 if (vec
->zvec_allow_log
) {
6063 lognv
= fnvlist_alloc();
6064 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6066 if (!nvlist_empty(innvl
)) {
6067 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6072 outnvl
= fnvlist_alloc();
6073 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6076 * Some commands can partially execute, modfiy state, and still
6077 * return an error. In these cases, attempt to record what
6081 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
6082 vec
->zvec_allow_log
&&
6083 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6084 if (!nvlist_empty(outnvl
)) {
6085 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6089 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
6092 (void) spa_history_log_nvl(spa
, lognv
);
6093 spa_close(spa
, FTAG
);
6095 fnvlist_free(lognv
);
6097 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6099 if (vec
->zvec_smush_outnvlist
) {
6100 smusherror
= nvlist_smush(outnvl
,
6101 zc
->zc_nvlist_dst_size
);
6103 if (smusherror
== 0)
6104 puterror
= put_nvlist(zc
, outnvl
);
6110 nvlist_free(outnvl
);
6112 error
= vec
->zvec_legacy_func(zc
);
6117 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6118 if (error
== 0 && rc
!= 0)
6119 error
= SET_ERROR(EFAULT
);
6120 if (error
== 0 && vec
->zvec_allow_log
) {
6121 char *s
= tsd_get(zfs_allow_log_key
);
6124 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6126 if (saved_poolname
!= NULL
)
6127 strfree(saved_poolname
);
6130 kmem_free(zc
, sizeof (zfs_cmd_t
));
6135 zfs_attach(dev_info_t
*dip
, ddi_attach_cmd_t cmd
)
6137 if (cmd
!= DDI_ATTACH
)
6138 return (DDI_FAILURE
);
6140 if (ddi_create_minor_node(dip
, "zfs", S_IFCHR
, 0,
6141 DDI_PSEUDO
, 0) == DDI_FAILURE
)
6142 return (DDI_FAILURE
);
6146 ddi_report_dev(dip
);
6148 return (DDI_SUCCESS
);
6152 zfs_detach(dev_info_t
*dip
, ddi_detach_cmd_t cmd
)
6154 if (spa_busy() || zfs_busy() || zvol_busy())
6155 return (DDI_FAILURE
);
6157 if (cmd
!= DDI_DETACH
)
6158 return (DDI_FAILURE
);
6162 ddi_prop_remove_all(dip
);
6163 ddi_remove_minor_node(dip
, NULL
);
6165 return (DDI_SUCCESS
);
6170 zfs_info(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
6173 case DDI_INFO_DEVT2DEVINFO
:
6175 return (DDI_SUCCESS
);
6177 case DDI_INFO_DEVT2INSTANCE
:
6179 return (DDI_SUCCESS
);
6182 return (DDI_FAILURE
);
6186 * OK, so this is a little weird.
6188 * /dev/zfs is the control node, i.e. minor 0.
6189 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
6191 * /dev/zfs has basically nothing to do except serve up ioctls,
6192 * so most of the standard driver entry points are in zvol.c.
6194 static struct cb_ops zfs_cb_ops
= {
6195 zfsdev_open
, /* open */
6196 zfsdev_close
, /* close */
6197 zvol_strategy
, /* strategy */
6199 zvol_dump
, /* dump */
6200 zvol_read
, /* read */
6201 zvol_write
, /* write */
6202 zfsdev_ioctl
, /* ioctl */
6206 nochpoll
, /* poll */
6207 ddi_prop_op
, /* prop_op */
6208 NULL
, /* streamtab */
6209 D_NEW
| D_MP
| D_64BIT
, /* Driver compatibility flag */
6210 CB_REV
, /* version */
6211 nodev
, /* async read */
6212 nodev
, /* async write */
6215 static struct dev_ops zfs_dev_ops
= {
6216 DEVO_REV
, /* version */
6218 zfs_info
, /* info */
6219 nulldev
, /* identify */
6220 nulldev
, /* probe */
6221 zfs_attach
, /* attach */
6222 zfs_detach
, /* detach */
6224 &zfs_cb_ops
, /* driver operations */
6225 NULL
, /* no bus operations */
6227 ddi_quiesce_not_needed
, /* quiesce */
6230 static struct modldrv zfs_modldrv
= {
6236 static struct modlinkage modlinkage
= {
6238 (void *)&zfs_modlfs
,
6239 (void *)&zfs_modldrv
,
6244 zfs_allow_log_destroy(void *arg
)
6246 char *poolname
= arg
;
6255 spa_init(FREAD
| FWRITE
);
6260 if ((error
= mod_install(&modlinkage
)) != 0) {
6267 tsd_create(&zfs_fsyncer_key
, NULL
);
6268 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
6269 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
6271 error
= ldi_ident_from_mod(&modlinkage
, &zfs_li
);
6273 mutex_init(&zfs_share_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6283 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled
)
6284 return (SET_ERROR(EBUSY
));
6286 if ((error
= mod_remove(&modlinkage
)) != 0)
6292 if (zfs_nfsshare_inited
)
6293 (void) ddi_modclose(nfs_mod
);
6294 if (zfs_smbshare_inited
)
6295 (void) ddi_modclose(smbsrv_mod
);
6296 if (zfs_nfsshare_inited
|| zfs_smbshare_inited
)
6297 (void) ddi_modclose(sharefs_mod
);
6299 tsd_destroy(&zfs_fsyncer_key
);
6300 ldi_ident_release(zfs_li
);
6302 mutex_destroy(&zfs_share_lock
);
6308 _info(struct modinfo
*modinfop
)
6310 return (mod_info(&modlinkage
, modinfop
));