libzfs_core.c revision 620f322510b2d6433f7f6af60fa52380c07756ad
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * CDDL HEADER START
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The contents of this file are subject to the terms of the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Common Development and Distribution License (the "License").
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * You may not use this file except in compliance with the License.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * or http://www.opensolaris.org/os/licensing.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * See the License for the specific language governing permissions
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * and limitations under the License.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * When distributing Covered Code, include this CDDL HEADER in each
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If applicable, add the following below this CDDL HEADER, with the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * fields enclosed by brackets "[]" replaced with your own identifying
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * CDDL HEADER END
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * LibZFS_Core (lzc) is intended to replace most functionality in libzfs.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * It has the following characteristics:
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - Thread Safe. libzfs_core is accessible concurrently from multiple
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * threads. This is accomplished primarily by avoiding global data
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * (e.g. caching). Since it's thread-safe, there is no reason for a
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * process to have multiple libzfs "instances". Therefore, we store
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * our few pieces of data (e.g. the file descriptor) in global
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * variables. The fd is reference-counted so that the libzfs_core
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * library can be "initialized" multiple times (e.g. by different
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * consumers within the same process).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - Committed Interface. The libzfs_core interface will be committed,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * therefore consumers can compile against it and be confident that
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * their code will continue to work on future releases of this code.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Currently, the interface is Evolving (not Committed), but we intend
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * to commit to it once it is more complete and we determine that it
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * meets the needs of all consumers.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - Programatic Error Handling. libzfs_core communicates errors with
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * defined error numbers, and doesn't print anything to stdout/stderr.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - Thin Layer. libzfs_core is a thin layer, marshaling arguments
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * to/from the kernel ioctls. There is generally a 1:1 correspondence
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * between libzfs_core functions and ioctls to /dev/zfs.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - Clear Atomicity. Because libzfs_core functions are generally 1:1
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * with kernel ioctls, and kernel ioctls are general atomic, each
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * libzfs_core function is atomic. For example, creating multiple
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * snapshots with a single call to lzc_snapshot() is atomic -- it
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * can't fail with only some of the requested snapshots created, even
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * in the event of power loss or system crash.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * - Continued libzfs Support. Some higher-level operations (e.g.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * support for "zfs send -R") are too complicated to fit the scope of
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * libzfs_core. This functionality will continue to live in libzfs.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Where appropriate, libzfs will use the underlying atomic operations
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * of libzfs_core. For example, libzfs may implement "zfs send -R |
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs receive" by using individual "send one snapshot", rename,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * destroy, and "receive one snapshot" operations in libzfs_core.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * /sbin/zfs and /zbin/zpool will link with both libzfs and
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * libzfs_core. Other consumers should aim to use only libzfs_core,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * since that will be the supported, stable interface going forwards.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrensstatic pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens zc.zc_nvlist_dst_size = MAX(size * 2, 128 * 1024);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens *resultp = fnvlist_unpack((void *)(uintptr_t)zc.zc_nvlist_dst,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_create(const char *fsname, dmu_objset_type_t type, nvlist_t *props)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = lzc_ioctl(ZFS_IOC_CREATE, fsname, args, NULL);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_clone(const char *fsname, const char *origin,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = lzc_ioctl(ZFS_IOC_CLONE, fsname, args, NULL);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Creates snapshots.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The keys in the snaps nvlist are the snapshots to be created.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * They must all be in the same pool.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The props nvlist is properties to set. Currently only user properties
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * are supported. { user:prop_name -> string value }
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The returned results nvlist will have an entry for each snapshot that failed.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The value will be the (int32) error code.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The return value will be 0 if all snapshots were created, otherwise it will
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * be the errno of a (unspecified) snapshot that failed.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t **errlist)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* determine the pool name */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = lzc_ioctl(ZFS_IOC_SNAPSHOT, pool, args, errlist);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Destroys snapshots.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The keys in the snaps nvlist are the snapshots to be destroyed.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * They must all be in the same pool.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Snapshots that do not exist will be silently ignored.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If 'defer' is not set, and a snapshot has user holds or clones, the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * destroy operation will fail and none of the snapshots will be
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If 'defer' is set, and a snapshot has user holds or clones, it will be
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * marked for deferred destruction, and will be destroyed when the last hold
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The return value will be 0 if all snapshots were destroyed (or marked for
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens * later destruction if 'defer' is set) or didn't exist to begin with.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Otherwise the return value will be the errno of a (unspecified) snapshot
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * that failed, no snapshots will be destroyed, and the errlist will have an
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * entry for each snapshot that failed. The value in the errlist will be
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * the (int32) error code.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_destroy_snaps(nvlist_t *snaps, boolean_t defer, nvlist_t **errlist)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* determine the pool name */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens error = lzc_ioctl(ZFS_IOC_DESTROY_SNAPS, pool, args, errlist);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_snaprange_space(const char *firstsnap, const char *lastsnap,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* determine the fs name */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_string(args, "firstsnap", firstsnap);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens err = lzc_ioctl(ZFS_IOC_SPACE_SNAPS, lastsnap, args, &result);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens *usedp = fnvlist_lookup_uint64(result, "used");
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The objset_stats ioctl is still legacy, so we need to construct our
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * own zfs_cmd_t rather than using zfsc_ioctl().
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (ioctl(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Create "user holds" on snapshots. If there is a hold on a snapshot,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * the snapshot can not be destroyed. (However, it can be marked for deletion
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * by lzc_destroy_snaps(defer=B_TRUE).)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The keys in the nvlist are snapshot names.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The snapshots must all be in the same pool.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The value is the name of the hold (string type).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * If cleanup_fd is not -1, it must be the result of open("/dev/zfs", O_EXCL).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * In this case, when the cleanup_fd is closed (including on process
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * termination), the holds will be released. If the system is shut down
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * uncleanly, the holds will be released when the pool is next opened
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * or imported.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Holds for snapshots which don't exist will be skipped and have an entry
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens * added to errlist, but will not cause an overall failure.
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens * The return value will be 0 if all holds, for snapshots that existed,
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens * were succesfully created.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Otherwise the return value will be the errno of a (unspecified) hold that
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * failed and no holds will be created.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * In all cases the errlist will have an entry for each hold that failed
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * (name = snapshot), with its value being the error code (int32).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenslzc_hold(nvlist_t *holds, int cleanup_fd, nvlist_t **errlist)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* determine the pool name */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens fnvlist_add_int32(args, "cleanup_fd", cleanup_fd);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = lzc_ioctl(ZFS_IOC_HOLD, pool, args, errlist);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Release "user holds" on snapshots. If the snapshot has been marked for
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * deferred destroy (by lzc_destroy_snaps(defer=B_TRUE)), it does not have
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * any clones, and all the user holds are removed, then the snapshot will be
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The keys in the nvlist are snapshot names.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The snapshots must all be in the same pool.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The value is a nvlist whose keys are the holds to remove.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Holds which failed to release because they didn't exist will have an entry
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens * added to errlist, but will not cause an overall failure.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * The return value will be 0 if the nvl holds was empty or all holds that
bb6e70758d0c30c09f148026d6e686e21cfc8d18Matthew Ahrens * existed, were successfully removed.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Otherwise the return value will be the errno of a (unspecified) hold that
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * failed to release and no holds will be released.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * In all cases the errlist will have an entry for each hold that failed to
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * to release.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenslzc_release(nvlist_t *holds, nvlist_t **errlist)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* determine the pool name */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (lzc_ioctl(ZFS_IOC_RELEASE, pool, holds, errlist));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Retrieve list of user holds on the specified snapshot.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * On success, *holdsp will be set to a nvlist which the caller must free.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The keys are the names of the holds, and the value is the creation time
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * of the hold (uint64) in seconds since the epoch.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenslzc_get_holds(const char *snapname, nvlist_t **holdsp)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = lzc_ioctl(ZFS_IOC_GET_HOLDS, snapname, innvl, holdsp);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Generate a zfs send stream for the specified snapshot and write it to
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * the specified file descriptor.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "snapname" is the full name of the snapshot to send (e.g. "pool/fs@snap")
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If "from" is NULL, a full (non-incremental) stream will be sent.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If "from" is non-NULL, it must be the full name of a snapshot or
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * bookmark to send an incremental from (e.g. "pool/fs@earlier_snap" or
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "pool/fs#earlier_bmark"). If non-NULL, the specified snapshot or
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * bookmark must represent an earlier point in the history of "snapname").
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * It can be an earlier snapshot in the same filesystem or zvol as "snapname",
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * or it can be the origin of "snapname"'s filesystem, or an earlier
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * snapshot in the origin, etc.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "fd" is the file descriptor to write the send stream to.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If "flags" contains LZC_SEND_FLAG_LARGE_BLOCK, the stream is permitted
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * to contain DRR_WRITE records with drr_length > 128K, and DRR_OBJECT
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * records with drr_blksz > 128K.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If "flags" contains LZC_SEND_FLAG_EMBED_DATA, the stream is permitted
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * to contain DRR_WRITE_EMBEDDED records with drr_etype==BP_EMBEDDED_TYPE_DATA,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * which the receiving system must support (as indicated by support
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * for the "embedded_data" feature).
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_send(const char *snapname, const char *from, int fd,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (lzc_send_resume(snapname, from, fd, flags, 0, 0));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_send_resume(const char *snapname, const char *from, int fd,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens enum lzc_send_flags flags, uint64_t resumeobj, uint64_t resumeoff)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_uint64(args, "resume_object", resumeobj);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens fnvlist_add_uint64(args, "resume_offset", resumeoff);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens err = lzc_ioctl(ZFS_IOC_SEND_NEW, snapname, args, NULL);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * "from" can be NULL, a snapshot, or a bookmark.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If from is NULL, a full (non-incremental) stream will be estimated. This
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * is calculated very efficiently.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If from is a snapshot, lzc_send_space uses the deadlists attached to
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * each snapshot to efficiently estimate the stream size.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If from is a bookmark, the indirect blocks in the destination snapshot
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * are traversed, looking for blocks with a birth time since the creation TXG of
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * the snapshot this bookmark was created from. This will result in
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * significantly more I/O and be less efficient than a send space estimation on
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * an equivalent snapshot.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrenslzc_send_space(const char *snapname, const char *from, uint64_t *spacep)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens err = lzc_ioctl(ZFS_IOC_SEND_SPACE, snapname, args, &result);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens *spacep = fnvlist_lookup_uint64(result, "space");
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens } while (rv > 0);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrensrecv_impl(const char *snapname, nvlist_t *props, const char *origin,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens boolean_t force, boolean_t resumable, int fd,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * The receive ioctl is still legacy, so we need to construct our own
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * zfs_cmd_t rather than using zfsc_ioctl().
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* zc_name is name of containing filesystem */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) strlcpy(zc.zc_name, snapname, sizeof (zc.zc_name));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* if the fs does not exist, try its parent. */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* zc_value is full name of the snapshot to create */
if (error != 0)
goto out;
if (error != 0)
out:
return (error);
return (EINVAL);
begin_record));
int err;
return (err);
int error;
return (error);
int error;
return (error);