From f3d4c7949622ca09aee10c54d95e7e480892f0f9 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Thu, 26 Feb 2026 08:17:33 +1100 Subject: [PATCH] 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 Reviewed-by: Brian Behlendorf Signed-off-by: Rob Norris Closes #18260 --- config/kernel-fs-context.m4 | 33 ++++++++++++++++++++++++++++++ config/kernel-fst-mount.m4 | 36 --------------------------------- config/kernel.m4 | 4 ++-- module/os/linux/zfs/zpl_super.c | 27 +++++++++++-------------- 4 files changed, 47 insertions(+), 53 deletions(-) create mode 100644 config/kernel-fs-context.m4 delete mode 100644 config/kernel-fst-mount.m4 diff --git a/config/kernel-fs-context.m4 b/config/kernel-fs-context.m4 new file mode 100644 index 000000000..13e1f5ffc --- /dev/null +++ b/config/kernel-fs-context.m4 @@ -0,0 +1,33 @@ +dnl # SPDX-License-Identifier: CDDL-1.0 +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 # +dnl # 5.2 API change +dnl # The new fs_context-based filesystem API is introduced, with the old +dnl # one (via file_system_type.mount) preserved as a compatibility shim. +dnl # +dnl # 7.0 API change +dnl # Compatibility shim removed, so all callers must go through the mount API. +dnl # +AC_DEFUN([ZFS_AC_KERNEL_SRC_FS_CONTEXT], [ + ZFS_LINUX_TEST_SRC([fs_context], [ + #include + #include + ],[ + static struct fs_context fs __attribute__ ((unused)) = { 0 }; + static struct fs_context *fsp __attribute__ ((unused)); + fsp = vfs_dup_fs_context(&fs); + ]) +]) + +AC_DEFUN([ZFS_AC_KERNEL_FS_CONTEXT], [ + AC_MSG_CHECKING([whether fs_context exists]) + ZFS_LINUX_TEST_RESULT([fs_context], [ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_FS_CONTEXT, 1, [fs_context exists]) + ],[ + AC_MSG_RESULT(no) + ]) +]) diff --git a/config/kernel-fst-mount.m4 b/config/kernel-fst-mount.m4 deleted file mode 100644 index 3c9137498..000000000 --- a/config/kernel-fst-mount.m4 +++ /dev/null @@ -1,36 +0,0 @@ -dnl # SPDX-License-Identifier: CDDL-1.0 -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 # -dnl # 7.0 API change -dnl # The .mount callback has been removed, requiring all mount work -dnl # to be done through the "new" mount API introduced in 5.2. -dnl # -AC_DEFUN([ZFS_AC_KERNEL_SRC_FST_MOUNT], [ - ZFS_LINUX_TEST_SRC([file_system_type_mount], [ - #include - - 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_DEFUN([ZFS_AC_KERNEL_FST_MOUNT], [ - AC_MSG_CHECKING([whether fst->mount() exists]) - ZFS_LINUX_TEST_RESULT([file_system_type_mount], [ - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_FST_MOUNT, 1, [fst->mount() exists]) - ],[ - AC_MSG_RESULT(no) - ]) -]) diff --git a/config/kernel.m4 b/config/kernel.m4 index c429397b0..45a215d22 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -75,7 +75,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [ ZFS_AC_KERNEL_SRC_DENTRY ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE ZFS_AC_KERNEL_SRC_SECURITY_INODE - ZFS_AC_KERNEL_SRC_FST_MOUNT + ZFS_AC_KERNEL_SRC_FS_CONTEXT ZFS_AC_KERNEL_SRC_SB_DYING ZFS_AC_KERNEL_SRC_SET_NLINK ZFS_AC_KERNEL_SRC_SGET @@ -199,7 +199,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [ ZFS_AC_KERNEL_DENTRY ZFS_AC_KERNEL_TRUNCATE_SETSIZE ZFS_AC_KERNEL_SECURITY_INODE - ZFS_AC_KERNEL_FST_MOUNT + ZFS_AC_KERNEL_FS_CONTEXT ZFS_AC_KERNEL_SB_DYING ZFS_AC_KERNEL_SET_NLINK ZFS_AC_KERNEL_SGET diff --git a/module/os/linux/zfs/zpl_super.c b/module/os/linux/zfs/zpl_super.c index d509152b6..f8d1e2a55 100644 --- a/module/os/linux/zfs/zpl_super.c +++ b/module/os/linux/zfs/zpl_super.c @@ -36,8 +36,7 @@ #include #include #include - -#ifndef HAVE_FST_MOUNT +#ifdef HAVE_FS_CONTEXT #include #endif @@ -509,17 +508,15 @@ zpl_prune_sb(uint64_t nr_to_scan, void *arg) #endif } -#ifndef HAVE_FST_MOUNT +#ifdef HAVE_FS_CONTEXT /* - * In kernel 7.0, the file_system_type->mount() and - * super_operations->remount_fs() callbacks have been removed, requiring all - * users to convert to the "new" fs_context-based mount API introduced in 5.2. + * Since kernel 5.2, the "new" fs_context-based mount API has been preferred + * over the traditional file_system_type->mount() and + * super_operations->remount_fs() callbacks, which were deprectate. In 7.0, + * those callbacks were removed. * - * This is the simplest compatibility shim possible to adapt the fs_context - * interface to the old-style calls. Although this interface exists in almost - * all versions of Linux currently supported by OpenZFS, we only use it when - * the kernel-provided shims are unavailable, to avoid bugs in these new shims - * affecting all OpenZFS deployments. + * Currently, the old-style interface are the only ones we need, so this is + * a simple compatibility shim to adapt the new API to the old-style calls. */ static int zpl_parse_monolithic(struct fs_context *fc, void *data) @@ -577,7 +574,7 @@ const struct super_operations zpl_super_operations = { .put_super = zpl_put_super, .sync_fs = zpl_sync_fs, .statfs = zpl_statfs, -#ifdef HAVE_FST_MOUNT +#ifndef HAVE_FS_CONTEXT .remount_fs = zpl_remount_fs, #endif .show_devname = zpl_show_devname, @@ -622,10 +619,10 @@ struct file_system_type zpl_fs_type = { #else .fs_flags = FS_USERNS_MOUNT, #endif -#ifdef HAVE_FST_MOUNT - .mount = zpl_mount, -#else +#ifdef HAVE_FS_CONTEXT .init_fs_context = zpl_init_fs_context, +#else + .mount = zpl_mount, #endif .kill_sb = zpl_kill_sb, };