]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exportfs: split out the ops for layout-based block device access
authorChristoph Hellwig <hch@lst.de>
Thu, 23 Apr 2026 18:18:52 +0000 (14:18 -0400)
committerChristian Brauner <brauner@kernel.org>
Mon, 11 May 2026 09:11:48 +0000 (11:11 +0200)
The support to grant layouts for direct block device access works
at a very different layer than the rest of exports.  Split the methods
for it into a separate struct, and move that into a separate header
to better split things out.  The pointer to the new operation vector
is kept in export_operations to avoid bloating the super_block.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Link: https://patch.msgid.link/20260423181854.743150-3-cel@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
MAINTAINERS
fs/nfsd/blocklayout.c
fs/nfsd/nfs4layouts.c
fs/xfs/xfs_export.c
fs/xfs/xfs_pnfs.c
fs/xfs/xfs_pnfs.h
include/linux/exportfs.h
include/linux/exportfs_block.h [new file with mode: 0644]

index 2fb1c75afd16388f590a77c04e08d2d6d002f5cc..bad36d48a4475965ae8c03c5526308e0ab36c15c 100644 (file)
@@ -9903,7 +9903,7 @@ S:        Supported
 F:     Documentation/filesystems/nfs/exporting.rst
 F:     fs/exportfs/
 F:     fs/fhandle.c
-F:     include/linux/exportfs.h
+F:     include/linux/exportfs*.h
 
 FILESYSTEMS [IDMAPPED MOUNTS]
 M:     Christian Brauner <brauner@kernel.org>
index 24cc5025f649289633c1b7455281f3f193976cce..e612fcf8666a8dc7d376ad09db0b2e849e9bb4ae 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * Copyright (c) 2014-2016 Christoph Hellwig.
  */
-#include <linux/exportfs.h>
+#include <linux/exportfs_block.h>
 #include <linux/iomap.h>
 #include <linux/slab.h>
 #include <linux/pr.h>
@@ -32,8 +32,8 @@ nfsd4_block_map_extent(struct inode *inode, const struct svc_fh *fhp,
        u32 device_generation = 0;
        int error;
 
-       error = sb->s_export_op->map_blocks(inode, offset, length, &iomap,
-                       iomode != IOMODE_READ, &device_generation);
+       error = sb->s_export_op->block_ops->map_blocks(inode, offset, length,
+                       &iomap, iomode != IOMODE_READ, &device_generation);
        if (error) {
                if (error == -ENXIO)
                        return nfserr_layoutunavailable;
@@ -199,8 +199,8 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp,
                iattr.ia_size = lcp->lc_newsize;
        }
 
-       error = inode->i_sb->s_export_op->commit_blocks(inode, iomaps,
-                       nr_iomaps, &iattr);
+       error = inode->i_sb->s_export_op->block_ops->commit_blocks(inode,
+                       iomaps, nr_iomaps, &iattr);
        kfree(iomaps);
        return nfserrno(error);
 }
@@ -223,8 +223,8 @@ nfsd4_block_get_device_info_simple(struct super_block *sb,
 
        b->type = PNFS_BLOCK_VOLUME_SIMPLE;
        b->simple.sig_len = PNFS_BLOCK_UUID_LEN;
-       return sb->s_export_op->get_uuid(sb, b->simple.sig, &b->simple.sig_len,
-                       &b->simple.offset);
+       return sb->s_export_op->block_ops->get_uuid(sb, b->simple.sig,
+                       &b->simple.sig_len, &b->simple.offset);
 }
 
 static __be32
index 69e41105efdd5b06f5e30dd4a64d7cdfc72fa2e2..cf5b7eb417c5ca7254c243e155f93ddc57dc9cef 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (c) 2014 Christoph Hellwig.
  */
 #include <linux/blkdev.h>
+#include <linux/exportfs_block.h>
 #include <linux/kmod.h>
 #include <linux/file.h>
 #include <linux/jhash.h>
@@ -129,6 +130,7 @@ void nfsd4_setup_layout_type(struct svc_export *exp)
 {
 #if defined(CONFIG_NFSD_BLOCKLAYOUT) || defined(CONFIG_NFSD_SCSILAYOUT)
        struct super_block *sb = exp->ex_path.mnt->mnt_sb;
+       const struct exportfs_block_ops *bops = sb->s_export_op->block_ops;
 #endif
 
        if (!(exp->ex_flags & NFSEXP_PNFS))
@@ -138,14 +140,11 @@ void nfsd4_setup_layout_type(struct svc_export *exp)
        exp->ex_layout_types |= 1 << LAYOUT_FLEX_FILES;
 #endif
 #ifdef CONFIG_NFSD_BLOCKLAYOUT
-       if (sb->s_export_op->get_uuid &&
-           sb->s_export_op->map_blocks &&
-           sb->s_export_op->commit_blocks)
+       if (bops && bops->get_uuid && bops->map_blocks && bops->commit_blocks)
                exp->ex_layout_types |= 1 << LAYOUT_BLOCK_VOLUME;
 #endif
 #ifdef CONFIG_NFSD_SCSILAYOUT
-       if (sb->s_export_op->map_blocks &&
-           sb->s_export_op->commit_blocks &&
+       if (bops && bops->map_blocks && bops->commit_blocks &&
            sb->s_bdev &&
            sb->s_bdev->bd_disk->fops->pr_ops &&
            sb->s_bdev->bd_disk->fops->get_unique_id)
index e3e3c3c898400be02e43e62563c66a83c6145113..9b2ad3786b1908a23f6bf1101f8b1b25c023e630 100644 (file)
@@ -244,8 +244,6 @@ const struct export_operations xfs_export_operations = {
        .get_parent             = xfs_fs_get_parent,
        .commit_metadata        = xfs_fs_nfs_commit_metadata,
 #ifdef CONFIG_EXPORTFS_BLOCK_OPS
-       .get_uuid               = xfs_fs_get_uuid,
-       .map_blocks             = xfs_fs_map_blocks,
-       .commit_blocks          = xfs_fs_commit_blocks,
+       .block_ops              = &xfs_export_block_ops,
 #endif
 };
index 221e55887a2a4d6e64e83554d14f73cfee82bee0..12e083f1b9bafb37c3e77720d79165efa9250737 100644 (file)
@@ -49,7 +49,7 @@ xfs_break_leased_layouts(
  * Get a unique ID including its location so that the client can identify
  * the exported device.
  */
-int
+static int
 xfs_fs_get_uuid(
        struct super_block      *sb,
        u8                      *buf,
@@ -104,7 +104,7 @@ xfs_fs_map_update_inode(
 /*
  * Get a layout for the pNFS client.
  */
-int
+static int
 xfs_fs_map_blocks(
        struct inode            *inode,
        loff_t                  offset,
@@ -252,7 +252,7 @@ xfs_pnfs_validate_isize(
  * to manually flush the cache here similar to what the fsync code path does
  * for datasyncs on files that have no dirty metadata.
  */
-int
+static int
 xfs_fs_commit_blocks(
        struct inode            *inode,
        struct iomap            *maps,
@@ -332,3 +332,9 @@ out_drop_iolock:
        xfs_iunlock(ip, XFS_IOLOCK_EXCL);
        return error;
 }
+
+const struct exportfs_block_ops xfs_export_block_ops = {
+       .get_uuid               = xfs_fs_get_uuid,
+       .map_blocks             = xfs_fs_map_blocks,
+       .commit_blocks          = xfs_fs_commit_blocks,
+};
index 940c6c2ad88c5589b7526ea5fb6e1c13fcc75410..bf43b2009e4cc1e9ee5802da83ad543a4927beac 100644 (file)
@@ -2,13 +2,9 @@
 #ifndef _XFS_PNFS_H
 #define _XFS_PNFS_H 1
 
-#ifdef CONFIG_EXPORTFS_BLOCK_OPS
-int xfs_fs_get_uuid(struct super_block *sb, u8 *buf, u32 *len, u64 *offset);
-int xfs_fs_map_blocks(struct inode *inode, loff_t offset, u64 length,
-               struct iomap *iomap, bool write, u32 *device_generation);
-int xfs_fs_commit_blocks(struct inode *inode, struct iomap *maps, int nr_maps,
-               struct iattr *iattr);
+#include <linux/exportfs_block.h>
 
+#ifdef CONFIG_EXPORTFS_BLOCK_OPS
 int xfs_break_leased_layouts(struct inode *inode, uint *iolock,
                bool *did_unlock);
 #else
@@ -18,4 +14,7 @@ xfs_break_leased_layouts(struct inode *inode, uint *iolock, bool *did_unlock)
        return 0;
 }
 #endif /* CONFIG_EXPORTFS_BLOCK_OPS */
+
+extern const struct exportfs_block_ops xfs_export_block_ops;
+
 #endif /* _XFS_PNFS_H */
index 8bcdba28b406075ce82a4b1247b22ff2da88dd07..c835bc64f4fada39ab8197ae683b62a2f87b4e84 100644 (file)
@@ -6,9 +6,8 @@
 #include <linux/path.h>
 
 struct dentry;
-struct iattr;
+struct exportfs_block_ops;
 struct inode;
-struct iomap;
 struct super_block;
 struct vfsmount;
 
@@ -260,19 +259,13 @@ struct handle_to_path_ctx {
  * @commit_metadata:
  *    @commit_metadata should commit metadata changes to stable storage.
  *
- * @get_uuid:
- *    Get a filesystem unique signature exposed to clients.
- *
- * @map_blocks:
- *    Map and, if necessary, allocate blocks for a layout.
- *
- * @commit_blocks:
- *    Commit blocks in a layout once the client is done with them.
- *
  * @flags:
  *    Allows the filesystem to communicate to nfsd that it may want to do things
  *    differently when dealing with it.
  *
+ * @block_ops:
+ *    Operations for layout grants to block on the underlying device.
+ *
  * Locking rules:
  *    get_parent is called with child->d_inode->i_rwsem down
  *    get_name is not (which is possibly inconsistent)
@@ -290,12 +283,6 @@ struct export_operations {
        struct dentry * (*get_parent)(struct dentry *child);
        int (*commit_metadata)(struct inode *inode);
 
-       int (*get_uuid)(struct super_block *sb, u8 *buf, u32 *len, u64 *offset);
-       int (*map_blocks)(struct inode *inode, loff_t offset,
-                         u64 len, struct iomap *iomap,
-                         bool write, u32 *device_generation);
-       int (*commit_blocks)(struct inode *inode, struct iomap *iomaps,
-                            int nr_iomaps, struct iattr *iattr);
        int (*permission)(struct handle_to_path_ctx *ctx, unsigned int oflags);
        struct file * (*open)(const struct path *path, unsigned int oflags);
 #define        EXPORT_OP_NOWCC                 (0x1) /* don't collect v3 wcc data */
@@ -308,6 +295,10 @@ struct export_operations {
 #define EXPORT_OP_FLUSH_ON_CLOSE       (0x20) /* fs flushes file data on close */
 #define EXPORT_OP_NOLOCKS              (0x40) /* no file locking support */
        unsigned long   flags;
+
+#ifdef CONFIG_EXPORTFS_BLOCK_OPS
+       const struct exportfs_block_ops *block_ops;
+#endif
 };
 
 /**
diff --git a/include/linux/exportfs_block.h b/include/linux/exportfs_block.h
new file mode 100644 (file)
index 0000000..1f52fea
--- /dev/null
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2014-2026 Christoph Hellwig.
+ *
+ * Support for exportfs-based layout grants for direct block device access.
+ */
+#ifndef LINUX_EXPORTFS_BLOCK_H
+#define LINUX_EXPORTFS_BLOCK_H 1
+
+#include <linux/types.h>
+
+struct iattr;
+struct inode;
+struct iomap;
+struct super_block;
+
+struct exportfs_block_ops {
+       /*
+        * Get the in-band device unique signature exposed to clients.
+        */
+       int (*get_uuid)(struct super_block *sb, u8 *buf, u32 *len, u64 *offset);
+
+       /*
+        * Map blocks for direct block access.
+        * If @write is %true, also allocate the blocks for the range if needed.
+        */
+       int (*map_blocks)(struct inode *inode, loff_t offset, u64 len,
+                       struct iomap *iomap, bool write,
+                       u32 *device_generation);
+
+       /*
+        * Commit blocks previously handed out by ->map_blocks and written to by
+        * the client.
+        */
+       int (*commit_blocks)(struct inode *inode, struct iomap *iomaps,
+                       int nr_iomaps, struct iattr *iattr);
+};
+
+#endif /* LINUX_EXPORTFS_BLOCK_H */