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, 2017 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.
35 * Copyright (c) 2017 Datto Inc.
41 * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
42 * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
44 * There are two ways that we handle ioctls: the legacy way where almost
45 * all of the logic is in the ioctl callback, and the new way where most
46 * of the marshalling is handled in the common entry point, zfsdev_ioctl().
48 * Non-legacy ioctls should be registered by calling
49 * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
50 * from userland by lzc_ioctl().
52 * The registration arguments are as follows:
55 * The name of the ioctl. This is used for history logging. If the
56 * ioctl returns successfully (the callback returns 0), and allow_log
57 * is true, then a history log entry will be recorded with the input &
58 * output nvlists. The log entry can be printed with "zpool history -i".
61 * The ioctl request number, which userland will pass to ioctl(2).
62 * The ioctl numbers can change from release to release, because
63 * the caller (libzfs) must be matched to the kernel.
65 * zfs_secpolicy_func_t *secpolicy
66 * This function will be called before the zfs_ioc_func_t, to
67 * determine if this operation is permitted. It should return EPERM
68 * on failure, and 0 on success. Checks include determining if the
69 * dataset is visible in this zone, and if the user has either all
70 * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
71 * to do this operation on this dataset with "zfs allow".
73 * zfs_ioc_namecheck_t namecheck
74 * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
75 * name, a dataset name, or nothing. If the name is not well-formed,
76 * the ioctl will fail and the callback will not be called.
77 * Therefore, the callback can assume that the name is well-formed
78 * (e.g. is null-terminated, doesn't have more than one '@' character,
79 * doesn't have invalid characters).
81 * zfs_ioc_poolcheck_t pool_check
82 * This specifies requirements on the pool state. If the pool does
83 * not meet them (is suspended or is readonly), the ioctl will fail
84 * and the callback will not be called. If any checks are specified
85 * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
86 * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
87 * POOL_CHECK_READONLY).
89 * boolean_t smush_outnvlist
90 * If smush_outnvlist is true, then the output is presumed to be a
91 * list of errors, and it will be "smushed" down to fit into the
92 * caller's buffer, by removing some entries and replacing them with a
93 * single "N_MORE_ERRORS" entry indicating how many were removed. See
94 * nvlist_smush() for details. If smush_outnvlist is false, and the
95 * outnvlist does not fit into the userland-provided buffer, then the
96 * ioctl will fail with ENOMEM.
98 * zfs_ioc_func_t *func
99 * The callback function that will perform the operation.
101 * The callback should return 0 on success, or an error number on
102 * failure. If the function fails, the userland ioctl will return -1,
103 * and errno will be set to the callback's return value. The callback
104 * will be called with the following arguments:
107 * The name of the pool or dataset to operate on, from
108 * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
109 * expected type (pool, dataset, or none).
112 * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
113 * NULL if no input nvlist was provided. Changes to this nvlist are
114 * ignored. If the input nvlist could not be deserialized, the
115 * ioctl will fail and the callback will not be called.
118 * The output nvlist, initially empty. The callback can fill it in,
119 * and it will be returned to userland by serializing it into
120 * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
121 * fails (e.g. because the caller didn't supply a large enough
122 * buffer), then the overall ioctl will fail. See the
123 * 'smush_nvlist' argument above for additional behaviors.
125 * There are two typical uses of the output nvlist:
126 * - To return state, e.g. property values. In this case,
127 * smush_outnvlist should be false. If the buffer was not large
128 * enough, the caller will reallocate a larger buffer and try
131 * - To return multiple errors from an ioctl which makes on-disk
132 * changes. In this case, smush_outnvlist should be true.
133 * Ioctls which make on-disk modifications should generally not
134 * use the outnvl if they succeed, because the caller can not
135 * distinguish between the operation failing, and
136 * deserialization failing.
139 #include <sys/types.h>
140 #include <sys/param.h>
141 #include <sys/errno.h>
144 #include <sys/modctl.h>
145 #include <sys/open.h>
146 #include <sys/file.h>
147 #include <sys/kmem.h>
148 #include <sys/conf.h>
149 #include <sys/cmn_err.h>
150 #include <sys/stat.h>
151 #include <sys/zfs_ioctl.h>
152 #include <sys/zfs_vfsops.h>
153 #include <sys/zfs_znode.h>
156 #include <sys/spa_impl.h>
157 #include <sys/vdev.h>
158 #include <sys/priv_impl.h>
160 #include <sys/dsl_dir.h>
161 #include <sys/dsl_dataset.h>
162 #include <sys/dsl_prop.h>
163 #include <sys/dsl_deleg.h>
164 #include <sys/dmu_objset.h>
165 #include <sys/dmu_impl.h>
166 #include <sys/dmu_tx.h>
168 #include <sys/sunddi.h>
169 #include <sys/sunldi.h>
170 #include <sys/policy.h>
171 #include <sys/zone.h>
172 #include <sys/nvpair.h>
173 #include <sys/pathname.h>
174 #include <sys/mount.h>
176 #include <sys/fs/zfs.h>
177 #include <sys/zfs_ctldir.h>
178 #include <sys/zfs_dir.h>
179 #include <sys/zfs_onexit.h>
180 #include <sys/zvol.h>
181 #include <sys/dsl_scan.h>
182 #include <sharefs/share.h>
183 #include <sys/dmu_objset.h>
184 #include <sys/dmu_send.h>
185 #include <sys/dsl_destroy.h>
186 #include <sys/dsl_bookmark.h>
187 #include <sys/dsl_userhold.h>
188 #include <sys/zfeature.h>
190 #include <sys/zio_checksum.h>
192 #include "zfs_namecheck.h"
193 #include "zfs_prop.h"
194 #include "zfs_deleg.h"
195 #include "zfs_comutil.h"
200 extern struct modlfs zfs_modlfs
;
202 extern void zfs_init(void);
203 extern void zfs_fini(void);
205 ldi_ident_t zfs_li
= NULL
;
208 uint_t zfs_fsyncer_key
;
209 extern uint_t rrw_tsd_key
;
210 static uint_t zfs_allow_log_key
;
212 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
213 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
214 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
220 } zfs_ioc_namecheck_t
;
223 POOL_CHECK_NONE
= 1 << 0,
224 POOL_CHECK_SUSPENDED
= 1 << 1,
225 POOL_CHECK_READONLY
= 1 << 2,
226 } zfs_ioc_poolcheck_t
;
228 typedef struct zfs_ioc_vec
{
229 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
230 zfs_ioc_func_t
*zvec_func
;
231 zfs_secpolicy_func_t
*zvec_secpolicy
;
232 zfs_ioc_namecheck_t zvec_namecheck
;
233 boolean_t zvec_allow_log
;
234 zfs_ioc_poolcheck_t zvec_pool_check
;
235 boolean_t zvec_smush_outnvlist
;
236 const char *zvec_name
;
239 /* This array is indexed by zfs_userquota_prop_t */
240 static const char *userquota_perms
[] = {
241 ZFS_DELEG_PERM_USERUSED
,
242 ZFS_DELEG_PERM_USERQUOTA
,
243 ZFS_DELEG_PERM_GROUPUSED
,
244 ZFS_DELEG_PERM_GROUPQUOTA
,
247 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
248 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
250 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
252 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
254 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
255 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
257 static int zfs_prop_activate_feature(spa_t
*spa
, spa_feature_t feature
);
259 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
261 __dprintf(const char *file
, const char *func
, int line
, const char *fmt
, ...)
268 * Get rid of annoying "../common/" prefix to filename.
270 newfile
= strrchr(file
, '/');
271 if (newfile
!= NULL
) {
272 newfile
= newfile
+ 1; /* Get rid of leading / */
278 (void) vsnprintf(buf
, sizeof (buf
), fmt
, adx
);
282 * To get this data, use the zfs-dprintf probe as so:
283 * dtrace -q -n 'zfs-dprintf \
284 * /stringof(arg0) == "dbuf.c"/ \
285 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
287 * arg1 = function name
291 DTRACE_PROBE4(zfs__dprintf
,
292 char *, newfile
, char *, func
, int, line
, char *, buf
);
296 history_str_free(char *buf
)
298 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
302 history_str_get(zfs_cmd_t
*zc
)
306 if (zc
->zc_history
== (uintptr_t)NULL
)
309 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
310 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
311 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
312 history_str_free(buf
);
316 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
322 * Check to see if the named dataset is currently defined as bootable
325 zfs_is_bootfs(const char *name
)
329 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
331 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
332 dmu_objset_rele(os
, FTAG
);
339 * Return non-zero if the spa version is less than requested version.
342 zfs_earlier_version(const char *name
, int version
)
346 if (spa_open(name
, &spa
, FTAG
) == 0) {
347 if (spa_version(spa
) < version
) {
348 spa_close(spa
, FTAG
);
351 spa_close(spa
, FTAG
);
357 * Return TRUE if the ZPL version is less than requested version.
360 zpl_earlier_version(const char *name
, int version
)
363 boolean_t rc
= B_TRUE
;
365 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
368 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
369 dmu_objset_rele(os
, FTAG
);
372 /* XXX reading from non-owned objset */
373 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
374 rc
= zplversion
< version
;
375 dmu_objset_rele(os
, FTAG
);
381 zfs_log_history(zfs_cmd_t
*zc
)
386 if ((buf
= history_str_get(zc
)) == NULL
)
389 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
390 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
391 (void) spa_history_log(spa
, buf
);
392 spa_close(spa
, FTAG
);
394 history_str_free(buf
);
398 * Policy for top-level read operations (list pools). Requires no privileges,
399 * and can be used in the local zone, as there is no associated dataset.
403 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
409 * Policy for dataset read operations (list children, get statistics). Requires
410 * no privileges, but must be visible in the local zone.
414 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
416 if (INGLOBALZONE(curproc
) ||
417 zone_dataset_visible(zc
->zc_name
, NULL
))
420 return (SET_ERROR(ENOENT
));
424 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
429 * The dataset must be visible by this zone -- check this first
430 * so they don't see EPERM on something they shouldn't know about.
432 if (!INGLOBALZONE(curproc
) &&
433 !zone_dataset_visible(dataset
, &writable
))
434 return (SET_ERROR(ENOENT
));
436 if (INGLOBALZONE(curproc
)) {
438 * If the fs is zoned, only root can access it from the
441 if (secpolicy_zfs(cr
) && zoned
)
442 return (SET_ERROR(EPERM
));
445 * If we are in a local zone, the 'zoned' property must be set.
448 return (SET_ERROR(EPERM
));
450 /* must be writable by this zone */
452 return (SET_ERROR(EPERM
));
458 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
462 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
463 return (SET_ERROR(ENOENT
));
465 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
469 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
473 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
474 return (SET_ERROR(ENOENT
));
476 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
480 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
481 const char *perm
, cred_t
*cr
)
485 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
487 error
= secpolicy_zfs(cr
);
489 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
495 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
502 * First do a quick check for root in the global zone, which
503 * is allowed to do all write_perms. This ensures that zfs_ioc_*
504 * will get to handle nonexistent datasets.
506 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
509 error
= dsl_pool_hold(name
, FTAG
, &dp
);
513 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
515 dsl_pool_rele(dp
, FTAG
);
519 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
521 dsl_dataset_rele(ds
, FTAG
);
522 dsl_pool_rele(dp
, FTAG
);
527 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
533 * Check permissions for special properties.
538 * Disallow setting of 'zoned' from within a local zone.
540 if (!INGLOBALZONE(curproc
))
541 return (SET_ERROR(EPERM
));
545 case ZFS_PROP_FILESYSTEM_LIMIT
:
546 case ZFS_PROP_SNAPSHOT_LIMIT
:
547 if (!INGLOBALZONE(curproc
)) {
549 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
551 * Unprivileged users are allowed to modify the
552 * limit on things *under* (ie. contained by)
553 * the thing they own.
555 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
557 return (SET_ERROR(EPERM
));
558 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
559 return (SET_ERROR(EPERM
));
564 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
569 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
573 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
578 * permission to set permissions will be evaluated later in
579 * dsl_deleg_can_allow()
586 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
588 return (zfs_secpolicy_write_perms(zc
->zc_name
,
589 ZFS_DELEG_PERM_ROLLBACK
, cr
));
594 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
602 * Generate the current snapshot name from the given objsetid, then
603 * use that name for the secpolicy/zone checks.
605 cp
= strchr(zc
->zc_name
, '@');
607 return (SET_ERROR(EINVAL
));
608 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
612 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
614 dsl_pool_rele(dp
, FTAG
);
618 dsl_dataset_name(ds
, zc
->zc_name
);
620 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
621 ZFS_DELEG_PERM_SEND
, cr
);
622 dsl_dataset_rele(ds
, FTAG
);
623 dsl_pool_rele(dp
, FTAG
);
630 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
632 return (zfs_secpolicy_write_perms(zc
->zc_name
,
633 ZFS_DELEG_PERM_SEND
, cr
));
638 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
643 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
644 NO_FOLLOW
, NULL
, &vp
)) != 0)
647 /* Now make sure mntpnt and dataset are ZFS */
649 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
650 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
651 zc
->zc_name
) != 0)) {
653 return (SET_ERROR(EPERM
));
657 return (dsl_deleg_access(zc
->zc_name
,
658 ZFS_DELEG_PERM_SHARE
, cr
));
662 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
664 if (!INGLOBALZONE(curproc
))
665 return (SET_ERROR(EPERM
));
667 if (secpolicy_nfs(cr
) == 0) {
670 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
675 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
677 if (!INGLOBALZONE(curproc
))
678 return (SET_ERROR(EPERM
));
680 if (secpolicy_smb(cr
) == 0) {
683 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
688 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
693 * Remove the @bla or /bla from the end of the name to get the parent.
695 (void) strncpy(parent
, datasetname
, parentsize
);
696 cp
= strrchr(parent
, '@');
700 cp
= strrchr(parent
, '/');
702 return (SET_ERROR(ENOENT
));
710 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
714 if ((error
= zfs_secpolicy_write_perms(name
,
715 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
718 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
723 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
725 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
729 * Destroying snapshots with delegated permissions requires
730 * descendant mount and destroy permissions.
734 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
737 nvpair_t
*pair
, *nextpair
;
740 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
741 return (SET_ERROR(EINVAL
));
742 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
744 nextpair
= nvlist_next_nvpair(snaps
, pair
);
745 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
746 if (error
== ENOENT
) {
748 * Ignore any snapshots that don't exist (we consider
749 * them "already destroyed"). Remove the name from the
750 * nvl here in case the snapshot is created between
751 * now and when we try to destroy it (in which case
752 * we don't want to destroy it since we haven't
753 * checked for permission).
755 fnvlist_remove_nvpair(snaps
, pair
);
766 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
768 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
771 if ((error
= zfs_secpolicy_write_perms(from
,
772 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
775 if ((error
= zfs_secpolicy_write_perms(from
,
776 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
779 if ((error
= zfs_get_parent(to
, parentname
,
780 sizeof (parentname
))) != 0)
783 if ((error
= zfs_secpolicy_write_perms(parentname
,
784 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
787 if ((error
= zfs_secpolicy_write_perms(parentname
,
788 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
796 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
798 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
803 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
806 dsl_dataset_t
*clone
;
809 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
810 ZFS_DELEG_PERM_PROMOTE
, cr
);
814 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
818 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
821 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
822 dsl_dataset_t
*origin
= NULL
;
826 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
827 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
829 dsl_dataset_rele(clone
, FTAG
);
830 dsl_pool_rele(dp
, FTAG
);
834 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
835 ZFS_DELEG_PERM_MOUNT
, cr
);
837 dsl_dataset_name(origin
, parentname
);
839 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
840 ZFS_DELEG_PERM_PROMOTE
, cr
);
842 dsl_dataset_rele(clone
, FTAG
);
843 dsl_dataset_rele(origin
, FTAG
);
845 dsl_pool_rele(dp
, FTAG
);
851 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
855 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
856 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
859 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
860 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
863 return (zfs_secpolicy_write_perms(zc
->zc_name
,
864 ZFS_DELEG_PERM_CREATE
, cr
));
868 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
870 return (zfs_secpolicy_write_perms(name
,
871 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
875 * Check for permission to create each snapshot in the nvlist.
879 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
885 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
886 return (SET_ERROR(EINVAL
));
887 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
888 pair
= nvlist_next_nvpair(snaps
, pair
)) {
889 char *name
= nvpair_name(pair
);
890 char *atp
= strchr(name
, '@');
893 error
= SET_ERROR(EINVAL
);
897 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
906 * Check for permission to create each snapshot in the nvlist.
910 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
914 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
915 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
916 char *name
= nvpair_name(pair
);
917 char *hashp
= strchr(name
, '#');
920 error
= SET_ERROR(EINVAL
);
924 error
= zfs_secpolicy_write_perms(name
,
925 ZFS_DELEG_PERM_BOOKMARK
, cr
);
935 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
937 nvpair_t
*pair
, *nextpair
;
940 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
942 char *name
= nvpair_name(pair
);
943 char *hashp
= strchr(name
, '#');
944 nextpair
= nvlist_next_nvpair(innvl
, pair
);
947 error
= SET_ERROR(EINVAL
);
952 error
= zfs_secpolicy_write_perms(name
,
953 ZFS_DELEG_PERM_DESTROY
, cr
);
955 if (error
== ENOENT
) {
957 * Ignore any filesystems that don't exist (we consider
958 * their bookmarks "already destroyed"). Remove
959 * the name from the nvl here in case the filesystem
960 * is created between now and when we try to destroy
961 * the bookmark (in which case we don't want to
962 * destroy it since we haven't checked for permission).
964 fnvlist_remove_nvpair(innvl
, pair
);
976 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
979 * Even root must have a proper TSD so that we know what pool
982 if (tsd_get(zfs_allow_log_key
) == NULL
)
983 return (SET_ERROR(EPERM
));
988 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
990 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
994 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
995 sizeof (parentname
))) != 0)
998 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
999 (error
= zfs_secpolicy_write_perms(origin
,
1000 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1003 if ((error
= zfs_secpolicy_write_perms(parentname
,
1004 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1007 return (zfs_secpolicy_write_perms(parentname
,
1008 ZFS_DELEG_PERM_MOUNT
, cr
));
1012 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1013 * SYS_CONFIG privilege, which is not available in a local zone.
1017 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1019 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1020 return (SET_ERROR(EPERM
));
1026 * Policy for object to name lookups.
1030 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1034 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1037 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1042 * Policy for fault injection. Requires all privileges.
1046 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1048 return (secpolicy_zinject(cr
));
1053 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1055 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1057 if (prop
== ZPROP_INVAL
) {
1058 if (!zfs_prop_user(zc
->zc_value
))
1059 return (SET_ERROR(EINVAL
));
1060 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1061 ZFS_DELEG_PERM_USERPROP
, cr
));
1063 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1069 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1071 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1075 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1076 return (SET_ERROR(EINVAL
));
1078 if (zc
->zc_value
[0] == 0) {
1080 * They are asking about a posix uid/gid. If it's
1081 * themself, allow it.
1083 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1084 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
1085 if (zc
->zc_guid
== crgetuid(cr
))
1088 if (groupmember(zc
->zc_guid
, cr
))
1093 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1094 userquota_perms
[zc
->zc_objset_type
], cr
));
1098 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1100 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1104 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1105 return (SET_ERROR(EINVAL
));
1107 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1108 userquota_perms
[zc
->zc_objset_type
], cr
));
1113 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1115 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1121 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1127 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1129 return (SET_ERROR(EINVAL
));
1131 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1132 pair
= nvlist_next_nvpair(holds
, pair
)) {
1133 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1134 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1137 error
= zfs_secpolicy_write_perms(fsname
,
1138 ZFS_DELEG_PERM_HOLD
, cr
);
1147 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1152 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1153 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1154 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1155 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1158 error
= zfs_secpolicy_write_perms(fsname
,
1159 ZFS_DELEG_PERM_RELEASE
, cr
);
1167 * Policy for allowing temporary snapshots to be taken or released
1170 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1173 * A temporary snapshot is the same as a snapshot,
1174 * hold, destroy and release all rolled into one.
1175 * Delegated diff alone is sufficient that we allow this.
1179 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1180 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1183 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1185 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1187 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1189 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1194 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1197 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1201 nvlist_t
*list
= NULL
;
1204 * Read in and unpack the user-supplied nvlist.
1207 return (SET_ERROR(EINVAL
));
1209 packed
= kmem_alloc(size
, KM_SLEEP
);
1211 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1213 kmem_free(packed
, size
);
1214 return (SET_ERROR(EFAULT
));
1217 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1218 kmem_free(packed
, size
);
1222 kmem_free(packed
, size
);
1229 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1230 * Entries will be removed from the end of the nvlist, and one int32 entry
1231 * named "N_MORE_ERRORS" will be added indicating how many entries were
1235 nvlist_smush(nvlist_t
*errors
, size_t max
)
1239 size
= fnvlist_size(errors
);
1242 nvpair_t
*more_errors
;
1246 return (SET_ERROR(ENOMEM
));
1248 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1249 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1252 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1254 fnvlist_remove_nvpair(errors
, pair
);
1256 size
= fnvlist_size(errors
);
1257 } while (size
> max
);
1259 fnvlist_remove_nvpair(errors
, more_errors
);
1260 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1261 ASSERT3U(fnvlist_size(errors
), <=, max
);
1268 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1270 char *packed
= NULL
;
1274 size
= fnvlist_size(nvl
);
1276 if (size
> zc
->zc_nvlist_dst_size
) {
1277 error
= SET_ERROR(ENOMEM
);
1279 packed
= fnvlist_pack(nvl
, &size
);
1280 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1281 size
, zc
->zc_iflags
) != 0)
1282 error
= SET_ERROR(EFAULT
);
1283 fnvlist_pack_free(packed
, size
);
1286 zc
->zc_nvlist_dst_size
= size
;
1287 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1292 getzfsvfs_impl(objset_t
*os
, zfsvfs_t
**zfvp
)
1295 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1296 return (SET_ERROR(EINVAL
));
1299 mutex_enter(&os
->os_user_ptr_lock
);
1300 *zfvp
= dmu_objset_get_user(os
);
1302 VFS_HOLD((*zfvp
)->z_vfs
);
1304 error
= SET_ERROR(ESRCH
);
1306 mutex_exit(&os
->os_user_ptr_lock
);
1311 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1316 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1320 error
= getzfsvfs_impl(os
, zfvp
);
1321 dmu_objset_rele(os
, FTAG
);
1326 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1327 * case its z_vfs will be NULL, and it will be opened as the owner.
1328 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1329 * which prevents all vnode ops from running.
1332 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1336 if (getzfsvfs(name
, zfvp
) != 0)
1337 error
= zfsvfs_create(name
, zfvp
);
1339 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1341 if ((*zfvp
)->z_unmounted
) {
1343 * XXX we could probably try again, since the unmounting
1344 * thread should be just about to disassociate the
1345 * objset from the zfsvfs.
1347 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1348 return (SET_ERROR(EBUSY
));
1355 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1357 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1359 if (zfsvfs
->z_vfs
) {
1360 VFS_RELE(zfsvfs
->z_vfs
);
1362 dmu_objset_disown(zfsvfs
->z_os
, zfsvfs
);
1363 zfsvfs_free(zfsvfs
);
1368 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1371 nvlist_t
*config
, *props
= NULL
;
1372 nvlist_t
*rootprops
= NULL
;
1373 nvlist_t
*zplprops
= NULL
;
1375 if (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1376 zc
->zc_iflags
, &config
))
1379 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1380 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1381 zc
->zc_iflags
, &props
))) {
1382 nvlist_free(config
);
1387 nvlist_t
*nvl
= NULL
;
1388 uint64_t version
= SPA_VERSION
;
1390 (void) nvlist_lookup_uint64(props
,
1391 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1392 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1393 error
= SET_ERROR(EINVAL
);
1394 goto pool_props_bad
;
1396 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1398 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1400 nvlist_free(config
);
1404 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1406 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1407 error
= zfs_fill_zplprops_root(version
, rootprops
,
1410 goto pool_props_bad
;
1413 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1416 * Set the remaining root properties
1418 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1419 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1420 (void) spa_destroy(zc
->zc_name
);
1423 nvlist_free(rootprops
);
1424 nvlist_free(zplprops
);
1425 nvlist_free(config
);
1432 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1435 zfs_log_history(zc
);
1436 error
= spa_destroy(zc
->zc_name
);
1438 zvol_remove_minors(zc
->zc_name
);
1443 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1445 nvlist_t
*config
, *props
= NULL
;
1449 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1450 zc
->zc_iflags
, &config
)) != 0)
1453 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1454 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1455 zc
->zc_iflags
, &props
))) {
1456 nvlist_free(config
);
1460 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1461 guid
!= zc
->zc_guid
)
1462 error
= SET_ERROR(EINVAL
);
1464 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1466 if (zc
->zc_nvlist_dst
!= 0) {
1469 if ((err
= put_nvlist(zc
, config
)) != 0)
1473 nvlist_free(config
);
1481 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1484 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1485 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1487 zfs_log_history(zc
);
1488 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1490 zvol_remove_minors(zc
->zc_name
);
1495 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1500 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1501 return (SET_ERROR(EEXIST
));
1503 error
= put_nvlist(zc
, configs
);
1505 nvlist_free(configs
);
1512 * zc_name name of the pool
1515 * zc_cookie real errno
1516 * zc_nvlist_dst config nvlist
1517 * zc_nvlist_dst_size size of config nvlist
1520 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1526 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1527 sizeof (zc
->zc_value
));
1529 if (config
!= NULL
) {
1530 ret
= put_nvlist(zc
, config
);
1531 nvlist_free(config
);
1534 * The config may be present even if 'error' is non-zero.
1535 * In this case we return success, and preserve the real errno
1538 zc
->zc_cookie
= error
;
1547 * Try to import the given pool, returning pool stats as appropriate so that
1548 * user land knows which devices are available and overall pool health.
1551 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1553 nvlist_t
*tryconfig
, *config
;
1556 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1557 zc
->zc_iflags
, &tryconfig
)) != 0)
1560 config
= spa_tryimport(tryconfig
);
1562 nvlist_free(tryconfig
);
1565 return (SET_ERROR(EINVAL
));
1567 error
= put_nvlist(zc
, config
);
1568 nvlist_free(config
);
1575 * zc_name name of the pool
1576 * zc_cookie scan func (pool_scan_func_t)
1577 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1580 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1585 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1588 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1589 return (SET_ERROR(EINVAL
));
1591 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1592 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1593 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1594 error
= spa_scan_stop(spa
);
1596 error
= spa_scan(spa
, zc
->zc_cookie
);
1598 spa_close(spa
, FTAG
);
1604 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1609 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1612 spa_close(spa
, FTAG
);
1618 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1623 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1626 if (zc
->zc_cookie
< spa_version(spa
) ||
1627 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1628 spa_close(spa
, FTAG
);
1629 return (SET_ERROR(EINVAL
));
1632 spa_upgrade(spa
, zc
->zc_cookie
);
1633 spa_close(spa
, FTAG
);
1639 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1646 if ((size
= zc
->zc_history_len
) == 0)
1647 return (SET_ERROR(EINVAL
));
1649 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1652 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1653 spa_close(spa
, FTAG
);
1654 return (SET_ERROR(ENOTSUP
));
1657 hist_buf
= kmem_alloc(size
, KM_SLEEP
);
1658 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1659 &zc
->zc_history_len
, hist_buf
)) == 0) {
1660 error
= ddi_copyout(hist_buf
,
1661 (void *)(uintptr_t)zc
->zc_history
,
1662 zc
->zc_history_len
, zc
->zc_iflags
);
1665 spa_close(spa
, FTAG
);
1666 kmem_free(hist_buf
, size
);
1671 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1676 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1678 error
= spa_change_guid(spa
);
1679 spa_close(spa
, FTAG
);
1685 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1687 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1692 * zc_name name of filesystem
1693 * zc_obj object to find
1696 * zc_value name of object
1699 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1704 /* XXX reading from objset not owned */
1705 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1707 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1708 dmu_objset_rele(os
, FTAG
);
1709 return (SET_ERROR(EINVAL
));
1711 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1712 sizeof (zc
->zc_value
));
1713 dmu_objset_rele(os
, FTAG
);
1720 * zc_name name of filesystem
1721 * zc_obj object to find
1724 * zc_stat stats on object
1725 * zc_value path to object
1728 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1733 /* XXX reading from objset not owned */
1734 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1736 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1737 dmu_objset_rele(os
, FTAG
);
1738 return (SET_ERROR(EINVAL
));
1740 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1741 sizeof (zc
->zc_value
));
1742 dmu_objset_rele(os
, FTAG
);
1748 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1752 nvlist_t
*config
, **l2cache
, **spares
;
1753 uint_t nl2cache
= 0, nspares
= 0;
1755 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1759 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1760 zc
->zc_iflags
, &config
);
1761 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_L2CACHE
,
1762 &l2cache
, &nl2cache
);
1764 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_SPARES
,
1768 * A root pool with concatenated devices is not supported.
1769 * Thus, can not add a device to a root pool.
1771 * Intent log device can not be added to a rootpool because
1772 * during mountroot, zil is replayed, a seperated log device
1773 * can not be accessed during the mountroot time.
1775 * l2cache and spare devices are ok to be added to a rootpool.
1777 if (spa_bootfs(spa
) != 0 && nl2cache
== 0 && nspares
== 0) {
1778 nvlist_free(config
);
1779 spa_close(spa
, FTAG
);
1780 return (SET_ERROR(EDOM
));
1784 error
= spa_vdev_add(spa
, config
);
1785 nvlist_free(config
);
1787 spa_close(spa
, FTAG
);
1793 * zc_name name of the pool
1794 * zc_nvlist_conf nvlist of devices to remove
1795 * zc_cookie to stop the remove?
1798 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1803 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1806 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1807 spa_close(spa
, FTAG
);
1812 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1816 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1818 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1820 switch (zc
->zc_cookie
) {
1821 case VDEV_STATE_ONLINE
:
1822 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1825 case VDEV_STATE_OFFLINE
:
1826 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1829 case VDEV_STATE_FAULTED
:
1830 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1831 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1832 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1834 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1837 case VDEV_STATE_DEGRADED
:
1838 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1839 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1840 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1842 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1846 error
= SET_ERROR(EINVAL
);
1848 zc
->zc_cookie
= newstate
;
1849 spa_close(spa
, FTAG
);
1854 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1857 int replacing
= zc
->zc_cookie
;
1861 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1864 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1865 zc
->zc_iflags
, &config
)) == 0) {
1866 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1867 nvlist_free(config
);
1870 spa_close(spa
, FTAG
);
1875 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1880 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1883 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1885 spa_close(spa
, FTAG
);
1890 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1893 nvlist_t
*config
, *props
= NULL
;
1895 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1897 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1900 if (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1901 zc
->zc_iflags
, &config
)) {
1902 spa_close(spa
, FTAG
);
1906 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1907 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1908 zc
->zc_iflags
, &props
))) {
1909 spa_close(spa
, FTAG
);
1910 nvlist_free(config
);
1914 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1916 spa_close(spa
, FTAG
);
1918 nvlist_free(config
);
1925 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1928 char *path
= zc
->zc_value
;
1929 uint64_t guid
= zc
->zc_guid
;
1932 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1936 error
= spa_vdev_setpath(spa
, guid
, path
);
1937 spa_close(spa
, FTAG
);
1942 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1945 char *fru
= zc
->zc_value
;
1946 uint64_t guid
= zc
->zc_guid
;
1949 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1953 error
= spa_vdev_setfru(spa
, guid
, fru
);
1954 spa_close(spa
, FTAG
);
1959 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
1964 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1966 if (zc
->zc_nvlist_dst
!= 0 &&
1967 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
1968 dmu_objset_stats(os
, nv
);
1970 * NB: zvol_get_stats() will read the objset contents,
1971 * which we aren't supposed to do with a
1972 * DS_MODE_USER hold, because it could be
1973 * inconsistent. So this is a bit of a workaround...
1974 * XXX reading with out owning
1976 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
1977 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
1978 error
= zvol_get_stats(os
, nv
);
1983 error
= put_nvlist(zc
, nv
);
1992 * zc_name name of filesystem
1993 * zc_nvlist_dst_size size of buffer for property nvlist
1996 * zc_objset_stats stats
1997 * zc_nvlist_dst property nvlist
1998 * zc_nvlist_dst_size size of property nvlist
2001 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2006 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2008 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2009 dmu_objset_rele(os
, FTAG
);
2017 * zc_name name of filesystem
2018 * zc_nvlist_dst_size size of buffer for property nvlist
2021 * zc_nvlist_dst received property nvlist
2022 * zc_nvlist_dst_size size of received property nvlist
2024 * Gets received properties (distinct from local properties on or after
2025 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2026 * local property values.
2029 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2035 * Without this check, we would return local property values if the
2036 * caller has not already received properties on or after
2037 * SPA_VERSION_RECVD_PROPS.
2039 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2040 return (SET_ERROR(ENOTSUP
));
2042 if (zc
->zc_nvlist_dst
!= 0 &&
2043 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2044 error
= put_nvlist(zc
, nv
);
2052 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2058 * zfs_get_zplprop() will either find a value or give us
2059 * the default value (if there is one).
2061 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2063 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2069 * zc_name name of filesystem
2070 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2073 * zc_nvlist_dst zpl property nvlist
2074 * zc_nvlist_dst_size size of zpl property nvlist
2077 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2082 /* XXX reading without owning */
2083 if (err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))
2086 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2089 * NB: nvl_add_zplprop() will read the objset contents,
2090 * which we aren't supposed to do with a DS_MODE_USER
2091 * hold, because it could be inconsistent.
2093 if (zc
->zc_nvlist_dst
!= (uintptr_t)NULL
&&
2094 !zc
->zc_objset_stats
.dds_inconsistent
&&
2095 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2098 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2099 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2100 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2101 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2102 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2103 err
= put_nvlist(zc
, nv
);
2106 err
= SET_ERROR(ENOENT
);
2108 dmu_objset_rele(os
, FTAG
);
2113 dataset_name_hidden(const char *name
)
2116 * Skip over datasets that are not visible in this zone,
2117 * internal datasets (which have a $ in their name), and
2118 * temporary datasets (which have a % in their name).
2120 if (strchr(name
, '$') != NULL
)
2122 if (strchr(name
, '%') != NULL
)
2124 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2131 * zc_name name of filesystem
2132 * zc_cookie zap cursor
2133 * zc_nvlist_dst_size size of buffer for property nvlist
2136 * zc_name name of next filesystem
2137 * zc_cookie zap cursor
2138 * zc_objset_stats stats
2139 * zc_nvlist_dst property nvlist
2140 * zc_nvlist_dst_size size of property nvlist
2143 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2148 size_t orig_len
= strlen(zc
->zc_name
);
2151 if (error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) {
2152 if (error
== ENOENT
)
2153 error
= SET_ERROR(ESRCH
);
2157 p
= strrchr(zc
->zc_name
, '/');
2158 if (p
== NULL
|| p
[1] != '\0')
2159 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2160 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2163 error
= dmu_dir_list_next(os
,
2164 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2165 NULL
, &zc
->zc_cookie
);
2166 if (error
== ENOENT
)
2167 error
= SET_ERROR(ESRCH
);
2168 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2169 dmu_objset_rele(os
, FTAG
);
2172 * If it's an internal dataset (ie. with a '$' in its name),
2173 * don't try to get stats for it, otherwise we'll return ENOENT.
2175 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2176 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2177 if (error
== ENOENT
) {
2178 /* We lost a race with destroy, get the next one. */
2179 zc
->zc_name
[orig_len
] = '\0';
2188 * zc_name name of filesystem
2189 * zc_cookie zap cursor
2190 * zc_nvlist_dst_size size of buffer for property nvlist
2191 * zc_simple when set, only name is requested
2194 * zc_name name of next snapshot
2195 * zc_objset_stats stats
2196 * zc_nvlist_dst property nvlist
2197 * zc_nvlist_dst_size size of property nvlist
2200 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2205 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2207 return (error
== ENOENT
? ESRCH
: error
);
2211 * A dataset name of maximum length cannot have any snapshots,
2212 * so exit immediately.
2214 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2215 ZFS_MAX_DATASET_NAME_LEN
) {
2216 dmu_objset_rele(os
, FTAG
);
2217 return (SET_ERROR(ESRCH
));
2220 error
= dmu_snapshot_list_next(os
,
2221 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2222 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2225 if (error
== 0 && !zc
->zc_simple
) {
2227 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2229 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2233 error
= dmu_objset_from_ds(ds
, &ossnap
);
2235 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2236 dsl_dataset_rele(ds
, FTAG
);
2238 } else if (error
== ENOENT
) {
2239 error
= SET_ERROR(ESRCH
);
2242 dmu_objset_rele(os
, FTAG
);
2243 /* if we failed, undo the @ that we tacked on to zc_name */
2245 *strchr(zc
->zc_name
, '@') = '\0';
2250 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2252 const char *propname
= nvpair_name(pair
);
2254 unsigned int vallen
;
2257 zfs_userquota_prop_t type
;
2263 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2265 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2266 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2268 return (SET_ERROR(EINVAL
));
2272 * A correctly constructed propname is encoded as
2273 * userquota@<rid>-<domain>.
2275 if ((dash
= strchr(propname
, '-')) == NULL
||
2276 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2278 return (SET_ERROR(EINVAL
));
2285 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2287 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2288 zfsvfs_rele(zfsvfs
, FTAG
);
2295 * If the named property is one that has a special function to set its value,
2296 * return 0 on success and a positive error code on failure; otherwise if it is
2297 * not one of the special properties handled by this function, return -1.
2299 * XXX: It would be better for callers of the property interface if we handled
2300 * these special cases in dsl_prop.c (in the dsl layer).
2303 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2306 const char *propname
= nvpair_name(pair
);
2307 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2311 if (prop
== ZPROP_INVAL
) {
2312 if (zfs_prop_userquota(propname
))
2313 return (zfs_prop_set_userquota(dsname
, pair
));
2317 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2319 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2320 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2324 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2327 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2330 case ZFS_PROP_QUOTA
:
2331 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2333 case ZFS_PROP_REFQUOTA
:
2334 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2336 case ZFS_PROP_FILESYSTEM_LIMIT
:
2337 case ZFS_PROP_SNAPSHOT_LIMIT
:
2338 if (intval
== UINT64_MAX
) {
2339 /* clearing the limit, just do it */
2342 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2345 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2346 * default path to set the value in the nvlist.
2351 case ZFS_PROP_RESERVATION
:
2352 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2354 case ZFS_PROP_REFRESERVATION
:
2355 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2357 case ZFS_PROP_VOLSIZE
:
2358 err
= zvol_set_volsize(dsname
, intval
);
2360 case ZFS_PROP_VERSION
:
2364 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2367 err
= zfs_set_version(zfsvfs
, intval
);
2368 zfsvfs_rele(zfsvfs
, FTAG
);
2370 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2373 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2374 (void) strcpy(zc
->zc_name
, dsname
);
2375 (void) zfs_ioc_userspace_upgrade(zc
);
2376 kmem_free(zc
, sizeof (zfs_cmd_t
));
2388 * This function is best effort. If it fails to set any of the given properties,
2389 * it continues to set as many as it can and returns the last error
2390 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2391 * with the list of names of all the properties that failed along with the
2392 * corresponding error numbers.
2394 * If every property is set successfully, zero is returned and errlist is not
2398 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2406 nvlist_t
*genericnvl
= fnvlist_alloc();
2407 nvlist_t
*retrynvl
= fnvlist_alloc();
2411 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2412 const char *propname
= nvpair_name(pair
);
2413 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2416 /* decode the property value */
2418 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2420 attrs
= fnvpair_value_nvlist(pair
);
2421 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2423 err
= SET_ERROR(EINVAL
);
2426 /* Validate value type */
2427 if (err
== 0 && prop
== ZPROP_INVAL
) {
2428 if (zfs_prop_user(propname
)) {
2429 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2430 err
= SET_ERROR(EINVAL
);
2431 } else if (zfs_prop_userquota(propname
)) {
2432 if (nvpair_type(propval
) !=
2433 DATA_TYPE_UINT64_ARRAY
)
2434 err
= SET_ERROR(EINVAL
);
2436 err
= SET_ERROR(EINVAL
);
2438 } else if (err
== 0) {
2439 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2440 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2441 err
= SET_ERROR(EINVAL
);
2442 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2445 intval
= fnvpair_value_uint64(propval
);
2447 switch (zfs_prop_get_type(prop
)) {
2448 case PROP_TYPE_NUMBER
:
2450 case PROP_TYPE_STRING
:
2451 err
= SET_ERROR(EINVAL
);
2453 case PROP_TYPE_INDEX
:
2454 if (zfs_prop_index_to_string(prop
,
2455 intval
, &unused
) != 0)
2456 err
= SET_ERROR(EINVAL
);
2460 "unknown property type");
2463 err
= SET_ERROR(EINVAL
);
2467 /* Validate permissions */
2469 err
= zfs_check_settable(dsname
, pair
, CRED());
2472 err
= zfs_prop_set_special(dsname
, source
, pair
);
2475 * For better performance we build up a list of
2476 * properties to set in a single transaction.
2478 err
= nvlist_add_nvpair(genericnvl
, pair
);
2479 } else if (err
!= 0 && nvl
!= retrynvl
) {
2481 * This may be a spurious error caused by
2482 * receiving quota and reservation out of order.
2483 * Try again in a second pass.
2485 err
= nvlist_add_nvpair(retrynvl
, pair
);
2490 if (errlist
!= NULL
)
2491 fnvlist_add_int32(errlist
, propname
, err
);
2496 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2501 if (!nvlist_empty(genericnvl
) &&
2502 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2504 * If this fails, we still want to set as many properties as we
2505 * can, so try setting them individually.
2508 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2509 const char *propname
= nvpair_name(pair
);
2513 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2515 attrs
= fnvpair_value_nvlist(pair
);
2516 propval
= fnvlist_lookup_nvpair(attrs
,
2520 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2521 strval
= fnvpair_value_string(propval
);
2522 err
= dsl_prop_set_string(dsname
, propname
,
2525 intval
= fnvpair_value_uint64(propval
);
2526 err
= dsl_prop_set_int(dsname
, propname
, source
,
2531 if (errlist
!= NULL
) {
2532 fnvlist_add_int32(errlist
, propname
,
2539 nvlist_free(genericnvl
);
2540 nvlist_free(retrynvl
);
2546 * Check that all the properties are valid user properties.
2549 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2551 nvpair_t
*pair
= NULL
;
2554 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2555 const char *propname
= nvpair_name(pair
);
2557 if (!zfs_prop_user(propname
) ||
2558 nvpair_type(pair
) != DATA_TYPE_STRING
)
2559 return (SET_ERROR(EINVAL
));
2561 if (error
= zfs_secpolicy_write_perms(fsname
,
2562 ZFS_DELEG_PERM_USERPROP
, CRED()))
2565 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2566 return (SET_ERROR(ENAMETOOLONG
));
2568 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2575 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2579 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2582 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2583 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2586 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2591 clear_received_props(const char *dsname
, nvlist_t
*props
,
2595 nvlist_t
*cleared_props
= NULL
;
2596 props_skip(props
, skipped
, &cleared_props
);
2597 if (!nvlist_empty(cleared_props
)) {
2599 * Acts on local properties until the dataset has received
2600 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2602 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2603 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2604 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2606 nvlist_free(cleared_props
);
2612 * zc_name name of filesystem
2613 * zc_value name of property to set
2614 * zc_nvlist_src{_size} nvlist of properties to apply
2615 * zc_cookie received properties flag
2618 * zc_nvlist_dst{_size} error for each unapplied received property
2621 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2624 boolean_t received
= zc
->zc_cookie
;
2625 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2630 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2631 zc
->zc_iflags
, &nvl
)) != 0)
2635 nvlist_t
*origprops
;
2637 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2638 (void) clear_received_props(zc
->zc_name
,
2640 nvlist_free(origprops
);
2643 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2646 errors
= fnvlist_alloc();
2648 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2650 if (zc
->zc_nvlist_dst
!= (uintptr_t)NULL
&& errors
!= NULL
) {
2651 (void) put_nvlist(zc
, errors
);
2654 nvlist_free(errors
);
2661 * zc_name name of filesystem
2662 * zc_value name of property to inherit
2663 * zc_cookie revert to received value if TRUE
2668 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2670 const char *propname
= zc
->zc_value
;
2671 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2672 boolean_t received
= zc
->zc_cookie
;
2673 zprop_source_t source
= (received
2674 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2675 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2684 * zfs_prop_set_special() expects properties in the form of an
2685 * nvpair with type info.
2687 if (prop
== ZPROP_INVAL
) {
2688 if (!zfs_prop_user(propname
))
2689 return (SET_ERROR(EINVAL
));
2691 type
= PROP_TYPE_STRING
;
2692 } else if (prop
== ZFS_PROP_VOLSIZE
||
2693 prop
== ZFS_PROP_VERSION
) {
2694 return (SET_ERROR(EINVAL
));
2696 type
= zfs_prop_get_type(prop
);
2699 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2702 case PROP_TYPE_STRING
:
2703 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2705 case PROP_TYPE_NUMBER
:
2706 case PROP_TYPE_INDEX
:
2707 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2711 return (SET_ERROR(EINVAL
));
2714 pair
= nvlist_next_nvpair(dummy
, NULL
);
2715 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2718 return (err
); /* special property already handled */
2721 * Only check this in the non-received case. We want to allow
2722 * 'inherit -S' to revert non-inheritable properties like quota
2723 * and reservation to the received or default values even though
2724 * they are not considered inheritable.
2726 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2727 return (SET_ERROR(EINVAL
));
2730 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2731 return (dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
, source
));
2735 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2742 if (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2743 zc
->zc_iflags
, &props
))
2747 * If the only property is the configfile, then just do a spa_lookup()
2748 * to handle the faulted case.
2750 pair
= nvlist_next_nvpair(props
, NULL
);
2751 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2752 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2753 nvlist_next_nvpair(props
, pair
) == NULL
) {
2754 mutex_enter(&spa_namespace_lock
);
2755 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2756 spa_configfile_set(spa
, props
, B_FALSE
);
2757 spa_config_sync(spa
, B_FALSE
, B_TRUE
);
2759 mutex_exit(&spa_namespace_lock
);
2766 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2771 error
= spa_prop_set(spa
, props
);
2774 spa_close(spa
, FTAG
);
2780 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2784 nvlist_t
*nvp
= NULL
;
2786 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2788 * If the pool is faulted, there may be properties we can still
2789 * get (such as altroot and cachefile), so attempt to get them
2792 mutex_enter(&spa_namespace_lock
);
2793 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2794 error
= spa_prop_get(spa
, &nvp
);
2795 mutex_exit(&spa_namespace_lock
);
2797 error
= spa_prop_get(spa
, &nvp
);
2798 spa_close(spa
, FTAG
);
2801 if (error
== 0 && zc
->zc_nvlist_dst
!= (uintptr_t)NULL
)
2802 error
= put_nvlist(zc
, nvp
);
2804 error
= SET_ERROR(EFAULT
);
2812 * zc_name name of filesystem
2813 * zc_nvlist_src{_size} nvlist of delegated permissions
2814 * zc_perm_action allow/unallow flag
2819 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2822 nvlist_t
*fsaclnv
= NULL
;
2824 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2825 zc
->zc_iflags
, &fsaclnv
)) != 0)
2829 * Verify nvlist is constructed correctly
2831 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2832 nvlist_free(fsaclnv
);
2833 return (SET_ERROR(EINVAL
));
2837 * If we don't have PRIV_SYS_MOUNT, then validate
2838 * that user is allowed to hand out each permission in
2842 error
= secpolicy_zfs(CRED());
2844 if (zc
->zc_perm_action
== B_FALSE
) {
2845 error
= dsl_deleg_can_allow(zc
->zc_name
,
2848 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2854 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2856 nvlist_free(fsaclnv
);
2862 * zc_name name of filesystem
2865 * zc_nvlist_src{_size} nvlist of delegated permissions
2868 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2873 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2874 error
= put_nvlist(zc
, nvp
);
2883 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2885 zfs_creat_t
*zct
= arg
;
2887 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2890 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2894 * os parent objset pointer (NULL if root fs)
2895 * fuids_ok fuids allowed in this version of the spa?
2896 * sa_ok SAs allowed in this version of the spa?
2897 * createprops list of properties requested by creator
2900 * zplprops values for the zplprops we attach to the master node object
2901 * is_ci true if requested file system will be purely case-insensitive
2903 * Determine the settings for utf8only, normalization and
2904 * casesensitivity. Specific values may have been requested by the
2905 * creator and/or we can inherit values from the parent dataset. If
2906 * the file system is of too early a vintage, a creator can not
2907 * request settings for these properties, even if the requested
2908 * setting is the default value. We don't actually want to create dsl
2909 * properties for these, so remove them from the source nvlist after
2913 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2914 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2915 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2917 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2918 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2919 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2921 ASSERT(zplprops
!= NULL
);
2923 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
2924 return (SET_ERROR(EINVAL
));
2927 * Pull out creator prop choices, if any.
2930 (void) nvlist_lookup_uint64(createprops
,
2931 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2932 (void) nvlist_lookup_uint64(createprops
,
2933 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2934 (void) nvlist_remove_all(createprops
,
2935 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2936 (void) nvlist_lookup_uint64(createprops
,
2937 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2938 (void) nvlist_remove_all(createprops
,
2939 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2940 (void) nvlist_lookup_uint64(createprops
,
2941 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2942 (void) nvlist_remove_all(createprops
,
2943 zfs_prop_to_name(ZFS_PROP_CASE
));
2947 * If the zpl version requested is whacky or the file system
2948 * or pool is version is too "young" to support normalization
2949 * and the creator tried to set a value for one of the props,
2952 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
2953 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
2954 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
2955 (zplver
< ZPL_VERSION_NORMALIZATION
&&
2956 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
2957 sense
!= ZFS_PROP_UNDEFINED
)))
2958 return (SET_ERROR(ENOTSUP
));
2961 * Put the version in the zplprops
2963 VERIFY(nvlist_add_uint64(zplprops
,
2964 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
2966 if (norm
== ZFS_PROP_UNDEFINED
)
2967 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
) == 0);
2968 VERIFY(nvlist_add_uint64(zplprops
,
2969 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
2972 * If we're normalizing, names must always be valid UTF-8 strings.
2976 if (u8
== ZFS_PROP_UNDEFINED
)
2977 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
) == 0);
2978 VERIFY(nvlist_add_uint64(zplprops
,
2979 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
2981 if (sense
== ZFS_PROP_UNDEFINED
)
2982 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
) == 0);
2983 VERIFY(nvlist_add_uint64(zplprops
,
2984 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
2987 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
2993 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
2994 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2996 boolean_t fuids_ok
, sa_ok
;
2997 uint64_t zplver
= ZPL_VERSION
;
2998 objset_t
*os
= NULL
;
2999 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3005 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3006 cp
= strrchr(parentname
, '/');
3010 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3013 spa_vers
= spa_version(spa
);
3014 spa_close(spa
, FTAG
);
3016 zplver
= zfs_zpl_version_map(spa_vers
);
3017 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3018 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3021 * Open parent object set so we can inherit zplprop values.
3023 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3026 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3028 dmu_objset_rele(os
, FTAG
);
3033 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3034 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3038 uint64_t zplver
= ZPL_VERSION
;
3041 zplver
= zfs_zpl_version_map(spa_vers
);
3042 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3043 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3045 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3046 createprops
, zplprops
, is_ci
);
3052 * "type" -> dmu_objset_type_t (int32)
3053 * (optional) "props" -> { prop -> value }
3056 * outnvl: propname -> error code (int32)
3059 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3062 zfs_creat_t zct
= { 0 };
3063 nvlist_t
*nvprops
= NULL
;
3064 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3066 dmu_objset_type_t type
;
3067 boolean_t is_insensitive
= B_FALSE
;
3069 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3070 return (SET_ERROR(EINVAL
));
3072 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3076 cbfunc
= zfs_create_cb
;
3080 cbfunc
= zvol_create_cb
;
3087 if (strchr(fsname
, '@') ||
3088 strchr(fsname
, '%'))
3089 return (SET_ERROR(EINVAL
));
3091 zct
.zct_props
= nvprops
;
3094 return (SET_ERROR(EINVAL
));
3096 if (type
== DMU_OST_ZVOL
) {
3097 uint64_t volsize
, volblocksize
;
3099 if (nvprops
== NULL
)
3100 return (SET_ERROR(EINVAL
));
3101 if (nvlist_lookup_uint64(nvprops
,
3102 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3103 return (SET_ERROR(EINVAL
));
3105 if ((error
= nvlist_lookup_uint64(nvprops
,
3106 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3107 &volblocksize
)) != 0 && error
!= ENOENT
)
3108 return (SET_ERROR(EINVAL
));
3111 volblocksize
= zfs_prop_default_numeric(
3112 ZFS_PROP_VOLBLOCKSIZE
);
3114 if ((error
= zvol_check_volblocksize(
3115 volblocksize
)) != 0 ||
3116 (error
= zvol_check_volsize(volsize
,
3117 volblocksize
)) != 0)
3119 } else if (type
== DMU_OST_ZFS
) {
3123 * We have to have normalization and
3124 * case-folding flags correct when we do the
3125 * file system creation, so go figure them out
3128 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3129 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3130 error
= zfs_fill_zplprops(fsname
, nvprops
,
3131 zct
.zct_zplprops
, &is_insensitive
);
3133 nvlist_free(zct
.zct_zplprops
);
3138 error
= dmu_objset_create(fsname
, type
,
3139 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3140 nvlist_free(zct
.zct_zplprops
);
3143 * It would be nice to do this atomically.
3146 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3149 (void) dsl_destroy_head(fsname
);
3156 * "origin" -> name of origin snapshot
3157 * (optional) "props" -> { prop -> value }
3160 * outnvl: propname -> error code (int32)
3163 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3166 nvlist_t
*nvprops
= NULL
;
3169 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3170 return (SET_ERROR(EINVAL
));
3171 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3173 if (strchr(fsname
, '@') ||
3174 strchr(fsname
, '%'))
3175 return (SET_ERROR(EINVAL
));
3177 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3178 return (SET_ERROR(EINVAL
));
3179 error
= dmu_objset_clone(fsname
, origin_name
);
3184 * It would be nice to do this atomically.
3187 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3190 (void) dsl_destroy_head(fsname
);
3197 * "snaps" -> { snapshot1, snapshot2 }
3198 * (optional) "props" -> { prop -> value (string) }
3201 * outnvl: snapshot -> error code (int32)
3204 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3207 nvlist_t
*props
= NULL
;
3211 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3212 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3215 if (!nvlist_empty(props
) &&
3216 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3217 return (SET_ERROR(ENOTSUP
));
3219 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3220 return (SET_ERROR(EINVAL
));
3221 poollen
= strlen(poolname
);
3222 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3223 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3224 const char *name
= nvpair_name(pair
);
3225 const char *cp
= strchr(name
, '@');
3228 * The snap name must contain an @, and the part after it must
3229 * contain only valid characters.
3232 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3233 return (SET_ERROR(EINVAL
));
3236 * The snap must be in the specified pool.
3238 if (strncmp(name
, poolname
, poollen
) != 0 ||
3239 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3240 return (SET_ERROR(EXDEV
));
3242 /* This must be the only snap of this fs. */
3243 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3244 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3245 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3247 return (SET_ERROR(EXDEV
));
3252 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3257 * innvl: "message" -> string
3261 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3269 * The poolname in the ioctl is not set, we get it from the TSD,
3270 * which was set at the end of the last successful ioctl that allows
3271 * logging. The secpolicy func already checked that it is set.
3272 * Only one log ioctl is allowed after each successful ioctl, so
3273 * we clear the TSD here.
3275 poolname
= tsd_get(zfs_allow_log_key
);
3276 (void) tsd_set(zfs_allow_log_key
, NULL
);
3277 error
= spa_open(poolname
, &spa
, FTAG
);
3282 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3283 spa_close(spa
, FTAG
);
3284 return (SET_ERROR(EINVAL
));
3287 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3288 spa_close(spa
, FTAG
);
3289 return (SET_ERROR(ENOTSUP
));
3292 error
= spa_history_log(spa
, message
);
3293 spa_close(spa
, FTAG
);
3298 * The dp_config_rwlock must not be held when calling this, because the
3299 * unmount may need to write out data.
3301 * This function is best-effort. Callers must deal gracefully if it
3302 * remains mounted (or is remounted after this call).
3304 * Returns 0 if the argument is not a snapshot, or it is not currently a
3305 * filesystem, or we were able to unmount it. Returns error code otherwise.
3308 zfs_unmount_snap(const char *snapname
)
3311 zfsvfs_t
*zfsvfs
= NULL
;
3313 if (strchr(snapname
, '@') == NULL
)
3316 int err
= getzfsvfs(snapname
, &zfsvfs
);
3318 ASSERT3P(zfsvfs
, ==, NULL
);
3321 vfsp
= zfsvfs
->z_vfs
;
3323 ASSERT(!dsl_pool_config_held(dmu_objset_pool(zfsvfs
->z_os
)));
3325 err
= vn_vfswlock(vfsp
->vfs_vnodecovered
);
3331 * Always force the unmount for snapshots.
3333 (void) dounmount(vfsp
, MS_FORCE
, kcred
);
3338 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3340 zfs_unmount_snap(snapname
);
3345 * When a clone is destroyed, its origin may also need to be destroyed,
3346 * in which case it must be unmounted. This routine will do that unmount
3350 zfs_destroy_unmount_origin(const char *fsname
)
3356 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3359 ds
= dmu_objset_ds(os
);
3360 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3361 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3362 dsl_dataset_name(ds
->ds_prev
, originname
);
3363 dmu_objset_rele(os
, FTAG
);
3364 zfs_unmount_snap(originname
);
3366 dmu_objset_rele(os
, FTAG
);
3372 * "snaps" -> { snapshot1, snapshot2 }
3373 * (optional boolean) "defer"
3376 * outnvl: snapshot -> error code (int32)
3381 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3387 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3388 return (SET_ERROR(EINVAL
));
3389 defer
= nvlist_exists(innvl
, "defer");
3391 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3392 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3393 zfs_unmount_snap(nvpair_name(pair
));
3396 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3400 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3401 * All bookmarks must be in the same pool.
3404 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3407 * outnvl: bookmark -> error code (int32)
3412 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3414 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3415 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3419 * Verify the snapshot argument.
3421 if (nvpair_value_string(pair
, &snap_name
) != 0)
3422 return (SET_ERROR(EINVAL
));
3425 /* Verify that the keys (bookmarks) are unique */
3426 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3427 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3428 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3429 return (SET_ERROR(EINVAL
));
3433 return (dsl_bookmark_create(innvl
, outnvl
));
3438 * property 1, property 2, ...
3442 * bookmark name 1 -> { property 1, property 2, ... },
3443 * bookmark name 2 -> { property 1, property 2, ... }
3448 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3450 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3455 * bookmark name 1, bookmark name 2
3458 * outnvl: bookmark -> error code (int32)
3462 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3467 poollen
= strlen(poolname
);
3468 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3469 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3470 const char *name
= nvpair_name(pair
);
3471 const char *cp
= strchr(name
, '#');
3474 * The bookmark name must contain an #, and the part after it
3475 * must contain only valid characters.
3478 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3479 return (SET_ERROR(EINVAL
));
3482 * The bookmark must be in the specified pool.
3484 if (strncmp(name
, poolname
, poollen
) != 0 ||
3485 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3486 return (SET_ERROR(EXDEV
));
3489 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3494 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3498 uint64_t instrlimit
, memlimit
;
3499 nvpair_t
*nvarg
= NULL
;
3501 if (0 != nvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
, &program
)) {
3504 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3505 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3507 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3508 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3510 if (0 != nvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
, &nvarg
)) {
3514 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3516 if (memlimit
== 0 || memlimit
> zfs_lua_max_memlimit
)
3519 return (zcp_eval(poolname
, program
, instrlimit
, memlimit
,
3525 * zc_name name of dataset to destroy
3526 * zc_objset_type type of objset
3527 * zc_defer_destroy mark for deferred destroy
3532 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3536 if (zc
->zc_objset_type
== DMU_OST_ZFS
)
3537 zfs_unmount_snap(zc
->zc_name
);
3539 if (strchr(zc
->zc_name
, '@'))
3540 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3542 err
= dsl_destroy_head(zc
->zc_name
);
3543 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3544 (void) zvol_remove_minor(zc
->zc_name
);
3549 * fsname is name of dataset to rollback (to most recent snapshot)
3551 * innvl may contain name of expected target snapshot
3553 * outnvl: "target" -> name of most recent snapshot
3558 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3561 char *target
= NULL
;
3564 (void) nvlist_lookup_string(innvl
, "target", &target
);
3565 if (target
!= NULL
) {
3566 int fslen
= strlen(fsname
);
3568 if (strncmp(fsname
, target
, fslen
) != 0)
3569 return (SET_ERROR(EINVAL
));
3570 if (target
[fslen
] != '@')
3571 return (SET_ERROR(EINVAL
));
3574 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3577 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3578 error
= zfs_suspend_fs(zfsvfs
);
3582 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3584 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3585 error
= error
? error
: resume_err
;
3587 VFS_RELE(zfsvfs
->z_vfs
);
3589 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3595 recursive_unmount(const char *fsname
, void *arg
)
3597 const char *snapname
= arg
;
3598 char fullname
[ZFS_MAX_DATASET_NAME_LEN
];
3600 (void) snprintf(fullname
, sizeof (fullname
), "%s@%s", fsname
, snapname
);
3601 zfs_unmount_snap(fullname
);
3608 * zc_name old name of dataset
3609 * zc_value new name of dataset
3610 * zc_cookie recursive flag (only valid for snapshots)
3615 zfs_ioc_rename(zfs_cmd_t
*zc
)
3617 boolean_t recursive
= zc
->zc_cookie
& 1;
3620 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3621 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3622 strchr(zc
->zc_value
, '%'))
3623 return (SET_ERROR(EINVAL
));
3625 at
= strchr(zc
->zc_name
, '@');
3627 /* snaps must be in same fs */
3630 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3631 return (SET_ERROR(EXDEV
));
3633 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3634 error
= dmu_objset_find(zc
->zc_name
,
3635 recursive_unmount
, at
+ 1,
3636 recursive
? DS_FIND_CHILDREN
: 0);
3642 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3643 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3648 if (zc
->zc_objset_type
== DMU_OST_ZVOL
)
3649 (void) zvol_remove_minor(zc
->zc_name
);
3650 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3655 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3657 const char *propname
= nvpair_name(pair
);
3658 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3659 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3663 if (prop
== ZPROP_INVAL
) {
3664 if (zfs_prop_user(propname
)) {
3665 if (err
= zfs_secpolicy_write_perms(dsname
,
3666 ZFS_DELEG_PERM_USERPROP
, cr
))
3671 if (!issnap
&& zfs_prop_userquota(propname
)) {
3672 const char *perm
= NULL
;
3673 const char *uq_prefix
=
3674 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3675 const char *gq_prefix
=
3676 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3678 if (strncmp(propname
, uq_prefix
,
3679 strlen(uq_prefix
)) == 0) {
3680 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3681 } else if (strncmp(propname
, gq_prefix
,
3682 strlen(gq_prefix
)) == 0) {
3683 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3685 /* USERUSED and GROUPUSED are read-only */
3686 return (SET_ERROR(EINVAL
));
3689 if (err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
))
3694 return (SET_ERROR(EINVAL
));
3698 return (SET_ERROR(EINVAL
));
3700 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3702 * dsl_prop_get_all_impl() returns properties in this
3706 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3707 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3712 * Check that this value is valid for this pool version
3715 case ZFS_PROP_COMPRESSION
:
3717 * If the user specified gzip compression, make sure
3718 * the SPA supports it. We ignore any errors here since
3719 * we'll catch them later.
3721 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3722 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3723 intval
<= ZIO_COMPRESS_GZIP_9
&&
3724 zfs_earlier_version(dsname
,
3725 SPA_VERSION_GZIP_COMPRESSION
)) {
3726 return (SET_ERROR(ENOTSUP
));
3729 if (intval
== ZIO_COMPRESS_ZLE
&&
3730 zfs_earlier_version(dsname
,
3731 SPA_VERSION_ZLE_COMPRESSION
))
3732 return (SET_ERROR(ENOTSUP
));
3734 if (intval
== ZIO_COMPRESS_LZ4
) {
3737 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3740 if (!spa_feature_is_enabled(spa
,
3741 SPA_FEATURE_LZ4_COMPRESS
)) {
3742 spa_close(spa
, FTAG
);
3743 return (SET_ERROR(ENOTSUP
));
3745 spa_close(spa
, FTAG
);
3749 * If this is a bootable dataset then
3750 * verify that the compression algorithm
3751 * is supported for booting. We must return
3752 * something other than ENOTSUP since it
3753 * implies a downrev pool version.
3755 if (zfs_is_bootfs(dsname
) &&
3756 !BOOTFS_COMPRESS_VALID(intval
)) {
3757 return (SET_ERROR(ERANGE
));
3762 case ZFS_PROP_COPIES
:
3763 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3764 return (SET_ERROR(ENOTSUP
));
3767 case ZFS_PROP_RECORDSIZE
:
3768 /* Record sizes above 128k need the feature to be enabled */
3769 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3770 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3774 * We don't allow setting the property above 1MB,
3775 * unless the tunable has been changed.
3777 if (intval
> zfs_max_recordsize
||
3778 intval
> SPA_MAXBLOCKSIZE
)
3779 return (SET_ERROR(ERANGE
));
3781 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3784 if (!spa_feature_is_enabled(spa
,
3785 SPA_FEATURE_LARGE_BLOCKS
)) {
3786 spa_close(spa
, FTAG
);
3787 return (SET_ERROR(ENOTSUP
));
3789 spa_close(spa
, FTAG
);
3793 case ZFS_PROP_SHARESMB
:
3794 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3795 return (SET_ERROR(ENOTSUP
));
3798 case ZFS_PROP_ACLINHERIT
:
3799 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3800 nvpair_value_uint64(pair
, &intval
) == 0) {
3801 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3802 zfs_earlier_version(dsname
,
3803 SPA_VERSION_PASSTHROUGH_X
))
3804 return (SET_ERROR(ENOTSUP
));
3808 case ZFS_PROP_CHECKSUM
:
3809 case ZFS_PROP_DEDUP
:
3811 spa_feature_t feature
;
3814 /* dedup feature version checks */
3815 if (prop
== ZFS_PROP_DEDUP
&&
3816 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3817 return (SET_ERROR(ENOTSUP
));
3819 if (nvpair_value_uint64(pair
, &intval
) != 0)
3820 return (SET_ERROR(EINVAL
));
3822 /* check prop value is enabled in features */
3823 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
3824 if (feature
== SPA_FEATURE_NONE
)
3827 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3830 * Salted checksums are not supported on root pools.
3832 if (spa_bootfs(spa
) != 0 &&
3833 intval
< ZIO_CHECKSUM_FUNCTIONS
&&
3834 (zio_checksum_table
[intval
].ci_flags
&
3835 ZCHECKSUM_FLAG_SALTED
)) {
3836 spa_close(spa
, FTAG
);
3837 return (SET_ERROR(ERANGE
));
3839 if (!spa_feature_is_enabled(spa
, feature
)) {
3840 spa_close(spa
, FTAG
);
3841 return (SET_ERROR(ENOTSUP
));
3843 spa_close(spa
, FTAG
);
3848 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3852 * Checks for a race condition to make sure we don't increment a feature flag
3856 zfs_prop_activate_feature_check(void *arg
, dmu_tx_t
*tx
)
3858 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3859 spa_feature_t
*featurep
= arg
;
3861 if (!spa_feature_is_active(spa
, *featurep
))
3864 return (SET_ERROR(EBUSY
));
3868 * The callback invoked on feature activation in the sync task caused by
3869 * zfs_prop_activate_feature.
3872 zfs_prop_activate_feature_sync(void *arg
, dmu_tx_t
*tx
)
3874 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3875 spa_feature_t
*featurep
= arg
;
3877 spa_feature_incr(spa
, *featurep
, tx
);
3881 * Activates a feature on a pool in response to a property setting. This
3882 * creates a new sync task which modifies the pool to reflect the feature
3886 zfs_prop_activate_feature(spa_t
*spa
, spa_feature_t feature
)
3890 /* EBUSY here indicates that the feature is already active */
3891 err
= dsl_sync_task(spa_name(spa
),
3892 zfs_prop_activate_feature_check
, zfs_prop_activate_feature_sync
,
3893 &feature
, 2, ZFS_SPACE_CHECK_RESERVED
);
3895 if (err
!= 0 && err
!= EBUSY
)
3902 * Removes properties from the given props list that fail permission checks
3903 * needed to clear them and to restore them in case of a receive error. For each
3904 * property, make sure we have both set and inherit permissions.
3906 * Returns the first error encountered if any permission checks fail. If the
3907 * caller provides a non-NULL errlist, it also gives the complete list of names
3908 * of all the properties that failed a permission check along with the
3909 * corresponding error numbers. The caller is responsible for freeing the
3912 * If every property checks out successfully, zero is returned and the list
3913 * pointed at by errlist is NULL.
3916 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3919 nvpair_t
*pair
, *next_pair
;
3926 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3928 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
3929 (void) strcpy(zc
->zc_name
, dataset
);
3930 pair
= nvlist_next_nvpair(props
, NULL
);
3931 while (pair
!= NULL
) {
3932 next_pair
= nvlist_next_nvpair(props
, pair
);
3934 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3935 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3936 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
3937 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3938 VERIFY(nvlist_add_int32(errors
,
3939 zc
->zc_value
, err
) == 0);
3943 kmem_free(zc
, sizeof (zfs_cmd_t
));
3945 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3946 nvlist_free(errors
);
3949 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3952 if (errlist
== NULL
)
3953 nvlist_free(errors
);
3961 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3963 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3964 /* dsl_prop_get_all_impl() format */
3966 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3967 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3971 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3973 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3974 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3978 if (nvpair_type(p1
) != nvpair_type(p2
))
3981 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
3982 char *valstr1
, *valstr2
;
3984 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
3985 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
3986 return (strcmp(valstr1
, valstr2
) == 0);
3988 uint64_t intval1
, intval2
;
3990 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
3991 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
3992 return (intval1
== intval2
);
3997 * Remove properties from props if they are not going to change (as determined
3998 * by comparison with origprops). Remove them from origprops as well, since we
3999 * do not need to clear or restore properties that won't change.
4002 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4004 nvpair_t
*pair
, *next_pair
;
4006 if (origprops
== NULL
)
4007 return; /* all props need to be received */
4009 pair
= nvlist_next_nvpair(props
, NULL
);
4010 while (pair
!= NULL
) {
4011 const char *propname
= nvpair_name(pair
);
4014 next_pair
= nvlist_next_nvpair(props
, pair
);
4016 if ((nvlist_lookup_nvpair(origprops
, propname
,
4017 &match
) != 0) || !propval_equals(pair
, match
))
4018 goto next
; /* need to set received value */
4020 /* don't clear the existing received value */
4021 (void) nvlist_remove_nvpair(origprops
, match
);
4022 /* don't bother receiving the property */
4023 (void) nvlist_remove_nvpair(props
, pair
);
4030 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4031 * For example, refquota cannot be set until after the receipt of a dataset,
4032 * because in replication streams, an older/earlier snapshot may exceed the
4033 * refquota. We want to receive the older/earlier snapshot, but setting
4034 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4035 * the older/earlier snapshot from being received (with EDQUOT).
4037 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4039 * libzfs will need to be judicious handling errors encountered by props
4040 * extracted by this function.
4043 extract_delay_props(nvlist_t
*props
)
4045 nvlist_t
*delayprops
;
4046 nvpair_t
*nvp
, *tmp
;
4047 static const zfs_prop_t delayable
[] = { ZFS_PROP_REFQUOTA
, 0 };
4050 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4052 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4053 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4055 * strcmp() is safe because zfs_prop_to_name() always returns
4058 for (i
= 0; delayable
[i
] != 0; i
++) {
4059 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4060 nvpair_name(nvp
)) == 0) {
4064 if (delayable
[i
] != 0) {
4065 tmp
= nvlist_prev_nvpair(props
, nvp
);
4066 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4067 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4072 if (nvlist_empty(delayprops
)) {
4073 nvlist_free(delayprops
);
4076 return (delayprops
);
4080 static boolean_t zfs_ioc_recv_inject_err
;
4085 * zc_name name of containing filesystem
4086 * zc_nvlist_src{_size} nvlist of properties to apply
4087 * zc_value name of snapshot to create
4088 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4089 * zc_cookie file descriptor to recv from
4090 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4091 * zc_guid force flag
4092 * zc_cleanup_fd cleanup-on-exit file descriptor
4093 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4094 * zc_resumable if data is incomplete assume sender will resume
4097 * zc_cookie number of bytes read
4098 * zc_nvlist_dst{_size} error for each unapplied received property
4099 * zc_obj zprop_errflags_t
4100 * zc_action_handle handle for this guid/ds mapping
4103 zfs_ioc_recv(zfs_cmd_t
*zc
)
4106 dmu_recv_cookie_t drc
;
4107 boolean_t force
= (boolean_t
)zc
->zc_guid
;
4110 int props_error
= 0;
4113 nvlist_t
*props
= NULL
; /* sent properties */
4114 nvlist_t
*origprops
= NULL
; /* existing properties */
4115 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4116 char *origin
= NULL
;
4118 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4119 boolean_t first_recvd_props
= B_FALSE
;
4121 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4122 strchr(zc
->zc_value
, '@') == NULL
||
4123 strchr(zc
->zc_value
, '%'))
4124 return (SET_ERROR(EINVAL
));
4126 (void) strcpy(tofs
, zc
->zc_value
);
4127 tosnap
= strchr(tofs
, '@');
4130 if (zc
->zc_nvlist_src
!= (uintptr_t)NULL
&&
4131 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4132 zc
->zc_iflags
, &props
)) != 0)
4139 return (SET_ERROR(EBADF
));
4142 errors
= fnvlist_alloc();
4144 if (zc
->zc_string
[0])
4145 origin
= zc
->zc_string
;
4147 error
= dmu_recv_begin(tofs
, tosnap
,
4148 &zc
->zc_begin_record
, force
, zc
->zc_resumable
, origin
, &drc
);
4153 * Set properties before we receive the stream so that they are applied
4154 * to the new data. Note that we must call dmu_recv_stream() if
4155 * dmu_recv_begin() succeeds.
4157 if (props
!= NULL
&& !drc
.drc_newfs
) {
4158 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4159 SPA_VERSION_RECVD_PROPS
&&
4160 !dsl_prop_get_hasrecvd(tofs
))
4161 first_recvd_props
= B_TRUE
;
4164 * If new received properties are supplied, they are to
4165 * completely replace the existing received properties, so stash
4166 * away the existing ones.
4168 if (dsl_prop_get_received(tofs
, &origprops
) == 0) {
4169 nvlist_t
*errlist
= NULL
;
4171 * Don't bother writing a property if its value won't
4172 * change (and avoid the unnecessary security checks).
4174 * The first receive after SPA_VERSION_RECVD_PROPS is a
4175 * special case where we blow away all local properties
4178 if (!first_recvd_props
)
4179 props_reduce(props
, origprops
);
4180 if (zfs_check_clearable(tofs
, origprops
, &errlist
) != 0)
4181 (void) nvlist_merge(errors
, errlist
, 0);
4182 nvlist_free(errlist
);
4184 if (clear_received_props(tofs
, origprops
,
4185 first_recvd_props
? NULL
: props
) != 0)
4186 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4188 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4192 if (props
!= NULL
) {
4193 props_error
= dsl_prop_set_hasrecvd(tofs
);
4195 if (props_error
== 0) {
4196 delayprops
= extract_delay_props(props
);
4197 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4203 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
4204 &zc
->zc_action_handle
);
4207 zfsvfs_t
*zfsvfs
= NULL
;
4209 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4214 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4215 error
= zfs_suspend_fs(zfsvfs
);
4217 * If the suspend fails, then the recv_end will
4218 * likely also fail, and clean up after itself.
4220 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4222 error
= zfs_resume_fs(zfsvfs
, ds
);
4223 error
= error
? error
: end_err
;
4224 VFS_RELE(zfsvfs
->z_vfs
);
4226 error
= dmu_recv_end(&drc
, NULL
);
4229 /* Set delayed properties now, after we're done receiving. */
4230 if (delayprops
!= NULL
&& error
== 0) {
4231 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4232 delayprops
, errors
);
4236 if (delayprops
!= NULL
) {
4238 * Merge delayed props back in with initial props, in case
4239 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4240 * we have to make sure clear_received_props() includes
4241 * the delayed properties).
4243 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4244 * using ASSERT() will be just like a VERIFY.
4246 ASSERT(nvlist_merge(props
, delayprops
, 0) == 0);
4247 nvlist_free(delayprops
);
4251 * Now that all props, initial and delayed, are set, report the prop
4252 * errors to the caller.
4254 if (zc
->zc_nvlist_dst_size
!= 0 &&
4255 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4256 put_nvlist(zc
, errors
) != 0)) {
4258 * Caller made zc->zc_nvlist_dst less than the minimum expected
4259 * size or supplied an invalid address.
4261 props_error
= SET_ERROR(EINVAL
);
4264 zc
->zc_cookie
= off
- fp
->f_offset
;
4265 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4269 if (zfs_ioc_recv_inject_err
) {
4270 zfs_ioc_recv_inject_err
= B_FALSE
;
4275 * On error, restore the original props.
4277 if (error
!= 0 && props
!= NULL
&& !drc
.drc_newfs
) {
4278 if (clear_received_props(tofs
, props
, NULL
) != 0) {
4280 * We failed to clear the received properties.
4281 * Since we may have left a $recvd value on the
4282 * system, we can't clear the $hasrecvd flag.
4284 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4285 } else if (first_recvd_props
) {
4286 dsl_prop_unset_hasrecvd(tofs
);
4289 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4290 /* We failed to stash the original properties. */
4291 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4295 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4296 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4297 * explictly if we're restoring local properties cleared in the
4298 * first new-style receive.
4300 if (origprops
!= NULL
&&
4301 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4302 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4303 origprops
, NULL
) != 0) {
4305 * We stashed the original properties but failed to
4308 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4313 nvlist_free(origprops
);
4314 nvlist_free(errors
);
4318 error
= props_error
;
4325 * zc_name name of snapshot to send
4326 * zc_cookie file descriptor to send stream to
4327 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4328 * zc_sendobj objsetid of snapshot to send
4329 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4330 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4331 * output size in zc_objset_type.
4332 * zc_flags lzc_send_flags
4335 * zc_objset_type estimated size, if zc_guid is set
4338 zfs_ioc_send(zfs_cmd_t
*zc
)
4342 boolean_t estimate
= (zc
->zc_guid
!= 0);
4343 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4344 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4345 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4347 if (zc
->zc_obj
!= 0) {
4349 dsl_dataset_t
*tosnap
;
4351 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4355 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4357 dsl_pool_rele(dp
, FTAG
);
4361 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4363 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4364 dsl_dataset_rele(tosnap
, FTAG
);
4365 dsl_pool_rele(dp
, FTAG
);
4370 dsl_dataset_t
*tosnap
;
4371 dsl_dataset_t
*fromsnap
= NULL
;
4373 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4377 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4379 dsl_pool_rele(dp
, FTAG
);
4383 if (zc
->zc_fromobj
!= 0) {
4384 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4387 dsl_dataset_rele(tosnap
, FTAG
);
4388 dsl_pool_rele(dp
, FTAG
);
4393 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
4394 &zc
->zc_objset_type
);
4396 if (fromsnap
!= NULL
)
4397 dsl_dataset_rele(fromsnap
, FTAG
);
4398 dsl_dataset_rele(tosnap
, FTAG
);
4399 dsl_pool_rele(dp
, FTAG
);
4401 file_t
*fp
= getf(zc
->zc_cookie
);
4403 return (SET_ERROR(EBADF
));
4406 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4407 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
,
4408 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4410 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4412 releasef(zc
->zc_cookie
);
4419 * zc_name name of snapshot on which to report progress
4420 * zc_cookie file descriptor of send stream
4423 * zc_cookie number of bytes written in send stream thus far
4426 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4430 dmu_sendarg_t
*dsp
= NULL
;
4433 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4437 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4439 dsl_pool_rele(dp
, FTAG
);
4443 mutex_enter(&ds
->ds_sendstream_lock
);
4446 * Iterate over all the send streams currently active on this dataset.
4447 * If there's one which matches the specified file descriptor _and_ the
4448 * stream was started by the current process, return the progress of
4451 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4452 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4453 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4454 dsp
->dsa_proc
== curproc
)
4459 zc
->zc_cookie
= *(dsp
->dsa_off
);
4461 error
= SET_ERROR(ENOENT
);
4463 mutex_exit(&ds
->ds_sendstream_lock
);
4464 dsl_dataset_rele(ds
, FTAG
);
4465 dsl_pool_rele(dp
, FTAG
);
4470 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4474 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4475 &zc
->zc_inject_record
);
4478 zc
->zc_guid
= (uint64_t)id
;
4484 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4486 return (zio_clear_fault((int)zc
->zc_guid
));
4490 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4492 int id
= (int)zc
->zc_guid
;
4495 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4496 &zc
->zc_inject_record
);
4504 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4508 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4510 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4513 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4516 zc
->zc_nvlist_dst_size
= count
;
4518 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4520 spa_close(spa
, FTAG
);
4526 zfs_ioc_clear(zfs_cmd_t
*zc
)
4533 * On zpool clear we also fix up missing slogs
4535 mutex_enter(&spa_namespace_lock
);
4536 spa
= spa_lookup(zc
->zc_name
);
4538 mutex_exit(&spa_namespace_lock
);
4539 return (SET_ERROR(EIO
));
4541 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4542 /* we need to let spa_open/spa_load clear the chains */
4543 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4545 spa
->spa_last_open_failed
= 0;
4546 mutex_exit(&spa_namespace_lock
);
4548 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4549 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4552 nvlist_t
*config
= NULL
;
4554 if (zc
->zc_nvlist_src
== (uintptr_t)NULL
)
4555 return (SET_ERROR(EINVAL
));
4557 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4558 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4559 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4561 if (config
!= NULL
) {
4564 if ((err
= put_nvlist(zc
, config
)) != 0)
4566 nvlist_free(config
);
4568 nvlist_free(policy
);
4575 spa_vdev_state_enter(spa
, SCL_NONE
);
4577 if (zc
->zc_guid
== 0) {
4580 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4582 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4583 spa_close(spa
, FTAG
);
4584 return (SET_ERROR(ENODEV
));
4588 vdev_clear(spa
, vd
);
4590 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4593 * Resume any suspended I/Os.
4595 if (zio_resume(spa
) != 0)
4596 error
= SET_ERROR(EIO
);
4598 spa_close(spa
, FTAG
);
4604 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4609 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4613 spa_vdev_state_enter(spa
, SCL_NONE
);
4616 * If a resilver is already in progress then set the
4617 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4618 * the scan as a side effect of the reopen. Otherwise, let
4619 * vdev_open() decided if a resilver is required.
4621 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4622 vdev_reopen(spa
->spa_root_vdev
);
4623 spa
->spa_scrub_reopen
= B_FALSE
;
4625 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4626 spa_close(spa
, FTAG
);
4631 * zc_name name of filesystem
4634 * zc_string name of conflicting snapshot, if there is one
4637 zfs_ioc_promote(zfs_cmd_t
*zc
)
4640 dsl_dataset_t
*ds
, *ods
;
4641 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
4645 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4649 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4651 dsl_pool_rele(dp
, FTAG
);
4655 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
4656 dsl_dataset_rele(ds
, FTAG
);
4657 dsl_pool_rele(dp
, FTAG
);
4658 return (SET_ERROR(EINVAL
));
4661 error
= dsl_dataset_hold_obj(dp
,
4662 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
4664 dsl_dataset_rele(ds
, FTAG
);
4665 dsl_pool_rele(dp
, FTAG
);
4669 dsl_dataset_name(ods
, origin
);
4670 dsl_dataset_rele(ods
, FTAG
);
4671 dsl_dataset_rele(ds
, FTAG
);
4672 dsl_pool_rele(dp
, FTAG
);
4675 * We don't need to unmount *all* the origin fs's snapshots, but
4678 cp
= strchr(origin
, '@');
4681 (void) dmu_objset_find(origin
,
4682 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
4683 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4687 * Retrieve a single {user|group}{used|quota}@... property.
4690 * zc_name name of filesystem
4691 * zc_objset_type zfs_userquota_prop_t
4692 * zc_value domain name (eg. "S-1-234-567-89")
4693 * zc_guid RID/UID/GID
4696 * zc_cookie property value
4699 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4704 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4705 return (SET_ERROR(EINVAL
));
4707 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
4711 error
= zfs_userspace_one(zfsvfs
,
4712 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4713 zfsvfs_rele(zfsvfs
, FTAG
);
4720 * zc_name name of filesystem
4721 * zc_cookie zap cursor
4722 * zc_objset_type zfs_userquota_prop_t
4723 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4726 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4727 * zc_cookie zap cursor
4730 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4733 int bufsize
= zc
->zc_nvlist_dst_size
;
4736 return (SET_ERROR(ENOMEM
));
4738 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
4742 void *buf
= kmem_alloc(bufsize
, KM_SLEEP
);
4744 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4745 buf
, &zc
->zc_nvlist_dst_size
);
4748 error
= xcopyout(buf
,
4749 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4750 zc
->zc_nvlist_dst_size
);
4752 kmem_free(buf
, bufsize
);
4753 zfsvfs_rele(zfsvfs
, FTAG
);
4760 * zc_name name of filesystem
4766 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4772 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
4773 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
4775 * If userused is not enabled, it may be because the
4776 * objset needs to be closed & reopened (to grow the
4777 * objset_phys_t). Suspend/resume the fs will do that.
4781 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4782 error
= zfs_suspend_fs(zfsvfs
);
4784 dmu_objset_refresh_ownership(zfsvfs
->z_os
,
4786 error
= zfs_resume_fs(zfsvfs
, ds
);
4790 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
4791 VFS_RELE(zfsvfs
->z_vfs
);
4793 /* XXX kind of reading contents without owning */
4794 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4798 error
= dmu_objset_userspace_upgrade(os
);
4799 dmu_objset_rele(os
, FTAG
);
4806 * We don't want to have a hard dependency
4807 * against some special symbols in sharefs
4808 * nfs, and smbsrv. Determine them if needed when
4809 * the first file system is shared.
4810 * Neither sharefs, nfs or smbsrv are unloadable modules.
4812 int (*znfsexport_fs
)(void *arg
);
4813 int (*zshare_fs
)(enum sharefs_sys_op
, share_t
*, uint32_t);
4814 int (*zsmbexport_fs
)(void *arg
, boolean_t add_share
);
4816 int zfs_nfsshare_inited
;
4817 int zfs_smbshare_inited
;
4819 ddi_modhandle_t nfs_mod
;
4820 ddi_modhandle_t sharefs_mod
;
4821 ddi_modhandle_t smbsrv_mod
;
4822 kmutex_t zfs_share_lock
;
4829 ASSERT(MUTEX_HELD(&zfs_share_lock
));
4830 /* Both NFS and SMB shares also require sharetab support. */
4831 if (sharefs_mod
== NULL
&& ((sharefs_mod
=
4832 ddi_modopen("fs/sharefs",
4833 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4834 return (SET_ERROR(ENOSYS
));
4836 if (zshare_fs
== NULL
&& ((zshare_fs
=
4837 (int (*)(enum sharefs_sys_op
, share_t
*, uint32_t))
4838 ddi_modsym(sharefs_mod
, "sharefs_impl", &error
)) == NULL
)) {
4839 return (SET_ERROR(ENOSYS
));
4845 zfs_ioc_share(zfs_cmd_t
*zc
)
4850 switch (zc
->zc_share
.z_sharetype
) {
4852 case ZFS_UNSHARE_NFS
:
4853 if (zfs_nfsshare_inited
== 0) {
4854 mutex_enter(&zfs_share_lock
);
4855 if (nfs_mod
== NULL
&& ((nfs_mod
= ddi_modopen("fs/nfs",
4856 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4857 mutex_exit(&zfs_share_lock
);
4858 return (SET_ERROR(ENOSYS
));
4860 if (znfsexport_fs
== NULL
&&
4861 ((znfsexport_fs
= (int (*)(void *))
4863 "nfs_export", &error
)) == NULL
)) {
4864 mutex_exit(&zfs_share_lock
);
4865 return (SET_ERROR(ENOSYS
));
4867 error
= zfs_init_sharefs();
4869 mutex_exit(&zfs_share_lock
);
4870 return (SET_ERROR(ENOSYS
));
4872 zfs_nfsshare_inited
= 1;
4873 mutex_exit(&zfs_share_lock
);
4877 case ZFS_UNSHARE_SMB
:
4878 if (zfs_smbshare_inited
== 0) {
4879 mutex_enter(&zfs_share_lock
);
4880 if (smbsrv_mod
== NULL
&& ((smbsrv_mod
=
4881 ddi_modopen("drv/smbsrv",
4882 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4883 mutex_exit(&zfs_share_lock
);
4884 return (SET_ERROR(ENOSYS
));
4886 if (zsmbexport_fs
== NULL
&& ((zsmbexport_fs
=
4887 (int (*)(void *, boolean_t
))ddi_modsym(smbsrv_mod
,
4888 "smb_server_share", &error
)) == NULL
)) {
4889 mutex_exit(&zfs_share_lock
);
4890 return (SET_ERROR(ENOSYS
));
4892 error
= zfs_init_sharefs();
4894 mutex_exit(&zfs_share_lock
);
4895 return (SET_ERROR(ENOSYS
));
4897 zfs_smbshare_inited
= 1;
4898 mutex_exit(&zfs_share_lock
);
4902 return (SET_ERROR(EINVAL
));
4905 switch (zc
->zc_share
.z_sharetype
) {
4907 case ZFS_UNSHARE_NFS
:
4909 znfsexport_fs((void *)
4910 (uintptr_t)zc
->zc_share
.z_exportdata
))
4914 case ZFS_UNSHARE_SMB
:
4915 if (error
= zsmbexport_fs((void *)
4916 (uintptr_t)zc
->zc_share
.z_exportdata
,
4917 zc
->zc_share
.z_sharetype
== ZFS_SHARE_SMB
?
4924 opcode
= (zc
->zc_share
.z_sharetype
== ZFS_SHARE_NFS
||
4925 zc
->zc_share
.z_sharetype
== ZFS_SHARE_SMB
) ?
4926 SHAREFS_ADD
: SHAREFS_REMOVE
;
4929 * Add or remove share from sharetab
4931 error
= zshare_fs(opcode
,
4932 (void *)(uintptr_t)zc
->zc_share
.z_sharedata
,
4933 zc
->zc_share
.z_sharemax
);
4939 ace_t full_access
[] = {
4940 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4945 * zc_name name of containing filesystem
4946 * zc_obj object # beyond which we want next in-use object #
4949 * zc_obj next in-use object #
4952 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4954 objset_t
*os
= NULL
;
4957 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4961 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4962 dsl_dataset_phys(os
->os_dsl_dataset
)->ds_prev_snap_txg
);
4964 dmu_objset_rele(os
, FTAG
);
4970 * zc_name name of filesystem
4971 * zc_value prefix name for snapshot
4972 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4975 * zc_value short name of new snapshot
4978 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
4985 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
4989 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
4990 (u_longlong_t
)ddi_get_lbolt64());
4991 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
4993 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
4996 (void) strcpy(zc
->zc_value
, snap_name
);
4999 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5005 * zc_name name of "to" snapshot
5006 * zc_value name of "from" snapshot
5007 * zc_cookie file descriptor to write diff data on
5010 * dmu_diff_record_t's to the file descriptor
5013 zfs_ioc_diff(zfs_cmd_t
*zc
)
5019 fp
= getf(zc
->zc_cookie
);
5021 return (SET_ERROR(EBADF
));
5025 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5027 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5029 releasef(zc
->zc_cookie
);
5035 * Remove all ACL files in shares dir
5038 zfs_smb_acl_purge(znode_t
*dzp
)
5041 zap_attribute_t zap
;
5042 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
5045 for (zap_cursor_init(&zc
, zfsvfs
->z_os
, dzp
->z_id
);
5046 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5047 zap_cursor_advance(&zc
)) {
5048 if ((error
= fop_remove(ZTOV(dzp
), zap
.za_name
, kcred
,
5052 zap_cursor_fini(&zc
);
5057 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5061 vnode_t
*resourcevp
= NULL
;
5070 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5071 NO_FOLLOW
, NULL
, &vp
)) != 0)
5074 /* Now make sure mntpnt and dataset are ZFS */
5076 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5077 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5078 zc
->zc_name
) != 0)) {
5080 return (SET_ERROR(EINVAL
));
5084 zfsvfs
= dzp
->z_zfsvfs
;
5088 * Create share dir if its missing.
5090 mutex_enter(&zfsvfs
->z_lock
);
5091 if (zfsvfs
->z_shares_dir
== 0) {
5094 tx
= dmu_tx_create(zfsvfs
->z_os
);
5095 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5097 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5098 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5102 error
= zfs_create_share_dir(zfsvfs
, tx
);
5106 mutex_exit(&zfsvfs
->z_lock
);
5112 mutex_exit(&zfsvfs
->z_lock
);
5114 ASSERT(zfsvfs
->z_shares_dir
);
5115 if ((error
= zfs_zget(zfsvfs
, zfsvfs
->z_shares_dir
, &sharedir
)) != 0) {
5121 switch (zc
->zc_cookie
) {
5122 case ZFS_SMB_ACL_ADD
:
5123 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5124 vattr
.va_type
= VREG
;
5125 vattr
.va_mode
= S_IFREG
|0777;
5129 vsec
.vsa_mask
= VSA_ACE
;
5130 vsec
.vsa_aclentp
= &full_access
;
5131 vsec
.vsa_aclentsz
= sizeof (full_access
);
5132 vsec
.vsa_aclcnt
= 1;
5134 error
= fop_create(ZTOV(sharedir
), zc
->zc_string
,
5135 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5137 VN_RELE(resourcevp
);
5140 case ZFS_SMB_ACL_REMOVE
:
5141 error
= fop_remove(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5145 case ZFS_SMB_ACL_RENAME
:
5146 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5147 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5149 VN_RELE(ZTOV(sharedir
));
5153 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5154 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5157 VN_RELE(ZTOV(sharedir
));
5159 nvlist_free(nvlist
);
5162 error
= fop_rename(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5164 nvlist_free(nvlist
);
5167 case ZFS_SMB_ACL_PURGE
:
5168 error
= zfs_smb_acl_purge(sharedir
);
5172 error
= SET_ERROR(EINVAL
);
5177 VN_RELE(ZTOV(sharedir
));
5186 * "holds" -> { snapname -> holdname (string), ... }
5187 * (optional) "cleanup_fd" -> fd (int32)
5191 * snapname -> error value (int32)
5197 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5201 int cleanup_fd
= -1;
5205 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5207 return (SET_ERROR(EINVAL
));
5209 /* make sure the user didn't pass us any invalid (empty) tags */
5210 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5211 pair
= nvlist_next_nvpair(holds
, pair
)) {
5214 error
= nvpair_value_string(pair
, &htag
);
5216 return (SET_ERROR(error
));
5218 if (strlen(htag
) == 0)
5219 return (SET_ERROR(EINVAL
));
5222 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5223 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5228 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5230 zfs_onexit_fd_rele(cleanup_fd
);
5235 * innvl is not used.
5238 * holdname -> time added (uint64 seconds since epoch)
5244 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5246 return (dsl_dataset_get_holds(snapname
, outnvl
));
5251 * snapname -> { holdname, ... }
5256 * snapname -> error value (int32)
5262 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5264 return (dsl_dataset_user_release(holds
, errlist
));
5269 * zc_name name of new filesystem or snapshot
5270 * zc_value full name of old snapshot
5273 * zc_cookie space in bytes
5274 * zc_objset_type compressed space in bytes
5275 * zc_perm_action uncompressed space in bytes
5278 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5282 dsl_dataset_t
*new, *old
;
5284 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5287 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5289 dsl_pool_rele(dp
, FTAG
);
5292 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5294 dsl_dataset_rele(new, FTAG
);
5295 dsl_pool_rele(dp
, FTAG
);
5299 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5300 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5301 dsl_dataset_rele(old
, FTAG
);
5302 dsl_dataset_rele(new, FTAG
);
5303 dsl_pool_rele(dp
, FTAG
);
5309 * "firstsnap" -> snapshot name
5313 * "used" -> space in bytes
5314 * "compressed" -> compressed space in bytes
5315 * "uncompressed" -> uncompressed space in bytes
5319 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5323 dsl_dataset_t
*new, *old
;
5325 uint64_t used
, comp
, uncomp
;
5327 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5328 return (SET_ERROR(EINVAL
));
5330 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5334 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5335 if (error
== 0 && !new->ds_is_snapshot
) {
5336 dsl_dataset_rele(new, FTAG
);
5337 error
= SET_ERROR(EINVAL
);
5340 dsl_pool_rele(dp
, FTAG
);
5343 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5344 if (error
== 0 && !old
->ds_is_snapshot
) {
5345 dsl_dataset_rele(old
, FTAG
);
5346 error
= SET_ERROR(EINVAL
);
5349 dsl_dataset_rele(new, FTAG
);
5350 dsl_pool_rele(dp
, FTAG
);
5354 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5355 dsl_dataset_rele(old
, FTAG
);
5356 dsl_dataset_rele(new, FTAG
);
5357 dsl_pool_rele(dp
, FTAG
);
5358 fnvlist_add_uint64(outnvl
, "used", used
);
5359 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5360 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5366 * "fd" -> file descriptor to write stream to (int32)
5367 * (optional) "fromsnap" -> full snap name to send an incremental from
5368 * (optional) "largeblockok" -> (value ignored)
5369 * indicates that blocks > 128KB are permitted
5370 * (optional) "embedok" -> (value ignored)
5371 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5372 * (optional) "compressok" -> (value ignored)
5373 * presence indicates compressed DRR_WRITE records are permitted
5374 * (optional) "resume_object" and "resume_offset" -> (uint64)
5375 * if present, resume send stream from specified object and offset.
5382 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5386 char *fromname
= NULL
;
5388 boolean_t largeblockok
;
5390 boolean_t compressok
;
5391 uint64_t resumeobj
= 0;
5392 uint64_t resumeoff
= 0;
5394 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5396 return (SET_ERROR(EINVAL
));
5398 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5400 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5401 embedok
= nvlist_exists(innvl
, "embedok");
5402 compressok
= nvlist_exists(innvl
, "compressok");
5404 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5405 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5407 file_t
*fp
= getf(fd
);
5409 return (SET_ERROR(EBADF
));
5412 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5413 fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5415 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5422 * Determine approximately how large a zfs send stream will be -- the number
5423 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5426 * (optional) "from" -> full snap or bookmark name to send an incremental
5428 * (optional) "largeblockok" -> (value ignored)
5429 * indicates that blocks > 128KB are permitted
5430 * (optional) "embedok" -> (value ignored)
5431 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5432 * (optional) "compressok" -> (value ignored)
5433 * presence indicates compressed DRR_WRITE records are permitted
5437 * "space" -> bytes of space (uint64)
5441 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5444 dsl_dataset_t
*tosnap
;
5447 boolean_t compressok
;
5450 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5454 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5456 dsl_pool_rele(dp
, FTAG
);
5460 compressok
= nvlist_exists(innvl
, "compressok");
5462 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5464 if (strchr(fromname
, '@') != NULL
) {
5466 * If from is a snapshot, hold it and use the more
5467 * efficient dmu_send_estimate to estimate send space
5468 * size using deadlists.
5470 dsl_dataset_t
*fromsnap
;
5471 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5474 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
5476 dsl_dataset_rele(fromsnap
, FTAG
);
5477 } else if (strchr(fromname
, '#') != NULL
) {
5479 * If from is a bookmark, fetch the creation TXG of the
5480 * snapshot it was created from and use that to find
5481 * blocks that were born after it.
5483 zfs_bookmark_phys_t frombm
;
5485 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
5489 error
= dmu_send_estimate_from_txg(tosnap
,
5490 frombm
.zbm_creation_txg
, compressok
, &space
);
5493 * from is not properly formatted as a snapshot or
5496 error
= SET_ERROR(EINVAL
);
5501 * If estimating the size of a full send, use dmu_send_estimate.
5503 error
= dmu_send_estimate(tosnap
, NULL
, compressok
, &space
);
5506 fnvlist_add_uint64(outnvl
, "space", space
);
5509 dsl_dataset_rele(tosnap
, FTAG
);
5510 dsl_pool_rele(dp
, FTAG
);
5514 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5517 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5518 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5519 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5521 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5523 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5524 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5525 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5526 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5528 vec
->zvec_legacy_func
= func
;
5529 vec
->zvec_secpolicy
= secpolicy
;
5530 vec
->zvec_namecheck
= namecheck
;
5531 vec
->zvec_allow_log
= log_history
;
5532 vec
->zvec_pool_check
= pool_check
;
5536 * See the block comment at the beginning of this file for details on
5537 * each argument to this function.
5540 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5541 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5542 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5543 boolean_t allow_log
)
5545 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5547 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5548 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5549 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5550 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5552 /* if we are logging, the name must be valid */
5553 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5555 vec
->zvec_name
= name
;
5556 vec
->zvec_func
= func
;
5557 vec
->zvec_secpolicy
= secpolicy
;
5558 vec
->zvec_namecheck
= namecheck
;
5559 vec
->zvec_pool_check
= pool_check
;
5560 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5561 vec
->zvec_allow_log
= allow_log
;
5565 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5566 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5567 zfs_ioc_poolcheck_t pool_check
)
5569 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5570 POOL_NAME
, log_history
, pool_check
);
5574 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5575 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5577 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5578 DATASET_NAME
, B_FALSE
, pool_check
);
5582 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5584 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5585 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5589 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5590 zfs_secpolicy_func_t
*secpolicy
)
5592 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5593 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5597 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5598 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5600 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5601 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5605 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5607 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5608 zfs_secpolicy_read
);
5612 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5613 zfs_secpolicy_func_t
*secpolicy
)
5615 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5616 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5620 zfs_ioctl_init(void)
5622 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5623 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5624 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5626 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5627 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5628 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5630 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5631 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5632 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5634 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5635 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5636 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5638 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5639 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5640 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5642 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5643 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5644 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5646 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5647 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5648 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5650 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5651 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5652 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5654 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
5655 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
5656 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5657 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
5658 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
5659 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5661 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
5662 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
5663 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5665 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
5666 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
5667 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
5669 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
5670 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
5671 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5673 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
5674 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
5675 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5677 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
5678 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
5680 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5682 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
5683 zfs_ioc_channel_program
, zfs_secpolicy_config
,
5684 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
5687 /* IOCTLS that use the legacy function signature */
5689 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5690 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5692 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5693 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5694 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5696 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5697 zfs_ioc_pool_upgrade
);
5698 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5700 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5701 zfs_ioc_vdev_remove
);
5702 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5703 zfs_ioc_vdev_set_state
);
5704 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5705 zfs_ioc_vdev_attach
);
5706 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5707 zfs_ioc_vdev_detach
);
5708 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5709 zfs_ioc_vdev_setpath
);
5710 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5711 zfs_ioc_vdev_setfru
);
5712 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5713 zfs_ioc_pool_set_props
);
5714 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5715 zfs_ioc_vdev_split
);
5716 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5717 zfs_ioc_pool_reguid
);
5719 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5720 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5721 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5722 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5723 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5724 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5725 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5726 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5727 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5728 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5731 * pool destroy, and export don't log the history as part of
5732 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5733 * does the logging of those commands.
5735 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5736 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5737 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5738 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5740 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5741 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5742 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5743 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5745 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5746 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5747 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5748 zfs_ioc_dsobj_to_dsname
,
5749 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5750 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5751 zfs_ioc_pool_get_history
,
5752 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5754 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5755 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5757 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5758 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5759 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5760 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5762 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5763 zfs_ioc_space_written
);
5764 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5765 zfs_ioc_objset_recvd_props
);
5766 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5768 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5770 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5771 zfs_ioc_objset_stats
);
5772 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5773 zfs_ioc_objset_zplprops
);
5774 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5775 zfs_ioc_dataset_list_next
);
5776 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5777 zfs_ioc_snapshot_list_next
);
5778 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5779 zfs_ioc_send_progress
);
5781 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5782 zfs_ioc_diff
, zfs_secpolicy_diff
);
5783 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5784 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5785 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5786 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5787 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5788 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5789 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5790 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5791 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5792 zfs_ioc_send
, zfs_secpolicy_send
);
5794 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5795 zfs_secpolicy_none
);
5796 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5797 zfs_secpolicy_destroy
);
5798 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5799 zfs_secpolicy_rename
);
5800 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5801 zfs_secpolicy_recv
);
5802 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5803 zfs_secpolicy_promote
);
5804 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5805 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5806 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5807 zfs_secpolicy_set_fsacl
);
5809 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5810 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5811 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5812 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5813 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5814 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5815 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5816 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5817 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5818 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5822 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5823 zfs_ioc_poolcheck_t check
)
5828 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5830 if (check
& POOL_CHECK_NONE
)
5833 error
= spa_open(name
, &spa
, FTAG
);
5835 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5836 error
= SET_ERROR(EAGAIN
);
5837 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5838 error
= SET_ERROR(EROFS
);
5839 spa_close(spa
, FTAG
);
5845 * Find a free minor number.
5848 zfsdev_minor_alloc(void)
5850 static minor_t last_minor
;
5853 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5855 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5856 if (m
> ZFSDEV_MAX_MINOR
)
5858 if (ddi_get_soft_state(zfsdev_state
, m
) == NULL
) {
5868 zfs_ctldev_init(dev_t
*devp
)
5871 zfs_soft_state_t
*zs
;
5873 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5874 ASSERT(getminor(*devp
) == 0);
5876 minor
= zfsdev_minor_alloc();
5878 return (SET_ERROR(ENXIO
));
5880 if (ddi_soft_state_zalloc(zfsdev_state
, minor
) != DDI_SUCCESS
)
5881 return (SET_ERROR(EAGAIN
));
5883 *devp
= makedevice(getemajor(*devp
), minor
);
5885 zs
= ddi_get_soft_state(zfsdev_state
, minor
);
5886 zs
->zss_type
= ZSST_CTLDEV
;
5887 zfs_onexit_init((zfs_onexit_t
**)&zs
->zss_data
);
5893 zfs_ctldev_destroy(zfs_onexit_t
*zo
, minor_t minor
)
5895 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5897 zfs_onexit_destroy(zo
);
5898 ddi_soft_state_free(zfsdev_state
, minor
);
5902 zfsdev_get_soft_state(minor_t minor
, enum zfs_soft_state_type which
)
5904 zfs_soft_state_t
*zp
;
5906 zp
= ddi_get_soft_state(zfsdev_state
, minor
);
5907 if (zp
== NULL
|| zp
->zss_type
!= which
)
5910 return (zp
->zss_data
);
5914 zfsdev_open(dev_t
*devp
, int flag
, int otyp
, cred_t
*cr
)
5918 if (getminor(*devp
) != 0)
5919 return (zvol_open(devp
, flag
, otyp
, cr
));
5921 /* This is the control device. Allocate a new minor if requested. */
5923 mutex_enter(&zfsdev_state_lock
);
5924 error
= zfs_ctldev_init(devp
);
5925 mutex_exit(&zfsdev_state_lock
);
5932 zfsdev_close(dev_t dev
, int flag
, int otyp
, cred_t
*cr
)
5935 minor_t minor
= getminor(dev
);
5940 mutex_enter(&zfsdev_state_lock
);
5941 zo
= zfsdev_get_soft_state(minor
, ZSST_CTLDEV
);
5943 mutex_exit(&zfsdev_state_lock
);
5944 return (zvol_close(dev
, flag
, otyp
, cr
));
5946 zfs_ctldev_destroy(zo
, minor
);
5947 mutex_exit(&zfsdev_state_lock
);
5953 zfsdev_ioctl(dev_t dev
, int cmd
, intptr_t arg
, int flag
, cred_t
*cr
, int *rvalp
)
5958 minor_t minor
= getminor(dev
);
5959 const zfs_ioc_vec_t
*vec
;
5960 char *saved_poolname
= NULL
;
5961 nvlist_t
*innvl
= NULL
;
5964 zfsdev_get_soft_state(minor
, ZSST_CTLDEV
) == NULL
)
5965 return (zvol_ioctl(dev
, cmd
, arg
, flag
, cr
, rvalp
));
5967 vecnum
= cmd
- ZFS_IOC_FIRST
;
5968 ASSERT3U(getmajor(dev
), ==, ddi_driver_major(zfs_dip
));
5970 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
5971 return (SET_ERROR(EINVAL
));
5972 vec
= &zfs_ioc_vec
[vecnum
];
5974 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
5976 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
5978 error
= SET_ERROR(EFAULT
);
5982 zc
->zc_iflags
= flag
& FKIOCTL
;
5983 if (zc
->zc_nvlist_src_size
!= 0) {
5984 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
5985 zc
->zc_iflags
, &innvl
);
5991 * Ensure that all pool/dataset names are valid before we pass down to
5994 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
5995 switch (vec
->zvec_namecheck
) {
5997 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
5998 error
= SET_ERROR(EINVAL
);
6000 error
= pool_status_check(zc
->zc_name
,
6001 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6005 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6006 error
= SET_ERROR(EINVAL
);
6008 error
= pool_status_check(zc
->zc_name
,
6009 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6018 error
= vec
->zvec_secpolicy(zc
, innvl
, cr
);
6023 /* legacy ioctls can modify zc_name */
6024 len
= strcspn(zc
->zc_name
, "/@#") + 1;
6025 saved_poolname
= kmem_alloc(len
, KM_SLEEP
);
6026 (void) strlcpy(saved_poolname
, zc
->zc_name
, len
);
6028 if (vec
->zvec_func
!= NULL
) {
6032 nvlist_t
*lognv
= NULL
;
6034 ASSERT(vec
->zvec_legacy_func
== NULL
);
6037 * Add the innvl to the lognv before calling the func,
6038 * in case the func changes the innvl.
6040 if (vec
->zvec_allow_log
) {
6041 lognv
= fnvlist_alloc();
6042 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6044 if (!nvlist_empty(innvl
)) {
6045 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6050 outnvl
= fnvlist_alloc();
6051 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6054 * Some commands can partially execute, modfiy state, and still
6055 * return an error. In these cases, attempt to record what
6059 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
6060 vec
->zvec_allow_log
&&
6061 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6062 if (!nvlist_empty(outnvl
)) {
6063 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6067 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
6070 (void) spa_history_log_nvl(spa
, lognv
);
6071 spa_close(spa
, FTAG
);
6073 fnvlist_free(lognv
);
6075 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6077 if (vec
->zvec_smush_outnvlist
) {
6078 smusherror
= nvlist_smush(outnvl
,
6079 zc
->zc_nvlist_dst_size
);
6081 if (smusherror
== 0)
6082 puterror
= put_nvlist(zc
, outnvl
);
6088 nvlist_free(outnvl
);
6090 error
= vec
->zvec_legacy_func(zc
);
6095 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6096 if (error
== 0 && rc
!= 0)
6097 error
= SET_ERROR(EFAULT
);
6098 if (error
== 0 && vec
->zvec_allow_log
) {
6099 char *s
= tsd_get(zfs_allow_log_key
);
6102 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6104 if (saved_poolname
!= NULL
)
6105 strfree(saved_poolname
);
6108 kmem_free(zc
, sizeof (zfs_cmd_t
));
6113 zfs_attach(dev_info_t
*dip
, ddi_attach_cmd_t cmd
)
6115 if (cmd
!= DDI_ATTACH
)
6116 return (DDI_FAILURE
);
6118 if (ddi_create_minor_node(dip
, "zfs", S_IFCHR
, 0,
6119 DDI_PSEUDO
, 0) == DDI_FAILURE
)
6120 return (DDI_FAILURE
);
6124 ddi_report_dev(dip
);
6126 return (DDI_SUCCESS
);
6130 zfs_detach(dev_info_t
*dip
, ddi_detach_cmd_t cmd
)
6132 if (spa_busy() || zfs_busy() || zvol_busy())
6133 return (DDI_FAILURE
);
6135 if (cmd
!= DDI_DETACH
)
6136 return (DDI_FAILURE
);
6140 ddi_prop_remove_all(dip
);
6141 ddi_remove_minor_node(dip
, NULL
);
6143 return (DDI_SUCCESS
);
6148 zfs_info(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
6151 case DDI_INFO_DEVT2DEVINFO
:
6153 return (DDI_SUCCESS
);
6155 case DDI_INFO_DEVT2INSTANCE
:
6157 return (DDI_SUCCESS
);
6160 return (DDI_FAILURE
);
6164 * OK, so this is a little weird.
6166 * /dev/zfs is the control node, i.e. minor 0.
6167 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
6169 * /dev/zfs has basically nothing to do except serve up ioctls,
6170 * so most of the standard driver entry points are in zvol.c.
6172 static struct cb_ops zfs_cb_ops
= {
6173 zfsdev_open
, /* open */
6174 zfsdev_close
, /* close */
6175 zvol_strategy
, /* strategy */
6177 zvol_dump
, /* dump */
6178 zvol_read
, /* read */
6179 zvol_write
, /* write */
6180 zfsdev_ioctl
, /* ioctl */
6184 nochpoll
, /* poll */
6185 ddi_prop_op
, /* prop_op */
6186 NULL
, /* streamtab */
6187 D_NEW
| D_MP
| D_64BIT
, /* Driver compatibility flag */
6188 CB_REV
, /* version */
6189 nodev
, /* async read */
6190 nodev
, /* async write */
6193 static struct dev_ops zfs_dev_ops
= {
6194 DEVO_REV
, /* version */
6196 zfs_info
, /* info */
6197 nulldev
, /* identify */
6198 nulldev
, /* probe */
6199 zfs_attach
, /* attach */
6200 zfs_detach
, /* detach */
6202 &zfs_cb_ops
, /* driver operations */
6203 NULL
, /* no bus operations */
6205 ddi_quiesce_not_needed
, /* quiesce */
6208 static struct modldrv zfs_modldrv
= {
6214 static struct modlinkage modlinkage
= {
6216 (void *)&zfs_modlfs
,
6217 (void *)&zfs_modldrv
,
6222 zfs_allow_log_destroy(void *arg
)
6224 char *poolname
= arg
;
6233 spa_init(FREAD
| FWRITE
);
6238 if ((error
= mod_install(&modlinkage
)) != 0) {
6245 tsd_create(&zfs_fsyncer_key
, NULL
);
6246 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
6247 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
6249 error
= ldi_ident_from_mod(&modlinkage
, &zfs_li
);
6251 mutex_init(&zfs_share_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6261 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled
)
6262 return (SET_ERROR(EBUSY
));
6264 if ((error
= mod_remove(&modlinkage
)) != 0)
6270 if (zfs_nfsshare_inited
)
6271 (void) ddi_modclose(nfs_mod
);
6272 if (zfs_smbshare_inited
)
6273 (void) ddi_modclose(smbsrv_mod
);
6274 if (zfs_nfsshare_inited
|| zfs_smbshare_inited
)
6275 (void) ddi_modclose(sharefs_mod
);
6277 tsd_destroy(&zfs_fsyncer_key
);
6278 ldi_ident_release(zfs_li
);
6280 mutex_destroy(&zfs_share_lock
);
6286 _info(struct modinfo
*modinfop
)
6288 return (mod_info(&modlinkage
, modinfop
));