forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-by: Tom Caputi <[email protected]> Signed-off-by: Alek Pinchuk <[email protected]> Signed-off-by: Seth Forshee <[email protected]> Closes openzfs#5796 Closes openzfs#7207
- Loading branch information
1 parent
1e37dee
commit 93b43af
Showing
8 changed files
with
219 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
dnl # | ||
dnl # 2.6.38 API change | ||
dnl # The .get_sb callback has been replaced by a .mount callback | ||
dnl # in the file_system_type structure. | ||
dnl # | ||
AC_DEFUN([ZFS_AC_KERNEL_FST_MOUNT], [ | ||
AC_MSG_CHECKING([whether fst->mount() exists]) | ||
ZFS_LINUX_TRY_COMPILE([ | ||
#include <linux/fs.h> | ||
static struct dentry * | ||
mount(struct file_system_type *fs_type, int flags, | ||
const char *osname, void *data) { | ||
struct dentry *d = NULL; | ||
return (d); | ||
} | ||
static struct file_system_type fst __attribute__ ((unused)) = { | ||
.mount = mount, | ||
}; | ||
],[ | ||
],[ | ||
AC_MSG_RESULT(yes) | ||
AC_DEFINE(HAVE_FST_MOUNT, 1, [fst->mount() exists]) | ||
],[ | ||
AC_MSG_RESULT(no) | ||
]) | ||
]) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_multi_mount.ksh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |