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>
191 #include <sys/vdev_removal.h>
193 #include "zfs_namecheck.h"
194 #include "zfs_prop.h"
195 #include "zfs_deleg.h"
196 #include "zfs_comutil.h"
201 extern struct modlfs zfs_modlfs
;
203 extern void zfs_init(void);
204 extern void zfs_fini(void);
206 ldi_ident_t zfs_li
= NULL
;
209 uint_t zfs_fsyncer_key
;
210 extern uint_t rrw_tsd_key
;
211 static uint_t zfs_allow_log_key
;
213 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t
*);
214 typedef int zfs_ioc_func_t(const char *, nvlist_t
*, nvlist_t
*);
215 typedef int zfs_secpolicy_func_t(zfs_cmd_t
*, nvlist_t
*, cred_t
*);
221 } zfs_ioc_namecheck_t
;
224 POOL_CHECK_NONE
= 1 << 0,
225 POOL_CHECK_SUSPENDED
= 1 << 1,
226 POOL_CHECK_READONLY
= 1 << 2,
227 } zfs_ioc_poolcheck_t
;
229 typedef struct zfs_ioc_vec
{
230 zfs_ioc_legacy_func_t
*zvec_legacy_func
;
231 zfs_ioc_func_t
*zvec_func
;
232 zfs_secpolicy_func_t
*zvec_secpolicy
;
233 zfs_ioc_namecheck_t zvec_namecheck
;
234 boolean_t zvec_allow_log
;
235 zfs_ioc_poolcheck_t zvec_pool_check
;
236 boolean_t zvec_smush_outnvlist
;
237 const char *zvec_name
;
240 /* This array is indexed by zfs_userquota_prop_t */
241 static const char *userquota_perms
[] = {
242 ZFS_DELEG_PERM_USERUSED
,
243 ZFS_DELEG_PERM_USERQUOTA
,
244 ZFS_DELEG_PERM_GROUPUSED
,
245 ZFS_DELEG_PERM_GROUPQUOTA
,
248 static int zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
);
249 static int zfs_check_settable(const char *name
, nvpair_t
*property
,
251 static int zfs_check_clearable(char *dataset
, nvlist_t
*props
,
253 static int zfs_fill_zplprops_root(uint64_t, nvlist_t
*, nvlist_t
*,
255 int zfs_set_prop_nvlist(const char *, zprop_source_t
, nvlist_t
*, nvlist_t
*);
256 static int get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
);
258 static int zfs_prop_activate_feature(spa_t
*spa
, spa_feature_t feature
);
260 /* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
262 __dprintf(const char *file
, const char *func
, int line
, const char *fmt
, ...)
269 * Get rid of annoying "../common/" prefix to filename.
271 newfile
= strrchr(file
, '/');
272 if (newfile
!= NULL
) {
273 newfile
= newfile
+ 1; /* Get rid of leading / */
279 (void) vsnprintf(buf
, sizeof (buf
), fmt
, adx
);
283 * To get this data, use the zfs-dprintf probe as so:
284 * dtrace -q -n 'zfs-dprintf \
285 * /stringof(arg0) == "dbuf.c"/ \
286 * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
288 * arg1 = function name
292 DTRACE_PROBE4(zfs__dprintf
,
293 char *, newfile
, char *, func
, int, line
, char *, buf
);
297 history_str_free(char *buf
)
299 kmem_free(buf
, HIS_MAX_RECORD_LEN
);
303 history_str_get(zfs_cmd_t
*zc
)
307 if (zc
->zc_history
== (uintptr_t)NULL
)
310 buf
= kmem_alloc(HIS_MAX_RECORD_LEN
, KM_SLEEP
);
311 if (copyinstr((void *)(uintptr_t)zc
->zc_history
,
312 buf
, HIS_MAX_RECORD_LEN
, NULL
) != 0) {
313 history_str_free(buf
);
317 buf
[HIS_MAX_RECORD_LEN
-1] = '\0';
323 * Check to see if the named dataset is currently defined as bootable
326 zfs_is_bootfs(const char *name
)
330 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
332 ret
= (dmu_objset_id(os
) == spa_bootfs(dmu_objset_spa(os
)));
333 dmu_objset_rele(os
, FTAG
);
340 * Return non-zero if the spa version is less than requested version.
343 zfs_earlier_version(const char *name
, int version
)
347 if (spa_open(name
, &spa
, FTAG
) == 0) {
348 if (spa_version(spa
) < version
) {
349 spa_close(spa
, FTAG
);
352 spa_close(spa
, FTAG
);
358 * Return TRUE if the ZPL version is less than requested version.
361 zpl_earlier_version(const char *name
, int version
)
364 boolean_t rc
= B_TRUE
;
366 if (dmu_objset_hold(name
, FTAG
, &os
) == 0) {
369 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
370 dmu_objset_rele(os
, FTAG
);
373 /* XXX reading from non-owned objset */
374 if (zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zplversion
) == 0)
375 rc
= zplversion
< version
;
376 dmu_objset_rele(os
, FTAG
);
382 zfs_log_history(zfs_cmd_t
*zc
)
387 if ((buf
= history_str_get(zc
)) == NULL
)
390 if (spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
391 if (spa_version(spa
) >= SPA_VERSION_ZPOOL_HISTORY
)
392 (void) spa_history_log(spa
, buf
);
393 spa_close(spa
, FTAG
);
395 history_str_free(buf
);
399 * Policy for top-level read operations (list pools). Requires no privileges,
400 * and can be used in the local zone, as there is no associated dataset.
404 zfs_secpolicy_none(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
410 * Policy for dataset read operations (list children, get statistics). Requires
411 * no privileges, but must be visible in the local zone.
415 zfs_secpolicy_read(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
417 if (INGLOBALZONE(curproc
) ||
418 zone_dataset_visible(zc
->zc_name
, NULL
))
421 return (SET_ERROR(ENOENT
));
425 zfs_dozonecheck_impl(const char *dataset
, uint64_t zoned
, cred_t
*cr
)
430 * The dataset must be visible by this zone -- check this first
431 * so they don't see EPERM on something they shouldn't know about.
433 if (!INGLOBALZONE(curproc
) &&
434 !zone_dataset_visible(dataset
, &writable
))
435 return (SET_ERROR(ENOENT
));
437 if (INGLOBALZONE(curproc
)) {
439 * If the fs is zoned, only root can access it from the
442 if (secpolicy_zfs(cr
) && zoned
)
443 return (SET_ERROR(EPERM
));
446 * If we are in a local zone, the 'zoned' property must be set.
449 return (SET_ERROR(EPERM
));
451 /* must be writable by this zone */
453 return (SET_ERROR(EPERM
));
459 zfs_dozonecheck(const char *dataset
, cred_t
*cr
)
463 if (dsl_prop_get_integer(dataset
, "zoned", &zoned
, NULL
))
464 return (SET_ERROR(ENOENT
));
466 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
470 zfs_dozonecheck_ds(const char *dataset
, dsl_dataset_t
*ds
, cred_t
*cr
)
474 if (dsl_prop_get_int_ds(ds
, "zoned", &zoned
))
475 return (SET_ERROR(ENOENT
));
477 return (zfs_dozonecheck_impl(dataset
, zoned
, cr
));
481 zfs_secpolicy_write_perms_ds(const char *name
, dsl_dataset_t
*ds
,
482 const char *perm
, cred_t
*cr
)
486 error
= zfs_dozonecheck_ds(name
, ds
, cr
);
488 error
= secpolicy_zfs(cr
);
490 error
= dsl_deleg_access_impl(ds
, perm
, cr
);
496 zfs_secpolicy_write_perms(const char *name
, const char *perm
, cred_t
*cr
)
503 * First do a quick check for root in the global zone, which
504 * is allowed to do all write_perms. This ensures that zfs_ioc_*
505 * will get to handle nonexistent datasets.
507 if (INGLOBALZONE(curproc
) && secpolicy_zfs(cr
) == 0)
510 error
= dsl_pool_hold(name
, FTAG
, &dp
);
514 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
516 dsl_pool_rele(dp
, FTAG
);
520 error
= zfs_secpolicy_write_perms_ds(name
, ds
, perm
, cr
);
522 dsl_dataset_rele(ds
, FTAG
);
523 dsl_pool_rele(dp
, FTAG
);
528 zfs_secpolicy_setprop(const char *dsname
, zfs_prop_t prop
, nvpair_t
*propval
,
534 * Check permissions for special properties.
539 * Disallow setting of 'zoned' from within a local zone.
541 if (!INGLOBALZONE(curproc
))
542 return (SET_ERROR(EPERM
));
546 case ZFS_PROP_FILESYSTEM_LIMIT
:
547 case ZFS_PROP_SNAPSHOT_LIMIT
:
548 if (!INGLOBALZONE(curproc
)) {
550 char setpoint
[ZFS_MAX_DATASET_NAME_LEN
];
552 * Unprivileged users are allowed to modify the
553 * limit on things *under* (ie. contained by)
554 * the thing they own.
556 if (dsl_prop_get_integer(dsname
, "zoned", &zoned
,
558 return (SET_ERROR(EPERM
));
559 if (!zoned
|| strlen(dsname
) <= strlen(setpoint
))
560 return (SET_ERROR(EPERM
));
565 return (zfs_secpolicy_write_perms(dsname
, zfs_prop_to_name(prop
), cr
));
570 zfs_secpolicy_set_fsacl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
574 error
= zfs_dozonecheck(zc
->zc_name
, cr
);
579 * permission to set permissions will be evaluated later in
580 * dsl_deleg_can_allow()
587 zfs_secpolicy_rollback(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
589 return (zfs_secpolicy_write_perms(zc
->zc_name
,
590 ZFS_DELEG_PERM_ROLLBACK
, cr
));
595 zfs_secpolicy_send(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
603 * Generate the current snapshot name from the given objsetid, then
604 * use that name for the secpolicy/zone checks.
606 cp
= strchr(zc
->zc_name
, '@');
608 return (SET_ERROR(EINVAL
));
609 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
613 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &ds
);
615 dsl_pool_rele(dp
, FTAG
);
619 dsl_dataset_name(ds
, zc
->zc_name
);
621 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, ds
,
622 ZFS_DELEG_PERM_SEND
, cr
);
623 dsl_dataset_rele(ds
, FTAG
);
624 dsl_pool_rele(dp
, FTAG
);
631 zfs_secpolicy_send_new(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
633 return (zfs_secpolicy_write_perms(zc
->zc_name
,
634 ZFS_DELEG_PERM_SEND
, cr
));
639 zfs_secpolicy_deleg_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
644 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
645 NO_FOLLOW
, NULL
, &vp
)) != 0)
648 /* Now make sure mntpnt and dataset are ZFS */
650 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
651 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
652 zc
->zc_name
) != 0)) {
654 return (SET_ERROR(EPERM
));
658 return (dsl_deleg_access(zc
->zc_name
,
659 ZFS_DELEG_PERM_SHARE
, cr
));
663 zfs_secpolicy_share(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
665 if (!INGLOBALZONE(curproc
))
666 return (SET_ERROR(EPERM
));
668 if (secpolicy_nfs(cr
) == 0) {
671 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
676 zfs_secpolicy_smb_acl(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
678 if (!INGLOBALZONE(curproc
))
679 return (SET_ERROR(EPERM
));
681 if (secpolicy_smb(cr
) == 0) {
684 return (zfs_secpolicy_deleg_share(zc
, innvl
, cr
));
689 zfs_get_parent(const char *datasetname
, char *parent
, int parentsize
)
694 * Remove the @bla or /bla from the end of the name to get the parent.
696 (void) strncpy(parent
, datasetname
, parentsize
);
697 cp
= strrchr(parent
, '@');
701 cp
= strrchr(parent
, '/');
703 return (SET_ERROR(ENOENT
));
711 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
715 if ((error
= zfs_secpolicy_write_perms(name
,
716 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
719 return (zfs_secpolicy_write_perms(name
, ZFS_DELEG_PERM_DESTROY
, cr
));
724 zfs_secpolicy_destroy(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
726 return (zfs_secpolicy_destroy_perms(zc
->zc_name
, cr
));
730 * Destroying snapshots with delegated permissions requires
731 * descendant mount and destroy permissions.
735 zfs_secpolicy_destroy_snaps(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
738 nvpair_t
*pair
, *nextpair
;
741 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
742 return (SET_ERROR(EINVAL
));
743 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
745 nextpair
= nvlist_next_nvpair(snaps
, pair
);
746 error
= zfs_secpolicy_destroy_perms(nvpair_name(pair
), cr
);
747 if (error
== ENOENT
) {
749 * Ignore any snapshots that don't exist (we consider
750 * them "already destroyed"). Remove the name from the
751 * nvl here in case the snapshot is created between
752 * now and when we try to destroy it (in which case
753 * we don't want to destroy it since we haven't
754 * checked for permission).
756 fnvlist_remove_nvpair(snaps
, pair
);
767 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
769 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
772 if ((error
= zfs_secpolicy_write_perms(from
,
773 ZFS_DELEG_PERM_RENAME
, cr
)) != 0)
776 if ((error
= zfs_secpolicy_write_perms(from
,
777 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
780 if ((error
= zfs_get_parent(to
, parentname
,
781 sizeof (parentname
))) != 0)
784 if ((error
= zfs_secpolicy_write_perms(parentname
,
785 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
788 if ((error
= zfs_secpolicy_write_perms(parentname
,
789 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
797 zfs_secpolicy_rename(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
799 return (zfs_secpolicy_rename_perms(zc
->zc_name
, zc
->zc_value
, cr
));
804 zfs_secpolicy_promote(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
807 dsl_dataset_t
*clone
;
810 error
= zfs_secpolicy_write_perms(zc
->zc_name
,
811 ZFS_DELEG_PERM_PROMOTE
, cr
);
815 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
819 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &clone
);
822 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
823 dsl_dataset_t
*origin
= NULL
;
827 error
= dsl_dataset_hold_obj(dd
->dd_pool
,
828 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin
);
830 dsl_dataset_rele(clone
, FTAG
);
831 dsl_pool_rele(dp
, FTAG
);
835 error
= zfs_secpolicy_write_perms_ds(zc
->zc_name
, clone
,
836 ZFS_DELEG_PERM_MOUNT
, cr
);
838 dsl_dataset_name(origin
, parentname
);
840 error
= zfs_secpolicy_write_perms_ds(parentname
, origin
,
841 ZFS_DELEG_PERM_PROMOTE
, cr
);
843 dsl_dataset_rele(clone
, FTAG
);
844 dsl_dataset_rele(origin
, FTAG
);
846 dsl_pool_rele(dp
, FTAG
);
852 zfs_secpolicy_recv(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
856 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
857 ZFS_DELEG_PERM_RECEIVE
, cr
)) != 0)
860 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
861 ZFS_DELEG_PERM_MOUNT
, cr
)) != 0)
864 return (zfs_secpolicy_write_perms(zc
->zc_name
,
865 ZFS_DELEG_PERM_CREATE
, cr
));
869 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
871 return (zfs_secpolicy_write_perms(name
,
872 ZFS_DELEG_PERM_SNAPSHOT
, cr
));
876 * Check for permission to create each snapshot in the nvlist.
880 zfs_secpolicy_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
886 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
887 return (SET_ERROR(EINVAL
));
888 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
889 pair
= nvlist_next_nvpair(snaps
, pair
)) {
890 char *name
= nvpair_name(pair
);
891 char *atp
= strchr(name
, '@');
894 error
= SET_ERROR(EINVAL
);
898 error
= zfs_secpolicy_snapshot_perms(name
, cr
);
907 * Check for permission to create each snapshot in the nvlist.
911 zfs_secpolicy_bookmark(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
915 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
916 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
917 char *name
= nvpair_name(pair
);
918 char *hashp
= strchr(name
, '#');
921 error
= SET_ERROR(EINVAL
);
925 error
= zfs_secpolicy_write_perms(name
,
926 ZFS_DELEG_PERM_BOOKMARK
, cr
);
936 zfs_secpolicy_remap(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
938 return (zfs_secpolicy_write_perms(zc
->zc_name
,
939 ZFS_DELEG_PERM_REMAP
, cr
));
944 zfs_secpolicy_destroy_bookmarks(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
946 nvpair_t
*pair
, *nextpair
;
949 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
951 char *name
= nvpair_name(pair
);
952 char *hashp
= strchr(name
, '#');
953 nextpair
= nvlist_next_nvpair(innvl
, pair
);
956 error
= SET_ERROR(EINVAL
);
961 error
= zfs_secpolicy_write_perms(name
,
962 ZFS_DELEG_PERM_DESTROY
, cr
);
964 if (error
== ENOENT
) {
966 * Ignore any filesystems that don't exist (we consider
967 * their bookmarks "already destroyed"). Remove
968 * the name from the nvl here in case the filesystem
969 * is created between now and when we try to destroy
970 * the bookmark (in which case we don't want to
971 * destroy it since we haven't checked for permission).
973 fnvlist_remove_nvpair(innvl
, pair
);
985 zfs_secpolicy_log_history(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
988 * Even root must have a proper TSD so that we know what pool
991 if (tsd_get(zfs_allow_log_key
) == NULL
)
992 return (SET_ERROR(EPERM
));
997 zfs_secpolicy_create_clone(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
999 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
1003 if ((error
= zfs_get_parent(zc
->zc_name
, parentname
,
1004 sizeof (parentname
))) != 0)
1007 if (nvlist_lookup_string(innvl
, "origin", &origin
) == 0 &&
1008 (error
= zfs_secpolicy_write_perms(origin
,
1009 ZFS_DELEG_PERM_CLONE
, cr
)) != 0)
1012 if ((error
= zfs_secpolicy_write_perms(parentname
,
1013 ZFS_DELEG_PERM_CREATE
, cr
)) != 0)
1016 return (zfs_secpolicy_write_perms(parentname
,
1017 ZFS_DELEG_PERM_MOUNT
, cr
));
1021 * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
1022 * SYS_CONFIG privilege, which is not available in a local zone.
1026 zfs_secpolicy_config(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1028 if (secpolicy_sys_config(cr
, B_FALSE
) != 0)
1029 return (SET_ERROR(EPERM
));
1035 * Policy for object to name lookups.
1039 zfs_secpolicy_diff(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1043 if ((error
= secpolicy_sys_config(cr
, B_FALSE
)) == 0)
1046 error
= zfs_secpolicy_write_perms(zc
->zc_name
, ZFS_DELEG_PERM_DIFF
, cr
);
1051 * Policy for fault injection. Requires all privileges.
1055 zfs_secpolicy_inject(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1057 return (secpolicy_zinject(cr
));
1062 zfs_secpolicy_inherit_prop(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1064 zfs_prop_t prop
= zfs_name_to_prop(zc
->zc_value
);
1066 if (prop
== ZPROP_INVAL
) {
1067 if (!zfs_prop_user(zc
->zc_value
))
1068 return (SET_ERROR(EINVAL
));
1069 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1070 ZFS_DELEG_PERM_USERPROP
, cr
));
1072 return (zfs_secpolicy_setprop(zc
->zc_name
, prop
,
1078 zfs_secpolicy_userspace_one(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1080 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1084 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1085 return (SET_ERROR(EINVAL
));
1087 if (zc
->zc_value
[0] == 0) {
1089 * They are asking about a posix uid/gid. If it's
1090 * themself, allow it.
1092 if (zc
->zc_objset_type
== ZFS_PROP_USERUSED
||
1093 zc
->zc_objset_type
== ZFS_PROP_USERQUOTA
) {
1094 if (zc
->zc_guid
== crgetuid(cr
))
1097 if (groupmember(zc
->zc_guid
, cr
))
1102 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1103 userquota_perms
[zc
->zc_objset_type
], cr
));
1107 zfs_secpolicy_userspace_many(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1109 int err
= zfs_secpolicy_read(zc
, innvl
, cr
);
1113 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
1114 return (SET_ERROR(EINVAL
));
1116 return (zfs_secpolicy_write_perms(zc
->zc_name
,
1117 userquota_perms
[zc
->zc_objset_type
], cr
));
1122 zfs_secpolicy_userspace_upgrade(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1124 return (zfs_secpolicy_setprop(zc
->zc_name
, ZFS_PROP_VERSION
,
1130 zfs_secpolicy_hold(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1136 error
= nvlist_lookup_nvlist(innvl
, "holds", &holds
);
1138 return (SET_ERROR(EINVAL
));
1140 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
1141 pair
= nvlist_next_nvpair(holds
, pair
)) {
1142 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1143 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1146 error
= zfs_secpolicy_write_perms(fsname
,
1147 ZFS_DELEG_PERM_HOLD
, cr
);
1156 zfs_secpolicy_release(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1161 for (pair
= nvlist_next_nvpair(innvl
, NULL
); pair
!= NULL
;
1162 pair
= nvlist_next_nvpair(innvl
, pair
)) {
1163 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1164 error
= dmu_fsname(nvpair_name(pair
), fsname
);
1167 error
= zfs_secpolicy_write_perms(fsname
,
1168 ZFS_DELEG_PERM_RELEASE
, cr
);
1176 * Policy for allowing temporary snapshots to be taken or released
1179 zfs_secpolicy_tmp_snapshot(zfs_cmd_t
*zc
, nvlist_t
*innvl
, cred_t
*cr
)
1182 * A temporary snapshot is the same as a snapshot,
1183 * hold, destroy and release all rolled into one.
1184 * Delegated diff alone is sufficient that we allow this.
1188 if ((error
= zfs_secpolicy_write_perms(zc
->zc_name
,
1189 ZFS_DELEG_PERM_DIFF
, cr
)) == 0)
1192 error
= zfs_secpolicy_snapshot_perms(zc
->zc_name
, cr
);
1194 error
= zfs_secpolicy_hold(zc
, innvl
, cr
);
1196 error
= zfs_secpolicy_release(zc
, innvl
, cr
);
1198 error
= zfs_secpolicy_destroy(zc
, innvl
, cr
);
1203 * Returns the nvlist as specified by the user in the zfs_cmd_t.
1206 get_nvlist(uint64_t nvl
, uint64_t size
, int iflag
, nvlist_t
**nvp
)
1210 nvlist_t
*list
= NULL
;
1213 * Read in and unpack the user-supplied nvlist.
1216 return (SET_ERROR(EINVAL
));
1218 packed
= kmem_alloc(size
, KM_SLEEP
);
1220 if ((error
= ddi_copyin((void *)(uintptr_t)nvl
, packed
, size
,
1222 kmem_free(packed
, size
);
1223 return (SET_ERROR(EFAULT
));
1226 if ((error
= nvlist_unpack(packed
, size
, &list
, 0)) != 0) {
1227 kmem_free(packed
, size
);
1231 kmem_free(packed
, size
);
1238 * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
1239 * Entries will be removed from the end of the nvlist, and one int32 entry
1240 * named "N_MORE_ERRORS" will be added indicating how many entries were
1244 nvlist_smush(nvlist_t
*errors
, size_t max
)
1248 size
= fnvlist_size(errors
);
1251 nvpair_t
*more_errors
;
1255 return (SET_ERROR(ENOMEM
));
1257 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, 0);
1258 more_errors
= nvlist_prev_nvpair(errors
, NULL
);
1261 nvpair_t
*pair
= nvlist_prev_nvpair(errors
,
1263 fnvlist_remove_nvpair(errors
, pair
);
1265 size
= fnvlist_size(errors
);
1266 } while (size
> max
);
1268 fnvlist_remove_nvpair(errors
, more_errors
);
1269 fnvlist_add_int32(errors
, ZPROP_N_MORE_ERRORS
, n
);
1270 ASSERT3U(fnvlist_size(errors
), <=, max
);
1277 put_nvlist(zfs_cmd_t
*zc
, nvlist_t
*nvl
)
1279 char *packed
= NULL
;
1283 size
= fnvlist_size(nvl
);
1285 if (size
> zc
->zc_nvlist_dst_size
) {
1286 error
= SET_ERROR(ENOMEM
);
1288 packed
= fnvlist_pack(nvl
, &size
);
1289 if (ddi_copyout(packed
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
1290 size
, zc
->zc_iflags
) != 0)
1291 error
= SET_ERROR(EFAULT
);
1292 fnvlist_pack_free(packed
, size
);
1295 zc
->zc_nvlist_dst_size
= size
;
1296 zc
->zc_nvlist_dst_filled
= B_TRUE
;
1301 getzfsvfs_impl(objset_t
*os
, zfsvfs_t
**zfvp
)
1304 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1305 return (SET_ERROR(EINVAL
));
1308 mutex_enter(&os
->os_user_ptr_lock
);
1309 *zfvp
= dmu_objset_get_user(os
);
1311 VFS_HOLD((*zfvp
)->z_vfs
);
1313 error
= SET_ERROR(ESRCH
);
1315 mutex_exit(&os
->os_user_ptr_lock
);
1320 getzfsvfs(const char *dsname
, zfsvfs_t
**zfvp
)
1325 error
= dmu_objset_hold(dsname
, FTAG
, &os
);
1329 error
= getzfsvfs_impl(os
, zfvp
);
1330 dmu_objset_rele(os
, FTAG
);
1335 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
1336 * case its z_vfs will be NULL, and it will be opened as the owner.
1337 * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
1338 * which prevents all vnode ops from running.
1341 zfsvfs_hold(const char *name
, void *tag
, zfsvfs_t
**zfvp
, boolean_t writer
)
1345 if (getzfsvfs(name
, zfvp
) != 0)
1346 error
= zfsvfs_create(name
, zfvp
);
1348 rrm_enter(&(*zfvp
)->z_teardown_lock
, (writer
) ? RW_WRITER
:
1350 if ((*zfvp
)->z_unmounted
) {
1352 * XXX we could probably try again, since the unmounting
1353 * thread should be just about to disassociate the
1354 * objset from the zfsvfs.
1356 rrm_exit(&(*zfvp
)->z_teardown_lock
, tag
);
1357 return (SET_ERROR(EBUSY
));
1364 zfsvfs_rele(zfsvfs_t
*zfsvfs
, void *tag
)
1366 rrm_exit(&zfsvfs
->z_teardown_lock
, tag
);
1368 if (zfsvfs
->z_vfs
) {
1369 VFS_RELE(zfsvfs
->z_vfs
);
1371 dmu_objset_disown(zfsvfs
->z_os
, zfsvfs
);
1372 zfsvfs_free(zfsvfs
);
1377 zfs_ioc_pool_create(zfs_cmd_t
*zc
)
1380 nvlist_t
*config
, *props
= NULL
;
1381 nvlist_t
*rootprops
= NULL
;
1382 nvlist_t
*zplprops
= NULL
;
1384 if (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1385 zc
->zc_iflags
, &config
))
1388 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1389 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1390 zc
->zc_iflags
, &props
))) {
1391 nvlist_free(config
);
1396 nvlist_t
*nvl
= NULL
;
1397 uint64_t version
= SPA_VERSION
;
1399 (void) nvlist_lookup_uint64(props
,
1400 zpool_prop_to_name(ZPOOL_PROP_VERSION
), &version
);
1401 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1402 error
= SET_ERROR(EINVAL
);
1403 goto pool_props_bad
;
1405 (void) nvlist_lookup_nvlist(props
, ZPOOL_ROOTFS_PROPS
, &nvl
);
1407 error
= nvlist_dup(nvl
, &rootprops
, KM_SLEEP
);
1409 nvlist_free(config
);
1413 (void) nvlist_remove_all(props
, ZPOOL_ROOTFS_PROPS
);
1415 VERIFY(nvlist_alloc(&zplprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
1416 error
= zfs_fill_zplprops_root(version
, rootprops
,
1419 goto pool_props_bad
;
1422 error
= spa_create(zc
->zc_name
, config
, props
, zplprops
);
1425 * Set the remaining root properties
1427 if (!error
&& (error
= zfs_set_prop_nvlist(zc
->zc_name
,
1428 ZPROP_SRC_LOCAL
, rootprops
, NULL
)) != 0)
1429 (void) spa_destroy(zc
->zc_name
);
1432 nvlist_free(rootprops
);
1433 nvlist_free(zplprops
);
1434 nvlist_free(config
);
1441 zfs_ioc_pool_destroy(zfs_cmd_t
*zc
)
1444 zfs_log_history(zc
);
1445 error
= spa_destroy(zc
->zc_name
);
1447 zvol_remove_minors(zc
->zc_name
);
1452 zfs_ioc_pool_import(zfs_cmd_t
*zc
)
1454 nvlist_t
*config
, *props
= NULL
;
1458 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1459 zc
->zc_iflags
, &config
)) != 0)
1462 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1463 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1464 zc
->zc_iflags
, &props
))) {
1465 nvlist_free(config
);
1469 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0 ||
1470 guid
!= zc
->zc_guid
)
1471 error
= SET_ERROR(EINVAL
);
1473 error
= spa_import(zc
->zc_name
, config
, props
, zc
->zc_cookie
);
1475 if (zc
->zc_nvlist_dst
!= 0) {
1478 if ((err
= put_nvlist(zc
, config
)) != 0)
1482 nvlist_free(config
);
1490 zfs_ioc_pool_export(zfs_cmd_t
*zc
)
1493 boolean_t force
= (boolean_t
)zc
->zc_cookie
;
1494 boolean_t hardforce
= (boolean_t
)zc
->zc_guid
;
1496 zfs_log_history(zc
);
1497 error
= spa_export(zc
->zc_name
, NULL
, force
, hardforce
);
1499 zvol_remove_minors(zc
->zc_name
);
1504 zfs_ioc_pool_configs(zfs_cmd_t
*zc
)
1509 if ((configs
= spa_all_configs(&zc
->zc_cookie
)) == NULL
)
1510 return (SET_ERROR(EEXIST
));
1512 error
= put_nvlist(zc
, configs
);
1514 nvlist_free(configs
);
1521 * zc_name name of the pool
1524 * zc_cookie real errno
1525 * zc_nvlist_dst config nvlist
1526 * zc_nvlist_dst_size size of config nvlist
1529 zfs_ioc_pool_stats(zfs_cmd_t
*zc
)
1535 error
= spa_get_stats(zc
->zc_name
, &config
, zc
->zc_value
,
1536 sizeof (zc
->zc_value
));
1538 if (config
!= NULL
) {
1539 ret
= put_nvlist(zc
, config
);
1540 nvlist_free(config
);
1543 * The config may be present even if 'error' is non-zero.
1544 * In this case we return success, and preserve the real errno
1547 zc
->zc_cookie
= error
;
1556 * Try to import the given pool, returning pool stats as appropriate so that
1557 * user land knows which devices are available and overall pool health.
1560 zfs_ioc_pool_tryimport(zfs_cmd_t
*zc
)
1562 nvlist_t
*tryconfig
, *config
;
1565 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1566 zc
->zc_iflags
, &tryconfig
)) != 0)
1569 config
= spa_tryimport(tryconfig
);
1571 nvlist_free(tryconfig
);
1574 return (SET_ERROR(EINVAL
));
1576 error
= put_nvlist(zc
, config
);
1577 nvlist_free(config
);
1584 * zc_name name of the pool
1585 * zc_cookie scan func (pool_scan_func_t)
1586 * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
1589 zfs_ioc_pool_scan(zfs_cmd_t
*zc
)
1594 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1597 if (zc
->zc_flags
>= POOL_SCRUB_FLAGS_END
)
1598 return (SET_ERROR(EINVAL
));
1600 if (zc
->zc_flags
== POOL_SCRUB_PAUSE
)
1601 error
= spa_scrub_pause_resume(spa
, POOL_SCRUB_PAUSE
);
1602 else if (zc
->zc_cookie
== POOL_SCAN_NONE
)
1603 error
= spa_scan_stop(spa
);
1605 error
= spa_scan(spa
, zc
->zc_cookie
);
1607 spa_close(spa
, FTAG
);
1613 zfs_ioc_pool_freeze(zfs_cmd_t
*zc
)
1618 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1621 spa_close(spa
, FTAG
);
1627 zfs_ioc_pool_upgrade(zfs_cmd_t
*zc
)
1632 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1635 if (zc
->zc_cookie
< spa_version(spa
) ||
1636 !SPA_VERSION_IS_SUPPORTED(zc
->zc_cookie
)) {
1637 spa_close(spa
, FTAG
);
1638 return (SET_ERROR(EINVAL
));
1641 spa_upgrade(spa
, zc
->zc_cookie
);
1642 spa_close(spa
, FTAG
);
1648 zfs_ioc_pool_get_history(zfs_cmd_t
*zc
)
1655 if ((size
= zc
->zc_history_len
) == 0)
1656 return (SET_ERROR(EINVAL
));
1658 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1661 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
1662 spa_close(spa
, FTAG
);
1663 return (SET_ERROR(ENOTSUP
));
1666 hist_buf
= kmem_alloc(size
, KM_SLEEP
);
1667 if ((error
= spa_history_get(spa
, &zc
->zc_history_offset
,
1668 &zc
->zc_history_len
, hist_buf
)) == 0) {
1669 error
= ddi_copyout(hist_buf
,
1670 (void *)(uintptr_t)zc
->zc_history
,
1671 zc
->zc_history_len
, zc
->zc_iflags
);
1674 spa_close(spa
, FTAG
);
1675 kmem_free(hist_buf
, size
);
1680 zfs_ioc_pool_reguid(zfs_cmd_t
*zc
)
1685 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1687 error
= spa_change_guid(spa
);
1688 spa_close(spa
, FTAG
);
1694 zfs_ioc_dsobj_to_dsname(zfs_cmd_t
*zc
)
1696 return (dsl_dsobj_to_dsname(zc
->zc_name
, zc
->zc_obj
, zc
->zc_value
));
1701 * zc_name name of filesystem
1702 * zc_obj object to find
1705 * zc_value name of object
1708 zfs_ioc_obj_to_path(zfs_cmd_t
*zc
)
1713 /* XXX reading from objset not owned */
1714 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1716 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1717 dmu_objset_rele(os
, FTAG
);
1718 return (SET_ERROR(EINVAL
));
1720 error
= zfs_obj_to_path(os
, zc
->zc_obj
, zc
->zc_value
,
1721 sizeof (zc
->zc_value
));
1722 dmu_objset_rele(os
, FTAG
);
1729 * zc_name name of filesystem
1730 * zc_obj object to find
1733 * zc_stat stats on object
1734 * zc_value path to object
1737 zfs_ioc_obj_to_stats(zfs_cmd_t
*zc
)
1742 /* XXX reading from objset not owned */
1743 if ((error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) != 0)
1745 if (dmu_objset_type(os
) != DMU_OST_ZFS
) {
1746 dmu_objset_rele(os
, FTAG
);
1747 return (SET_ERROR(EINVAL
));
1749 error
= zfs_obj_to_stats(os
, zc
->zc_obj
, &zc
->zc_stat
, zc
->zc_value
,
1750 sizeof (zc
->zc_value
));
1751 dmu_objset_rele(os
, FTAG
);
1757 zfs_ioc_vdev_add(zfs_cmd_t
*zc
)
1761 nvlist_t
*config
, **l2cache
, **spares
;
1762 uint_t nl2cache
= 0, nspares
= 0;
1764 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1768 error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1769 zc
->zc_iflags
, &config
);
1770 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_L2CACHE
,
1771 &l2cache
, &nl2cache
);
1773 (void) nvlist_lookup_nvlist_array(config
, ZPOOL_CONFIG_SPARES
,
1777 * A root pool with concatenated devices is not supported.
1778 * Thus, can not add a device to a root pool.
1780 * Intent log device can not be added to a rootpool because
1781 * during mountroot, zil is replayed, a seperated log device
1782 * can not be accessed during the mountroot time.
1784 * l2cache and spare devices are ok to be added to a rootpool.
1786 if (spa_bootfs(spa
) != 0 && nl2cache
== 0 && nspares
== 0) {
1787 nvlist_free(config
);
1788 spa_close(spa
, FTAG
);
1789 return (SET_ERROR(EDOM
));
1793 error
= spa_vdev_add(spa
, config
);
1794 nvlist_free(config
);
1796 spa_close(spa
, FTAG
);
1802 * zc_name name of the pool
1803 * zc_guid guid of vdev to remove
1804 * zc_cookie cancel removal
1807 zfs_ioc_vdev_remove(zfs_cmd_t
*zc
)
1812 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1815 if (zc
->zc_cookie
!= 0) {
1816 error
= spa_vdev_remove_cancel(spa
);
1818 error
= spa_vdev_remove(spa
, zc
->zc_guid
, B_FALSE
);
1820 spa_close(spa
, FTAG
);
1825 zfs_ioc_vdev_set_state(zfs_cmd_t
*zc
)
1829 vdev_state_t newstate
= VDEV_STATE_UNKNOWN
;
1831 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1833 switch (zc
->zc_cookie
) {
1834 case VDEV_STATE_ONLINE
:
1835 error
= vdev_online(spa
, zc
->zc_guid
, zc
->zc_obj
, &newstate
);
1838 case VDEV_STATE_OFFLINE
:
1839 error
= vdev_offline(spa
, zc
->zc_guid
, zc
->zc_obj
);
1842 case VDEV_STATE_FAULTED
:
1843 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1844 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1845 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1847 error
= vdev_fault(spa
, zc
->zc_guid
, zc
->zc_obj
);
1850 case VDEV_STATE_DEGRADED
:
1851 if (zc
->zc_obj
!= VDEV_AUX_ERR_EXCEEDED
&&
1852 zc
->zc_obj
!= VDEV_AUX_EXTERNAL
)
1853 zc
->zc_obj
= VDEV_AUX_ERR_EXCEEDED
;
1855 error
= vdev_degrade(spa
, zc
->zc_guid
, zc
->zc_obj
);
1859 error
= SET_ERROR(EINVAL
);
1861 zc
->zc_cookie
= newstate
;
1862 spa_close(spa
, FTAG
);
1867 zfs_ioc_vdev_attach(zfs_cmd_t
*zc
)
1870 int replacing
= zc
->zc_cookie
;
1874 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1877 if ((error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1878 zc
->zc_iflags
, &config
)) == 0) {
1879 error
= spa_vdev_attach(spa
, zc
->zc_guid
, config
, replacing
);
1880 nvlist_free(config
);
1883 spa_close(spa
, FTAG
);
1888 zfs_ioc_vdev_detach(zfs_cmd_t
*zc
)
1893 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1896 error
= spa_vdev_detach(spa
, zc
->zc_guid
, 0, B_FALSE
);
1898 spa_close(spa
, FTAG
);
1903 zfs_ioc_vdev_split(zfs_cmd_t
*zc
)
1906 nvlist_t
*config
, *props
= NULL
;
1908 boolean_t exp
= !!(zc
->zc_cookie
& ZPOOL_EXPORT_AFTER_SPLIT
);
1910 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
1913 if (error
= get_nvlist(zc
->zc_nvlist_conf
, zc
->zc_nvlist_conf_size
,
1914 zc
->zc_iflags
, &config
)) {
1915 spa_close(spa
, FTAG
);
1919 if (zc
->zc_nvlist_src_size
!= 0 && (error
=
1920 get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
1921 zc
->zc_iflags
, &props
))) {
1922 spa_close(spa
, FTAG
);
1923 nvlist_free(config
);
1927 error
= spa_vdev_split_mirror(spa
, zc
->zc_string
, config
, props
, exp
);
1929 spa_close(spa
, FTAG
);
1931 nvlist_free(config
);
1938 zfs_ioc_vdev_setpath(zfs_cmd_t
*zc
)
1941 char *path
= zc
->zc_value
;
1942 uint64_t guid
= zc
->zc_guid
;
1945 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1949 error
= spa_vdev_setpath(spa
, guid
, path
);
1950 spa_close(spa
, FTAG
);
1955 zfs_ioc_vdev_setfru(zfs_cmd_t
*zc
)
1958 char *fru
= zc
->zc_value
;
1959 uint64_t guid
= zc
->zc_guid
;
1962 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
1966 error
= spa_vdev_setfru(spa
, guid
, fru
);
1967 spa_close(spa
, FTAG
);
1972 zfs_ioc_objset_stats_impl(zfs_cmd_t
*zc
, objset_t
*os
)
1977 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
1979 if (zc
->zc_nvlist_dst
!= 0 &&
1980 (error
= dsl_prop_get_all(os
, &nv
)) == 0) {
1981 dmu_objset_stats(os
, nv
);
1983 * NB: zvol_get_stats() will read the objset contents,
1984 * which we aren't supposed to do with a
1985 * DS_MODE_USER hold, because it could be
1986 * inconsistent. So this is a bit of a workaround...
1987 * XXX reading with out owning
1989 if (!zc
->zc_objset_stats
.dds_inconsistent
&&
1990 dmu_objset_type(os
) == DMU_OST_ZVOL
) {
1991 error
= zvol_get_stats(os
, nv
);
1996 error
= put_nvlist(zc
, nv
);
2005 * zc_name name of filesystem
2006 * zc_nvlist_dst_size size of buffer for property nvlist
2009 * zc_objset_stats stats
2010 * zc_nvlist_dst property nvlist
2011 * zc_nvlist_dst_size size of property nvlist
2014 zfs_ioc_objset_stats(zfs_cmd_t
*zc
)
2019 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2021 error
= zfs_ioc_objset_stats_impl(zc
, os
);
2022 dmu_objset_rele(os
, FTAG
);
2030 * zc_name name of filesystem
2031 * zc_nvlist_dst_size size of buffer for property nvlist
2034 * zc_nvlist_dst received property nvlist
2035 * zc_nvlist_dst_size size of received property nvlist
2037 * Gets received properties (distinct from local properties on or after
2038 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
2039 * local property values.
2042 zfs_ioc_objset_recvd_props(zfs_cmd_t
*zc
)
2048 * Without this check, we would return local property values if the
2049 * caller has not already received properties on or after
2050 * SPA_VERSION_RECVD_PROPS.
2052 if (!dsl_prop_get_hasrecvd(zc
->zc_name
))
2053 return (SET_ERROR(ENOTSUP
));
2055 if (zc
->zc_nvlist_dst
!= 0 &&
2056 (error
= dsl_prop_get_received(zc
->zc_name
, &nv
)) == 0) {
2057 error
= put_nvlist(zc
, nv
);
2065 nvl_add_zplprop(objset_t
*os
, nvlist_t
*props
, zfs_prop_t prop
)
2071 * zfs_get_zplprop() will either find a value or give us
2072 * the default value (if there is one).
2074 if ((error
= zfs_get_zplprop(os
, prop
, &value
)) != 0)
2076 VERIFY(nvlist_add_uint64(props
, zfs_prop_to_name(prop
), value
) == 0);
2082 * zc_name name of filesystem
2083 * zc_nvlist_dst_size size of buffer for zpl property nvlist
2086 * zc_nvlist_dst zpl property nvlist
2087 * zc_nvlist_dst_size size of zpl property nvlist
2090 zfs_ioc_objset_zplprops(zfs_cmd_t
*zc
)
2095 /* XXX reading without owning */
2096 if (err
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
))
2099 dmu_objset_fast_stat(os
, &zc
->zc_objset_stats
);
2102 * NB: nvl_add_zplprop() will read the objset contents,
2103 * which we aren't supposed to do with a DS_MODE_USER
2104 * hold, because it could be inconsistent.
2106 if (zc
->zc_nvlist_dst
!= (uintptr_t)NULL
&&
2107 !zc
->zc_objset_stats
.dds_inconsistent
&&
2108 dmu_objset_type(os
) == DMU_OST_ZFS
) {
2111 VERIFY(nvlist_alloc(&nv
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2112 if ((err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_VERSION
)) == 0 &&
2113 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_NORMALIZE
)) == 0 &&
2114 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_UTF8ONLY
)) == 0 &&
2115 (err
= nvl_add_zplprop(os
, nv
, ZFS_PROP_CASE
)) == 0)
2116 err
= put_nvlist(zc
, nv
);
2119 err
= SET_ERROR(ENOENT
);
2121 dmu_objset_rele(os
, FTAG
);
2126 dataset_name_hidden(const char *name
)
2129 * Skip over datasets that are not visible in this zone,
2130 * internal datasets (which have a $ in their name), and
2131 * temporary datasets (which have a % in their name).
2133 if (strchr(name
, '$') != NULL
)
2135 if (strchr(name
, '%') != NULL
)
2137 if (!INGLOBALZONE(curproc
) && !zone_dataset_visible(name
, NULL
))
2144 * zc_name name of filesystem
2145 * zc_cookie zap cursor
2146 * zc_nvlist_dst_size size of buffer for property nvlist
2149 * zc_name name of next filesystem
2150 * zc_cookie zap cursor
2151 * zc_objset_stats stats
2152 * zc_nvlist_dst property nvlist
2153 * zc_nvlist_dst_size size of property nvlist
2156 zfs_ioc_dataset_list_next(zfs_cmd_t
*zc
)
2161 size_t orig_len
= strlen(zc
->zc_name
);
2164 if (error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
)) {
2165 if (error
== ENOENT
)
2166 error
= SET_ERROR(ESRCH
);
2170 p
= strrchr(zc
->zc_name
, '/');
2171 if (p
== NULL
|| p
[1] != '\0')
2172 (void) strlcat(zc
->zc_name
, "/", sizeof (zc
->zc_name
));
2173 p
= zc
->zc_name
+ strlen(zc
->zc_name
);
2176 error
= dmu_dir_list_next(os
,
2177 sizeof (zc
->zc_name
) - (p
- zc
->zc_name
), p
,
2178 NULL
, &zc
->zc_cookie
);
2179 if (error
== ENOENT
)
2180 error
= SET_ERROR(ESRCH
);
2181 } while (error
== 0 && dataset_name_hidden(zc
->zc_name
));
2182 dmu_objset_rele(os
, FTAG
);
2185 * If it's an internal dataset (ie. with a '$' in its name),
2186 * don't try to get stats for it, otherwise we'll return ENOENT.
2188 if (error
== 0 && strchr(zc
->zc_name
, '$') == NULL
) {
2189 error
= zfs_ioc_objset_stats(zc
); /* fill in the stats */
2190 if (error
== ENOENT
) {
2191 /* We lost a race with destroy, get the next one. */
2192 zc
->zc_name
[orig_len
] = '\0';
2201 * zc_name name of filesystem
2202 * zc_cookie zap cursor
2203 * zc_nvlist_dst_size size of buffer for property nvlist
2204 * zc_simple when set, only name is requested
2207 * zc_name name of next snapshot
2208 * zc_objset_stats stats
2209 * zc_nvlist_dst property nvlist
2210 * zc_nvlist_dst_size size of property nvlist
2213 zfs_ioc_snapshot_list_next(zfs_cmd_t
*zc
)
2218 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
2220 return (error
== ENOENT
? ESRCH
: error
);
2224 * A dataset name of maximum length cannot have any snapshots,
2225 * so exit immediately.
2227 if (strlcat(zc
->zc_name
, "@", sizeof (zc
->zc_name
)) >=
2228 ZFS_MAX_DATASET_NAME_LEN
) {
2229 dmu_objset_rele(os
, FTAG
);
2230 return (SET_ERROR(ESRCH
));
2233 error
= dmu_snapshot_list_next(os
,
2234 sizeof (zc
->zc_name
) - strlen(zc
->zc_name
),
2235 zc
->zc_name
+ strlen(zc
->zc_name
), &zc
->zc_obj
, &zc
->zc_cookie
,
2238 if (error
== 0 && !zc
->zc_simple
) {
2240 dsl_pool_t
*dp
= os
->os_dsl_dataset
->ds_dir
->dd_pool
;
2242 error
= dsl_dataset_hold_obj(dp
, zc
->zc_obj
, FTAG
, &ds
);
2246 error
= dmu_objset_from_ds(ds
, &ossnap
);
2248 error
= zfs_ioc_objset_stats_impl(zc
, ossnap
);
2249 dsl_dataset_rele(ds
, FTAG
);
2251 } else if (error
== ENOENT
) {
2252 error
= SET_ERROR(ESRCH
);
2255 dmu_objset_rele(os
, FTAG
);
2256 /* if we failed, undo the @ that we tacked on to zc_name */
2258 *strchr(zc
->zc_name
, '@') = '\0';
2263 zfs_prop_set_userquota(const char *dsname
, nvpair_t
*pair
)
2265 const char *propname
= nvpair_name(pair
);
2267 unsigned int vallen
;
2270 zfs_userquota_prop_t type
;
2276 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2278 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2279 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2281 return (SET_ERROR(EINVAL
));
2285 * A correctly constructed propname is encoded as
2286 * userquota@<rid>-<domain>.
2288 if ((dash
= strchr(propname
, '-')) == NULL
||
2289 nvpair_value_uint64_array(pair
, &valary
, &vallen
) != 0 ||
2291 return (SET_ERROR(EINVAL
));
2298 err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_FALSE
);
2300 err
= zfs_set_userquota(zfsvfs
, type
, domain
, rid
, quota
);
2301 zfsvfs_rele(zfsvfs
, FTAG
);
2308 * If the named property is one that has a special function to set its value,
2309 * return 0 on success and a positive error code on failure; otherwise if it is
2310 * not one of the special properties handled by this function, return -1.
2312 * XXX: It would be better for callers of the property interface if we handled
2313 * these special cases in dsl_prop.c (in the dsl layer).
2316 zfs_prop_set_special(const char *dsname
, zprop_source_t source
,
2319 const char *propname
= nvpair_name(pair
);
2320 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2324 if (prop
== ZPROP_INVAL
) {
2325 if (zfs_prop_userquota(propname
))
2326 return (zfs_prop_set_userquota(dsname
, pair
));
2330 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2332 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
2333 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2337 if (zfs_prop_get_type(prop
) == PROP_TYPE_STRING
)
2340 VERIFY(0 == nvpair_value_uint64(pair
, &intval
));
2343 case ZFS_PROP_QUOTA
:
2344 err
= dsl_dir_set_quota(dsname
, source
, intval
);
2346 case ZFS_PROP_REFQUOTA
:
2347 err
= dsl_dataset_set_refquota(dsname
, source
, intval
);
2349 case ZFS_PROP_FILESYSTEM_LIMIT
:
2350 case ZFS_PROP_SNAPSHOT_LIMIT
:
2351 if (intval
== UINT64_MAX
) {
2352 /* clearing the limit, just do it */
2355 err
= dsl_dir_activate_fs_ss_limit(dsname
);
2358 * Set err to -1 to force the zfs_set_prop_nvlist code down the
2359 * default path to set the value in the nvlist.
2364 case ZFS_PROP_RESERVATION
:
2365 err
= dsl_dir_set_reservation(dsname
, source
, intval
);
2367 case ZFS_PROP_REFRESERVATION
:
2368 err
= dsl_dataset_set_refreservation(dsname
, source
, intval
);
2370 case ZFS_PROP_VOLSIZE
:
2371 err
= zvol_set_volsize(dsname
, intval
);
2373 case ZFS_PROP_VERSION
:
2377 if ((err
= zfsvfs_hold(dsname
, FTAG
, &zfsvfs
, B_TRUE
)) != 0)
2380 err
= zfs_set_version(zfsvfs
, intval
);
2381 zfsvfs_rele(zfsvfs
, FTAG
);
2383 if (err
== 0 && intval
>= ZPL_VERSION_USERSPACE
) {
2386 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
2387 (void) strcpy(zc
->zc_name
, dsname
);
2388 (void) zfs_ioc_userspace_upgrade(zc
);
2389 kmem_free(zc
, sizeof (zfs_cmd_t
));
2401 * This function is best effort. If it fails to set any of the given properties,
2402 * it continues to set as many as it can and returns the last error
2403 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2404 * with the list of names of all the properties that failed along with the
2405 * corresponding error numbers.
2407 * If every property is set successfully, zero is returned and errlist is not
2411 zfs_set_prop_nvlist(const char *dsname
, zprop_source_t source
, nvlist_t
*nvl
,
2419 nvlist_t
*genericnvl
= fnvlist_alloc();
2420 nvlist_t
*retrynvl
= fnvlist_alloc();
2424 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2425 const char *propname
= nvpair_name(pair
);
2426 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2429 /* decode the property value */
2431 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2433 attrs
= fnvpair_value_nvlist(pair
);
2434 if (nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
2436 err
= SET_ERROR(EINVAL
);
2439 /* Validate value type */
2440 if (err
== 0 && prop
== ZPROP_INVAL
) {
2441 if (zfs_prop_user(propname
)) {
2442 if (nvpair_type(propval
) != DATA_TYPE_STRING
)
2443 err
= SET_ERROR(EINVAL
);
2444 } else if (zfs_prop_userquota(propname
)) {
2445 if (nvpair_type(propval
) !=
2446 DATA_TYPE_UINT64_ARRAY
)
2447 err
= SET_ERROR(EINVAL
);
2449 err
= SET_ERROR(EINVAL
);
2451 } else if (err
== 0) {
2452 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2453 if (zfs_prop_get_type(prop
) != PROP_TYPE_STRING
)
2454 err
= SET_ERROR(EINVAL
);
2455 } else if (nvpair_type(propval
) == DATA_TYPE_UINT64
) {
2458 intval
= fnvpair_value_uint64(propval
);
2460 switch (zfs_prop_get_type(prop
)) {
2461 case PROP_TYPE_NUMBER
:
2463 case PROP_TYPE_STRING
:
2464 err
= SET_ERROR(EINVAL
);
2466 case PROP_TYPE_INDEX
:
2467 if (zfs_prop_index_to_string(prop
,
2468 intval
, &unused
) != 0)
2469 err
= SET_ERROR(EINVAL
);
2473 "unknown property type");
2476 err
= SET_ERROR(EINVAL
);
2480 /* Validate permissions */
2482 err
= zfs_check_settable(dsname
, pair
, CRED());
2485 err
= zfs_prop_set_special(dsname
, source
, pair
);
2488 * For better performance we build up a list of
2489 * properties to set in a single transaction.
2491 err
= nvlist_add_nvpair(genericnvl
, pair
);
2492 } else if (err
!= 0 && nvl
!= retrynvl
) {
2494 * This may be a spurious error caused by
2495 * receiving quota and reservation out of order.
2496 * Try again in a second pass.
2498 err
= nvlist_add_nvpair(retrynvl
, pair
);
2503 if (errlist
!= NULL
)
2504 fnvlist_add_int32(errlist
, propname
, err
);
2509 if (nvl
!= retrynvl
&& !nvlist_empty(retrynvl
)) {
2514 if (!nvlist_empty(genericnvl
) &&
2515 dsl_props_set(dsname
, source
, genericnvl
) != 0) {
2517 * If this fails, we still want to set as many properties as we
2518 * can, so try setting them individually.
2521 while ((pair
= nvlist_next_nvpair(genericnvl
, pair
)) != NULL
) {
2522 const char *propname
= nvpair_name(pair
);
2526 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
2528 attrs
= fnvpair_value_nvlist(pair
);
2529 propval
= fnvlist_lookup_nvpair(attrs
,
2533 if (nvpair_type(propval
) == DATA_TYPE_STRING
) {
2534 strval
= fnvpair_value_string(propval
);
2535 err
= dsl_prop_set_string(dsname
, propname
,
2538 intval
= fnvpair_value_uint64(propval
);
2539 err
= dsl_prop_set_int(dsname
, propname
, source
,
2544 if (errlist
!= NULL
) {
2545 fnvlist_add_int32(errlist
, propname
,
2552 nvlist_free(genericnvl
);
2553 nvlist_free(retrynvl
);
2559 * Check that all the properties are valid user properties.
2562 zfs_check_userprops(const char *fsname
, nvlist_t
*nvl
)
2564 nvpair_t
*pair
= NULL
;
2567 while ((pair
= nvlist_next_nvpair(nvl
, pair
)) != NULL
) {
2568 const char *propname
= nvpair_name(pair
);
2570 if (!zfs_prop_user(propname
) ||
2571 nvpair_type(pair
) != DATA_TYPE_STRING
)
2572 return (SET_ERROR(EINVAL
));
2574 if (error
= zfs_secpolicy_write_perms(fsname
,
2575 ZFS_DELEG_PERM_USERPROP
, CRED()))
2578 if (strlen(propname
) >= ZAP_MAXNAMELEN
)
2579 return (SET_ERROR(ENAMETOOLONG
));
2581 if (strlen(fnvpair_value_string(pair
)) >= ZAP_MAXVALUELEN
)
2588 props_skip(nvlist_t
*props
, nvlist_t
*skipped
, nvlist_t
**newprops
)
2592 VERIFY(nvlist_alloc(newprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2595 while ((pair
= nvlist_next_nvpair(props
, pair
)) != NULL
) {
2596 if (nvlist_exists(skipped
, nvpair_name(pair
)))
2599 VERIFY(nvlist_add_nvpair(*newprops
, pair
) == 0);
2604 clear_received_props(const char *dsname
, nvlist_t
*props
,
2608 nvlist_t
*cleared_props
= NULL
;
2609 props_skip(props
, skipped
, &cleared_props
);
2610 if (!nvlist_empty(cleared_props
)) {
2612 * Acts on local properties until the dataset has received
2613 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
2615 zprop_source_t flags
= (ZPROP_SRC_NONE
|
2616 (dsl_prop_get_hasrecvd(dsname
) ? ZPROP_SRC_RECEIVED
: 0));
2617 err
= zfs_set_prop_nvlist(dsname
, flags
, cleared_props
, NULL
);
2619 nvlist_free(cleared_props
);
2625 * zc_name name of filesystem
2626 * zc_value name of property to set
2627 * zc_nvlist_src{_size} nvlist of properties to apply
2628 * zc_cookie received properties flag
2631 * zc_nvlist_dst{_size} error for each unapplied received property
2634 zfs_ioc_set_prop(zfs_cmd_t
*zc
)
2637 boolean_t received
= zc
->zc_cookie
;
2638 zprop_source_t source
= (received
? ZPROP_SRC_RECEIVED
:
2643 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2644 zc
->zc_iflags
, &nvl
)) != 0)
2648 nvlist_t
*origprops
;
2650 if (dsl_prop_get_received(zc
->zc_name
, &origprops
) == 0) {
2651 (void) clear_received_props(zc
->zc_name
,
2653 nvlist_free(origprops
);
2656 error
= dsl_prop_set_hasrecvd(zc
->zc_name
);
2659 errors
= fnvlist_alloc();
2661 error
= zfs_set_prop_nvlist(zc
->zc_name
, source
, nvl
, errors
);
2663 if (zc
->zc_nvlist_dst
!= (uintptr_t)NULL
&& errors
!= NULL
) {
2664 (void) put_nvlist(zc
, errors
);
2667 nvlist_free(errors
);
2674 * zc_name name of filesystem
2675 * zc_value name of property to inherit
2676 * zc_cookie revert to received value if TRUE
2681 zfs_ioc_inherit_prop(zfs_cmd_t
*zc
)
2683 const char *propname
= zc
->zc_value
;
2684 zfs_prop_t prop
= zfs_name_to_prop(propname
);
2685 boolean_t received
= zc
->zc_cookie
;
2686 zprop_source_t source
= (received
2687 ? ZPROP_SRC_NONE
/* revert to received value, if any */
2688 : ZPROP_SRC_INHERITED
); /* explicitly inherit */
2697 * zfs_prop_set_special() expects properties in the form of an
2698 * nvpair with type info.
2700 if (prop
== ZPROP_INVAL
) {
2701 if (!zfs_prop_user(propname
))
2702 return (SET_ERROR(EINVAL
));
2704 type
= PROP_TYPE_STRING
;
2705 } else if (prop
== ZFS_PROP_VOLSIZE
||
2706 prop
== ZFS_PROP_VERSION
) {
2707 return (SET_ERROR(EINVAL
));
2709 type
= zfs_prop_get_type(prop
);
2712 VERIFY(nvlist_alloc(&dummy
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
2715 case PROP_TYPE_STRING
:
2716 VERIFY(0 == nvlist_add_string(dummy
, propname
, ""));
2718 case PROP_TYPE_NUMBER
:
2719 case PROP_TYPE_INDEX
:
2720 VERIFY(0 == nvlist_add_uint64(dummy
, propname
, 0));
2724 return (SET_ERROR(EINVAL
));
2727 pair
= nvlist_next_nvpair(dummy
, NULL
);
2728 err
= zfs_prop_set_special(zc
->zc_name
, source
, pair
);
2731 return (err
); /* special property already handled */
2734 * Only check this in the non-received case. We want to allow
2735 * 'inherit -S' to revert non-inheritable properties like quota
2736 * and reservation to the received or default values even though
2737 * they are not considered inheritable.
2739 if (prop
!= ZPROP_INVAL
&& !zfs_prop_inheritable(prop
))
2740 return (SET_ERROR(EINVAL
));
2743 /* property name has been validated by zfs_secpolicy_inherit_prop() */
2744 return (dsl_prop_inherit(zc
->zc_name
, zc
->zc_value
, source
));
2748 zfs_ioc_pool_set_props(zfs_cmd_t
*zc
)
2755 if (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2756 zc
->zc_iflags
, &props
))
2760 * If the only property is the configfile, then just do a spa_lookup()
2761 * to handle the faulted case.
2763 pair
= nvlist_next_nvpair(props
, NULL
);
2764 if (pair
!= NULL
&& strcmp(nvpair_name(pair
),
2765 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
)) == 0 &&
2766 nvlist_next_nvpair(props
, pair
) == NULL
) {
2767 mutex_enter(&spa_namespace_lock
);
2768 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
) {
2769 spa_configfile_set(spa
, props
, B_FALSE
);
2770 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
);
2772 mutex_exit(&spa_namespace_lock
);
2779 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2784 error
= spa_prop_set(spa
, props
);
2787 spa_close(spa
, FTAG
);
2793 zfs_ioc_pool_get_props(zfs_cmd_t
*zc
)
2797 nvlist_t
*nvp
= NULL
;
2799 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0) {
2801 * If the pool is faulted, there may be properties we can still
2802 * get (such as altroot and cachefile), so attempt to get them
2805 mutex_enter(&spa_namespace_lock
);
2806 if ((spa
= spa_lookup(zc
->zc_name
)) != NULL
)
2807 error
= spa_prop_get(spa
, &nvp
);
2808 mutex_exit(&spa_namespace_lock
);
2810 error
= spa_prop_get(spa
, &nvp
);
2811 spa_close(spa
, FTAG
);
2814 if (error
== 0 && zc
->zc_nvlist_dst
!= (uintptr_t)NULL
)
2815 error
= put_nvlist(zc
, nvp
);
2817 error
= SET_ERROR(EFAULT
);
2825 * zc_name name of filesystem
2826 * zc_nvlist_src{_size} nvlist of delegated permissions
2827 * zc_perm_action allow/unallow flag
2832 zfs_ioc_set_fsacl(zfs_cmd_t
*zc
)
2835 nvlist_t
*fsaclnv
= NULL
;
2837 if ((error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
2838 zc
->zc_iflags
, &fsaclnv
)) != 0)
2842 * Verify nvlist is constructed correctly
2844 if ((error
= zfs_deleg_verify_nvlist(fsaclnv
)) != 0) {
2845 nvlist_free(fsaclnv
);
2846 return (SET_ERROR(EINVAL
));
2850 * If we don't have PRIV_SYS_MOUNT, then validate
2851 * that user is allowed to hand out each permission in
2855 error
= secpolicy_zfs(CRED());
2857 if (zc
->zc_perm_action
== B_FALSE
) {
2858 error
= dsl_deleg_can_allow(zc
->zc_name
,
2861 error
= dsl_deleg_can_unallow(zc
->zc_name
,
2867 error
= dsl_deleg_set(zc
->zc_name
, fsaclnv
, zc
->zc_perm_action
);
2869 nvlist_free(fsaclnv
);
2875 * zc_name name of filesystem
2878 * zc_nvlist_src{_size} nvlist of delegated permissions
2881 zfs_ioc_get_fsacl(zfs_cmd_t
*zc
)
2886 if ((error
= dsl_deleg_get(zc
->zc_name
, &nvp
)) == 0) {
2887 error
= put_nvlist(zc
, nvp
);
2896 zfs_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
2898 zfs_creat_t
*zct
= arg
;
2900 zfs_create_fs(os
, cr
, zct
->zct_zplprops
, tx
);
2903 #define ZFS_PROP_UNDEFINED ((uint64_t)-1)
2907 * os parent objset pointer (NULL if root fs)
2908 * fuids_ok fuids allowed in this version of the spa?
2909 * sa_ok SAs allowed in this version of the spa?
2910 * createprops list of properties requested by creator
2913 * zplprops values for the zplprops we attach to the master node object
2914 * is_ci true if requested file system will be purely case-insensitive
2916 * Determine the settings for utf8only, normalization and
2917 * casesensitivity. Specific values may have been requested by the
2918 * creator and/or we can inherit values from the parent dataset. If
2919 * the file system is of too early a vintage, a creator can not
2920 * request settings for these properties, even if the requested
2921 * setting is the default value. We don't actually want to create dsl
2922 * properties for these, so remove them from the source nvlist after
2926 zfs_fill_zplprops_impl(objset_t
*os
, uint64_t zplver
,
2927 boolean_t fuids_ok
, boolean_t sa_ok
, nvlist_t
*createprops
,
2928 nvlist_t
*zplprops
, boolean_t
*is_ci
)
2930 uint64_t sense
= ZFS_PROP_UNDEFINED
;
2931 uint64_t norm
= ZFS_PROP_UNDEFINED
;
2932 uint64_t u8
= ZFS_PROP_UNDEFINED
;
2934 ASSERT(zplprops
!= NULL
);
2936 if (os
!= NULL
&& os
->os_phys
->os_type
!= DMU_OST_ZFS
)
2937 return (SET_ERROR(EINVAL
));
2940 * Pull out creator prop choices, if any.
2943 (void) nvlist_lookup_uint64(createprops
,
2944 zfs_prop_to_name(ZFS_PROP_VERSION
), &zplver
);
2945 (void) nvlist_lookup_uint64(createprops
,
2946 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), &norm
);
2947 (void) nvlist_remove_all(createprops
,
2948 zfs_prop_to_name(ZFS_PROP_NORMALIZE
));
2949 (void) nvlist_lookup_uint64(createprops
,
2950 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), &u8
);
2951 (void) nvlist_remove_all(createprops
,
2952 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
));
2953 (void) nvlist_lookup_uint64(createprops
,
2954 zfs_prop_to_name(ZFS_PROP_CASE
), &sense
);
2955 (void) nvlist_remove_all(createprops
,
2956 zfs_prop_to_name(ZFS_PROP_CASE
));
2960 * If the zpl version requested is whacky or the file system
2961 * or pool is version is too "young" to support normalization
2962 * and the creator tried to set a value for one of the props,
2965 if ((zplver
< ZPL_VERSION_INITIAL
|| zplver
> ZPL_VERSION
) ||
2966 (zplver
>= ZPL_VERSION_FUID
&& !fuids_ok
) ||
2967 (zplver
>= ZPL_VERSION_SA
&& !sa_ok
) ||
2968 (zplver
< ZPL_VERSION_NORMALIZATION
&&
2969 (norm
!= ZFS_PROP_UNDEFINED
|| u8
!= ZFS_PROP_UNDEFINED
||
2970 sense
!= ZFS_PROP_UNDEFINED
)))
2971 return (SET_ERROR(ENOTSUP
));
2974 * Put the version in the zplprops
2976 VERIFY(nvlist_add_uint64(zplprops
,
2977 zfs_prop_to_name(ZFS_PROP_VERSION
), zplver
) == 0);
2979 if (norm
== ZFS_PROP_UNDEFINED
)
2980 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &norm
) == 0);
2981 VERIFY(nvlist_add_uint64(zplprops
,
2982 zfs_prop_to_name(ZFS_PROP_NORMALIZE
), norm
) == 0);
2985 * If we're normalizing, names must always be valid UTF-8 strings.
2989 if (u8
== ZFS_PROP_UNDEFINED
)
2990 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &u8
) == 0);
2991 VERIFY(nvlist_add_uint64(zplprops
,
2992 zfs_prop_to_name(ZFS_PROP_UTF8ONLY
), u8
) == 0);
2994 if (sense
== ZFS_PROP_UNDEFINED
)
2995 VERIFY(zfs_get_zplprop(os
, ZFS_PROP_CASE
, &sense
) == 0);
2996 VERIFY(nvlist_add_uint64(zplprops
,
2997 zfs_prop_to_name(ZFS_PROP_CASE
), sense
) == 0);
3000 *is_ci
= (sense
== ZFS_CASE_INSENSITIVE
);
3006 zfs_fill_zplprops(const char *dataset
, nvlist_t
*createprops
,
3007 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3009 boolean_t fuids_ok
, sa_ok
;
3010 uint64_t zplver
= ZPL_VERSION
;
3011 objset_t
*os
= NULL
;
3012 char parentname
[ZFS_MAX_DATASET_NAME_LEN
];
3018 (void) strlcpy(parentname
, dataset
, sizeof (parentname
));
3019 cp
= strrchr(parentname
, '/');
3023 if ((error
= spa_open(dataset
, &spa
, FTAG
)) != 0)
3026 spa_vers
= spa_version(spa
);
3027 spa_close(spa
, FTAG
);
3029 zplver
= zfs_zpl_version_map(spa_vers
);
3030 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3031 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3034 * Open parent object set so we can inherit zplprop values.
3036 if ((error
= dmu_objset_hold(parentname
, FTAG
, &os
)) != 0)
3039 error
= zfs_fill_zplprops_impl(os
, zplver
, fuids_ok
, sa_ok
, createprops
,
3041 dmu_objset_rele(os
, FTAG
);
3046 zfs_fill_zplprops_root(uint64_t spa_vers
, nvlist_t
*createprops
,
3047 nvlist_t
*zplprops
, boolean_t
*is_ci
)
3051 uint64_t zplver
= ZPL_VERSION
;
3054 zplver
= zfs_zpl_version_map(spa_vers
);
3055 fuids_ok
= (zplver
>= ZPL_VERSION_FUID
);
3056 sa_ok
= (zplver
>= ZPL_VERSION_SA
);
3058 error
= zfs_fill_zplprops_impl(NULL
, zplver
, fuids_ok
, sa_ok
,
3059 createprops
, zplprops
, is_ci
);
3065 * "type" -> dmu_objset_type_t (int32)
3066 * (optional) "props" -> { prop -> value }
3069 * outnvl: propname -> error code (int32)
3072 zfs_ioc_create(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3075 zfs_creat_t zct
= { 0 };
3076 nvlist_t
*nvprops
= NULL
;
3077 void (*cbfunc
)(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
);
3079 dmu_objset_type_t type
;
3080 boolean_t is_insensitive
= B_FALSE
;
3082 if (nvlist_lookup_int32(innvl
, "type", &type32
) != 0)
3083 return (SET_ERROR(EINVAL
));
3085 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3089 cbfunc
= zfs_create_cb
;
3093 cbfunc
= zvol_create_cb
;
3100 if (strchr(fsname
, '@') ||
3101 strchr(fsname
, '%'))
3102 return (SET_ERROR(EINVAL
));
3104 zct
.zct_props
= nvprops
;
3107 return (SET_ERROR(EINVAL
));
3109 if (type
== DMU_OST_ZVOL
) {
3110 uint64_t volsize
, volblocksize
;
3112 if (nvprops
== NULL
)
3113 return (SET_ERROR(EINVAL
));
3114 if (nvlist_lookup_uint64(nvprops
,
3115 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) != 0)
3116 return (SET_ERROR(EINVAL
));
3118 if ((error
= nvlist_lookup_uint64(nvprops
,
3119 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
),
3120 &volblocksize
)) != 0 && error
!= ENOENT
)
3121 return (SET_ERROR(EINVAL
));
3124 volblocksize
= zfs_prop_default_numeric(
3125 ZFS_PROP_VOLBLOCKSIZE
);
3127 if ((error
= zvol_check_volblocksize(
3128 volblocksize
)) != 0 ||
3129 (error
= zvol_check_volsize(volsize
,
3130 volblocksize
)) != 0)
3132 } else if (type
== DMU_OST_ZFS
) {
3136 * We have to have normalization and
3137 * case-folding flags correct when we do the
3138 * file system creation, so go figure them out
3141 VERIFY(nvlist_alloc(&zct
.zct_zplprops
,
3142 NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3143 error
= zfs_fill_zplprops(fsname
, nvprops
,
3144 zct
.zct_zplprops
, &is_insensitive
);
3146 nvlist_free(zct
.zct_zplprops
);
3151 error
= dmu_objset_create(fsname
, type
,
3152 is_insensitive
? DS_FLAG_CI_DATASET
: 0, cbfunc
, &zct
);
3153 nvlist_free(zct
.zct_zplprops
);
3156 * It would be nice to do this atomically.
3159 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3162 (void) dsl_destroy_head(fsname
);
3169 * "origin" -> name of origin snapshot
3170 * (optional) "props" -> { prop -> value }
3173 * outnvl: propname -> error code (int32)
3176 zfs_ioc_clone(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3179 nvlist_t
*nvprops
= NULL
;
3182 if (nvlist_lookup_string(innvl
, "origin", &origin_name
) != 0)
3183 return (SET_ERROR(EINVAL
));
3184 (void) nvlist_lookup_nvlist(innvl
, "props", &nvprops
);
3186 if (strchr(fsname
, '@') ||
3187 strchr(fsname
, '%'))
3188 return (SET_ERROR(EINVAL
));
3190 if (dataset_namecheck(origin_name
, NULL
, NULL
) != 0)
3191 return (SET_ERROR(EINVAL
));
3192 error
= dmu_objset_clone(fsname
, origin_name
);
3197 * It would be nice to do this atomically.
3200 error
= zfs_set_prop_nvlist(fsname
, ZPROP_SRC_LOCAL
,
3203 (void) dsl_destroy_head(fsname
);
3210 zfs_ioc_remap(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3212 if (strchr(fsname
, '@') ||
3213 strchr(fsname
, '%'))
3214 return (SET_ERROR(EINVAL
));
3216 return (dmu_objset_remap_indirects(fsname
));
3221 * "snaps" -> { snapshot1, snapshot2 }
3222 * (optional) "props" -> { prop -> value (string) }
3225 * outnvl: snapshot -> error code (int32)
3228 zfs_ioc_snapshot(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3231 nvlist_t
*props
= NULL
;
3235 (void) nvlist_lookup_nvlist(innvl
, "props", &props
);
3236 if ((error
= zfs_check_userprops(poolname
, props
)) != 0)
3239 if (!nvlist_empty(props
) &&
3240 zfs_earlier_version(poolname
, SPA_VERSION_SNAP_PROPS
))
3241 return (SET_ERROR(ENOTSUP
));
3243 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3244 return (SET_ERROR(EINVAL
));
3245 poollen
= strlen(poolname
);
3246 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3247 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3248 const char *name
= nvpair_name(pair
);
3249 const char *cp
= strchr(name
, '@');
3252 * The snap name must contain an @, and the part after it must
3253 * contain only valid characters.
3256 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3257 return (SET_ERROR(EINVAL
));
3260 * The snap must be in the specified pool.
3262 if (strncmp(name
, poolname
, poollen
) != 0 ||
3263 (name
[poollen
] != '/' && name
[poollen
] != '@'))
3264 return (SET_ERROR(EXDEV
));
3266 /* This must be the only snap of this fs. */
3267 for (nvpair_t
*pair2
= nvlist_next_nvpair(snaps
, pair
);
3268 pair2
!= NULL
; pair2
= nvlist_next_nvpair(snaps
, pair2
)) {
3269 if (strncmp(name
, nvpair_name(pair2
), cp
- name
+ 1)
3271 return (SET_ERROR(EXDEV
));
3276 error
= dsl_dataset_snapshot(snaps
, props
, outnvl
);
3281 * innvl: "message" -> string
3285 zfs_ioc_log_history(const char *unused
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3293 * The poolname in the ioctl is not set, we get it from the TSD,
3294 * which was set at the end of the last successful ioctl that allows
3295 * logging. The secpolicy func already checked that it is set.
3296 * Only one log ioctl is allowed after each successful ioctl, so
3297 * we clear the TSD here.
3299 poolname
= tsd_get(zfs_allow_log_key
);
3300 (void) tsd_set(zfs_allow_log_key
, NULL
);
3301 error
= spa_open(poolname
, &spa
, FTAG
);
3306 if (nvlist_lookup_string(innvl
, "message", &message
) != 0) {
3307 spa_close(spa
, FTAG
);
3308 return (SET_ERROR(EINVAL
));
3311 if (spa_version(spa
) < SPA_VERSION_ZPOOL_HISTORY
) {
3312 spa_close(spa
, FTAG
);
3313 return (SET_ERROR(ENOTSUP
));
3316 error
= spa_history_log(spa
, message
);
3317 spa_close(spa
, FTAG
);
3322 * The dp_config_rwlock must not be held when calling this, because the
3323 * unmount may need to write out data.
3325 * This function is best-effort. Callers must deal gracefully if it
3326 * remains mounted (or is remounted after this call).
3328 * Returns 0 if the argument is not a snapshot, or it is not currently a
3329 * filesystem, or we were able to unmount it. Returns error code otherwise.
3332 zfs_unmount_snap(const char *snapname
)
3335 zfsvfs_t
*zfsvfs
= NULL
;
3337 if (strchr(snapname
, '@') == NULL
)
3340 int err
= getzfsvfs(snapname
, &zfsvfs
);
3342 ASSERT3P(zfsvfs
, ==, NULL
);
3345 vfsp
= zfsvfs
->z_vfs
;
3347 ASSERT(!dsl_pool_config_held(dmu_objset_pool(zfsvfs
->z_os
)));
3349 err
= vn_vfswlock(vfsp
->vfs_vnodecovered
);
3355 * Always force the unmount for snapshots.
3357 (void) dounmount(vfsp
, MS_FORCE
, kcred
);
3362 zfs_unmount_snap_cb(const char *snapname
, void *arg
)
3364 zfs_unmount_snap(snapname
);
3369 * When a clone is destroyed, its origin may also need to be destroyed,
3370 * in which case it must be unmounted. This routine will do that unmount
3374 zfs_destroy_unmount_origin(const char *fsname
)
3380 error
= dmu_objset_hold(fsname
, FTAG
, &os
);
3383 ds
= dmu_objset_ds(os
);
3384 if (dsl_dir_is_clone(ds
->ds_dir
) && DS_IS_DEFER_DESTROY(ds
->ds_prev
)) {
3385 char originname
[ZFS_MAX_DATASET_NAME_LEN
];
3386 dsl_dataset_name(ds
->ds_prev
, originname
);
3387 dmu_objset_rele(os
, FTAG
);
3388 zfs_unmount_snap(originname
);
3390 dmu_objset_rele(os
, FTAG
);
3396 * "snaps" -> { snapshot1, snapshot2 }
3397 * (optional boolean) "defer"
3400 * outnvl: snapshot -> error code (int32)
3405 zfs_ioc_destroy_snaps(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3411 if (nvlist_lookup_nvlist(innvl
, "snaps", &snaps
) != 0)
3412 return (SET_ERROR(EINVAL
));
3413 defer
= nvlist_exists(innvl
, "defer");
3415 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
3416 pair
= nvlist_next_nvpair(snaps
, pair
)) {
3417 zfs_unmount_snap(nvpair_name(pair
));
3420 return (dsl_destroy_snapshots_nvl(snaps
, defer
, outnvl
));
3424 * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
3425 * All bookmarks must be in the same pool.
3428 * bookmark1 -> snapshot1, bookmark2 -> snapshot2
3431 * outnvl: bookmark -> error code (int32)
3436 zfs_ioc_bookmark(const char *poolname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3438 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3439 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3443 * Verify the snapshot argument.
3445 if (nvpair_value_string(pair
, &snap_name
) != 0)
3446 return (SET_ERROR(EINVAL
));
3449 /* Verify that the keys (bookmarks) are unique */
3450 for (nvpair_t
*pair2
= nvlist_next_nvpair(innvl
, pair
);
3451 pair2
!= NULL
; pair2
= nvlist_next_nvpair(innvl
, pair2
)) {
3452 if (strcmp(nvpair_name(pair
), nvpair_name(pair2
)) == 0)
3453 return (SET_ERROR(EINVAL
));
3457 return (dsl_bookmark_create(innvl
, outnvl
));
3462 * property 1, property 2, ...
3466 * bookmark name 1 -> { property 1, property 2, ... },
3467 * bookmark name 2 -> { property 1, property 2, ... }
3472 zfs_ioc_get_bookmarks(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3474 return (dsl_get_bookmarks(fsname
, innvl
, outnvl
));
3479 * bookmark name 1, bookmark name 2
3482 * outnvl: bookmark -> error code (int32)
3486 zfs_ioc_destroy_bookmarks(const char *poolname
, nvlist_t
*innvl
,
3491 poollen
= strlen(poolname
);
3492 for (nvpair_t
*pair
= nvlist_next_nvpair(innvl
, NULL
);
3493 pair
!= NULL
; pair
= nvlist_next_nvpair(innvl
, pair
)) {
3494 const char *name
= nvpair_name(pair
);
3495 const char *cp
= strchr(name
, '#');
3498 * The bookmark name must contain an #, and the part after it
3499 * must contain only valid characters.
3502 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3503 return (SET_ERROR(EINVAL
));
3506 * The bookmark must be in the specified pool.
3508 if (strncmp(name
, poolname
, poollen
) != 0 ||
3509 (name
[poollen
] != '/' && name
[poollen
] != '#'))
3510 return (SET_ERROR(EXDEV
));
3513 error
= dsl_bookmark_destroy(innvl
, outnvl
);
3518 zfs_ioc_channel_program(const char *poolname
, nvlist_t
*innvl
,
3522 uint64_t instrlimit
, memlimit
;
3523 boolean_t sync_flag
;
3524 nvpair_t
*nvarg
= NULL
;
3526 if (0 != nvlist_lookup_string(innvl
, ZCP_ARG_PROGRAM
, &program
)) {
3529 if (0 != nvlist_lookup_boolean_value(innvl
, ZCP_ARG_SYNC
, &sync_flag
)) {
3532 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_INSTRLIMIT
, &instrlimit
)) {
3533 instrlimit
= ZCP_DEFAULT_INSTRLIMIT
;
3535 if (0 != nvlist_lookup_uint64(innvl
, ZCP_ARG_MEMLIMIT
, &memlimit
)) {
3536 memlimit
= ZCP_DEFAULT_MEMLIMIT
;
3538 if (0 != nvlist_lookup_nvpair(innvl
, ZCP_ARG_ARGLIST
, &nvarg
)) {
3542 if (instrlimit
== 0 || instrlimit
> zfs_lua_max_instrlimit
)
3544 if (memlimit
== 0 || memlimit
> zfs_lua_max_memlimit
)
3547 return (zcp_eval(poolname
, program
, sync_flag
, instrlimit
, memlimit
,
3553 * zc_name name of dataset to destroy
3554 * zc_objset_type type of objset
3555 * zc_defer_destroy mark for deferred destroy
3560 zfs_ioc_destroy(zfs_cmd_t
*zc
)
3564 if (zc
->zc_objset_type
== DMU_OST_ZFS
)
3565 zfs_unmount_snap(zc
->zc_name
);
3567 if (strchr(zc
->zc_name
, '@'))
3568 err
= dsl_destroy_snapshot(zc
->zc_name
, zc
->zc_defer_destroy
);
3570 err
= dsl_destroy_head(zc
->zc_name
);
3571 if (zc
->zc_objset_type
== DMU_OST_ZVOL
&& err
== 0)
3572 (void) zvol_remove_minor(zc
->zc_name
);
3577 * fsname is name of dataset to rollback (to most recent snapshot)
3579 * innvl may contain name of expected target snapshot
3581 * outnvl: "target" -> name of most recent snapshot
3586 zfs_ioc_rollback(const char *fsname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
3589 char *target
= NULL
;
3592 (void) nvlist_lookup_string(innvl
, "target", &target
);
3593 if (target
!= NULL
) {
3594 const char *cp
= strchr(target
, '@');
3597 * The snap name must contain an @, and the part after it must
3598 * contain only valid characters.
3601 zfs_component_namecheck(cp
+ 1, NULL
, NULL
) != 0)
3602 return (SET_ERROR(EINVAL
));
3605 if (getzfsvfs(fsname
, &zfsvfs
) == 0) {
3608 ds
= dmu_objset_ds(zfsvfs
->z_os
);
3609 error
= zfs_suspend_fs(zfsvfs
);
3613 error
= dsl_dataset_rollback(fsname
, target
, zfsvfs
,
3615 resume_err
= zfs_resume_fs(zfsvfs
, ds
);
3616 error
= error
? error
: resume_err
;
3618 VFS_RELE(zfsvfs
->z_vfs
);
3620 error
= dsl_dataset_rollback(fsname
, target
, NULL
, outnvl
);
3626 recursive_unmount(const char *fsname
, void *arg
)
3628 const char *snapname
= arg
;
3629 char fullname
[ZFS_MAX_DATASET_NAME_LEN
];
3631 (void) snprintf(fullname
, sizeof (fullname
), "%s@%s", fsname
, snapname
);
3632 zfs_unmount_snap(fullname
);
3639 * zc_name old name of dataset
3640 * zc_value new name of dataset
3641 * zc_cookie recursive flag (only valid for snapshots)
3646 zfs_ioc_rename(zfs_cmd_t
*zc
)
3648 boolean_t recursive
= zc
->zc_cookie
& 1;
3651 /* "zfs rename" from and to ...%recv datasets should both fail */
3652 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
3653 zc
->zc_value
[sizeof (zc
->zc_value
) - 1] = '\0';
3654 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
3655 dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
3656 strchr(zc
->zc_name
, '%') || strchr(zc
->zc_value
, '%'))
3657 return (SET_ERROR(EINVAL
));
3659 at
= strchr(zc
->zc_name
, '@');
3661 /* snaps must be in same fs */
3664 if (strncmp(zc
->zc_name
, zc
->zc_value
, at
- zc
->zc_name
+ 1))
3665 return (SET_ERROR(EXDEV
));
3667 if (zc
->zc_objset_type
== DMU_OST_ZFS
) {
3668 error
= dmu_objset_find(zc
->zc_name
,
3669 recursive_unmount
, at
+ 1,
3670 recursive
? DS_FIND_CHILDREN
: 0);
3676 error
= dsl_dataset_rename_snapshot(zc
->zc_name
,
3677 at
+ 1, strchr(zc
->zc_value
, '@') + 1, recursive
);
3682 if (zc
->zc_objset_type
== DMU_OST_ZVOL
)
3683 (void) zvol_remove_minor(zc
->zc_name
);
3684 return (dsl_dir_rename(zc
->zc_name
, zc
->zc_value
));
3689 zfs_check_settable(const char *dsname
, nvpair_t
*pair
, cred_t
*cr
)
3691 const char *propname
= nvpair_name(pair
);
3692 boolean_t issnap
= (strchr(dsname
, '@') != NULL
);
3693 zfs_prop_t prop
= zfs_name_to_prop(propname
);
3697 if (prop
== ZPROP_INVAL
) {
3698 if (zfs_prop_user(propname
)) {
3699 if (err
= zfs_secpolicy_write_perms(dsname
,
3700 ZFS_DELEG_PERM_USERPROP
, cr
))
3705 if (!issnap
&& zfs_prop_userquota(propname
)) {
3706 const char *perm
= NULL
;
3707 const char *uq_prefix
=
3708 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
];
3709 const char *gq_prefix
=
3710 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
];
3712 if (strncmp(propname
, uq_prefix
,
3713 strlen(uq_prefix
)) == 0) {
3714 perm
= ZFS_DELEG_PERM_USERQUOTA
;
3715 } else if (strncmp(propname
, gq_prefix
,
3716 strlen(gq_prefix
)) == 0) {
3717 perm
= ZFS_DELEG_PERM_GROUPQUOTA
;
3719 /* USERUSED and GROUPUSED are read-only */
3720 return (SET_ERROR(EINVAL
));
3723 if (err
= zfs_secpolicy_write_perms(dsname
, perm
, cr
))
3728 return (SET_ERROR(EINVAL
));
3732 return (SET_ERROR(EINVAL
));
3734 if (nvpair_type(pair
) == DATA_TYPE_NVLIST
) {
3736 * dsl_prop_get_all_impl() returns properties in this
3740 VERIFY(nvpair_value_nvlist(pair
, &attrs
) == 0);
3741 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3746 * Check that this value is valid for this pool version
3749 case ZFS_PROP_COMPRESSION
:
3751 * If the user specified gzip compression, make sure
3752 * the SPA supports it. We ignore any errors here since
3753 * we'll catch them later.
3755 if (nvpair_value_uint64(pair
, &intval
) == 0) {
3756 if (intval
>= ZIO_COMPRESS_GZIP_1
&&
3757 intval
<= ZIO_COMPRESS_GZIP_9
&&
3758 zfs_earlier_version(dsname
,
3759 SPA_VERSION_GZIP_COMPRESSION
)) {
3760 return (SET_ERROR(ENOTSUP
));
3763 if (intval
== ZIO_COMPRESS_ZLE
&&
3764 zfs_earlier_version(dsname
,
3765 SPA_VERSION_ZLE_COMPRESSION
))
3766 return (SET_ERROR(ENOTSUP
));
3768 if (intval
== ZIO_COMPRESS_LZ4
) {
3771 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3774 if (!spa_feature_is_enabled(spa
,
3775 SPA_FEATURE_LZ4_COMPRESS
)) {
3776 spa_close(spa
, FTAG
);
3777 return (SET_ERROR(ENOTSUP
));
3779 spa_close(spa
, FTAG
);
3783 * If this is a bootable dataset then
3784 * verify that the compression algorithm
3785 * is supported for booting. We must return
3786 * something other than ENOTSUP since it
3787 * implies a downrev pool version.
3789 if (zfs_is_bootfs(dsname
) &&
3790 !BOOTFS_COMPRESS_VALID(intval
)) {
3791 return (SET_ERROR(ERANGE
));
3796 case ZFS_PROP_COPIES
:
3797 if (zfs_earlier_version(dsname
, SPA_VERSION_DITTO_BLOCKS
))
3798 return (SET_ERROR(ENOTSUP
));
3801 case ZFS_PROP_RECORDSIZE
:
3802 /* Record sizes above 128k need the feature to be enabled */
3803 if (nvpair_value_uint64(pair
, &intval
) == 0 &&
3804 intval
> SPA_OLD_MAXBLOCKSIZE
) {
3808 * We don't allow setting the property above 1MB,
3809 * unless the tunable has been changed.
3811 if (intval
> zfs_max_recordsize
||
3812 intval
> SPA_MAXBLOCKSIZE
)
3813 return (SET_ERROR(ERANGE
));
3815 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3818 if (!spa_feature_is_enabled(spa
,
3819 SPA_FEATURE_LARGE_BLOCKS
)) {
3820 spa_close(spa
, FTAG
);
3821 return (SET_ERROR(ENOTSUP
));
3823 spa_close(spa
, FTAG
);
3827 case ZFS_PROP_SHARESMB
:
3828 if (zpl_earlier_version(dsname
, ZPL_VERSION_FUID
))
3829 return (SET_ERROR(ENOTSUP
));
3832 case ZFS_PROP_ACLINHERIT
:
3833 if (nvpair_type(pair
) == DATA_TYPE_UINT64
&&
3834 nvpair_value_uint64(pair
, &intval
) == 0) {
3835 if (intval
== ZFS_ACL_PASSTHROUGH_X
&&
3836 zfs_earlier_version(dsname
,
3837 SPA_VERSION_PASSTHROUGH_X
))
3838 return (SET_ERROR(ENOTSUP
));
3842 case ZFS_PROP_CHECKSUM
:
3843 case ZFS_PROP_DEDUP
:
3845 spa_feature_t feature
;
3848 /* dedup feature version checks */
3849 if (prop
== ZFS_PROP_DEDUP
&&
3850 zfs_earlier_version(dsname
, SPA_VERSION_DEDUP
))
3851 return (SET_ERROR(ENOTSUP
));
3853 if (nvpair_value_uint64(pair
, &intval
) != 0)
3854 return (SET_ERROR(EINVAL
));
3856 /* check prop value is enabled in features */
3857 feature
= zio_checksum_to_feature(intval
& ZIO_CHECKSUM_MASK
);
3858 if (feature
== SPA_FEATURE_NONE
)
3861 if ((err
= spa_open(dsname
, &spa
, FTAG
)) != 0)
3864 if (!spa_feature_is_enabled(spa
, feature
)) {
3865 spa_close(spa
, FTAG
);
3866 return (SET_ERROR(ENOTSUP
));
3868 spa_close(spa
, FTAG
);
3873 return (zfs_secpolicy_setprop(dsname
, prop
, pair
, CRED()));
3877 * Checks for a race condition to make sure we don't increment a feature flag
3881 zfs_prop_activate_feature_check(void *arg
, dmu_tx_t
*tx
)
3883 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3884 spa_feature_t
*featurep
= arg
;
3886 if (!spa_feature_is_active(spa
, *featurep
))
3889 return (SET_ERROR(EBUSY
));
3893 * The callback invoked on feature activation in the sync task caused by
3894 * zfs_prop_activate_feature.
3897 zfs_prop_activate_feature_sync(void *arg
, dmu_tx_t
*tx
)
3899 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
3900 spa_feature_t
*featurep
= arg
;
3902 spa_feature_incr(spa
, *featurep
, tx
);
3906 * Activates a feature on a pool in response to a property setting. This
3907 * creates a new sync task which modifies the pool to reflect the feature
3911 zfs_prop_activate_feature(spa_t
*spa
, spa_feature_t feature
)
3915 /* EBUSY here indicates that the feature is already active */
3916 err
= dsl_sync_task(spa_name(spa
),
3917 zfs_prop_activate_feature_check
, zfs_prop_activate_feature_sync
,
3918 &feature
, 2, ZFS_SPACE_CHECK_RESERVED
);
3920 if (err
!= 0 && err
!= EBUSY
)
3927 * Removes properties from the given props list that fail permission checks
3928 * needed to clear them and to restore them in case of a receive error. For each
3929 * property, make sure we have both set and inherit permissions.
3931 * Returns the first error encountered if any permission checks fail. If the
3932 * caller provides a non-NULL errlist, it also gives the complete list of names
3933 * of all the properties that failed a permission check along with the
3934 * corresponding error numbers. The caller is responsible for freeing the
3937 * If every property checks out successfully, zero is returned and the list
3938 * pointed at by errlist is NULL.
3941 zfs_check_clearable(char *dataset
, nvlist_t
*props
, nvlist_t
**errlist
)
3944 nvpair_t
*pair
, *next_pair
;
3951 VERIFY(nvlist_alloc(&errors
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
3953 zc
= kmem_alloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
3954 (void) strcpy(zc
->zc_name
, dataset
);
3955 pair
= nvlist_next_nvpair(props
, NULL
);
3956 while (pair
!= NULL
) {
3957 next_pair
= nvlist_next_nvpair(props
, pair
);
3959 (void) strcpy(zc
->zc_value
, nvpair_name(pair
));
3960 if ((err
= zfs_check_settable(dataset
, pair
, CRED())) != 0 ||
3961 (err
= zfs_secpolicy_inherit_prop(zc
, NULL
, CRED())) != 0) {
3962 VERIFY(nvlist_remove_nvpair(props
, pair
) == 0);
3963 VERIFY(nvlist_add_int32(errors
,
3964 zc
->zc_value
, err
) == 0);
3968 kmem_free(zc
, sizeof (zfs_cmd_t
));
3970 if ((pair
= nvlist_next_nvpair(errors
, NULL
)) == NULL
) {
3971 nvlist_free(errors
);
3974 VERIFY(nvpair_value_int32(pair
, &rv
) == 0);
3977 if (errlist
== NULL
)
3978 nvlist_free(errors
);
3986 propval_equals(nvpair_t
*p1
, nvpair_t
*p2
)
3988 if (nvpair_type(p1
) == DATA_TYPE_NVLIST
) {
3989 /* dsl_prop_get_all_impl() format */
3991 VERIFY(nvpair_value_nvlist(p1
, &attrs
) == 0);
3992 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
3996 if (nvpair_type(p2
) == DATA_TYPE_NVLIST
) {
3998 VERIFY(nvpair_value_nvlist(p2
, &attrs
) == 0);
3999 VERIFY(nvlist_lookup_nvpair(attrs
, ZPROP_VALUE
,
4003 if (nvpair_type(p1
) != nvpair_type(p2
))
4006 if (nvpair_type(p1
) == DATA_TYPE_STRING
) {
4007 char *valstr1
, *valstr2
;
4009 VERIFY(nvpair_value_string(p1
, (char **)&valstr1
) == 0);
4010 VERIFY(nvpair_value_string(p2
, (char **)&valstr2
) == 0);
4011 return (strcmp(valstr1
, valstr2
) == 0);
4013 uint64_t intval1
, intval2
;
4015 VERIFY(nvpair_value_uint64(p1
, &intval1
) == 0);
4016 VERIFY(nvpair_value_uint64(p2
, &intval2
) == 0);
4017 return (intval1
== intval2
);
4022 * Remove properties from props if they are not going to change (as determined
4023 * by comparison with origprops). Remove them from origprops as well, since we
4024 * do not need to clear or restore properties that won't change.
4027 props_reduce(nvlist_t
*props
, nvlist_t
*origprops
)
4029 nvpair_t
*pair
, *next_pair
;
4031 if (origprops
== NULL
)
4032 return; /* all props need to be received */
4034 pair
= nvlist_next_nvpair(props
, NULL
);
4035 while (pair
!= NULL
) {
4036 const char *propname
= nvpair_name(pair
);
4039 next_pair
= nvlist_next_nvpair(props
, pair
);
4041 if ((nvlist_lookup_nvpair(origprops
, propname
,
4042 &match
) != 0) || !propval_equals(pair
, match
))
4043 goto next
; /* need to set received value */
4045 /* don't clear the existing received value */
4046 (void) nvlist_remove_nvpair(origprops
, match
);
4047 /* don't bother receiving the property */
4048 (void) nvlist_remove_nvpair(props
, pair
);
4055 * Extract properties that cannot be set PRIOR to the receipt of a dataset.
4056 * For example, refquota cannot be set until after the receipt of a dataset,
4057 * because in replication streams, an older/earlier snapshot may exceed the
4058 * refquota. We want to receive the older/earlier snapshot, but setting
4059 * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
4060 * the older/earlier snapshot from being received (with EDQUOT).
4062 * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
4064 * libzfs will need to be judicious handling errors encountered by props
4065 * extracted by this function.
4068 extract_delay_props(nvlist_t
*props
)
4070 nvlist_t
*delayprops
;
4071 nvpair_t
*nvp
, *tmp
;
4072 static const zfs_prop_t delayable
[] = { ZFS_PROP_REFQUOTA
, 0 };
4075 VERIFY(nvlist_alloc(&delayprops
, NV_UNIQUE_NAME
, KM_SLEEP
) == 0);
4077 for (nvp
= nvlist_next_nvpair(props
, NULL
); nvp
!= NULL
;
4078 nvp
= nvlist_next_nvpair(props
, nvp
)) {
4080 * strcmp() is safe because zfs_prop_to_name() always returns
4083 for (i
= 0; delayable
[i
] != 0; i
++) {
4084 if (strcmp(zfs_prop_to_name(delayable
[i
]),
4085 nvpair_name(nvp
)) == 0) {
4089 if (delayable
[i
] != 0) {
4090 tmp
= nvlist_prev_nvpair(props
, nvp
);
4091 VERIFY(nvlist_add_nvpair(delayprops
, nvp
) == 0);
4092 VERIFY(nvlist_remove_nvpair(props
, nvp
) == 0);
4097 if (nvlist_empty(delayprops
)) {
4098 nvlist_free(delayprops
);
4101 return (delayprops
);
4105 static boolean_t zfs_ioc_recv_inject_err
;
4110 * zc_name name of containing filesystem
4111 * zc_nvlist_src{_size} nvlist of properties to apply
4112 * zc_value name of snapshot to create
4113 * zc_string name of clone origin (if DRR_FLAG_CLONE)
4114 * zc_cookie file descriptor to recv from
4115 * zc_begin_record the BEGIN record of the stream (not byteswapped)
4116 * zc_guid force flag
4117 * zc_cleanup_fd cleanup-on-exit file descriptor
4118 * zc_action_handle handle for this guid/ds mapping (or zero on first call)
4119 * zc_resumable if data is incomplete assume sender will resume
4122 * zc_cookie number of bytes read
4123 * zc_nvlist_dst{_size} error for each unapplied received property
4124 * zc_obj zprop_errflags_t
4125 * zc_action_handle handle for this guid/ds mapping
4128 zfs_ioc_recv(zfs_cmd_t
*zc
)
4131 dmu_recv_cookie_t drc
;
4132 boolean_t force
= (boolean_t
)zc
->zc_guid
;
4135 int props_error
= 0;
4138 nvlist_t
*props
= NULL
; /* sent properties */
4139 nvlist_t
*origprops
= NULL
; /* existing properties */
4140 nvlist_t
*delayprops
= NULL
; /* sent properties applied post-receive */
4141 char *origin
= NULL
;
4143 char tofs
[ZFS_MAX_DATASET_NAME_LEN
];
4144 boolean_t first_recvd_props
= B_FALSE
;
4146 if (dataset_namecheck(zc
->zc_value
, NULL
, NULL
) != 0 ||
4147 strchr(zc
->zc_value
, '@') == NULL
||
4148 strchr(zc
->zc_value
, '%'))
4149 return (SET_ERROR(EINVAL
));
4151 (void) strcpy(tofs
, zc
->zc_value
);
4152 tosnap
= strchr(tofs
, '@');
4155 if (zc
->zc_nvlist_src
!= (uintptr_t)NULL
&&
4156 (error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
4157 zc
->zc_iflags
, &props
)) != 0)
4164 return (SET_ERROR(EBADF
));
4167 errors
= fnvlist_alloc();
4169 if (zc
->zc_string
[0])
4170 origin
= zc
->zc_string
;
4172 error
= dmu_recv_begin(tofs
, tosnap
,
4173 &zc
->zc_begin_record
, force
, zc
->zc_resumable
, origin
, &drc
);
4178 * Set properties before we receive the stream so that they are applied
4179 * to the new data. Note that we must call dmu_recv_stream() if
4180 * dmu_recv_begin() succeeds.
4182 if (props
!= NULL
&& !drc
.drc_newfs
) {
4183 if (spa_version(dsl_dataset_get_spa(drc
.drc_ds
)) >=
4184 SPA_VERSION_RECVD_PROPS
&&
4185 !dsl_prop_get_hasrecvd(tofs
))
4186 first_recvd_props
= B_TRUE
;
4189 * If new received properties are supplied, they are to
4190 * completely replace the existing received properties, so stash
4191 * away the existing ones.
4193 if (dsl_prop_get_received(tofs
, &origprops
) == 0) {
4194 nvlist_t
*errlist
= NULL
;
4196 * Don't bother writing a property if its value won't
4197 * change (and avoid the unnecessary security checks).
4199 * The first receive after SPA_VERSION_RECVD_PROPS is a
4200 * special case where we blow away all local properties
4203 if (!first_recvd_props
)
4204 props_reduce(props
, origprops
);
4205 if (zfs_check_clearable(tofs
, origprops
, &errlist
) != 0)
4206 (void) nvlist_merge(errors
, errlist
, 0);
4207 nvlist_free(errlist
);
4209 if (clear_received_props(tofs
, origprops
,
4210 first_recvd_props
? NULL
: props
) != 0)
4211 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4213 zc
->zc_obj
|= ZPROP_ERR_NOCLEAR
;
4217 if (props
!= NULL
) {
4218 props_error
= dsl_prop_set_hasrecvd(tofs
);
4220 if (props_error
== 0) {
4221 delayprops
= extract_delay_props(props
);
4222 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4228 error
= dmu_recv_stream(&drc
, fp
->f_vnode
, &off
, zc
->zc_cleanup_fd
,
4229 &zc
->zc_action_handle
);
4232 zfsvfs_t
*zfsvfs
= NULL
;
4234 if (getzfsvfs(tofs
, &zfsvfs
) == 0) {
4239 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4240 error
= zfs_suspend_fs(zfsvfs
);
4242 * If the suspend fails, then the recv_end will
4243 * likely also fail, and clean up after itself.
4245 end_err
= dmu_recv_end(&drc
, zfsvfs
);
4247 error
= zfs_resume_fs(zfsvfs
, ds
);
4248 error
= error
? error
: end_err
;
4249 VFS_RELE(zfsvfs
->z_vfs
);
4251 error
= dmu_recv_end(&drc
, NULL
);
4254 /* Set delayed properties now, after we're done receiving. */
4255 if (delayprops
!= NULL
&& error
== 0) {
4256 (void) zfs_set_prop_nvlist(tofs
, ZPROP_SRC_RECEIVED
,
4257 delayprops
, errors
);
4261 if (delayprops
!= NULL
) {
4263 * Merge delayed props back in with initial props, in case
4264 * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
4265 * we have to make sure clear_received_props() includes
4266 * the delayed properties).
4268 * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
4269 * using ASSERT() will be just like a VERIFY.
4271 ASSERT(nvlist_merge(props
, delayprops
, 0) == 0);
4272 nvlist_free(delayprops
);
4276 * Now that all props, initial and delayed, are set, report the prop
4277 * errors to the caller.
4279 if (zc
->zc_nvlist_dst_size
!= 0 &&
4280 (nvlist_smush(errors
, zc
->zc_nvlist_dst_size
) != 0 ||
4281 put_nvlist(zc
, errors
) != 0)) {
4283 * Caller made zc->zc_nvlist_dst less than the minimum expected
4284 * size or supplied an invalid address.
4286 props_error
= SET_ERROR(EINVAL
);
4289 zc
->zc_cookie
= off
- fp
->f_offset
;
4290 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4294 if (zfs_ioc_recv_inject_err
) {
4295 zfs_ioc_recv_inject_err
= B_FALSE
;
4300 * On error, restore the original props.
4302 if (error
!= 0 && props
!= NULL
&& !drc
.drc_newfs
) {
4303 if (clear_received_props(tofs
, props
, NULL
) != 0) {
4305 * We failed to clear the received properties.
4306 * Since we may have left a $recvd value on the
4307 * system, we can't clear the $hasrecvd flag.
4309 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4310 } else if (first_recvd_props
) {
4311 dsl_prop_unset_hasrecvd(tofs
);
4314 if (origprops
== NULL
&& !drc
.drc_newfs
) {
4315 /* We failed to stash the original properties. */
4316 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4320 * dsl_props_set() will not convert RECEIVED to LOCAL on or
4321 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
4322 * explictly if we're restoring local properties cleared in the
4323 * first new-style receive.
4325 if (origprops
!= NULL
&&
4326 zfs_set_prop_nvlist(tofs
, (first_recvd_props
?
4327 ZPROP_SRC_LOCAL
: ZPROP_SRC_RECEIVED
),
4328 origprops
, NULL
) != 0) {
4330 * We stashed the original properties but failed to
4333 zc
->zc_obj
|= ZPROP_ERR_NORESTORE
;
4338 nvlist_free(origprops
);
4339 nvlist_free(errors
);
4343 error
= props_error
;
4350 * zc_name name of snapshot to send
4351 * zc_cookie file descriptor to send stream to
4352 * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
4353 * zc_sendobj objsetid of snapshot to send
4354 * zc_fromobj objsetid of incremental fromsnap (may be zero)
4355 * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
4356 * output size in zc_objset_type.
4357 * zc_flags lzc_send_flags
4360 * zc_objset_type estimated size, if zc_guid is set
4363 zfs_ioc_send(zfs_cmd_t
*zc
)
4367 boolean_t estimate
= (zc
->zc_guid
!= 0);
4368 boolean_t embedok
= (zc
->zc_flags
& 0x1);
4369 boolean_t large_block_ok
= (zc
->zc_flags
& 0x2);
4370 boolean_t compressok
= (zc
->zc_flags
& 0x4);
4372 if (zc
->zc_obj
!= 0) {
4374 dsl_dataset_t
*tosnap
;
4376 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4380 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4382 dsl_pool_rele(dp
, FTAG
);
4386 if (dsl_dir_is_clone(tosnap
->ds_dir
))
4388 dsl_dir_phys(tosnap
->ds_dir
)->dd_origin_obj
;
4389 dsl_dataset_rele(tosnap
, FTAG
);
4390 dsl_pool_rele(dp
, FTAG
);
4395 dsl_dataset_t
*tosnap
;
4396 dsl_dataset_t
*fromsnap
= NULL
;
4398 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4402 error
= dsl_dataset_hold_obj(dp
, zc
->zc_sendobj
, FTAG
, &tosnap
);
4404 dsl_pool_rele(dp
, FTAG
);
4408 if (zc
->zc_fromobj
!= 0) {
4409 error
= dsl_dataset_hold_obj(dp
, zc
->zc_fromobj
,
4412 dsl_dataset_rele(tosnap
, FTAG
);
4413 dsl_pool_rele(dp
, FTAG
);
4418 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
4419 &zc
->zc_objset_type
);
4421 if (fromsnap
!= NULL
)
4422 dsl_dataset_rele(fromsnap
, FTAG
);
4423 dsl_dataset_rele(tosnap
, FTAG
);
4424 dsl_pool_rele(dp
, FTAG
);
4426 file_t
*fp
= getf(zc
->zc_cookie
);
4428 return (SET_ERROR(EBADF
));
4431 error
= dmu_send_obj(zc
->zc_name
, zc
->zc_sendobj
,
4432 zc
->zc_fromobj
, embedok
, large_block_ok
, compressok
,
4433 zc
->zc_cookie
, fp
->f_vnode
, &off
);
4435 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
4437 releasef(zc
->zc_cookie
);
4444 * zc_name name of snapshot on which to report progress
4445 * zc_cookie file descriptor of send stream
4448 * zc_cookie number of bytes written in send stream thus far
4451 zfs_ioc_send_progress(zfs_cmd_t
*zc
)
4455 dmu_sendarg_t
*dsp
= NULL
;
4458 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4462 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4464 dsl_pool_rele(dp
, FTAG
);
4468 mutex_enter(&ds
->ds_sendstream_lock
);
4471 * Iterate over all the send streams currently active on this dataset.
4472 * If there's one which matches the specified file descriptor _and_ the
4473 * stream was started by the current process, return the progress of
4476 for (dsp
= list_head(&ds
->ds_sendstreams
); dsp
!= NULL
;
4477 dsp
= list_next(&ds
->ds_sendstreams
, dsp
)) {
4478 if (dsp
->dsa_outfd
== zc
->zc_cookie
&&
4479 dsp
->dsa_proc
== curproc
)
4484 zc
->zc_cookie
= *(dsp
->dsa_off
);
4486 error
= SET_ERROR(ENOENT
);
4488 mutex_exit(&ds
->ds_sendstream_lock
);
4489 dsl_dataset_rele(ds
, FTAG
);
4490 dsl_pool_rele(dp
, FTAG
);
4495 zfs_ioc_inject_fault(zfs_cmd_t
*zc
)
4499 error
= zio_inject_fault(zc
->zc_name
, (int)zc
->zc_guid
, &id
,
4500 &zc
->zc_inject_record
);
4503 zc
->zc_guid
= (uint64_t)id
;
4509 zfs_ioc_clear_fault(zfs_cmd_t
*zc
)
4511 return (zio_clear_fault((int)zc
->zc_guid
));
4515 zfs_ioc_inject_list_next(zfs_cmd_t
*zc
)
4517 int id
= (int)zc
->zc_guid
;
4520 error
= zio_inject_list_next(&id
, zc
->zc_name
, sizeof (zc
->zc_name
),
4521 &zc
->zc_inject_record
);
4529 zfs_ioc_error_log(zfs_cmd_t
*zc
)
4533 size_t count
= (size_t)zc
->zc_nvlist_dst_size
;
4535 if ((error
= spa_open(zc
->zc_name
, &spa
, FTAG
)) != 0)
4538 error
= spa_get_errlog(spa
, (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4541 zc
->zc_nvlist_dst_size
= count
;
4543 zc
->zc_nvlist_dst_size
= spa_get_errlog_size(spa
);
4545 spa_close(spa
, FTAG
);
4551 zfs_ioc_clear(zfs_cmd_t
*zc
)
4558 * On zpool clear we also fix up missing slogs
4560 mutex_enter(&spa_namespace_lock
);
4561 spa
= spa_lookup(zc
->zc_name
);
4563 mutex_exit(&spa_namespace_lock
);
4564 return (SET_ERROR(EIO
));
4566 if (spa_get_log_state(spa
) == SPA_LOG_MISSING
) {
4567 /* we need to let spa_open/spa_load clear the chains */
4568 spa_set_log_state(spa
, SPA_LOG_CLEAR
);
4570 spa
->spa_last_open_failed
= 0;
4571 mutex_exit(&spa_namespace_lock
);
4573 if (zc
->zc_cookie
& ZPOOL_NO_REWIND
) {
4574 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4577 nvlist_t
*config
= NULL
;
4579 if (zc
->zc_nvlist_src
== (uintptr_t)NULL
)
4580 return (SET_ERROR(EINVAL
));
4582 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
4583 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &policy
)) == 0) {
4584 error
= spa_open_rewind(zc
->zc_name
, &spa
, FTAG
,
4586 if (config
!= NULL
) {
4589 if ((err
= put_nvlist(zc
, config
)) != 0)
4591 nvlist_free(config
);
4593 nvlist_free(policy
);
4600 spa_vdev_state_enter(spa
, SCL_NONE
);
4602 if (zc
->zc_guid
== 0) {
4605 vd
= spa_lookup_by_guid(spa
, zc
->zc_guid
, B_TRUE
);
4607 (void) spa_vdev_state_exit(spa
, NULL
, ENODEV
);
4608 spa_close(spa
, FTAG
);
4609 return (SET_ERROR(ENODEV
));
4613 vdev_clear(spa
, vd
);
4615 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4618 * Resume any suspended I/Os.
4620 if (zio_resume(spa
) != 0)
4621 error
= SET_ERROR(EIO
);
4623 spa_close(spa
, FTAG
);
4629 zfs_ioc_pool_reopen(zfs_cmd_t
*zc
)
4634 error
= spa_open(zc
->zc_name
, &spa
, FTAG
);
4638 spa_vdev_state_enter(spa
, SCL_NONE
);
4641 * If a resilver is already in progress then set the
4642 * spa_scrub_reopen flag to B_TRUE so that we don't restart
4643 * the scan as a side effect of the reopen. Otherwise, let
4644 * vdev_open() decided if a resilver is required.
4646 spa
->spa_scrub_reopen
= dsl_scan_resilvering(spa
->spa_dsl_pool
);
4647 vdev_reopen(spa
->spa_root_vdev
);
4648 spa
->spa_scrub_reopen
= B_FALSE
;
4650 (void) spa_vdev_state_exit(spa
, NULL
, 0);
4651 spa_close(spa
, FTAG
);
4656 * zc_name name of filesystem
4659 * zc_string name of conflicting snapshot, if there is one
4662 zfs_ioc_promote(zfs_cmd_t
*zc
)
4665 dsl_dataset_t
*ds
, *ods
;
4666 char origin
[ZFS_MAX_DATASET_NAME_LEN
];
4670 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
4671 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0 ||
4672 strchr(zc
->zc_name
, '%'))
4673 return (SET_ERROR(EINVAL
));
4675 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
4679 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &ds
);
4681 dsl_pool_rele(dp
, FTAG
);
4685 if (!dsl_dir_is_clone(ds
->ds_dir
)) {
4686 dsl_dataset_rele(ds
, FTAG
);
4687 dsl_pool_rele(dp
, FTAG
);
4688 return (SET_ERROR(EINVAL
));
4691 error
= dsl_dataset_hold_obj(dp
,
4692 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
, FTAG
, &ods
);
4694 dsl_dataset_rele(ds
, FTAG
);
4695 dsl_pool_rele(dp
, FTAG
);
4699 dsl_dataset_name(ods
, origin
);
4700 dsl_dataset_rele(ods
, FTAG
);
4701 dsl_dataset_rele(ds
, FTAG
);
4702 dsl_pool_rele(dp
, FTAG
);
4705 * We don't need to unmount *all* the origin fs's snapshots, but
4708 cp
= strchr(origin
, '@');
4711 (void) dmu_objset_find(origin
,
4712 zfs_unmount_snap_cb
, NULL
, DS_FIND_SNAPSHOTS
);
4713 return (dsl_dataset_promote(zc
->zc_name
, zc
->zc_string
));
4717 * Retrieve a single {user|group}{used|quota}@... property.
4720 * zc_name name of filesystem
4721 * zc_objset_type zfs_userquota_prop_t
4722 * zc_value domain name (eg. "S-1-234-567-89")
4723 * zc_guid RID/UID/GID
4726 * zc_cookie property value
4729 zfs_ioc_userspace_one(zfs_cmd_t
*zc
)
4734 if (zc
->zc_objset_type
>= ZFS_NUM_USERQUOTA_PROPS
)
4735 return (SET_ERROR(EINVAL
));
4737 error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
4741 error
= zfs_userspace_one(zfsvfs
,
4742 zc
->zc_objset_type
, zc
->zc_value
, zc
->zc_guid
, &zc
->zc_cookie
);
4743 zfsvfs_rele(zfsvfs
, FTAG
);
4750 * zc_name name of filesystem
4751 * zc_cookie zap cursor
4752 * zc_objset_type zfs_userquota_prop_t
4753 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
4756 * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
4757 * zc_cookie zap cursor
4760 zfs_ioc_userspace_many(zfs_cmd_t
*zc
)
4763 int bufsize
= zc
->zc_nvlist_dst_size
;
4766 return (SET_ERROR(ENOMEM
));
4768 int error
= zfsvfs_hold(zc
->zc_name
, FTAG
, &zfsvfs
, B_FALSE
);
4772 void *buf
= kmem_alloc(bufsize
, KM_SLEEP
);
4774 error
= zfs_userspace_many(zfsvfs
, zc
->zc_objset_type
, &zc
->zc_cookie
,
4775 buf
, &zc
->zc_nvlist_dst_size
);
4778 error
= xcopyout(buf
,
4779 (void *)(uintptr_t)zc
->zc_nvlist_dst
,
4780 zc
->zc_nvlist_dst_size
);
4782 kmem_free(buf
, bufsize
);
4783 zfsvfs_rele(zfsvfs
, FTAG
);
4790 * zc_name name of filesystem
4796 zfs_ioc_userspace_upgrade(zfs_cmd_t
*zc
)
4802 if (getzfsvfs(zc
->zc_name
, &zfsvfs
) == 0) {
4803 if (!dmu_objset_userused_enabled(zfsvfs
->z_os
)) {
4805 * If userused is not enabled, it may be because the
4806 * objset needs to be closed & reopened (to grow the
4807 * objset_phys_t). Suspend/resume the fs will do that.
4809 dsl_dataset_t
*ds
, *newds
;
4811 ds
= dmu_objset_ds(zfsvfs
->z_os
);
4812 error
= zfs_suspend_fs(zfsvfs
);
4814 dmu_objset_refresh_ownership(ds
, &newds
,
4816 error
= zfs_resume_fs(zfsvfs
, newds
);
4820 error
= dmu_objset_userspace_upgrade(zfsvfs
->z_os
);
4821 VFS_RELE(zfsvfs
->z_vfs
);
4823 /* XXX kind of reading contents without owning */
4824 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4828 error
= dmu_objset_userspace_upgrade(os
);
4829 dmu_objset_rele(os
, FTAG
);
4836 * We don't want to have a hard dependency
4837 * against some special symbols in sharefs
4838 * nfs, and smbsrv. Determine them if needed when
4839 * the first file system is shared.
4840 * Neither sharefs, nfs or smbsrv are unloadable modules.
4842 int (*znfsexport_fs
)(void *arg
);
4843 int (*zshare_fs
)(enum sharefs_sys_op
, share_t
*, uint32_t);
4844 int (*zsmbexport_fs
)(void *arg
, boolean_t add_share
);
4846 int zfs_nfsshare_inited
;
4847 int zfs_smbshare_inited
;
4849 ddi_modhandle_t nfs_mod
;
4850 ddi_modhandle_t sharefs_mod
;
4851 ddi_modhandle_t smbsrv_mod
;
4852 kmutex_t zfs_share_lock
;
4859 ASSERT(MUTEX_HELD(&zfs_share_lock
));
4860 /* Both NFS and SMB shares also require sharetab support. */
4861 if (sharefs_mod
== NULL
&& ((sharefs_mod
=
4862 ddi_modopen("fs/sharefs",
4863 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4864 return (SET_ERROR(ENOSYS
));
4866 if (zshare_fs
== NULL
&& ((zshare_fs
=
4867 (int (*)(enum sharefs_sys_op
, share_t
*, uint32_t))
4868 ddi_modsym(sharefs_mod
, "sharefs_impl", &error
)) == NULL
)) {
4869 return (SET_ERROR(ENOSYS
));
4875 zfs_ioc_share(zfs_cmd_t
*zc
)
4880 switch (zc
->zc_share
.z_sharetype
) {
4882 case ZFS_UNSHARE_NFS
:
4883 if (zfs_nfsshare_inited
== 0) {
4884 mutex_enter(&zfs_share_lock
);
4885 if (nfs_mod
== NULL
&& ((nfs_mod
= ddi_modopen("fs/nfs",
4886 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4887 mutex_exit(&zfs_share_lock
);
4888 return (SET_ERROR(ENOSYS
));
4890 if (znfsexport_fs
== NULL
&&
4891 ((znfsexport_fs
= (int (*)(void *))
4893 "nfs_export", &error
)) == NULL
)) {
4894 mutex_exit(&zfs_share_lock
);
4895 return (SET_ERROR(ENOSYS
));
4897 error
= zfs_init_sharefs();
4899 mutex_exit(&zfs_share_lock
);
4900 return (SET_ERROR(ENOSYS
));
4902 zfs_nfsshare_inited
= 1;
4903 mutex_exit(&zfs_share_lock
);
4907 case ZFS_UNSHARE_SMB
:
4908 if (zfs_smbshare_inited
== 0) {
4909 mutex_enter(&zfs_share_lock
);
4910 if (smbsrv_mod
== NULL
&& ((smbsrv_mod
=
4911 ddi_modopen("drv/smbsrv",
4912 KRTLD_MODE_FIRST
, &error
)) == NULL
)) {
4913 mutex_exit(&zfs_share_lock
);
4914 return (SET_ERROR(ENOSYS
));
4916 if (zsmbexport_fs
== NULL
&& ((zsmbexport_fs
=
4917 (int (*)(void *, boolean_t
))ddi_modsym(smbsrv_mod
,
4918 "smb_server_share", &error
)) == NULL
)) {
4919 mutex_exit(&zfs_share_lock
);
4920 return (SET_ERROR(ENOSYS
));
4922 error
= zfs_init_sharefs();
4924 mutex_exit(&zfs_share_lock
);
4925 return (SET_ERROR(ENOSYS
));
4927 zfs_smbshare_inited
= 1;
4928 mutex_exit(&zfs_share_lock
);
4932 return (SET_ERROR(EINVAL
));
4935 switch (zc
->zc_share
.z_sharetype
) {
4937 case ZFS_UNSHARE_NFS
:
4939 znfsexport_fs((void *)
4940 (uintptr_t)zc
->zc_share
.z_exportdata
))
4944 case ZFS_UNSHARE_SMB
:
4945 if (error
= zsmbexport_fs((void *)
4946 (uintptr_t)zc
->zc_share
.z_exportdata
,
4947 zc
->zc_share
.z_sharetype
== ZFS_SHARE_SMB
?
4954 opcode
= (zc
->zc_share
.z_sharetype
== ZFS_SHARE_NFS
||
4955 zc
->zc_share
.z_sharetype
== ZFS_SHARE_SMB
) ?
4956 SHAREFS_ADD
: SHAREFS_REMOVE
;
4959 * Add or remove share from sharetab
4961 error
= zshare_fs(opcode
,
4962 (void *)(uintptr_t)zc
->zc_share
.z_sharedata
,
4963 zc
->zc_share
.z_sharemax
);
4969 ace_t full_access
[] = {
4970 {(uid_t
)-1, ACE_ALL_PERMS
, ACE_EVERYONE
, 0}
4975 * zc_name name of containing filesystem
4976 * zc_obj object # beyond which we want next in-use object #
4979 * zc_obj next in-use object #
4982 zfs_ioc_next_obj(zfs_cmd_t
*zc
)
4984 objset_t
*os
= NULL
;
4987 error
= dmu_objset_hold(zc
->zc_name
, FTAG
, &os
);
4991 error
= dmu_object_next(os
, &zc
->zc_obj
, B_FALSE
,
4992 dsl_dataset_phys(os
->os_dsl_dataset
)->ds_prev_snap_txg
);
4994 dmu_objset_rele(os
, FTAG
);
5000 * zc_name name of filesystem
5001 * zc_value prefix name for snapshot
5002 * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
5005 * zc_value short name of new snapshot
5008 zfs_ioc_tmp_snapshot(zfs_cmd_t
*zc
)
5015 error
= zfs_onexit_fd_hold(zc
->zc_cleanup_fd
, &minor
);
5019 snap_name
= kmem_asprintf("%s-%016llx", zc
->zc_value
,
5020 (u_longlong_t
)ddi_get_lbolt64());
5021 hold_name
= kmem_asprintf("%%%s", zc
->zc_value
);
5023 error
= dsl_dataset_snapshot_tmp(zc
->zc_name
, snap_name
, minor
,
5026 (void) strcpy(zc
->zc_value
, snap_name
);
5029 zfs_onexit_fd_rele(zc
->zc_cleanup_fd
);
5035 * zc_name name of "to" snapshot
5036 * zc_value name of "from" snapshot
5037 * zc_cookie file descriptor to write diff data on
5040 * dmu_diff_record_t's to the file descriptor
5043 zfs_ioc_diff(zfs_cmd_t
*zc
)
5049 fp
= getf(zc
->zc_cookie
);
5051 return (SET_ERROR(EBADF
));
5055 error
= dmu_diff(zc
->zc_name
, zc
->zc_value
, fp
->f_vnode
, &off
);
5057 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5059 releasef(zc
->zc_cookie
);
5065 * Remove all ACL files in shares dir
5068 zfs_smb_acl_purge(znode_t
*dzp
)
5071 zap_attribute_t zap
;
5072 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
5075 for (zap_cursor_init(&zc
, zfsvfs
->z_os
, dzp
->z_id
);
5076 (error
= zap_cursor_retrieve(&zc
, &zap
)) == 0;
5077 zap_cursor_advance(&zc
)) {
5078 if ((error
= fop_remove(ZTOV(dzp
), zap
.za_name
, kcred
,
5082 zap_cursor_fini(&zc
);
5087 zfs_ioc_smb_acl(zfs_cmd_t
*zc
)
5091 vnode_t
*resourcevp
= NULL
;
5100 if ((error
= lookupname(zc
->zc_value
, UIO_SYSSPACE
,
5101 NO_FOLLOW
, NULL
, &vp
)) != 0)
5104 /* Now make sure mntpnt and dataset are ZFS */
5106 if (vp
->v_vfsp
->vfs_fstype
!= zfsfstype
||
5107 (strcmp((char *)refstr_value(vp
->v_vfsp
->vfs_resource
),
5108 zc
->zc_name
) != 0)) {
5110 return (SET_ERROR(EINVAL
));
5114 zfsvfs
= dzp
->z_zfsvfs
;
5118 * Create share dir if its missing.
5120 mutex_enter(&zfsvfs
->z_lock
);
5121 if (zfsvfs
->z_shares_dir
== 0) {
5124 tx
= dmu_tx_create(zfsvfs
->z_os
);
5125 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, TRUE
,
5127 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
5128 error
= dmu_tx_assign(tx
, TXG_WAIT
);
5132 error
= zfs_create_share_dir(zfsvfs
, tx
);
5136 mutex_exit(&zfsvfs
->z_lock
);
5142 mutex_exit(&zfsvfs
->z_lock
);
5144 ASSERT(zfsvfs
->z_shares_dir
);
5145 if ((error
= zfs_zget(zfsvfs
, zfsvfs
->z_shares_dir
, &sharedir
)) != 0) {
5151 switch (zc
->zc_cookie
) {
5152 case ZFS_SMB_ACL_ADD
:
5153 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
5154 vattr
.va_type
= VREG
;
5155 vattr
.va_mode
= S_IFREG
|0777;
5159 vsec
.vsa_mask
= VSA_ACE
;
5160 vsec
.vsa_aclentp
= &full_access
;
5161 vsec
.vsa_aclentsz
= sizeof (full_access
);
5162 vsec
.vsa_aclcnt
= 1;
5164 error
= fop_create(ZTOV(sharedir
), zc
->zc_string
,
5165 &vattr
, EXCL
, 0, &resourcevp
, kcred
, 0, NULL
, &vsec
);
5167 VN_RELE(resourcevp
);
5170 case ZFS_SMB_ACL_REMOVE
:
5171 error
= fop_remove(ZTOV(sharedir
), zc
->zc_string
, kcred
,
5175 case ZFS_SMB_ACL_RENAME
:
5176 if ((error
= get_nvlist(zc
->zc_nvlist_src
,
5177 zc
->zc_nvlist_src_size
, zc
->zc_iflags
, &nvlist
)) != 0) {
5179 VN_RELE(ZTOV(sharedir
));
5183 if (nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_SRC
, &src
) ||
5184 nvlist_lookup_string(nvlist
, ZFS_SMB_ACL_TARGET
,
5187 VN_RELE(ZTOV(sharedir
));
5189 nvlist_free(nvlist
);
5192 error
= fop_rename(ZTOV(sharedir
), src
, ZTOV(sharedir
), target
,
5194 nvlist_free(nvlist
);
5197 case ZFS_SMB_ACL_PURGE
:
5198 error
= zfs_smb_acl_purge(sharedir
);
5202 error
= SET_ERROR(EINVAL
);
5207 VN_RELE(ZTOV(sharedir
));
5216 * "holds" -> { snapname -> holdname (string), ... }
5217 * (optional) "cleanup_fd" -> fd (int32)
5221 * snapname -> error value (int32)
5227 zfs_ioc_hold(const char *pool
, nvlist_t
*args
, nvlist_t
*errlist
)
5231 int cleanup_fd
= -1;
5235 error
= nvlist_lookup_nvlist(args
, "holds", &holds
);
5237 return (SET_ERROR(EINVAL
));
5239 /* make sure the user didn't pass us any invalid (empty) tags */
5240 for (pair
= nvlist_next_nvpair(holds
, NULL
); pair
!= NULL
;
5241 pair
= nvlist_next_nvpair(holds
, pair
)) {
5244 error
= nvpair_value_string(pair
, &htag
);
5246 return (SET_ERROR(error
));
5248 if (strlen(htag
) == 0)
5249 return (SET_ERROR(EINVAL
));
5252 if (nvlist_lookup_int32(args
, "cleanup_fd", &cleanup_fd
) == 0) {
5253 error
= zfs_onexit_fd_hold(cleanup_fd
, &minor
);
5258 error
= dsl_dataset_user_hold(holds
, minor
, errlist
);
5260 zfs_onexit_fd_rele(cleanup_fd
);
5265 * innvl is not used.
5268 * holdname -> time added (uint64 seconds since epoch)
5274 zfs_ioc_get_holds(const char *snapname
, nvlist_t
*args
, nvlist_t
*outnvl
)
5276 return (dsl_dataset_get_holds(snapname
, outnvl
));
5281 * snapname -> { holdname, ... }
5286 * snapname -> error value (int32)
5292 zfs_ioc_release(const char *pool
, nvlist_t
*holds
, nvlist_t
*errlist
)
5294 return (dsl_dataset_user_release(holds
, errlist
));
5299 * zc_name name of new filesystem or snapshot
5300 * zc_value full name of old snapshot
5303 * zc_cookie space in bytes
5304 * zc_objset_type compressed space in bytes
5305 * zc_perm_action uncompressed space in bytes
5308 zfs_ioc_space_written(zfs_cmd_t
*zc
)
5312 dsl_dataset_t
*new, *old
;
5314 error
= dsl_pool_hold(zc
->zc_name
, FTAG
, &dp
);
5317 error
= dsl_dataset_hold(dp
, zc
->zc_name
, FTAG
, &new);
5319 dsl_pool_rele(dp
, FTAG
);
5322 error
= dsl_dataset_hold(dp
, zc
->zc_value
, FTAG
, &old
);
5324 dsl_dataset_rele(new, FTAG
);
5325 dsl_pool_rele(dp
, FTAG
);
5329 error
= dsl_dataset_space_written(old
, new, &zc
->zc_cookie
,
5330 &zc
->zc_objset_type
, &zc
->zc_perm_action
);
5331 dsl_dataset_rele(old
, FTAG
);
5332 dsl_dataset_rele(new, FTAG
);
5333 dsl_pool_rele(dp
, FTAG
);
5339 * "firstsnap" -> snapshot name
5343 * "used" -> space in bytes
5344 * "compressed" -> compressed space in bytes
5345 * "uncompressed" -> uncompressed space in bytes
5349 zfs_ioc_space_snaps(const char *lastsnap
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5353 dsl_dataset_t
*new, *old
;
5355 uint64_t used
, comp
, uncomp
;
5357 if (nvlist_lookup_string(innvl
, "firstsnap", &firstsnap
) != 0)
5358 return (SET_ERROR(EINVAL
));
5360 error
= dsl_pool_hold(lastsnap
, FTAG
, &dp
);
5364 error
= dsl_dataset_hold(dp
, lastsnap
, FTAG
, &new);
5365 if (error
== 0 && !new->ds_is_snapshot
) {
5366 dsl_dataset_rele(new, FTAG
);
5367 error
= SET_ERROR(EINVAL
);
5370 dsl_pool_rele(dp
, FTAG
);
5373 error
= dsl_dataset_hold(dp
, firstsnap
, FTAG
, &old
);
5374 if (error
== 0 && !old
->ds_is_snapshot
) {
5375 dsl_dataset_rele(old
, FTAG
);
5376 error
= SET_ERROR(EINVAL
);
5379 dsl_dataset_rele(new, FTAG
);
5380 dsl_pool_rele(dp
, FTAG
);
5384 error
= dsl_dataset_space_wouldfree(old
, new, &used
, &comp
, &uncomp
);
5385 dsl_dataset_rele(old
, FTAG
);
5386 dsl_dataset_rele(new, FTAG
);
5387 dsl_pool_rele(dp
, FTAG
);
5388 fnvlist_add_uint64(outnvl
, "used", used
);
5389 fnvlist_add_uint64(outnvl
, "compressed", comp
);
5390 fnvlist_add_uint64(outnvl
, "uncompressed", uncomp
);
5396 * "fd" -> file descriptor to write stream to (int32)
5397 * (optional) "fromsnap" -> full snap name to send an incremental from
5398 * (optional) "largeblockok" -> (value ignored)
5399 * indicates that blocks > 128KB are permitted
5400 * (optional) "embedok" -> (value ignored)
5401 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5402 * (optional) "compressok" -> (value ignored)
5403 * presence indicates compressed DRR_WRITE records are permitted
5404 * (optional) "resume_object" and "resume_offset" -> (uint64)
5405 * if present, resume send stream from specified object and offset.
5412 zfs_ioc_send_new(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5416 char *fromname
= NULL
;
5418 boolean_t largeblockok
;
5420 boolean_t compressok
;
5421 uint64_t resumeobj
= 0;
5422 uint64_t resumeoff
= 0;
5424 error
= nvlist_lookup_int32(innvl
, "fd", &fd
);
5426 return (SET_ERROR(EINVAL
));
5428 (void) nvlist_lookup_string(innvl
, "fromsnap", &fromname
);
5430 largeblockok
= nvlist_exists(innvl
, "largeblockok");
5431 embedok
= nvlist_exists(innvl
, "embedok");
5432 compressok
= nvlist_exists(innvl
, "compressok");
5434 (void) nvlist_lookup_uint64(innvl
, "resume_object", &resumeobj
);
5435 (void) nvlist_lookup_uint64(innvl
, "resume_offset", &resumeoff
);
5437 file_t
*fp
= getf(fd
);
5439 return (SET_ERROR(EBADF
));
5442 error
= dmu_send(snapname
, fromname
, embedok
, largeblockok
, compressok
,
5443 fd
, resumeobj
, resumeoff
, fp
->f_vnode
, &off
);
5445 if (fop_seek(fp
->f_vnode
, fp
->f_offset
, &off
, NULL
) == 0)
5452 * Determine approximately how large a zfs send stream will be -- the number
5453 * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
5456 * (optional) "from" -> full snap or bookmark name to send an incremental
5458 * (optional) "largeblockok" -> (value ignored)
5459 * indicates that blocks > 128KB are permitted
5460 * (optional) "embedok" -> (value ignored)
5461 * presence indicates DRR_WRITE_EMBEDDED records are permitted
5462 * (optional) "compressok" -> (value ignored)
5463 * presence indicates compressed DRR_WRITE records are permitted
5467 * "space" -> bytes of space (uint64)
5471 zfs_ioc_send_space(const char *snapname
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5474 dsl_dataset_t
*tosnap
;
5477 boolean_t compressok
;
5480 error
= dsl_pool_hold(snapname
, FTAG
, &dp
);
5484 error
= dsl_dataset_hold(dp
, snapname
, FTAG
, &tosnap
);
5486 dsl_pool_rele(dp
, FTAG
);
5490 compressok
= nvlist_exists(innvl
, "compressok");
5492 error
= nvlist_lookup_string(innvl
, "from", &fromname
);
5494 if (strchr(fromname
, '@') != NULL
) {
5496 * If from is a snapshot, hold it and use the more
5497 * efficient dmu_send_estimate to estimate send space
5498 * size using deadlists.
5500 dsl_dataset_t
*fromsnap
;
5501 error
= dsl_dataset_hold(dp
, fromname
, FTAG
, &fromsnap
);
5504 error
= dmu_send_estimate(tosnap
, fromsnap
, compressok
,
5506 dsl_dataset_rele(fromsnap
, FTAG
);
5507 } else if (strchr(fromname
, '#') != NULL
) {
5509 * If from is a bookmark, fetch the creation TXG of the
5510 * snapshot it was created from and use that to find
5511 * blocks that were born after it.
5513 zfs_bookmark_phys_t frombm
;
5515 error
= dsl_bookmark_lookup(dp
, fromname
, tosnap
,
5519 error
= dmu_send_estimate_from_txg(tosnap
,
5520 frombm
.zbm_creation_txg
, compressok
, &space
);
5523 * from is not properly formatted as a snapshot or
5526 error
= SET_ERROR(EINVAL
);
5531 * If estimating the size of a full send, use dmu_send_estimate.
5533 error
= dmu_send_estimate(tosnap
, NULL
, compressok
, &space
);
5536 fnvlist_add_uint64(outnvl
, "space", space
);
5539 dsl_dataset_rele(tosnap
, FTAG
);
5540 dsl_pool_rele(dp
, FTAG
);
5544 static zfs_ioc_vec_t zfs_ioc_vec
[ZFS_IOC_LAST
- ZFS_IOC_FIRST
];
5547 zfs_ioctl_register_legacy(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5548 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5549 boolean_t log_history
, zfs_ioc_poolcheck_t pool_check
)
5551 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5553 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5554 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5555 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5556 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5558 vec
->zvec_legacy_func
= func
;
5559 vec
->zvec_secpolicy
= secpolicy
;
5560 vec
->zvec_namecheck
= namecheck
;
5561 vec
->zvec_allow_log
= log_history
;
5562 vec
->zvec_pool_check
= pool_check
;
5566 * See the block comment at the beginning of this file for details on
5567 * each argument to this function.
5570 zfs_ioctl_register(const char *name
, zfs_ioc_t ioc
, zfs_ioc_func_t
*func
,
5571 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_namecheck_t namecheck
,
5572 zfs_ioc_poolcheck_t pool_check
, boolean_t smush_outnvlist
,
5573 boolean_t allow_log
)
5575 zfs_ioc_vec_t
*vec
= &zfs_ioc_vec
[ioc
- ZFS_IOC_FIRST
];
5577 ASSERT3U(ioc
, >=, ZFS_IOC_FIRST
);
5578 ASSERT3U(ioc
, <, ZFS_IOC_LAST
);
5579 ASSERT3P(vec
->zvec_legacy_func
, ==, NULL
);
5580 ASSERT3P(vec
->zvec_func
, ==, NULL
);
5582 /* if we are logging, the name must be valid */
5583 ASSERT(!allow_log
|| namecheck
!= NO_NAME
);
5585 vec
->zvec_name
= name
;
5586 vec
->zvec_func
= func
;
5587 vec
->zvec_secpolicy
= secpolicy
;
5588 vec
->zvec_namecheck
= namecheck
;
5589 vec
->zvec_pool_check
= pool_check
;
5590 vec
->zvec_smush_outnvlist
= smush_outnvlist
;
5591 vec
->zvec_allow_log
= allow_log
;
5595 zfs_ioctl_register_pool(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5596 zfs_secpolicy_func_t
*secpolicy
, boolean_t log_history
,
5597 zfs_ioc_poolcheck_t pool_check
)
5599 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5600 POOL_NAME
, log_history
, pool_check
);
5604 zfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5605 zfs_secpolicy_func_t
*secpolicy
, zfs_ioc_poolcheck_t pool_check
)
5607 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5608 DATASET_NAME
, B_FALSE
, pool_check
);
5612 zfs_ioctl_register_pool_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5614 zfs_ioctl_register_legacy(ioc
, func
, zfs_secpolicy_config
,
5615 POOL_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5619 zfs_ioctl_register_pool_meta(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5620 zfs_secpolicy_func_t
*secpolicy
)
5622 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5623 NO_NAME
, B_FALSE
, POOL_CHECK_NONE
);
5627 zfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc
,
5628 zfs_ioc_legacy_func_t
*func
, zfs_secpolicy_func_t
*secpolicy
)
5630 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5631 DATASET_NAME
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5635 zfs_ioctl_register_dataset_read(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
)
5637 zfs_ioctl_register_dataset_read_secpolicy(ioc
, func
,
5638 zfs_secpolicy_read
);
5642 zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc
, zfs_ioc_legacy_func_t
*func
,
5643 zfs_secpolicy_func_t
*secpolicy
)
5645 zfs_ioctl_register_legacy(ioc
, func
, secpolicy
,
5646 DATASET_NAME
, B_TRUE
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5650 zfs_ioctl_init(void)
5652 zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT
,
5653 zfs_ioc_snapshot
, zfs_secpolicy_snapshot
, POOL_NAME
,
5654 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5656 zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY
,
5657 zfs_ioc_log_history
, zfs_secpolicy_log_history
, NO_NAME
,
5658 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_FALSE
);
5660 zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS
,
5661 zfs_ioc_space_snaps
, zfs_secpolicy_read
, DATASET_NAME
,
5662 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5664 zfs_ioctl_register("send", ZFS_IOC_SEND_NEW
,
5665 zfs_ioc_send_new
, zfs_secpolicy_send_new
, DATASET_NAME
,
5666 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5668 zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE
,
5669 zfs_ioc_send_space
, zfs_secpolicy_read
, DATASET_NAME
,
5670 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5672 zfs_ioctl_register("create", ZFS_IOC_CREATE
,
5673 zfs_ioc_create
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5674 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5676 zfs_ioctl_register("clone", ZFS_IOC_CLONE
,
5677 zfs_ioc_clone
, zfs_secpolicy_create_clone
, DATASET_NAME
,
5678 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5680 zfs_ioctl_register("remap", ZFS_IOC_REMAP
,
5681 zfs_ioc_remap
, zfs_secpolicy_remap
, DATASET_NAME
,
5682 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
5684 zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS
,
5685 zfs_ioc_destroy_snaps
, zfs_secpolicy_destroy_snaps
, POOL_NAME
,
5686 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5688 zfs_ioctl_register("hold", ZFS_IOC_HOLD
,
5689 zfs_ioc_hold
, zfs_secpolicy_hold
, POOL_NAME
,
5690 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5691 zfs_ioctl_register("release", ZFS_IOC_RELEASE
,
5692 zfs_ioc_release
, zfs_secpolicy_release
, POOL_NAME
,
5693 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5695 zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS
,
5696 zfs_ioc_get_holds
, zfs_secpolicy_read
, DATASET_NAME
,
5697 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5699 zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK
,
5700 zfs_ioc_rollback
, zfs_secpolicy_rollback
, DATASET_NAME
,
5701 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_FALSE
, B_TRUE
);
5703 zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK
,
5704 zfs_ioc_bookmark
, zfs_secpolicy_bookmark
, POOL_NAME
,
5705 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5707 zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS
,
5708 zfs_ioc_get_bookmarks
, zfs_secpolicy_read
, DATASET_NAME
,
5709 POOL_CHECK_SUSPENDED
, B_FALSE
, B_FALSE
);
5711 zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS
,
5712 zfs_ioc_destroy_bookmarks
, zfs_secpolicy_destroy_bookmarks
,
5714 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
, B_TRUE
);
5716 zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM
,
5717 zfs_ioc_channel_program
, zfs_secpolicy_config
,
5718 POOL_NAME
, POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
, B_TRUE
,
5721 /* IOCTLS that use the legacy function signature */
5723 zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE
, zfs_ioc_pool_freeze
,
5724 zfs_secpolicy_config
, NO_NAME
, B_FALSE
, POOL_CHECK_READONLY
);
5726 zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE
, zfs_ioc_pool_create
,
5727 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5728 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN
,
5730 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE
,
5731 zfs_ioc_pool_upgrade
);
5732 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD
,
5734 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE
,
5735 zfs_ioc_vdev_remove
);
5736 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE
,
5737 zfs_ioc_vdev_set_state
);
5738 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH
,
5739 zfs_ioc_vdev_attach
);
5740 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH
,
5741 zfs_ioc_vdev_detach
);
5742 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH
,
5743 zfs_ioc_vdev_setpath
);
5744 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU
,
5745 zfs_ioc_vdev_setfru
);
5746 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS
,
5747 zfs_ioc_pool_set_props
);
5748 zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT
,
5749 zfs_ioc_vdev_split
);
5750 zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID
,
5751 zfs_ioc_pool_reguid
);
5753 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS
,
5754 zfs_ioc_pool_configs
, zfs_secpolicy_none
);
5755 zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT
,
5756 zfs_ioc_pool_tryimport
, zfs_secpolicy_config
);
5757 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT
,
5758 zfs_ioc_inject_fault
, zfs_secpolicy_inject
);
5759 zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT
,
5760 zfs_ioc_clear_fault
, zfs_secpolicy_inject
);
5761 zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT
,
5762 zfs_ioc_inject_list_next
, zfs_secpolicy_inject
);
5765 * pool destroy, and export don't log the history as part of
5766 * zfsdev_ioctl, but rather zfs_ioc_pool_export
5767 * does the logging of those commands.
5769 zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY
, zfs_ioc_pool_destroy
,
5770 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5771 zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT
, zfs_ioc_pool_export
,
5772 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_NONE
);
5774 zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS
, zfs_ioc_pool_stats
,
5775 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5776 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS
, zfs_ioc_pool_get_props
,
5777 zfs_secpolicy_read
, B_FALSE
, POOL_CHECK_NONE
);
5779 zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG
, zfs_ioc_error_log
,
5780 zfs_secpolicy_inject
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5781 zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME
,
5782 zfs_ioc_dsobj_to_dsname
,
5783 zfs_secpolicy_diff
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5784 zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY
,
5785 zfs_ioc_pool_get_history
,
5786 zfs_secpolicy_config
, B_FALSE
, POOL_CHECK_SUSPENDED
);
5788 zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT
, zfs_ioc_pool_import
,
5789 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_NONE
);
5791 zfs_ioctl_register_pool(ZFS_IOC_CLEAR
, zfs_ioc_clear
,
5792 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_READONLY
);
5793 zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN
, zfs_ioc_pool_reopen
,
5794 zfs_secpolicy_config
, B_TRUE
, POOL_CHECK_SUSPENDED
);
5796 zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN
,
5797 zfs_ioc_space_written
);
5798 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS
,
5799 zfs_ioc_objset_recvd_props
);
5800 zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ
,
5802 zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL
,
5804 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS
,
5805 zfs_ioc_objset_stats
);
5806 zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS
,
5807 zfs_ioc_objset_zplprops
);
5808 zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT
,
5809 zfs_ioc_dataset_list_next
);
5810 zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT
,
5811 zfs_ioc_snapshot_list_next
);
5812 zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS
,
5813 zfs_ioc_send_progress
);
5815 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF
,
5816 zfs_ioc_diff
, zfs_secpolicy_diff
);
5817 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS
,
5818 zfs_ioc_obj_to_stats
, zfs_secpolicy_diff
);
5819 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH
,
5820 zfs_ioc_obj_to_path
, zfs_secpolicy_diff
);
5821 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE
,
5822 zfs_ioc_userspace_one
, zfs_secpolicy_userspace_one
);
5823 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY
,
5824 zfs_ioc_userspace_many
, zfs_secpolicy_userspace_many
);
5825 zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND
,
5826 zfs_ioc_send
, zfs_secpolicy_send
);
5828 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP
, zfs_ioc_set_prop
,
5829 zfs_secpolicy_none
);
5830 zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY
, zfs_ioc_destroy
,
5831 zfs_secpolicy_destroy
);
5832 zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME
, zfs_ioc_rename
,
5833 zfs_secpolicy_rename
);
5834 zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV
, zfs_ioc_recv
,
5835 zfs_secpolicy_recv
);
5836 zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE
, zfs_ioc_promote
,
5837 zfs_secpolicy_promote
);
5838 zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP
,
5839 zfs_ioc_inherit_prop
, zfs_secpolicy_inherit_prop
);
5840 zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL
, zfs_ioc_set_fsacl
,
5841 zfs_secpolicy_set_fsacl
);
5843 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE
, zfs_ioc_share
,
5844 zfs_secpolicy_share
, POOL_CHECK_NONE
);
5845 zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL
, zfs_ioc_smb_acl
,
5846 zfs_secpolicy_smb_acl
, POOL_CHECK_NONE
);
5847 zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE
,
5848 zfs_ioc_userspace_upgrade
, zfs_secpolicy_userspace_upgrade
,
5849 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5850 zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT
,
5851 zfs_ioc_tmp_snapshot
, zfs_secpolicy_tmp_snapshot
,
5852 POOL_CHECK_SUSPENDED
| POOL_CHECK_READONLY
);
5856 pool_status_check(const char *name
, zfs_ioc_namecheck_t type
,
5857 zfs_ioc_poolcheck_t check
)
5862 ASSERT(type
== POOL_NAME
|| type
== DATASET_NAME
);
5864 if (check
& POOL_CHECK_NONE
)
5867 error
= spa_open(name
, &spa
, FTAG
);
5869 if ((check
& POOL_CHECK_SUSPENDED
) && spa_suspended(spa
))
5870 error
= SET_ERROR(EAGAIN
);
5871 else if ((check
& POOL_CHECK_READONLY
) && !spa_writeable(spa
))
5872 error
= SET_ERROR(EROFS
);
5873 spa_close(spa
, FTAG
);
5879 * Find a free minor number.
5882 zfsdev_minor_alloc(void)
5884 static minor_t last_minor
;
5887 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5889 for (m
= last_minor
+ 1; m
!= last_minor
; m
++) {
5890 if (m
> ZFSDEV_MAX_MINOR
)
5892 if (ddi_get_soft_state(zfsdev_state
, m
) == NULL
) {
5902 zfs_ctldev_init(dev_t
*devp
)
5905 zfs_soft_state_t
*zs
;
5907 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5908 ASSERT(getminor(*devp
) == 0);
5910 minor
= zfsdev_minor_alloc();
5912 return (SET_ERROR(ENXIO
));
5914 if (ddi_soft_state_zalloc(zfsdev_state
, minor
) != DDI_SUCCESS
)
5915 return (SET_ERROR(EAGAIN
));
5917 *devp
= makedevice(getemajor(*devp
), minor
);
5919 zs
= ddi_get_soft_state(zfsdev_state
, minor
);
5920 zs
->zss_type
= ZSST_CTLDEV
;
5921 zfs_onexit_init((zfs_onexit_t
**)&zs
->zss_data
);
5927 zfs_ctldev_destroy(zfs_onexit_t
*zo
, minor_t minor
)
5929 ASSERT(MUTEX_HELD(&zfsdev_state_lock
));
5931 zfs_onexit_destroy(zo
);
5932 ddi_soft_state_free(zfsdev_state
, minor
);
5936 zfsdev_get_soft_state(minor_t minor
, enum zfs_soft_state_type which
)
5938 zfs_soft_state_t
*zp
;
5940 zp
= ddi_get_soft_state(zfsdev_state
, minor
);
5941 if (zp
== NULL
|| zp
->zss_type
!= which
)
5944 return (zp
->zss_data
);
5948 zfsdev_open(dev_t
*devp
, int flag
, int otyp
, cred_t
*cr
)
5952 if (getminor(*devp
) != 0)
5953 return (zvol_open(devp
, flag
, otyp
, cr
));
5955 /* This is the control device. Allocate a new minor if requested. */
5957 mutex_enter(&zfsdev_state_lock
);
5958 error
= zfs_ctldev_init(devp
);
5959 mutex_exit(&zfsdev_state_lock
);
5966 zfsdev_close(dev_t dev
, int flag
, int otyp
, cred_t
*cr
)
5969 minor_t minor
= getminor(dev
);
5974 mutex_enter(&zfsdev_state_lock
);
5975 zo
= zfsdev_get_soft_state(minor
, ZSST_CTLDEV
);
5977 mutex_exit(&zfsdev_state_lock
);
5978 return (zvol_close(dev
, flag
, otyp
, cr
));
5980 zfs_ctldev_destroy(zo
, minor
);
5981 mutex_exit(&zfsdev_state_lock
);
5987 zfsdev_ioctl(dev_t dev
, int cmd
, intptr_t arg
, int flag
, cred_t
*cr
, int *rvalp
)
5992 minor_t minor
= getminor(dev
);
5993 const zfs_ioc_vec_t
*vec
;
5994 char *saved_poolname
= NULL
;
5995 nvlist_t
*innvl
= NULL
;
5998 zfsdev_get_soft_state(minor
, ZSST_CTLDEV
) == NULL
)
5999 return (zvol_ioctl(dev
, cmd
, arg
, flag
, cr
, rvalp
));
6001 vecnum
= cmd
- ZFS_IOC_FIRST
;
6002 ASSERT3U(getmajor(dev
), ==, ddi_driver_major(zfs_dip
));
6004 if (vecnum
>= sizeof (zfs_ioc_vec
) / sizeof (zfs_ioc_vec
[0]))
6005 return (SET_ERROR(EINVAL
));
6006 vec
= &zfs_ioc_vec
[vecnum
];
6008 zc
= kmem_zalloc(sizeof (zfs_cmd_t
), KM_SLEEP
);
6010 error
= ddi_copyin((void *)arg
, zc
, sizeof (zfs_cmd_t
), flag
);
6012 error
= SET_ERROR(EFAULT
);
6016 zc
->zc_iflags
= flag
& FKIOCTL
;
6017 if (zc
->zc_nvlist_src_size
!= 0) {
6018 error
= get_nvlist(zc
->zc_nvlist_src
, zc
->zc_nvlist_src_size
,
6019 zc
->zc_iflags
, &innvl
);
6025 * Ensure that all pool/dataset names are valid before we pass down to
6028 zc
->zc_name
[sizeof (zc
->zc_name
) - 1] = '\0';
6029 switch (vec
->zvec_namecheck
) {
6031 if (pool_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6032 error
= SET_ERROR(EINVAL
);
6034 error
= pool_status_check(zc
->zc_name
,
6035 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6039 if (dataset_namecheck(zc
->zc_name
, NULL
, NULL
) != 0)
6040 error
= SET_ERROR(EINVAL
);
6042 error
= pool_status_check(zc
->zc_name
,
6043 vec
->zvec_namecheck
, vec
->zvec_pool_check
);
6052 error
= vec
->zvec_secpolicy(zc
, innvl
, cr
);
6057 /* legacy ioctls can modify zc_name */
6058 len
= strcspn(zc
->zc_name
, "/@#") + 1;
6059 saved_poolname
= kmem_alloc(len
, KM_SLEEP
);
6060 (void) strlcpy(saved_poolname
, zc
->zc_name
, len
);
6062 if (vec
->zvec_func
!= NULL
) {
6066 nvlist_t
*lognv
= NULL
;
6068 ASSERT(vec
->zvec_legacy_func
== NULL
);
6071 * Add the innvl to the lognv before calling the func,
6072 * in case the func changes the innvl.
6074 if (vec
->zvec_allow_log
) {
6075 lognv
= fnvlist_alloc();
6076 fnvlist_add_string(lognv
, ZPOOL_HIST_IOCTL
,
6078 if (!nvlist_empty(innvl
)) {
6079 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_INPUT_NVL
,
6084 outnvl
= fnvlist_alloc();
6085 error
= vec
->zvec_func(zc
->zc_name
, innvl
, outnvl
);
6088 * Some commands can partially execute, modfiy state, and still
6089 * return an error. In these cases, attempt to record what
6093 (cmd
== ZFS_IOC_CHANNEL_PROGRAM
&& error
!= EINVAL
)) &&
6094 vec
->zvec_allow_log
&&
6095 spa_open(zc
->zc_name
, &spa
, FTAG
) == 0) {
6096 if (!nvlist_empty(outnvl
)) {
6097 fnvlist_add_nvlist(lognv
, ZPOOL_HIST_OUTPUT_NVL
,
6101 fnvlist_add_int64(lognv
, ZPOOL_HIST_ERRNO
,
6104 (void) spa_history_log_nvl(spa
, lognv
);
6105 spa_close(spa
, FTAG
);
6107 fnvlist_free(lognv
);
6109 if (!nvlist_empty(outnvl
) || zc
->zc_nvlist_dst_size
!= 0) {
6111 if (vec
->zvec_smush_outnvlist
) {
6112 smusherror
= nvlist_smush(outnvl
,
6113 zc
->zc_nvlist_dst_size
);
6115 if (smusherror
== 0)
6116 puterror
= put_nvlist(zc
, outnvl
);
6122 nvlist_free(outnvl
);
6124 error
= vec
->zvec_legacy_func(zc
);
6129 rc
= ddi_copyout(zc
, (void *)arg
, sizeof (zfs_cmd_t
), flag
);
6130 if (error
== 0 && rc
!= 0)
6131 error
= SET_ERROR(EFAULT
);
6132 if (error
== 0 && vec
->zvec_allow_log
) {
6133 char *s
= tsd_get(zfs_allow_log_key
);
6136 (void) tsd_set(zfs_allow_log_key
, saved_poolname
);
6138 if (saved_poolname
!= NULL
)
6139 strfree(saved_poolname
);
6142 kmem_free(zc
, sizeof (zfs_cmd_t
));
6147 zfs_attach(dev_info_t
*dip
, ddi_attach_cmd_t cmd
)
6149 if (cmd
!= DDI_ATTACH
)
6150 return (DDI_FAILURE
);
6152 if (ddi_create_minor_node(dip
, "zfs", S_IFCHR
, 0,
6153 DDI_PSEUDO
, 0) == DDI_FAILURE
)
6154 return (DDI_FAILURE
);
6158 ddi_report_dev(dip
);
6160 return (DDI_SUCCESS
);
6164 zfs_detach(dev_info_t
*dip
, ddi_detach_cmd_t cmd
)
6166 if (spa_busy() || zfs_busy() || zvol_busy())
6167 return (DDI_FAILURE
);
6169 if (cmd
!= DDI_DETACH
)
6170 return (DDI_FAILURE
);
6174 ddi_prop_remove_all(dip
);
6175 ddi_remove_minor_node(dip
, NULL
);
6177 return (DDI_SUCCESS
);
6182 zfs_info(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
6185 case DDI_INFO_DEVT2DEVINFO
:
6187 return (DDI_SUCCESS
);
6189 case DDI_INFO_DEVT2INSTANCE
:
6191 return (DDI_SUCCESS
);
6194 return (DDI_FAILURE
);
6198 * OK, so this is a little weird.
6200 * /dev/zfs is the control node, i.e. minor 0.
6201 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
6203 * /dev/zfs has basically nothing to do except serve up ioctls,
6204 * so most of the standard driver entry points are in zvol.c.
6206 static struct cb_ops zfs_cb_ops
= {
6207 zfsdev_open
, /* open */
6208 zfsdev_close
, /* close */
6209 zvol_strategy
, /* strategy */
6211 zvol_dump
, /* dump */
6212 zvol_read
, /* read */
6213 zvol_write
, /* write */
6214 zfsdev_ioctl
, /* ioctl */
6218 nochpoll
, /* poll */
6219 ddi_prop_op
, /* prop_op */
6220 NULL
, /* streamtab */
6221 D_NEW
| D_MP
| D_64BIT
, /* Driver compatibility flag */
6222 CB_REV
, /* version */
6223 nodev
, /* async read */
6224 nodev
, /* async write */
6227 static struct dev_ops zfs_dev_ops
= {
6228 DEVO_REV
, /* version */
6230 zfs_info
, /* info */
6231 nulldev
, /* identify */
6232 nulldev
, /* probe */
6233 zfs_attach
, /* attach */
6234 zfs_detach
, /* detach */
6236 &zfs_cb_ops
, /* driver operations */
6237 NULL
, /* no bus operations */
6239 ddi_quiesce_not_needed
, /* quiesce */
6242 static struct modldrv zfs_modldrv
= {
6248 static struct modlinkage modlinkage
= {
6250 (void *)&zfs_modlfs
,
6251 (void *)&zfs_modldrv
,
6256 zfs_allow_log_destroy(void *arg
)
6258 char *poolname
= arg
;
6267 spa_init(FREAD
| FWRITE
);
6272 if ((error
= mod_install(&modlinkage
)) != 0) {
6279 tsd_create(&zfs_fsyncer_key
, NULL
);
6280 tsd_create(&rrw_tsd_key
, rrw_tsd_destroy
);
6281 tsd_create(&zfs_allow_log_key
, zfs_allow_log_destroy
);
6283 error
= ldi_ident_from_mod(&modlinkage
, &zfs_li
);
6285 mutex_init(&zfs_share_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
6295 if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled
)
6296 return (SET_ERROR(EBUSY
));
6298 if ((error
= mod_remove(&modlinkage
)) != 0)
6304 if (zfs_nfsshare_inited
)
6305 (void) ddi_modclose(nfs_mod
);
6306 if (zfs_smbshare_inited
)
6307 (void) ddi_modclose(smbsrv_mod
);
6308 if (zfs_nfsshare_inited
|| zfs_smbshare_inited
)
6309 (void) ddi_modclose(sharefs_mod
);
6311 tsd_destroy(&zfs_fsyncer_key
);
6312 ldi_ident_release(zfs_li
);
6314 mutex_destroy(&zfs_share_lock
);
6320 _info(struct modinfo
*modinfop
)
6322 return (mod_info(&modlinkage
, modinfop
));