BugLink: https://bugs.launchpad.net/bugs/1759848
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.
[ Sync'd from zfsutils-linux, from a patch by Seth Forshee ]
Signed-off-by: Colin Ian King <colin.king@canonical.com>
[ saf: sync missing test for HAVE_FST_MOUNT ]
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
UBUNTU: SAUCE: (noup) Update zfs to 0.7.5-1ubuntu13
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Name: zfs
Branch: 1.0
Version: 0.7.5
-Release: 1ubuntu12
+Release: 1ubuntu13
Release-Tags: relext
License: CDDL
Author: OpenZFS on Linux
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
m4_include([config/kernel-fmode-t.m4])
m4_include([config/kernel-follow-down-one.m4])
m4_include([config/kernel-fpu.m4])
+m4_include([config/kernel-fst-mount.m4])
m4_include([config/kernel-fsync.m4])
m4_include([config/kernel-generic_io_acct.m4])
m4_include([config/kernel-generic_readlink.m4])
m4_include([config/kernel-mk-request-fn.m4])
m4_include([config/kernel-mkdir-umode-t.m4])
m4_include([config/kernel-mod-param.m4])
-m4_include([config/kernel-mount-nodev.m4])
m4_include([config/kernel-objtool.m4])
m4_include([config/kernel-open-bdev-exclusive.m4])
m4_include([config/kernel-put-link.m4])
--- /dev/null
+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)
+ ])
+])
+++ /dev/null
-dnl #
-dnl # 2.6.39 API change
-dnl # The .get_sb callback has been replaced by a .mount callback
-dnl # in the file_system_type structure. When using the new
-dnl # interface the caller must now use the mount_nodev() helper.
-dnl # This updated callback and helper no longer pass the vfsmount.
-dnl #
-AC_DEFUN([ZFS_AC_KERNEL_MOUNT_NODEV],
- [AC_MSG_CHECKING([whether mount_nodev() is available])
- ZFS_LINUX_TRY_COMPILE_SYMBOL([
- #include <linux/fs.h>
- ], [
- mount_nodev(NULL, 0, NULL, NULL);
- ], [mount_nodev], [fs/super.c], [
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_MOUNT_NODEV, 1, [mount_nodev() is available])
- ], [
- AC_MSG_RESULT(no)
- ])
-])
ZFS_AC_KERNEL_TRUNCATE_SETSIZE
ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
- ZFS_AC_KERNEL_MOUNT_NODEV
+ ZFS_AC_KERNEL_FST_MOUNT
ZFS_AC_KERNEL_SHRINK
ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
ZFS_AC_KERNEL_S_INSTANCES_LIST_HEAD
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mount_nodev() is available" >&5
-$as_echo_n "checking whether mount_nodev() is available... " >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether fst->mount() exists" >&5
+$as_echo_n "checking whether fst->mount() exists... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.c
- #include <linux/fs.h>
+ #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,
+ };
int
main (void)
{
- mount_nodev(NULL, 0, NULL, NULL);
;
return 0;
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then :
- rc=0
-else
- $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
- rc=1
-
-fi
- rm -Rf build
-
-
- if test $rc -ne 0; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+$as_echo "#define HAVE_FST_MOUNT 1" >>confdefs.h
- else
- if test "x$enable_linux_builtin" != xyes; then
-
- grep -q -E '[[:space:]]mount_nodev[[:space:]]' \
- $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
- rc=$?
- if test $rc -ne 0; then
- export=0
- for file in fs/super.c; do
- grep -q -E "EXPORT_SYMBOL.*(mount_nodev)" \
- "$LINUX/$file" 2>/dev/null
- rc=$?
- if test $rc -eq 0; then
- export=1
- break;
- fi
- done
- if test $export -eq 0; then :
- rc=1
- else :
- rc=0
- fi
- else :
- rc=0
- fi
- fi
- if test $rc -ne 0; then :
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- else :
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-$as_echo "#define HAVE_MOUNT_NODEV 1" >>confdefs.h
+fi
+ rm -Rf build
- fi
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mount_nodev() is available" >&5
-$as_echo_n "checking whether mount_nodev() is available... " >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether fst->mount() exists" >&5
+$as_echo_n "checking whether fst->mount() exists... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.c
- #include <linux/fs.h>
+ #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,
+ };
int
main (void)
{
- mount_nodev(NULL, 0, NULL, NULL);
;
return 0;
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then :
- rc=0
-else
- $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
- rc=1
-
-fi
- rm -Rf build
-
-
- if test $rc -ne 0; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+$as_echo "#define HAVE_FST_MOUNT 1" >>confdefs.h
- else
- if test "x$enable_linux_builtin" != xyes; then
-
- grep -q -E '[[:space:]]mount_nodev[[:space:]]' \
- $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
- rc=$?
- if test $rc -ne 0; then
- export=0
- for file in fs/super.c; do
- grep -q -E "EXPORT_SYMBOL.*(mount_nodev)" \
- "$LINUX/$file" 2>/dev/null
- rc=$?
- if test $rc -eq 0; then
- export=1
- break;
- fi
- done
- if test $export -eq 0; then :
- rc=1
- else :
- rc=0
- fi
- else :
- rc=0
- fi
- fi
- if test $rc -ne 0; then :
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- else :
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-$as_echo "#define HAVE_MOUNT_NODEV 1" >>confdefs.h
+fi
+ rm -Rf build
- fi
- fi
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
}
#endif
+/*
+ * 4.14 adds SB_* flag definitions, define them to MS_* equivalents
+ * if not set.
+ */
+#ifndef SB_RDONLY
+#define SB_RDONLY MS_RDONLY
+#endif
+
+#ifndef SB_SILENT
+#define SB_SILENT MS_SILENT
+#endif
+
+#ifndef SB_ACTIVE
+#define SB_ACTIVE MS_ACTIVE
+#endif
+
+#ifndef SB_POSIXACL
+#define SB_POSIXACL MS_POSIXACL
+#endif
+
+#ifndef SB_MANDLOCK
+#define SB_MANDLOCK MS_MANDLOCK
+#endif
+
/*
* 2.6.38 API change,
* LOOKUP_RCU flag introduced to distinguish rcu-walk from ref-walk cases.
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
$(top_srcdir)/config/kernel-fmode-t.m4 \
$(top_srcdir)/config/kernel-follow-down-one.m4 \
$(top_srcdir)/config/kernel-fpu.m4 \
+ $(top_srcdir)/config/kernel-fst-mount.m4 \
$(top_srcdir)/config/kernel-fsync.m4 \
$(top_srcdir)/config/kernel-generic_io_acct.m4 \
$(top_srcdir)/config/kernel-generic_readlink.m4 \
$(top_srcdir)/config/kernel-mk-request-fn.m4 \
$(top_srcdir)/config/kernel-mkdir-umode-t.m4 \
$(top_srcdir)/config/kernel-mod-param.m4 \
- $(top_srcdir)/config/kernel-mount-nodev.m4 \
$(top_srcdir)/config/kernel-objtool.m4 \
$(top_srcdir)/config/kernel-open-bdev-exclusive.m4 \
$(top_srcdir)/config/kernel-put-link.m4 \
return (error);
}
-#ifdef HAVE_MOUNT_NODEV
+static int
+zpl_test_super(struct super_block *s, void *data)
+{
+ zfsvfs_t *zfsvfs = s->s_fs_info;
+ objset_t *os = data;
+
+ if (zfsvfs == NULL)
+ return (0);
+
+ return (os == zfsvfs->z_os);
+}
+
+static struct super_block *
+zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
+{
+ struct super_block *s;
+ objset_t *os;
+ int err;
+
+ err = dmu_objset_hold(zm->mnt_osname, FTAG, &os);
+ if (err)
+ return (ERR_PTR(-err));
+
+ s = zpl_sget(fs_type, zpl_test_super, set_anon_super, flags, os);
+ dmu_objset_rele(os, FTAG);
+ if (IS_ERR(s))
+ return (ERR_CAST(s));
+
+ if (s->s_root == NULL) {
+ err = zpl_fill_super(s, zm, flags & SB_SILENT ? 1 : 0);
+ if (err) {
+ deactivate_locked_super(s);
+ return (ERR_PTR(err));
+ }
+ s->s_flags |= SB_ACTIVE;
+ } else if ((flags ^ s->s_flags) & SB_RDONLY) {
+ deactivate_locked_super(s);
+ return (ERR_PTR(-EBUSY));
+ }
+
+ return (s);
+}
+
+#ifdef HAVE_FST_MOUNT
static struct dentry *
zpl_mount(struct file_system_type *fs_type, int flags,
const char *osname, void *data)
{
zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
- return (mount_nodev(fs_type, flags, &zm, zpl_fill_super));
+ struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
+ if (IS_ERR(sb))
+ return (ERR_CAST(sb));
+
+ return (dget(sb->s_root));
}
#else
static int
{
zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
- return (get_sb_nodev(fs_type, flags, &zm, zpl_fill_super, mnt));
+ struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
+ if (IS_ERR(sb))
+ return (PTR_ERR(sb));
+
+ (void) simple_set_mnt(mnt, sb);
+
+ return (0);
}
-#endif /* HAVE_MOUNT_NODEV */
+#endif /* HAVE_FST_MOUNT */
static void
zpl_kill_sb(struct super_block *sb)
struct file_system_type zpl_fs_type = {
.owner = THIS_MODULE,
.name = ZFS_DRIVER,
-#ifdef HAVE_MOUNT_NODEV
+#ifdef HAVE_FST_MOUNT
.mount = zpl_mount,
#else
.get_sb = zpl_get_sb,
-#endif /* HAVE_MOUNT_NODEV */
+#endif /* HAVE_FST_MOUNT */
.kill_sb = zpl_kill_sb,
};
/* sops->free_cached_objects() exists */
#undef HAVE_FREE_CACHED_OBJECTS
+/* fst->mount() exists */
+#undef HAVE_FST_MOUNT
+
/* fops->fsync() with range */
#undef HAVE_FSYNC_RANGE
/* Define to 1 if you have the `mlockall' function. */
#undef HAVE_MLOCKALL
-/* mount_nodev() is available */
-#undef HAVE_MOUNT_NODEV
-
/* new_sync_read() is available */
#undef HAVE_NEW_SYNC_READ