FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
/*
 * Given an nvlist, produce an avl tree of snapshots, ordered by guid
 */
Given an nvlist, produce an avl tree of snapshots, ordered by guid
Given an nvlist produce an avl tree of snapshots ordered by guid
static avl_tree_t *
fsavl_create(nvlist_t *fss)
{
	avl_tree_t *fsavl;
	nvpair_t *fselem = NULL;
	if ((fsavl = malloc(sizeof (avl_tree_t))) == NULL)
		return (NULL);
	avl_create(fsavl, fsavl_compare, sizeof (fsavl_node_t),
	    offsetof(fsavl_node_t, fn_node));
	while ((fselem = nvlist_next_nvpair(fss, fselem)) != NULL) {
		nvlist_t *nvfs, *snaps;
		nvpair_t *snapelem = NULL;
		VERIFY(0 == nvpair_value_nvlist(fselem, &nvfs));
		VERIFY(0 == nvlist_lookup_nvlist(nvfs, "snaps", &snaps));
		while ((snapelem =
		    nvlist_next_nvpair(snaps, snapelem)) != NULL) {
			fsavl_node_t *fn;
			uint64_t guid;
			VERIFY(0 == nvpair_value_uint64(snapelem, &guid));
			if ((fn = malloc(sizeof (fsavl_node_t))) == NULL) {
				fsavl_destroy(fsavl);
				return (NULL);
			}
			fn->fn_nvfs = nvfs;
			fn->fn_snapname = nvpair_name(snapelem);
			fn->fn_guid = guid;
			if (avl_find(fsavl, fn, NULL) == NULL)
				avl_add(fsavl, fn);
			else
				free(fn);
		}
	}
	return (fsavl);
}
static avl_tree_t * fsavl_create ( nvlist_t * fss ) { avl_tree_t * fsavl ; nvpair_t * fselem = NULL ; if ( ( fsavl = malloc ( sizeof ( avl_tree_t ) ) ) == NULL ) return ( NULL ) ; avl_create ( fsavl , fsavl_compare , sizeof ( fsavl_node_t ) , offsetof ( fsavl_node_t , fn_node ) ) ; while ( ( fselem = nvlist_next_nvpair ( fss , fselem ) ) != NULL ) { nvlist_t * nvfs , * snaps ; nvpair_t * snapelem = NULL ; VERIFY ( 0 == nvpair_value_nvlist ( fselem , & nvfs ) ) ; VERIFY ( 0 == nvlist_lookup_nvlist ( nvfs , " " , & snaps ) ) ; while ( ( snapelem = nvlist_next_nvpair ( snaps , snapelem ) ) != NULL ) { fsavl_node_t * fn ; uint64_t guid ; VERIFY ( 0 == nvpair_value_uint64 ( snapelem , & guid ) ) ; if ( ( fn = malloc ( sizeof ( fsavl_node_t ) ) ) == NULL ) { fsavl_destroy ( fsavl ) ; return ( NULL ) ; } fn -> fn_nvfs = nvfs ; fn -> fn_snapname = nvpair_name ( snapelem ) ; fn -> fn_guid = guid ; if ( avl_find ( fsavl , fn , NULL ) == NULL ) avl_add ( fsavl , fn ) ; else free ( fn ) ; } } return ( fsavl ) ; }
Given an nvlist, produce an avl tree of snapshots, ordered by guid
Given an nvlist produce an avl tree of snapshots ordered by guid
/*
			 * Note: if there are multiple snaps with the
			 * same GUID, we ignore all but one.
			 */