libzfs_dataset.c revision cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fec
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
798d58343cb97956d4d6e85444da08a3f92c61e3gw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
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.
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_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);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * This function takes the raw DSL properties, and filters out the user-defined
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * properties into a separate nvlist.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (nvlist_alloc(&zhp->zfs_user_props, NV_UNIQUE_NAME, 0) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while ((elem = nvlist_next_nvpair(zhp->zfs_props, elem)) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
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 */
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zhp->zfs_root, zc.zc_value, sizeof (zhp->zfs_root));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_read_dst_nvlist(hdl, &zc, &zhp->zfs_props) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
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);
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));
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens /* If we can successfully roll it back, reget the stats */
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_ROLLBACK, &zc) == 0)
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * If we can sucessfully destroy it, pretend that it
31fd60d36d9ae794bbedd5e834b8be6d412a853fahrens * never existed.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &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.
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.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a numeric suffix, convert the value into a number of bits that the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * resulting value must be shifted.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We want to allow trailing 'b' characters for 'GB' or 'Mb'. But don't
fa9e4066f08beec538e775443c5be79dd423fcabahrens * allow 'BB' - that's just weird.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (buf[1] == '\0' || (toupper(buf[1]) == 'B' && buf[2] == '\0' &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (10*i);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Convert a string of the form '100G' into a real number. Used when setting
fa9e4066f08beec538e775443c5be79dd423fcabahrens * properties or creating a volume. 'buf' is used to place an extended error
fa9e4066f08beec538e775443c5be79dd423fcabahrens * message for the caller to use.
99653d4ee642c6528e88224f12409a5f23060994eschrocknicestrtonum(libzfs_handle_t *hdl, const char *value, uint64_t *num)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Check to see if this looks like a number. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((value[0] < '0' || value[0] > '9') && value[0] != '.') {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Rely on stroll() to process the numeric portion. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check for ERANGE, which indicates that the value is too large to fit
fa9e4066f08beec538e775443c5be79dd423fcabahrens * in a 64-bit value.
99653d4ee642c6528e88224f12409a5f23060994eschrock "numeric value is too large"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we have a decimal value, then do the computation with floating
fa9e4066f08beec538e775443c5be79dd423fcabahrens * point arithmetic. Otherwise, use standard arithmetic.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock "numeric value is too large"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Check for overflow */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (shift >= 64 || (*num << shift) >> shift != *num) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "numeric value is too large"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_nicestrtonum(libzfs_handle_t *hdl, const char *str, uint64_t *val)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * The prop_parse_*() functions are designed to allow flexibility in callers
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * when setting properties. At the DSL layer, all properties are either 64-bit
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * numbers or strings. We want the user to be able to ignore this fact and
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * specify properties as native values (boolean, for example) or as strings (to
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * simplify command line utilities). This also handles converting index types
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * (compression, checksum, etc) from strings to their on-disk index.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockprop_parse_boolean(libzfs_handle_t *hdl, nvpair_t *elem, uint64_t *val)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "property '%s' must be 'on' or 'off'"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a boolean value"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a boolean value"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockprop_parse_number(libzfs_handle_t *hdl, nvpair_t *elem, zfs_prop_t prop,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a number"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Quota special: force 'none' and don't allow 0.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (ret == 0 && !isnone && prop == ZFS_PROP_QUOTA) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "use 'none' to disable quota"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockprop_parse_index(libzfs_handle_t *hdl, nvpair_t *elem, zfs_prop_t prop,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zfs_prop_string_to_index(prop, value, val) != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
b1b8ab34de515a5e83206da22c3d7e563241b021lling * Check if the bootfs name has the same pool name as it is set to.
b1b8ab34de515a5e83206da22c3d7e563241b021lling * Assuming bootfs is a valid dataset name.
b1b8ab34de515a5e83206da22c3d7e563241b021lling /* get the pool name from the bootfs name */
b1b8ab34de515a5e83206da22c3d7e563241b021lling while (*bootfs && !isspace(*bootfs) && *bootfs != '/')
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
b1b8ab34de515a5e83206da22c3d7e563241b021llingzfs_validate_properties(libzfs_handle_t *hdl, zfs_type_t type, char *pool_name,
b1b8ab34de515a5e83206da22c3d7e563241b021lling nvlist_t *nvl, uint64_t zoned, zfs_handle_t *zhp, const char *errbuf)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock const char *propname;
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "snapshot properties cannot be modified"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Make sure this property is valid and applies to this type.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "invalid property '%s'"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If this is a user property, make sure it's a
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * string, and that it's less than
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * ZAP_MAXNAMELEN.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a string"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "property name '%s' is too long"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (nvlist_add_string(ret, propname, strval) != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Normalize the name, to get rid of shorthand abbrevations.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Convert any properties to the internal DSL value types.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be a string"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (prop_parse_number(hdl, elem, prop, &intval) != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (prop_parse_index(hdl, elem, prop, &intval) != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Add the result to our return set of properties.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (nvlist_add_string(ret, propname, strval) != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock } else if (nvlist_add_uint64(ret, propname, intval) != 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Perform some additional checks for specific properties.
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'"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "'%s' must be an absolute path, "
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl /*FALLTHRU*/
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * For the mountpoint and sharenfs properties, check if
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * it can be set in a 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)
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * zoned=off mountpoint (yes) N/A
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * sharenfs (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 "
b1b8ab34de515a5e83206da22c3d7e563241b021lling * bootfs property value has to be a dataset name and
b1b8ab34de515a5e83206da22c3d7e563241b021lling * the dataset has to be in the same pool as it sets to.
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"),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If this is an existing volume, and someone is setting the volsize,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * make sure that it matches the reservation, or add it if necessary.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock nvlist_lookup_uint64(ret, zfs_prop_to_name(ZFS_PROP_VOLSIZE),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a property name and value, set the property for the given dataset.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockzfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
b1b8ab34de515a5e83206da22c3d7e563241b021lling if ((realprops = zfs_validate_properties(hdl, zhp->zfs_type, NULL, nvl,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, errbuf)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "child dataset with inherited mountpoint is used "
99653d4ee642c6528e88224f12409a5f23060994eschrock "in a non-global zone"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Execute the corresponding ioctl() to set this property.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_write_src_nvlist(hdl, &zc, nvl, NULL) != 0)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock ret = ioctl(hdl->libzfs_fd, ZFS_IOC_SET_PROP, &zc);
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"));
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl "pool must be upgraded to allow gzip compression"));
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);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if ((prop = zfs_name_to_prop(propname)) == ZFS_PROP_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));
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.
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"));
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)
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock verify(nvlist_lookup_uint64(nv, ZFS_PROP_VALUE, &value) == 0);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) nvlist_lookup_string(nv, ZFS_PROP_SOURCE, source);
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockstatic char *
7f7322febbcfe774b7270abc3b191c094bfcc517eschrockgetprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock verify(nvlist_lookup_string(nv, ZFS_PROP_VALUE, &value) == 0);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) nvlist_lookup_string(nv, ZFS_PROP_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".
fa9e4066f08beec538e775443c5be79dd423fcabahrensget_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zfs_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);
fda77a98c5f7fd534bf18ad9ab85e2b79d8670d8rm if (*val == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock "cannot get non-numeric property"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Calculate the source type, given the raw source string.
fa9e4066f08beec538e775443c5be79dd423fcabahrensget_source(zfs_handle_t *zhp, zfs_source_t *srctype, char *source,
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (statbuf == NULL || *srctype == ZFS_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,
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_source_t *src, char *statbuf, size_t statlen, boolean_t literal)
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *root;
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock const char *strval;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check to see if this property applies to our object
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Basic boolean values are built on top of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * get_numeric_property().
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Basic numeric values are built on top of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * get_numeric_property().
99653d4ee642c6528e88224f12409a5f23060994eschrock if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock verify(zfs_prop_index_to_string(prop, val, &strval) == 0);
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 default mountpoints, construct it as /zfs/<dataset>
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);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* 'legacy' or 'none' */
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock (void) strlcpy(propbuf, getprop_string(zhp, prop, &source),
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.
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.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) get_numeric_property(zhp, prop, &sourcetype, &source, &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)
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)
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);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Checks to make sure that the given path has a parent, and that it exists. We
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * also fetch the 'zoned' property, which is used to validate property settings
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * when creating new datasets.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockcheck_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 */
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = make_dataset_handle(hdl, parent)) == NULL) {
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);
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 */
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));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "dataset already exists"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (props && (props = zfs_validate_properties(hdl, type, NULL, 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 "
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"),
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));
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * Unconditionally unshare this zvol ignoring failure as it
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * indicates only that the volume wasn't shared initially.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl if (ioctl(zhp->zfs_hdl->libzfs_fd, 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));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens ret = ioctl(zhp->zfs_hdl->libzfs_fd, 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 */
99653d4ee642c6528e88224f12409a5f23060994eschrock if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents exist */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* do the clone */
b1b8ab34de515a5e83206da22c3d7e563241b021lling if ((props = zfs_validate_properties(hdl, type, NULL, props,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_write_src_nvlist(hdl, &zc, props, NULL) != 0) {
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));
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_CREATE, &zc);
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"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(parent, zhp->zfs_dmustats.dds_clone_of, sizeof (parent));
99653d4ee642c6528e88224f12409a5f23060994eschrock "not a cloned filesystem"));
99653d4ee642c6528e88224f12409a5f23060994eschrock /* Walk the snapshots we will be moving */
99653d4ee642c6528e88224f12409a5f23060994eschrock pzhp = zfs_open(hdl, zhp->zfs_dmustats.dds_clone_of, 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 */
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_clone_of,
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.
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrenszfs_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 */
99653d4ee642c6528e88224f12409a5f23060994eschrock if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure the parent exists and is of the appropriate type */
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((parent = zfs_alloc(hdl, delim - path + 1)) == NULL)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
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 ret = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SNAPSHOT, &zc);
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * if it was recursive, the one that actually failed will be in
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * zc.zc_name.
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "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) {
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_DESTROY,
72bdce51192b13a20009855f749004480874291bahl * Dumps a backup of the given snapshot (incremental from fromsnap if it's not
72bdce51192b13a20009855f749004480874291bahl * NULL) to the file descriptor specified by outfd.
72bdce51192b13a20009855f749004480874291bahlzfs_send(zfs_handle_t *zhp, const char *fromsnap, int outfd)
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) strlcpy(zc.zc_value, fromsnap, sizeof (zc.zc_name));
72bdce51192b13a20009855f749004480874291bahl if (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SENDBACKUP, &zc) != 0) {
72bdce51192b13a20009855f749004480874291bahl (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "not an earlier snapshot from the same fs"));
72bdce51192b13a20009855f749004480874291bahl return (0);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * Create ancestors of 'target', but not target itself, and not
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * ancestors whose names are shorter than prefixlen. Die if
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * prefixlen-ancestor does not exist.
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrenscreate_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens /* make sure prefix exists */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens return (-1);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * Attempt to create, mount, and share any ancestor filesystems,
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * up to the prefixlen-long one.
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens const char *opname;
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens /* it already exists, nothing to do here */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens if (zfs_share(h) != 0)
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens return (-1);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens return (0);
72bdce51192b13a20009855f749004480874291bahl * Restores a backup of tosnap from the file descriptor specified by infd.
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_receive(libzfs_handle_t *hdl, const char *tosnap, int isprefix,
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "cannot receive"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* read in the BEGIN record */
9b4f025ea51100e697da5c5d6afbcb60aee41c73ahrens } while (size > 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid "
99653d4ee642c6528e88224f12409a5f23060994eschrock "stream (failed to read first record)"));
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid "
99653d4ee642c6528e88224f12409a5f23060994eschrock "stream (bad magic number)"));
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "only version "
99653d4ee642c6528e88224f12409a5f23060994eschrock "0x%llx is supported (stream is version 0x%llx)"),
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens if (strchr(drr.drr_u.drr_begin.drr_toname, '@') == NULL) {
b1b8ab34de515a5e83206da22c3d7e563241b021lling "stream (bad snapshot name)"));
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * Determine how much of the snapshot name stored in the stream
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * we are going to tack on to the name they specified on the
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * command line, and how much we are going to chop off.
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * If they specified a snapshot, chop the entire name stored in
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * the stream.
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) strcpy(chopprefix, drr.drr_u.drr_begin.drr_toname);
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * They specified a fs with -d, we want to tack on
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * everything but the pool name stored in the stream
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens "argument - snapshot not allowed with -d"));
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * If they specified a filesystem without -d, we want to
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * tack on everything after the fs specified in the
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * first name from the stream.
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * Determine name of destination snapshot, store in zc_value.
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens (void) strncat(zc.zc_value, drr.drr_u.drr_begin.drr_toname+choplen,
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens if (!zfs_validate_name(hdl, zc.zc_value, ZFS_TYPE_SNAPSHOT))
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* incremental backup stream */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens /* do the recvbackup ioctl to the containing fs */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* make sure destination fs exists */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
98579b20de8e05c5117968705a18979f8b75b863nd * We need to unmount all the dependents of the dataset
98579b20de8e05c5117968705a18979f8b75b863nd * and the dataset itself. If it's a volume
98579b20de8e05c5117968705a18979f8b75b863nd * then remove device link.
98579b20de8e05c5117968705a18979f8b75b863nd return (-1);
98579b20de8e05c5117968705a18979f8b75b863nd return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* full backup stream */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens /* Make sure destination fs does not exist */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0) {
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * they're trying to do a recv into a
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * nonexistant topmost filesystem.
9b4f025ea51100e697da5c5d6afbcb60aee41c73ahrens /* Do the recvbackup ioctl to the fs's parent. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
99653d4ee642c6528e88224f12409a5f23060994eschrock err = ioctl_err = ioctl(hdl->libzfs_fd, ZFS_IOC_RECVBACKUP, &zc);
99653d4ee642c6528e88224f12409a5f23060994eschrock "most recent snapshot does not match incremental "
99653d4ee642c6528e88224f12409a5f23060994eschrock "source"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "destination has been modified since most recent "
99653d4ee642c6528e88224f12409a5f23060994eschrock "snapshot"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* it's the containing fs that exists */
99653d4ee642c6528e88224f12409a5f23060994eschrock "destination already exists"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "invalid stream (checksum mismatch)"));
9b4f025ea51100e697da5c5d6afbcb60aee41c73ahrens * Mount or recreate the /dev links for the target filesystem
9b4f025ea51100e697da5c5d6afbcb60aee41c73ahrens * (if created, or if we tore them down to do an incremental
9b4f025ea51100e697da5c5d6afbcb60aee41c73ahrens * restore), and the /dev links for the new snapshot (if
98579b20de8e05c5117968705a18979f8b75b863nd * created). Also mount any children of the target filesystem
98579b20de8e05c5117968705a18979f8b75b863nd * if we did an incremental receive.
9b4f025ea51100e697da5c5d6afbcb60aee41c73ahrens return (-1);
f2a3c691e1fab4dee486fd83642311ec59dc3732ahrens (void) printf("received %sb stream in %lu seconds (%sb/sec)\n",
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
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 {
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock if (zfs_iter_dependents(zhp, B_FALSE, rollback_destroy,
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling return (0);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Rollback the dataset to its latest snapshot.
99653d4ee642c6528e88224f12409a5f23060994eschrock zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We rely on the consumer to verify that there are no newer snapshots
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for the given dataset. Given these constraints, we can simply pass
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the name on to the ioctl() call. There is still an unlikely race
fa9e4066f08beec538e775443c5be79dd423fcabahrens * condition where the user has taken a snapshot since we verified that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * this was the most recent.
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((ret = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_ROLLBACK,
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = zvol_create_link(zhp->zfs_hdl, zhp->zfs_name);
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.
b12a1c38fc215cc54fa6014069fd2b8dbb496646llingzfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, int flag)
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Unmount all dependendents of the dataset and the dataset itself.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * The list we need to gather is the same as for doing rename
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling clp = changelist_gather(zhp, ZFS_PROP_NAME, flag ? MS_FORCE: 0);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling return (-1);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Destroy all recent snapshots and its dependends.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * Now that we have verified that the snapshot is the latest,
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * rollback to the given snapshot.
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling if (ret != 0) {
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * We only want to re-mount the filesystem if it was mounted in the
b12a1c38fc215cc54fa6014069fd2b8dbb496646lling * first place.
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.
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusantezfs_rename(zfs_handle_t *zhp, const char *target, int 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"));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante "recursive rename must be a snapshot"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* validate parents */
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"));
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_ANY);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante return (-1);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante /* We remove any zvol links prior to renaming them */
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante ret = zfs_iter_filesystems(zhrp, zfs_remove_link_cb, &dd);
cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fecmmusante if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 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));
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((ret = ioctl(zhp->zfs_hdl->libzfs_fd, 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 "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Call devfsadm and wait for the links to magically appear.
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((dhdl = di_devlink_init(ZFS_DRIVER, DI_MAKE_LINK)) == NULL) {
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot create device links "
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
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);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Given a comma-separated list of properties, contruct a property list
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * containing both user-defined and native properties. This function will
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * return a NULL list if 'all' is specified, which can later be expanded on a
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * per-dataset basis by zfs_expand_proplist().
b1b8ab34de515a5e83206da22c3d7e563241b021llingzfs_get_proplist_common(libzfs_handle_t *hdl, char *fields,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock char *s, *p;
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If 'all' is specified, return a NULL list.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If no fields were specified, return an error.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "no properties specified"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (zfs_error(hdl, EZFS_BADPROP, dgettext(TEXT_DOMAIN,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "bad property list")));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * It would be nice to use getsubopt() here, but the inclusion of column
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * aliases makes this more effort than it's worth.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock while (*s != '\0') {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Check for empty options.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (len == 0) {
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "empty property name"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Check all regular property names.
b1b8ab34de515a5e83206da22c3d7e563241b021lling * When no property table entry can be found, return failure if
b1b8ab34de515a5e83206da22c3d7e563241b021lling * this is a pool property or if this isn't a user-defined
b1b8ab34de515a5e83206da22c3d7e563241b021lling * dataset property,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "invalid property '%s'"), s);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if ((entry = zfs_alloc(hdl, sizeof (zfs_proplist_t))) == NULL)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (c == ',')
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (0);
b1b8ab34de515a5e83206da22c3d7e563241b021llingzfs_get_proplist(libzfs_handle_t *hdl, char *fields, zfs_proplist_t **listp)
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (zfs_get_proplist_common(hdl, fields, listp, ZFS_TYPE_ANY));
66e2aacc02a4625d105fb249ad16c27e79604ff2gwtypedef struct expand_data {
66e2aacc02a4625d105fb249ad16c27e79604ff2gw if ((entry = zfs_alloc(edp->hdl, sizeof (zfs_proplist_t))) == NULL)
66e2aacc02a4625d105fb249ad16c27e79604ff2gw entry->pl_width = zfs_prop_width(prop, &entry->pl_fixed);
b1b8ab34de515a5e83206da22c3d7e563241b021llingzfs_expand_proplist_common(libzfs_handle_t *hdl, zfs_proplist_t **plp,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * If this is the very first time we've been called for an 'all'
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * specification, expand the list to include all native
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * properties.
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zfs_prop_iter_common(zfs_expand_proplist_cb, &exp, type,
66e2aacc02a4625d105fb249ad16c27e79604ff2gw return (-1);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * Add 'name' to the beginning of the list, which is handled
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * specially.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling 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.
b1b8ab34de515a5e83206da22c3d7e563241b021llingzfs_expand_proplist(zfs_handle_t *zhp, zfs_proplist_t **plp)
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zfs_expand_proplist_common(hdl, plp, ZFS_TYPE_ANY) != 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);