public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Christoph Hellwig <hch@lst.de>,
	Chuck Lever <chuck.lever@oracle.com>,
	 Amir Goldstein <amir73il@gmail.com>
Cc: NeilBrown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	 Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	linux-nfs@vger.kernel.org, 	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 4/4] exportfs,nfsd: rework checking for layout-based block device access support
Date: Tue, 31 Mar 2026 13:52:09 -0400	[thread overview]
Message-ID: <73abf22dec079ed8eb3795ecdeaa851b704bdcb8.camel@kernel.org> (raw)
In-Reply-To: <20260331153406.4049290-5-hch@lst.de>

On Tue, 2026-03-31 at 17:33 +0200, Christoph Hellwig wrote:
> Currently NFSD hard codes checking support for block-style layouts.
> Lift the checks into a file system-helper and provide a exportfs-level
> helper to implement the typical checks.
> 
> This prepares for supporting block layout export of multiple devices
> per file system.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/nfsd/export.c               |  3 +-
>  fs/nfsd/nfs4layouts.c          | 26 +++++------------
>  fs/xfs/xfs_pnfs.c              | 13 +++++++++
>  include/linux/exportfs_block.h | 52 +++++++++++++++++++++++++++++++++-
>  4 files changed, 73 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
> index 8e8a76a44ff0..e20298f9212f 100644
> --- a/fs/nfsd/export.c
> +++ b/fs/nfsd/export.c
> @@ -735,7 +735,8 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
>  			goto out4;
>  		err = 0;
>  
> -		nfsd4_setup_layout_type(&exp);
> +		if (exp.ex_flags & NFSEXP_PNFS)
> +			nfsd4_setup_layout_type(&exp);
>  	}
>  
>  	expp = svc_export_lookup(&exp);
> diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c
> index c53eb67969eb..7b849b637b5e 100644
> --- a/fs/nfsd/nfs4layouts.c
> +++ b/fs/nfsd/nfs4layouts.c
> @@ -2,7 +2,6 @@
>  /*
>   * Copyright (c) 2014 Christoph Hellwig.
>   */
> -#include <linux/blkdev.h>
>  #include <linux/exportfs_block.h>
>  #include <linux/kmod.h>
>  #include <linux/file.h>
> @@ -126,28 +125,17 @@ nfsd4_set_deviceid(struct nfsd4_deviceid *id, const struct svc_fh *fhp,
>  
>  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;
> -	struct exportfs_block_ops *bops = sb->s_export_op->block_ops;
> -#endif
> -
> -	if (!(exp->ex_flags & NFSEXP_PNFS))
> -		return;
> +	expfs_block_layouts_t block_supported = exporfs_layouts_supported(sb);
>  
> -#ifdef CONFIG_NFSD_FLEXFILELAYOUT
> -	exp->ex_layout_types |= 1 << LAYOUT_FLEX_FILES;
> -#endif
> -#ifdef CONFIG_NFSD_BLOCKLAYOUT
> -	if (bops && bops->get_uuid && bops->map_blocks && bops->commit_blocks)
> +	if (IS_ENABLED(CONFIG_NFSD_FLEXFILELAYOUT))
> +		exp->ex_layout_types |= 1 << LAYOUT_FLEX_FILES;
> +	if (IS_ENABLED(CONFIG_NFSD_BLOCKLAYOUT) &&
> +	    (block_supported & EXPFS_BLOCK_IN_BAND_ID))
>  		exp->ex_layout_types |= 1 << LAYOUT_BLOCK_VOLUME;
> -#endif
> -#ifdef CONFIG_NFSD_SCSILAYOUT
> -	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)
> +	if (IS_ENABLED(CONFIG_NFSD_SCSILAYOUT) &&
> +	    (block_supported & EXPFS_BLOCK_OUT_OF_BAND_ID))
>  		exp->ex_layout_types |= 1 << LAYOUT_SCSI;
> -#endif
>  }
>  
>  void nfsd4_close_layout(struct nfs4_layout_stateid *ls)
> diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
> index fee782a3edbe..acefa0b99f53 100644
> --- a/fs/xfs/xfs_pnfs.c
> +++ b/fs/xfs/xfs_pnfs.c
> @@ -13,6 +13,7 @@
>  #include "xfs_bmap.h"
>  #include "xfs_iomap.h"
>  #include "xfs_pnfs.h"
> +#include <linux/exportfs_block.h>
>  
>  /*
>   * Ensure that we do not have any outstanding pNFS layouts that can be used by
> @@ -45,6 +46,17 @@ xfs_break_leased_layouts(
>  	return error;
>  }
>  
> +static expfs_block_layouts_t
> +xfs_fs_layouts_supported(
> +	struct super_block	*sb)
> +{
> +	expfs_block_layouts_t	supported = EXPFS_BLOCK_IN_BAND_ID;
> +
> +	if (exportfs_bdev_supports_out_of_band_id(sb->s_bdev))
> +		supported |= EXPFS_BLOCK_OUT_OF_BAND_ID;
> +	return supported;
> +}
> +
>  /*
>   * Get a unique ID including its location so that the client can identify
>   * the exported device.
> @@ -335,6 +347,7 @@ xfs_fs_commit_blocks(
>  }
>  
>  struct exportfs_block_ops xfs_export_block_ops = {
> +	.layouts_supported	= xfs_fs_layouts_supported,
>  	.get_uuid		= xfs_fs_get_uuid,
>  	.map_blocks		= xfs_fs_map_blocks,
>  	.commit_blocks		= xfs_fs_commit_blocks,
> diff --git a/include/linux/exportfs_block.h b/include/linux/exportfs_block.h
> index d1dec4689b14..8d5b0b0c5a82 100644
> --- a/include/linux/exportfs_block.h
> +++ b/include/linux/exportfs_block.h
> @@ -7,13 +7,35 @@
>  #ifndef LINUX_EXPORTFS_BLOCK_H
>  #define LINUX_EXPORTFS_BLOCK_H 1
>  
> -#include <linux/types.h>
> +#include <linux/blkdev.h>
> +#include <linux/exportfs.h>
> +#include <linux/fs.h>
>  
>  struct inode;
>  struct iomap;
>  struct super_block;
>  
> +/*
> + * There are the two types of block-style layout support:
> + *  - In-band implies a device identified by a unique cookie inside the actual
> + *    device address space checked by the ->get_uuid method as used by the pNFS
> + *    block layout.  This is a bit dangerous and deprecated.
> + *  - Out of band implies identification by out of band unique identifiers
> + *    specified by the storage protocol, which is much safer and used by the
> + *    pNFS SCSI/NVMe layouts.
> + */
> +typedef unsigned int __bitwise expfs_block_layouts_t;
> +#define EXPFS_BLOCK_FLAG(__bit) \
> +	((__force expfs_block_layouts_t)(1u << __bit))
> +#define EXPFS_BLOCK_IN_BAND_ID		EXPFS_BLOCK_FLAG(0)
> +#define EXPFS_BLOCK_OUT_OF_BAND_ID	EXPFS_BLOCK_FLAG(1)
> +
>  struct exportfs_block_ops {
> +	/*
> +	 * Returns the EXPFS_BLOCK_* bitmap of supported layout types.
> +	 */
> +	expfs_block_layouts_t (*layouts_supported)(struct super_block *sb);
> +
>  	/*
>  	 * Get the in-band device unique signature exposed to clients.
>  	 */
> @@ -35,4 +57,32 @@ struct exportfs_block_ops {
>  			int nr_iomaps, loff_t new_size);
>  };
>  
> +static inline bool
> +exportfs_bdev_supports_out_of_band_id(struct block_device *bdev)
> +{
> +	return bdev->bd_disk->fops->pr_ops &&
> +		bdev->bd_disk->fops->get_unique_id;
> +}
> +
> +#ifdef CONFIG_EXPORTFS_BLOCK_OPS
> +static inline expfs_block_layouts_t
> +exporfs_layouts_supported(struct super_block *sb)
> +{
> +	struct exportfs_block_ops *bops = sb->s_export_op->block_ops;
> +
> +	if (!bops ||
> +	    !bops->layouts_supported ||
> +	    WARN_ON_ONCE(!bops->map_blocks) ||
> +	    WARN_ON_ONCE(!bops->commit_blocks))
> +		return 0;
> +	return bops->layouts_supported(sb);
> +}
> +#else
> +static inline expfs_block_layouts_t
> +exporfs_layouts_supported(struct super_block *sb)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_EXPORTFS_BLOCK_OPS */
> +
>  #endif /* LINUX_EXPORTFS_BLOCK_H */

Much cleaner.

Reviewed-by: Jeff Layton <jlayton@kernel.org>

  reply	other threads:[~2026-03-31 17:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 15:33 cleanup block-style layouts exports Christoph Hellwig
2026-03-31 15:33 ` [PATCH 1/4] nfsd/blocklayout: always ignore loca_time_modify Christoph Hellwig
2026-03-31 17:09   ` Jeff Layton
2026-04-01 14:25     ` Christoph Hellwig
2026-03-31 15:33 ` [PATCH 2/4] exportfs: split out the ops for layout-based block device access Christoph Hellwig
2026-03-31 17:24   ` Jeff Layton
2026-04-01 14:27     ` Christoph Hellwig
2026-03-31 18:07   ` Chuck Lever
2026-04-01  6:23     ` Christoph Hellwig
2026-03-31 15:33 ` [PATCH 3/4] exportfs: don't pass struct iattr to ->commit_blocks Christoph Hellwig
2026-03-31 17:26   ` Jeff Layton
2026-03-31 17:30     ` Chuck Lever
2026-03-31 17:33       ` Jeff Layton
2026-04-01  6:24         ` Christoph Hellwig
2026-03-31 15:33 ` [PATCH 4/4] exportfs,nfsd: rework checking for layout-based block device access support Christoph Hellwig
2026-03-31 17:52   ` Jeff Layton [this message]
2026-03-31 18:00   ` Chuck Lever
2026-03-31 17:33 ` cleanup block-style layouts exports Chuck Lever
2026-04-01  6:19   ` Christoph Hellwig
2026-04-01 13:39     ` Chuck Lever
  -- strict thread matches above, loose matches on Subject: below --
2026-04-01 14:40 cleanup block-style layouts exports v2 Christoph Hellwig
2026-04-01 14:40 ` [PATCH 4/4] exportfs,nfsd: rework checking for layout-based block device access support Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73abf22dec079ed8eb3795ecdeaa851b704bdcb8.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=amir73il@gmail.com \
    --cc=chuck.lever@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox