Skip to content

Commit b93077e

Browse files
grwilsonjsai20
authored andcommitted
Remove dependency on sharetab file and refactor sharing logic
== Motivation and Context The current implementation of 'sharenfs' and 'sharesmb' relies on the use of the sharetab file. The use of this file is os-specific and not required by linux or freebsd. Currently the code must maintain updates to this file which adds complexity and presents a significant performance impact when sharing many datasets. In addition, concurrently running 'zfs sharenfs' command results in missing entries in the sharetab file leading to unexpected failures. == Description This change removes the sharetab logic from the linux and freebsd implementation of 'sharenfs' and 'sharesmb'. It still preserves an os-specific library which contains the logic required for sharing NFS or SMB. The following entry points exist in the vastly simplified libshare library: - sa_enable_share -- shares a dataset but may not commit the change - sa_disable_share -- unshares a dataset but may not commit the change - sa_is_shared -- determine if a dataset is shared - sa_commit_share -- notify NFS/SMB subsystem to commit the shares - sa_validate_shareopts -- determine if sharing options are valid The sa_commit_share entry point is provided as a performance enhancement and is not required. The sa_enable_share/sa_disable_share may commit the share as part of the implementation. Libshare provides a framework for both NFS and SMB but some operating systems may not fully support these protocols or all features of the protocol. NFS Operation: For linux, libshare updates /etc/exports.d/zfs.exports to add and remove shares and then commits the changes by invoking 'exportfs -r'. This file, is automatically read by the kernel NFS implementation which makes for better integration with the NFS systemd service. For FreeBSD, libshare updates /etc/zfs/exports to add and remove shares and then commits the changes by sending a SIGHUP to mountd. SMB Operation: For linux, libshare adds and removes files in /var/lib/samba/usershares by calling the 'net' command directly. There is no need to commit the changes. FreeBSD does not support SMB. == Performance Results To test sharing performance we created a pool with an increasing number of datasets and invoked various zfs actions that would enable and disable sharing. The performance testing was limited to NFS sharing. The following tests were performed on an 8 vCPU system with 128GB and a pool comprised of 4 50GB SSDs: Scale testing: - Share all filesystems in parallel -- zfs sharenfs=on <dataset> & - Unshare all filesystems in parallel -- zfs sharenfs=off <dataset> & Functional testing: - share each filesystem serially -- zfs share -a - unshare each filesystem serially -- zfs unshare -a - reset sharenfs property and unshare -- zfs inherit -r sharenfs <pool> For 'zfs sharenfs=on' scale testing we saw an average reduction in time of 89.43% and for 'zfs sharenfs=off' we saw an average reduction in time of 83.36%. Functional testing also shows a huge improvement: - zfs share -- 97.97% reduction in time - zfs unshare -- 96.47% reduction in time - zfs inhert -r sharenfs -- 99.01% reduction in time Reviewed-by: Matt Ahrens <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Reviewed-by: Bryant G. Ly <[email protected]> Signed-off-by: George Wilson <[email protected]> External-Issue: DLPX-68690 Closes openzfs#1603 Closes openzfs#7692 Closes openzfs#7943 Closes openzfs#10300
1 parent 96026e3 commit b93077e

File tree

30 files changed

+1545
-1651
lines changed

30 files changed

+1545
-1651
lines changed

cmd/zfs/zfs_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ zfs_mount_and_share(libzfs_handle_t *hdl, const char *dataset, zfs_type_t type)
772772
"successfully created, but not shared\n"));
773773
ret = 1;
774774
}
775+
zfs_commit_all_shares();
775776
}
776777

777778
zfs_close(zhp);
@@ -6927,6 +6928,8 @@ share_mount(int op, int argc, char **argv)
69276928
zfs_foreach_mountpoint(g_zfs, cb.cb_handles, cb.cb_used,
69286929
share_mount_one_cb, &share_mount_state,
69296930
op == OP_MOUNT && !(flags & MS_CRYPT));
6931+
zfs_commit_all_shares();
6932+
69306933
ret = share_mount_state.sm_status;
69316934

69326935
for (int i = 0; i < cb.cb_used; i++)
@@ -6979,6 +6982,7 @@ share_mount(int op, int argc, char **argv)
69796982
} else {
69806983
ret = share_mount_one(zhp, op, flags, NULL, B_TRUE,
69816984
options);
6985+
zfs_commit_all_shares();
69826986
zfs_close(zhp);
69836987
}
69846988
}
@@ -7108,6 +7112,7 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual)
71087112
"not currently shared\n"), path);
71097113
} else {
71107114
ret = zfs_unshareall_bypath(zhp, path);
7115+
zfs_commit_all_shares();
71117116
}
71127117
} else {
71137118
char mtpt_prop[ZFS_MAXPROPLEN];
@@ -7328,6 +7333,9 @@ unshare_unmount(int op, int argc, char **argv)
73287333
free(node);
73297334
}
73307335

7336+
if (op == OP_SHARE)
7337+
zfs_commit_shares(protocol);
7338+
73317339
uu_avl_walk_end(walk);
73327340
uu_avl_destroy(tree);
73337341
uu_avl_pool_destroy(pool);

cmd/zpool/zpool_main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2424
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25-
* Copyright (c) 2011, 2018 by Delphix. All rights reserved.
25+
* Copyright (c) 2011, 2020 by Delphix. All rights reserved.
2626
* Copyright (c) 2012 by Frederik Wessels. All rights reserved.
2727
* Copyright (c) 2012 by Cyril Plisko. All rights reserved.
2828
* Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
@@ -1587,8 +1587,10 @@ zpool_do_create(int argc, char **argv)
15871587
zfs_handle_t *pool = zfs_open(g_zfs,
15881588
tname ? tname : poolname, ZFS_TYPE_FILESYSTEM);
15891589
if (pool != NULL) {
1590-
if (zfs_mount(pool, NULL, 0) == 0)
1590+
if (zfs_mount(pool, NULL, 0) == 0) {
15911591
ret = zfs_shareall(pool);
1592+
zfs_commit_all_shares();
1593+
}
15921594
zfs_close(pool);
15931595
}
15941596
} else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {

etc/systemd/system/zfs-share.service.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ PartOf=smb.service
1212
[Service]
1313
Type=oneshot
1414
RemainAfterExit=yes
15-
ExecStartPre=-/bin/rm -f /etc/dfs/sharetab
1615
ExecStart=@sbindir@/zfs share -a
1716

1817
[Install]

include/libzfs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,10 @@ extern int zfs_unshareall_bytype(zfs_handle_t *, const char *, const char *);
837837
extern int zfs_unshareall(zfs_handle_t *);
838838
extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
839839
void *, void *, int, zfs_share_op_t);
840+
extern void zfs_commit_nfs_shares(void);
841+
extern void zfs_commit_smb_shares(void);
842+
extern void zfs_commit_all_shares(void);
843+
extern void zfs_commit_shares(const char *);
840844

841845
extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
842846

include/libzfs_impl.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct libzfs_handle {
4949
int libzfs_error;
5050
int libzfs_fd;
5151
FILE *libzfs_mnttab;
52-
FILE *libzfs_sharetab;
5352
zpool_handle_t *libzfs_pool_handles;
5453
uu_avl_pool_t *libzfs_ns_avlpool;
5554
uu_avl_t *libzfs_ns_avl;
@@ -59,8 +58,6 @@ struct libzfs_handle {
5958
char libzfs_desc[1024];
6059
int libzfs_printerr;
6160
int libzfs_storeerr; /* stuff error messages into buffer */
62-
void *libzfs_sharehdl; /* libshare handle */
63-
uint_t libzfs_shareflags;
6461
boolean_t libzfs_mnttab_enable;
6562
/*
6663
* We need a lock to handle the case where parallel mount
@@ -76,8 +73,6 @@ struct libzfs_handle {
7673
regex_t libzfs_urire;
7774
};
7875

79-
#define ZFSSHARE_MISS 0x01 /* Didn't find entry in cache */
80-
8176
struct zfs_handle {
8277
libzfs_handle_t *zfs_hdl;
8378
zpool_handle_t *zpool_hdl;
@@ -206,12 +201,6 @@ int zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
206201

207202
void namespace_clear(libzfs_handle_t *);
208203

209-
/*
210-
* libshare (sharemgr) interfaces used internally.
211-
*/
212-
213-
extern int zfs_init_libshare(libzfs_handle_t *, int);
214-
extern void zfs_uninit_libshare(libzfs_handle_t *);
215204
extern int zfs_parse_options(char *, zfs_share_proto_t);
216205

217206
extern int zfs_unshare_proto(zfs_handle_t *,
@@ -256,13 +245,14 @@ extern int unshare_one(libzfs_handle_t *hdl, const char *name,
256245
const char *mountpoint, zfs_share_proto_t proto);
257246
extern boolean_t zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen,
258247
zprop_source_t *source, int flags);
259-
extern zfs_share_type_t is_shared_impl(libzfs_handle_t *hdl,
260-
const char *mountpoint, zfs_share_proto_t proto);
248+
extern zfs_share_type_t is_shared(const char *mountpoint,
249+
zfs_share_proto_t proto);
261250
extern int libzfs_load_module(void);
262251
extern int zpool_relabel_disk(libzfs_handle_t *hdl, const char *path,
263252
const char *msg);
264253
extern int find_shares_object(differ_info_t *di);
265254
extern void libzfs_set_pipe_max(int infd);
255+
extern void zfs_commit_proto(zfs_share_proto_t *);
266256

267257
#ifdef __cplusplus
268258
}

include/sys/fs/zfs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,6 @@ typedef struct ddt_histogram {
11701170
#define ZVOL_DRIVER "zvol"
11711171
#define ZFS_DRIVER "zfs"
11721172
#define ZFS_DEV "/dev/zfs"
1173-
#define ZFS_SHARETAB "/etc/dfs/sharetab"
11741173

11751174
#define ZFS_SUPER_MAGIC 0x2fc12fc1
11761175

lib/libshare/Makefile.am

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
include $(top_srcdir)/config/Rules.am
22

3+
DEFAULT_INCLUDES += -I$(srcdir)
4+
35
noinst_LTLIBRARIES = libshare.la
46

57
USER_C = \
68
libshare_impl.h \
79
libshare.c \
8-
nfs.c \
910
nfs.h \
10-
smb.c \
1111
smb.h
1212

13+
if BUILD_LINUX
14+
USER_C += \
15+
os/linux/nfs.c \
16+
os/linux/smb.c
17+
endif
18+
19+
if BUILD_FREEBSD
20+
USER_C += \
21+
os/freebsd/nfs.c \
22+
os/freebsd/smb.c
23+
endif
24+
1325
libshare_la_SOURCES = $(USER_C)

0 commit comments

Comments
 (0)