libzfs_dataset.c revision 503ad85c168c7992ccc310af845a581cff3c72b5
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * 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
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusantestatic int zvol_create_link_common(libzfs_handle_t *, const char *, int);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensstatic int userquota_propname_decode(const char *propname, boolean_t zoned,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a single type (not a mask of types), return the type in a human
fa9e4066f08beec538e775443c5be79dd423fcabahrens * readable form.
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a path and mask of ZFS types, return a string describing this dataset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is used when we fail to open a dataset and we cannot get an exact type.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We guess what the type would have been based on the path and the mask of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * acceptable types.
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic const char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When given a single type, always report the exact type.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The user is requesting more than one type of dataset. If this is the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * case, consult the path itself. If we're looking for a snapshot, and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a '@' is found, then report it as "snapshot". Otherwise, remove the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * snapshot attribute and try again.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (path_to_str(path, types & ~ZFS_TYPE_SNAPSHOT));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The user has requested either filesystems or volumes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We have no way of knowing a priori what type this would be, so always
fa9e4066f08beec538e775443c5be79dd423fcabahrens * report it as "filesystem" or "volume", our two primitive types.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Validate a ZFS path. This is used even before trying to open the dataset, to
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * provide a more meaningful error message. We call zfs_error_aux() to
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * explain exactly why the name was not valid.
f18faf3f3e5def85fdfff681617d227703ace2adekzfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
99653d4ee642c6528e88224f12409a5f23060994eschrock "name is too long"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "leading slash in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "empty component in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "trailing slash in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "multiple '@' delimiters in name"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "pool doesn't begin with a letter"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "name is reserved"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "reserved disk name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshot delimiter '@' in filesystem name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "missing '@' delimiter in snapshot name"));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (0);
f18faf3f3e5def85fdfff681617d227703ace2adek return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * This function takes the raw DSL properties, and filters out the user-defined
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * properties into a separate nvlist.
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrockprocess_user_props(zfs_handle_t *zhp, nvlist_t *props)
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock if (nvlist_add_nvlist(nvl, nvpair_name(elem), propval) != 0) {
29ab75c9a733dad2978c4860efd954b5625e3467rmzpool_add_handle(zfs_handle_t *zhp, const char *pool_name)
29ab75c9a733dad2978c4860efd954b5625e3467rm if ((zph = zpool_open_canfail(hdl, pool_name)) != NULL) {
29ab75c9a733dad2978c4860efd954b5625e3467rmzpool_find_handle(zfs_handle_t *zhp, const char *pool_name, int len)
29ab75c9a733dad2978c4860efd954b5625e3467rm * Returns a handle to the pool that contains the provided dataset.
29ab75c9a733dad2978c4860efd954b5625e3467rm * If a handle to that pool already exists then that handle is returned.
29ab75c9a733dad2978c4860efd954b5625e3467rm * Otherwise, a new handle is created and added to the list of handles.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Utility function to gather stats (objset and zpl) for the given object.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylorget_stats_ioctl(zfs_handle_t *zhp, zfs_cmd_t *zc)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor (void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor while (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, zc) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock return (-1);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor zhp->zfs_dmustats = zc->zc_objset_stats; /* structure assignment */
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (zcmd_read_dst_nvlist(zhp->zfs_hdl, zc, &allprops) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * XXX Why do we store the user props separately, in addition to
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * storing them in zfs_props?
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock if ((userprops = process_user_props(zhp, allprops)) == NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Refresh the properties currently stored in the handle.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Makes a handle from the given dataset name. Used by zfs_open() and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_iter_* to create child handles on the fly.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylormake_dataset_handle_common(zfs_handle_t *zhp, zfs_cmd_t *zc)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We've managed to open the dataset and gather statistics. Determine
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the high-level type.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylormake_dataset_handle(libzfs_handle_t *hdl, const char *path)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor (void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name));
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (make_dataset_handle_common(zhp, &zc) == -1) {
ebedde844eddf46049b2403f974b50bcba47356eEric Taylormake_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor (void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name));
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (make_dataset_handle_common(zhp, zc) == -1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Opens the given snapshot, filesystem, or volume. The 'types'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * argument is a mask of acceptable types. The function will print an
fa9e4066f08beec538e775443c5be79dd423fcabahrens * appropriate error message and return NULL if it can't be opened.
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_open(libzfs_handle_t *hdl, const char *path, int types)
99653d4ee642c6528e88224f12409a5f23060994eschrock * Validate the name before we even try to open it.
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, path, ZFS_TYPE_DATASET, B_FALSE)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "invalid dataset name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Try to get stats for the dataset, which will tell us if it exists.
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = make_dataset_handle(hdl, path)) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Release a ZFS handle. Nothing to do but free the associated memory.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylortypedef struct mnttab_node {
ebedde844eddf46049b2403f974b50bcba47356eEric Taylorlibzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor rv = strcmp(mtn1->mtn_mt.mnt_special, mtn2->mtn_mt.mnt_special);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_special = zfs_strdup(hdl, entry.mnt_special);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, entry.mnt_mountp);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, entry.mnt_fstype);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, entry.mnt_mntopts);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor while (mtn = avl_destroy_nodes(&hdl->libzfs_mnttab_cache, &cookie)) {
b2634b9c57bbcfa01bb5dec2e196aec32957925fEric Taylorlibzfs_mnttab_cache(libzfs_handle_t *hdl, boolean_t enable)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylorlibzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
b2634b9c57bbcfa01bb5dec2e196aec32957925fEric Taylor if (getmntany(hdl->libzfs_mnttab, entry, &srch) == 0)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn = avl_find(&hdl->libzfs_mnttab_cache, &find, NULL);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylorlibzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylorlibzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL)) {
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (0);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * The choice of reservation property depends on the SPA version.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rmzfs_which_resv_prop(zfs_handle_t *zhp, zfs_prop_t *resv_prop)
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Given an nvlist of properties to set, validates that they are correct, and
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * parses any numeric properties (index, boolean, etc) if they are specified as
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhzfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
990b4856d0eaada6f8140335733a1b1771ed2746lling uint64_t zoned, zfs_handle_t *zhp, const char *errbuf)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Make sure this property is valid and applies to this type.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (prop == ZPROP_INVAL && zfs_prop_user(propname)) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * This is a user property: make sure it's a
990b4856d0eaada6f8140335733a1b1771ed2746lling * string, and that it's less than ZAP_MAXNAMELEN.
990b4856d0eaada6f8140335733a1b1771ed2746lling "property name '%s' is too long"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (nvlist_add_string(ret, propname, strval) != 0) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Currently, only user properties can be modified on
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens "this property can not be modified for snapshots"));
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (prop == ZPROP_INVAL && zfs_prop_userquota(propname)) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (userquota_propname_decode(propname, zoned,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens &uqtype, domain, sizeof (domain), &rid) != 0) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens "'%s' has an invalid user/group name"),
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens "use 'none' to disable "
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens (void) snprintf(newpropname, sizeof (newpropname),
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (nvlist_add_uint64_array(ret, newpropname,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Perform some additional checks for specific properties.
e7437265dc2a4920c197ed4337665539d358b22cahrens "Can not downgrade; already at version %u"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock /* must be power of two within SPA_{MIN,MAX}BLOCKSIZE */
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be power of 2 from %u "
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl "'%s' must be 'on', 'off', or 'type=disk'"),
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm switch (why) {
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm "'%s' must be an absolute path, "
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm "component of '%s' is too long"),
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl /*FALLTHRU*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * For the mountpoint and sharenfs or sharesmb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties, check if it can be set in a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * global/non-global zone based on
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * the zoned property value:
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * global zone non-global zone
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * --------------------------------------------------
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * zoned=on mountpoint (no) mountpoint (yes)
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * sharenfs (no) sharenfs (no)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sharesmb (no) sharesmb (no)
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * zoned=off mountpoint (yes) N/A
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * sharenfs (yes)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sharesmb (yes)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be set on "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "dataset in a non-global zone"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be set in "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If zoned property is 'off', this must be in
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * a global zone. If not, something is wrong.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be set while dataset "
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * At this point, it is legitimate to set the
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * property. Now we want to make sure that the
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * property value is valid if it is sharenfs.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Must be an valid sharing protocol
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * option string so init the libshare
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in order to enable the parser and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * then parse the options. We use the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * control API since we don't care about
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the current configuration and don't
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * want the overhead of loading it
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * until we actually do something.
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * An error occurred so we can't do
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock "'%s' cannot be set: problem "
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock "in share initialization"),
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * There was an error in parsing so
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * deal with it by issuing an error
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * message and leaving after
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * uninitializing the the libshare
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * interface.
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock "'%s' cannot be set to invalid "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * For changes to existing volumes, we have some additional
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * checks to enforce.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' is greater than current "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a multiple of "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume block size (%s)"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be zero"),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If normalization was chosen, but no UTF8 choice was made,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * enforce rejection of non-UTF8 names.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If normalization was chosen, but rejecting non-UTF8 names
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * was explicitly not chosen, it is an error.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "'%s' must be set 'on' if normalization chosen"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If this is an existing volume, and someone is setting the volsize,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * make sure that it matches the reservation, or add it if necessary.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock nvlist_lookup_uint64(ret, zfs_prop_to_name(ZFS_PROP_VOLSIZE),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a property name and value, set the property for the given dataset.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if ((realprops = zfs_valid_proplist(hdl, zhp->zfs_type, nvl,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, errbuf)) == NULL)
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "child dataset with inherited mountpoint is used "
99653d4ee642c6528e88224f12409a5f23060994eschrock "in a non-global zone"));
0068372b94fa8832a6e2897de3239ff2b7b2c6b9Mark J Musante * If the dataset's canmount property is being set to noauto,
0068372b94fa8832a6e2897de3239ff2b7b2c6b9Mark J Musante * then we want to prevent unmounting & remounting it.
0068372b94fa8832a6e2897de3239ff2b7b2c6b9Mark J Musante ZFS_TYPE_DATASET) == 0) && (idx == ZFS_CANMOUNT_NOAUTO));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Execute the corresponding ioctl() to set this property.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * For quotas and reservations, ENOSPC indicates
fa9e4066f08beec538e775443c5be79dd423fcabahrens * something different; setting a quota or reservation
fa9e4066f08beec538e775443c5be79dd423fcabahrens * doesn't use any disk space.
99653d4ee642c6528e88224f12409a5f23060994eschrock "size is less than current used or "
99653d4ee642c6528e88224f12409a5f23060994eschrock "reserved space"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "size is greater than available space"));
9e6eda553d3d6d77b83da5c596c89990d82bd485marks "pool and or dataset must be upgraded to set this "
40feaa914945406e86e193599d115ea71a171d18ahrens "property or value"));
15e6edf145a9c2bb0e0272cf8debe823bb97529bgw "property setting is not allowed on "
15e6edf145a9c2bb0e0272cf8debe823bb97529bgw "bootable datasets"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This platform can't address a volume this big.
99653d4ee642c6528e88224f12409a5f23060994eschrock /* FALLTHROUGH */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Refresh the statistics so the new property value
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is reflected.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a property, inherit the value from the parent dataset.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_prop_inherit(zfs_handle_t *zhp, const char *propname)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "cannot inherit %s for '%s'"), propname, zhp->zfs_name);
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * For user properties, the amount of work we have to do is very
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * small, so just do it here.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "invalid property"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Verify that this property is inheritable.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (zfs_error(hdl, EZFS_PROPREADONLY, errbuf));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (zfs_error(hdl, EZFS_PROPNONINHERIT, errbuf));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if the value applies to this type
bf7c2d400a7b538aed6f356c7107284378a19fa8rm * Normalize the name, to get rid of shorthand abbrevations.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && getzoneid() == GLOBAL_ZONEID &&
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset is used in a non-global zone"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Determine datasets which will be affected by this change, if any.
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "child dataset with inherited mountpoint is used "
99653d4ee642c6528e88224f12409a5f23060994eschrock "in a non-global zone"));
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc)) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Refresh the statistics so the new property is reflected.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * True DSL properties are stored in an nvlist. The following two functions
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * extract them appropriately.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockgetprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
990b4856d0eaada6f8140335733a1b1771ed2746lling verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
990b4856d0eaada6f8140335733a1b1771ed2746lling (void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockstatic char *
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockgetprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
990b4856d0eaada6f8140335733a1b1771ed2746lling verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
990b4856d0eaada6f8140335733a1b1771ed2746lling (void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock if ((value = (char *)zfs_prop_default_string(prop)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Internal function for getting a numeric property. Both zfs_prop_get() and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_prop_get_int() are built using this interface.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Certain properties can be overridden using 'mount -o'. In this case, scan
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the contents of the /etc/mnttab entry, searching for the appropriate options.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If they differ from the on-disk values, report the current values and mark
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the source "temporary".
990b4856d0eaada6f8140335733a1b1771ed2746llingget_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock * Because looking up the mount options is potentially expensive
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock * (iterating over all of /etc/mnttab), we defer its calculation until
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock * we're looking up a property which requires its presence.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0) {
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens return (-1);
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (!zfs_prop_valid_for_type(prop, zhp->zfs_head_type) ||
3d7934e1eaaab784a1928c5c9bdb6273eeb7275drm return (-1);
bd00f61bf62a14e7e8914ca126c52af5c38e94e1rm (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_OBJSET_ZPLPROPS, &zc)) {
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &zplprops) != 0 ||
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * If we tried to use a default value for a
74e7dc986c89efca1f2e4451c7a572e05e4a6e4fMatthew Ahrens * readonly property, it means that it was not
74e7dc986c89efca1f2e4451c7a572e05e4a6e4fMatthew Ahrens * present; return an error.
e7437265dc2a4920c197ed4337665539d358b22cahrens "cannot get non-numeric property"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Calculate the source type, given the raw source string.
990b4856d0eaada6f8140335733a1b1771ed2746llingget_source(zfs_handle_t *zhp, zprop_source_t *srctype, char *source,
990b4856d0eaada6f8140335733a1b1771ed2746lling if (statbuf == NULL || *srctype == ZPROP_SRC_TEMPORARY)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Retrieve a property from the given object. If 'literal' is specified, then
fa9e4066f08beec538e775443c5be79dd423fcabahrens * numbers are left as exact values. Otherwise, numbers are converted to a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * human-readable form.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns 0 on success, or -1 on error.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
990b4856d0eaada6f8140335733a1b1771ed2746lling zprop_source_t *src, char *statbuf, size_t statlen, boolean_t literal)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock const char *strval;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if this property applies to our object
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 'creation' is a time_t stored in the statistics. We convert
fa9e4066f08beec538e775443c5be79dd423fcabahrens * this into a string unless 'literal' is specified.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Getting the precise mountpoint can be tricky.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * - for 'none' or 'legacy', return those values.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * - for inherited mountpoints, we want to take everything
fa9e4066f08beec538e775443c5be79dd423fcabahrens * after our ancestor and append it to the inherited value.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the pool has an alternate root, we want to prepend that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * root to any values we return.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock const char *relpath = zhp->zfs_name + strlen(source);
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * Special case an alternate root of '/'. This will
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * avoid having multiple leading slashes in the
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * mountpoint path.
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * If the mountpoint is '/' then skip over this
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * if we are obtaining either an alternate root or
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * an inherited mountpoint.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* 'legacy' or 'none' */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) strlcpy(propbuf, getprop_string(zhp, prop, &source),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If there is no parent at all, return failure to indicate that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * it doesn't apply to this dataset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If quota or reservation is 0, we translate this into 'none'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (unless literal is set), and indicate that it's the default
fa9e4066f08beec538e775443c5be79dd423fcabahrens * value. Otherwise, we print the number nicely and indicate
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that its set locally.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (val == 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
5ad820458efd0fdb914baff9c1447c22b819fa23nd (void) snprintf(propbuf, proplen, "%lld.%02lldx", (longlong_t)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The 'mounted' property is a pseudo-property that described
fa9e4066f08beec538e775443c5be79dd423fcabahrens * whether the filesystem is currently mounted. Even though
fa9e4066f08beec538e775443c5be79dd423fcabahrens * it's a boolean value, the typical values of "on" and "off"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * don't make sense, so we translate to "yes" and "no".
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The 'name' property is a pseudo-property derived from the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dataset name. It is presented as a real property to simplify
fa9e4066f08beec538e775443c5be79dd423fcabahrens * consumers.
e7437265dc2a4920c197ed4337665539d358b22cahrens return (-1);
fe192f767b9104ea1c90dc1eb713f2e3773e8f81ahrens return (-1);
fe192f767b9104ea1c90dc1eb713f2e3773e8f81ahrens if (zfs_prop_index_to_string(prop, val, &strval) != 0)
e7437265dc2a4920c197ed4337665539d358b22cahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Utility function to get the given numeric property. Does no validation that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the given property is the appropriate type; should only be used with
fa9e4066f08beec538e775443c5be79dd423fcabahrens * hard-coded property types.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (void) get_numeric_property(zhp, prop, NULL, &source, &val);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rmzfs_prop_set_int(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t val)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens (void) snprintf(buf, sizeof (buf), "%llu", (longlong_t)val);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Similar to zfs_prop_get(), but returns the value as an integer.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_prop_get_numeric(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t *value,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if this property applies to our object
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, value) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensidmap_id_to_numeric_domain_rid(uid_t id, boolean_t isuser,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (idmap_get_create(idmap_hdl, &get_hdl) != IDMAP_SUCCESS)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens IDMAP_REQ_FLG_USE_CACHE, domainp, ridp, &status);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens IDMAP_REQ_FLG_USE_CACHE, domainp, ridp, &status);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens idmap_get_mappings(get_hdl) == IDMAP_SUCCESS &&
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * convert the propname into parameters needed by kernel
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Eg: userquota@ahrens -> ZFS_PROP_USERQUOTA, "", 126829
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Eg: userused@matt@domain -> ZFS_PROP_USERUSED, "S-1-123-456", 789
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensuserquota_propname_decode(const char *propname, boolean_t zoned,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* Figure out the property type ({user|group}{quota|space}) */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens for (type = 0; type < ZFS_NUM_USERQUOTA_PROPS; type++) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (strncmp(propname, zfs_userquota_prop_prefixes[type],
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens strlen(zfs_userquota_prop_prefixes[type])) == 0)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * It's a SID name (eg "user@domain") that needs to be
3b12c289fe048d2e1698e22811cbfd6d3b3ed96eMatthew Ahrens * turned into S-1-domainID-RID.
3b12c289fe048d2e1698e22811cbfd6d3b3ed96eMatthew Ahrens /* will be further decoded below */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* It's a numeric SID (eg "S-1-234-567-89") */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * It's a user/group name (eg "user") that needs to be
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * turned into a uid/gid
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* It's a user/group ID (eg "12345"). */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* It's an ephemeral ID. */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (idmap_id_to_numeric_domain_rid(id, isuser,
3b12c289fe048d2e1698e22811cbfd6d3b3ed96eMatthew Ahrens (void) strlcpy(domain, mapdomain, domainlen);
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Lingzfs_prop_get_userquota_common(zfs_handle_t *zhp, const char *propname,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens (void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Ling typep, zc.zc_value, sizeof (zc.zc_value), &zc.zc_guid);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens err = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_USERSPACE_ONE, &zc);
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Ling return (0);
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Lingzfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Ling return (zfs_prop_get_userquota_common(zhp, propname, propvalue,
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Lingzfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Ling err = zfs_prop_get_userquota_common(zhp, propname, &propvalue,
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Ling (void) snprintf(propbuf, proplen, "%llu", propvalue);
edea4b556f0b07459cdcc780ffcd28a40b374945Lin Ling } else if (propvalue == 0 &&
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens (type == ZFS_PROP_USERQUOTA || type == ZFS_PROP_GROUPQUOTA)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns the name of the given zfs handle.
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns the type of the given zfs handle.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylorzfs_do_list_ioctl(zfs_handle_t *zhp, int arg, zfs_cmd_t *zc)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor (void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor /* expand nvlist memory and try again */
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc) != 0) {
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor return (-1);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor * An errno value of ESRCH indicates normal completion.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor * If ENOENT is returned, then the underlying dataset
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor * has been removed since we obtained the handle.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor "cannot iterate filesystems"));
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * Iterate over all child filesystems
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockzfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor return (-1);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Silently ignore errors, as the only plausible explanation is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that the pool has since been removed.
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * Iterate over all snapshots
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockzfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor return (-1);
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT,
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * Iterate over all children, snapshots and filesystems
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockzfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data)
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a complete name, return just the portion that refers to the parent.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can return NULL if this is a pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrensparent_name(const char *path, char *buf, size_t buflen)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * If accept_ancestor is false, then check to make sure that the given path has
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * a parent, and that it exists. If accept_ancestor is true, then find the
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * closest existing ancestor for the given path. In prefixlen return the
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * length of already existing prefix of the given path. We also fetch the
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * 'zoned' property, which is used to validate property settings when creating
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * new datasets.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbcheck_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned,
deb8317b8f5925e3f6dd7cb6ed0cdd035f546a5aMark J Musante dgettext(TEXT_DOMAIN, "cannot create '%s'"), path);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get parent, and check to see if this is just a pool */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (parent_name(path, parent, sizeof (parent)) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "missing dataset name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check to see if the pool exists */
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0 &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check to see if the parent dataset exists */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb while ((zhp = make_dataset_handle(hdl, parent)) == NULL) {
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Go deeper to find an ancestor, give up on top level.
99653d4ee642c6528e88224f12409a5f23060994eschrock "parent does not exist"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* we are in a non-global zone, but parent is in the global zone */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure parent is a filesystem */
99653d4ee642c6528e88224f12409a5f23060994eschrock "parent is not a filesystem"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb return (0);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Finds whether the dataset of the given type(s) exists.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbzfs_dataset_exists(libzfs_handle_t *hdl, const char *path, zfs_type_t types)
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Try to get stats for the dataset, which will tell us if it exists.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Given a path to 'target', create all the ancestors between
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * the prefixlen portion of the path, and the target itself.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Fail if the initial prefixlen-ancestor does not already exist.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrenscreate_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens const char *opname;
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* make sure prefix exists */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (-1);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Attempt to create, mount, and share any ancestor filesystems,
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * up to the prefixlen-long one.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* it already exists, nothing to do here */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (h == NULL) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (zfs_share(h) != 0) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (-1);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Creates non-existing ancestors of the given path.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbzfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, path, &zoned, B_TRUE, &prefix) != 0)
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb return (-1);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Create a new filesystem or volume.
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type,
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t blocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate the path, taking care to note the extended error message */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents exist */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, path, &zoned, B_FALSE, NULL) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The failure modes when creating a dataset of a different type over
fa9e4066f08beec538e775443c5be79dd423fcabahrens * one that already exists is a little strange. In particular, if you
fa9e4066f08beec538e775443c5be79dd423fcabahrens * try to create a dataset on top of an existing dataset, the ioctl()
fa9e4066f08beec538e775443c5be79dd423fcabahrens * will return ENOENT, not EEXIST. To prevent this from happening, we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * first try to see if the dataset exists.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, path, sizeof (zc.zc_name));
990b4856d0eaada6f8140335733a1b1771ed2746lling if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset already exists"));
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if (props && (props = zfs_valid_proplist(hdl, type, props,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * If we are creating a volume, the size and block size must
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * satisfy a few restraints. First, the blocksize must be a
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * valid block size between SPA_{MIN,MAX}BLOCKSIZE. Second, the
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * volsize must be a multiple of the block size, and cannot be
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "missing volume size"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "missing volume block size"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (size == 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume size cannot be zero"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume size must be a multiple of volume block "
990b4856d0eaada6f8140335733a1b1771ed2746lling if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the dataset */
b1b8ab34de515a5e83206da22c3d7e563241b021lling "Volume successfully created, but device links "
b1b8ab34de515a5e83206da22c3d7e563241b021lling "were not created"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check for failure */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume block size must be power of 2 from "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "%u to %uk"),
40feaa914945406e86e193599d115ea71a171d18ahrens "pool must be upgraded to set this "
40feaa914945406e86e193599d115ea71a171d18ahrens "property or value"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This platform can't address a volume this big.
99653d4ee642c6528e88224f12409a5f23060994eschrock /* FALLTHROUGH */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Destroys the given dataset. The caller must make sure that the filesystem
fa9e4066f08beec538e775443c5be79dd423fcabahrens * isn't mounted, and that there are no active dependents.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * If user doesn't have permissions to unshare volume, then
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * abort the request. This would only happen for a
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * non-privileged user.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY, &zc) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(name, zhp->zfs_name, sizeof (name));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * NB: this is simply a best-effort. We don't want to
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * return an error, because then we wouldn't visit all
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * the volumes.
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens rv = zfs_iter_filesystems(zhp, zfs_remove_link_cb, arg);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * Destroys all snapshots with the given name in zhp & descendants.
842727c2f41f01b380de4f5e787d905702870f23Chris Kirbyzfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS, &zc);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (ret != 0) {
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens "snapshot is cloned"));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (zfs_error(zhp->zfs_hdl, EZFS_EXISTS, errbuf));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Clones the given dataset. The target must be of the same type as the source.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate the target name */
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM, B_TRUE))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents exist */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, target, &zoned, B_FALSE, NULL) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* do the clone */
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if ((props = zfs_valid_proplist(hdl, type, props, zoned,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, target, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, zhp->zfs_name, sizeof (zc.zc_value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The parent doesn't exist. We should have caught this
fa9e4066f08beec538e775443c5be79dd423fcabahrens * above, but there may a race condition that has since
fa9e4066f08beec538e775443c5be79dd423fcabahrens * destroyed the parent.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * At this point, we don't know whether it's the source
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that doesn't exist anymore, or whether the target
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dataset doesn't exist.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf));
99653d4ee642c6528e88224f12409a5f23060994eschrock "source and target pools differ"));
99653d4ee642c6528e88224f12409a5f23060994eschrocktypedef struct promote_data {
99653d4ee642c6528e88224f12409a5f23060994eschrock /* We don't care about snapshots after the pivot point */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > pd->cb_pivot_txg) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
0b69c2f001a429251e2d38f25aca860396551214ahrens /* Remove the device link if it's a zvol. */
0b69c2f001a429251e2d38f25aca860396551214ahrens (void) zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name);
99653d4ee642c6528e88224f12409a5f23060994eschrock /* Check for conflicting names */
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(snapname, pd->cb_target, sizeof (snapname));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcat(snapname, strchr(zhp->zfs_name, '@'), sizeof (snapname));
99653d4ee642c6528e88224f12409a5f23060994eschrock szhp = make_dataset_handle(zhp->zfs_hdl, snapname);
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshot name '%s' from origin \n"
99653d4ee642c6528e88224f12409a5f23060994eschrock "conflicts with '%s' from target"),
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens rv = zfs_error(zhp->zfs_hdl, EZFS_EXISTS, pd->cb_errbuf);
0b69c2f001a429251e2d38f25aca860396551214ahrens /* We don't care about snapshots after the pivot point */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) <= pd->cb_pivot_txg) {
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens /* Create the device link if it's a zvol. */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens (void) zvol_create_link(zhp->zfs_hdl, zhp->zfs_name);
0b69c2f001a429251e2d38f25aca860396551214ahrens return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock * Promotes the given clone fs to be the clone parent.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshots can not be promoted"));
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
99653d4ee642c6528e88224f12409a5f23060994eschrock "not a cloned filesystem"));
99653d4ee642c6528e88224f12409a5f23060994eschrock /* Walk the snapshots we will be moving */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens pzhp = zfs_open(hdl, zhp->zfs_dmustats.dds_origin, ZFS_TYPE_SNAPSHOT);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock pd.cb_pivot_txg = zfs_prop_get_int(pzhp, ZFS_PROP_CREATETXG);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) zfs_prop_get(pzhp, ZFS_PROP_MOUNTPOINT, pd.cb_mountpoint,
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = zfs_iter_snapshots(pzhp, promote_snap_cb, &pd);
0b69c2f001a429251e2d38f25aca860396551214ahrens if (ret != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock /* issue the ioctl */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ret != 0) {
0b69c2f001a429251e2d38f25aca860396551214ahrens (void) zfs_iter_snapshots(pzhp, promote_snap_done_cb, &pd);
99653d4ee642c6528e88224f12409a5f23060994eschrock * There is a conflicting snapshot name. We
99653d4ee642c6528e88224f12409a5f23060994eschrock * should have caught this above, but they could
99653d4ee642c6528e88224f12409a5f23060994eschrock * have renamed something in the mean time.
99653d4ee642c6528e88224f12409a5f23060994eschrock "conflicting snapshot name from parent '%s'"),
0b69c2f001a429251e2d38f25aca860396551214ahrens return (zfs_standard_error(hdl, save_errno, errbuf));
0b69c2f001a429251e2d38f25aca860396551214ahrens (void) zfs_iter_snapshots(zhp, promote_snap_done_cb, &pd);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(name, zhp->zfs_name, sizeof (name));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) strlcat(name, cd->cd_snapname, sizeof (name));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * NB: this is simply a best-effort. We don't want to
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * return an error, because then we wouldn't visit all
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * the volumes.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhp, zfs_create_link_cb, cd);
72bdce51192b13a20009855f749004480874291bahl * Takes a snapshot of the given dataset.
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrenszfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *delim;
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock /* validate the target name */
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT, B_TRUE))
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens if ((props = zfs_valid_proplist(hdl, ZFS_TYPE_SNAPSHOT,
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens return (-1);
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure the parent exists and is of the appropriate type */
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = zfs_open(hdl, parent, ZFS_TYPE_FILESYSTEM |
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, delim+1, sizeof (zc.zc_value));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * if it was recursive, the one that actually failed will be in
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * zc.zc_name.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "cannot create snapshot '%s@%s'"), zc.zc_name, zc.zc_value);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) zfs_iter_filesystems(zhp, zfs_create_link_cb, &cd);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (ret != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "Volume successfully snapshotted, but device links "
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "were not created"));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Destroy any more recent snapshots. We invoke this callback on any dependents
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * of the snapshot first. If the 'cb_dependent' member is non-zero, then this
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * is a dependent and we should just destroy it without checking the transaction
b12a1c38fc215cc54fa6014069fd2b8dbb496646llingtypedef struct rollback_data {
c391e322108d10533bc61ba3ef7099b302214341ahrens /* We must destroy this clone; first unmount it */
c391e322108d10533bc61ba3ef7099b302214341ahrens return (0);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling return (0);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Given a dataset, rollback to a specific snapshot, discarding any
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * data changes since then and making it the active dataset.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Any snapshots more recent than the target are destroyed, along with
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * their dependents.
c391e322108d10533bc61ba3ef7099b302214341ahrenszfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Destroy all recent snapshots and its dependends.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
c391e322108d10533bc61ba3ef7099b302214341ahrens return (-1);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Now that we have verified that the snapshot is the latest,
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * rollback to the given snapshot.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * We rely on zfs_iter_children() to verify that there are no
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * newer snapshots for the given dataset. Therefore, we can
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * simply pass the name on to the ioctl() call. There is still
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * an unlikely race condition where the user has taken a
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * snapshot since we verified that this was the most recent.
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens if ((err = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_ROLLBACK, &zc)) != 0) {
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * For volumes, if the pre-rollback volsize matched the pre-
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * rollback reservation and the volsize has changed then set
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * the reservation property to the post-rollback volsize.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * Make a new handle since the rollback closed the dataset.
b9415e832db4ec89116104788643227b77ed508arm (zhp = make_dataset_handle(zhp->zfs_hdl, zhp->zfs_name))) {
b9415e832db4ec89116104788643227b77ed508arm if (err = zvol_create_link(zhp->zfs_hdl, zhp->zfs_name)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all dependents for a given dataset. This includes both
fa9e4066f08beec538e775443c5be79dd423fcabahrens * hierarchical dependents (children) and data dependents (snapshots and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * clones). The bulk of the processing occurs in get_dependents() in
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrockzfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock if (get_dependents(zhp->zfs_hdl, allowrecursion, zhp->zfs_name,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < count; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < count; i++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Renames the given dataset.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbzfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* if we have the same exact name, just return success */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure the target name is valid
98579b20de8e05c5117968705a18979f8b75b863nd * Snapshot target name is abbreviated,
98579b20de8e05c5117968705a18979f8b75b863nd * reconstruct full dataset name
98579b20de8e05c5117968705a18979f8b75b863nd sizeof (parent));
98579b20de8e05c5117968705a18979f8b75b863nd * Make sure we're renaming within the same dataset.
98579b20de8e05c5117968705a18979f8b75b863nd "snapshots must be part of same "
98579b20de8e05c5117968705a18979f8b75b863nd "dataset"));
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "recursive rename must be a snapshot"));
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, target, &unused, B_FALSE, NULL) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure we're in the same pool */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (strncmp(zhp->zfs_name, target, delim - target) != 0 ||
99653d4ee642c6528e88224f12409a5f23060994eschrock "datasets must be within same pool"));
f2fdf992e7f966d7f6d0c41679a1058bf225a936nd /* new name cannot be a child of the current dataset name */
f2fdf992e7f966d7f6d0c41679a1058bf225a936nd "New dataset name cannot be a descendent of "
f2fdf992e7f966d7f6d0c41679a1058bf225a936nd "current dataset name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot rename '%s'"), zhp->zfs_name);
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset is used in a non-global zone"));
f0c5ee210eebf913b19e8715470ed4fe669425a4mmusante parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
990b4856d0eaada6f8140335733a1b1771ed2746lling zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* We remove any zvol links prior to renaming them */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhrp, zfs_remove_link_cb, &dd);
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0)) == NULL)
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (-1);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "child dataset with inherited mountpoint is used "
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "in a non-global zone"));
98579b20de8e05c5117968705a18979f8b75b863nd (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_RENAME, &zc)) != 0) {
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * if it was recursive, the one that actually failed will
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * be in zc.zc_name
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "a child dataset already has a snapshot "
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "with the new name"));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * On failure, we still want to remount any filesystems that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * were previously mounted, so we don't alter the system state.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* only create links for datasets that had existed */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) zfs_iter_filesystems(zhrp, zfs_create_link_cb,
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* only create links for datasets that had existed */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhrp, zfs_create_link_cb,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a zvol dataset, issue the ioctl to create the appropriate minor node,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * poke devfsadm to create the /dev link, and then wait for the link to appear.
99653d4ee642c6528e88224f12409a5f23060994eschrockzvol_create_link(libzfs_handle_t *hdl, const char *dataset)
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (zvol_create_link_common(hdl, dataset, B_FALSE));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusantezvol_create_link_common(libzfs_handle_t *hdl, const char *dataset, int ifexists)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Issue the appropriate ioctl.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_CREATE_MINOR, &zc) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Silently ignore the case where the link already
fa9e4066f08beec538e775443c5be79dd423fcabahrens * exists. This allows 'zfs volinit' to be run multiple
fa9e4066f08beec538e775443c5be79dd423fcabahrens * times without errors.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * Dataset does not exist in the kernel. If we
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * don't care (see zfs_rename), then ignore the
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * error quietly.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (0);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* FALLTHROUGH */
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot create device links "
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * If privileged call devfsadm and wait for the links to
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * magically appear.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Otherwise, print out an informational message.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks privileged = (priv_isfullset(priv_effective) == B_TRUE);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * This is the poor mans way of waiting for the link
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * to show up. If after 10 seconds we still don't
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * have it, then print out a message.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) snprintf(pathname, sizeof (pathname), "/dev/zvol/dsk/%s",
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks for (i = 0; i != MAX_WAIT; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove a minor node for the given zvol and the associated /dev links.
99653d4ee642c6528e88224f12409a5f23060994eschrockzvol_remove_link(libzfs_handle_t *hdl, const char *dataset)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Silently ignore the case where the link no longer
fa9e4066f08beec538e775443c5be79dd423fcabahrens * exists, so that 'zfs volfini' can be run multiple
fa9e4066f08beec538e775443c5be79dd423fcabahrens * times without errors.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
b1b8ab34de515a5e83206da22c3d7e563241b021lling * This function is used by 'zfs list' to determine the exact set of columns to
b1b8ab34de515a5e83206da22c3d7e563241b021lling * display, and their maximum widths. This does two main things:
b1b8ab34de515a5e83206da22c3d7e563241b021lling * - If this is a list of all properties, then expand the list to include
b1b8ab34de515a5e83206da22c3d7e563241b021lling * all native properties, and set a flag so that for each dataset we look
b1b8ab34de515a5e83206da22c3d7e563241b021lling * for new unique user properties and add them to the list.
b1b8ab34de515a5e83206da22c3d7e563241b021lling * - For non fixed-width properties, keep track of the maximum width seen
b1b8ab34de515a5e83206da22c3d7e563241b021lling * so that we can size the column appropriately.
990b4856d0eaada6f8140335733a1b1771ed2746llingzfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp)
990b4856d0eaada6f8140335733a1b1771ed2746lling if (zprop_expand_list(hdl, plp, ZFS_TYPE_DATASET) != 0)
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (entry->pl_all && nvlist_next_nvpair(userprops, NULL) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Go through and add any user properties as necessary. We
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * start by incrementing our list pointer to the first
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * non-native property.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while ((elem = nvlist_next_nvpair(userprops, elem)) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * See if we've already found this property in our list.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Now go through and check the width of any non-fixed columns
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock for (entry = *plp; entry != NULL; entry = entry->pl_next) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_iscsi_perm_check(libzfs_handle_t *hdl, char *dataset, ucred_t *cred)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (uid == (uid_t)-1 || gid == (uid_t)-1 || group_cnt == (uid_t)-1)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_UID, uid) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_GID, gid) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks ZFS_DELEG_PERM_GROUPS, (uint32_t *)groups, group_cnt) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks error = ioctl(hdl->libzfs_fd, ZFS_IOC_ISCSI_PERM_CHECK, &zc);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_deleg_share_nfs(libzfs_handle_t *hdl, char *dataset, char *path,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value));
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (void) strlcpy(zc.zc_string, resource, sizeof (zc.zc_string));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks zc.zc_share.z_sharedata = (uint64_t)(uintptr_t)sharetab;
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks zc.zc_share.z_exportdata = (uint64_t)(uintptr_t)export;
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadizfs_prune_proplist(zfs_handle_t *zhp, uint8_t *props)
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi * Keep a reference to the props-table against which we prune the
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi * properties.
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi curr = nvlist_next_nvpair(zhp->zfs_props, NULL);
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi zfs_prop_t zfs_prop = zfs_name_to_prop(nvpair_name(curr));
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi nvpair_t *next = nvlist_next_nvpair(zhp->zfs_props, curr);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * We leave user:props in the nvlist, so there will be
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * some ZPROP_INVAL. To be extra safe, don't prune
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (zfs_prop != ZPROP_INVAL && props[zfs_prop] == B_FALSE)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_smb_acl_mgmt(libzfs_handle_t *hdl, char *dataset, char *path,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright zfs_smb_acl_op_t cmd, char *resource1, char *resource2)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value));
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (nvlist_alloc(&nvlist, NV_UNIQUE_NAME, 0) != 0) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (void) strlcpy(zc.zc_string, resource1, sizeof (zc.zc_string));
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (-1);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (nvlist_add_string(nvlist, ZFS_SMB_ACL_TARGET,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (-1);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (zcmd_write_src_nvlist(hdl, &zc, nvlist) != 0) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (-1);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (-1);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright error = ioctl(hdl->libzfs_fd, ZFS_IOC_SMB_ACL, &zc);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_smb_acl_add(libzfs_handle_t *hdl, char *dataset,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_ADD,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_smb_acl_remove(libzfs_handle_t *hdl, char *dataset,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_REMOVE,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_smb_acl_purge(libzfs_handle_t *hdl, char *dataset, char *path)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_PURGE,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_smb_acl_rename(libzfs_handle_t *hdl, char *dataset, char *path,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_RENAME,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrenszfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens (void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* CONSTCOND */
0aea4b19873599c9a11db600b90263c7233db953Matthew Ahrens error = func(arg, zua->zu_domain, zua->zu_rid,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens zc.zc_nvlist_dst_size -= sizeof (zfs_useracct_t);
842727c2f41f01b380de4f5e787d905702870f23Chris Kirbyzfs_hold(zfs_handle_t *zhp, const char *snapname, const char *tag,
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) strlcpy(zc.zc_string, tag, sizeof (zc.zc_string));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby * if it was recursive, the one that actually failed will be in
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby * zc.zc_name.
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby "pool must be upgraded"));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby return (zfs_error(hdl, EZFS_BADVERSION, errbuf));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby return (zfs_error(hdl, EZFS_REFTAG_HOLD, errbuf));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby return (zfs_standard_error_fmt(hdl, errno, errbuf));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirbyzfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag,
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) strlcpy(zc.zc_string, tag, sizeof (zc.zc_string));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby if (zfs_ioctl(hdl, ZFS_IOC_RELEASE, &zc) != 0) {
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby * if it was recursive, the one that actually failed will be in
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby * zc.zc_name.
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby "cannot release '%s@%s'"), zc.zc_name, snapname);
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby return (zfs_error(hdl, EZFS_REFTAG_RELE, errbuf));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby "pool must be upgraded"));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby return (zfs_error(hdl, EZFS_BADVERSION, errbuf));