Skip to content

Commit

Permalink
11032 Time spent sharing SMB filesystems could be reduced by optimizi…
Browse files Browse the repository at this point in the history
…ng 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>
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Approved by: Garrett D'Amore <garrett@damore.org>
  • Loading branch information
joicemcintosh authored and gwr committed Aug 22, 2019
1 parent 44bf619 commit 87b8175
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 36 deletions.
20 changes: 13 additions & 7 deletions usr/src/cmd/smbsrv/smbd/smbd_vss.c
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
* Copyright 2016 Martin Matuska. All rights reserved.
*/

Expand Down Expand Up @@ -110,11 +110,13 @@ smbd_vss_get_count(const char *path, uint32_t *count)
bzero(&vss_count, sizeof (smbd_vss_count_t));
*count = 0;

if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
if ((libhd = libzfs_init()) == NULL)
return (-1);

if ((libhd = libzfs_init()) == NULL)
if (smb_getdataset(libhd, path, dataset, MAXPATHLEN) != 0) {
libzfs_fini(libhd);
return (-1);
}

if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
libzfs_fini(libhd);
Expand Down Expand Up @@ -165,16 +167,18 @@ smbd_vss_get_snapshots(const char *path, uint32_t count,
vss_uint64_date.gd_count = count;
vss_uint64_date.gd_return_count = 0;
vss_uint64_date.gd_gmt_array = malloc(count * sizeof (uint64_t));

if (vss_uint64_date.gd_gmt_array == NULL)
return;

if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) {
if ((libhd = libzfs_init()) == NULL) {
free(vss_uint64_date.gd_gmt_array);
return;
}

if ((libhd = libzfs_init()) == NULL) {
if (smb_getdataset(libhd, path, dataset, MAXPATHLEN) != 0) {
free(vss_uint64_date.gd_gmt_array);
libzfs_fini(libhd);
return;
}

Expand Down Expand Up @@ -251,11 +255,13 @@ smbd_vss_map_gmttoken(const char *path, char *gmttoken, time_t toktime,
vss_map_gmttoken.mg_snapname = snapname;
*snapname = '\0';

if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
if ((libhd = libzfs_init()) == NULL)
return (-1);

if ((libhd = libzfs_init()) == NULL)
if (smb_getdataset(libhd, path, dataset, MAXPATHLEN) != 0) {
libzfs_fini(libhd);
return (-1);
}

if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
libzfs_fini(libhd);
Expand Down
10 changes: 6 additions & 4 deletions usr/src/lib/smbsrv/libmlsvc/common/smb_quota.c
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/

#include <stdio.h>
Expand Down Expand Up @@ -1083,12 +1083,14 @@ smb_quota_zfs_init(const char *path, smb_quota_zfs_handle_t *zfs_hdl)
{
char dataset[MAXPATHLEN];

if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
return (NT_STATUS_INVALID_PARAMETER);

if ((zfs_hdl->z_lib = libzfs_init()) == NULL)
return (NT_STATUS_INTERNAL_ERROR);

if (smb_getdataset(zfs_hdl->z_lib, path, dataset, MAXPATHLEN) != 0) {
libzfs_fini(zfs_hdl->z_lib);
return (NT_STATUS_INVALID_PARAMETER);
}

zfs_hdl->z_fs = zfs_open(zfs_hdl->z_lib, dataset, ZFS_TYPE_DATASET);
if (zfs_hdl->z_fs == NULL) {
libzfs_fini(zfs_hdl->z_lib);
Expand Down
20 changes: 13 additions & 7 deletions usr/src/lib/smbsrv/libmlsvc/common/smb_share.c
Expand Up @@ -19,7 +19,7 @@
* CDDL HEADER END
*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2017 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/

/*
Expand Down Expand Up @@ -2240,11 +2240,13 @@ smb_shr_zfs_add(smb_share_t *si)
int ret;
char buf[MAXPATHLEN]; /* dataset or mountpoint */

if (smb_getdataset(si->shr_path, buf, MAXPATHLEN) != 0)
if ((libhd = libzfs_init()) == NULL)
return;

if ((libhd = libzfs_init()) == NULL)
if (smb_getdataset(libhd, si->shr_path, buf, MAXPATHLEN) != 0) {
libzfs_fini(libhd);
return;
}

if ((zfshd = zfs_open(libhd, buf, ZFS_TYPE_FILESYSTEM)) == NULL) {
libzfs_fini(libhd);
Expand Down Expand Up @@ -2285,11 +2287,13 @@ smb_shr_zfs_remove(smb_share_t *si)
int ret;
char buf[MAXPATHLEN]; /* dataset or mountpoint */

if (smb_getdataset(si->shr_path, buf, MAXPATHLEN) != 0)
if ((libhd = libzfs_init()) == NULL)
return;

if ((libhd = libzfs_init()) == NULL)
if (smb_getdataset(libhd, si->shr_path, buf, MAXPATHLEN) != 0) {
libzfs_fini(libhd);
return;
}

errno = 0;
ret = zfs_smb_acl_remove(libhd, buf, si->shr_path, si->shr_name);
Expand Down Expand Up @@ -2318,11 +2322,13 @@ smb_shr_zfs_rename(smb_share_t *from, smb_share_t *to)
int ret;
char dataset[MAXPATHLEN];

if (smb_getdataset(from->shr_path, dataset, MAXPATHLEN) != 0)
if ((libhd = libzfs_init()) == NULL)
return;

if ((libhd = libzfs_init()) == NULL)
if (smb_getdataset(libhd, from->shr_path, dataset, MAXPATHLEN) != 0) {
libzfs_fini(libhd);
return;
}

if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_FILESYSTEM)) == NULL) {
libzfs_fini(libhd);
Expand Down
12 changes: 8 additions & 4 deletions usr/src/lib/smbsrv/libmlsvc/common/srvsvc_sd.c
Expand Up @@ -21,6 +21,7 @@

/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/

/*
Expand Down Expand Up @@ -59,13 +60,16 @@ srvsvc_shareacl_getpath(smb_share_t *si, char *shr_acl_path)
zfs_handle_t *zfshd;
int ret = 0;

ret = smb_getdataset(si->shr_path, dataset, MAXPATHLEN);
if (ret != 0)
return (ret);

if ((libhd = libzfs_init()) == NULL)
return (-1);

ret = smb_getdataset(libhd, si->shr_path, dataset, MAXPATHLEN);
if (ret != 0) {
libzfs_fini(libhd);
return (ret);
}


if ((zfshd = zfs_open(libhd, dataset, ZFS_TYPE_DATASET)) == NULL) {
libzfs_fini(libhd);
return (-1);
Expand Down
14 changes: 7 additions & 7 deletions usr/src/lib/smbsrv/libsmb/Makefile.com
Expand Up @@ -20,30 +20,30 @@
#
#
# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
# Copyright 2018 Nexenta Systems, Inc. All rights reserved.
#
# Copyright (c) 2018, Joyent, Inc.

LIBRARY= libsmb.a
VERS= .1

OBJS_SHARED = \
OBJS_SHARED = \
smb_cfg_util.o \
smb_door_legacy.o \
smb_door_legacy.o \
smb_inet.o \
smb_msgbuf.o \
smb_native.o \
smb_oem.o \
smb_sid.o \
smb_string.o \
smb_string.o \
smb_token.o \
smb_token_xdr.o \
smb_utf8.o \
smb_xdr.o

OBJS_COMMON = \
OBJS_COMMON = \
smb_acl.o \
smb_auth.o \
smb_auth.o \
smb_cache.o \
smb_cfg.o \
smb_crypt.o \
Expand Down Expand Up @@ -83,7 +83,7 @@ LDLIBS += $(MACH_LDLIBS)
# perfer to keep libs ordered by dependence
LDLIBS += -lscf -lmd -luuid -lpkcs11 -lcryptoutil
LDLIBS += -lsec -lidmap -lreparse -lcmdutils -lavl
LDLIBS += -lnvpair -lresolv -lsocket -lnsl -lc
LDLIBS += -lnvpair -lresolv -lsocket -lnsl -lzfs -lc
CPPFLAGS += $(INCS) -D_REENTRANT
CPPFLAGS += -Dsyslog=smb_syslog
CERRWARN += $(CNOWARN_UNINIT)
Expand Down
5 changes: 3 additions & 2 deletions usr/src/lib/smbsrv/libsmb/common/libsmb.h
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2017 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/

#ifndef _LIBSMB_H
Expand Down Expand Up @@ -186,7 +186,8 @@ extern int smb_smf_restart_service(void);
extern int smb_smf_maintenance_mode(void);

/* ZFS interface */
int smb_getdataset(const char *, char *, size_t);
struct libzfs_handle;
int smb_getdataset(struct libzfs_handle *, const char *, char *, size_t);

/* Configuration management functions */
extern int smb_config_get(smb_cfg_id_t, char *, int);
Expand Down
38 changes: 33 additions & 5 deletions usr/src/lib/smbsrv/libsmb/common/smb_util.c
Expand Up @@ -20,7 +20,7 @@
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/

#include <ctype.h>
Expand Down Expand Up @@ -627,7 +627,8 @@ smb_netgroup_match(struct nd_hostservlist *clnames, char *glist, int grc)
* -1 = Failure to open /etc/mnttab file or to get ZFS dataset.
*/
int
smb_getdataset(const char *path, char *dataset, size_t len)
smb_getdataset(libzfs_handle_t *libhdl, const char *path, char *dataset,
size_t len)
{
char tmppath[MAXPATHLEN];
char *cp;
Expand All @@ -636,6 +637,33 @@ smb_getdataset(const char *path, char *dataset, size_t len)
struct mnttab mntpref;
int rc = -1;

/*
* Optimisation: if the path is the default mountpoint then
* the dataset name can be determined from path.
* Attempt to open dataset by derived name and, if successful,
* check if its mountpoint matches path.
*/
if (libhdl != NULL) {
zfs_handle_t *hdl;
char mountpnt[ZFS_MAXPROPLEN];
char *dsname = (char *)path + strspn(path, "/");

hdl = zfs_open(libhdl, dsname, ZFS_TYPE_FILESYSTEM);
if (hdl != NULL) {
if ((zfs_prop_get(hdl, ZFS_PROP_MOUNTPOINT, mountpnt,
sizeof (mountpnt), NULL, NULL, 0, B_FALSE) == 0) &&
(strcmp(mountpnt, path) == 0)) {
zfs_close(hdl);
(void) strlcpy(dataset, dsname, len);
return (0);
}
zfs_close(hdl);
}
}

/*
* Couldn't find a filesystem optimistically, use mnttab
*/
if ((fp = fopen(MNTTAB, "r")) == NULL)
return (-1);

Expand Down Expand Up @@ -899,9 +927,9 @@ smb_name_validate_domain(const char *domain)
* hyphens.
*
* It cannot:
* - be blank or longer than 15 chracters
* - contain all numbers
* - be the same as the computer name
* - be blank or longer than 15 chracters
* - contain all numbers
* - be the same as the computer name
*/
uint32_t
smb_name_validate_nbdomain(const char *name)
Expand Down

0 comments on commit 87b8175

Please sign in to comment.