Print this page
NEX-16159 Time spent sharing SMB filesystems could be reduced by optimizing smb_getdataset for default mount points
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Reviewed by: Matt Barden <matt.barden@nexenta.com>
SMB-136 Snapshots not visible in Windows previous versions

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/smbsrv/smbd/smbd_vss.c
          +++ new/usr/src/cmd/smbsrv/smbd/smbd_vss.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
       24 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  25   25   * Copyright 2016 Martin Matuska. All rights reserved.
  26   26   */
  27   27  
  28   28  #include <synch.h>
  29   29  #include <pthread.h>
  30   30  #include <unistd.h>
  31   31  #include <string.h>
  32   32  #include <strings.h>
  33   33  #include <sys/errno.h>
  34   34  #include <libzfs.h>
↓ open down ↓ 68 lines elided ↑ open up ↑
 103  103  smbd_vss_get_count(const char *path, uint32_t *count)
 104  104  {
 105  105          char dataset[MAXPATHLEN];
 106  106          libzfs_handle_t *libhd;
 107  107          zfs_handle_t *zfshd;
 108  108          smbd_vss_count_t vss_count;
 109  109  
 110  110          bzero(&vss_count, sizeof (smbd_vss_count_t));
 111  111          *count = 0;
 112  112  
 113      -        if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
      113 +        if ((libhd = libzfs_init()) == NULL)
 114  114                  return (-1);
 115  115  
 116      -        if ((libhd = libzfs_init()) == NULL)
      116 +        if (smb_getdataset(libhd, path, dataset, MAXPATHLEN) != 0) {
      117 +                libzfs_fini(libhd);
 117  118                  return (-1);
      119 +        }
 118  120  
 119  121          if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
 120  122                  libzfs_fini(libhd);
 121  123                  return (-1);
 122  124          }
 123  125  
 124  126          (void) zfs_iter_snapshots(zfshd, B_FALSE, smbd_vss_iterate_count,
 125  127              (void *)&vss_count);
 126  128  
 127  129          if (vss_count.vc_count > SMBD_VSS_SNAPSHOT_MAX)
↓ open down ↓ 30 lines elided ↑ open up ↑
 158  160  
 159  161          if (count == 0)
 160  162                  return;
 161  163  
 162  164          if (count > SMBD_VSS_SNAPSHOT_MAX)
 163  165                  count = SMBD_VSS_SNAPSHOT_MAX;
 164  166  
 165  167          vss_uint64_date.gd_count = count;
 166  168          vss_uint64_date.gd_return_count = 0;
 167  169          vss_uint64_date.gd_gmt_array = malloc(count * sizeof (uint64_t));
      170 +
 168  171          if (vss_uint64_date.gd_gmt_array == NULL)
 169  172                  return;
 170  173  
 171      -        if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) {
      174 +        if ((libhd = libzfs_init()) == NULL) {
 172  175                  free(vss_uint64_date.gd_gmt_array);
 173  176                  return;
 174  177          }
 175  178  
 176      -        if ((libhd = libzfs_init()) == NULL) {
      179 +        if (smb_getdataset(libhd, path, dataset, MAXPATHLEN) != 0) {
 177  180                  free(vss_uint64_date.gd_gmt_array);
      181 +                libzfs_fini(libhd);
 178  182                  return;
 179  183          }
 180  184  
 181  185          if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
 182  186                  free(vss_uint64_date.gd_gmt_array);
 183  187                  libzfs_fini(libhd);
 184  188                  return;
 185  189          }
 186  190  
 187  191          (void) zfs_iter_snapshots(zfshd, B_FALSE,
↓ open down ↓ 56 lines elided ↑ open up ↑
 244  248  
 245  249          if (gmttoken != NULL && *gmttoken == '@' &&
 246  250              strptime(gmttoken, smbd_vss_gmttoken_fmt, &tm) != NULL) {
 247  251                  toktime = timegm(&tm);
 248  252          }
 249  253  
 250  254          vss_map_gmttoken.mg_snaptime = toktime;
 251  255          vss_map_gmttoken.mg_snapname = snapname;
 252  256          *snapname = '\0';
 253  257  
 254      -        if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
      258 +        if ((libhd = libzfs_init()) == NULL)
 255  259                  return (-1);
 256  260  
 257      -        if ((libhd = libzfs_init()) == NULL)
      261 +        if (smb_getdataset(libhd, path, dataset, MAXPATHLEN) != 0) {
      262 +                libzfs_fini(libhd);
 258  263                  return (-1);
      264 +        }
 259  265  
 260  266          if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
 261  267                  libzfs_fini(libhd);
 262  268                  return (-1);
 263  269          }
 264  270  
 265  271          (void) zfs_iter_snapshots(zfshd, B_FALSE, smbd_vss_iterate_map_gmttoken,
 266  272              (void *)&vss_map_gmttoken);
 267  273  
 268  274          /* compare the zfs snapshot name and the local snap name */
↓ open down ↓ 110 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX