From 3fa419b0931f93da7401b24da9107e3a7ad71fe0 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Sat, 8 Jun 2019 01:37:03 +0900 Subject: [PATCH] Fix parallel mount failure caused by ZoL specific behavior The main reason parallel mount behaves differently on ZoL is that pthreads fork/execs another process for /bin/mount, whereas illumos and FreeBSD calls mount(2) and nmount(2) respectively. By taking a global lock around /bin/mount (and also /bin/umount) call, ZoL will behave similarly to other implementations. See #8833 for details. Signed-off-by: Tomohiro Kusumi --- lib/libzfs/libzfs_mount.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index 649c232aa3e..a92acbfda27 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -352,6 +352,8 @@ zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen, * http://www.kernel.org/pub/linux/utils/util-linux/libmount-docs/index.html */ +static pthread_mutex_t mount_lock = PTHREAD_MUTEX_INITIALIZER; + static int do_mount(const char *src, const char *mntpt, char *opts) { @@ -366,7 +368,9 @@ do_mount(const char *src, const char *mntpt, char *opts) int rc; /* Return only the most critical mount error */ + pthread_mutex_lock(&mount_lock); rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE); + pthread_mutex_unlock(&mount_lock); if (rc) { if (rc & MOUNT_FILEIO) return (EIO); @@ -409,7 +413,10 @@ do_unmount(const char *mntpt, int flags) } argv[count] = (char *)mntpt; + + pthread_mutex_lock(&mount_lock); rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE); + pthread_mutex_unlock(&mount_lock); return (rc ? EINVAL : 0); }