From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793929991; b=NnGhyyNuRz9weuYVcoblwRTPvji3O/UEPy6uMrkrRulafB6wCUC/gVUnYE2Ow0vbs/i3 aZibQL6SaThykdeuw5wq5DnN2SX82q9ig52YFXKcqT4Am/zHUGx6HDY3HAVpgojGBo4Fa CROTdRzaQMrxgQxbSTP9DlnzAfTuXkCdaoBdDisr7O1+ZR5ElkoKN9giUrCg45VXeQUuH xYxQIoUnYESWL/ZgAK1ap+L9MCjOCtNOW95yVfFIPk4205iX0AVf+HOuZyXxeZXdvxwut fqHtjrzdt9XkT56JF3lsE3uq/MV904FB7AWUTI/Tz79O/aW+GlGuW3YP2L1EHEJbwRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793929991; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=AB5Xy9M8EQNyTDF3PXby2HzG3zYBypqZG25vTORx/rY=; b=cAwbDehlSsMwIR86+vRS8GnQiHCf8owwm9P4kVAjMyRH35o3G+GfKRIphpy4nPACdn7b Q5yTSatdUBPv9R2qXy058j+v1kUrxfqrL3UbC6xVIRfLbEE7sV+ZsPabdI3CDfUNd5Wr1 nwTVb/Mn/24rLqRUFkCVD7QrlG3SQHLc5HYRtICkpDGS//FS1g3gZF2/gV2pfk2E/pvG8 9KY1X56Alo4fd7QjI3ee80CuLG//GAh4vwpCXCJ5sLdTf3ERSAEpZsjCMYLTufu/a+4lx 4hSfazliWX/X6U5Qy07ub1l0CqvSK+vFu1/NWWlMO6JPoKM8rCtomwpIg8KInab/DiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nFfEuSkW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8859606A329 for ; Fri, 6 Nov 2026 01:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nFfEuSkW Received: by smtp.kernel.org (Postfix) with ESMTPSA id D176E1F008A1; Fri, 6 Nov 2026 01:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793929990; bh=AB5Xy9M8EQNyTDF3PXby2HzG3zYBypqZG25vTORx/rY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nFfEuSkWhw2jG8H+01JuVe+WNJpdizlDJFhezEWiO/6J1sHMxNPGzm2G9Zk2wZ8Uw jRo+0JFxZdXDd0FQZydr2syijzB6q6pNQcDaFhWm6mNDrLmgIdXJxIy6e9MHqfcgKn GLDSTSwTDtAxLFZ7T+X1aeyAhH6J/DAzvn8Nol8R9xS5S9HYkgpDO8I0nYyiG3A5OE zWnTmQ+XPN8ibTphUTTI8VpIldYJWCKk2Ty49P7j870KpTGzfYFdC4DQJu4+0AvhvF QGjQ7nYCClQq6dOf1tf9bJ+x5txPD3pYWJ5sv0ItHYSQfwtnKoFYrOzpn2lxkTcf03 ZRfOTBpeDZnBw== From: Sasha Levin To: stable@vger.kernel.org Cc: Christoph Hellwig , Jeff Layton , Chuck Lever , Christian Brauner , Sasha Levin Subject: [PATCH 6.18.y 4/5] exportfs,nfsd: rework checking for layout-based block device access support Date: Thu, 5 Nov 2026 20:53:04 -0500 Message-ID: <20261106015245.3586810-4-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261106015245.3586810-1-sashal@kernel.org> References: <2026110409-glaucoma-strongman-8f52@gregkh> <20261106015245.3586810-1-sashal@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Christoph Hellwig [ Upstream commit da9baa5470dcb077a7c9806f0925c60b530c470b ] 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 Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Link: https://patch.msgid.link/20260423181854.743150-5-cel@kernel.org Signed-off-by: Christian Brauner Stable-dep-of: 5d28b2c920d9 ("nfsd: don't offer flexfiles layouts when NFSv3 isn't being served") Signed-off-by: Sasha Levin --- 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 2a1499f2ad196..e33843a937dd6 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -722,7 +722,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 6b6f55ae0472d..c2d435c99bf5e 100644 --- a/fs/nfsd/nfs4layouts.c +++ b/fs/nfsd/nfs4layouts.c @@ -2,7 +2,6 @@ /* * Copyright (c) 2014 Christoph Hellwig. */ -#include #include #include #include @@ -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; - const 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 = exportfs_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 c685995b69d7e..1b0b739571612 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 /* * 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. @@ -334,6 +346,7 @@ xfs_fs_commit_blocks( } const 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 1f52fea8e4dce..92f990d190bba 100644 --- a/include/linux/exportfs_block.h +++ b/include/linux/exportfs_block.h @@ -7,14 +7,36 @@ #ifndef LINUX_EXPORTFS_BLOCK_H #define LINUX_EXPORTFS_BLOCK_H 1 -#include +#include +#include +#include struct iattr; 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. */ @@ -36,4 +58,32 @@ struct exportfs_block_ops { int nr_iomaps, struct iattr *iattr); }; +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 +exportfs_layouts_supported(struct super_block *sb) +{ + const 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 +exportfs_layouts_supported(struct super_block *sb) +{ + return 0; +} +#endif /* CONFIG_EXPORTFS_BLOCK_OPS */ + #endif /* LINUX_EXPORTFS_BLOCK_H */ -- 2.53.0