FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
/*
 * Restores a backup of tosnap from the file descriptor specified by infd.
 * Return 0 on total success, -2 if some things couldn't be
 * destroyed/renamed/promoted, -1 if some things couldn't be received.
 * (-1 will override -2, if -1 and the resumable flag was specified the
 * transfer can be resumed if the sending side supports it).
 */
Restores a backup of tosnap from the file descriptor specified by infd.
Return 0 on total success, -2 if some things couldn't be
destroyed/renamed/promoted, -1 if some things couldn't be received.
(-1 will override -2, if -1 and the resumable flag was specified the
transfer can be resumed if the sending side supports it).
Restores a backup of tosnap from the file descriptor specified by infd . Return 0 on total success - 2 if some things couldn ' t be destroyed / renamed / promoted - 1 if some things couldn ' t be received . ( - 1 will override - 2 if - 1 and the resumable flag was specified the transfer can be resumed if the sending side supports it ) .
int
zfs_receive(libzfs_handle_t *hdl, const char *tosnap, nvlist_t *props,
    recvflags_t *flags, int infd, avl_tree_t *stream_avl)
{
	char *top_zfs = NULL;
	int err;
	int cleanup_fd;
	uint64_t action_handle = 0;
	char *originsnap = NULL;
	if (props) {
		err = nvlist_lookup_string(props, "origin", &originsnap);
		if (err && err != ENOENT)
			return (err);
	}
	cleanup_fd = open(ZFS_DEV, O_RDWR|O_EXCL);
	VERIFY(cleanup_fd >= 0);
	err = zfs_receive_impl(hdl, tosnap, originsnap, flags, infd, NULL, NULL,
	    stream_avl, &top_zfs, cleanup_fd, &action_handle, NULL);
	VERIFY(0 == close(cleanup_fd));
	if (err == 0 && !flags->nomount && top_zfs) {
		zfs_handle_t *zhp;
		prop_changelist_t *clp;
		zhp = zfs_open(hdl, top_zfs, ZFS_TYPE_FILESYSTEM);
		if (zhp != NULL) {
			clp = changelist_gather(zhp, ZFS_PROP_MOUNTPOINT,
			    CL_GATHER_MOUNT_ALWAYS, 0);
			zfs_close(zhp);
			if (clp != NULL) {
				err = changelist_postfix(clp);
				changelist_free(clp);
			}
		}
		if (zhp == NULL || clp == NULL || err)
			err = -1;
	}
	if (top_zfs)
		free(top_zfs);
	return (err);
}
int zfs_receive ( libzfs_handle_t * hdl , const char * tosnap , nvlist_t * props , recvflags_t * flags , int infd , avl_tree_t * stream_avl ) { char * top_zfs = NULL ; int err ; int cleanup_fd ; uint64_t action_handle = 0 ; char * originsnap = NULL ; if ( props ) { err = nvlist_lookup_string ( props , " " , & originsnap ) ; if ( err && err != ENOENT ) return ( err ) ; } cleanup_fd = open ( ZFS_DEV , O_RDWR | O_EXCL ) ; VERIFY ( cleanup_fd >= 0 ) ; err = zfs_receive_impl ( hdl , tosnap , originsnap , flags , infd , NULL , NULL , stream_avl , & top_zfs , cleanup_fd , & action_handle , NULL ) ; VERIFY ( 0 == close ( cleanup_fd ) ) ; if ( err == 0 && ! flags -> nomount && top_zfs ) { zfs_handle_t * zhp ; prop_changelist_t * clp ; zhp = zfs_open ( hdl , top_zfs , ZFS_TYPE_FILESYSTEM ) ; if ( zhp != NULL ) { clp = changelist_gather ( zhp , ZFS_PROP_MOUNTPOINT , CL_GATHER_MOUNT_ALWAYS , 0 ) ; zfs_close ( zhp ) ; if ( clp != NULL ) { err = changelist_postfix ( clp ) ; changelist_free ( clp ) ; } } if ( zhp == NULL || clp == NULL || err ) err = -1 ; } if ( top_zfs ) free ( top_zfs ) ; return ( err ) ; }
Restores a backup of tosnap from the file descriptor specified by infd.
Restores a backup of tosnap from the file descriptor specified by infd .
/* mount and share received datasets */