head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
/*
 * recursively generate nvlists describing datasets.  See comment
 * for the data structure send_data_t above for description of contents
 * of the nvlist.
 */
recursively generate nvlists describing datasets.  See comment
for the data structure send_data_t above for description of contents
of the nvlist.
recursively generate nvlists describing datasets . See comment for the data structure send_data_t above for description of contents of the nvlist .
static int
send_iterate_fs(zfs_handle_t *zhp, void *arg)
{
	send_data_t *sd = arg;
	nvlist_t *nvfs, *nv;
	int rv = 0;
	uint64_t parent_fromsnap_guid_save = sd->parent_fromsnap_guid;
	uint64_t guid = zhp->zfs_dmustats.dds_guid;
	char guidstring[64];
	VERIFY(0 == nvlist_alloc(&nvfs, NV_UNIQUE_NAME, 0));
	VERIFY(0 == nvlist_add_string(nvfs, "name", zhp->zfs_name));
	VERIFY(0 == nvlist_add_uint64(nvfs, "parentfromsnap",
	    sd->parent_fromsnap_guid));
	if (zhp->zfs_dmustats.dds_origin[0]) {
		zfs_handle_t *origin = zfs_open(zhp->zfs_hdl,
		    zhp->zfs_dmustats.dds_origin, ZFS_TYPE_SNAPSHOT);
		if (origin == NULL)
			return (-1);
		VERIFY(0 == nvlist_add_uint64(nvfs, "origin",
		    origin->zfs_dmustats.dds_guid));
	}
	VERIFY(0 == nvlist_alloc(&nv, NV_UNIQUE_NAME, 0));
	send_iterate_prop(zhp, nv);
	VERIFY(0 == nvlist_add_nvlist(nvfs, "props", nv));
	nvlist_free(nv);
	sd->parent_fromsnap_guid = 0;
	VERIFY(0 == nvlist_alloc(&sd->parent_snaps, NV_UNIQUE_NAME, 0));
	VERIFY(0 == nvlist_alloc(&sd->snapprops, NV_UNIQUE_NAME, 0));
	(void) zfs_iter_snapshots_sorted(zhp, send_iterate_snap, sd);
	VERIFY(0 == nvlist_add_nvlist(nvfs, "snaps", sd->parent_snaps));
	VERIFY(0 == nvlist_add_nvlist(nvfs, "snapprops", sd->snapprops));
	nvlist_free(sd->parent_snaps);
	nvlist_free(sd->snapprops);
	(void) snprintf(guidstring, sizeof (guidstring),
	    "0x%llx", (longlong_t)guid);
	VERIFY(0 == nvlist_add_nvlist(sd->fss, guidstring, nvfs));
	nvlist_free(nvfs);
	if (sd->recursive)
		rv = zfs_iter_filesystems(zhp, send_iterate_fs, sd);
	sd->parent_fromsnap_guid = parent_fromsnap_guid_save;
	zfs_close(zhp);
	return (rv);
}
static int send_iterate_fs ( zfs_handle_t * zhp , void * arg ) { send_data_t * sd = arg ; nvlist_t * nvfs , * nv ; int rv = 0 ; uint64_t parent_fromsnap_guid_save = sd -> parent_fromsnap_guid ; uint64_t guid = zhp -> zfs_dmustats . dds_guid ; char guidstring [ 64 ] ; VERIFY ( 0 == nvlist_alloc ( & nvfs , NV_UNIQUE_NAME , 0 ) ) ; VERIFY ( 0 == nvlist_add_string ( nvfs , " " , zhp -> zfs_name ) ) ; VERIFY ( 0 == nvlist_add_uint64 ( nvfs , " " , sd -> parent_fromsnap_guid ) ) ; if ( zhp -> zfs_dmustats . dds_origin [ 0 ] ) { zfs_handle_t * origin = zfs_open ( zhp -> zfs_hdl , zhp -> zfs_dmustats . dds_origin , ZFS_TYPE_SNAPSHOT ) ; if ( origin == NULL ) return ( -1 ) ; VERIFY ( 0 == nvlist_add_uint64 ( nvfs , " " , origin -> zfs_dmustats . dds_guid ) ) ; } VERIFY ( 0 == nvlist_alloc ( & nv , NV_UNIQUE_NAME , 0 ) ) ; send_iterate_prop ( zhp , nv ) ; VERIFY ( 0 == nvlist_add_nvlist ( nvfs , " " , nv ) ) ; nvlist_free ( nv ) ; sd -> parent_fromsnap_guid = 0 ; VERIFY ( 0 == nvlist_alloc ( & sd -> parent_snaps , NV_UNIQUE_NAME , 0 ) ) ; VERIFY ( 0 == nvlist_alloc ( & sd -> snapprops , NV_UNIQUE_NAME , 0 ) ) ; ( void ) zfs_iter_snapshots_sorted ( zhp , send_iterate_snap , sd ) ; VERIFY ( 0 == nvlist_add_nvlist ( nvfs , " " , sd -> parent_snaps ) ) ; VERIFY ( 0 == nvlist_add_nvlist ( nvfs , " " , sd -> snapprops ) ) ; nvlist_free ( sd -> parent_snaps ) ; nvlist_free ( sd -> snapprops ) ; ( void ) snprintf ( guidstring , sizeof ( guidstring ) , " " , ( longlong_t ) guid ) ; VERIFY ( 0 == nvlist_add_nvlist ( sd -> fss , guidstring , nvfs ) ) ; nvlist_free ( nvfs ) ; if ( sd -> recursive ) rv = zfs_iter_filesystems ( zhp , send_iterate_fs , sd ) ; sd -> parent_fromsnap_guid = parent_fromsnap_guid_save ; zfs_close ( zhp ) ; return ( rv ) ; }
recursively generate nvlists describing datasets.
recursively generate nvlists describing datasets .
/* iterate over props */ /* iterate over snaps, and set sd->parent_fromsnap_guid */ /* add this fs to nvlist */ /* iterate over children */