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
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Copyright (c) 2013, Joyent, Inc. All rights reserved.
ad2760acbd9c3b479bf632f05c6f03d89830799dMatthew Ahrens * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
f0f3ef5a19910089bada873cb30b3f5d88cb9e00Garrett D'Amore * Copyright (c) 2012 DEY Storage Systems, Inc. All rights reserved.
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
013023d4ed2f6d0cf75380ec686a4aac392b4e43Martin Matuska * Copyright (c) 2013 Martin Matuska. All rights reserved.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
8808ac5dae118369991f158b6ab736cb2691ecdeYuri Pankov * Copyright 2016 Nexenta Systems, Inc.
88f61dee20b358671b1b643e9d1dbf220a1d69beIgor Kozhukhov * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
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 * 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,
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if (entity_namecheck(path, &why, &what) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "name is too long"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "leading slash in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "empty component in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "trailing slash in name"));
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka "multiple '@' and/or '#' delimiters in "
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) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka "snapshot delimiter '@' is not expected here"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "missing '@' delimiter in snapshot name"));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (0);
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if (!(type & ZFS_TYPE_BOOKMARK) && strchr(path, '#') != NULL) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka "bookmark delimiter '#' is not expected here"));
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if (type == ZFS_TYPE_BOOKMARK && strchr(path, '#') == NULL) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka "missing '#' delimiter in bookmark name"));
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);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Utility function to get the received properties of the given object.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson while (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_RECVD_PROPS, &zc) != 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &recvdprops);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson 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.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if ((zhp->zpool_hdl = zpool_handle(zhp)) == NULL)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (-1);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
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) {
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuskamake_dataset_simple_handle_zc(zfs_handle_t *pzhp, zfs_cmd_t *zc)
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska (void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcpy(zhp->zfs_name, zhp_orig->zfs_name,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens zhp->zfs_head_type = zhp_orig->zfs_head_type;
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens if (nvlist_dup(zhp_orig->zfs_props, &zhp->zfs_props, 0) != 0) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens zhp->zfs_mntopts = zfs_strdup(zhp_orig->zfs_hdl,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens zhp->zfs_props_table = zhp_orig->zfs_props_table;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens (void) strlcpy(fsname, path, sizeof (fsname));
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = lzc_get_bookmarks(fsname, props, &bmarks);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrensmake_bookmark_handle(zfs_handle_t *parent, const char *path,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens /* Fill in the name. */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens (void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name));
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens /* Set the property lists. */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (nvlist_dup(bmark_props, &zhp->zfs_props, 0) != 0) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens /* Set the types. */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if ((zhp->zpool_hdl = zpool_handle(zhp)) == NULL) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telkazfs_open_bookmarks_cb(zfs_handle_t *zhp, void *data)
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Is it the one we are looking for?
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if (strcmp(dp->path, zfs_get_name(zhp)) == 0) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * We found it. Save it and let the caller know we are done.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Not found. Close the handle and ask for another one.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Opens the given snapshot, bookmark, 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.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if (!zfs_validate_name(hdl, path, types, B_FALSE)) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Bookmarks needs to be handled separately.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Try to get stats for the dataset, which will tell us if it
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if ((zhp = make_dataset_handle(hdl, path)) == NULL) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka struct zfs_open_bookmarks_cb_data cb_data = {path, NULL};
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * We need to cut out '#' and everything after '#'
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * to get the parent dataset name only.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Create handle for the parent dataset.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if ((pzhp = make_dataset_handle(hdl, dsname)) == NULL) {
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka * Iterate bookmarks to find the right one.
edb901aab9c738b5eb15aa55933e82b0f2f9d9a2Marcel Telka if ((zfs_iter_bookmarks(pzhp, zfs_open_bookmarks_cb,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Release a ZFS handle. Nothing to do but free the associated memory.
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);
88f61dee20b358671b1b643e9d1dbf220a1d69beIgor Kozhukhov 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)
88f61dee20b358671b1b643e9d1dbf220a1d69beIgor Kozhukhov 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,
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein uint64_t zoned, zfs_handle_t *zhp, zpool_handle_t *zpool_hdl,
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein 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 "
2d5843db7439a2f07385993dc762c76159967f5aMatthew Ahrens * Encode the prop name as
2d5843db7439a2f07385993dc762c76159967f5aMatthew Ahrens * userquota@<hex-rid>-domain, to make it easy
2d5843db7439a2f07385993dc762c76159967f5aMatthew Ahrens * for the kernel to decode.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens (void) snprintf(newpropname, sizeof (newpropname),
2d5843db7439a2f07385993dc762c76159967f5aMatthew Ahrens "%s%llx-%s", zfs_userquota_prop_prefixes[uqtype],
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (nvlist_add_uint64_array(ret, newpropname,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens } else if (prop == ZPROP_INVAL && zfs_prop_written(propname)) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens "'%s' is readonly"),
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Perform some additional checks for specific properties.
e7437265dc2a4920c197ed4337665539d358b22cahrens "Can not downgrade; already at version %u"),
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * Volumes are limited to a volblocksize of 128KB,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * because they typically service workloads with
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * small random writes, which incur a large performance
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * penalty with large blocks.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * The value must be a power of two between
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * SPA_MINBLOCKSIZE and maxbs.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens "'%s' must be power of 2 from 512B "
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * Verify the mlslabel string and convert to
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * internal hex label string.
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* Default value is already OK. */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* Verify the label can be converted to binary form */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire if (((new_sl = m_label_alloc(MAC_LABEL)) == NULL) ||
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* Now translate to hex internal label string */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* If string is already in internal form, we're done. */
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire /* Replace the label string with the internal form. */
569038c95d651bec86b85f4d3c73961dcd957551Ric Aleshire (void) nvlist_remove(ret, zfs_prop_to_name(prop),
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire verify(nvlist_add_string(ret, zfs_prop_to_name(prop),
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm switch (why) {
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm "'%s' must be an absolute path, "
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm "component of '%s' is too long"),
88f61dee20b358671b1b643e9d1dbf220a1d69beIgor Kozhukhov "(%d) not defined"),
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"),
36db6475cbf2fb46847d57950898a52117b69fecEric Taylorzfs_add_synthetic_resv(zfs_handle_t *zhp, nvlist_t *nvl)
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.
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor old_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE);
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor return (-1);
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor old_reservation = zfs_prop_get_int(zhp, resv_prop);
c61ea5668634a215fd1c9000beb7f6d2853b3468George Wilson fnvlist_add_uint64(props, zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
c61ea5668634a215fd1c9000beb7f6d2853b3468George Wilson zfs_prop_get_int(zhp, ZFS_PROP_VOLBLOCKSIZE));
c61ea5668634a215fd1c9000beb7f6d2853b3468George Wilson if ((zvol_volsize_to_reservation(old_volsize, props) !=
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor if (nvlist_lookup_uint64(nvl, zfs_prop_to_name(ZFS_PROP_VOLSIZE),
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor return (-1);
c61ea5668634a215fd1c9000beb7f6d2853b3468George Wilson new_reservation = zvol_volsize_to_reservation(new_volsize, props);
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor if (nvlist_add_uint64(nvl, zfs_prop_to_name(resv_prop),
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_setprop_error(libzfs_handle_t *hdl, zfs_prop_t prop, int err,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * For quotas and reservations, ENOSPC indicates
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * something different; setting a quota or reservation
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * doesn't use any disk space.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "size is less than current used or "
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "reserved space"));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "size is greater than available space"));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson (void) zfs_error(hdl, EZFS_DSREADONLY, errbuf);
6fdcb3d1c2baae812d9cbce37b41469b924efd90Will Andrews "property value too long"));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "pool and or dataset must be upgraded to set this "
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "property or value"));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson (void) zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "property setting is not allowed on "
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson "bootable datasets"));
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens (void) zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens "property setting is not allowed on "
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens "root pools"));
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * This platform can't address a volume this big.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* FALLTHROUGH */
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'"),
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * Given an nvlist of property names and values, set the properties for the
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * given dataset.
30925561c223021e91d15899cbe75f80e54d8889Chris Williamsonzfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson if ((nvl = zfs_valid_proplist(hdl, zhp->zfs_type, props,
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, zhp->zpool_hdl,
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * We have to check for any extra properties which need to be added
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * before computing the length of the nvlist.
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson for (nvpair_t *elem = nvlist_next_nvpair(nvl, NULL);
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson if (zfs_name_to_prop(nvpair_name(elem)) == ZFS_PROP_VOLSIZE &&
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson (added_resv = zfs_add_synthetic_resv(zhp, nvl)) == -1) {
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * Check how many properties we're setting and allocate an array to
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * store changelist pointers for postfix().
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson for (nvpair_t *elem = nvlist_next_nvpair(nvl, NULL);
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson if ((cls = calloc(nvl_len, sizeof (prop_changelist_t *))) == NULL)
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson for (nvpair_t *elem = nvlist_next_nvpair(nvl, NULL);
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson zfs_prop_t prop = zfs_name_to_prop(nvpair_name(elem));
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * We don't want to unmount & remount the dataset when changing
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * its canmount property to 'on' or 'noauto'. We only use
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * the changelist logic to unmount when setting canmount=off.
c079fa4d202eff15e318131c52755d214ffa2da7Andriy Gapon (fnvpair_value_uint64(elem) == ZFS_CANMOUNT_OFF &&
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson cls[cl_idx] = changelist_gather(zhp, prop, 0, 0);
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson "child dataset with inherited mountpoint is used "
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson "in a non-global zone"));
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson (ret = changelist_prefix(cls[cl_idx])) != 0)
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson * Execute the corresponding ioctl() to set this list of properties.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson if ((ret = zcmd_write_src_nvlist(hdl, &zc, nvl)) != 0 ||
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson (ret = zcmd_alloc_dst_nvlist(hdl, &zc, 0)) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson /* Get the list of unset properties back and report them. */
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson if (zcmd_read_dst_nvlist(hdl, &zc, &errorprops) != 0)
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson for (nvpair_t *elem = nvlist_next_nvpair(nvl, NULL);
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson zfs_prop_t prop = zfs_name_to_prop(nvpair_name(elem));
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson zfs_setprop_error(hdl, prop, errno, errbuf);
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor /* clean up the volsize property we tried to set */
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson for (cl_idx = 0; cl_idx < nvl_len; cl_idx++) {
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson int clp_err = changelist_postfix(cls[cl_idx]);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Refresh the statistics so the new property value
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is reflected.
30925561c223021e91d15899cbe75f80e54d8889Chris Williamson for (cl_idx = 0; cl_idx < nvl_len; cl_idx++) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * Given a property, inherit the value from the parent dataset, or if received
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * is TRUE, revert to the received value, if any.
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received)
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
36db6475cbf2fb46847d57950898a52117b69fecEric Taylor * Normalize the name, to get rid of shorthand abbreviations.
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);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensstatic const char *
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockgetprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens value = fnvlist_lookup_string(nv, ZPROP_VALUE);
990b4856d0eaada6f8140335733a1b1771ed2746lling (void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (zhp->zfs_props == zhp->zfs_recvd_props);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_set_recvd_props_mode(zfs_handle_t *zhp, uint64_t *cookie)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_unset_recvd_props_mode(zfs_handle_t *zhp, uint64_t *cookie)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson zhp->zfs_props = (nvlist_t *)(uintptr_t)*cookie;
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,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson boolean_t received = zfs_is_recvd_props_mode(zhp);
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);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson /* not default, must be local */
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 ||
ca48f36f20f6098ceb19d5b084b6b3d4b8eca9faKeith M Wesolowski *val = zhp->zfs_dmustats.dds_inconsistent;
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * If we tried to use a default value for a
74e7dc986c89efca1f2e4451c7a572e05e4a6e4fMatthew Ahrens * readonly property, it means that it was not
4d86c0eab246bdfddc2dd52410ba808433bd6266Matthew Ahrens * present. Note this only applies to "truly"
4d86c0eab246bdfddc2dd52410ba808433bd6266Matthew Ahrens * readonly properties, not set-once properties
4d86c0eab246bdfddc2dd52410ba808433bd6266Matthew Ahrens * like volblocksize.
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)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson } else if (strstr(source, ZPROP_SOURCE_VAL_RECVD) != NULL) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonzfs_prop_get_recvd(zfs_handle_t *zhp, const char *propname, char *propbuf,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (!nvlist_exists(zhp->zfs_recvd_props, propname))
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson err = zfs_prop_get(zhp, prop, propbuf, proplen,
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson verify(nvlist_lookup_string(propval, ZPROP_VALUE,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrensget_clones_string(zfs_handle_t *zhp, char *propbuf, size_t proplen)
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens for (pair = nvlist_next_nvpair(value, NULL); pair != NULL;
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcat(propbuf, nvpair_name(pair), proplen);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens if (zfs_prop_get(zhp, ZFS_PROP_ORIGIN, gca->buf, sizeof (gca->buf),
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens fnvlist_add_boolean(gca->value, zfs_get_name(zhp));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) zfs_iter_children(zhp, get_clones_cb, gca);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens zfs_prop_to_name(ZFS_PROP_CLONES), &nv) != 0) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * if this is a snapshot, then the kernel wasn't able
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * to get the clones. Do it by slowly iterating.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens if (nvlist_alloc(&nv, NV_UNIQUE_NAME, 0) != 0)
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens if (nvlist_alloc(&value, NV_UNIQUE_NAME, 0) != 0) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens gca.numclones = zfs_prop_get_int(zhp, ZFS_PROP_NUMCLONES);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* get the pool name */
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcpy(pool, zhp->zfs_name, sizeof (pool));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens nvlist_add_nvlist(nv, ZPROP_VALUE, value) != 0 ||
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens zfs_prop_to_name(ZFS_PROP_CLONES), nv) != 0) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens verify(0 == nvlist_lookup_nvlist(zhp->zfs_props,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens verify(nvlist_lookup_nvlist(nv, ZPROP_VALUE, &value) == 0);
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)
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson boolean_t received = zfs_is_recvd_props_mode(zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if this property applies to our object
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson 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.
a79992aa86337b5472ea858477dfcdfe49945c80Tom Erickson * If we inherit the mountpoint, even from a dataset
a79992aa86337b5472ea858477dfcdfe49945c80Tom Erickson * with a received value, the source will be the path of
a79992aa86337b5472ea858477dfcdfe49945c80Tom Erickson * the dataset we inherit from. If source is
a79992aa86337b5472ea858477dfcdfe49945c80Tom Erickson * ZPROP_SOURCE_VAL_RECVD, the received value is not
a79992aa86337b5472ea858477dfcdfe49945c80Tom Erickson * inherited.
a79992aa86337b5472ea858477dfcdfe49945c80Tom Erickson if (strcmp(source, ZPROP_SOURCE_VAL_RECVD) == 0) {
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' */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens if (get_clones_string(zhp, propbuf, proplen) != 0)
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) {
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * If limit is UINT64_MAX, we translate this into 'none' (unless
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * literal is set), and indicate that it's the default value.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Otherwise, we print the number nicely and indicate that it's
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * set locally.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick (void) snprintf(propbuf, proplen, "%llu.%02llux",
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.
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * Try to translate the internal hex string to
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * human-readable output. If there are any
4201a95e0468170d576f82c3aa63afecf718497aRic Aleshire * problems just use the hex string.
f0f3ef5a19910089bada873cb30b3f5d88cb9e00Garrett D'Amore * GUIDs are stored as numbers, but they are identifiers.
f0f3ef5a19910089bada873cb30b3f5d88cb9e00Garrett D'Amore * We don't want them to be pretty printed, because pretty
f0f3ef5a19910089bada873cb30b3f5d88cb9e00Garrett D'Amore * printing mangles the ID into a truncated and useless value.
f0f3ef5a19910089bada873cb30b3f5d88cb9e00Garrett D'Amore if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
f0f3ef5a19910089bada873cb30b3f5d88cb9e00Garrett D'Amore (void) snprintf(propbuf, proplen, "%llu", (u_longlong_t)val);
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,
1fdeec650620e8498c06f832ea4bd2292f7e9632joyce mcintosh if (idmap_get_create(&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.
1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9fGordon Ross stat = idmap_getuidbywinname(cp, NULL, flag, &pid);
1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9fGordon Ross stat = idmap_get_sidbyuid(gh, pid, flag, &numericsid,
1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9fGordon Ross stat = idmap_getgidbywinname(cp, NULL, flag, &pid);
1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9fGordon Ross stat = idmap_get_sidbygid(gh, pid, flag, &numericsid,
3b12c289fe048d2e1698e22811cbfd6d3b3ed96eMatthew Ahrens /* will be further decoded below */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* It's a numeric SID (eg "S-1-234-567-89") */
1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9fGordon Ross if (*ridp == 0) {
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,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcpy(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)) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrenszfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* snapname is the short name, append it to zhp's fsname */
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcat(zc.zc_value, "@", sizeof (zc.zc_value));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcat(zc.zc_value, snapname, sizeof (zc.zc_value));
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens err = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SPACE_WRITTEN, &zc);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrenszfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens char *propbuf, int proplen, boolean_t literal)
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens err = zfs_prop_get_written_int(zhp, propname, &propvalue);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) snprintf(propbuf, proplen, "%llu", propvalue);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Returns the name of the given zfs handle.
8808ac5dae118369991f158b6ab736cb2691ecdeYuri Pankov * Returns the name of the parent pool for the given zfs handle.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Returns the type of the given zfs handle.
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante * Is one dataset name a child dataset of another?
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante * Needs to handle these cases:
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante * Dataset 1 "a/foo" "a/foo" "a/foo" "a/foo"
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante * Dataset 2 "a/fo" "a/foobar" "a/bar/baz" "a/foo/bar"
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante * Descendant? No. No. No. Yes.
d41c437653d9e16d837cc66844073e1885276ceeMark J Musanteis_descendant(const char *ds1, const char *ds2)
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante /* ds2 can't be a descendant if it's smaller */
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante /* otherwise, compare strings and verify that there's a '/' char */
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante return (ds2[d1len] == '/' && (strncmp(ds1, ds2, d1len) == 0));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a complete name, return just the portion that refers to the parent.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Will return -1 if there is no parent (path is just the name of the
fa9e4066f08beec538e775443c5be79dd423fcabahrensparent_name(const char *path, char *buf, size_t buflen)
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 */
8ac09fcebf848c31516b15ce92861de4b2f514e8Richard Lowe (void) strncpy(zc.zc_name, parent, slash - parent);
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"));
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante is_zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* we are in a non-global zone, but parent is in the global zone */
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante if (getzoneid() != GLOBAL_ZONEID && !is_zoned) {
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 /* make sure prefix exists */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (-1);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Attempt to create, mount, and share any ancestor filesystems,
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * up to the prefixlen-long one.
88f61dee20b358671b1b643e9d1dbf220a1d69beIgor Kozhukhov (cp = strchr(cp, '/')) != NULL; *cp = '/', cp++) {
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)
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante if (check_parents(hdl, path, NULL, 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.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (zfs_dataset_exists(hdl, path, ZFS_TYPE_DATASET)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset already exists"));
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein /* open zpool handle for prop validation */
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein (void) strlcpy(pool_path, path, sizeof (pool_path));
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein /* truncate pool_path at first slash */
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein zpool_handle_t *zpool_handle = zpool_open(hdl, pool_path);
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 "
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the dataset */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check for failure */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
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
65fec9f6c72fa6b5f798dcf3831d94959ef5e281Christopher Siden * isn't mounted, and that there are no active dependents. If the file system
65fec9f6c72fa6b5f798dcf3831d94959ef5e281Christopher Siden * does not exist this function does nothing.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens return (zfs_standard_error_fmt(zhp->zfs_hdl, errno,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens dgettext(TEXT_DOMAIN, "cannot destroy '%s'"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
65fec9f6c72fa6b5f798dcf3831d94959ef5e281Christopher Siden if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY, &zc) != 0 &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens verify(nvlist_add_boolean(dd->nvl, name) == 0);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, dd);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * Destroys all snapshots with the given name in zhp & descendants.
842727c2f41f01b380de4f5e787d905702870f23Chris Kirbyzfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens verify(nvlist_alloc(&dd.nvl, NV_UNIQUE_NAME, 0) == 0);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) zfs_check_snap_cb(zfs_handle_dup(zhp), &dd);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens ret = zfs_standard_error_fmt(zhp->zfs_hdl, ENOENT,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ret = zfs_destroy_snaps_nvl(zhp->zfs_hdl, dd.nvl, defer);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Destroys all the snapshots named in the nvlist.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenszfs_destroy_snaps_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, boolean_t defer)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens ret = lzc_destroy_snaps(snaps, defer, &errlist);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dgettext(TEXT_DOMAIN, "cannot destroy snapshots"));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (nvpair_t *pair = nvlist_next_nvpair(errlist, NULL);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens pair != NULL; pair = nvlist_next_nvpair(errlist, pair)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dgettext(TEXT_DOMAIN, "cannot destroy snapshot %s"),
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dgettext(TEXT_DOMAIN, "snapshot is cloned"));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ret = zfs_standard_error(hdl, errno, errbuf);
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,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* validate the target/clone 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);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens ret = lzc_clone(target, zhp->zfs_name, props);
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"));
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"));
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) {
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor /* There is a conflicting snapshot name. */
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor "conflicting snapshot '%s' from parent '%s'"),
0b69c2f001a429251e2d38f25aca860396551214ahrens return (zfs_standard_error(hdl, save_errno, errbuf));
ca48f36f20f6098ceb19d5b084b6b3d4b8eca9faKeith M Wesolowski if (zfs_prop_get_int(zhp, ZFS_PROP_INCONSISTENT) == 0) {
ca48f36f20f6098ceb19d5b084b6b3d4b8eca9faKeith M Wesolowski "%s@%s", zfs_get_name(zhp), sd->sd_snapname);
ca48f36f20f6098ceb19d5b084b6b3d4b8eca9faKeith M Wesolowski rv = zfs_iter_filesystems(zhp, zfs_snapshot_cb, sd);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Creates snapshots. The keys in the snaps nvlist are the snapshots to be
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, nvlist_t *props)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens "cannot create snapshots "));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens while ((elem = nvlist_next_nvpair(snaps, elem)) != NULL) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* validate the target name */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (!zfs_validate_name(hdl, snapname, ZFS_TYPE_SNAPSHOT,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein * get pool handle for prop validation. assumes all snaps are in the
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein * same pool, as does lzc_snapshot (below).
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein zpool_handle_t *zpool_hdl = zpool_open(hdl, pool);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (props = zfs_valid_proplist(hdl, ZFS_TYPE_SNAPSHOT,
e9316f7696401f3e5e263a5939031cb8d5641a88Joe Stein props, B_FALSE, NULL, zpool_hdl, errbuf)) == NULL) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens for (elem = nvlist_next_nvpair(errors, NULL);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens "cannot create snapshot '%s'"), nvpair_name(elem));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens "multiple snapshots of same "
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens "fs not allowed"));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenszfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT, B_TRUE))
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(fsname, path, sizeof (fsname));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if ((zhp = zfs_open(hdl, fsname, ZFS_TYPE_FILESYSTEM |
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens verify(nvlist_alloc(&sd.sd_nvl, NV_UNIQUE_NAME, 0) == 0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) zfs_snapshot_cb(zfs_handle_dup(zhp), &sd);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens ret = zfs_snapshot_nvl(hdl, sd.sd_nvl, props);
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
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrensrollback_destroy_dependent(zfs_handle_t *zhp, void *data)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens /* We must destroy this clone; first unmount it */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens clp = changelist_gather(zhp, ZFS_PROP_NAME, 0,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (clp == NULL || changelist_prefix(clp) != 0) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrensrollback_destroy(zfs_handle_t *zhp, void *data)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > cbp->cb_create) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens cbp->cb_error |= zfs_iter_dependents(zhp, B_FALSE,
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.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Any snapshots and bookmarks more recent than the target are
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * destroyed, along with their dependents (i.e. clones).
c391e322108d10533bc61ba3ef7099b302214341ahrenszfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
2e2c135528b3edfe9aaf67d1f004dc0202fa1a54Matthew Ahrens * Destroy all recent snapshots and their dependents.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska (void) zfs_iter_snapshots(zhp, B_FALSE, rollback_destroy, &cb);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens (void) zfs_iter_bookmarks(zhp, rollback_destroy, &cb);
c391e322108d10533bc61ba3ef7099b302214341ahrens return (-1);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Now that we have verified that the snapshot is the latest,
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * rollback to the given snapshot.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
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.
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))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Renames the given dataset.
6a9cb0ea17f11529b1bb8ca31944abd37736b99eEric Schrockzfs_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 */
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante if (check_parents(hdl, target, NULL, 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 */
d41c437653d9e16d837cc66844073e1885276ceeMark J Musante "New dataset name cannot be a descendant 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);
33cde0d0c27645bc9ec94c4d2955193c3dd4027cMatthew Ahrens } else if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT) {
6a9cb0ea17f11529b1bb8ca31944abd37736b99eEric Schrock if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0,
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.
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
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * so that we can size the column appropriately. If the user has
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * requested received property values, we also need to compute the width
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson * of the RECEIVED column.
43d68d68c1ce08fb35026bebfb141af422e7082eYuri Pankovzfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
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) {
43d68d68c1ce08fb35026bebfb141af422e7082eYuri Pankov buf, sizeof (buf), NULL, NULL, 0, literal) == 0) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson if (nvlist_lookup_nvlist(userprops, entry->pl_user_prop,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
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);
faaa641552b99562194e991c932a94074682407bEric Schrock * User properties will result in ZPROP_INVAL, and since we
faaa641552b99562194e991c932a94074682407bEric Schrock * only know how to prune standard ZFS properties, we always
faaa641552b99562194e991c932a94074682407bEric Schrock * leave these in the list. This can also happen if we
faaa641552b99562194e991c932a94074682407bEric Schrock * encounter an unknown DSL property (when running older
faaa641552b99562194e991c932a94074682407bEric Schrock * software, for example).
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,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
70f56fa69343b013f47e010537cff8ef3a7a40a5Yuri Pankov if (zfs_ioctl(hdl, ZFS_IOC_USERSPACE_MANY, &zc) != 0) {
70f56fa69343b013f47e010537cff8ef3a7a40a5Yuri Pankov return (zfs_standard_error_fmt(hdl, errno, errbuf));
70f56fa69343b013f47e010537cff8ef3a7a40a5Yuri Pankov if ((ret = func(arg, zua->zu_domain, zua->zu_rid,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens zc.zc_nvlist_dst_size -= sizeof (zfs_useracct_t);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens rv = zfs_iter_filesystems(zhp, zfs_hold_one, ha);
842727c2f41f01b380de4f5e787d905702870f23Chris Kirbyzfs_hold(zfs_handle_t *zhp, const char *snapname, const char *tag,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_hold_one(zfs_handle_dup(zhp), &ha);
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland "cannot hold snapshot '%s@%s'"),
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland (void) zfs_standard_error(zhp->zfs_hdl, ret, errbuf);
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland ret = zfs_hold_nvl(zhp, cleanup_fd, ha.nvl);
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartlandzfs_hold_nvl(zfs_handle_t *zhp, int cleanup_fd, nvlist_t *holds)
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland /* There may be errors even in the success case. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* no hold-specific errors */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens "pool must be upgraded"));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (elem = nvlist_next_nvpair(errors, NULL);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens "cannot hold snapshot '%s'"), nvpair_name(elem));
15508ac067f2fb55a439711838b971c02d42316fChris Kirby * Temporary tags wind up having the ds object id
15508ac067f2fb55a439711838b971c02d42316fChris Kirby * prepended. So even if we passed the length check
15508ac067f2fb55a439711838b971c02d42316fChris Kirby * above, it's still possible for the tag to wind
15508ac067f2fb55a439711838b971c02d42316fChris Kirby * up being slightly too long.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_error(hdl, EZFS_TAGTOOLONG, errbuf);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_error(hdl, EZFS_REFTAG_HOLD, errbuf);
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens if (lzc_get_holds(name, &existing_holds) != 0) {
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens } else if (!nvlist_exists(existing_holds, ha->tag)) {
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens fnvlist_add_nvlist(ha->nvl, name, torelease);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens rv = zfs_iter_filesystems(zhp, zfs_release_one, ha);
842727c2f41f01b380de4f5e787d905702870f23Chris Kirbyzfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_release_one(zfs_handle_dup(zhp), &ha);
013023d4ed2f6d0cf75380ec686a4aac392b4e43Martin Matuska "cannot release hold from snapshot '%s@%s'"),
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens (void) zfs_error(hdl, EZFS_REFTAG_RELE, errbuf);
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland /* There may be errors even in the success case. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* no hold-specific errors */
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens "cannot release"));
842727c2f41f01b380de4f5e787d905702870f23Chris Kirby "pool must be upgraded"));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_standard_error_fmt(hdl, errno, errbuf);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (elem = nvlist_next_nvpair(errors, NULL);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens "cannot release hold from snapshot '%s'"),
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) zfs_error(hdl, EZFS_REFTAG_RELE, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenkozfs_get_fsacl(zfs_handle_t *zhp, nvlist_t **nvl)
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko assert(zhp->zfs_type == ZFS_TYPE_VOLUME ||
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = (zfs_error(hdl, EZFS_NOMEM, strerror(errno)));
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
d7f601ef8b0a2967964481b924713899dcc045bbGeorge Wilson if (ioctl(hdl->libzfs_fd, ZFS_IOC_GET_FSACL, &zc) != 0) {
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko (void) snprintf(errbuf, sizeof (errbuf),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko dgettext(TEXT_DOMAIN, "cannot get permissions on '%s'"),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko "pool must be upgraded"));
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_BADVERSION, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_BADTYPE, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_NOENT, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_standard_error_fmt(hdl, errno, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko int rc = nvlist_unpack(nvbuf, zc.zc_nvlist_dst_size, nvl, 0);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko (void) snprintf(errbuf, sizeof (errbuf), dgettext(
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko TEXT_DOMAIN, "cannot get permissions on '%s'"),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_standard_error_fmt(hdl, rc, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenkozfs_set_fsacl(zfs_handle_t *zhp, boolean_t un, nvlist_t *nvl)
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko assert(zhp->zfs_type == ZFS_TYPE_VOLUME ||
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = nvlist_size(nvl, &nvsz, NV_ENCODE_NATIVE);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = nvlist_pack(nvl, &nvbuf, &nvsz, NV_ENCODE_NATIVE, 0);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko if (zfs_ioctl(hdl, ZFS_IOC_SET_FSACL, &zc) != 0) {
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko (void) snprintf(errbuf, sizeof (errbuf),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko dgettext(TEXT_DOMAIN, "cannot set permissions on '%s'"),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko "pool must be upgraded"));
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_BADVERSION, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_BADTYPE, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_NOENT, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_standard_error_fmt(hdl, errno, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenkozfs_get_holds(zfs_handle_t *zhp, nvlist_t **nvl)
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko (void) snprintf(errbuf, sizeof (errbuf),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko dgettext(TEXT_DOMAIN, "cannot get holds for '%s'"),
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko "pool must be upgraded"));
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_BADVERSION, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_BADTYPE, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_error(hdl, EZFS_NOENT, errbuf);
1af68beac368dae20a9c5d738cf6b6320cf9d63aAlexander Stetsenko err = zfs_standard_error_fmt(hdl, errno, errbuf);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * Convert the zvol's volume size to an appropriate reservation.
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * Note: If this routine is updated, it is necessary to update the ZFS test
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * suite's shell version in reservation.kshlib.
c144956179190829a882ff695f7771ba19f65becEric Taylorzvol_volsize_to_reservation(uint64_t volsize, nvlist_t *props)
c144956179190829a882ff695f7771ba19f65becEric Taylor zfs_prop_to_name(ZFS_PROP_COPIES), &strval) == 0)
c144956179190829a882ff695f7771ba19f65becEric Taylor /* start with metadnode L0-L6 */
c144956179190829a882ff695f7771ba19f65becEric Taylor /* calculate number of indirects */
c144956179190829a882ff695f7771ba19f65becEric Taylor * this is exactly DN_MAX_INDBLKSHIFT when metadata isn't
c144956179190829a882ff695f7771ba19f65becEric Taylor * compressed, but in practice they compress down to about
c144956179190829a882ff695f7771ba19f65becEric Taylor * 1100 bytes