libzfs_dataset.c revision 74e7dc986c89efca1f2e4451c7a572e05e4a6e4f
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
9e6eda553d3d6d77b83da5c596c89990d82bd485marks * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusantestatic int zvol_create_link_common(libzfs_handle_t *, const char *, int);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a single type (not a mask of types), return the type in a human
fa9e4066f08beec538e775443c5be79dd423fcabahrens * readable form.
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a path and mask of ZFS types, return a string describing this dataset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is used when we fail to open a dataset and we cannot get an exact type.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We guess what the type would have been based on the path and the mask of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * acceptable types.
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic const char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When given a single type, always report the exact type.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The user is requesting more than one type of dataset. If this is the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * case, consult the path itself. If we're looking for a snapshot, and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a '@' is found, then report it as "snapshot". Otherwise, remove the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * snapshot attribute and try again.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (path_to_str(path, types & ~ZFS_TYPE_SNAPSHOT));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The user has requested either filesystems or volumes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We have no way of knowing a priori what type this would be, so always
fa9e4066f08beec538e775443c5be79dd423fcabahrens * report it as "filesystem" or "volume", our two primitive types.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Validate a ZFS path. This is used even before trying to open the dataset, to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * provide a more meaningful error message. We place a more useful message in
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 'buf' detailing exactly why the name was not valid.
f18faf3f3e5def85fdfff681617d227703ace2adekzfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
99653d4ee642c6528e88224f12409a5f23060994eschrock "name is too long"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "leading slash in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "empty component in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "trailing slash in name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "multiple '@' delimiters in name"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "pool doesn't begin with a letter"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "name is reserved"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "reserved disk name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshot delimiter '@' in filesystem name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "missing '@' delimiter in snapshot name"));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (0);
f18faf3f3e5def85fdfff681617d227703ace2adek return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * This function takes the raw DSL properties, and filters out the user-defined
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * properties into a separate nvlist.
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrockprocess_user_props(zfs_handle_t *zhp, nvlist_t *props)
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock if (nvlist_add_nvlist(nvl, nvpair_name(elem), propval) != 0) {
29ab75c9a733dad2978c4860efd954b5625e3467rmzpool_add_handle(zfs_handle_t *zhp, const char *pool_name)
29ab75c9a733dad2978c4860efd954b5625e3467rm if ((zph = zpool_open_canfail(hdl, pool_name)) != NULL) {
29ab75c9a733dad2978c4860efd954b5625e3467rmzpool_find_handle(zfs_handle_t *zhp, const char *pool_name, int len)
29ab75c9a733dad2978c4860efd954b5625e3467rm * Returns a handle to the pool that contains the provided dataset.
29ab75c9a733dad2978c4860efd954b5625e3467rm * If a handle to that pool already exists then that handle is returned.
29ab75c9a733dad2978c4860efd954b5625e3467rm * Otherwise, a new handle is created and added to the list of handles.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Utility function to gather stats (objset and zpl) for the given object.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock while (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock return (-1);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens zhp->zfs_dmustats = zc.zc_objset_stats; /* structure assignment */
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock if (zcmd_read_dst_nvlist(hdl, &zc, &allprops) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock if ((userprops = process_user_props(zhp, allprops)) == NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
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.
99653d4ee642c6528e88224f12409a5f23060994eschrockmake_dataset_handle(libzfs_handle_t *hdl, const char *path)
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Preserve history log string.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * any changes performed here will be
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * logged as an internal event.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name));
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * If it is dds_inconsistent, then we've caught it in
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * the middle of a 'zfs receive' or 'zfs destroy', and
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * it is inconsistent from the ZPL's point of view, so
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * can't be mounted. However, it could also be that we
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * have crashed in the middle of one of those
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * operations, in which case we need to get rid of the
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * inconsistent state. We do that by either rolling
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * back to the previous snapshot (which will fail if
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * there is none), or destroying the filesystem. Note
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * that if we are still in the middle of an active
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * 'receive' or 'destroy', then the rollback and destroy
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * will fail with EBUSY and we will drive on as usual.
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If we can successfully destroy it, pretend that it
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * never existed.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc) == 0) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* If we can successfully roll it back, reget the stats */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (ioctl(hdl->libzfs_fd, ZFS_IOC_ROLLBACK, &zc) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We've managed to open the dataset and gather statistics. Determine
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the high-level type.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Opens the given snapshot, filesystem, or volume. The 'types'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * argument is a mask of acceptable types. The function will print an
fa9e4066f08beec538e775443c5be79dd423fcabahrens * appropriate error message and return NULL if it can't be opened.
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_open(libzfs_handle_t *hdl, const char *path, int types)
99653d4ee642c6528e88224f12409a5f23060994eschrock * Validate the name before we even try to open it.
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, path, ZFS_TYPE_DATASET, B_FALSE)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "invalid dataset name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Try to get stats for the dataset, which will tell us if it exists.
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = make_dataset_handle(hdl, path)) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Release a ZFS handle. Nothing to do but free the associated memory.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (0);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * The choice of reservation property depends on the SPA version.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rmzfs_which_resv_prop(zfs_handle_t *zhp, zfs_prop_t *resv_prop)
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Given an nvlist of properties to set, validates that they are correct, and
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * parses any numeric properties (index, boolean, etc) if they are specified as
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhzfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
990b4856d0eaada6f8140335733a1b1771ed2746lling uint64_t zoned, zfs_handle_t *zhp, const char *errbuf)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Make sure this property is valid and applies to this type.
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
990b4856d0eaada6f8140335733a1b1771ed2746lling * If 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) {
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens "this property can not be modified for snapshots"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Perform some additional checks for specific properties.
e7437265dc2a4920c197ed4337665539d358b22cahrens "Can not downgrade; already at version %u"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock /* must be power of two within SPA_{MIN,MAX}BLOCKSIZE */
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be power of 2 from %u "
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl "'%s' must be 'on', 'off', or 'type=disk'"),
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm switch (why) {
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm "'%s' must be an absolute path, "
89eef05efc3ad959ce1fcc4fbf4d428b4fc015adrm "component of '%s' is too long"),
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl /*FALLTHRU*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * For the mountpoint and sharenfs or sharesmb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties, check if it can be set in a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * global/non-global zone based on
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * the zoned property value:
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * global zone non-global zone
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * --------------------------------------------------
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * zoned=on mountpoint (no) mountpoint (yes)
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * sharenfs (no) sharenfs (no)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sharesmb (no) sharesmb (no)
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * zoned=off mountpoint (yes) N/A
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * sharenfs (yes)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sharesmb (yes)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be set on "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "dataset in a non-global zone"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be set in "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If zoned property is 'off', this must be in
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * a globle zone. If not, something is wrong.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be set while dataset "
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * At this point, it is legitimate to set the
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * property. Now we want to make sure that the
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * property value is valid if it is sharenfs.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Must be an valid sharing protocol
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * option string so init the libshare
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in order to enable the parser and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * then parse the options. We use the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * control API since we don't care about
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the current configuration and don't
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * want the overhead of loading it
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * until we actually do something.
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * An error occurred so we can't do
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock "'%s' cannot be set: problem "
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock "in share initialization"),
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * There was an error in parsing so
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * deal with it by issuing an error
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * message and leaving after
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * uninitializing the the libshare
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock * interface.
fac3008cc3156093d29951128c236e1a6c4bc0e8eschrock "'%s' cannot be set to invalid "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * For changes to existing volumes, we have some additional
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * checks to enforce.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' is greater than current "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a multiple of "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume block size (%s)"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' cannot be zero"),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If normalization was chosen, but no UTF8 choice was made,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * enforce rejection of non-UTF8 names.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If normalization was chosen, but rejecting non-UTF8 names
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * was explicitly not chosen, it is an error.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "'%s' must be set 'on' if normalization chosen"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If this is an existing volume, and someone is setting the volsize,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * make sure that it matches the reservation, or add it if necessary.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock nvlist_lookup_uint64(ret, zfs_prop_to_name(ZFS_PROP_VOLSIZE),
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_get_perm_who(const char *who, zfs_deleg_who_type_t *who_type,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (*who_type == ZFS_DELEG_EVERYONE || *who_type == ZFS_DELEG_CREATE ||
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (who == NULL && !(*who_type == ZFS_DELEG_EVERYONE))
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks } else if (pwd) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks } else if (grp) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_perms_add_to_nvlist(nvlist_t *who_nvp, char *name, nvlist_t *perms_nvp)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkshelper(zfs_deleg_who_type_t who_type, uint64_t whoid, char *whostr,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks zfs_deleg_inherit_t inherit, nvlist_t *who_nvp, nvlist_t *perms_nvp,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks do_perms = (nvlist_next_nvpair(perms_nvp, NULL) != NULL);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks do_sets = (nvlist_next_nvpair(sets_nvp, NULL) != NULL);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_perms_add_who_nvlist(nvlist_t *who_nvp, uint64_t whoid, void *whostr,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks zfs_deleg_who_type_t who_type, zfs_deleg_inherit_t inherit)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (who_type == ZFS_DELEG_NAMED_SET || who_type == ZFS_DELEG_CREATE) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Construct nvlist to pass down to kernel for setting/removing permissions.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * The nvlist is constructed as a series of nvpairs with an optional embedded
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * nvlist of permissions to remove or set. The topmost nvpairs are the actual
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * base attribute named stored in the dsl.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Arguments:
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * whostr: is a comma separated list of users, groups, or a single set name.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * whostr may be null for everyone or create perms.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * who_type: is the type of entry in whostr. Typically this will be
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * ZFS_DELEG_WHO_UNKNOWN.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * perms: common separated list of permissions. May be null if user
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * is requested to remove permissions by who.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * inherit: Specifies the inheritance of the permissions. Will be either
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * ZFS_DELEG_PERM_LOCAL and/or ZFS_DELEG_PERM_DESCENDENT.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * nvp The constructed nvlist to pass to zfs_perm_set().
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * The output nvp will look something like this.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * ul$1234 -> {create ; destroy }
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Ul$1234 -> { @myset }
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * s-$@myset - { snapshot; checksum; compression }
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_build_perms(zfs_handle_t *zhp, char *whostr, char *perms,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks zfs_deleg_who_type_t who_type, zfs_deleg_inherit_t inherit, nvlist_t **nvp)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((error = nvlist_alloc(&who_nvp, NV_UNIQUE_NAME, 0)) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((error = permset_namecheck(whostr, &why, &what)) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks switch (why) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "set definition must begin with an '@' "
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "character"));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Build up nvlist(s) of permissions. Two nvlists are maintained.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * The first nvlist perms_nvp will have normal permissions and the
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * other sets_nvp will have only permssion set names in it.
91ebeef555ce7f899b6270a3c2df47b51f7ad59aahrens for (perm = strtok(perms, ","); perm; perm = strtok(NULL, ",")) {
91ebeef555ce7f899b6270a3c2df47b51f7ad59aahrens const char *perm_canonical = zfs_deleg_canonicalize_perm(perm);
91ebeef555ce7f899b6270a3c2df47b51f7ad59aahrens return (zfs_error(zhp->zfs_hdl, EZFS_BADPERM, perm));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_error(zhp->zfs_hdl, EZFS_BADWHO, errbuf));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Now create the nvlist(s)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "Unable to determine uid/gid for "
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_error(zhp->zfs_hdl, EZFS_BADWHO, errbuf));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * add entries for both local and descendent when required
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_perm_set_common(zfs_handle_t *zhp, nvlist_t *nvp, boolean_t unset)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks dgettext(TEXT_DOMAIN, "Cannot update 'allows' for '%s'"),
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks error = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SET_FSACL, &zc);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks gettext("Pool must be upgraded to use 'allow/unallow'"));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_error(zhp->zfs_hdl, EZFS_BADVERSION, errbuf));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks } else if (error) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (zfs_standard_error(zhp->zfs_hdl, errno, errbuf));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens while ((permnode = avl_destroy_nodes(tree, &cookie)) != NULL)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks while ((allownode = avl_destroy_nodes(tree, &cookie)) != NULL) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_alloc_perm_tree(zfs_handle_t *zhp, zfs_allow_t *prev, char *setpoint)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(ptree->z_setpoint, setpoint, sizeof (ptree->z_setpoint));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Add permissions to the appropriate AVL permission tree.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * The appropriate tree may not be the requested tree.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * For example if ld indicates a local permission, but
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * same permission also exists as a descendent permission
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * then the permission will be removed from the descendent
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * tree and add the the local+descendent tree.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_coalesce_perm(zfs_handle_t *zhp, zfs_allow_node_t *allownode,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(pnode.z_pname, perm, sizeof (pnode.z_pname));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Now insert new permission in either requested location
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * local/descendent or into ld when perm will exist in both.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Uggh, this is going to be a bit complicated.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * we have an nvlist coming out of the kernel that
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * will indicate where the permission is set and then
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * it will contain allow of the various "who's", and what
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * their permissions are. To further complicate this
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * we will then have to coalesce the local,descendent
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * and local+descendent permissions where appropriate.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * The kernel only knows about a permission as being local
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * or descendent, but not both.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * In order to make this easier for zfs_main to deal with
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * a series of AVL trees will be used to maintain
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * all of this, primarily for sorting purposes as well
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * as the ability to quickly locate a specific entry.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * What we end up with are tree's for sets, create perms,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * user, groups and everyone. With each of those trees
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * we have subtrees for local, descendent and local+descendent
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * permissions.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_perm_get(zfs_handle_t *zhp, zfs_allow_t **zfs_perms)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks while (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_GET_FSACL, &zc) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &nvlist) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks *zfs_perms = zfs_alloc_perm_tree(zhp, NULL, nvpair_name(source_pair));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((error = nvpair_value_nvlist(source_pair, &sourcenv)) != 0)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Make sure nvlist is composed correctly
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * First build up the key to use
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * for looking up in the various
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * who trees.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Place who in tree
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Now iterate over the permissions and
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * place them in the appropriate local,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * descendent or local+descendent tree.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * The permissions are added to the tree
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * via zfs_coalesce_perm().
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks } while (who_pair = nvlist_next_nvpair(sourcenv, who_pair));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks source_pair = nvlist_next_nvpair(nvlist, source_pair);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * allocate another node from the link list of
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * zfs_allow_t structures
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marksstatic char *
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks * Don't put newlines on end of lines
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Must also have the 'mount' ability"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Must also have the 'mount' ability"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Must also have the 'mount' ability"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Must also have the 'mount' ability"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks return (dgettext(TEXT_DOMAIN, "Must also have the 'create' "
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "ability and 'mount'\n"
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "\t\t\t\tability in the origin file system"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'\n"
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "\t\t\t\tand 'promote' ability in the origin file system"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks return (dgettext(TEXT_DOMAIN, "Must also have the 'mount' "
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "and 'create' \n\t\t\t\tability in the new parent"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'"
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks " and 'create' ability"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Allows changing any user property"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Must also have the permission that is being\n"
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "\t\t\t\tallowed"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Allows mount/umount of ZFS datasets"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "Allows sharing file systems over NFS or SMB\n"
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks "\t\t\t\tprotocols"));
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1markstypedef enum {
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks * is the permission a subcommand or other?
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marksstatic char *
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks return ("");
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks/*ARGSUSED*/
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks (void) fprintf(stderr, "%-15s %-15s\n", zfs_prop_to_name(prop),
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks (void) fprintf(stderr, "\n%-15s %-15s\t%s\n\n", "NAME",
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks * First print out the subcommands
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks for (i = 0; zfs_deleg_perm_tab[i].z_perm != NULL; i++) {
6949a980ded6490cd1bcf4a93a1d074d46d9a6c1marks (void) zprop_iter(zfs_deleg_prop_cb, NULL, B_FALSE, B_TRUE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a property name and value, set the property for the given dataset.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if ((realprops = zfs_valid_proplist(hdl, zhp->zfs_type, nvl,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, errbuf)) == NULL)
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "child dataset with inherited mountpoint is used "
99653d4ee642c6528e88224f12409a5f23060994eschrock "in a non-global zone"));
a227b7f4f323ad89c40a86c430a5e891504a8e8bhs /* do not unmount dataset if canmount is being set to noauto */
a227b7f4f323ad89c40a86c430a5e891504a8e8bhs if (prop == ZFS_PROP_CANMOUNT && *propval == ZFS_CANMOUNT_NOAUTO)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Execute the corresponding ioctl() to set this property.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * For quotas and reservations, ENOSPC indicates
fa9e4066f08beec538e775443c5be79dd423fcabahrens * something different; setting a quota or reservation
fa9e4066f08beec538e775443c5be79dd423fcabahrens * doesn't use any disk space.
99653d4ee642c6528e88224f12409a5f23060994eschrock "size is less than current used or "
99653d4ee642c6528e88224f12409a5f23060994eschrock "reserved space"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "size is greater than available space"));
9e6eda553d3d6d77b83da5c596c89990d82bd485marks "pool and or dataset must be upgraded to set this "
40feaa914945406e86e193599d115ea71a171d18ahrens "property or value"));
15e6edf145a9c2bb0e0272cf8debe823bb97529bgw "property setting is not allowed on "
15e6edf145a9c2bb0e0272cf8debe823bb97529bgw "bootable datasets"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This platform can't address a volume this big.
99653d4ee642c6528e88224f12409a5f23060994eschrock /* FALLTHROUGH */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Refresh the statistics so the new property value
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is reflected.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a property, inherit the value from the parent dataset.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_prop_inherit(zfs_handle_t *zhp, const char *propname)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "cannot inherit %s for '%s'"), propname, zhp->zfs_name);
990b4856d0eaada6f8140335733a1b1771ed2746lling if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * For user properties, the amount of work we have to do is very
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * small, so just do it here.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "invalid property"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Verify that this property is inheritable.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (zfs_error(hdl, EZFS_PROPREADONLY, errbuf));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (zfs_error(hdl, EZFS_PROPNONINHERIT, errbuf));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if the value applies to this type
bf7c2d400a7b538aed6f356c7107284378a19fa8rm * Normalize the name, to get rid of shorthand abbrevations.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && getzoneid() == GLOBAL_ZONEID &&
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset is used in a non-global zone"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Determine datasets which will be affected by this change, if any.
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "child dataset with inherited mountpoint is used "
99653d4ee642c6528e88224f12409a5f23060994eschrock "in a non-global zone"));
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc)) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Refresh the statistics so the new property is reflected.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * True DSL properties are stored in an nvlist. The following two functions
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * extract them appropriately.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockgetprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
990b4856d0eaada6f8140335733a1b1771ed2746lling verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
990b4856d0eaada6f8140335733a1b1771ed2746lling (void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockstatic char *
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockgetprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
990b4856d0eaada6f8140335733a1b1771ed2746lling verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
990b4856d0eaada6f8140335733a1b1771ed2746lling (void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock if ((value = (char *)zfs_prop_default_string(prop)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Internal function for getting a numeric property. Both zfs_prop_get() and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_prop_get_int() are built using this interface.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Certain properties can be overridden using 'mount -o'. In this case, scan
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the contents of the /etc/mnttab entry, searching for the appropriate options.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If they differ from the on-disk values, report the current values and mark
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the source "temporary".
990b4856d0eaada6f8140335733a1b1771ed2746llingget_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock * Because looking up the mount options is potentially expensive
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock * (iterating over all of /etc/mnttab), we defer its calculation until
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock * we're looking up a property which requires its presence.
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens return (-1);
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (!zfs_prop_valid_for_type(prop, zhp->zfs_head_type) ||
3d7934e1eaaab784a1928c5c9bdb6273eeb7275drm return (-1);
bd00f61bf62a14e7e8914ca126c52af5c38e94e1rm (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_OBJSET_ZPLPROPS, &zc)) {
de8267e0f723ed2c38ea9def92d465f69a300f56timh "unable to get %s property"),
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &zplprops) != 0 ||
de8267e0f723ed2c38ea9def92d465f69a300f56timh "unable to get %s property"),
74e7dc986c89efca1f2e4451c7a572e05e4a6e4fMatthew Ahrens * If we tried to use a defalut value for a
74e7dc986c89efca1f2e4451c7a572e05e4a6e4fMatthew Ahrens * readonly property, it means that it was not
74e7dc986c89efca1f2e4451c7a572e05e4a6e4fMatthew Ahrens * present; return an error.
e7437265dc2a4920c197ed4337665539d358b22cahrens "cannot get non-numeric property"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Calculate the source type, given the raw source string.
990b4856d0eaada6f8140335733a1b1771ed2746llingget_source(zfs_handle_t *zhp, zprop_source_t *srctype, char *source,
990b4856d0eaada6f8140335733a1b1771ed2746lling if (statbuf == NULL || *srctype == ZPROP_SRC_TEMPORARY)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Retrieve a property from the given object. If 'literal' is specified, then
fa9e4066f08beec538e775443c5be79dd423fcabahrens * numbers are left as exact values. Otherwise, numbers are converted to a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * human-readable form.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns 0 on success, or -1 on error.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
990b4856d0eaada6f8140335733a1b1771ed2746lling zprop_source_t *src, char *statbuf, size_t statlen, boolean_t literal)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock const char *strval;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if this property applies to our object
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 'creation' is a time_t stored in the statistics. We convert
fa9e4066f08beec538e775443c5be79dd423fcabahrens * this into a string unless 'literal' is specified.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Getting the precise mountpoint can be tricky.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * - for 'none' or 'legacy', return those values.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * - for inherited mountpoints, we want to take everything
fa9e4066f08beec538e775443c5be79dd423fcabahrens * after our ancestor and append it to the inherited value.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the pool has an alternate root, we want to prepend that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * root to any values we return.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock const char *relpath = zhp->zfs_name + strlen(source);
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * Special case an alternate root of '/'. This will
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * avoid having multiple leading slashes in the
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * mountpoint path.
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * If the mountpoint is '/' then skip over this
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * if we are obtaining either an alternate root or
b21718f06a7f8468913c84002f8381a5ee1cb8c4gw * an inherited mountpoint.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* 'legacy' or 'none' */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) strlcpy(propbuf, getprop_string(zhp, prop, &source),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If there is no parent at all, return failure to indicate that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * it doesn't apply to this dataset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If quota or reservation is 0, we translate this into 'none'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (unless literal is set), and indicate that it's the default
fa9e4066f08beec538e775443c5be79dd423fcabahrens * value. Otherwise, we print the number nicely and indicate
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that its set locally.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (val == 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
5ad820458efd0fdb914baff9c1447c22b819fa23nd (void) snprintf(propbuf, proplen, "%lld.%02lldx", (longlong_t)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The 'mounted' property is a pseudo-property that described
fa9e4066f08beec538e775443c5be79dd423fcabahrens * whether the filesystem is currently mounted. Even though
fa9e4066f08beec538e775443c5be79dd423fcabahrens * it's a boolean value, the typical values of "on" and "off"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * don't make sense, so we translate to "yes" and "no".
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The 'name' property is a pseudo-property derived from the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dataset name. It is presented as a real property to simplify
fa9e4066f08beec538e775443c5be79dd423fcabahrens * consumers.
e7437265dc2a4920c197ed4337665539d358b22cahrens return (-1);
fe192f767b9104ea1c90dc1eb713f2e3773e8f81ahrens return (-1);
fe192f767b9104ea1c90dc1eb713f2e3773e8f81ahrens if (zfs_prop_index_to_string(prop, val, &strval) != 0)
e7437265dc2a4920c197ed4337665539d358b22cahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Utility function to get the given numeric property. Does no validation that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the given property is the appropriate type; should only be used with
fa9e4066f08beec538e775443c5be79dd423fcabahrens * hard-coded property types.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (void) get_numeric_property(zhp, prop, NULL, &source, &val);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rmzfs_prop_set_int(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t val)
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);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns the name of the given zfs handle.
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns the type of the given zfs handle.
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * Iterate over all child filesystems
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockzfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for ((void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_DATASET_LIST_NEXT, &zc) == 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Ignore private dataset names.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Silently ignore errors, as the only plausible explanation is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that the pool has since been removed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * An errno value of ESRCH indicates normal completion. If ENOENT is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * returned, then the underlying dataset has been removed since we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * obtained the handle.
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot iterate filesystems")));
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock return (0);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * Iterate over all snapshots
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockzfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for ((void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SNAPSHOT_LIST_NEXT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * An errno value of ESRCH indicates normal completion. If ENOENT is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * returned, then the underlying dataset has been removed since we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * obtained the handle. Silently ignore this case, and return success.
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot iterate filesystems")));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock * Iterate over all children, snapshots and filesystems
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockzfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data)
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a complete name, return just the portion that refers to the parent.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can return NULL if this is a pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrensparent_name(const char *path, char *buf, size_t buflen)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * If accept_ancestor is false, then check to make sure that the given path has
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * a parent, and that it exists. If accept_ancestor is true, then find the
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * closest existing ancestor for the given path. In prefixlen return the
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * length of already existing prefix of the given path. We also fetch the
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * 'zoned' property, which is used to validate property settings when creating
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * new datasets.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbcheck_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned,
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), "cannot create '%s'",
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get parent, and check to see if this is just a pool */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (parent_name(path, parent, sizeof (parent)) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "missing dataset name"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check to see if the pool exists */
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0 &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check to see if the parent dataset exists */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb while ((zhp = make_dataset_handle(hdl, parent)) == NULL) {
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Go deeper to find an ancestor, give up on top level.
99653d4ee642c6528e88224f12409a5f23060994eschrock "parent does not exist"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* we are in a non-global zone, but parent is in the global zone */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure parent is a filesystem */
99653d4ee642c6528e88224f12409a5f23060994eschrock "parent is not a filesystem"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb return (0);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Finds whether the dataset of the given type(s) exists.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbzfs_dataset_exists(libzfs_handle_t *hdl, const char *path, zfs_type_t types)
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Try to get stats for the dataset, which will tell us if it exists.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Given a path to 'target', create all the ancestors between
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * the prefixlen portion of the path, and the target itself.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Fail if the initial prefixlen-ancestor does not already exist.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrenscreate_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens const char *opname;
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* make sure prefix exists */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (-1);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * Attempt to create, mount, and share any ancestor filesystems,
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * up to the prefixlen-long one.
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* it already exists, nothing to do here */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (h == NULL) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (zfs_share(h) != 0) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (-1);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb * Creates non-existing ancestors of the given path.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbzfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, path, &zoned, B_TRUE, &prefix) != 0)
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb return (-1);
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Create a new filesystem or volume.
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type,
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t blocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate the path, taking care to note the extended error message */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents exist */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, path, &zoned, B_FALSE, NULL) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The failure modes when creating a dataset of a different type over
fa9e4066f08beec538e775443c5be79dd423fcabahrens * one that already exists is a little strange. In particular, if you
fa9e4066f08beec538e775443c5be79dd423fcabahrens * try to create a dataset on top of an existing dataset, the ioctl()
fa9e4066f08beec538e775443c5be79dd423fcabahrens * will return ENOENT, not EEXIST. To prevent this from happening, we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * first try to see if the dataset exists.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, path, sizeof (zc.zc_name));
990b4856d0eaada6f8140335733a1b1771ed2746lling if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset already exists"));
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if (props && (props = zfs_valid_proplist(hdl, type, props,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * If we are creating a volume, the size and block size must
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * satisfy a few restraints. First, the blocksize must be a
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * valid block size between SPA_{MIN,MAX}BLOCKSIZE. Second, the
5c5460e9570bdcad6b03b01c30ceb683a77ceb88eschrock * volsize must be a multiple of the block size, and cannot be
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "missing volume size"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "missing volume block size"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (size == 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume size cannot be zero"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume size must be a multiple of volume block "
990b4856d0eaada6f8140335733a1b1771ed2746lling if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the dataset */
b1b8ab34de515a5e83206da22c3d7e563241b021lling "Volume successfully created, but device links "
b1b8ab34de515a5e83206da22c3d7e563241b021lling "were not created"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check for failure */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "volume block size must be power of 2 from "
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "%u to %uk"),
40feaa914945406e86e193599d115ea71a171d18ahrens "pool must be upgraded to set this "
40feaa914945406e86e193599d115ea71a171d18ahrens "property or value"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This platform can't address a volume this big.
99653d4ee642c6528e88224f12409a5f23060994eschrock /* FALLTHROUGH */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Destroys the given dataset. The caller must make sure that the filesystem
fa9e4066f08beec538e775443c5be79dd423fcabahrens * isn't mounted, and that there are no active dependents.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * If user doesn't have permissions to unshare volume, then
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * abort the request. This would only happen for a
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * non-privileged user.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY, &zc) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(name, zhp->zfs_name, sizeof (name));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * NB: this is simply a best-effort. We don't want to
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * return an error, because then we wouldn't visit all
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * the volumes.
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens rv = zfs_iter_filesystems(zhp, zfs_remove_link_cb, arg);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * Destroys all snapshots with the given name in zhp & descendants.
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS, &zc);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (ret != 0) {
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens "snapshot is cloned"));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (zfs_error(zhp->zfs_hdl, EZFS_EXISTS, errbuf));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Clones the given dataset. The target must be of the same type as the source.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate the target name */
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM, B_TRUE))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents exist */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, target, &zoned, B_FALSE, NULL) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* do the clone */
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimh if ((props = zfs_valid_proplist(hdl, type, props, zoned,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, target, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, zhp->zfs_name, sizeof (zc.zc_value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The parent doesn't exist. We should have caught this
fa9e4066f08beec538e775443c5be79dd423fcabahrens * above, but there may a race condition that has since
fa9e4066f08beec538e775443c5be79dd423fcabahrens * destroyed the parent.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * At this point, we don't know whether it's the source
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that doesn't exist anymore, or whether the target
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dataset doesn't exist.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf));
99653d4ee642c6528e88224f12409a5f23060994eschrock "source and target pools differ"));
99653d4ee642c6528e88224f12409a5f23060994eschrocktypedef struct promote_data {
99653d4ee642c6528e88224f12409a5f23060994eschrock /* We don't care about snapshots after the pivot point */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > pd->cb_pivot_txg) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
0b69c2f001a429251e2d38f25aca860396551214ahrens /* Remove the device link if it's a zvol. */
0b69c2f001a429251e2d38f25aca860396551214ahrens (void) zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name);
99653d4ee642c6528e88224f12409a5f23060994eschrock /* Check for conflicting names */
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(snapname, pd->cb_target, sizeof (snapname));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcat(snapname, strchr(zhp->zfs_name, '@'), sizeof (snapname));
99653d4ee642c6528e88224f12409a5f23060994eschrock szhp = make_dataset_handle(zhp->zfs_hdl, snapname);
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshot name '%s' from origin \n"
99653d4ee642c6528e88224f12409a5f23060994eschrock "conflicts with '%s' from target"),
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens rv = zfs_error(zhp->zfs_hdl, EZFS_EXISTS, pd->cb_errbuf);
0b69c2f001a429251e2d38f25aca860396551214ahrens /* We don't care about snapshots after the pivot point */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) <= pd->cb_pivot_txg) {
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens /* Create the device link if it's a zvol. */
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens (void) zvol_create_link(zhp->zfs_hdl, zhp->zfs_name);
0b69c2f001a429251e2d38f25aca860396551214ahrens return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock * Promotes the given clone fs to be the clone parent.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshots can not be promoted"));
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
99653d4ee642c6528e88224f12409a5f23060994eschrock "not a cloned filesystem"));
99653d4ee642c6528e88224f12409a5f23060994eschrock /* Walk the snapshots we will be moving */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens pzhp = zfs_open(hdl, zhp->zfs_dmustats.dds_origin, ZFS_TYPE_SNAPSHOT);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock pd.cb_pivot_txg = zfs_prop_get_int(pzhp, ZFS_PROP_CREATETXG);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) zfs_prop_get(pzhp, ZFS_PROP_MOUNTPOINT, pd.cb_mountpoint,
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = zfs_iter_snapshots(pzhp, promote_snap_cb, &pd);
0b69c2f001a429251e2d38f25aca860396551214ahrens if (ret != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock /* issue the ioctl */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens (void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ret != 0) {
0b69c2f001a429251e2d38f25aca860396551214ahrens (void) zfs_iter_snapshots(pzhp, promote_snap_done_cb, &pd);
99653d4ee642c6528e88224f12409a5f23060994eschrock * There is a conflicting snapshot name. We
99653d4ee642c6528e88224f12409a5f23060994eschrock * should have caught this above, but they could
99653d4ee642c6528e88224f12409a5f23060994eschrock * have renamed something in the mean time.
99653d4ee642c6528e88224f12409a5f23060994eschrock "conflicting snapshot name from parent '%s'"),
0b69c2f001a429251e2d38f25aca860396551214ahrens return (zfs_standard_error(hdl, save_errno, errbuf));
0b69c2f001a429251e2d38f25aca860396551214ahrens (void) zfs_iter_snapshots(zhp, promote_snap_done_cb, &pd);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(name, zhp->zfs_name, sizeof (name));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) strlcat(name, cd->cd_snapname, sizeof (name));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * NB: this is simply a best-effort. We don't want to
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * return an error, because then we wouldn't visit all
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * the volumes.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhp, zfs_create_link_cb, cd);
72bdce51192b13a20009855f749004480874291bahl * Takes a snapshot of the given dataset.
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrenszfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *delim;
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock /* validate the target name */
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT, B_TRUE))
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens if ((props = zfs_valid_proplist(hdl, ZFS_TYPE_SNAPSHOT,
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens return (-1);
bb0ade0978a02d3fe0b0165cd4725fdcb593fbfbahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure the parent exists and is of the appropriate type */
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = zfs_open(hdl, parent, ZFS_TYPE_FILESYSTEM |
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, delim+1, sizeof (zc.zc_value));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * if it was recursive, the one that actually failed will be in
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * zc.zc_name.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "cannot create snapshot '%s@%s'"), zc.zc_name, zc.zc_value);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) zfs_iter_filesystems(zhp, zfs_create_link_cb, &cd);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens if (ret != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "Volume successfully snapshotted, but device links "
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks "were not created"));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Destroy any more recent snapshots. We invoke this callback on any dependents
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * of the snapshot first. If the 'cb_dependent' member is non-zero, then this
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * is a dependent and we should just destroy it without checking the transaction
b12a1c38fc215cc54fa6014069fd2b8dbb496646llingtypedef struct rollback_data {
c391e322108d10533bc61ba3ef7099b302214341ahrens /* We must destroy this clone; first unmount it */
c391e322108d10533bc61ba3ef7099b302214341ahrens return (0);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling return (0);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Given a dataset, rollback to a specific snapshot, discarding any
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * data changes since then and making it the active dataset.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Any snapshots more recent than the target are destroyed, along with
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * their dependents.
c391e322108d10533bc61ba3ef7099b302214341ahrenszfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Destroy all recent snapshots and its dependends.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
c391e322108d10533bc61ba3ef7099b302214341ahrens return (-1);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Now that we have verified that the snapshot is the latest,
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * rollback to the given snapshot.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm return (-1);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * We rely on zfs_iter_children() to verify that there are no
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * newer snapshots for the given dataset. Therefore, we can
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * simply pass the name on to the ioctl() call. There is still
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * an unlikely race condition where the user has taken a
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * snapshot since we verified that this was the most recent.
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens if ((err = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_ROLLBACK, &zc)) != 0) {
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * For volumes, if the pre-rollback volsize matched the pre-
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * rollback reservation and the volsize has changed then set
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * the reservation property to the post-rollback volsize.
7b97dc1abb536bd13204496f8ae5a6f2fe9f2fb3rm * Make a new handle since the rollback closed the dataset.
b9415e832db4ec89116104788643227b77ed508arm (zhp = make_dataset_handle(zhp->zfs_hdl, zhp->zfs_name))) {
b9415e832db4ec89116104788643227b77ed508arm if (err = zvol_create_link(zhp->zfs_hdl, zhp->zfs_name)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all dependents for a given dataset. This includes both
fa9e4066f08beec538e775443c5be79dd423fcabahrens * hierarchical dependents (children) and data dependents (snapshots and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * clones). The bulk of the processing occurs in get_dependents() in
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrockzfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock if (get_dependents(zhp->zfs_hdl, allowrecursion, zhp->zfs_name,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < count; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < count; i++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Renames the given dataset.
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vbzfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* if we have the same exact name, just return success */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure the target name is valid
98579b20de8e05c5117968705a18979f8b75b863nd * Snapshot target name is abbreviated,
98579b20de8e05c5117968705a18979f8b75b863nd * reconstruct full dataset name
98579b20de8e05c5117968705a18979f8b75b863nd sizeof (parent));
98579b20de8e05c5117968705a18979f8b75b863nd * Make sure we're renaming within the same dataset.
98579b20de8e05c5117968705a18979f8b75b863nd "snapshots must be part of same "
98579b20de8e05c5117968705a18979f8b75b863nd "dataset"));
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "recursive rename must be a snapshot"));
f18faf3f3e5def85fdfff681617d227703ace2adek if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents */
7f1f55ea3af0e6153a8ee9316c7f0b8b4f1ba773vb if (check_parents(hdl, target, &unused, B_FALSE, NULL) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure we're in the same pool */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (strncmp(zhp->zfs_name, target, delim - target) != 0 ||
99653d4ee642c6528e88224f12409a5f23060994eschrock "datasets must be within same pool"));
f2fdf992e7f966d7f6d0c41679a1058bf225a936nd /* new name cannot be a child of the current dataset name */
f2fdf992e7f966d7f6d0c41679a1058bf225a936nd "New dataset name cannot be a descendent of "
f2fdf992e7f966d7f6d0c41679a1058bf225a936nd "current dataset name"));
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot rename '%s'"), zhp->zfs_name);
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset is used in a non-global zone"));
f0c5ee210eebf913b19e8715470ed4fe669425a4mmusante parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
990b4856d0eaada6f8140335733a1b1771ed2746lling zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* We remove any zvol links prior to renaming them */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhrp, zfs_remove_link_cb, &dd);
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0)) == NULL)
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (-1);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "child dataset with inherited mountpoint is used "
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "in a non-global zone"));
98579b20de8e05c5117968705a18979f8b75b863nd (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_RENAME, &zc)) != 0) {
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * if it was recursive, the one that actually failed will
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * be in zc.zc_name
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "a child dataset already has a snapshot "
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "with the new name"));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * On failure, we still want to remount any filesystems that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * were previously mounted, so we don't alter the system state.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* only create links for datasets that had existed */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante (void) zfs_iter_filesystems(zhrp, zfs_create_link_cb,
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* only create links for datasets that had existed */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhrp, zfs_create_link_cb,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a zvol dataset, issue the ioctl to create the appropriate minor node,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * poke devfsadm to create the /dev link, and then wait for the link to appear.
99653d4ee642c6528e88224f12409a5f23060994eschrockzvol_create_link(libzfs_handle_t *hdl, const char *dataset)
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (zvol_create_link_common(hdl, dataset, B_FALSE));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusantezvol_create_link_common(libzfs_handle_t *hdl, const char *dataset, int ifexists)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Issue the appropriate ioctl.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_CREATE_MINOR, &zc) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Silently ignore the case where the link already
fa9e4066f08beec538e775443c5be79dd423fcabahrens * exists. This allows 'zfs volinit' to be run multiple
fa9e4066f08beec538e775443c5be79dd423fcabahrens * times without errors.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * Dataset does not exist in the kernel. If we
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * don't care (see zfs_rename), then ignore the
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante * error quietly.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (0);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* FALLTHROUGH */
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot create device links "
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * If privileged call devfsadm and wait for the links to
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * magically appear.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * Otherwise, print out an informational message.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks privileged = (priv_isfullset(priv_effective) == B_TRUE);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * This is the poor mans way of waiting for the link
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * to show up. If after 10 seconds we still don't
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks * have it, then print out a message.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) snprintf(pathname, sizeof (pathname), "/dev/zvol/dsk/%s",
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks for (i = 0; i != MAX_WAIT; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove a minor node for the given zvol and the associated /dev links.
99653d4ee642c6528e88224f12409a5f23060994eschrockzvol_remove_link(libzfs_handle_t *hdl, const char *dataset)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Silently ignore the case where the link no longer
fa9e4066f08beec538e775443c5be79dd423fcabahrens * exists, so that 'zfs volfini' can be run multiple
fa9e4066f08beec538e775443c5be79dd423fcabahrens * times without errors.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
b1b8ab34de515a5e83206da22c3d7e563241b021lling * This function is used by 'zfs list' to determine the exact set of columns to
b1b8ab34de515a5e83206da22c3d7e563241b021lling * display, and their maximum widths. This does two main things:
b1b8ab34de515a5e83206da22c3d7e563241b021lling * - If this is a list of all properties, then expand the list to include
b1b8ab34de515a5e83206da22c3d7e563241b021lling * all native properties, and set a flag so that for each dataset we look
b1b8ab34de515a5e83206da22c3d7e563241b021lling * for new unique user properties and add them to the list.
b1b8ab34de515a5e83206da22c3d7e563241b021lling * - For non fixed-width properties, keep track of the maximum width seen
b1b8ab34de515a5e83206da22c3d7e563241b021lling * so that we can size the column appropriately.
990b4856d0eaada6f8140335733a1b1771ed2746llingzfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp)
990b4856d0eaada6f8140335733a1b1771ed2746lling if (zprop_expand_list(hdl, plp, ZFS_TYPE_DATASET) != 0)
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (entry->pl_all && nvlist_next_nvpair(userprops, NULL) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Go through and add any user properties as necessary. We
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * start by incrementing our list pointer to the first
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * non-native property.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while ((elem = nvlist_next_nvpair(userprops, elem)) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * See if we've already found this property in our list.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Now go through and check the width of any non-fixed columns
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock for (entry = *plp; entry != NULL; entry = entry->pl_next) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_iscsi_perm_check(libzfs_handle_t *hdl, char *dataset, ucred_t *cred)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (uid == (uid_t)-1 || gid == (uid_t)-1 || group_cnt == (uid_t)-1)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_UID, uid) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_GID, gid) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks ZFS_DELEG_PERM_GROUPS, (uint32_t *)groups, group_cnt) != 0) {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (-1);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks error = ioctl(hdl->libzfs_fd, ZFS_IOC_ISCSI_PERM_CHECK, &zc);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_deleg_share_nfs(libzfs_handle_t *hdl, char *dataset, char *path,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void *export, void *sharetab, int sharemax, zfs_share_op_t operation)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value));
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks zc.zc_share.z_sharedata = (uint64_t)(uintptr_t)sharetab;