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 */ 21148c5f43SAlan Wright 2289dc44ceSjose borrego /* 23148c5f43SAlan Wright * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 24*a90cf9f2SGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 2589dc44ceSjose borrego */ 2689dc44ceSjose borrego 2789dc44ceSjose borrego #include <synch.h> 2889dc44ceSjose borrego #include <pthread.h> 2989dc44ceSjose borrego #include <unistd.h> 3089dc44ceSjose borrego #include <string.h> 3189dc44ceSjose borrego #include <strings.h> 3289dc44ceSjose borrego #include <sys/errno.h> 336d57f833SAlan Wright #include <libzfs.h> 3489dc44ceSjose borrego 3589dc44ceSjose borrego #include <smbsrv/libsmb.h> 3689dc44ceSjose borrego #include <smbsrv/libsmbns.h> 3789dc44ceSjose borrego #include <smbsrv/libmlsvc.h> 3889dc44ceSjose borrego #include <smbsrv/smbinfo.h> 3989dc44ceSjose borrego #include "smbd.h" 4089dc44ceSjose borrego 4189dc44ceSjose borrego /* 4289dc44ceSjose borrego * This file supports three basic functions that all use the 4389dc44ceSjose borrego * the zfs_iter_snapshots function to get the snapshot info 4489dc44ceSjose borrego * from ZFS. If the filesystem is not ZFS, the an error is sent 4589dc44ceSjose borrego * to the caller (door functions in this case) with the count of 4689dc44ceSjose borrego * zero in the case of smbd_vss_get_count. Each function 4789dc44ceSjose borrego * is expecting a path that is the root of the dataset. 4889dc44ceSjose borrego * The basic idea is to define a structure for the data and 4989dc44ceSjose borrego * an iterator function that will be called for every snapshot 5089dc44ceSjose borrego * in the dataset that was opened. The iterator function gets 5189dc44ceSjose borrego * a zfs_handle_t(that needs to be closed) for the snapshot 5289dc44ceSjose borrego * and a pointer to the structure of data defined passed to it. 5389dc44ceSjose borrego * If the iterator function returns a non-zero value, no more 5489dc44ceSjose borrego * snapshots will be processed. There is no guarantee in the 5589dc44ceSjose borrego * order in which the snapshots are processed. 5689dc44ceSjose borrego * 5789dc44ceSjose borrego * The structure of this file is: 5889dc44ceSjose borrego * Three structures that are used between the iterator functions 5989dc44ceSjose borrego * and "main" functions 6089dc44ceSjose borrego * The 3 "main" functions 6189dc44ceSjose borrego * Support functions 6289dc44ceSjose borrego * The 3 iterator functions 6389dc44ceSjose borrego */ 6489dc44ceSjose borrego 658b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /* 668b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * The maximum number of snapshots returned per request. 678b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States */ 688b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States #define SMBD_VSS_SNAPSHOT_MAX 725 698b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 7089dc44ceSjose borrego static void smbd_vss_time2gmttoken(time_t time, char *gmttoken); 7189dc44ceSjose borrego static int smbd_vss_cmp_time(const void *a, const void *b); 7289dc44ceSjose borrego static int smbd_vss_iterate_count(zfs_handle_t *zhp, void *data); 7389dc44ceSjose borrego static int smbd_vss_iterate_get_uint64_date(zfs_handle_t *zhp, void *data); 7489dc44ceSjose borrego static int smbd_vss_iterate_map_gmttoken(zfs_handle_t *zhp, void *data); 7589dc44ceSjose borrego 7689dc44ceSjose borrego typedef struct smbd_vss_count { 7789dc44ceSjose borrego int vc_count; 7889dc44ceSjose borrego } smbd_vss_count_t; 7989dc44ceSjose borrego 8089dc44ceSjose borrego /* 8189dc44ceSjose borrego * gd_count how many @GMT tokens are expected 8289dc44ceSjose borrego * gd_return_count how many @GMT tokens are being returned 8389dc44ceSjose borrego * gd_gmt_array array of the @GMT token with max size of gd_count 8489dc44ceSjose borrego */ 8589dc44ceSjose borrego typedef struct smbd_vss_get_uint64_date { 8689dc44ceSjose borrego int gd_count; 8789dc44ceSjose borrego int gd_return_count; 8889dc44ceSjose borrego uint64_t *gd_gmt_array; 8989dc44ceSjose borrego } smbd_vss_get_uint64_date_t; 9089dc44ceSjose borrego 9189dc44ceSjose borrego typedef struct smbd_vss_map_gmttoken { 92*a90cf9f2SGordon Ross time_t mg_snaptime; 9389dc44ceSjose borrego char *mg_snapname; 9489dc44ceSjose borrego } smbd_vss_map_gmttoken_t; 9589dc44ceSjose borrego 9689dc44ceSjose borrego 9789dc44ceSjose borrego /* 9889dc44ceSjose borrego * path - path of the dataset 9989dc44ceSjose borrego * count - return value of the number of snapshots for the dataset 10089dc44ceSjose borrego */ 10189dc44ceSjose borrego int 1026d57f833SAlan Wright smbd_vss_get_count(const char *path, uint32_t *count) 10389dc44ceSjose borrego { 1046d57f833SAlan Wright char dataset[MAXPATHLEN]; 1056d57f833SAlan Wright libzfs_handle_t *libhd; 1066d57f833SAlan Wright zfs_handle_t *zfshd; 10789dc44ceSjose borrego smbd_vss_count_t vss_count; 10889dc44ceSjose borrego 10989dc44ceSjose borrego bzero(&vss_count, sizeof (smbd_vss_count_t)); 11089dc44ceSjose borrego *count = 0; 11189dc44ceSjose borrego 1126d57f833SAlan Wright if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) 1136d57f833SAlan Wright return (-1); 11489dc44ceSjose borrego 1156d57f833SAlan Wright if ((libhd = libzfs_init()) == NULL) 1166d57f833SAlan Wright return (-1); 11789dc44ceSjose borrego 1186d57f833SAlan Wright if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) { 1196d57f833SAlan Wright libzfs_fini(libhd); 12089dc44ceSjose borrego return (-1); 12189dc44ceSjose borrego } 12289dc44ceSjose borrego 1236d57f833SAlan Wright (void) zfs_iter_snapshots(zfshd, smbd_vss_iterate_count, 12489dc44ceSjose borrego (void *)&vss_count); 12589dc44ceSjose borrego 1268b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (vss_count.vc_count > SMBD_VSS_SNAPSHOT_MAX) 1278b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States vss_count.vc_count = SMBD_VSS_SNAPSHOT_MAX; 1288b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 12989dc44ceSjose borrego *count = vss_count.vc_count; 1306d57f833SAlan Wright zfs_close(zfshd); 1316d57f833SAlan Wright libzfs_fini(libhd); 13289dc44ceSjose borrego return (0); 13389dc44ceSjose borrego } 13489dc44ceSjose borrego 13589dc44ceSjose borrego /* 13689dc44ceSjose borrego * path - is the path of the dataset 13789dc44ceSjose borrego * count - is the maxium number of GMT tokens allowed to be returned 13889dc44ceSjose borrego * return_count - is how many should be returned 13989dc44ceSjose borrego * num_gmttokens - how many gmttokens in gmttokenp (0 if error) 14089dc44ceSjose borrego * gmttokenp - array of @GMT tokens (even if zero, elements still need 14189dc44ceSjose borrego * to be freed) 14289dc44ceSjose borrego */ 14389dc44ceSjose borrego 14489dc44ceSjose borrego void 1456d57f833SAlan Wright smbd_vss_get_snapshots(const char *path, uint32_t count, 1466d57f833SAlan Wright uint32_t *return_count, uint32_t *num_gmttokens, char **gmttokenp) 14789dc44ceSjose borrego { 1486d57f833SAlan Wright char dataset[MAXPATHLEN]; 1496d57f833SAlan Wright libzfs_handle_t *libhd; 1506d57f833SAlan Wright zfs_handle_t *zfshd; 15189dc44ceSjose borrego smbd_vss_get_uint64_date_t vss_uint64_date; 15289dc44ceSjose borrego int i; 15389dc44ceSjose borrego uint64_t *timep; 15489dc44ceSjose borrego 15589dc44ceSjose borrego *return_count = 0; 15689dc44ceSjose borrego *num_gmttokens = 0; 15789dc44ceSjose borrego 1588b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (count == 0) 1596d57f833SAlan Wright return; 16089dc44ceSjose borrego 1618b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (count > SMBD_VSS_SNAPSHOT_MAX) 1628b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States count = SMBD_VSS_SNAPSHOT_MAX; 16389dc44ceSjose borrego 16489dc44ceSjose borrego vss_uint64_date.gd_count = count; 16589dc44ceSjose borrego vss_uint64_date.gd_return_count = 0; 16689dc44ceSjose borrego vss_uint64_date.gd_gmt_array = malloc(count * sizeof (uint64_t)); 1678b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (vss_uint64_date.gd_gmt_array == NULL) 1688b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States return; 16989dc44ceSjose borrego 1708b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) { 1718b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States free(vss_uint64_date.gd_gmt_array); 1728b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States return; 1738b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States } 1748b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 1758b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if ((libhd = libzfs_init()) == NULL) { 1768b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States free(vss_uint64_date.gd_gmt_array); 1778b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States return; 1788b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States } 1798b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 1808b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) { 1818b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States free(vss_uint64_date.gd_gmt_array); 1828b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States libzfs_fini(libhd); 1838b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States return; 1848b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States } 1858b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 1868b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States (void) zfs_iter_snapshots(zfshd, smbd_vss_iterate_get_uint64_date, 18789dc44ceSjose borrego (void *)&vss_uint64_date); 18889dc44ceSjose borrego 18989dc44ceSjose borrego *num_gmttokens = vss_uint64_date.gd_return_count; 19089dc44ceSjose borrego *return_count = vss_uint64_date.gd_return_count; 19189dc44ceSjose borrego 1926d57f833SAlan Wright /* 1938b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Sort the list since neither zfs nor the client sorts it. 1946d57f833SAlan Wright */ 19589dc44ceSjose borrego qsort((char *)vss_uint64_date.gd_gmt_array, 19689dc44ceSjose borrego vss_uint64_date.gd_return_count, 19789dc44ceSjose borrego sizeof (uint64_t), smbd_vss_cmp_time); 19889dc44ceSjose borrego 19989dc44ceSjose borrego timep = vss_uint64_date.gd_gmt_array; 20089dc44ceSjose borrego 20189dc44ceSjose borrego for (i = 0; i < vss_uint64_date.gd_return_count; i++) { 20289dc44ceSjose borrego *gmttokenp = malloc(SMB_VSS_GMT_SIZE); 20389dc44ceSjose borrego 2048b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (*gmttokenp) 2058b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States smbd_vss_time2gmttoken(*timep, *gmttokenp); 2068b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States else 20789dc44ceSjose borrego vss_uint64_date.gd_return_count = 0; 20889dc44ceSjose borrego 20989dc44ceSjose borrego timep++; 21089dc44ceSjose borrego gmttokenp++; 21189dc44ceSjose borrego } 21289dc44ceSjose borrego 21389dc44ceSjose borrego free(vss_uint64_date.gd_gmt_array); 2146d57f833SAlan Wright zfs_close(zfshd); 2156d57f833SAlan Wright libzfs_fini(libhd); 21689dc44ceSjose borrego } 21789dc44ceSjose borrego 218*a90cf9f2SGordon Ross static const char 219*a90cf9f2SGordon Ross smbd_vss_gmttoken_fmt[] = "@GMT-%Y.%m.%d-%H.%M.%S"; 220*a90cf9f2SGordon Ross 22189dc44ceSjose borrego /* 22289dc44ceSjose borrego * path - path of the dataset for the operation 22389dc44ceSjose borrego * gmttoken - the @GMT token to be looked up 224*a90cf9f2SGordon Ross * toktime - time_t used if gmttoken == NULL 225*a90cf9f2SGordon Ross * snapname - the snapshot name to be returned [MAXPATHLEN] 22689dc44ceSjose borrego * 22789dc44ceSjose borrego * Here we are going to get the snapshot name from the @GMT token 22889dc44ceSjose borrego * The snapname returned by ZFS is : <dataset name>@<snapshot name> 22989dc44ceSjose borrego * So we are going to make sure there is the @ symbol in 23089dc44ceSjose borrego * the right place and then just return the snapshot name 23189dc44ceSjose borrego */ 23289dc44ceSjose borrego int 233*a90cf9f2SGordon Ross smbd_vss_map_gmttoken(const char *path, char *gmttoken, time_t toktime, 234*a90cf9f2SGordon Ross char *snapname) 23589dc44ceSjose borrego { 2366d57f833SAlan Wright char dataset[MAXPATHLEN]; 2376d57f833SAlan Wright libzfs_handle_t *libhd; 2386d57f833SAlan Wright zfs_handle_t *zfshd; 23989dc44ceSjose borrego smbd_vss_map_gmttoken_t vss_map_gmttoken; 2406d57f833SAlan Wright char *zsnap; 2416d57f833SAlan Wright const char *lsnap; 242*a90cf9f2SGordon Ross struct tm tm; 24389dc44ceSjose borrego 244*a90cf9f2SGordon Ross if (gmttoken != NULL && *gmttoken == '@' && 245*a90cf9f2SGordon Ross strptime(gmttoken, smbd_vss_gmttoken_fmt, &tm) != NULL) { 246*a90cf9f2SGordon Ross toktime = timegm(&tm); 247*a90cf9f2SGordon Ross } 248*a90cf9f2SGordon Ross 249*a90cf9f2SGordon Ross vss_map_gmttoken.mg_snaptime = toktime; 25089dc44ceSjose borrego vss_map_gmttoken.mg_snapname = snapname; 25189dc44ceSjose borrego *snapname = '\0'; 25289dc44ceSjose borrego 2536d57f833SAlan Wright if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) 2546d57f833SAlan Wright return (-1); 25589dc44ceSjose borrego 2566d57f833SAlan Wright if ((libhd = libzfs_init()) == NULL) 2576d57f833SAlan Wright return (-1); 25889dc44ceSjose borrego 2596d57f833SAlan Wright if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) { 2606d57f833SAlan Wright libzfs_fini(libhd); 26189dc44ceSjose borrego return (-1); 26289dc44ceSjose borrego } 26389dc44ceSjose borrego 2646d57f833SAlan Wright (void) zfs_iter_snapshots(zfshd, smbd_vss_iterate_map_gmttoken, 26589dc44ceSjose borrego (void *)&vss_map_gmttoken); 26689dc44ceSjose borrego 26789dc44ceSjose borrego /* compare the zfs snapshot name and the local snap name */ 26889dc44ceSjose borrego zsnap = snapname; 2696d57f833SAlan Wright lsnap = dataset; 27089dc44ceSjose borrego while ((*lsnap != '\0') && (*zsnap != '\0') && (*lsnap == *zsnap)) { 27189dc44ceSjose borrego zsnap++; 27289dc44ceSjose borrego lsnap++; 27389dc44ceSjose borrego } 27489dc44ceSjose borrego 27589dc44ceSjose borrego /* Now we should be passed the dataset name */ 27689dc44ceSjose borrego if ((*zsnap == '@') && (*lsnap == '\0')) { 27789dc44ceSjose borrego zsnap++; 27889dc44ceSjose borrego (void) strlcpy(snapname, zsnap, MAXPATHLEN); 27989dc44ceSjose borrego } else { 28089dc44ceSjose borrego *snapname = '\0'; 28189dc44ceSjose borrego } 28289dc44ceSjose borrego 2836d57f833SAlan Wright zfs_close(zfshd); 2846d57f833SAlan Wright libzfs_fini(libhd); 28589dc44ceSjose borrego return (0); 28689dc44ceSjose borrego } 28789dc44ceSjose borrego 28889dc44ceSjose borrego static void 28989dc44ceSjose borrego smbd_vss_time2gmttoken(time_t time, char *gmttoken) 29089dc44ceSjose borrego { 29189dc44ceSjose borrego struct tm t; 29289dc44ceSjose borrego 29389dc44ceSjose borrego (void) gmtime_r(&time, &t); 29489dc44ceSjose borrego 29589dc44ceSjose borrego (void) strftime(gmttoken, SMB_VSS_GMT_SIZE, 296*a90cf9f2SGordon Ross smbd_vss_gmttoken_fmt, &t); 29789dc44ceSjose borrego } 29889dc44ceSjose borrego 29989dc44ceSjose borrego static int 30089dc44ceSjose borrego smbd_vss_cmp_time(const void *a, const void *b) 30189dc44ceSjose borrego { 30289dc44ceSjose borrego if (*(uint64_t *)a < *(uint64_t *)b) 30389dc44ceSjose borrego return (1); 30489dc44ceSjose borrego if (*(uint64_t *)a == *(uint64_t *)b) 30589dc44ceSjose borrego return (0); 30689dc44ceSjose borrego return (-1); 30789dc44ceSjose borrego } 30889dc44ceSjose borrego 3098b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /* 3108b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * ZFS snapshot iterator to count snapshots. 3118b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Note: libzfs expects us to close the handle. 3128b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Return 0 to continue iterating or non-zreo to terminate the iteration. 3138b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States */ 31489dc44ceSjose borrego static int 31589dc44ceSjose borrego smbd_vss_iterate_count(zfs_handle_t *zhp, void *data) 31689dc44ceSjose borrego { 3178b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States smbd_vss_count_t *vss_data = data; 3188b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 3198b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (vss_data->vc_count < SMBD_VSS_SNAPSHOT_MAX) { 32089dc44ceSjose borrego vss_data->vc_count++; 32189dc44ceSjose borrego zfs_close(zhp); 32289dc44ceSjose borrego return (0); 32389dc44ceSjose borrego } 32489dc44ceSjose borrego 3258b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States zfs_close(zhp); 3268b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States return (-1); 3278b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States } 3288b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 3298b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /* 3308b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * ZFS snapshot iterator to get snapshot creation time. 3318b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Note: libzfs expects us to close the handle. 3328b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Return 0 to continue iterating or non-zreo to terminate the iteration. 3338b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States */ 33489dc44ceSjose borrego static int 33589dc44ceSjose borrego smbd_vss_iterate_get_uint64_date(zfs_handle_t *zhp, void *data) 33689dc44ceSjose borrego { 3378b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States smbd_vss_get_uint64_date_t *vss_data = data; 3388b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States int count; 33989dc44ceSjose borrego 3408b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States count = vss_data->gd_return_count; 34189dc44ceSjose borrego 3428b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States if (count < vss_data->gd_count) { 3438b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States vss_data->gd_gmt_array[count] = 34489dc44ceSjose borrego zfs_prop_get_int(zhp, ZFS_PROP_CREATION); 3458b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States vss_data->gd_return_count++; 34689dc44ceSjose borrego zfs_close(zhp); 34789dc44ceSjose borrego return (0); 34889dc44ceSjose borrego } 34989dc44ceSjose borrego 3508b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States zfs_close(zhp); 3518b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States return (-1); 3528b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States } 3538b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 3548b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States /* 3558b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * ZFS snapshot iterator to map a snapshot creation time to a token. 3568b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Note: libzfs expects us to close the handle. 3578b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States * Return 0 to continue iterating or non-zreo to terminate the iteration. 3588b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States */ 35989dc44ceSjose borrego static int 36089dc44ceSjose borrego smbd_vss_iterate_map_gmttoken(zfs_handle_t *zhp, void *data) 36189dc44ceSjose borrego { 3628b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States smbd_vss_map_gmttoken_t *vss_data = data; 36389dc44ceSjose borrego time_t time; 36489dc44ceSjose borrego 36589dc44ceSjose borrego time = (time_t)zfs_prop_get_int(zhp, ZFS_PROP_CREATION); 366*a90cf9f2SGordon Ross if (time == vss_data->mg_snaptime) { 36789dc44ceSjose borrego (void) strlcpy(vss_data->mg_snapname, zfs_get_name(zhp), 36889dc44ceSjose borrego MAXPATHLEN); 36989dc44ceSjose borrego 37089dc44ceSjose borrego /* we found a match, do not process anymore snapshots */ 3718b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States zfs_close(zhp); 37289dc44ceSjose borrego return (-1); 37389dc44ceSjose borrego } 37489dc44ceSjose borrego 37589dc44ceSjose borrego zfs_close(zhp); 37689dc44ceSjose borrego return (0); 37789dc44ceSjose borrego } 378