Skip to content

Commit

Permalink
Fix parallel mount failure caused by ZoL specific behavior
Browse files Browse the repository at this point in the history
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 openzfs#8833 for details.

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
  • Loading branch information
kusumi committed Jun 8, 2019
1 parent 893a6d6 commit 3fa419b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 3fa419b

Please sign in to comment.