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=1796387690; b=2NGtZhx/ebaqN150VAjyWm7au04yl+cS5E6df3Bta1EJDg0WSMVI0o4sXzpgRmxZv4j/ AeUerwcT6+FtM4jlgKA7eJ+HG75HjMyd8VLSjbBRal88KRrR8CtuV6CS/Wdx18Qi5/Mkj PkNPY5n3JRbRqUhKV6+xtYpWnR22jy9y6gSMJBljdPG0t+oUxfRLGQrjyy/M2lsnub9TM cJUqkEvMelIxQpDWo877f6Aigk7KLdO5pF9qCVo3xvHe8+9LLhmUZfO2xQaqyBN91+gVR YzwkAfVf8frRfV/W3V8QEiSyygJADes/fpw6oNER5/ES17po5PN1fk0qs1e/iPLXINg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387690; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=JEnmJYzTIuE4yy+vfjP4UNe2oZ7zeuwBeeVSaLz3JGw=; b=kPO8M8XHegAuA0RBpfJUeWKm9mXBeFemlPd7wBeTbaOjLlRB0N2KenNFV7bf2t0PRAPb 9Btxz6dvu2Vrgdd/AbjBzrrnXMBblWfMCkrFqMLwRo++rAgpbHGp1c/pDgT/3K1WT8RYU Evl/u+X98TAhStOK7GZqqLus9wwHn6Z8ft7/NZD6QnMG55FVTmp3+eILUj9deK7YMTuj4 18jNsICJ4s/UMGtPueONjlgVWWp5FOij7FOdasP8x9iHRQBzGv9eKq8I9csTk2atdymPz tFLFdhEMhkDsY2B5Qu+o9M68IaU72rihmqpgKFgPlAVGtazDW6iQ56KcTzpTXArPVFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=MZZxe7jZ; 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 BF2F6606A322; Fri, 4 Dec 2026 12:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=MZZxe7jZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3725F1F000CE; Fri, 4 Dec 2026 12:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387690; bh=JEnmJYzTIuE4yy+vfjP4UNe2oZ7zeuwBeeVSaLz3JGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MZZxe7jZ+t7BhhNawGBjEMKYIKJa9vmDvvyhLlMk9tYADuiXAgxeSPS0yc8GwIX0U k/ARXLLXK63p9Xu0uoEt34XWtw+ce2jvMdBFeWXcdbbrHM39ynYx1UdTwOt3MKRxN0 AsLGYzF2JxCSRmYFMwFjiAxwIs4mtcsmEHeTT2OY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mike Snitzer , Anna Schumaker , Sasha Levin Subject: [PATCH 6.1 0349/1059] pNFS/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS over the mdsthreshold hint Date: Fri, 4 Dec 2026 18:58:00 +0900 Message-ID: <20261204100653.306251581@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mike Snitzer [ Upstream commit 78422f623c1e150e3cdfe62598c6e352a2dcfc5f ] A flexfiles layout may carry FF_FLAGS_NO_IO_THRU_MDS, which tells the client that this file's data must not be read or written through the metadata server. The RFC 5661 mdsthreshold hint pulls the other way. When a server returns one, pnfs_within_mdsthreshold() answers "use MDS I/O" for every I/O below the threshold, pnfs_update_layout() then hands back no segment, and ff_layout_pg_init_read() reads through the MDS - the very thing the layout forbids. A server that sets both is asking for two incompatible things; the layout flag is the stronger statement, and the one whose violation the client cannot recover from. Record the policy on the inode, where it outlives the layout hdr that carried it, and consult it before the hint: - ff_layout_alloc_lseg() sets NFS_INO_NO_IO_THRU_MDS beside the existing sticky hdr-level NFS4_FF_HDR_NO_IO_THRU_MDS bit. - pnfs_within_mdsthreshold() returns false at once for such an inode, so no I/O is diverted to the MDS on the strength of the hint. The bit is never cleared for the life of the in-core inode. Servers are assumed to be consistent in their no-fallback policy per file, which is the assumption ff_layout_hdr_no_fallback_to_mds() already makes; a server that was not would lose the effect of its mdsthreshold hint - a SHOULD - on an inode that is already in core, and nothing else. Fixes: 260074cd8413 ("pNFS/flexfiles: Add support for FF_FLAGS_NO_IO_THRU_MDS") Assisted-by: Claude:claude-opus-5[1m] Signed-off-by: Mike Snitzer Signed-off-by: Anna Schumaker [ sashal: Omitted the nfs_file_block_o_direct() context in internal.h, since that helper is missing here, so the new bit and helpers are inserted before the NFS_PATH_CANONICAL define instead. ] Signed-off-by: Sasha Levin --- fs/nfs/flexfilelayout/flexfilelayout.c | 5 ++++- fs/nfs/internal.h | 29 ++++++++++++++++++++++++++ fs/nfs/pnfs.c | 12 ++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 8e9d523bcb6a9..79b1210986ab3 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -539,9 +539,12 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh, if (!p) goto out_sort_mirrors; fls->flags = be32_to_cpup(p); - if (fls->flags & FF_FLAGS_NO_IO_THRU_MDS) + if (fls->flags & FF_FLAGS_NO_IO_THRU_MDS) { set_bit(NFS4_FF_HDR_NO_IO_THRU_MDS, &FF_LAYOUT_FROM_HDR(lh)->flags); + /* Outlives this layout hdr; see NFS_INO_NO_IO_THRU_MDS */ + nfs_set_no_io_thru_mds(lh->plh_inode); + } p = xdr_inline_decode(&stream, 4); if (!p) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 87f16510777ec..d71098bb69e17 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -464,6 +464,35 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi) return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0; } +/* + * Module-private nfs_inode->flags bit (not in , so no + * exported layout changes): set, and never cleared for the life of the + * in-core inode, once a layout driver has seen the server forbid I/O + * through the MDS for this file (flexfiles sets it from + * FF_FLAGS_NO_IO_THRU_MDS in ff_layout_alloc_lseg()). The RFC 5661 + * mdsthreshold hint must not be acted on for such a file, since the only + * thing pnfs_within_mdsthreshold() can ask for is the one thing the + * layout forbids. Servers are assumed to be consistent in their + * no-fallback policy per file, the same assumption + * ff_layout_hdr_no_fallback_to_mds() already makes; if one were not, the + * only effect is that its mdsthreshold hint - a SHOULD - stops being + * honored for an inode that is already in core. + */ +#define NFS_INO_NO_IO_THRU_MDS (30) + +static inline void nfs_set_no_io_thru_mds(struct inode *inode) +{ + struct nfs_inode *nfsi = NFS_I(inode); + + if (!test_bit(NFS_INO_NO_IO_THRU_MDS, &nfsi->flags)) + set_bit(NFS_INO_NO_IO_THRU_MDS, &nfsi->flags); +} + +static inline bool nfs_no_io_thru_mds(struct inode *inode) +{ + return test_bit(NFS_INO_NO_IO_THRU_MDS, &NFS_I(inode)->flags); +} + /* namespace.c */ #define NFS_PATH_CANONICAL 1 extern char *nfs_path(char **p, struct dentry *dentry, diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 9e1c50e0d6a53..0e792b9e72bcc 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1870,7 +1870,9 @@ pnfs_find_lseg(struct pnfs_layout_hdr *lo, * is set to IOMODE_READ for a READ request, and set to IOMODE_RW for a * WRITE request. * - * A return of true means use MDS I/O. + * A return of true means use MDS I/O, so for a file whose layout forbids + * that (see NFS_INO_NO_IO_THRU_MDS) the hint is not evaluated at all: + * there is no answer it could give that this client may act on. * * From rfc 5661: * If a file's size is smaller than the file size threshold, data accesses @@ -1891,6 +1893,14 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx, if (t == NULL) return ret; + /* + * The server has told a layout driver that this file's I/O may not + * go through the MDS (flexfiles FF_FLAGS_NO_IO_THRU_MDS). Honor + * that over its own mdsthreshold hint. + */ + if (nfs_no_io_thru_mds(ino)) + return ret; + dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", __func__, t->bm, t->rd_sz, t->wr_sz, t->rd_io_sz, t->wr_io_sz); -- 2.53.0