xref: /titanic_44/usr/src/cmd/smbsrv/smbd/smbd_vss.c (revision 148c5f43199ca0b43fc8e3b643aab11cd66ea327)
189dc44ceSjose borrego /*
289dc44ceSjose borrego  * CDDL HEADER START
389dc44ceSjose borrego  *
489dc44ceSjose borrego  * The contents of this file are subject to the terms of the
589dc44ceSjose borrego  * Common Development and Distribution License (the "License").
689dc44ceSjose borrego  * You may not use this file except in compliance with the License.
789dc44ceSjose borrego  *
889dc44ceSjose borrego  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
989dc44ceSjose borrego  * or http://www.opensolaris.org/os/licensing.
1089dc44ceSjose borrego  * See the License for the specific language governing permissions
1189dc44ceSjose borrego  * and limitations under the License.
1289dc44ceSjose borrego  *
1389dc44ceSjose borrego  * When distributing Covered Code, include this CDDL HEADER in each
1489dc44ceSjose borrego  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1589dc44ceSjose borrego  * If applicable, add the following below this CDDL HEADER, with the
1689dc44ceSjose borrego  * fields enclosed by brackets "[]" replaced with your own identifying
1789dc44ceSjose borrego  * information: Portions Copyright [yyyy] [name of copyright owner]
1889dc44ceSjose borrego  *
1989dc44ceSjose borrego  * CDDL HEADER END
2089dc44ceSjose borrego  */
21*148c5f43SAlan Wright 
2289dc44ceSjose borrego /*
23*148c5f43SAlan Wright  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2489dc44ceSjose borrego  */
2589dc44ceSjose borrego 
2689dc44ceSjose borrego #include <synch.h>
2789dc44ceSjose borrego #include <pthread.h>
2889dc44ceSjose borrego #include <unistd.h>
2989dc44ceSjose borrego #include <string.h>
3089dc44ceSjose borrego #include <strings.h>
3189dc44ceSjose borrego #include <sys/errno.h>
326d57f833SAlan Wright #include <libzfs.h>
3389dc44ceSjose borrego 
3489dc44ceSjose borrego #include <smbsrv/libsmb.h>
3589dc44ceSjose borrego #include <smbsrv/libsmbns.h>
3689dc44ceSjose borrego #include <smbsrv/libmlsvc.h>
3789dc44ceSjose borrego #include <smbsrv/smbinfo.h>
3889dc44ceSjose borrego #include "smbd.h"
3989dc44ceSjose borrego 
4089dc44ceSjose borrego /*
4189dc44ceSjose borrego  * This file supports three basic functions that all use the
4289dc44ceSjose borrego  * the zfs_iter_snapshots function to get the snapshot info
4389dc44ceSjose borrego  * from ZFS.  If the filesystem is not ZFS, the an error is sent
4489dc44ceSjose borrego  * to the caller (door functions in this case) with the count of
4589dc44ceSjose borrego  * zero in the case of smbd_vss_get_count.  Each function
4689dc44ceSjose borrego  * is expecting a path that is the root of the dataset.
4789dc44ceSjose borrego  * The basic idea is to define a structure for the data and
4889dc44ceSjose borrego  * an iterator function that will be called for every snapshot
4989dc44ceSjose borrego  * in the dataset that was opened.  The iterator function gets
5089dc44ceSjose borrego  * a zfs_handle_t(that needs to be closed) for the snapshot
5189dc44ceSjose borrego  * and a pointer to the structure of data defined passed to it.
5289dc44ceSjose borrego  * If the iterator function returns a non-zero value, no more
5389dc44ceSjose borrego  * snapshots will be processed.  There is no guarantee in the
5489dc44ceSjose borrego  * order in which the snapshots are processed.
5589dc44ceSjose borrego  *
5689dc44ceSjose borrego  * The structure of this file is:
5789dc44ceSjose borrego  * Three structures that are used between the iterator functions
5889dc44ceSjose borrego  * and "main" functions
5989dc44ceSjose borrego  * The 3 "main" functions
6089dc44ceSjose borrego  * Support functions
6189dc44ceSjose borrego  * The 3 iterator functions
6289dc44ceSjose borrego  */
6389dc44ceSjose borrego 
648b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /*
658b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * The maximum number of snapshots returned per request.
668b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  */
678b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States #define	SMBD_VSS_SNAPSHOT_MAX	725
688b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
6989dc44ceSjose borrego static void smbd_vss_time2gmttoken(time_t time, char *gmttoken);
7089dc44ceSjose borrego static int smbd_vss_cmp_time(const void *a, const void *b);
7189dc44ceSjose borrego static int smbd_vss_iterate_count(zfs_handle_t *zhp, void *data);
7289dc44ceSjose borrego static int smbd_vss_iterate_get_uint64_date(zfs_handle_t *zhp, void *data);
7389dc44ceSjose borrego static int smbd_vss_iterate_map_gmttoken(zfs_handle_t *zhp, void *data);
7489dc44ceSjose borrego 
7589dc44ceSjose borrego typedef struct smbd_vss_count {
7689dc44ceSjose borrego 	int vc_count;
7789dc44ceSjose borrego } smbd_vss_count_t;
7889dc44ceSjose borrego 
7989dc44ceSjose borrego /*
8089dc44ceSjose borrego  * gd_count how many @GMT tokens are expected
8189dc44ceSjose borrego  * gd_return_count how many @GMT tokens are being returned
8289dc44ceSjose borrego  * gd_gmt_array array of the @GMT token with max size of gd_count
8389dc44ceSjose borrego  */
8489dc44ceSjose borrego typedef struct smbd_vss_get_uint64_date {
8589dc44ceSjose borrego 	int gd_count;
8689dc44ceSjose borrego 	int gd_return_count;
8789dc44ceSjose borrego 	uint64_t *gd_gmt_array;
8889dc44ceSjose borrego } smbd_vss_get_uint64_date_t;
8989dc44ceSjose borrego 
9089dc44ceSjose borrego typedef struct smbd_vss_map_gmttoken {
9189dc44ceSjose borrego 	char *mg_gmttoken;
9289dc44ceSjose borrego 	char *mg_snapname;
9389dc44ceSjose borrego } smbd_vss_map_gmttoken_t;
9489dc44ceSjose borrego 
9589dc44ceSjose borrego 
9689dc44ceSjose borrego /*
9789dc44ceSjose borrego  * path - path of the dataset
9889dc44ceSjose borrego  * count - return value of the number of snapshots for the dataset
9989dc44ceSjose borrego  */
10089dc44ceSjose borrego int
smbd_vss_get_count(const char * path,uint32_t * count)1016d57f833SAlan Wright smbd_vss_get_count(const char *path, uint32_t *count)
10289dc44ceSjose borrego {
1036d57f833SAlan Wright 	char dataset[MAXPATHLEN];
1046d57f833SAlan Wright 	libzfs_handle_t *libhd;
1056d57f833SAlan Wright 	zfs_handle_t *zfshd;
10689dc44ceSjose borrego 	smbd_vss_count_t vss_count;
10789dc44ceSjose borrego 
10889dc44ceSjose borrego 	bzero(&vss_count, sizeof (smbd_vss_count_t));
10989dc44ceSjose borrego 	*count = 0;
11089dc44ceSjose borrego 
1116d57f833SAlan Wright 	if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
1126d57f833SAlan Wright 		return (-1);
11389dc44ceSjose borrego 
1146d57f833SAlan Wright 	if ((libhd = libzfs_init()) == NULL)
1156d57f833SAlan Wright 		return (-1);
11689dc44ceSjose borrego 
1176d57f833SAlan Wright 	if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
1186d57f833SAlan Wright 		libzfs_fini(libhd);
11989dc44ceSjose borrego 		return (-1);
12089dc44ceSjose borrego 	}
12189dc44ceSjose borrego 
1226d57f833SAlan Wright 	(void) zfs_iter_snapshots(zfshd, smbd_vss_iterate_count,
12389dc44ceSjose borrego 	    (void *)&vss_count);
12489dc44ceSjose borrego 
1258b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (vss_count.vc_count > SMBD_VSS_SNAPSHOT_MAX)
1268b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		vss_count.vc_count = SMBD_VSS_SNAPSHOT_MAX;
1278b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
12889dc44ceSjose borrego 	*count = vss_count.vc_count;
1296d57f833SAlan Wright 	zfs_close(zfshd);
1306d57f833SAlan Wright 	libzfs_fini(libhd);
13189dc44ceSjose borrego 	return (0);
13289dc44ceSjose borrego }
13389dc44ceSjose borrego 
13489dc44ceSjose borrego /*
13589dc44ceSjose borrego  * path - is the path of the dataset
13689dc44ceSjose borrego  * count - is the maxium number of GMT tokens allowed to be returned
13789dc44ceSjose borrego  * return_count - is how many should be returned
13889dc44ceSjose borrego  * num_gmttokens - how many gmttokens in gmttokenp (0 if error)
13989dc44ceSjose borrego  * gmttokenp - array of @GMT tokens (even if zero, elements still need
14089dc44ceSjose borrego  * to be freed)
14189dc44ceSjose borrego  */
14289dc44ceSjose borrego 
14389dc44ceSjose borrego void
smbd_vss_get_snapshots(const char * path,uint32_t count,uint32_t * return_count,uint32_t * num_gmttokens,char ** gmttokenp)1446d57f833SAlan Wright smbd_vss_get_snapshots(const char *path, uint32_t count,
1456d57f833SAlan Wright     uint32_t *return_count, uint32_t *num_gmttokens, char **gmttokenp)
14689dc44ceSjose borrego {
1476d57f833SAlan Wright 	char dataset[MAXPATHLEN];
1486d57f833SAlan Wright 	libzfs_handle_t *libhd;
1496d57f833SAlan Wright 	zfs_handle_t *zfshd;
15089dc44ceSjose borrego 	smbd_vss_get_uint64_date_t vss_uint64_date;
15189dc44ceSjose borrego 	int i;
15289dc44ceSjose borrego 	uint64_t *timep;
15389dc44ceSjose borrego 
15489dc44ceSjose borrego 	*return_count = 0;
15589dc44ceSjose borrego 	*num_gmttokens = 0;
15689dc44ceSjose borrego 
1578b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (count == 0)
1586d57f833SAlan Wright 		return;
15989dc44ceSjose borrego 
1608b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (count > SMBD_VSS_SNAPSHOT_MAX)
1618b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		count = SMBD_VSS_SNAPSHOT_MAX;
16289dc44ceSjose borrego 
16389dc44ceSjose borrego 	vss_uint64_date.gd_count = count;
16489dc44ceSjose borrego 	vss_uint64_date.gd_return_count = 0;
16589dc44ceSjose borrego 	vss_uint64_date.gd_gmt_array = malloc(count * sizeof (uint64_t));
1668b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (vss_uint64_date.gd_gmt_array == NULL)
1678b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		return;
16889dc44ceSjose borrego 
1698b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) {
1708b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		free(vss_uint64_date.gd_gmt_array);
1718b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		return;
1728b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	}
1738b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
1748b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if ((libhd = libzfs_init()) == NULL) {
1758b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		free(vss_uint64_date.gd_gmt_array);
1768b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		return;
1778b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	}
1788b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
1798b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
1808b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		free(vss_uint64_date.gd_gmt_array);
1818b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		libzfs_fini(libhd);
1828b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		return;
1838b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	}
1848b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
1858b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	(void) zfs_iter_snapshots(zfshd, smbd_vss_iterate_get_uint64_date,
18689dc44ceSjose borrego 	    (void *)&vss_uint64_date);
18789dc44ceSjose borrego 
18889dc44ceSjose borrego 	*num_gmttokens = vss_uint64_date.gd_return_count;
18989dc44ceSjose borrego 	*return_count = vss_uint64_date.gd_return_count;
19089dc44ceSjose borrego 
1916d57f833SAlan Wright 	/*
1928b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	 * Sort the list since neither zfs nor the client sorts it.
1936d57f833SAlan Wright 	 */
19489dc44ceSjose borrego 	qsort((char *)vss_uint64_date.gd_gmt_array,
19589dc44ceSjose borrego 	    vss_uint64_date.gd_return_count,
19689dc44ceSjose borrego 	    sizeof (uint64_t), smbd_vss_cmp_time);
19789dc44ceSjose borrego 
19889dc44ceSjose borrego 	timep = vss_uint64_date.gd_gmt_array;
19989dc44ceSjose borrego 
20089dc44ceSjose borrego 	for (i = 0; i < vss_uint64_date.gd_return_count; i++) {
20189dc44ceSjose borrego 		*gmttokenp = malloc(SMB_VSS_GMT_SIZE);
20289dc44ceSjose borrego 
2038b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		if (*gmttokenp)
2048b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 			smbd_vss_time2gmttoken(*timep, *gmttokenp);
2058b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		else
20689dc44ceSjose borrego 			vss_uint64_date.gd_return_count = 0;
20789dc44ceSjose borrego 
20889dc44ceSjose borrego 		timep++;
20989dc44ceSjose borrego 		gmttokenp++;
21089dc44ceSjose borrego 	}
21189dc44ceSjose borrego 
21289dc44ceSjose borrego 	free(vss_uint64_date.gd_gmt_array);
2136d57f833SAlan Wright 	zfs_close(zfshd);
2146d57f833SAlan Wright 	libzfs_fini(libhd);
21589dc44ceSjose borrego }
21689dc44ceSjose borrego 
21789dc44ceSjose borrego /*
21889dc44ceSjose borrego  * path - path of the dataset for the operation
21989dc44ceSjose borrego  * gmttoken - the @GMT token to be looked up
22089dc44ceSjose borrego  * snapname - the snapshot name to be returned
22189dc44ceSjose borrego  *
22289dc44ceSjose borrego  * Here we are going to get the snapshot name from the @GMT token
22389dc44ceSjose borrego  * The snapname returned by ZFS is : <dataset name>@<snapshot name>
22489dc44ceSjose borrego  * So we are going to make sure there is the @ symbol in
22589dc44ceSjose borrego  * the right place and then just return the snapshot name
22689dc44ceSjose borrego  */
22789dc44ceSjose borrego int
smbd_vss_map_gmttoken(const char * path,char * gmttoken,char * snapname)2286d57f833SAlan Wright smbd_vss_map_gmttoken(const char *path, char *gmttoken, char *snapname)
22989dc44ceSjose borrego {
2306d57f833SAlan Wright 	char dataset[MAXPATHLEN];
2316d57f833SAlan Wright 	libzfs_handle_t *libhd;
2326d57f833SAlan Wright 	zfs_handle_t *zfshd;
23389dc44ceSjose borrego 	smbd_vss_map_gmttoken_t vss_map_gmttoken;
2346d57f833SAlan Wright 	char *zsnap;
2356d57f833SAlan Wright 	const char *lsnap;
23689dc44ceSjose borrego 
23789dc44ceSjose borrego 	vss_map_gmttoken.mg_gmttoken = gmttoken;
23889dc44ceSjose borrego 	vss_map_gmttoken.mg_snapname = snapname;
23989dc44ceSjose borrego 	*snapname = '\0';
24089dc44ceSjose borrego 
2416d57f833SAlan Wright 	if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
2426d57f833SAlan Wright 		return (-1);
24389dc44ceSjose borrego 
2446d57f833SAlan Wright 	if ((libhd = libzfs_init()) == NULL)
2456d57f833SAlan Wright 		return (-1);
24689dc44ceSjose borrego 
2476d57f833SAlan Wright 	if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
2486d57f833SAlan Wright 		libzfs_fini(libhd);
24989dc44ceSjose borrego 		return (-1);
25089dc44ceSjose borrego 	}
25189dc44ceSjose borrego 
2526d57f833SAlan Wright 	(void) zfs_iter_snapshots(zfshd, smbd_vss_iterate_map_gmttoken,
25389dc44ceSjose borrego 	    (void *)&vss_map_gmttoken);
25489dc44ceSjose borrego 
25589dc44ceSjose borrego 	/* compare the zfs snapshot name and the local snap name */
25689dc44ceSjose borrego 	zsnap = snapname;
2576d57f833SAlan Wright 	lsnap = dataset;
25889dc44ceSjose borrego 	while ((*lsnap != '\0') && (*zsnap != '\0') && (*lsnap == *zsnap)) {
25989dc44ceSjose borrego 		zsnap++;
26089dc44ceSjose borrego 		lsnap++;
26189dc44ceSjose borrego 	}
26289dc44ceSjose borrego 
26389dc44ceSjose borrego 	/* Now we should be passed the dataset name */
26489dc44ceSjose borrego 	if ((*zsnap == '@') && (*lsnap == '\0')) {
26589dc44ceSjose borrego 		zsnap++;
26689dc44ceSjose borrego 		(void) strlcpy(snapname, zsnap, MAXPATHLEN);
26789dc44ceSjose borrego 	} else {
26889dc44ceSjose borrego 		*snapname = '\0';
26989dc44ceSjose borrego 	}
27089dc44ceSjose borrego 
2716d57f833SAlan Wright 	zfs_close(zfshd);
2726d57f833SAlan Wright 	libzfs_fini(libhd);
27389dc44ceSjose borrego 	return (0);
27489dc44ceSjose borrego }
27589dc44ceSjose borrego 
27689dc44ceSjose borrego static void
smbd_vss_time2gmttoken(time_t time,char * gmttoken)27789dc44ceSjose borrego smbd_vss_time2gmttoken(time_t time, char *gmttoken)
27889dc44ceSjose borrego {
27989dc44ceSjose borrego 	struct tm t;
28089dc44ceSjose borrego 
28189dc44ceSjose borrego 	(void) gmtime_r(&time, &t);
28289dc44ceSjose borrego 
28389dc44ceSjose borrego 	(void) strftime(gmttoken, SMB_VSS_GMT_SIZE,
28489dc44ceSjose borrego 	    "@GMT-%Y.%m.%d-%H.%M.%S", &t);
28589dc44ceSjose borrego }
28689dc44ceSjose borrego 
28789dc44ceSjose borrego static int
smbd_vss_cmp_time(const void * a,const void * b)28889dc44ceSjose borrego smbd_vss_cmp_time(const void *a, const void *b)
28989dc44ceSjose borrego {
29089dc44ceSjose borrego 	if (*(uint64_t *)a < *(uint64_t *)b)
29189dc44ceSjose borrego 		return (1);
29289dc44ceSjose borrego 	if (*(uint64_t *)a == *(uint64_t *)b)
29389dc44ceSjose borrego 		return (0);
29489dc44ceSjose borrego 	return (-1);
29589dc44ceSjose borrego }
29689dc44ceSjose borrego 
2978b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /*
2988b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * ZFS snapshot iterator to count snapshots.
2998b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Note: libzfs expects us to close the handle.
3008b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Return 0 to continue iterating or non-zreo to terminate the iteration.
3018b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  */
30289dc44ceSjose borrego static int
smbd_vss_iterate_count(zfs_handle_t * zhp,void * data)30389dc44ceSjose borrego smbd_vss_iterate_count(zfs_handle_t *zhp, void *data)
30489dc44ceSjose borrego {
3058b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	smbd_vss_count_t *vss_data = data;
3068b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
3078b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (vss_data->vc_count < SMBD_VSS_SNAPSHOT_MAX) {
30889dc44ceSjose borrego 		vss_data->vc_count++;
30989dc44ceSjose borrego 		zfs_close(zhp);
31089dc44ceSjose borrego 		return (0);
31189dc44ceSjose borrego 	}
31289dc44ceSjose borrego 
3138b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	zfs_close(zhp);
3148b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	return (-1);
3158b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States }
3168b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
3178b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /*
3188b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * ZFS snapshot iterator to get snapshot creation time.
3198b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Note: libzfs expects us to close the handle.
3208b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Return 0 to continue iterating or non-zreo to terminate the iteration.
3218b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  */
32289dc44ceSjose borrego static int
smbd_vss_iterate_get_uint64_date(zfs_handle_t * zhp,void * data)32389dc44ceSjose borrego smbd_vss_iterate_get_uint64_date(zfs_handle_t *zhp, void *data)
32489dc44ceSjose borrego {
3258b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	smbd_vss_get_uint64_date_t *vss_data = data;
3268b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	int count;
32789dc44ceSjose borrego 
3288b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	count = vss_data->gd_return_count;
32989dc44ceSjose borrego 
3308b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	if (count < vss_data->gd_count) {
3318b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		vss_data->gd_gmt_array[count] =
33289dc44ceSjose borrego 		    zfs_prop_get_int(zhp, ZFS_PROP_CREATION);
3338b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		vss_data->gd_return_count++;
33489dc44ceSjose borrego 		zfs_close(zhp);
33589dc44ceSjose borrego 		return (0);
33689dc44ceSjose borrego 	}
33789dc44ceSjose borrego 
3388b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	zfs_close(zhp);
3398b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	return (-1);
3408b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States }
3418b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 
3428b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /*
3438b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * ZFS snapshot iterator to map a snapshot creation time to a token.
3448b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Note: libzfs expects us to close the handle.
3458b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Return 0 to continue iterating or non-zreo to terminate the iteration.
3468b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  */
34789dc44ceSjose borrego static int
smbd_vss_iterate_map_gmttoken(zfs_handle_t * zhp,void * data)34889dc44ceSjose borrego smbd_vss_iterate_map_gmttoken(zfs_handle_t *zhp, void *data)
34989dc44ceSjose borrego {
3508b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	smbd_vss_map_gmttoken_t *vss_data = data;
35189dc44ceSjose borrego 	time_t time;
35289dc44ceSjose borrego 	char gmttoken[SMB_VSS_GMT_SIZE];
35389dc44ceSjose borrego 
35489dc44ceSjose borrego 	time = (time_t)zfs_prop_get_int(zhp, ZFS_PROP_CREATION);
35589dc44ceSjose borrego 	smbd_vss_time2gmttoken(time, gmttoken);
35689dc44ceSjose borrego 
3576d57f833SAlan Wright 	if (strncmp(gmttoken, vss_data->mg_gmttoken, SMB_VSS_GMT_SIZE) == 0) {
35889dc44ceSjose borrego 		(void) strlcpy(vss_data->mg_snapname, zfs_get_name(zhp),
35989dc44ceSjose borrego 		    MAXPATHLEN);
36089dc44ceSjose borrego 
36189dc44ceSjose borrego 		/* we found a match, do not process anymore snapshots */
3628b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 		zfs_close(zhp);
36389dc44ceSjose borrego 		return (-1);
36489dc44ceSjose borrego 	}
36589dc44ceSjose borrego 
36689dc44ceSjose borrego 	zfs_close(zhp);
36789dc44ceSjose borrego 	return (0);
36889dc44ceSjose borrego }
369