From 87335787bab64d78059c248ce95c16b88a512dfb Mon Sep 17 00:00:00 2001 From: George Wilson Date: Mon, 8 Apr 2019 21:37:50 -0600 Subject: [PATCH] DLPX-62600 zfs sharenfs commands make slow progress on scalability system (#45) Signed-off-by: Bryant G. Ly Conflicts: cmd/zpool/zpool_main.c --- cmd/zpool/zpool_main.c | 5 ++--- lib/libshare/libshare.c | 20 ++++++++++++++++++++ lib/libspl/include/libshare.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 1e4cfaefab74..745837d0d183 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -1648,12 +1648,9 @@ zpool_export_one(zpool_handle_t *zhp, void *data) { export_cbdata_t *cb = data; - verify(sharetab_lock() == 0); if (zpool_disable_datasets(zhp, cb->force || cb->hardforce) != 0) { - verify(sharetab_unlock() == 0); return (1); } - verify(sharetab_unlock() == 0); /* The history must be logged as part of the export */ log_history = B_FALSE; @@ -1727,7 +1724,9 @@ zpool_do_export(int argc, char **argv) usage(B_FALSE); } + verify(sharetab_lock() == 0); ret = for_each_pool(argc, argv, B_TRUE, NULL, zpool_export_one, &cb); + verify(sharetab_unlock() == 0); return (ret); } diff --git a/lib/libshare/libshare.c b/lib/libshare/libshare.c index a315e6deeabb..0b4de53e53be 100644 --- a/lib/libshare/libshare.c +++ b/lib/libshare/libshare.c @@ -92,6 +92,20 @@ sa_init(int init_service) impl_handle->zfs_libhandle = libzfs_init(); + /* + * When libshare initializes the shares below, it needs to parse the + * MNTTAB to determine if a filesystem is mounted by calling + * zfs_is_mounted(). On systems with thousands of filesystems, + * repeatedly parsing the MNTTAB can be very slow. As a performance + * improvement, we cache the MNTTAB so that we only have to read it + * once. Repeated calls to zfs_is_mounted will just lookup entries in + * the AVL tree. We can only safely do this when we've locked the + * sharetab to other zfs sharenfs operations from concurrently + * updating the MNTTAB. + */ + if (sharetab_locked()) + libzfs_mnttab_cache(impl_handle->zfs_libhandle, B_TRUE); + if (impl_handle->zfs_libhandle != NULL) { libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE); } @@ -218,6 +232,12 @@ sharetab_unlock(void) return (retval); } +boolean_t +sharetab_locked(void) +{ + return(sharetab_fd != -1); +} + static void update_sharetab(sa_handle_impl_t impl_handle) { diff --git a/lib/libspl/include/libshare.h b/lib/libspl/include/libshare.h index 4831d2260abb..acd9f4dc9810 100644 --- a/lib/libspl/include/libshare.h +++ b/lib/libspl/include/libshare.h @@ -87,6 +87,7 @@ extern int sa_generate_share(const char *, const char *); extern int sharetab_lock(void); extern int sharetab_unlock(void); +extern boolean_t sharetab_locked(void); /* protocol specific interfaces */ extern int sa_parse_legacy_options(sa_group_t, char *, char *);