fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * Common Development and Distribution License (the "License").
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
1df56ada43861dec046a93e1643fec1c4e7b2ed5Martin Matuska * Portions Copyright 2011 Martin Matuska
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
752fd8dabccac68d6d09f82f3bf3561e055e400bJosef 'Jeff' Sipek * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
45b1747515a17db45e8971501ee84a26bdff37b2Alex Wilson * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
6de9bb5603e65b16816b7ab29e39bac820e2da2bMatthew Ahrens * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
a6f561b4aee75d0d028e7b36b151c8ed8a86bc76Sašo Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
c8811bd3e2427dddbac6c05a59cfe117d8fea370Toomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com>
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * ZFS ioctls.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * There are two ways that we handle ioctls: the legacy way where almost
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * all of the logic is in the ioctl callback, and the new way where most
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * of the marshalling is handled in the common entry point, zfsdev_ioctl().
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Non-legacy ioctls should be registered by calling
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_ioctl_register() from zfs_ioctl_init(). The ioctl is invoked
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * from userland by lzc_ioctl().
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The registration arguments are as follows:
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * const char *name
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The name of the ioctl. This is used for history logging. If the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * ioctl returns successfully (the callback returns 0), and allow_log
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * is true, then a history log entry will be recorded with the input &
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * output nvlists. The log entry can be printed with "zpool history -i".
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_ioc_t ioc
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The ioctl request number, which userland will pass to ioctl(2).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The ioctl numbers can change from release to release, because
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * the caller (libzfs) must be matched to the kernel.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_secpolicy_func_t *secpolicy
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * This function will be called before the zfs_ioc_func_t, to
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * determine if this operation is permitted. It should return EPERM
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * on failure, and 0 on success. Checks include determining if the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * dataset is visible in this zone, and if the user has either all
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs privileges in the zone (SYS_MOUNT), or has been granted permission
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * to do this operation on this dataset with "zfs allow".
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_ioc_namecheck_t namecheck
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * This specifies what to expect in the zfs_cmd_t:zc_name -- a pool
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * name, a dataset name, or nothing. If the name is not well-formed,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * the ioctl will fail and the callback will not be called.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Therefore, the callback can assume that the name is well-formed
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (e.g. is null-terminated, doesn't have more than one '@' character,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * doesn't have invalid characters).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_ioc_poolcheck_t pool_check
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * This specifies requirements on the pool state. If the pool does
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * not meet them (is suspended or is readonly), the ioctl will fail
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * and the callback will not be called. If any checks are specified
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (i.e. it is not POOL_CHECK_NONE), namecheck must not be NO_NAME.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * POOL_CHECK_READONLY).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * boolean_t smush_outnvlist
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If smush_outnvlist is true, then the output is presumed to be a
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * list of errors, and it will be "smushed" down to fit into the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * caller's buffer, by removing some entries and replacing them with a
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * single "N_MORE_ERRORS" entry indicating how many were removed. See
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * nvlist_smush() for details. If smush_outnvlist is false, and the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * outnvlist does not fit into the userland-provided buffer, then the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * ioctl will fail with ENOMEM.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_ioc_func_t *func
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The callback function that will perform the operation.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The callback should return 0 on success, or an error number on
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * failure. If the function fails, the userland ioctl will return -1,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * and errno will be set to the callback's return value. The callback
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * will be called with the following arguments:
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * const char *name
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The name of the pool or dataset to operate on, from
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_cmd_t:zc_name. The 'namecheck' argument specifies the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * expected type (pool, dataset, or none).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * nvlist_t *innvl
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The input nvlist, deserialized from zfs_cmd_t:zc_nvlist_src. Or
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * NULL if no input nvlist was provided. Changes to this nvlist are
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * ignored. If the input nvlist could not be deserialized, the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * ioctl will fail and the callback will not be called.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * nvlist_t *outnvl
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The output nvlist, initially empty. The callback can fill it in,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * and it will be returned to userland by serializing it into
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_cmd_t:zc_nvlist_dst. If it is non-empty, and serialization
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * fails (e.g. because the caller didn't supply a large enough
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * buffer), then the overall ioctl will fail. See the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * 'smush_nvlist' argument above for additional behaviors.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * There are two typical uses of the output nvlist:
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - To return state, e.g. property values. In this case,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * smush_outnvlist should be false. If the buffer was not large
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * enough, the caller will reallocate a larger buffer and try
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * the ioctl again.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - To return multiple errors from an ioctl which makes on-disk
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * changes. In this case, smush_outnvlist should be true.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Ioctls which make on-disk modifications should generally not
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * use the outnvl if they succeed, because the caller can not
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * distinguish between the operation failing, and
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * deserialization failing.
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void zfs_init(void);
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void zfs_fini(void);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenstypedef int zfs_ioc_legacy_func_t(zfs_cmd_t *);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenstypedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenstypedef int zfs_secpolicy_func_t(zfs_cmd_t *, nvlist_t *, cred_t *);
54d692b75b7a6f90ce7787309da5451f7458e66aGeorge Wilsontypedef enum {
f9af39bacaaa0f9dda3b75ff6858b9f3988a39afGeorge Wilsontypedef enum {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens/* This array is indexed by zfs_userquota_prop_t */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensstatic int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonstatic int zfs_check_settable(const char *name, nvpair_t *property,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonstatic int zfs_check_clearable(char *dataset, nvlist_t *props,
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhstatic int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrensint zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t *);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrensstatic int get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp);
2acef22db7808606888f8f92715629ff3ba555b9Matthew Ahrensstatic int zfs_prop_activate_feature(spa_t *spa, spa_feature_t feature);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
fa9e4066f08beec538e775443c5be79dd423fcabahrens__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Get rid of annoying "../common/" prefix to filename.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * To get this data, use the zfs-dprintf probe as so:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dtrace -q -n 'zfs-dprintf \
fa9e4066f08beec538e775443c5be79dd423fcabahrens * /stringof(arg0) == "dbuf.c"/ \
fa9e4066f08beec538e775443c5be79dd423fcabahrens * {printf("%s: %s", stringof(arg1), stringof(arg3))}'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * arg0 = file name
fa9e4066f08beec538e775443c5be79dd423fcabahrens * arg1 = function name
fa9e4066f08beec538e775443c5be79dd423fcabahrens * arg2 = line number
fa9e4066f08beec538e775443c5be79dd423fcabahrens * arg3 = message
fa9e4066f08beec538e775443c5be79dd423fcabahrens char *, newfile, char *, func, int, line, char *, buf);
228975cc44c2290cc190960e5894ac6ce0863855ekstatic char *
15e6edf145a9c2bb0e0272cf8debe823bb97529bgw * Check to see if the named dataset is currently defined as bootable
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick ret = (dmu_objset_id(os) == spa_bootfs(dmu_objset_spa(os)));
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Return non-zero if the spa version is less than requested version.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
745cd3c5371d020efae7a911c58c526aa1fd0dbamaybee * Return TRUE if the ZPL version is less than requested version.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens /* XXX reading from non-owned objset */
745cd3c5371d020efae7a911c58c526aa1fd0dbamaybee if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
228975cc44c2290cc190960e5894ac6ce0863855ekstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Policy for top-level read operations (list pools). Requires no privileges,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and can be used in the local zone, as there is no associated dataset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_none(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Policy for dataset read operations (list children, get statistics). Requires
fa9e4066f08beec538e775443c5be79dd423fcabahrens * no privileges, but must be visible in the local zone.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_read(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirbyzfs_dozonecheck_impl(const char *dataset, uint64_t zoned, cred_t *cr)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The dataset must be visible by this zone -- check this first
fa9e4066f08beec538e775443c5be79dd423fcabahrens * so they don't see EPERM on something they shouldn't know about.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the fs is zoned, only root can access it from the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * global zone.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we are in a local zone, the 'zoned' property must be set.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* must be writable by this zone */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby return (zfs_dozonecheck_impl(dataset, zoned, cr));
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirbyzfs_dozonecheck_ds(const char *dataset, dsl_dataset_t *ds, cred_t *cr)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (dsl_prop_get_int_ds(ds, "zoned", &zoned))
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby return (zfs_dozonecheck_impl(dataset, zoned, cr));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_secpolicy_write_perms_ds(const char *name, dsl_dataset_t *ds,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (error == 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
25f7d993adbfb3452ac4625b3791670746d35ae3Matthew Ahrens * First do a quick check for root in the global zone, which
25f7d993adbfb3452ac4625b3791670746d35ae3Matthew Ahrens * is allowed to do all write_perms. This ensures that zfs_ioc_*
25f7d993adbfb3452ac4625b3791670746d35ae3Matthew Ahrens * will get to handle nonexistent datasets.
25f7d993adbfb3452ac4625b3791670746d35ae3Matthew Ahrens if (INGLOBALZONE(curproc) && secpolicy_zfs(cr) == 0)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, name, FTAG, &ds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zfs_secpolicy_write_perms_ds(name, ds, perm, cr);
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * Policy for setting the security label property.
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * Returns 0 for success, non-zero for access and other errors.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* First get the existing dataset label. */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* The label must be translatable */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * In a non-global zone, disallow attempts to set a label that
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * doesn't match that of the zone; otherwise no other checks
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * are needed.
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire if (new_default || !blequal(&new_sl, CR_SL(CRED())))
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * For global-zone datasets (i.e., those whose zoned property is
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * "off", verify that the specified new label is valid for the
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * global zone.
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * If the existing dataset label is nondefault, check if the
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * dataset is mounted (label cannot be changed while mounted).
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * Get the zfsvfs; if there isn't one, then the dataset isn't
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * mounted (or isn't a dataset, doesn't exist, ...).
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * Try to own the dataset; abort if there is any error,
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * (e.g., already mounted, in use, or other error).
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* dataset currently has a default label */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Check permissions for special properties.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Disallow setting of 'zoned' from within a local zone.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Unprivileged users are allowed to modify the
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * limit on things *under* (ie. contained by)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * the thing they own.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (dsl_prop_get_integer(dsname, "zoned", &zoned,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (!zoned || strlen(dsname) <= strlen(setpoint))
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (nvpair_value_string(propval, &strval) == 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zfs_set_slabel_policy(dsname, strval, CRED());
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (zfs_secpolicy_write_perms(dsname, zfs_prop_to_name(prop), cr));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_set_fsacl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * permission to set permissions will be evaluated later in
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * dsl_deleg_can_allow()
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_rollback(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_send(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * Generate the current snapshot name from the given objsetid, then
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * use that name for the secpolicy/zone checks.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &ds);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby error = zfs_secpolicy_write_perms_ds(zc->zc_name, ds,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_send_new(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (zfs_secpolicy_write_perms(zc->zc_name,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_deleg_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright /* Now make sure mntpnt and dataset are ZFS */
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (zfs_secpolicy_deleg_share(zc, innvl, cr));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (zfs_secpolicy_deleg_share(zc, innvl, cr));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_get_parent(const char *datasetname, char *parent, int parentsize)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove the @bla or /bla from the end of the name to get the parent.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_destroy(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
cbf6f6aa3573519d92d495af2546021be3443b57William Gorrell * Destroying snapshots with delegated permissions requires
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * descendant mount and destroy permissions.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens error = zfs_secpolicy_destroy_perms(nvpair_name(pair), cr);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Ignore any snapshots that don't exist (we consider
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * them "already destroyed"). Remove the name from the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * nvl here in case the snapshot is created between
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * now and when we try to destroy it (in which case
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * we don't want to destroy it since we haven't
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * checked for permission).
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks sizeof (parentname))) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_rename(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_promote(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &clone);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (error == 0) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(dd)->dd_origin_obj, FTAG, &origin);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zfs_secpolicy_write_perms_ds(zc->zc_name, clone,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zfs_secpolicy_write_perms_ds(parentname, origin,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_recv(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Check for permission to create each snapshot in the nvlist.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = zfs_secpolicy_snapshot_perms(name, cr);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Check for permission to create each snapshot in the nvlist.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens/* ARGSUSED */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrenszfs_secpolicy_bookmark(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens/* ARGSUSED */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrenszfs_secpolicy_destroy_bookmarks(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Ignore any filesystems that don't exist (we consider
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * their bookmarks "already destroyed"). Remove
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * the name from the nvl here in case the filesystem
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * is created between now and when we try to destroy
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * the bookmark (in which case we don't want to
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * destroy it since we haven't checked for permission).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_log_history(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Even root must have a proper TSD so that we know what pool
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_create_clone(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks sizeof (parentname))) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_string(innvl, "origin", &origin) == 0 &&
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (zfs_secpolicy_write_perms(parentname,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Policy for pool operations - create/destroy pools, add vdevs, etc. Requires
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SYS_CONFIG privilege, which is not available in a local zone.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_config(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * Policy for object to name lookups.
99d5e173470cf967aa87653364ed614299e7b511Tim Haley/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_diff(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
99d5e173470cf967aa87653364ed614299e7b511Tim Haley if ((error = secpolicy_sys_config(cr, B_FALSE)) == 0)
99d5e173470cf967aa87653364ed614299e7b511Tim Haley error = zfs_secpolicy_write_perms(zc->zc_name, ZFS_DELEG_PERM_DIFF, cr);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Policy for fault injection. Requires all privileges.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_inject(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_inherit_prop(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (zfs_secpolicy_setprop(zc->zc_name, prop,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_userspace_one(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * They are asking about a posix uid/gid. If it's
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * themself, allow it.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens return (zfs_secpolicy_write_perms(zc->zc_name,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_userspace_many(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens return (zfs_secpolicy_write_perms(zc->zc_name,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_hold(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = nvlist_lookup_nvlist(innvl, "holds", &holds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_fsname(nvpair_name(pair), fsname);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_release(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (pair = nvlist_next_nvpair(innvl, NULL); pair != NULL;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_fsname(nvpair_name(pair), fsname);
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * Policy for allowing temporary snapshots to be taken or released
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_secpolicy_tmp_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * A temporary snapshot is the same as a snapshot,
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * hold, destroy and release all rolled into one.
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * Delegated diff alone is sufficient that we allow this.
99d5e173470cf967aa87653364ed614299e7b511Tim Haley if ((error = zfs_secpolicy_write_perms(zc->zc_name,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = zfs_secpolicy_snapshot_perms(zc->zc_name, cr);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = zfs_secpolicy_release(zc, innvl, cr);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = zfs_secpolicy_destroy(zc, innvl, cr);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns the nvlist as specified by the user in the zfs_cmd_t.
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylorget_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Read in and unpack the user-supplied nvlist.
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Reduce the size of this nvlist until it can be serialized in 'max' bytes.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Entries will be removed from the end of the nvlist, and one int32 entry
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * named "N_MORE_ERRORS" will be added indicating how many entries were
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, 0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens more_errors = nvlist_prev_nvpair(errors, NULL);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, n);
6e27f86863a47869e7b2514d7445d3ea6fc6cf4aSam Falkner if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * case its z_vfs will be NULL, and it will be opened as the owner.
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * which prevents all vnode ops from running.
1412a1a223b7a94990edf5114c108b0a29c3f881Mark Shellenbaumzfsvfs_hold(const char *name, void *tag, zfsvfs_t **zfvp, boolean_t writer)
c9030f6c93613fe30ee0c16f92b96da7816ac052Alexander Motin rrm_enter(&(*zfvp)->z_teardown_lock, (writer) ? RW_WRITER :
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * XXX we could probably try again, since the unmounting
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * thread should be just about to disassociate the
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * objset from the zfsvfs.
990b4856d0eaada6f8140335733a1b1771ed2746lling if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if (error != 0) {
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = spa_create(zc->zc_name, config, props, zplprops);
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * Set the remaining root properties
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson error = spa_import(zc->zc_name, config, props, zc->zc_cookie);
394ab0cbe9de0b3be5bf232d9224a9d050999ae5George Wilson error = spa_export(zc->zc_name, NULL, force, hardforce);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * zc_name name of the pool
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * zc_cookie real errno
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * zc_nvlist_dst config nvlist
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * zc_nvlist_dst_size size of config nvlist
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * The config may be present even if 'error' is non-zero.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * In this case we return success, and preserve the real errno
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * in 'zc_cookie'.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Try to import the given pool, returning pool stats as appropriate so that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * user land knows which devices are available and overall pool health.
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * zc_name name of the pool
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * zc_cookie scan func (pool_scan_func_t)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (error == 0) {
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden !SPA_VERSION_IS_SUPPORTED(zc->zc_cookie)) {
06eeb2ad640ce72d394ac521094bed7681044408ek if ((error = spa_history_get(spa, &zc->zc_history_offset,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value));
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens * zc_name name of filesystem
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens * zc_obj object to find
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens * zc_value name of object
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens /* XXX reading from objset not owned */
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_name name of filesystem
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_obj object to find
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_stat stats on object
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_value path to object
99d5e173470cf967aa87653364ed614299e7b511Tim Haley /* XXX reading from objset not owned */
99d5e173470cf967aa87653364ed614299e7b511Tim Haley if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
99d5e173470cf967aa87653364ed614299e7b511Tim Haley error = zfs_obj_to_stats(os, zc->zc_obj, &zc->zc_stat, zc->zc_value,
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
b1b8ab34de515a5e83206da22c3d7e563241b021lling * A root pool with concatenated devices is not supported.
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw * Thus, can not add a device to a root pool.
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw * Intent log device can not be added to a rootpool because
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw * during mountroot, zil is replayed, a seperated log device
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw * can not be accessed during the mountroot time.
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw * l2cache and spare devices are ok to be added to a rootpool.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (spa_bootfs(spa) != 0 && nl2cache == 0 && nspares == 0) {
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan if (error == 0) {
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * zc_name name of the pool
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * zc_nvlist_conf nvlist of devices to remove
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * zc_cookie to stop the remove?
99653d4ee642c6528e88224f12409a5f23060994eschrock error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock error = vdev_degrade(spa, zc->zc_guid, zc->zc_obj);
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante boolean_t exp = !!(zc->zc_cookie & ZPOOL_EXPORT_AFTER_SPLIT);
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante error = spa_vdev_split_mirror(spa, zc->zc_string, config, props, exp);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirbyzfs_ioc_objset_stats_impl(zfs_cmd_t *zc, objset_t *os)
bd00f61bf62a14e7e8914ca126c52af5c38e94e1rm * NB: zvol_get_stats() will read the objset contents,
432f72fd2958c0d1ecc680b0573d8f65a22de385ahrens * which we aren't supposed to do with a
745cd3c5371d020efae7a911c58c526aa1fd0dbamaybee * DS_MODE_USER hold, because it could be
432f72fd2958c0d1ecc680b0573d8f65a22de385ahrens * inconsistent. So this is a bit of a workaround...
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens * XXX reading with out owning
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_name name of filesystem
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_nvlist_dst_size size of buffer for property nvlist
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_objset_stats stats
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_nvlist_dst property nvlist
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_nvlist_dst_size size of property nvlist
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_objset_hold(zc->zc_name, FTAG, &os);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_name name of filesystem
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_nvlist_dst_size size of buffer for property nvlist
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_nvlist_dst received property nvlist
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_nvlist_dst_size size of received property nvlist
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Gets received properties (distinct from local properties on or after
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * local property values.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Without this check, we would return local property values if the
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * caller has not already received properties on or after
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * SPA_VERSION_RECVD_PROPS.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (error = dsl_prop_get_received(zc->zc_name, &nv)) == 0) {
de8267e0f723ed2c38ea9def92d465f69a300f56timhnvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zfs_get_zplprop() will either find a value or give us
de8267e0f723ed2c38ea9def92d465f69a300f56timh * the default value (if there is one).
de8267e0f723ed2c38ea9def92d465f69a300f56timh VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
de8267e0f723ed2c38ea9def92d465f69a300f56timh return (0);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_nvlist_dst_size size of buffer for zpl property nvlist
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_nvlist_dst zpl property nvlist
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_nvlist_dst_size size of zpl property nvlist
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens /* XXX reading without owning */
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if (err = dmu_objset_hold(zc->zc_name, FTAG, &os))
de8267e0f723ed2c38ea9def92d465f69a300f56timh * NB: nvl_add_zplprop() will read the objset contents,
745cd3c5371d020efae7a911c58c526aa1fd0dbamaybee * which we aren't supposed to do with a DS_MODE_USER
745cd3c5371d020efae7a911c58c526aa1fd0dbamaybee * hold, because it could be inconsistent.
de8267e0f723ed2c38ea9def92d465f69a300f56timh VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
de8267e0f723ed2c38ea9def92d465f69a300f56timh if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
de8267e0f723ed2c38ea9def92d465f69a300f56timh (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
de8267e0f723ed2c38ea9def92d465f69a300f56timh (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Skip over datasets that are not visible in this zone,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * internal datasets (which have a $ in their name), and
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * temporary datasets (which have a % in their name).
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_name name of filesystem
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_cookie zap cursor
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_nvlist_dst_size size of buffer for property nvlist
de8267e0f723ed2c38ea9def92d465f69a300f56timh * outputs:
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_name name of next filesystem
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_cookie zap cursor
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_objset_stats stats
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_nvlist_dst property nvlist
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zc_nvlist_dst_size size of property nvlist
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if (error = dmu_objset_hold(zc->zc_name, FTAG, &os)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens } while (error == 0 && dataset_name_hidden(zc->zc_name));
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor * If it's an internal dataset (ie. with a '$' in its name),
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor * don't try to get stats for it, otherwise we'll return ENOENT.
620252bccdfe3034779d8a7711db71205d45c949Chris Kirby if (error == 0 && strchr(zc->zc_name, '$') == NULL) {
87e5029a3226958edab1512d6182bc74d8d80c9aahrens error = zfs_ioc_objset_stats(zc); /* fill in the stats */
620252bccdfe3034779d8a7711db71205d45c949Chris Kirby /* We lost a race with destroy, get the next one. */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_cookie zap cursor
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_dst_size size of buffer for property nvlist
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska * zc_simple when set, only name is requested
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of next snapshot
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_objset_stats stats
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_dst property nvlist
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_dst_size size of property nvlist
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens error = dmu_objset_hold(zc->zc_name, FTAG, &os);
b81d61a68b235e0529ebadc18e14d9d1dd52a258lling * A dataset name of maximum length cannot have any snapshots,
b81d61a68b235e0529ebadc18e14d9d1dd52a258lling * so exit immediately.
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >=
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby zc->zc_name + strlen(zc->zc_name), &zc->zc_obj, &zc->zc_cookie,
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby error = dsl_dataset_hold_obj(dp, zc->zc_obj, FTAG, &ds);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* if we failed, undo the @ that we tacked on to zc_name */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
eeb850025028edf902b22785c950c98e0f33fb88Tim Haley * A correctly constructed propname is encoded as
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * userquota@<rid>-<domain>.
eeb850025028edf902b22785c950c98e0f33fb88Tim Haley nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
1412a1a223b7a94990edf5114c108b0a29c3f881Mark Shellenbaum err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_FALSE);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zfs_set_userquota(zfsvfs, type, domain, rid, quota);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * If the named property is one that has a special function to set its value,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * return 0 on success and a positive error code on failure; otherwise if it is
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * not one of the special properties handled by this function, return -1.
eeb850025028edf902b22785c950c98e0f33fb88Tim Haley * XXX: It would be better for callers of the property interface if we handled
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * these special cases in dsl_prop.c (in the dsl layer).
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_prop_set_special(const char *dsname, zprop_source_t source,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(0 == nvpair_value_uint64(pair, &intval));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = dsl_dir_set_quota(dsname, source, intval);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_set_refquota(dsname, source, intval);
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek /* clearing the limit, just do it */
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Set err to -1 to force the zfs_set_prop_nvlist code down the
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * default path to set the value in the nvlist.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = dsl_dir_set_reservation(dsname, source, intval);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_set_refreservation(dsname, source, intval);
1412a1a223b7a94990edf5114c108b0a29c3f881Mark Shellenbaum if ((err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_TRUE)) != 0)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
b16da2e29e074fb6eaeadc4fd7d17ae7340ba240George Wilson zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * This function is best effort. If it fails to set any of the given properties,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * it continues to set as many as it can and returns the last error
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * encountered. If the caller provides a non-NULL errlist, it will be filled in
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * with the list of names of all the properties that failed along with the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * corresponding error numbers.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If every property is set successfully, zero is returned and errlist is not
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* decode the property value */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* Validate value type */
eeb850025028edf902b22785c950c98e0f33fb88Tim Haley } else if (err == 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (nvpair_type(propval) == DATA_TYPE_STRING) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson } else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
e7437265dc2a4920c197ed4337665539d358b22cahrens "unknown property type");
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* Validate permissions */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zfs_check_settable(dsname, pair, CRED());
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zfs_prop_set_special(dsname, source, pair);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * For better performance we build up a list of
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * properties to set in a single transaction.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * This may be a spurious error caused by
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * receiving quota and reservation out of order.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Try again in a second pass.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (nvl != retrynvl && !nvlist_empty(retrynvl)) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson dsl_props_set(dsname, source, genericnvl) != 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * If this fails, we still want to set as many properties as we
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * can, so try setting them individually.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (nvpair_type(propval) == DATA_TYPE_STRING) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_prop_set_int(dsname, propname, source,
ea2f5b9e5bf4966630882d6d681a94768aea1d75Matthew Ahrens * Check that all the properties are valid user properties.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_check_userprops(const char *fsname, nvlist_t *nvl)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
ea2f5b9e5bf4966630882d6d681a94768aea1d75Matthew Ahrens if (error = zfs_secpolicy_write_perms(fsname,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (strlen(fnvpair_value_string(pair)) >= ZAP_MAXVALUELEN)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonprops_skip(nvlist_t *props, nvlist_t *skipped, nvlist_t **newprops)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_alloc(newprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson while ((pair = nvlist_next_nvpair(props, pair)) != NULL) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_add_nvpair(*newprops, pair) == 0);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensclear_received_props(const char *dsname, nvlist_t *props,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Acts on local properties until the dataset has received
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * properties at least once on or after SPA_VERSION_RECVD_PROPS.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (dsl_prop_get_hasrecvd(dsname) ? ZPROP_SRC_RECEIVED : 0));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = zfs_set_prop_nvlist(dsname, flags, cleared_props, NULL);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
5c0b6a79c494b543020a5d970d3f10597234672cRich Morris * zc_value name of property to set
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_src{_size} nvlist of properties to apply
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_cookie received properties flag
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_nvlist_dst{_size} error for each unapplied received property
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson zprop_source_t source = (received ? ZPROP_SRC_RECEIVED :
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (dsl_prop_get_received(zc->zc_name, &origprops) == 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zfs_set_prop_nvlist(zc->zc_name, source, nvl, errors);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (zc->zc_nvlist_dst != NULL && errors != NULL) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_value name of property to inherit
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_cookie revert to received value if TRUE
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * outputs: none
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson ? ZPROP_SRC_NONE /* revert to received value, if any */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson : ZPROP_SRC_INHERITED); /* explicitly inherit */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zfs_prop_set_special() expects properties in the form of an
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * nvpair with type info.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(0 == nvlist_add_string(dummy, propname, ""));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zfs_prop_set_special(zc->zc_name, source, pair);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (err); /* special property already handled */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Only check this in the non-received case. We want to allow
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * 'inherit -S' to revert non-inheritable properties like quota
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * and reservation to the received or default values even though
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * they are not considered inheritable.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* property name has been validated by zfs_secpolicy_inherit_prop() */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_prop_inherit(zc->zc_name, zc->zc_value, source));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
379c004d1f26b343f034bba8a350290691d00d38Eric Schrock * If the only property is the configfile, then just do a spa_lookup()
379c004d1f26b343f034bba8a350290691d00d38Eric Schrock * to handle the faulted case.
379c004d1f26b343f034bba8a350290691d00d38Eric Schrock zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
b1b8ab34de515a5e83206da22c3d7e563241b021lling if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
379c004d1f26b343f034bba8a350290691d00d38Eric Schrock if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
379c004d1f26b343f034bba8a350290691d00d38Eric Schrock * If the pool is faulted, there may be properties we can still
379c004d1f26b343f034bba8a350290691d00d38Eric Schrock * get (such as altroot and cachefile), so attempt to get them
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_src{_size} nvlist of delegated permissions
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_perm_action allow/unallow flag
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * outputs: none
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Verify nvlist is constructed correctly
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * If we don't have PRIV_SYS_MOUNT, then validate
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * that user is allowed to hand out each permission in
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * the nvlist(s)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_src{_size} nvlist of delegated permissions
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Search the vfs list for a specified resource. Returns a pointer to it
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or NULL if no suitable entry is found. The caller of this routine
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is responsible for releasing the returned vfs pointer.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks/* ARGSUSED */
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * os parent objset pointer (NULL if root fs)
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * fuids_ok fuids allowed in this version of the spa?
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * sa_ok SAs allowed in this version of the spa?
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * createprops list of properties requested by creator
de8267e0f723ed2c38ea9def92d465f69a300f56timh * outputs:
de8267e0f723ed2c38ea9def92d465f69a300f56timh * zplprops values for the zplprops we attach to the master node object
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * is_ci true if requested file system will be purely case-insensitive
de8267e0f723ed2c38ea9def92d465f69a300f56timh * Determine the settings for utf8only, normalization and
de8267e0f723ed2c38ea9def92d465f69a300f56timh * casesensitivity. Specific values may have been requested by the
de8267e0f723ed2c38ea9def92d465f69a300f56timh * creator and/or we can inherit values from the parent dataset. If
de8267e0f723ed2c38ea9def92d465f69a300f56timh * the file system is of too early a vintage, a creator can not
de8267e0f723ed2c38ea9def92d465f69a300f56timh * request settings for these properties, even if the requested
de8267e0f723ed2c38ea9def92d465f69a300f56timh * setting is the default value. We don't actually want to create dsl
de8267e0f723ed2c38ea9def92d465f69a300f56timh * properties for these, so remove them from the source nvlist after
de8267e0f723ed2c38ea9def92d465f69a300f56timh * processing.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrenszfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum boolean_t fuids_ok, boolean_t sa_ok, nvlist_t *createprops,
de8267e0f723ed2c38ea9def92d465f69a300f56timh * Pull out creator prop choices, if any.
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * If the zpl version requested is whacky or the file system
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * or pool is version is too "young" to support normalization
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * and the creator tried to set a value for one of the props,
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * error out.
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
de8267e0f723ed2c38ea9def92d465f69a300f56timh (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
de8267e0f723ed2c38ea9def92d465f69a300f56timh * Put the version in the zplprops
de8267e0f723ed2c38ea9def92d465f69a300f56timh VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
de8267e0f723ed2c38ea9def92d465f69a300f56timh * If we're normalizing, names must always be valid UTF-8 strings.
de8267e0f723ed2c38ea9def92d465f69a300f56timh VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
de8267e0f723ed2c38ea9def92d465f69a300f56timh VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhzfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh (void) strlcpy(parentname, dataset, sizeof (parentname));
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if ((error = spa_open(dataset, &spa, FTAG)) != 0)
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh * Open parent object set so we can inherit zplprop values.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if ((error = dmu_objset_hold(parentname, FTAG, &os)) != 0)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, sa_ok, createprops,
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhzfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, sa_ok,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "type" -> dmu_objset_type_t (int32)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (optional) "props" -> { prop -> value }
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * outnvl: propname -> error code (int32)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * We have to have normalization and
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * case-folding flags correct when we do the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * file system creation, so go figure them out
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * It would be nice to do this atomically.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "origin" -> name of origin snapshot
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (optional) "props" -> { prop -> value }
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * outnvl: propname -> error code (int32)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_string(innvl, "origin", &origin_name) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (dataset_namecheck(origin_name, NULL, NULL) != 0)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_objset_clone(fsname, origin_name);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * It would be nice to do this atomically.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = zfs_set_prop_nvlist(fsname, ZPROP_SRC_LOCAL,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "snaps" -> { snapshot1, snapshot2 }
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (optional) "props" -> { prop -> value (string) }
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * outnvl: snapshot -> error code (int32)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) nvlist_lookup_nvlist(innvl, "props", &props);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if ((error = zfs_check_userprops(poolname, props)) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The snap name must contain an @, and the part after it must
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * contain only valid characters.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The snap must be in the specified pool.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (name[poollen] != '/' && name[poollen] != '@'))
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* This must be the only snap of this fs. */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens for (nvpair_t *pair2 = nvlist_next_nvpair(snaps, pair);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens pair2 != NULL; pair2 = nvlist_next_nvpair(snaps, pair2)) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (strncmp(name, nvpair_name(pair2), cp - name + 1)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_snapshot(snaps, props, outnvl);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * innvl: "message" -> string
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The poolname in the ioctl is not set, we get it from the TSD,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * which was set at the end of the last successful ioctl that allows
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * logging. The secpolicy func already checked that it is set.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Only one log ioctl is allowed after each successful ioctl, so
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * we clear the TSD here.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_string(innvl, "message", &message) != 0) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The dp_config_rwlock must not be held when calling this, because the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * unmount may need to write out data.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * This function is best-effort. Callers must deal gracefully if it
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * remains mounted (or is remounted after this call).
fc7a6e3fefc649cb65c8e2a35d194781445008b0Will Andrews * Returns 0 if the argument is not a snapshot, or it is not currently a
fc7a6e3fefc649cb65c8e2a35d194781445008b0Will Andrews * filesystem, or we were able to unmount it. Returns error code otherwise.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(!dsl_pool_config_held(dmu_objset_pool(zfsvfs->z_os)));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Always force the unmount for snapshots.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_unmount_snap_cb(const char *snapname, void *arg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * When a clone is destroyed, its origin may also need to be destroyed,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * in which case it must be unmounted. This routine will do that unmount
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * if necessary.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_destroy_unmount_origin(const char *fsname)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev)) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "snaps" -> { snapshot1, snapshot2 }
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (optional boolean) "defer"
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * outnvl: snapshot -> error code (int32)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens return (dsl_destroy_snapshots_nvl(snaps, defer, outnvl));
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Create bookmarks. Bookmark names are of the form <fs>#<bmark>.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * All bookmarks must be in the same pool.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * bookmark1 -> snapshot1, bookmark2 -> snapshot2
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * outnvl: bookmark -> error code (int32)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens/* ARGSUSED */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrenszfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Verify the snapshot argument.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (nvpair_value_string(pair, &snap_name) != 0)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens /* Verify that the keys (bookmarks) are unique */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens for (nvpair_t *pair2 = nvlist_next_nvpair(innvl, pair);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens pair2 != NULL; pair2 = nvlist_next_nvpair(innvl, pair2)) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (strcmp(nvpair_name(pair), nvpair_name(pair2)) == 0)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * property 1, property 2, ...
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * bookmark name 1 -> { property 1, property 2, ... },
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * bookmark name 2 -> { property 1, property 2, ... }
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrenszfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens return (dsl_get_bookmarks(fsname, innvl, outnvl));
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * bookmark name 1, bookmark name 2
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * outnvl: bookmark -> error code (int32)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrenszfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * The bookmark name must contain an #, and the part after it
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * must contain only valid characters.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * The bookmark must be in the specified pool.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens (name[poollen] != '/' && name[poollen] != '#'))
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of dataset to destroy
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_objset_type type of objset
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby * zc_defer_destroy mark for deferred destroy
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * outputs: none
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens * fsname is name of dataset to rollback (to most recent snapshot)
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens * innvl is not used.
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens * outnvl: "target" -> name of most recent snapshot
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens/* ARGSUSED */
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrenszfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
47f263f4211a47222fcc65b18b0cfa06d33f3c33ek if (error == 0) {
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens error = dsl_dataset_rollback(fsname, zfsvfs, outnvl);
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens error = dsl_dataset_rollback(fsname, NULL, outnvl);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensrecursive_unmount(const char *fsname, void *arg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) snprintf(fullname, sizeof (fullname), "%s@%s", fsname, snapname);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name old name of dataset
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_value new name of dataset
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_cookie recursive flag (only valid for snapshots)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * outputs: none
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* snaps must be in same fs */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (strncmp(zc->zc_name, zc->zc_value, at - zc->zc_name + 1))
a0c1127b147dc6a0372b141deb8c0c2b0195b8eaSteven Hartland error = dsl_dataset_rename_snapshot(zc->zc_name,
a0c1127b147dc6a0372b141deb8c0c2b0195b8eaSteven Hartland at + 1, strchr(zc->zc_value, '@') + 1, recursive);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_dir_rename(zc->zc_name, zc->zc_value));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson boolean_t issnap = (strchr(dsname, '@') != NULL);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA];
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA];
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* USERUSED and GROUPUSED are read-only */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (err = zfs_secpolicy_write_perms(dsname, perm, cr))
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * dsl_prop_get_all_impl() returns properties in this
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Check that this value is valid for this pool version
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * If the user specified gzip compression, make sure
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * the SPA supports it. We ignore any errors here since
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * we'll catch them later.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens if (nvpair_value_uint64(pair, &intval) == 0) {
a6f561b4aee75d0d028e7b36b151c8ed8a86bc76Sašo Kiselkov if ((err = spa_open(dsname, &spa, FTAG)) != 0)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * If this is a bootable dataset then
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * verify that the compression algorithm
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * is supported for booting. We must return
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * something other than ENOTSUP since it
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * implies a downrev pool version.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens /* Record sizes above 128k need the feature to be enabled */
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens if (nvpair_value_uint64(pair, &intval) == 0 &&
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * We don't allow setting the property above 1MB,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * unless the tunable has been changed.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens if ((err = spa_open(dsname, &spa, FTAG)) != 0)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens /* dedup feature version checks */
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens /* check prop value is enabled in features */
971640e6aa954c91b0706543741aa4570299f4d7ilovezfs feature = zio_checksum_to_feature(intval & ZIO_CHECKSUM_MASK);
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens if ((err = spa_open(dsname, &spa, FTAG)) != 0)
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens * Salted checksums are not supported on root pools.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
a6f561b4aee75d0d028e7b36b151c8ed8a86bc76Sašo Kiselkov * Checks for a race condition to make sure we don't increment a feature flag
a6f561b4aee75d0d028e7b36b151c8ed8a86bc76Sašo Kiselkov * multiple times.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_prop_activate_feature_check(void *arg, dmu_tx_t *tx)
a6f561b4aee75d0d028e7b36b151c8ed8a86bc76Sašo Kiselkov * The callback invoked on feature activation in the sync task caused by
a6f561b4aee75d0d028e7b36b151c8ed8a86bc76Sašo Kiselkov * zfs_prop_activate_feature.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_prop_activate_feature_sync(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Activates a feature on a pool in response to a property setting. This
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * creates a new sync task which modifies the pool to reflect the feature
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * as being active.
2acef22db7808606888f8f92715629ff3ba555b9Matthew Ahrenszfs_prop_activate_feature(spa_t *spa, spa_feature_t feature)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* EBUSY here indicates that the feature is already active */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens zfs_prop_activate_feature_check, zfs_prop_activate_feature_sync,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Removes properties from the given props list that fail permission checks
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * needed to clear them and to restore them in case of a receive error. For each
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * property, make sure we have both set and inherit permissions.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Returns the first error encountered if any permission checks fail. If the
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * caller provides a non-NULL errlist, it also gives the complete list of names
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * of all the properties that failed a permission check along with the
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * corresponding error numbers. The caller is responsible for freeing the
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * returned errlist.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * If every property checks out successfully, zero is returned and the list
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * pointed at by errlist is NULL.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_check_clearable(char *dataset, nvlist_t *props, nvlist_t **errlist)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson (void) strcpy(zc->zc_value, nvpair_name(pair));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if ((err = zfs_check_settable(dataset, pair, CRED())) != 0 ||
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (err = zfs_secpolicy_inherit_prop(zc, NULL, CRED())) != 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_remove_nvpair(props, pair) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* dsl_prop_get_all_impl() format */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_string(p1, (char **)&valstr1) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_string(p2, (char **)&valstr2) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_uint64(p1, &intval1) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson VERIFY(nvpair_value_uint64(p2, &intval2) == 0);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Remove properties from props if they are not going to change (as determined
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * by comparison with origprops). Remove them from origprops as well, since we
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * do not need to clear or restore properties that won't change.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonprops_reduce(nvlist_t *props, nvlist_t *origprops)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return; /* all props need to be received */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* don't clear the existing received value */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* don't bother receiving the property */
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * Extract properties that cannot be set PRIOR to the receipt of a dataset.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * For example, refquota cannot be set until after the receipt of a dataset,
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * because in replication streams, an older/earlier snapshot may exceed the
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * refquota. We want to receive the older/earlier snapshot, but setting
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * refquota pre-receipt will set the dsl's ACTUAL quota, which will prevent
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * the older/earlier snapshot from being received (with EDQUOT).
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * The ZFS test "zfs_receive_011_pos" demonstrates such a scenario.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * libzfs will need to be judicious handling errors encountered by props
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * extracted by this function.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald static const zfs_prop_t delayable[] = { ZFS_PROP_REFQUOTA, 0 };
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald VERIFY(nvlist_alloc(&delayprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald for (nvp = nvlist_next_nvpair(props, NULL); nvp != NULL;
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * strcmp() is safe because zfs_prop_to_name() always returns
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * a bounded string.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald for (i = 0; delayable[i] != 0; i++) {
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald if (delayable[i] != 0) {
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald VERIFY(nvlist_add_nvpair(delayprops, nvp) == 0);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of containing filesystem
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_nvlist_src{_size} nvlist of properties to apply
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_value name of snapshot to create
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_string name of clone origin (if DRR_FLAG_CLONE)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_cookie file descriptor to recv from
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_begin_record the BEGIN record of the stream (not byteswapped)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_guid force flag
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby * zc_cleanup_fd cleanup-on-exit file descriptor
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby * zc_action_handle handle for this guid/ds mapping (or zero on first call)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * zc_resumable if data is incomplete assume sender will resume
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_cookie number of bytes read
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_nvlist_dst{_size} error for each unapplied received property
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * zc_obj zprop_errflags_t
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby * zc_action_handle handle for this guid/ds mapping
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson nvlist_t *origprops = NULL; /* existing properties */
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald nvlist_t *delayprops = NULL; /* sent properties applied post-receive */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens &zc->zc_begin_record, force, zc->zc_resumable, origin, &drc);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Set properties before we receive the stream so that they are applied
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * to the new data. Note that we must call dmu_recv_stream() if
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dmu_recv_begin() succeeds.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (spa_version(dsl_dataset_get_spa(drc.drc_ds)) >=
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * If new received properties are supplied, they are to
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * completely replace the existing received properties, so stash
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * away the existing ones.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (dsl_prop_get_received(tofs, &origprops) == 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Don't bother writing a property if its value won't
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * change (and avoid the unnecessary security checks).
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * The first receive after SPA_VERSION_RECVD_PROPS is a
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * special case where we blow away all local properties
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * regardless.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (zfs_check_clearable(tofs, origprops, &errlist) != 0)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby error = dmu_recv_stream(&drc, fp->f_vnode, &off, zc->zc_cleanup_fd,
f4b94bde302dc950da6b4ec29936dd9a7b9d61abMatthew Ahrens /* online recv */
f4b94bde302dc950da6b4ec29936dd9a7b9d61abMatthew Ahrens * If the suspend fails, then the recv_end will
f4b94bde302dc950da6b4ec29936dd9a7b9d61abMatthew Ahrens * likely also fail, and clean up after itself.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald /* Set delayed properties now, after we're done receiving. */
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * Merge delayed props back in with initial props, in case
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * we have to make sure clear_received_props() includes
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * the delayed properties).
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * using ASSERT() will be just like a VERIFY.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald ASSERT(nvlist_merge(props, delayprops, 0) == 0);
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * Now that all props, initial and delayed, are set, report the prop
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * errors to the caller.
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald (nvlist_smush(errors, zc->zc_nvlist_dst_size) != 0 ||
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * Caller made zc->zc_nvlist_dst less than the minimum expected
5878fad70d76d8711f6608c1f80b0447601261c6Dan McDonald * size or supplied an invalid address.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
745cd3c5371d020efae7a911c58c526aa1fd0dbamaybee * On error, restore the original props.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (error != 0 && props != NULL && !drc.drc_newfs) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (clear_received_props(tofs, props, NULL) != 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * We failed to clear the received properties.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Since we may have left a $recvd value on the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * system, we can't clear the $hasrecvd flag.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* We failed to stash the original properties. */
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * dsl_props_set() will not convert RECEIVED to LOCAL on or
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * explictly if we're restoring local properties cleared in the
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * first new-style receive.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * We stashed the original properties but failed to
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * restore them.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of snapshot to send
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_cookie file descriptor to send stream to
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_obj fromorigin flag (mutually exclusive with zc_fromobj)
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_sendobj objsetid of snapshot to send
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby * zc_fromobj objsetid of incremental fromsnap (may be zero)
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * zc_guid if set, estimate size of stream only. zc_cookie is ignored.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * output size in zc_objset_type.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * zc_flags lzc_send_flags
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * zc_objset_type estimated size, if zc_guid is set
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens boolean_t large_block_ok = (zc->zc_flags & 0x2);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(tosnap->ds_dir)->dd_origin_obj;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold_obj(dp, zc->zc_fromobj,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel error = dmu_send_estimate(tosnap, fromsnap, compressok,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel zc->zc_fromobj, embedok, large_block_ok, compressok,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * zc_name name of snapshot on which to report progress
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * zc_cookie file descriptor of send stream
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * zc_cookie number of bytes written in send stream thus far
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &ds);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * Iterate over all the send streams currently active on this dataset.
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * If there's one which matches the specified file descriptor _and_ the
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * stream was started by the current process, return the progress of
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * that stream.
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski for (dsp = list_head(&ds->ds_sendstreams); dsp != NULL;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
b87f3af36bb994656da117319f5129ddfd05ed21perrin * On zpool clear we also fix up missing slogs
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
b87f3af36bb994656da117319f5129ddfd05ed21perrin /* we need to let spa_open/spa_load clear the chains */
468c413a79615e77179e8d98f22a7e513a8135bdTim Haley zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * Resume any suspended I/Os.
d6afdce20f8481c95471dd821bc8ec0dbde66213George Wilson * If a resilver is already in progress then set the
d6afdce20f8481c95471dd821bc8ec0dbde66213George Wilson * spa_scrub_reopen flag to B_TRUE so that we don't restart
d6afdce20f8481c95471dd821bc8ec0dbde66213George Wilson * the scan as a side effect of the reopen. Otherwise, let
d6afdce20f8481c95471dd821bc8ec0dbde66213George Wilson * vdev_open() decided if a resilver is required.
d6afdce20f8481c95471dd821bc8ec0dbde66213George Wilson spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_name name of filesystem
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * zc_value name of origin snapshot
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor * zc_string name of conflicting snapshot, if there is one
0b69c2f001a429251e2d38f25aca860396551214ahrens * We don't need to unmount *all* the origin fs's snapshots, but
0b69c2f001a429251e2d38f25aca860396551214ahrens * it's easier.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Retrieve a single {user|group}{used|quota}@... property.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_name name of filesystem
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_objset_type zfs_userquota_prop_t
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_value domain name (eg. "S-1-234-567-89")
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_cookie property value
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
1412a1a223b7a94990edf5114c108b0a29c3f881Mark Shellenbaum error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs, B_FALSE);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_name name of filesystem
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_cookie zap cursor
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_objset_type zfs_userquota_prop_t
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_nvlist_dst[_size] data buffer (array of zfs_useracct_t)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_cookie zap cursor
1412a1a223b7a94990edf5114c108b0a29c3f881Mark Shellenbaum int error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs, B_FALSE);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens error = zfs_userspace_many(zfsvfs, zc->zc_objset_type, &zc->zc_cookie,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * zc_name name of filesystem
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if (!dmu_objset_userused_enabled(zfsvfs->z_os)) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * If userused is not enabled, it may be because the
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * objset needs to be closed & reopened (to grow the
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * objset_phys_t). Suspend/resume the fs will do that.
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski dmu_objset_refresh_ownership(zfsvfs->z_os,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens error = dmu_objset_userspace_upgrade(zfsvfs->z_os);
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens /* XXX kind of reading contents without owning */
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens error = dmu_objset_hold(zc->zc_name, FTAG, &os);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * We don't want to have a hard dependency
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * against some special symbols in sharefs
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * nfs, and smbsrv. Determine them if needed when
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * the first file system is shared.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Neither sharefs, nfs or smbsrv are unloadable modules.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarksint (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Both NFS and SMB shares also require sharetab support. */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ((znfsexport_fs = (int (*)(void *))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Add or remove share from sharetab
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_name name of containing filesystem
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_obj object # beyond which we want next in-use object #
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_obj next in-use object #
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(os->os_dsl_dataset)->ds_prev_snap_txg);
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_name name of filesystem
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_value prefix name for snapshot
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_cleanup_fd cleanup-on-exit file descriptor for calling process
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zc_value short name of new snapshot
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zfs_onexit_fd_hold(zc->zc_cleanup_fd, &minor);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens snap_name = kmem_asprintf("%s-%016llx", zc->zc_value,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens hold_name = kmem_asprintf("%%%s", zc->zc_value);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_snapshot_tmp(zc->zc_name, snap_name, minor,
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_name name of "to" snapshot
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_value name of "from" snapshot
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * zc_cookie file descriptor to write diff data on
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * dmu_diff_record_t's to the file descriptor
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off);
99d5e173470cf967aa87653364ed614299e7b511Tim Haley if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * Remove all ACL files in shares dir
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright /* Now make sure mntpnt and dataset are ZFS */
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum * Create share dir if its missing.
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &sharedir)) != 0) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * "holds" -> { snapname -> holdname (string), ... }
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (optional) "cleanup_fd" -> fd (int32)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * snapname -> error value (int32)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = nvlist_lookup_nvlist(args, "holds", &holds);
752fd8dabccac68d6d09f82f3bf3561e055e400bJosef 'Jeff' Sipek /* make sure the user didn't pass us any invalid (empty) tags */
752fd8dabccac68d6d09f82f3bf3561e055e400bJosef 'Jeff' Sipek for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
752fd8dabccac68d6d09f82f3bf3561e055e400bJosef 'Jeff' Sipek pair = nvlist_next_nvpair(holds, pair)) {
752fd8dabccac68d6d09f82f3bf3561e055e400bJosef 'Jeff' Sipek error = nvpair_value_string(pair, &htag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (nvlist_lookup_int32(args, "cleanup_fd", &cleanup_fd) == 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zfs_onexit_fd_hold(cleanup_fd, &minor);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_user_hold(holds, minor, errlist);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * innvl is not used.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * holdname -> time added (uint64 seconds since epoch)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_dataset_get_holds(snapname, outnvl));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * snapname -> { holdname, ... }
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * snapname -> error value (int32)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_dataset_user_release(holds, errlist));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * zc_name name of new filesystem or snapshot
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * zc_value full name of old snapshot
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * zc_cookie space in bytes
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * zc_objset_type compressed space in bytes
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * zc_perm_action uncompressed space in bytes
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &new);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, zc->zc_value, FTAG, &old);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens error = dsl_dataset_space_written(old, new, &zc->zc_cookie,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "firstsnap" -> snapshot name
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "used" -> space in bytes
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "compressed" -> compressed space in bytes
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "uncompressed" -> uncompressed space in bytes
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, lastsnap, FTAG, &new);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, firstsnap, FTAG, &old);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = dsl_dataset_space_wouldfree(old, new, &used, &comp, &uncomp);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_uint64(outnvl, "compressed", comp);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_uint64(outnvl, "uncompressed", uncomp);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "fd" -> file descriptor to write stream to (int32)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (optional) "fromsnap" -> full snap name to send an incremental from
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * (optional) "largeblockok" -> (value ignored)
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * indicates that blocks > 128KB are permitted
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * (optional) "embedok" -> (value ignored)
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * presence indicates DRR_WRITE_EMBEDDED records are permitted
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * (optional) "compressok" -> (value ignored)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * presence indicates compressed DRR_WRITE records are permitted
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * (optional) "resume_object" and "resume_offset" -> (uint64)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * if present, resume send stream from specified object and offset.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * outnvl is unused
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens/* ARGSUSED */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = nvlist_lookup_int32(innvl, "fd", &fd);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens largeblockok = nvlist_exists(innvl, "largeblockok");
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) nvlist_lookup_uint64(innvl, "resume_object", &resumeobj);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) nvlist_lookup_uint64(innvl, "resume_offset", &resumeoff);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel error = dmu_send(snapname, fromname, embedok, largeblockok, compressok,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Determine approximately how large a zfs send stream will be -- the number
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * of bytes that will be written to the fd supplied to zfs_ioc_send_new().
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * (optional) "from" -> full snap or bookmark name to send an incremental
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * (optional) "largeblockok" -> (value ignored)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * indicates that blocks > 128KB are permitted
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * (optional) "embedok" -> (value ignored)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * presence indicates DRR_WRITE_EMBEDDED records are permitted
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * (optional) "compressok" -> (value ignored)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * presence indicates compressed DRR_WRITE records are permitted
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "space" -> bytes of space (uint64)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioc_send_space(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* LINTED E_FUNC_SET_NOT_USED */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* LINTED E_FUNC_SET_NOT_USED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, snapname, FTAG, &tosnap);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel largeblockok = nvlist_exists(innvl, "largeblockok");
643da460c8ca583e39ce053081754e24087f84c8Max Grossman error = nvlist_lookup_string(innvl, "from", &fromname);
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * If from is a snapshot, hold it and use the more
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * efficient dmu_send_estimate to estimate send space
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * size using deadlists.
643da460c8ca583e39ce053081754e24087f84c8Max Grossman error = dsl_dataset_hold(dp, fromname, FTAG, &fromsnap);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel error = dmu_send_estimate(tosnap, fromsnap, compressok,
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * If from is a bookmark, fetch the creation TXG of the
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * snapshot it was created from and use that to find
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * blocks that were born after it.
643da460c8ca583e39ce053081754e24087f84c8Max Grossman error = dsl_bookmark_lookup(dp, fromname, tosnap,
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * from is not properly formatted as a snapshot or
643da460c8ca583e39ce053081754e24087f84c8Max Grossman // If estimating the size of a full send, use dmu_send_estimate
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel error = dmu_send_estimate(tosnap, NULL, compressok, &space);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrensstatic zfs_ioc_vec_t zfs_ioc_vec[ZFS_IOC_LAST - ZFS_IOC_FIRST];
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_legacy(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens boolean_t log_history, zfs_ioc_poolcheck_t pool_check)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * See the block comment at the beginning of this file for details on
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * each argument to this function.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_poolcheck_t pool_check, boolean_t smush_outnvlist,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* if we are logging, the name must be valid */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_pool(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_func_t *secpolicy, boolean_t log_history,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ioc, func, secpolicy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_dataset_nolog(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_func_t *secpolicy, zfs_ioc_poolcheck_t pool_check)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ioc, func, secpolicy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_pool_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ioc, func, zfs_secpolicy_config,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens POOL_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_pool_meta(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ioc, func, secpolicy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_dataset_read_secpolicy(zfs_ioc_t ioc,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_legacy_func_t *func, zfs_secpolicy_func_t *secpolicy)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ioc, func, secpolicy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens DATASET_NAME, B_FALSE, POOL_CHECK_SUSPENDED);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_dataset_read(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ioc, func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_ioctl_register_dataset_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ioc, func, secpolicy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens DATASET_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_snapshot, zfs_secpolicy_snapshot, POOL_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_log_history, zfs_secpolicy_log_history, NO_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_space_snaps, zfs_secpolicy_read, DATASET_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_send_new, zfs_secpolicy_send_new, DATASET_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_send_space, zfs_secpolicy_read, DATASET_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_create, zfs_secpolicy_create_clone, DATASET_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens zfs_ioctl_register("release", ZFS_IOC_RELEASE,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
a7027df17fad220a20367b9d1eb251bc6300d203Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_ioc_bookmark, zfs_secpolicy_bookmark, POOL_NAME,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_ioc_get_bookmarks, zfs_secpolicy_read, DATASET_NAME,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_ioc_destroy_bookmarks, zfs_secpolicy_destroy_bookmarks,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* IOCTLS that use the legacy function signature */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_READONLY);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE, zfs_ioc_pool_create,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETPATH,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SETFRU,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SET_PROPS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SPLIT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_REGUID,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_CONFIGS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_meta(ZFS_IOC_POOL_TRYIMPORT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_pool_tryimport, zfs_secpolicy_config);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_FAULT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_meta(ZFS_IOC_CLEAR_FAULT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool_meta(ZFS_IOC_INJECT_LIST_NEXT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_inject_list_next, zfs_secpolicy_inject);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * pool destroy, and export don't log the history as part of
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfsdev_ioctl, but rather zfs_ioc_pool_export
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * does the logging of those commands.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_DESTROY, zfs_ioc_pool_destroy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, B_FALSE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_EXPORT, zfs_ioc_pool_export,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, B_FALSE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_STATS, zfs_ioc_pool_stats,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_PROPS, zfs_ioc_pool_get_props,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_read, B_FALSE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_ERROR_LOG, zfs_ioc_error_log,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_inject, B_FALSE, POOL_CHECK_SUSPENDED);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_DSOBJ_TO_DSNAME,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_diff, B_FALSE, POOL_CHECK_SUSPENDED);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_GET_HISTORY,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, B_FALSE, POOL_CHECK_SUSPENDED);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_IMPORT, zfs_ioc_pool_import,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_CLEAR, zfs_ioc_clear,
22e30981d82a0b6dc89253596ededafae8655e00George Wilson zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_RECVD_PROPS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_NEXT_OBJ,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_GET_FSACL,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_STATS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_OBJSET_ZPLPROPS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_DATASET_LIST_NEXT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_SNAPSHOT_LIST_NEXT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_userspace_one, zfs_secpolicy_userspace_one);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_userspace_many, zfs_secpolicy_userspace_many);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP, zfs_ioc_set_prop,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE, zfs_ioc_promote,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_inherit_prop, zfs_secpolicy_inherit_prop);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL, zfs_ioc_set_fsacl,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE, zfs_ioc_share,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL, zfs_ioc_smb_acl,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zfs_ioc_tmp_snapshot, zfs_secpolicy_tmp_snapshot,
f9af39bacaaa0f9dda3b75ff6858b9f3988a39afGeorge Wilsonpool_status_check(const char *name, zfs_ioc_namecheck_t type,
54d692b75b7a6f90ce7787309da5451f7458e66aGeorge Wilson ASSERT(type == POOL_NAME || type == DATASET_NAME);
f9af39bacaaa0f9dda3b75ff6858b9f3988a39afGeorge Wilson if ((check & POOL_CHECK_SUSPENDED) && spa_suspended(spa))
f9af39bacaaa0f9dda3b75ff6858b9f3988a39afGeorge Wilson else if ((check & POOL_CHECK_READONLY) && !spa_writeable(spa))
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby * Find a free minor number.
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby for (m = last_minor + 1; m != last_minor; m++) {
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby if (ddi_get_soft_state(zfsdev_state, m) == NULL) {
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby if (ddi_soft_state_zalloc(zfsdev_state, minor) != DDI_SUCCESS)
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby zfs_onexit_init((zfs_onexit_t **)&zs->zss_data);
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirbyzfs_ctldev_destroy(zfs_onexit_t *zo, minor_t minor)
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirbyzfsdev_get_soft_state(minor_t minor, enum zfs_soft_state_type which)
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirbyzfsdev_open(dev_t *devp, int flag, int otyp, cred_t *cr)
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby /* This is the control device. Allocate a new minor if requested. */
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirbyzfsdev_close(dev_t dev, int flag, int otyp, cred_t *cr)
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby zfsdev_get_soft_state(minor, ZSST_CTLDEV) == NULL)
91ebeef555ce7f899b6270a3c2df47b51f7ad59aahrens ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Ensure that all pool/dataset names are valid before we pass down to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the lower layers.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* legacy ioctls can modify zc_name */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(saved_poolname, zc->zc_name, len);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Add the innvl to the lognv before calling the func,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * in case the func changes the innvl.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_nvlist(lognv, ZPOOL_HIST_INPUT_NVL,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = vec->zvec_func(zc->zc_name, innvl, outnvl);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_nvlist(lognv, ZPOOL_HIST_OUTPUT_NVL,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (!nvlist_empty(outnvl) || zc->zc_nvlist_dst_size != 0) {
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) tsd_set(zfs_allow_log_key, saved_poolname);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
a0965f35d4137b1f6bb1655ae1cb8fee88dfa66fbonwick *result = (void *)0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * OK, so this is a little weird.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * /dev/zfs is the control node, i.e. minor 0.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * /dev/zfs has basically nothing to do except serve up ioctls,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * so most of the standard driver entry points are in zvol.c.
fa9e4066f08beec538e775443c5be79dd423fcabahrens D_NEW | D_MP | D_64BIT, /* Driver compatibility flag */
fa9e4066f08beec538e775443c5be79dd423fcabahrens 0, /* refcnt */
193974072f41a843678abf5f61979c748687e66bSherry Moore "ZFS storage pool",
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)