FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
/*
 * Dumps a backup of the given snapshot (incremental from fromsnap if it's not
 * NULL) to the file descriptor specified by outfd.
 */
Dumps a backup of the given snapshot (incremental from fromsnap if it's not
NULL) to the file descriptor specified by outfd.
Dumps a backup of the given snapshot ( incremental from fromsnap if it ' s not NULL ) to the file descriptor specified by outfd .
static int
dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj,
    boolean_t fromorigin, int outfd, enum lzc_send_flags flags,
    nvlist_t *debugnv)
{
	zfs_cmd_t zc = { 0 };
	libzfs_handle_t *hdl = zhp->zfs_hdl;
	nvlist_t *thisdbg;
	assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT);
	assert(fromsnap_obj == 0 || !fromorigin);
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
	zc.zc_cookie = outfd;
	zc.zc_obj = fromorigin;
	zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID);
	zc.zc_fromobj = fromsnap_obj;
	zc.zc_flags = flags;
	VERIFY(0 == nvlist_alloc(&thisdbg, NV_UNIQUE_NAME, 0));
	if (fromsnap && fromsnap[0] != '\0') {
		VERIFY(0 == nvlist_add_string(thisdbg,
		    "fromsnap", fromsnap));
	}
	if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) {
		char errbuf[1024];
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
		    "warning: cannot send '%s'"), zhp->zfs_name);
		VERIFY(0 == nvlist_add_uint64(thisdbg, "error", errno));
		if (debugnv) {
			VERIFY(0 == nvlist_add_nvlist(debugnv,
			    zhp->zfs_name, thisdbg));
		}
		nvlist_free(thisdbg);
		switch (errno) {
		case EXDEV:
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
			    "not an earlier snapshot from the same fs"));
			return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf));
		case ENOENT:
			if (zfs_dataset_exists(hdl, zc.zc_name,
			    ZFS_TYPE_SNAPSHOT)) {
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
				    "incremental source (@%s) does not exist"),
				    zc.zc_value);
			}
			return (zfs_error(hdl, EZFS_NOENT, errbuf));
		case EDQUOT:
		case EFBIG:
		case EIO:
		case ENOLINK:
		case ENOSPC:
#ifdef illumos
		case ENOSTR:
#endif
		case ENXIO:
		case EPIPE:
		case ERANGE:
		case EFAULT:
		case EROFS:
			zfs_error_aux(hdl, strerror(errno));
			return (zfs_error(hdl, EZFS_BADBACKUP, errbuf));
		default:
			return (zfs_standard_error(hdl, errno, errbuf));
		}
	}
	if (debugnv)
		VERIFY(0 == nvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg));
	nvlist_free(thisdbg);
	return (0);
}
static int dump_ioctl ( zfs_handle_t * zhp , const char * fromsnap , uint64_t fromsnap_obj , boolean_t fromorigin , int outfd , enum lzc_send_flags flags , nvlist_t * debugnv ) { zfs_cmd_t zc = { 0 } ; libzfs_handle_t * hdl = zhp -> zfs_hdl ; nvlist_t * thisdbg ; assert ( zhp -> zfs_type == ZFS_TYPE_SNAPSHOT ) ; assert ( fromsnap_obj == 0 || ! fromorigin ) ; ( void ) strlcpy ( zc . zc_name , zhp -> zfs_name , sizeof ( zc . zc_name ) ) ; zc . zc_cookie = outfd ; zc . zc_obj = fromorigin ; zc . zc_sendobj = zfs_prop_get_int ( zhp , ZFS_PROP_OBJSETID ) ; zc . zc_fromobj = fromsnap_obj ; zc . zc_flags = flags ; VERIFY ( 0 == nvlist_alloc ( & thisdbg , NV_UNIQUE_NAME , 0 ) ) ; if ( fromsnap && fromsnap [ 0 ] != ' \0 ' ) { VERIFY ( 0 == nvlist_add_string ( thisdbg , " " , fromsnap ) ) ; } if ( zfs_ioctl ( zhp -> zfs_hdl , ZFS_IOC_SEND , & zc ) != 0 ) { char errbuf [ 1024 ] ; ( void ) snprintf ( errbuf , sizeof ( errbuf ) , dgettext ( TEXT_DOMAIN , " " ) , zhp -> zfs_name ) ; VERIFY ( 0 == nvlist_add_uint64 ( thisdbg , " " , errno ) ) ; if ( debugnv ) { VERIFY ( 0 == nvlist_add_nvlist ( debugnv , zhp -> zfs_name , thisdbg ) ) ; } nvlist_free ( thisdbg ) ; switch ( errno ) { case EXDEV : zfs_error_aux ( hdl , dgettext ( TEXT_DOMAIN , " " ) ) ; return ( zfs_error ( hdl , EZFS_CROSSTARGET , errbuf ) ) ; case ENOENT : if ( zfs_dataset_exists ( hdl , zc . zc_name , ZFS_TYPE_SNAPSHOT ) ) { zfs_error_aux ( hdl , dgettext ( TEXT_DOMAIN , " " ) , zc . zc_value ) ; } return ( zfs_error ( hdl , EZFS_NOENT , errbuf ) ) ; case EDQUOT : case EFBIG : case EIO : case ENOLINK : case ENOSPC : #ifdef illumos case ENOSTR : #endif case ENXIO : case EPIPE : case ERANGE : case EFAULT : case EROFS : zfs_error_aux ( hdl , strerror ( errno ) ) ; return ( zfs_error ( hdl , EZFS_BADBACKUP , errbuf ) ) ; default : return ( zfs_standard_error ( hdl , errno , errbuf ) ) ; } } if ( debugnv ) VERIFY ( 0 == nvlist_add_nvlist ( debugnv , zhp -> zfs_name , thisdbg ) ) ; nvlist_free ( thisdbg ) ; return ( 0 ) ; }
Dumps a backup of the given snapshot (incremental from fromsnap if it's not
 NULL) to the file descriptor specified by outfd.
Dumps a backup of the given snapshot ( incremental from fromsnap if it ' s not NULL ) to the file descriptor specified by outfd .