Allow mounting datasets more than once

Currently mounting an already mounted zfs dataset results in an
error, whereas it is typically allowed with other filesystems.
This causes some bad interactions with mount namespaces. Take
this sequence for example:

- Create a dataset
- Create a snapshot of the dataset
- Create a clone of the snapshot
- Create a new mount namespace
- Rename the original dataset

The rename results in unmounting and remounting the clone in the
original mount namespace, however the remount fails because the
dataset is still mounted in the new mount namespace. (Note that
this means the mount in the new mount namespace is never being
unmounted, so perhaps the unmount/remount of the clone isn't
actually necessary.)

The problem here is a result of the way mounting is implemented
in the kernel module. Since it is not mounting block devices it
uses mount_nodev() instead of the usual mount_bdev(). However,
mount_nodev() is written for filesystems for which each mount is
a new instance (i.e. a new super block), and zfs should be able
to detect when a mount request can be satisfied using an existing
super block.

Change zpl_mount() to call sget() directly with it's own test
callback. Passing the objset_t object as the fs data allows
checking if a superblock already exists for the dataset, and in
that case we just need to return a new reference for the sb's
root dentry.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Alek Pinchuk <apinchuk@datto.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Closes #5796
Closes #7207
This commit is contained in:
Seth Forshee
2018-04-12 15:24:38 -04:00
committed by Brian Behlendorf
parent 1e37dee03f
commit 93b43af10d
8 changed files with 219 additions and 29 deletions
@@ -16,7 +16,8 @@ dist_pkgdata_SCRIPTS = \
zfs_mount_012_neg.ksh \
zfs_mount_encrypted.ksh \
zfs_mount_all_001_pos.ksh \
zfs_mount_remount.ksh
zfs_mount_remount.ksh \
zfs_multi_mount.ksh
dist_pkgdata_DATA = \
zfs_mount.cfg \
@@ -0,0 +1,104 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy is of the CDDL is also available via the Internet
# at http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
#
# Copyright(c) 2018 Datto Inc.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Verify multi mount functionality
#
# STRATEGY:
# 1. Create fs
# 2. Create and hold open file in filesystem
# 3. Lazy unmount
# 4. Verify remounting fs that was lazily unmounted is possible
# 5. Verify multiple mounts of the same dataset are possible
# 6. Verify bind mount doesn't prevent rename
#
verify_runnable "both"
function cleanup
{
ismounted $MNTPFS && log_must umount $MNTPFS
ismounted $MNTPFS2 && log_must umount $MNTPFS2
ismounted $MNTPFS3 && log_must umount $MNTPFS3
ismounted $MNTPFS4 && log_must umount $MNTPFS4
ismounted $RENAMEMNT && log_must umount $RENAMEMNT
datasetexists $TESTDS && log_must destroy_dataset "$TESTDS" "-f"
}
log_onexit cleanup
log_assert "Verify multiple mounts into one namespace are possible"
# 1. Create fs
TESTDS="$TESTPOOL/multi-mount-test"
log_must zfs create $TESTDS
# 2. Create and hold open file in filesystem
MNTPFS="$(get_prop mountpoint $TESTDS)"
FILENAME="$MNTPFS/file"
log_must mkfile 128k $FILENAME
log_must exec 9<> $FILENAME # open file
# 3. Lazy umount
log_must umount -l $MNTPFS
if [ -f $FILENAME ]; then
log_fail "Lazy unmount failed"
fi
# 4. Verify remounting fs that was lazily unmounted is possible
log_must zfs mount $TESTDS
if [ ! -f $FILENAME ]; then
log_fail "Lazy remount failed"
fi
log_must exec 9>&- # close fd
# 5. Verify multiple mounts of the same dataset are possible
MNTPFS2="$MNTPFS-second"
FILENAME="$MNTPFS2/file"
log_must mkdir $MNTPFS2
log_must mount -t zfs -o zfsutil $TESTDS $MNTPFS2
if [ ! -f $FILENAME ]; then
log_fail "First multi mount failed"
fi
MNTPFS3="$MNTPFS-third"
FILENAME="$MNTPFS3/file"
log_must mkdir $MNTPFS3
log_must mount -t zfs -o zfsutil $TESTDS $MNTPFS3
if [ ! -f $FILENAME ]; then
log_fail "Second multi mount failed"
fi
# 6. Verify bind mount doesn't prevent rename
RENAMEFS="$TESTDS-newname"
MNTPFS4="$MNTPFS-fourth"
log_must mkdir $MNTPFS4
log_must mount --bind $MNTPFS $MNTPFS4
log_must zfs rename $TESTDS $RENAMEFS
RENAMEMNT="$(get_prop mountpoint $RENAMEFS)"
FILENAME="$RENAMEMNT/file"
if [ ! -f $FILENAME ]; then
log_fail "Rename failed"
fi
log_must zfs rename $RENAMEFS $TESTDS
log_pass "Multiple mounts are possible"