Skip to content

Commit f3d4c79

Browse files
authored
zpl_super: prefer "new" mount API when available
This API has been available since kernel 5.2, and having it available (almost) everywhere should give us a lot more flexibility for mount management in the future. Sponsored-by: TrueNAS Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #18260
1 parent 09c27a1 commit f3d4c79

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

config/kernel-fs-context.m4

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
dnl # SPDX-License-Identifier: CDDL-1.0
2+
dnl #
3+
dnl # 2.6.38 API change
4+
dnl # The .get_sb callback has been replaced by a .mount callback
5+
dnl # in the file_system_type structure.
6+
dnl #
7+
dnl # 5.2 API change
8+
dnl # The new fs_context-based filesystem API is introduced, with the old
9+
dnl # one (via file_system_type.mount) preserved as a compatibility shim.
10+
dnl #
11+
dnl # 7.0 API change
12+
dnl # Compatibility shim removed, so all callers must go through the mount API.
13+
dnl #
14+
AC_DEFUN([ZFS_AC_KERNEL_SRC_FS_CONTEXT], [
15+
ZFS_LINUX_TEST_SRC([fs_context], [
16+
#include <linux/fs.h>
17+
#include <linux/fs_context.h>
18+
],[
19+
static struct fs_context fs __attribute__ ((unused)) = { 0 };
20+
static struct fs_context *fsp __attribute__ ((unused));
21+
fsp = vfs_dup_fs_context(&fs);
22+
])
23+
])
24+
25+
AC_DEFUN([ZFS_AC_KERNEL_FS_CONTEXT], [
26+
AC_MSG_CHECKING([whether fs_context exists])
27+
ZFS_LINUX_TEST_RESULT([fs_context], [
28+
AC_MSG_RESULT(yes)
29+
AC_DEFINE(HAVE_FS_CONTEXT, 1, [fs_context exists])
30+
],[
31+
AC_MSG_RESULT(no)
32+
])
33+
])

config/kernel-fst-mount.m4

Lines changed: 0 additions & 36 deletions
This file was deleted.

config/kernel.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
7575
ZFS_AC_KERNEL_SRC_DENTRY
7676
ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
7777
ZFS_AC_KERNEL_SRC_SECURITY_INODE
78-
ZFS_AC_KERNEL_SRC_FST_MOUNT
78+
ZFS_AC_KERNEL_SRC_FS_CONTEXT
7979
ZFS_AC_KERNEL_SRC_SB_DYING
8080
ZFS_AC_KERNEL_SRC_SET_NLINK
8181
ZFS_AC_KERNEL_SRC_SGET
@@ -199,7 +199,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
199199
ZFS_AC_KERNEL_DENTRY
200200
ZFS_AC_KERNEL_TRUNCATE_SETSIZE
201201
ZFS_AC_KERNEL_SECURITY_INODE
202-
ZFS_AC_KERNEL_FST_MOUNT
202+
ZFS_AC_KERNEL_FS_CONTEXT
203203
ZFS_AC_KERNEL_SB_DYING
204204
ZFS_AC_KERNEL_SET_NLINK
205205
ZFS_AC_KERNEL_SGET

module/os/linux/zfs/zpl_super.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
#include <linux/iversion.h>
3737
#include <linux/version.h>
3838
#include <linux/vfs_compat.h>
39-
40-
#ifndef HAVE_FST_MOUNT
39+
#ifdef HAVE_FS_CONTEXT
4140
#include <linux/fs_context.h>
4241
#endif
4342

@@ -509,17 +508,15 @@ zpl_prune_sb(uint64_t nr_to_scan, void *arg)
509508
#endif
510509
}
511510

512-
#ifndef HAVE_FST_MOUNT
511+
#ifdef HAVE_FS_CONTEXT
513512
/*
514-
* In kernel 7.0, the file_system_type->mount() and
515-
* super_operations->remount_fs() callbacks have been removed, requiring all
516-
* users to convert to the "new" fs_context-based mount API introduced in 5.2.
513+
* Since kernel 5.2, the "new" fs_context-based mount API has been preferred
514+
* over the traditional file_system_type->mount() and
515+
* super_operations->remount_fs() callbacks, which were deprectate. In 7.0,
516+
* those callbacks were removed.
517517
*
518-
* This is the simplest compatibility shim possible to adapt the fs_context
519-
* interface to the old-style calls. Although this interface exists in almost
520-
* all versions of Linux currently supported by OpenZFS, we only use it when
521-
* the kernel-provided shims are unavailable, to avoid bugs in these new shims
522-
* affecting all OpenZFS deployments.
518+
* Currently, the old-style interface are the only ones we need, so this is
519+
* a simple compatibility shim to adapt the new API to the old-style calls.
523520
*/
524521
static int
525522
zpl_parse_monolithic(struct fs_context *fc, void *data)
@@ -577,7 +574,7 @@ const struct super_operations zpl_super_operations = {
577574
.put_super = zpl_put_super,
578575
.sync_fs = zpl_sync_fs,
579576
.statfs = zpl_statfs,
580-
#ifdef HAVE_FST_MOUNT
577+
#ifndef HAVE_FS_CONTEXT
581578
.remount_fs = zpl_remount_fs,
582579
#endif
583580
.show_devname = zpl_show_devname,
@@ -622,10 +619,10 @@ struct file_system_type zpl_fs_type = {
622619
#else
623620
.fs_flags = FS_USERNS_MOUNT,
624621
#endif
625-
#ifdef HAVE_FST_MOUNT
626-
.mount = zpl_mount,
627-
#else
622+
#ifdef HAVE_FS_CONTEXT
628623
.init_fs_context = zpl_init_fs_context,
624+
#else
625+
.mount = zpl_mount,
629626
#endif
630627
.kill_sb = zpl_kill_sb,
631628
};

0 commit comments

Comments
 (0)